OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrGLSLFragmentShaderBuilder.h" | 8 #include "GrGLSLFragmentShaderBuilder.h" |
9 #include "GrRenderTarget.h" | 9 #include "GrRenderTarget.h" |
10 #include "gl/GrGLGpu.h" | 10 #include "gl/GrGLGpu.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 67 } |
68 | 68 |
69 GrGLSLFragmentShaderBuilder::GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder* p
rogram, | 69 GrGLSLFragmentShaderBuilder::GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder* p
rogram, |
70 uint8_t fragPosKey) | 70 uint8_t fragPosKey) |
71 : GrGLSLFragmentBuilder(program) | 71 : GrGLSLFragmentBuilder(program) |
72 , fSetupFragPosition(false) | 72 , fSetupFragPosition(false) |
73 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == fragPosKey) | 73 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == fragPosKey) |
74 , fHasCustomColorOutput(false) | 74 , fHasCustomColorOutput(false) |
75 , fCustomColorOutputIndex(-1) | 75 , fCustomColorOutputIndex(-1) |
76 , fHasSecondaryOutput(false) | 76 , fHasSecondaryOutput(false) |
77 , fHasInitializedSampleMask(false) | 77 , fHasInitializedSampleMask(false) { |
78 , fHasReadDstColor(false) | |
79 , fHasReadFragmentPosition(false) { | |
80 fSubstageIndices.push_back(0); | 78 fSubstageIndices.push_back(0); |
| 79 #ifdef SK_DEBUG |
| 80 fUsedBuiltInState = GrProcessor::kNone_BuiltInState; |
| 81 fHasReadDstColor = false; |
| 82 #endif |
81 } | 83 } |
82 | 84 |
83 bool GrGLSLFragmentShaderBuilder::enableFeature(GLSLFeature feature) { | 85 bool GrGLSLFragmentShaderBuilder::enableFeature(GLSLFeature feature) { |
84 switch (feature) { | 86 switch (feature) { |
85 case kStandardDerivatives_GLSLFeature: { | 87 case kStandardDerivatives_GLSLFeature: { |
86 if (!fProgramBuilder->glslCaps()->shaderDerivativeSupport()) { | 88 if (!fProgramBuilder->glslCaps()->shaderDerivativeSupport()) { |
87 return false; | 89 return false; |
88 } | 90 } |
89 const char* extension = fProgramBuilder->glslCaps()->shaderDerivativ
eExtensionString(); | 91 const char* extension = fProgramBuilder->glslCaps()->shaderDerivativ
eExtensionString(); |
90 if (extension) { | 92 if (extension) { |
(...skipping 25 matching lines...) Expand all Loading... |
116 SkString coords2D("coords2D"); | 118 SkString coords2D("coords2D"); |
117 if (0 != index) { | 119 if (0 != index) { |
118 coords2D.appendf("_%i", index); | 120 coords2D.appendf("_%i", index); |
119 } | 121 } |
120 this->codeAppendf("\tvec2 %s = %s.xy / %s.z;", | 122 this->codeAppendf("\tvec2 %s = %s.xy / %s.z;", |
121 coords2D.c_str(), coords[index].c_str(), coords[index].c_s
tr()); | 123 coords2D.c_str(), coords[index].c_str(), coords[index].c_s
tr()); |
122 return coords2D; | 124 return coords2D; |
123 } | 125 } |
124 | 126 |
125 const char* GrGLSLFragmentShaderBuilder::fragmentPosition() { | 127 const char* GrGLSLFragmentShaderBuilder::fragmentPosition() { |
126 fHasReadFragmentPosition = true; | 128 SkDEBUGCODE(fUsedBuiltInState |= GrProcessor::kFragmentPosition_BuiltInState
;) |
127 | 129 |
128 const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps(); | 130 const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps(); |
129 // We only declare "gl_FragCoord" when we're in the case where we want to us
e layout qualifiers | 131 // We only declare "gl_FragCoord" when we're in the case where we want to us
e layout qualifiers |
130 // to reverse y. Otherwise it isn't necessary and whether the "in" qualifier
appears in the | 132 // to reverse y. Otherwise it isn't necessary and whether the "in" qualifier
appears in the |
131 // declaration varies in earlier GLSL specs. So it is simpler to omit it. | 133 // declaration varies in earlier GLSL specs. So it is simpler to omit it. |
132 if (fTopLeftFragPosRead) { | 134 if (fTopLeftFragPosRead) { |
133 fSetupFragPosition = true; | 135 fSetupFragPosition = true; |
134 return "gl_FragCoord"; | 136 return "gl_FragCoord"; |
135 } else if (const char* extension = glslCaps->fragCoordConventionsExtensionSt
ring()) { | 137 } else if (const char* extension = glslCaps->fragCoordConventionsExtensionSt
ring()) { |
136 if (!fSetupFragPosition) { | 138 if (!fSetupFragPosition) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 // Redeclare gl_SampleMask with layout(override_coverage) if we haven't
already. | 207 // Redeclare gl_SampleMask with layout(override_coverage) if we haven't
already. |
206 fOutputs.push_back().set(kInt_GrSLType, GrShaderVar::kOut_TypeModifier, | 208 fOutputs.push_back().set(kInt_GrSLType, GrShaderVar::kOut_TypeModifier, |
207 "gl_SampleMask", 1, kHigh_GrSLPrecision, | 209 "gl_SampleMask", 1, kHigh_GrSLPrecision, |
208 "override_coverage"); | 210 "override_coverage"); |
209 } | 211 } |
210 this->codeAppendf("gl_SampleMask[0] = %s;", mask); | 212 this->codeAppendf("gl_SampleMask[0] = %s;", mask); |
211 fHasInitializedSampleMask = true; | 213 fHasInitializedSampleMask = true; |
212 } | 214 } |
213 | 215 |
214 const char* GrGLSLFragmentShaderBuilder::dstColor() { | 216 const char* GrGLSLFragmentShaderBuilder::dstColor() { |
215 fHasReadDstColor = true; | 217 SkDEBUGCODE(fHasReadDstColor = true;) |
216 | 218 |
217 const char* override = fProgramBuilder->primitiveProcessor().getDestColorOve
rride(); | 219 const char* override = fProgramBuilder->primitiveProcessor().getDestColorOve
rride(); |
218 if (override != nullptr) { | 220 if (override != nullptr) { |
219 return override; | 221 return override; |
220 } | 222 } |
221 | 223 |
222 const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps(); | 224 const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps(); |
223 if (glslCaps->fbFetchSupport()) { | 225 if (glslCaps->fbFetchSupport()) { |
224 this->addFeature(1 << kFramebufferFetch_GLSLPrivateFeature, | 226 this->addFeature(1 << kFramebufferFetch_GLSLPrivateFeature, |
225 glslCaps->fbFetchExtensionString()); | 227 glslCaps->fbFetchExtensionString()); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 319 } |
318 | 320 |
319 void GrGLSLFragmentShaderBuilder::onAfterChildProcEmitCode() { | 321 void GrGLSLFragmentShaderBuilder::onAfterChildProcEmitCode() { |
320 SkASSERT(fSubstageIndices.count() >= 2); | 322 SkASSERT(fSubstageIndices.count() >= 2); |
321 fSubstageIndices.pop_back(); | 323 fSubstageIndices.pop_back(); |
322 fSubstageIndices.back()++; | 324 fSubstageIndices.back()++; |
323 int removeAt = fMangleString.findLastOf('_'); | 325 int removeAt = fMangleString.findLastOf('_'); |
324 fMangleString.remove(removeAt, fMangleString.size() - removeAt); | 326 fMangleString.remove(removeAt, fMangleString.size() - removeAt); |
325 } | 327 } |
326 | 328 |
OLD | NEW |