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 , fHasReadDstColor(false) | 78 , fHasReadDstColor(false) |
78 , fHasReadFragmentPosition(false) { | 79 , fHasReadFragmentPosition(false) { |
79 fSubstageIndices.push_back(0); | 80 fSubstageIndices.push_back(0); |
80 } | 81 } |
81 | 82 |
82 bool GrGLSLFragmentShaderBuilder::enableFeature(GLSLFeature feature) { | 83 bool GrGLSLFragmentShaderBuilder::enableFeature(GLSLFeature feature) { |
83 switch (feature) { | 84 switch (feature) { |
84 case kStandardDerivatives_GLSLFeature: { | 85 case kStandardDerivatives_GLSLFeature: { |
85 if (!fProgramBuilder->glslCaps()->shaderDerivativeSupport()) { | 86 if (!fProgramBuilder->glslCaps()->shaderDerivativeSupport()) { |
86 return false; | 87 return false; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 this->codePrependf("\t%svec4 %s = vec4(%s.x, %s - %s.y, 1.0, 1.0);\n
", | 163 this->codePrependf("\t%svec4 %s = vec4(%s.x, %s - %s.y, 1.0, 1.0);\n
", |
163 precision, kCoordName, kTempName, rtHeightName, k
TempName); | 164 precision, kCoordName, kTempName, rtHeightName, k
TempName); |
164 this->codePrependf("%svec2 %s = gl_FragCoord.xy;", precision, kTempN
ame); | 165 this->codePrependf("%svec2 %s = gl_FragCoord.xy;", precision, kTempN
ame); |
165 fSetupFragPosition = true; | 166 fSetupFragPosition = true; |
166 } | 167 } |
167 SkASSERT(fProgramBuilder->fUniformHandles.fRTHeightUni.isValid()); | 168 SkASSERT(fProgramBuilder->fUniformHandles.fRTHeightUni.isValid()); |
168 return kCoordName; | 169 return kCoordName; |
169 } | 170 } |
170 } | 171 } |
171 | 172 |
| 173 void GrGLSLFragmentShaderBuilder::maskSampleCoverage(const char* mask, bool inve
rt) { |
| 174 const GrGLSLCaps& glslCaps = *fProgramBuilder->glslCaps(); |
| 175 if (!glslCaps.sampleVariablesSupport()) { |
| 176 SkDEBUGFAIL("Attempted to mask sample coverage without support."); |
| 177 return; |
| 178 } |
| 179 if (const char* extension = glslCaps.sampleVariablesExtensionString()) { |
| 180 this->addFeature(1 << kSampleVariables_GLSLPrivateFeature, extension); |
| 181 } |
| 182 if (!fHasInitializedSampleMask) { |
| 183 this->codePrependf("gl_SampleMask[0] = -1;"); |
| 184 fHasInitializedSampleMask = true; |
| 185 } |
| 186 if (invert) { |
| 187 this->codeAppendf("gl_SampleMask[0] &= ~(%s);", mask); |
| 188 } else { |
| 189 this->codeAppendf("gl_SampleMask[0] &= %s;", mask); |
| 190 } |
| 191 } |
| 192 |
| 193 void GrGLSLFragmentShaderBuilder::overrideSampleCoverage(const char* mask) { |
| 194 const GrGLSLCaps& glslCaps = *fProgramBuilder->glslCaps(); |
| 195 if (!glslCaps.sampleMaskOverrideCoverageSupport()) { |
| 196 SkDEBUGFAIL("Attempted to override sample coverage without support."); |
| 197 return; |
| 198 } |
| 199 SkASSERT(glslCaps.sampleVariablesSupport()); |
| 200 if (const char* extension = glslCaps.sampleVariablesExtensionString()) { |
| 201 this->addFeature(1 << kSampleVariables_GLSLPrivateFeature, extension); |
| 202 } |
| 203 if (this->addFeature(1 << kSampleMaskOverrideCoverage_GLSLPrivateFeature, |
| 204 "GL_NV_sample_mask_override_coverage")) { |
| 205 // Redeclare gl_SampleMask with layout(override_coverage) if we haven't
already. |
| 206 fOutputs.push_back().set(kInt_GrSLType, GrShaderVar::kOut_TypeModifier, |
| 207 "gl_SampleMask", 1, kHigh_GrSLPrecision, |
| 208 "override_coverage"); |
| 209 } |
| 210 this->codeAppendf("gl_SampleMask[0] = %s;", mask); |
| 211 fHasInitializedSampleMask = true; |
| 212 } |
| 213 |
172 const char* GrGLSLFragmentShaderBuilder::dstColor() { | 214 const char* GrGLSLFragmentShaderBuilder::dstColor() { |
173 fHasReadDstColor = true; | 215 fHasReadDstColor = true; |
174 | 216 |
175 const char* override = fProgramBuilder->primitiveProcessor().getDestColorOve
rride(); | 217 const char* override = fProgramBuilder->primitiveProcessor().getDestColorOve
rride(); |
176 if (override != nullptr) { | 218 if (override != nullptr) { |
177 return override; | 219 return override; |
178 } | 220 } |
179 | 221 |
180 const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps(); | 222 const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps(); |
181 if (glslCaps->fbFetchSupport()) { | 223 if (glslCaps->fbFetchSupport()) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 } | 317 } |
276 | 318 |
277 void GrGLSLFragmentShaderBuilder::onAfterChildProcEmitCode() { | 319 void GrGLSLFragmentShaderBuilder::onAfterChildProcEmitCode() { |
278 SkASSERT(fSubstageIndices.count() >= 2); | 320 SkASSERT(fSubstageIndices.count() >= 2); |
279 fSubstageIndices.pop_back(); | 321 fSubstageIndices.pop_back(); |
280 fSubstageIndices.back()++; | 322 fSubstageIndices.back()++; |
281 int removeAt = fMangleString.findLastOf('_'); | 323 int removeAt = fMangleString.findLastOf('_'); |
282 fMangleString.remove(removeAt, fMangleString.size() - removeAt); | 324 fMangleString.remove(removeAt, fMangleString.size() - removeAt); |
283 } | 325 } |
284 | 326 |
OLD | NEW |