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