Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(699)

Side by Side Diff: src/gpu/glsl/GrGLSLProgramBuilder.cpp

Issue 1896013003: Revert of Refactor how we store and use samplers in Ganesh (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/glsl/GrGLSLProgramBuilder.h ('k') | src/gpu/glsl/GrGLSLSampler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "glsl/GrGLSLFragmentProcessor.h" 11 #include "glsl/GrGLSLFragmentProcessor.h"
12 #include "glsl/GrGLSLGeometryProcessor.h" 12 #include "glsl/GrGLSLGeometryProcessor.h"
13 #include "glsl/GrGLSLVarying.h" 13 #include "glsl/GrGLSLVarying.h"
14 #include "glsl/GrGLSLXferProcessor.h" 14 #include "glsl/GrGLSLXferProcessor.h"
15 15
16 const int GrGLSLProgramBuilder::kVarsPerBlock = 8; 16 const int GrGLSLProgramBuilder::kVarsPerBlock = 8;
17 17
18 GrGLSLProgramBuilder::GrGLSLProgramBuilder(const GrPipeline& pipeline, 18 GrGLSLProgramBuilder::GrGLSLProgramBuilder(const GrPipeline& pipeline,
19 const GrPrimitiveProcessor& primProc, 19 const GrPrimitiveProcessor& primProc,
20 const GrProgramDesc& desc) 20 const GrProgramDesc& desc)
21 : fVS(this) 21 : fVS(this)
22 , fGS(this) 22 , fGS(this)
23 , fFS(this) 23 , fFS(this)
24 , fStageIndex(-1) 24 , fStageIndex(-1)
25 , fPipeline(pipeline) 25 , fPipeline(pipeline)
26 , fPrimProc(primProc) 26 , fPrimProc(primProc)
27 , fDesc(desc) 27 , fDesc(desc)
28 , fGeometryProcessor(nullptr) 28 , fGeometryProcessor(nullptr)
29 , fXferProcessor(nullptr) 29 , fXferProcessor(nullptr)
30 , fSamplerUniforms(4)
30 , fNumVertexSamplers(0) 31 , fNumVertexSamplers(0)
31 , fNumGeometrySamplers(0) 32 , fNumGeometrySamplers(0)
32 , fNumFragmentSamplers(0) { 33 , fNumFragmentSamplers(0) {
33 } 34 }
34 35
35 void GrGLSLProgramBuilder::addFeature(GrShaderFlags shaders, 36 void GrGLSLProgramBuilder::addFeature(GrShaderFlags shaders,
36 uint32_t featureBit, 37 uint32_t featureBit,
37 const char* extensionName) { 38 const char* extensionName) {
38 if (shaders & kVertex_GrShaderFlag) { 39 if (shaders & kVertex_GrShaderFlag) {
39 fVS.addFeature(featureBit, extensionName); 40 fVS.addFeature(featureBit, extensionName);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 90
90 // Enclose custom code in a block to avoid namespace conflicts 91 // Enclose custom code in a block to avoid namespace conflicts
91 SkString openBrace; 92 SkString openBrace;
92 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, proc.name()); 93 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, proc.name());
93 fFS.codeAppend(openBrace.c_str()); 94 fFS.codeAppend(openBrace.c_str());
94 fVS.codeAppendf("// Primitive Processor %s\n", proc.name()); 95 fVS.codeAppendf("// Primitive Processor %s\n", proc.name());
95 96
96 SkASSERT(!fGeometryProcessor); 97 SkASSERT(!fGeometryProcessor);
97 fGeometryProcessor = proc.createGLSLInstance(*this->glslCaps()); 98 fGeometryProcessor = proc.createGLSLInstance(*this->glslCaps());
98 99
99 SkSTArray<4, SamplerHandle> texSamplers(proc.numTextures()); 100 SkSTArray<4, GrGLSLSampler> texSamplers(proc.numTextures());
100 SkSTArray<2, SamplerHandle> bufferSamplers(proc.numBuffers()); 101 SkSTArray<2, GrGLSLSampler> bufferSamplers(proc.numBuffers());
101 this->emitSamplers(proc, &texSamplers, &bufferSamplers); 102 this->emitSamplers(proc, &texSamplers, &bufferSamplers);
102 103
103 GrGLSLGeometryProcessor::EmitArgs args(&fVS, 104 GrGLSLGeometryProcessor::EmitArgs args(&fVS,
104 &fFS, 105 &fFS,
105 this->varyingHandler(), 106 this->varyingHandler(),
106 this->uniformHandler(), 107 this->uniformHandler(),
107 this->glslCaps(), 108 this->glslCaps(),
108 proc, 109 proc,
109 outputColor->c_str(), 110 outputColor->c_str(),
110 outputCoverage->c_str(), 111 outputCoverage->c_str(),
111 texSamplers.begin(), 112 texSamplers,
112 bufferSamplers.begin(), 113 bufferSamplers,
113 fCoordTransforms, 114 fCoordTransforms,
114 &fOutCoords); 115 &fOutCoords);
115 fGeometryProcessor->emitCode(args); 116 fGeometryProcessor->emitCode(args);
116 117
117 // 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
118 // 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
119 SkDEBUGCODE(verify(proc);) 120 SkDEBUGCODE(verify(proc);)
120 121
121 fFS.codeAppend("}"); 122 fFS.codeAppend("}");
122 } 123 }
(...skipping 19 matching lines...) Expand all
142 AutoStageAdvance adv(this); 143 AutoStageAdvance adv(this);
143 this->nameExpression(output, "output"); 144 this->nameExpression(output, "output");
144 145
145 // Enclose custom code in a block to avoid namespace conflicts 146 // Enclose custom code in a block to avoid namespace conflicts
146 SkString openBrace; 147 SkString openBrace;
147 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, fp.name()); 148 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, fp.name());
148 fFS.codeAppend(openBrace.c_str()); 149 fFS.codeAppend(openBrace.c_str());
149 150
150 GrGLSLFragmentProcessor* fragProc = fp.createGLSLInstance(); 151 GrGLSLFragmentProcessor* fragProc = fp.createGLSLInstance();
151 152
152 SkSTArray<4, SamplerHandle> texSamplers(fp.numTextures()); 153 SkSTArray<4, GrGLSLSampler> texSamplers(fp.numTextures());
153 SkSTArray<2, SamplerHandle> bufferSamplers(fp.numBuffers()); 154 SkSTArray<2, GrGLSLSampler> bufferSamplers(fp.numBuffers());
154 this->emitSamplers(fp, &texSamplers, &bufferSamplers); 155 this->emitSamplers(fp, &texSamplers, &bufferSamplers);
155 156
156 GrGLSLFragmentProcessor::EmitArgs args(&fFS, 157 GrGLSLFragmentProcessor::EmitArgs args(&fFS,
157 this->uniformHandler(), 158 this->uniformHandler(),
158 this->glslCaps(), 159 this->glslCaps(),
159 fp, 160 fp,
160 output->c_str(), 161 output->c_str(),
161 input.isOnes() ? nullptr : input.c_st r(), 162 input.isOnes() ? nullptr : input.c_st r(),
162 fOutCoords[index], 163 fOutCoords[index],
163 texSamplers.begin(), 164 texSamplers,
164 bufferSamplers.begin()); 165 bufferSamplers);
165 fragProc->emitCode(args); 166 fragProc->emitCode(args);
166 167
167 // 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
168 // 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
169 SkDEBUGCODE(verify(fp);) 170 SkDEBUGCODE(verify(fp);)
170 fFragmentProcessors.push_back(fragProc); 171 fFragmentProcessors.push_back(fragProc);
171 172
172 fFS.codeAppend("}"); 173 fFS.codeAppend("}");
173 } 174 }
174 175
(...skipping 14 matching lines...) Expand all
189 } 190 }
190 191
191 if (this->glslCaps()->mustDeclareFragmentShaderOutput()) { 192 if (this->glslCaps()->mustDeclareFragmentShaderOutput()) {
192 fFS.enableCustomOutput(); 193 fFS.enableCustomOutput();
193 } 194 }
194 195
195 SkString openBrace; 196 SkString openBrace;
196 openBrace.printf("{ // Xfer Processor: %s\n", xp.name()); 197 openBrace.printf("{ // Xfer Processor: %s\n", xp.name());
197 fFS.codeAppend(openBrace.c_str()); 198 fFS.codeAppend(openBrace.c_str());
198 199
199 SkSTArray<4, SamplerHandle> texSamplers(xp.numTextures()); 200 SkSTArray<4, GrGLSLSampler> texSamplers(xp.numTextures());
200 SkSTArray<2, SamplerHandle> bufferSamplers(xp.numBuffers()); 201 SkSTArray<2, GrGLSLSampler> bufferSamplers(xp.numBuffers());
201 this->emitSamplers(xp, &texSamplers, &bufferSamplers); 202 this->emitSamplers(xp, &texSamplers, &bufferSamplers);
202 203
203 bool usePLSDstRead = (plsState == GrPixelLocalStorageState::kFinish_GrPixelL ocalStorageState); 204 bool usePLSDstRead = (plsState == GrPixelLocalStorageState::kFinish_GrPixelL ocalStorageState);
204 GrGLSLXferProcessor::EmitArgs args(&fFS, 205 GrGLSLXferProcessor::EmitArgs args(&fFS,
205 this->uniformHandler(), 206 this->uniformHandler(),
206 this->glslCaps(), 207 this->glslCaps(),
207 xp, colorIn.c_str(), 208 xp, colorIn.c_str(),
208 ignoresCoverage ? nullptr : coverageIn.c_ str(), 209 ignoresCoverage ? nullptr : coverageIn.c_ str(),
209 fFS.getPrimaryColorOutputName(), 210 fFS.getPrimaryColorOutputName(),
210 fFS.getSecondaryColorOutputName(), 211 fFS.getSecondaryColorOutputName(),
211 texSamplers.begin(), 212 texSamplers,
212 bufferSamplers.begin(), 213 bufferSamplers,
213 usePLSDstRead); 214 usePLSDstRead);
214 fXferProcessor->emitCode(args); 215 fXferProcessor->emitCode(args);
215 216
216 // 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
217 // 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
218 SkDEBUGCODE(verify(xp);) 219 SkDEBUGCODE(verify(xp);)
219 fFS.codeAppend("}"); 220 fFS.codeAppend("}");
220 } 221 }
221 222
222 void GrGLSLProgramBuilder::emitSamplers(const GrProcessor& processor, 223 void GrGLSLProgramBuilder::emitSamplers(const GrProcessor& processor,
223 SkTArray<SamplerHandle>* outTexSamplers, 224 GrGLSLSampler::SamplerArray* outTexSampl ers,
224 SkTArray<SamplerHandle>* outBufferSample rs) { 225 GrGLSLSampler::SamplerArray* outBufferSa mplers) {
225 SkString name; 226 SkString name;
226 int numTextures = processor.numTextures(); 227 int numTextures = processor.numTextures();
227 for (int t = 0; t < numTextures; ++t) { 228 for (int t = 0; t < numTextures; ++t) {
228 const GrTextureAccess& access = processor.textureAccess(t); 229 const GrTextureAccess& access = processor.textureAccess(t);
229 GrSLType samplerType = access.getTexture()->samplerType(); 230 GrSLType samplerType = access.getTexture()->samplerType();
230 if (kSamplerExternal_GrSLType == samplerType) { 231 if (kSamplerExternal_GrSLType == samplerType) {
231 const char* externalFeatureString = this->glslCaps()->externalTextur eExtensionString(); 232 const char* externalFeatureString = this->glslCaps()->externalTextur eExtensionString();
232 // 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
233 SkASSERT(externalFeatureString); 234 SkASSERT(externalFeatureString);
234 this->addFeature(access.getVisibility(), 235 this->addFeature(access.getVisibility(),
(...skipping 22 matching lines...) Expand all
257 1 << GrGLSLShaderBuilder::kTexelBuffer_GLSLPrivateF eature, 258 1 << GrGLSLShaderBuilder::kTexelBuffer_GLSLPrivateF eature,
258 extension); 259 extension);
259 } 260 }
260 } 261 }
261 } 262 }
262 263
263 void GrGLSLProgramBuilder::emitSampler(GrSLType samplerType, 264 void GrGLSLProgramBuilder::emitSampler(GrSLType samplerType,
264 GrPixelConfig config, 265 GrPixelConfig config,
265 const char* name, 266 const char* name,
266 GrShaderFlags visibility, 267 GrShaderFlags visibility,
267 SkTArray<SamplerHandle>* outSamplers) { 268 GrGLSLSampler::SamplerArray* outSamplers) {
268 if (visibility & kVertex_GrShaderFlag) { 269 if (visibility & kVertex_GrShaderFlag) {
269 ++fNumVertexSamplers; 270 ++fNumVertexSamplers;
270 } 271 }
271 if (visibility & kGeometry_GrShaderFlag) { 272 if (visibility & kGeometry_GrShaderFlag) {
272 SkASSERT(this->primitiveProcessor().willUseGeoShader()); 273 SkASSERT(this->primitiveProcessor().willUseGeoShader());
273 ++fNumGeometrySamplers; 274 ++fNumGeometrySamplers;
274 } 275 }
275 if (visibility & kFragment_GrShaderFlag) { 276 if (visibility & kFragment_GrShaderFlag) {
276 ++fNumFragmentSamplers; 277 ++fNumFragmentSamplers;
277 } 278 }
278 GrSLPrecision precision = this->glslCaps()->samplerPrecision(config, visibil ity); 279 GrSLPrecision precision = this->glslCaps()->samplerPrecision(config, visibil ity);
279 SamplerHandle handle = this->uniformHandler()->addSampler(visibility, 280 UniformHandle u = this->uniformHandler()->addUniform(visibility, samplerType , precision, name);
280 config, 281 fSamplerUniforms.push_back(u);
281 samplerType, 282 outSamplers->emplace_back(u, config);
282 precision,
283 name);
284 outSamplers->emplace_back(handle);
285 } 283 }
286 284
287 void GrGLSLProgramBuilder::emitFSOutputSwizzle(bool hasSecondaryOutput) { 285 void GrGLSLProgramBuilder::emitFSOutputSwizzle(bool hasSecondaryOutput) {
288 // Swizzle the fragment shader outputs if necessary. 286 // Swizzle the fragment shader outputs if necessary.
289 GrSwizzle swizzle; 287 GrSwizzle swizzle;
290 swizzle.setFromKey(this->desc().header().fOutputSwizzle); 288 swizzle.setFromKey(this->desc().header().fOutputSwizzle);
291 if (swizzle != GrSwizzle::RGBA()) { 289 if (swizzle != GrSwizzle::RGBA()) {
292 fFS.codeAppendf("%s = %s.%s;", fFS.getPrimaryColorOutputName(), 290 fFS.codeAppendf("%s = %s.%s;", fFS.getPrimaryColorOutputName(),
293 fFS.getPrimaryColorOutputName(), 291 fFS.getPrimaryColorOutputName(),
294 swizzle.c_str()); 292 swizzle.c_str());
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 this->nameVariable(&outName, '\0', baseName); 362 this->nameVariable(&outName, '\0', baseName);
365 } 363 }
366 fFS.codeAppendf("vec4 %s;", outName.c_str()); 364 fFS.codeAppendf("vec4 %s;", outName.c_str());
367 *output = outName; 365 *output = outName;
368 } 366 }
369 367
370 void GrGLSLProgramBuilder::appendUniformDecls(GrShaderFlags visibility, SkString * out) const { 368 void GrGLSLProgramBuilder::appendUniformDecls(GrShaderFlags visibility, SkString * out) const {
371 this->uniformHandler()->appendUniformDecls(visibility, out); 369 this->uniformHandler()->appendUniformDecls(visibility, out);
372 } 370 }
373 371
374 const GrGLSLSampler& GrGLSLProgramBuilder::getSampler(SamplerHandle handle) cons t {
375 return this->uniformHandler()->getSampler(handle);
376 }
377
378 void GrGLSLProgramBuilder::addRTAdjustmentUniform(GrSLPrecision precision, 372 void GrGLSLProgramBuilder::addRTAdjustmentUniform(GrSLPrecision precision,
379 const char* name, 373 const char* name,
380 const char** outName) { 374 const char** outName) {
381 SkASSERT(!fUniformHandles.fRTAdjustmentUni.isValid()); 375 SkASSERT(!fUniformHandles.fRTAdjustmentUni.isValid());
382 fUniformHandles.fRTAdjustmentUni = 376 fUniformHandles.fRTAdjustmentUni =
383 this->uniformHandler()->addUniform(kVertex_GrShaderFlag, 377 this->uniformHandler()->addUniform(kVertex_GrShaderFlag,
384 kVec4f_GrSLType, 378 kVec4f_GrSLType,
385 precision, 379 precision,
386 name, 380 name,
387 outName); 381 outName);
(...skipping 13 matching lines...) Expand all
401 delete fFragmentProcessors[i]; 395 delete fFragmentProcessors[i];
402 } 396 }
403 } 397 }
404 398
405 void GrGLSLProgramBuilder::finalizeShaders() { 399 void GrGLSLProgramBuilder::finalizeShaders() {
406 this->varyingHandler()->finalize(); 400 this->varyingHandler()->finalize();
407 fVS.finalize(kVertex_GrShaderFlag); 401 fVS.finalize(kVertex_GrShaderFlag);
408 fFS.finalize(kFragment_GrShaderFlag); 402 fFS.finalize(kFragment_GrShaderFlag);
409 403
410 } 404 }
OLDNEW
« no previous file with comments | « src/gpu/glsl/GrGLSLProgramBuilder.h ('k') | src/gpu/glsl/GrGLSLSampler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698