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 fUsedProcessorFeatures = GrProcessor::kNone_RequiredFeatures; |
| 81 fHasReadDstColor = false; |
| 82 #endif |
| 83 } |
| 84 |
| 85 bool GrGLSLFragmentShaderBuilder::hasFragmentPosition() const { |
| 86 return 0 != fProgramBuilder->header().fFragPosKey; |
81 } | 87 } |
82 | 88 |
83 bool GrGLSLFragmentShaderBuilder::enableFeature(GLSLFeature feature) { | 89 bool GrGLSLFragmentShaderBuilder::enableFeature(GLSLFeature feature) { |
84 switch (feature) { | 90 switch (feature) { |
85 case kStandardDerivatives_GLSLFeature: { | 91 case kStandardDerivatives_GLSLFeature: { |
86 if (!fProgramBuilder->glslCaps()->shaderDerivativeSupport()) { | 92 if (!fProgramBuilder->glslCaps()->shaderDerivativeSupport()) { |
87 return false; | 93 return false; |
88 } | 94 } |
89 const char* extension = fProgramBuilder->glslCaps()->shaderDerivativ
eExtensionString(); | 95 const char* extension = fProgramBuilder->glslCaps()->shaderDerivativ
eExtensionString(); |
90 if (extension) { | 96 if (extension) { |
(...skipping 25 matching lines...) Expand all Loading... |
116 SkString coords2D("coords2D"); | 122 SkString coords2D("coords2D"); |
117 if (0 != index) { | 123 if (0 != index) { |
118 coords2D.appendf("_%i", index); | 124 coords2D.appendf("_%i", index); |
119 } | 125 } |
120 this->codeAppendf("\tvec2 %s = %s.xy / %s.z;", | 126 this->codeAppendf("\tvec2 %s = %s.xy / %s.z;", |
121 coords2D.c_str(), coords[index].c_str(), coords[index].c_s
tr()); | 127 coords2D.c_str(), coords[index].c_str(), coords[index].c_s
tr()); |
122 return coords2D; | 128 return coords2D; |
123 } | 129 } |
124 | 130 |
125 const char* GrGLSLFragmentShaderBuilder::fragmentPosition() { | 131 const char* GrGLSLFragmentShaderBuilder::fragmentPosition() { |
126 fHasReadFragmentPosition = true; | 132 SkASSERT(this->hasFragmentPosition()); |
| 133 SkDEBUGCODE(fUsedProcessorFeatures |= GrProcessor::kFragmentPosition_Require
dFeature;) |
127 | 134 |
128 const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps(); | 135 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 | 136 // 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 | 137 // 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. | 138 // declaration varies in earlier GLSL specs. So it is simpler to omit it. |
132 if (fTopLeftFragPosRead) { | 139 if (fTopLeftFragPosRead) { |
133 fSetupFragPosition = true; | 140 fSetupFragPosition = true; |
134 return "gl_FragCoord"; | 141 return "gl_FragCoord"; |
135 } else if (const char* extension = glslCaps->fragCoordConventionsExtensionSt
ring()) { | 142 } else if (const char* extension = glslCaps->fragCoordConventionsExtensionSt
ring()) { |
136 if (!fSetupFragPosition) { | 143 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. | 212 // Redeclare gl_SampleMask with layout(override_coverage) if we haven't
already. |
206 fOutputs.push_back().set(kInt_GrSLType, GrShaderVar::kOut_TypeModifier, | 213 fOutputs.push_back().set(kInt_GrSLType, GrShaderVar::kOut_TypeModifier, |
207 "gl_SampleMask", 1, kHigh_GrSLPrecision, | 214 "gl_SampleMask", 1, kHigh_GrSLPrecision, |
208 "override_coverage"); | 215 "override_coverage"); |
209 } | 216 } |
210 this->codeAppendf("gl_SampleMask[0] = %s;", mask); | 217 this->codeAppendf("gl_SampleMask[0] = %s;", mask); |
211 fHasInitializedSampleMask = true; | 218 fHasInitializedSampleMask = true; |
212 } | 219 } |
213 | 220 |
214 const char* GrGLSLFragmentShaderBuilder::dstColor() { | 221 const char* GrGLSLFragmentShaderBuilder::dstColor() { |
215 fHasReadDstColor = true; | 222 SkDEBUGCODE(fHasReadDstColor = true;) |
216 | 223 |
217 const char* override = fProgramBuilder->primitiveProcessor().getDestColorOve
rride(); | 224 const char* override = fProgramBuilder->primitiveProcessor().getDestColorOve
rride(); |
218 if (override != nullptr) { | 225 if (override != nullptr) { |
219 return override; | 226 return override; |
220 } | 227 } |
221 | 228 |
222 const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps(); | 229 const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps(); |
223 if (glslCaps->fbFetchSupport()) { | 230 if (glslCaps->fbFetchSupport()) { |
224 this->addFeature(1 << kFramebufferFetch_GLSLPrivateFeature, | 231 this->addFeature(1 << kFramebufferFetch_GLSLPrivateFeature, |
225 glslCaps->fbFetchExtensionString()); | 232 glslCaps->fbFetchExtensionString()); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 324 } |
318 | 325 |
319 void GrGLSLFragmentShaderBuilder::onAfterChildProcEmitCode() { | 326 void GrGLSLFragmentShaderBuilder::onAfterChildProcEmitCode() { |
320 SkASSERT(fSubstageIndices.count() >= 2); | 327 SkASSERT(fSubstageIndices.count() >= 2); |
321 fSubstageIndices.pop_back(); | 328 fSubstageIndices.pop_back(); |
322 fSubstageIndices.back()++; | 329 fSubstageIndices.back()++; |
323 int removeAt = fMangleString.findLastOf('_'); | 330 int removeAt = fMangleString.findLastOf('_'); |
324 fMangleString.remove(removeAt, fMangleString.size() - removeAt); | 331 fMangleString.remove(removeAt, fMangleString.size() - removeAt); |
325 } | 332 } |
326 | 333 |
OLD | NEW |