| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "glsl/GrGLSLProgramBuilder.h" | 8 #include "glsl/GrGLSLProgramBuilder.h" |
| 9 | 9 |
| 10 #include "GrPipeline.h" | 10 #include "GrPipeline.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 // Enclose custom code in a block to avoid namespace conflicts | 91 // Enclose custom code in a block to avoid namespace conflicts |
| 92 SkString openBrace; | 92 SkString openBrace; |
| 93 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, proc.name()); | 93 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, proc.name()); |
| 94 fFS.codeAppend(openBrace.c_str()); | 94 fFS.codeAppend(openBrace.c_str()); |
| 95 fVS.codeAppendf("// Primitive Processor %s\n", proc.name()); | 95 fVS.codeAppendf("// Primitive Processor %s\n", proc.name()); |
| 96 | 96 |
| 97 SkASSERT(!fGeometryProcessor); | 97 SkASSERT(!fGeometryProcessor); |
| 98 fGeometryProcessor = proc.createGLSLInstance(*this->glslCaps()); | 98 fGeometryProcessor = proc.createGLSLInstance(*this->glslCaps()); |
| 99 | 99 |
| 100 SkSTArray<4, GrGLSLTextureSampler> samplers(proc.numTextures()); | 100 SkSTArray<4, GrGLSLSampler> texSamplers(proc.numTextures()); |
| 101 this->emitSamplers(proc, &samplers); | 101 this->emitSamplers(proc, &texSamplers); |
| 102 | 102 |
| 103 GrGLSLGeometryProcessor::EmitArgs args(&fVS, | 103 GrGLSLGeometryProcessor::EmitArgs args(&fVS, |
| 104 &fFS, | 104 &fFS, |
| 105 this->varyingHandler(), | 105 this->varyingHandler(), |
| 106 this->uniformHandler(), | 106 this->uniformHandler(), |
| 107 this->glslCaps(), | 107 this->glslCaps(), |
| 108 proc, | 108 proc, |
| 109 outputColor->c_str(), | 109 outputColor->c_str(), |
| 110 outputCoverage->c_str(), | 110 outputCoverage->c_str(), |
| 111 samplers, | 111 texSamplers, |
| 112 fCoordTransforms, | 112 fCoordTransforms, |
| 113 &fOutCoords); | 113 &fOutCoords); |
| 114 fGeometryProcessor->emitCode(args); | 114 fGeometryProcessor->emitCode(args); |
| 115 | 115 |
| 116 // We have to check that effects and the code they emit are consistent, ie i
f an effect | 116 // We have to check that effects and the code they emit are consistent, ie i
f an effect |
| 117 // asks for dst color, then the emit code needs to follow suit | 117 // asks for dst color, then the emit code needs to follow suit |
| 118 SkDEBUGCODE(verify(proc);) | 118 SkDEBUGCODE(verify(proc);) |
| 119 | 119 |
| 120 fFS.codeAppend("}"); | 120 fFS.codeAppend("}"); |
| 121 } | 121 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 141 AutoStageAdvance adv(this); | 141 AutoStageAdvance adv(this); |
| 142 this->nameExpression(output, "output"); | 142 this->nameExpression(output, "output"); |
| 143 | 143 |
| 144 // Enclose custom code in a block to avoid namespace conflicts | 144 // Enclose custom code in a block to avoid namespace conflicts |
| 145 SkString openBrace; | 145 SkString openBrace; |
| 146 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, fp.name()); | 146 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, fp.name()); |
| 147 fFS.codeAppend(openBrace.c_str()); | 147 fFS.codeAppend(openBrace.c_str()); |
| 148 | 148 |
| 149 GrGLSLFragmentProcessor* fragProc = fp.createGLSLInstance(); | 149 GrGLSLFragmentProcessor* fragProc = fp.createGLSLInstance(); |
| 150 | 150 |
| 151 SkSTArray<4, GrGLSLTextureSampler> samplers(fp.numTextures()); | 151 SkSTArray<4, GrGLSLSampler> texSamplers(fp.numTextures()); |
| 152 this->emitSamplers(fp, &samplers); | 152 this->emitSamplers(fp, &texSamplers); |
| 153 | 153 |
| 154 GrGLSLFragmentProcessor::EmitArgs args(&fFS, | 154 GrGLSLFragmentProcessor::EmitArgs args(&fFS, |
| 155 this->uniformHandler(), | 155 this->uniformHandler(), |
| 156 this->glslCaps(), | 156 this->glslCaps(), |
| 157 fp, | 157 fp, |
| 158 output->c_str(), | 158 output->c_str(), |
| 159 input.isOnes() ? nullptr : input.c_st
r(), | 159 input.isOnes() ? nullptr : input.c_st
r(), |
| 160 fOutCoords[index], | 160 fOutCoords[index], |
| 161 samplers); | 161 texSamplers); |
| 162 fragProc->emitCode(args); | 162 fragProc->emitCode(args); |
| 163 | 163 |
| 164 // We have to check that effects and the code they emit are consistent, ie i
f an effect | 164 // We have to check that effects and the code they emit are consistent, ie i
f an effect |
| 165 // asks for dst color, then the emit code needs to follow suit | 165 // asks for dst color, then the emit code needs to follow suit |
| 166 SkDEBUGCODE(verify(fp);) | 166 SkDEBUGCODE(verify(fp);) |
| 167 fFragmentProcessors.push_back(fragProc); | 167 fFragmentProcessors.push_back(fragProc); |
| 168 | 168 |
| 169 fFS.codeAppend("}"); | 169 fFS.codeAppend("}"); |
| 170 } | 170 } |
| 171 | 171 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 186 } | 186 } |
| 187 | 187 |
| 188 if (this->glslCaps()->mustDeclareFragmentShaderOutput()) { | 188 if (this->glslCaps()->mustDeclareFragmentShaderOutput()) { |
| 189 fFS.enableCustomOutput(); | 189 fFS.enableCustomOutput(); |
| 190 } | 190 } |
| 191 | 191 |
| 192 SkString openBrace; | 192 SkString openBrace; |
| 193 openBrace.printf("{ // Xfer Processor: %s\n", xp.name()); | 193 openBrace.printf("{ // Xfer Processor: %s\n", xp.name()); |
| 194 fFS.codeAppend(openBrace.c_str()); | 194 fFS.codeAppend(openBrace.c_str()); |
| 195 | 195 |
| 196 SkSTArray<4, GrGLSLTextureSampler> samplers(xp.numTextures()); | 196 SkSTArray<4, GrGLSLSampler> texSamplers(xp.numTextures()); |
| 197 this->emitSamplers(xp, &samplers); | 197 this->emitSamplers(xp, &texSamplers); |
| 198 | 198 |
| 199 bool usePLSDstRead = (plsState == GrPixelLocalStorageState::kFinish_GrPixelL
ocalStorageState); | 199 bool usePLSDstRead = (plsState == GrPixelLocalStorageState::kFinish_GrPixelL
ocalStorageState); |
| 200 GrGLSLXferProcessor::EmitArgs args(&fFS, | 200 GrGLSLXferProcessor::EmitArgs args(&fFS, |
| 201 this->uniformHandler(), | 201 this->uniformHandler(), |
| 202 this->glslCaps(), | 202 this->glslCaps(), |
| 203 xp, colorIn.c_str(), | 203 xp, colorIn.c_str(), |
| 204 ignoresCoverage ? nullptr : coverageIn.c_
str(), | 204 ignoresCoverage ? nullptr : coverageIn.c_
str(), |
| 205 fFS.getPrimaryColorOutputName(), | 205 fFS.getPrimaryColorOutputName(), |
| 206 fFS.getSecondaryColorOutputName(), | 206 fFS.getSecondaryColorOutputName(), |
| 207 samplers, | 207 texSamplers, |
| 208 usePLSDstRead); | 208 usePLSDstRead); |
| 209 fXferProcessor->emitCode(args); | 209 fXferProcessor->emitCode(args); |
| 210 | 210 |
| 211 // We have to check that effects and the code they emit are consistent, ie i
f an effect | 211 // We have to check that effects and the code they emit are consistent, ie i
f an effect |
| 212 // asks for dst color, then the emit code needs to follow suit | 212 // asks for dst color, then the emit code needs to follow suit |
| 213 SkDEBUGCODE(verify(xp);) | 213 SkDEBUGCODE(verify(xp);) |
| 214 fFS.codeAppend("}"); | 214 fFS.codeAppend("}"); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void GrGLSLProgramBuilder::emitSamplers(const GrProcessor& processor, | 217 void GrGLSLProgramBuilder::emitSamplers(const GrProcessor& processor, |
| 218 GrGLSLTextureSampler::TextureSamplerArra
y* outSamplers) { | 218 GrGLSLSampler::SamplerArray* outTexSampl
ers) { |
| 219 int numTextures = processor.numTextures(); | 219 int numTextures = processor.numTextures(); |
| 220 UniformHandle* localSamplerUniforms = fSamplerUniforms.push_back_n(numTextur
es); | 220 UniformHandle* localSamplerUniforms = fSamplerUniforms.push_back_n(numTextur
es); |
| 221 SkString name; | 221 SkString name; |
| 222 for (int t = 0; t < numTextures; ++t) { | 222 for (int t = 0; t < numTextures; ++t) { |
| 223 const GrTextureAccess& access = processor.textureAccess(t); | 223 const GrTextureAccess& access = processor.textureAccess(t); |
| 224 GrShaderFlags visibility = access.getVisibility(); | 224 GrShaderFlags visibility = access.getVisibility(); |
| 225 if (visibility & kVertex_GrShaderFlag) { | 225 if (visibility & kVertex_GrShaderFlag) { |
| 226 ++fNumVertexSamplers; | 226 ++fNumVertexSamplers; |
| 227 } | 227 } |
| 228 if (visibility & kGeometry_GrShaderFlag) { | 228 if (visibility & kGeometry_GrShaderFlag) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 241 1 << GrGLSLShaderBuilder::kExternalTexture_GLSLPriv
ateFeature, | 241 1 << GrGLSLShaderBuilder::kExternalTexture_GLSLPriv
ateFeature, |
| 242 externalFeatureString); | 242 externalFeatureString); |
| 243 } | 243 } |
| 244 GrSLPrecision precision = this->glslCaps()->samplerPrecision(access.getT
exture()->config(), | 244 GrSLPrecision precision = this->glslCaps()->samplerPrecision(access.getT
exture()->config(), |
| 245 visibility)
; | 245 visibility)
; |
| 246 name.printf("Sampler%d", t); | 246 name.printf("Sampler%d", t); |
| 247 localSamplerUniforms[t] = this->uniformHandler()->addUniform(visibility, | 247 localSamplerUniforms[t] = this->uniformHandler()->addUniform(visibility, |
| 248 samplerType
, | 248 samplerType
, |
| 249 precision, | 249 precision, |
| 250 name.c_str(
)); | 250 name.c_str(
)); |
| 251 outSamplers->emplace_back(localSamplerUniforms[t], access); | 251 outTexSamplers->emplace_back(localSamplerUniforms[t], access.getTexture(
)->config()); |
| 252 } | 252 } |
| 253 } | 253 } |
| 254 | 254 |
| 255 void GrGLSLProgramBuilder::emitFSOutputSwizzle(bool hasSecondaryOutput) { | 255 void GrGLSLProgramBuilder::emitFSOutputSwizzle(bool hasSecondaryOutput) { |
| 256 // Swizzle the fragment shader outputs if necessary. | 256 // Swizzle the fragment shader outputs if necessary. |
| 257 GrSwizzle swizzle; | 257 GrSwizzle swizzle; |
| 258 swizzle.setFromKey(this->desc().header().fOutputSwizzle); | 258 swizzle.setFromKey(this->desc().header().fOutputSwizzle); |
| 259 if (swizzle != GrSwizzle::RGBA()) { | 259 if (swizzle != GrSwizzle::RGBA()) { |
| 260 fFS.codeAppendf("%s = %s.%s;", fFS.getPrimaryColorOutputName(), | 260 fFS.codeAppendf("%s = %s.%s;", fFS.getPrimaryColorOutputName(), |
| 261 fFS.getPrimaryColorOutputName(), | 261 fFS.getPrimaryColorOutputName(), |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 delete fFragmentProcessors[i]; | 365 delete fFragmentProcessors[i]; |
| 366 } | 366 } |
| 367 } | 367 } |
| 368 | 368 |
| 369 void GrGLSLProgramBuilder::finalizeShaders() { | 369 void GrGLSLProgramBuilder::finalizeShaders() { |
| 370 this->varyingHandler()->finalize(); | 370 this->varyingHandler()->finalize(); |
| 371 fVS.finalize(kVertex_GrShaderFlag); | 371 fVS.finalize(kVertex_GrShaderFlag); |
| 372 fFS.finalize(kFragment_GrShaderFlag); | 372 fFS.finalize(kFragment_GrShaderFlag); |
| 373 | 373 |
| 374 } | 374 } |
| OLD | NEW |