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" | |
11 #include "glsl/GrGLSL.h" | 10 #include "glsl/GrGLSL.h" |
12 #include "glsl/GrGLSLCaps.h" | 11 #include "glsl/GrGLSLCaps.h" |
13 #include "glsl/GrGLSLProgramBuilder.h" | 12 #include "glsl/GrGLSLProgramBuilder.h" |
14 #include "glsl/GrGLSLUniformHandler.h" | 13 #include "glsl/GrGLSLUniformHandler.h" |
15 #include "glsl/GrGLSLVarying.h" | 14 #include "glsl/GrGLSLVarying.h" |
16 | 15 |
17 const char* GrGLSLFragmentShaderBuilder::kDstTextureColorName = "_dstColor"; | 16 const char* GrGLSLFragmentShaderBuilder::kDstTextureColorName = "_dstColor"; |
18 | 17 |
19 static const char* specific_layout_qualifier_name(GrBlendEquation equation) { | 18 static const char* specific_layout_qualifier_name(GrBlendEquation equation) { |
20 SkASSERT(GrBlendEquationIsAdvanced(equation)); | 19 SkASSERT(GrBlendEquationIsAdvanced(equation)); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 case kStandardDerivatives_GLSLFeature: { | 80 case kStandardDerivatives_GLSLFeature: { |
82 if (!fProgramBuilder->glslCaps()->shaderDerivativeSupport()) { | 81 if (!fProgramBuilder->glslCaps()->shaderDerivativeSupport()) { |
83 return false; | 82 return false; |
84 } | 83 } |
85 const char* extension = fProgramBuilder->glslCaps()->shaderDerivativ
eExtensionString(); | 84 const char* extension = fProgramBuilder->glslCaps()->shaderDerivativ
eExtensionString(); |
86 if (extension) { | 85 if (extension) { |
87 this->addFeature(1 << kStandardDerivatives_GLSLFeature, extensio
n); | 86 this->addFeature(1 << kStandardDerivatives_GLSLFeature, extensio
n); |
88 } | 87 } |
89 return true; | 88 return true; |
90 } | 89 } |
91 case kPixelLocalStorage_GLSLFeature: { | |
92 if (fProgramBuilder->glslCaps()->pixelLocalStorageSize() <= 0) { | |
93 return false; | |
94 } | |
95 this->addFeature(1 << kPixelLocalStorage_GLSLFeature, | |
96 "GL_EXT_shader_pixel_local_storage"); | |
97 return true; | |
98 } | |
99 default: | 90 default: |
100 SkFAIL("Unexpected GLSLFeature requested."); | 91 SkFAIL("Unexpected GLSLFeature requested."); |
101 return false; | 92 return false; |
102 } | 93 } |
103 } | 94 } |
104 | 95 |
105 SkString GrGLSLFragmentShaderBuilder::ensureFSCoords2D(const GrGLSLTransformedCo
ordsArray& coords, | 96 SkString GrGLSLFragmentShaderBuilder::ensureFSCoords2D(const GrGLSLTransformedCo
ordsArray& coords, |
106 int index) { | 97 int index) { |
107 if (kVec3f_GrSLType != coords[index].getType()) { | 98 if (kVec3f_GrSLType != coords[index].getType()) { |
108 SkASSERT(kVec2f_GrSLType == coords[index].getType()); | 99 SkASSERT(kVec2f_GrSLType == coords[index].getType()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 fSetupFragPosition = true; | 153 fSetupFragPosition = true; |
163 } | 154 } |
164 SkASSERT(fProgramBuilder->fUniformHandles.fRTHeightUni.isValid()); | 155 SkASSERT(fProgramBuilder->fUniformHandles.fRTHeightUni.isValid()); |
165 return kCoordName; | 156 return kCoordName; |
166 } | 157 } |
167 } | 158 } |
168 | 159 |
169 const char* GrGLSLFragmentShaderBuilder::dstColor() { | 160 const char* GrGLSLFragmentShaderBuilder::dstColor() { |
170 fHasReadDstColor = true; | 161 fHasReadDstColor = true; |
171 | 162 |
172 const char* override = fProgramBuilder->primitiveProcessor().getDestColorOve
rride(); | |
173 if (override != nullptr) { | |
174 return override; | |
175 } | |
176 | |
177 const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps(); | 163 const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps(); |
178 if (glslCaps->fbFetchSupport()) { | 164 if (glslCaps->fbFetchSupport()) { |
179 this->addFeature(1 << (GrGLSLFragmentShaderBuilder::kLastGLSLPrivateFeat
ure + 1), | 165 this->addFeature(1 << (GrGLSLFragmentShaderBuilder::kLastGLSLPrivateFeat
ure + 1), |
180 glslCaps->fbFetchExtensionString()); | 166 glslCaps->fbFetchExtensionString()); |
181 | 167 |
182 // Some versions of this extension string require declaring custom color
output on ES 3.0+ | 168 // Some versions of this extension string require declaring custom color
output on ES 3.0+ |
183 const char* fbFetchColorName = glslCaps->fbFetchColorName(); | 169 const char* fbFetchColorName = glslCaps->fbFetchColorName(); |
184 if (glslCaps->fbFetchNeedsCustomOutput()) { | 170 if (glslCaps->fbFetchNeedsCustomOutput()) { |
185 this->enableCustomOutput(); | 171 this->enableCustomOutput(); |
186 fOutputs[fCustomColorOutputIndex].setTypeModifier(GrShaderVar::kInOu
t_TypeModifier); | 172 fOutputs[fCustomColorOutputIndex].setTypeModifier(GrShaderVar::kInOu
t_TypeModifier); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 if (caps.mustDeclareFragmentShaderOutput()) { | 220 if (caps.mustDeclareFragmentShaderOutput()) { |
235 fOutputs.push_back().set(kVec4f_GrSLType, GrGLSLShaderVar::kOut_TypeModi
fier, | 221 fOutputs.push_back().set(kVec4f_GrSLType, GrGLSLShaderVar::kOut_TypeModi
fier, |
236 DeclaredSecondaryColorOutputName()); | 222 DeclaredSecondaryColorOutputName()); |
237 } | 223 } |
238 } | 224 } |
239 | 225 |
240 const char* GrGLSLFragmentShaderBuilder::getPrimaryColorOutputName() const { | 226 const char* GrGLSLFragmentShaderBuilder::getPrimaryColorOutputName() const { |
241 return fHasCustomColorOutput ? DeclaredColorOutputName() : "gl_FragColor"; | 227 return fHasCustomColorOutput ? DeclaredColorOutputName() : "gl_FragColor"; |
242 } | 228 } |
243 | 229 |
244 void GrGLSLFragmentBuilder::declAppendf(const char* fmt, ...) { | |
245 va_list argp; | |
246 va_start(argp, fmt); | |
247 inputs().appendVAList(fmt, argp); | |
248 va_end(argp); | |
249 } | |
250 | |
251 const char* GrGLSLFragmentShaderBuilder::getSecondaryColorOutputName() const { | 230 const char* GrGLSLFragmentShaderBuilder::getSecondaryColorOutputName() const { |
252 const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); | 231 const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); |
253 return caps.mustDeclareFragmentShaderOutput() ? DeclaredSecondaryColorOutput
Name() | 232 return caps.mustDeclareFragmentShaderOutput() ? DeclaredSecondaryColorOutput
Name() |
254 : "gl_SecondaryFragColorEXT"; | 233 : "gl_SecondaryFragColorEXT"; |
255 } | 234 } |
256 | 235 |
257 void GrGLSLFragmentShaderBuilder::onFinalize() { | 236 void GrGLSLFragmentShaderBuilder::onFinalize() { |
258 fProgramBuilder->varyingHandler()->getFragDecls(&this->inputs(), &this->outp
uts()); | 237 fProgramBuilder->varyingHandler()->getFragDecls(&this->inputs(), &this->outp
uts()); |
259 GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, | 238 GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, |
260 *fProgramBuilder->glslCaps(), | 239 *fProgramBuilder->glslCaps(), |
261 &this->precisionQualifier()); | 240 &this->precisionQualifier()); |
262 } | 241 } |
263 | 242 |
264 void GrGLSLFragmentBuilder::onBeforeChildProcEmitCode() { | 243 void GrGLSLFragmentBuilder::onBeforeChildProcEmitCode() { |
265 SkASSERT(fSubstageIndices.count() >= 1); | 244 SkASSERT(fSubstageIndices.count() >= 1); |
266 fSubstageIndices.push_back(0); | 245 fSubstageIndices.push_back(0); |
267 // second-to-last value in the fSubstageIndices stack is the index of the ch
ild proc | 246 // second-to-last value in the fSubstageIndices stack is the index of the ch
ild proc |
268 // at that level which is currently emitting code. | 247 // at that level which is currently emitting code. |
269 fMangleString.appendf("_c%d", fSubstageIndices[fSubstageIndices.count() - 2]
); | 248 fMangleString.appendf("_c%d", fSubstageIndices[fSubstageIndices.count() - 2]
); |
270 } | 249 } |
271 | 250 |
272 void GrGLSLFragmentBuilder::onAfterChildProcEmitCode() { | 251 void GrGLSLFragmentBuilder::onAfterChildProcEmitCode() { |
273 SkASSERT(fSubstageIndices.count() >= 2); | 252 SkASSERT(fSubstageIndices.count() >= 2); |
274 fSubstageIndices.pop_back(); | 253 fSubstageIndices.pop_back(); |
275 fSubstageIndices.back()++; | 254 fSubstageIndices.back()++; |
276 int removeAt = fMangleString.findLastOf('_'); | 255 int removeAt = fMangleString.findLastOf('_'); |
277 fMangleString.remove(removeAt, fMangleString.size() - removeAt); | 256 fMangleString.remove(removeAt, fMangleString.size() - removeAt); |
278 } | 257 } |
279 | 258 |
OLD | NEW |