@@ -91,8 +91,7 @@ const char* GrGLSLFragmentShaderBuilder::sampleOffsets() {
9191 return " _sampleOffsets" ;
9292}
9393
94- void GrGLSLFragmentShaderBuilder::maskOffMultisampleCoverage (
95- const char * mask, ScopeFlags scopeFlags) {
94+ void GrGLSLFragmentShaderBuilder::maskOffMultisampleCoverage (const char * mask, Scope scope) {
9695 const GrShaderCaps& shaderCaps = *fProgramBuilder ->shaderCaps ();
9796 if (!shaderCaps.sampleVariablesSupport ()) {
9897 SkDEBUGFAIL (" Attempted to mask sample coverage without support." );
@@ -102,58 +101,16 @@ void GrGLSLFragmentShaderBuilder::maskOffMultisampleCoverage(
102101 this ->addFeature (1 << kSampleVariables_GLSLPrivateFeature , extension);
103102 }
104103
105- if (!fHasModifiedSampleMask ) {
106- fHasModifiedSampleMask = true ;
107- if (ScopeFlags::kTopLevel != scopeFlags) {
108- this ->codePrependf (" gl_SampleMask[0] = ~0;" );
109- }
110- if (!(ScopeFlags::kInsideLoop & scopeFlags)) {
111- this ->codeAppendf (" gl_SampleMask[0] = (%s);" , mask);
112- return ;
113- }
104+ if (!fHasInitializedSampleMask && Scope::kTopLevel == scope) {
105+ this ->codeAppendf (" gl_SampleMask[0] = (%s);" , mask);
106+ fHasInitializedSampleMask = true ;
107+ return ;
114108 }
115-
116- this ->codeAppendf (" gl_SampleMask[0] &= (%s);" , mask);
117- }
118-
119- void GrGLSLFragmentShaderBuilder::applyFnToMultisampleMask (
120- const char * fn, const char * grad, ScopeFlags scopeFlags) {
121- SkASSERT (CustomFeatures::kSampleLocations & fProgramBuilder ->header ().processorFeatures ());
122- SkDEBUGCODE (fUsedProcessorFeaturesThisStage_DebugOnly |= CustomFeatures::kSampleLocations );
123- SkDEBUGCODE (fUsedProcessorFeaturesAllStages_DebugOnly |= CustomFeatures::kSampleLocations );
124-
125- int sampleCnt = fProgramBuilder ->effectiveSampleCnt ();
126- SkASSERT (sampleCnt > 1 );
127-
128- this ->codeAppendf (" {" );
129-
130- if (!grad) {
131- SkASSERT (fProgramBuilder ->shaderCaps ()->shaderDerivativeSupport ());
132- // In order to use HW derivatives, our neighbors within the same primitive must also be
133- // executing the same code. A per-pixel branch makes this pre-condition impossible to
134- // fulfill.
135- SkASSERT (!(ScopeFlags::kInsidePerPixelBranch & scopeFlags));
136- this ->codeAppendf (" float2 grad = float2(dFdx(fn), dFdy(fn));" );
137- this ->codeAppendf (" float fnwidth = fwidth(fn);" );
138- grad = " grad" ;
139- } else {
140- this ->codeAppendf (" float fnwidth = abs(%s.x) + abs(%s.y);" , grad, grad);
109+ if (!fHasInitializedSampleMask ) {
110+ this ->codePrependf (" gl_SampleMask[0] = ~0;" );
111+ fHasInitializedSampleMask = true ;
141112 }
142-
143- this ->codeAppendf (" int mask = 0;" );
144- this ->codeAppendf (" if (%s*2 < fnwidth) {" , fn); // Are ANY samples inside the implicit fn?
145- this ->codeAppendf ( " if (%s*-2 >= fnwidth) {" , fn); // Are ALL samples inside the implicit?
146- this ->codeAppendf ( " mask = ~0;" );
147- this ->codeAppendf ( " } else for (int i = 0; i < %i; ++i) {" , sampleCnt);
148- this ->codeAppendf ( " float fnsample = dot(%s, _sampleOffsets[i]) + %s;" , grad, fn);
149- this ->codeAppendf ( " if (fnsample < 0) {" );
150- this ->codeAppendf ( " mask |= (1 << i);" );
151- this ->codeAppendf ( " }" );
152- this ->codeAppendf ( " }" );
153- this ->codeAppendf (" }" );
154- this ->maskOffMultisampleCoverage (" mask" , scopeFlags);
155-
156- this ->codeAppendf (" }" );
113+ this ->codeAppendf (" gl_SampleMask[0] &= (%s);" , mask);
157114}
158115
159116const char * GrGLSLFragmentShaderBuilder::dstColor () {
@@ -260,10 +217,10 @@ void GrGLSLFragmentShaderBuilder::onFinalize() {
260217 == fUsedProcessorFeaturesAllStages_DebugOnly );
261218
262219 if (CustomFeatures::kSampleLocations & fProgramBuilder ->header ().processorFeatures ()) {
220+ this ->definitions ().append (" const float2 _sampleOffsets[] = float2[](" );
263221 const GrPipeline& pipeline = fProgramBuilder ->pipeline ();
264222 const SkTArray<SkPoint>& sampleLocations =
265223 fProgramBuilder ->renderTarget ()->renderTargetPriv ().getSampleLocations (pipeline);
266- this ->definitions ().append (" const float2 _sampleOffsets[] = float2[](" );
267224 for (int i = 0 ; i < sampleLocations.count (); ++i) {
268225 SkPoint offset = sampleLocations[i] - SkPoint::Make (.5f , .5f );
269226 if (kBottomLeft_GrSurfaceOrigin == this ->getSurfaceOrigin ()) {
0 commit comments