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, GrGLSLSampler> texSamplers(proc.numTextures()); | 100 SkSTArray<4, SamplerHandle> texSamplers(proc.numTextures()); |
101 SkSTArray<2, GrGLSLSampler> bufferSamplers(proc.numBuffers()); | 101 SkSTArray<2, SamplerHandle> bufferSamplers(proc.numBuffers()); |
102 this->emitSamplers(proc, &texSamplers, &bufferSamplers); | 102 this->emitSamplers(proc, &texSamplers, &bufferSamplers); |
103 | 103 |
104 GrGLSLGeometryProcessor::EmitArgs args(&fVS, | 104 GrGLSLGeometryProcessor::EmitArgs args(&fVS, |
105 &fFS, | 105 &fFS, |
106 this->varyingHandler(), | 106 this->varyingHandler(), |
107 this->uniformHandler(), | 107 this->uniformHandler(), |
108 this->glslCaps(), | 108 this->glslCaps(), |
109 proc, | 109 proc, |
110 outputColor->c_str(), | 110 outputColor->c_str(), |
111 outputCoverage->c_str(), | 111 outputCoverage->c_str(), |
112 texSamplers, | 112 texSamplers.begin(), |
113 bufferSamplers, | 113 bufferSamplers.begin(), |
114 fCoordTransforms, | 114 fCoordTransforms, |
115 &fOutCoords); | 115 &fOutCoords); |
116 fGeometryProcessor->emitCode(args); | 116 fGeometryProcessor->emitCode(args); |
117 | 117 |
118 // We have to check that effects and the code they emit are consistent, ie i
f an effect | 118 // We have to check that effects and the code they emit are consistent, ie i
f an effect |
119 // asks for dst color, then the emit code needs to follow suit | 119 // asks for dst color, then the emit code needs to follow suit |
120 SkDEBUGCODE(verify(proc);) | 120 SkDEBUGCODE(verify(proc);) |
121 | 121 |
122 fFS.codeAppend("}"); | 122 fFS.codeAppend("}"); |
123 } | 123 } |
(...skipping 19 matching lines...) Expand all Loading... |
143 AutoStageAdvance adv(this); | 143 AutoStageAdvance adv(this); |
144 this->nameExpression(output, "output"); | 144 this->nameExpression(output, "output"); |
145 | 145 |
146 // Enclose custom code in a block to avoid namespace conflicts | 146 // Enclose custom code in a block to avoid namespace conflicts |
147 SkString openBrace; | 147 SkString openBrace; |
148 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, fp.name()); | 148 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, fp.name()); |
149 fFS.codeAppend(openBrace.c_str()); | 149 fFS.codeAppend(openBrace.c_str()); |
150 | 150 |
151 GrGLSLFragmentProcessor* fragProc = fp.createGLSLInstance(); | 151 GrGLSLFragmentProcessor* fragProc = fp.createGLSLInstance(); |
152 | 152 |
153 SkSTArray<4, GrGLSLSampler> texSamplers(fp.numTextures()); | 153 SkSTArray<4, SamplerHandle> texSamplers(fp.numTextures()); |
154 SkSTArray<2, GrGLSLSampler> bufferSamplers(fp.numBuffers()); | 154 SkSTArray<2, SamplerHandle> bufferSamplers(fp.numBuffers()); |
155 this->emitSamplers(fp, &texSamplers, &bufferSamplers); | 155 this->emitSamplers(fp, &texSamplers, &bufferSamplers); |
156 | 156 |
157 GrGLSLFragmentProcessor::EmitArgs args(&fFS, | 157 GrGLSLFragmentProcessor::EmitArgs args(&fFS, |
158 this->uniformHandler(), | 158 this->uniformHandler(), |
159 this->glslCaps(), | 159 this->glslCaps(), |
160 fp, | 160 fp, |
161 output->c_str(), | 161 output->c_str(), |
162 input.isOnes() ? nullptr : input.c_st
r(), | 162 input.isOnes() ? nullptr : input.c_st
r(), |
163 fOutCoords[index], | 163 fOutCoords[index], |
164 texSamplers, | 164 texSamplers.begin(), |
165 bufferSamplers); | 165 bufferSamplers.begin()); |
166 fragProc->emitCode(args); | 166 fragProc->emitCode(args); |
167 | 167 |
168 // We have to check that effects and the code they emit are consistent, ie i
f an effect | 168 // We have to check that effects and the code they emit are consistent, ie i
f an effect |
169 // asks for dst color, then the emit code needs to follow suit | 169 // asks for dst color, then the emit code needs to follow suit |
170 SkDEBUGCODE(verify(fp);) | 170 SkDEBUGCODE(verify(fp);) |
171 fFragmentProcessors.push_back(fragProc); | 171 fFragmentProcessors.push_back(fragProc); |
172 | 172 |
173 fFS.codeAppend("}"); | 173 fFS.codeAppend("}"); |
174 } | 174 } |
175 | 175 |
(...skipping 14 matching lines...) Expand all Loading... |
190 } | 190 } |
191 | 191 |
192 if (this->glslCaps()->mustDeclareFragmentShaderOutput()) { | 192 if (this->glslCaps()->mustDeclareFragmentShaderOutput()) { |
193 fFS.enableCustomOutput(); | 193 fFS.enableCustomOutput(); |
194 } | 194 } |
195 | 195 |
196 SkString openBrace; | 196 SkString openBrace; |
197 openBrace.printf("{ // Xfer Processor: %s\n", xp.name()); | 197 openBrace.printf("{ // Xfer Processor: %s\n", xp.name()); |
198 fFS.codeAppend(openBrace.c_str()); | 198 fFS.codeAppend(openBrace.c_str()); |
199 | 199 |
200 SkSTArray<4, GrGLSLSampler> texSamplers(xp.numTextures()); | 200 SkSTArray<4, SamplerHandle> texSamplers(xp.numTextures()); |
201 SkSTArray<2, GrGLSLSampler> bufferSamplers(xp.numBuffers()); | 201 SkSTArray<2, SamplerHandle> bufferSamplers(xp.numBuffers()); |
202 this->emitSamplers(xp, &texSamplers, &bufferSamplers); | 202 this->emitSamplers(xp, &texSamplers, &bufferSamplers); |
203 | 203 |
204 bool usePLSDstRead = (plsState == GrPixelLocalStorageState::kFinish_GrPixelL
ocalStorageState); | 204 bool usePLSDstRead = (plsState == GrPixelLocalStorageState::kFinish_GrPixelL
ocalStorageState); |
205 GrGLSLXferProcessor::EmitArgs args(&fFS, | 205 GrGLSLXferProcessor::EmitArgs args(&fFS, |
206 this->uniformHandler(), | 206 this->uniformHandler(), |
207 this->glslCaps(), | 207 this->glslCaps(), |
208 xp, colorIn.c_str(), | 208 xp, colorIn.c_str(), |
209 ignoresCoverage ? nullptr : coverageIn.c_
str(), | 209 ignoresCoverage ? nullptr : coverageIn.c_
str(), |
210 fFS.getPrimaryColorOutputName(), | 210 fFS.getPrimaryColorOutputName(), |
211 fFS.getSecondaryColorOutputName(), | 211 fFS.getSecondaryColorOutputName(), |
212 texSamplers, | 212 texSamplers.begin(), |
213 bufferSamplers, | 213 bufferSamplers.begin(), |
214 usePLSDstRead); | 214 usePLSDstRead); |
215 fXferProcessor->emitCode(args); | 215 fXferProcessor->emitCode(args); |
216 | 216 |
217 // We have to check that effects and the code they emit are consistent, ie i
f an effect | 217 // We have to check that effects and the code they emit are consistent, ie i
f an effect |
218 // asks for dst color, then the emit code needs to follow suit | 218 // asks for dst color, then the emit code needs to follow suit |
219 SkDEBUGCODE(verify(xp);) | 219 SkDEBUGCODE(verify(xp);) |
220 fFS.codeAppend("}"); | 220 fFS.codeAppend("}"); |
221 } | 221 } |
222 | 222 |
223 void GrGLSLProgramBuilder::emitSamplers(const GrProcessor& processor, | 223 void GrGLSLProgramBuilder::emitSamplers(const GrProcessor& processor, |
224 GrGLSLSampler::SamplerArray* outTexSampl
ers, | 224 SkTArray<SamplerHandle>* outTexSamplers, |
225 GrGLSLSampler::SamplerArray* outBufferSa
mplers) { | 225 SkTArray<SamplerHandle>* outBufferSample
rs) { |
226 SkString name; | 226 SkString name; |
227 int numTextures = processor.numTextures(); | 227 int numTextures = processor.numTextures(); |
228 for (int t = 0; t < numTextures; ++t) { | 228 for (int t = 0; t < numTextures; ++t) { |
229 const GrTextureAccess& access = processor.textureAccess(t); | 229 const GrTextureAccess& access = processor.textureAccess(t); |
230 GrSLType samplerType = access.getTexture()->samplerType(); | 230 GrSLType samplerType = access.getTexture()->samplerType(); |
231 if (kSamplerExternal_GrSLType == samplerType) { | 231 if (kSamplerExternal_GrSLType == samplerType) { |
232 const char* externalFeatureString = this->glslCaps()->externalTextur
eExtensionString(); | 232 const char* externalFeatureString = this->glslCaps()->externalTextur
eExtensionString(); |
233 // We shouldn't ever create a GrGLTexture that requires external sam
pler type | 233 // We shouldn't ever create a GrGLTexture that requires external sam
pler type |
234 SkASSERT(externalFeatureString); | 234 SkASSERT(externalFeatureString); |
235 this->addFeature(access.getVisibility(), | 235 this->addFeature(access.getVisibility(), |
(...skipping 22 matching lines...) Expand all Loading... |
258 1 << GrGLSLShaderBuilder::kTexelBuffer_GLSLPrivateF
eature, | 258 1 << GrGLSLShaderBuilder::kTexelBuffer_GLSLPrivateF
eature, |
259 extension); | 259 extension); |
260 } | 260 } |
261 } | 261 } |
262 } | 262 } |
263 | 263 |
264 void GrGLSLProgramBuilder::emitSampler(GrSLType samplerType, | 264 void GrGLSLProgramBuilder::emitSampler(GrSLType samplerType, |
265 GrPixelConfig config, | 265 GrPixelConfig config, |
266 const char* name, | 266 const char* name, |
267 GrShaderFlags visibility, | 267 GrShaderFlags visibility, |
268 GrGLSLSampler::SamplerArray* outSamplers)
{ | 268 SkTArray<SamplerHandle>* outSamplers) { |
269 if (visibility & kVertex_GrShaderFlag) { | 269 if (visibility & kVertex_GrShaderFlag) { |
270 ++fNumVertexSamplers; | 270 ++fNumVertexSamplers; |
271 } | 271 } |
272 if (visibility & kGeometry_GrShaderFlag) { | 272 if (visibility & kGeometry_GrShaderFlag) { |
273 SkASSERT(this->primitiveProcessor().willUseGeoShader()); | 273 SkASSERT(this->primitiveProcessor().willUseGeoShader()); |
274 ++fNumGeometrySamplers; | 274 ++fNumGeometrySamplers; |
275 } | 275 } |
276 if (visibility & kFragment_GrShaderFlag) { | 276 if (visibility & kFragment_GrShaderFlag) { |
277 ++fNumFragmentSamplers; | 277 ++fNumFragmentSamplers; |
278 } | 278 } |
279 GrSLPrecision precision = this->glslCaps()->samplerPrecision(config, visibil
ity); | 279 GrSLPrecision precision = this->glslCaps()->samplerPrecision(config, visibil
ity); |
280 UniformHandle u = this->uniformHandler()->addUniform(visibility, samplerType
, precision, name); | 280 SamplerHandle handle = this->uniformHandler()->addSampler(visibility, |
281 fSamplerUniforms.push_back(u); | 281 config, |
282 outSamplers->emplace_back(u, config); | 282 samplerType, |
| 283 precision, |
| 284 name); |
| 285 outSamplers->emplace_back(handle); |
283 } | 286 } |
284 | 287 |
285 void GrGLSLProgramBuilder::emitFSOutputSwizzle(bool hasSecondaryOutput) { | 288 void GrGLSLProgramBuilder::emitFSOutputSwizzle(bool hasSecondaryOutput) { |
286 // Swizzle the fragment shader outputs if necessary. | 289 // Swizzle the fragment shader outputs if necessary. |
287 GrSwizzle swizzle; | 290 GrSwizzle swizzle; |
288 swizzle.setFromKey(this->desc().header().fOutputSwizzle); | 291 swizzle.setFromKey(this->desc().header().fOutputSwizzle); |
289 if (swizzle != GrSwizzle::RGBA()) { | 292 if (swizzle != GrSwizzle::RGBA()) { |
290 fFS.codeAppendf("%s = %s.%s;", fFS.getPrimaryColorOutputName(), | 293 fFS.codeAppendf("%s = %s.%s;", fFS.getPrimaryColorOutputName(), |
291 fFS.getPrimaryColorOutputName(), | 294 fFS.getPrimaryColorOutputName(), |
292 swizzle.c_str()); | 295 swizzle.c_str()); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 delete fFragmentProcessors[i]; | 398 delete fFragmentProcessors[i]; |
396 } | 399 } |
397 } | 400 } |
398 | 401 |
399 void GrGLSLProgramBuilder::finalizeShaders() { | 402 void GrGLSLProgramBuilder::finalizeShaders() { |
400 this->varyingHandler()->finalize(); | 403 this->varyingHandler()->finalize(); |
401 fVS.finalize(kVertex_GrShaderFlag); | 404 fVS.finalize(kVertex_GrShaderFlag); |
402 fFS.finalize(kFragment_GrShaderFlag); | 405 fFS.finalize(kFragment_GrShaderFlag); |
403 | 406 |
404 } | 407 } |
OLD | NEW |