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

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

Issue 2351753002: Revert of Stop flattening GrCoordTransforms in parent GrFragmentProcessors. (Closed)
Patch Set: Created 4 years, 3 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/instanced/InstanceProcessor.cpp » ('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"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 fFS.addFeature(featureBit, extensionName); 46 fFS.addFeature(featureBit, extensionName);
47 } 47 }
48 } 48 }
49 49
50 bool GrGLSLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor, 50 bool GrGLSLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor,
51 GrGLSLExpr4* inputCoverage) { 51 GrGLSLExpr4* inputCoverage) {
52 // First we loop over all of the installed processors and collect coord tran sforms. These will 52 // First we loop over all of the installed processors and collect coord tran sforms. These will
53 // be sent to the GrGLSLPrimitiveProcessor in its emitCode function 53 // be sent to the GrGLSLPrimitiveProcessor in its emitCode function
54 const GrPrimitiveProcessor& primProc = this->primitiveProcessor(); 54 const GrPrimitiveProcessor& primProc = this->primitiveProcessor();
55 55
56 for (int i = 0; i < this->pipeline().numFragmentProcessors(); i++) {
57 const GrFragmentProcessor& processor = this->pipeline().getFragmentProce ssor(i);
58
59 SkTArray<const GrCoordTransform*, true>& procCoords = fCoordTransforms.p ush_back();
60 processor.gatherCoordTransforms(&procCoords);
61 }
62
56 this->emitAndInstallPrimProc(primProc, inputColor, inputCoverage); 63 this->emitAndInstallPrimProc(primProc, inputColor, inputCoverage);
57 64
58 this->emitAndInstallFragProcs(inputColor, inputCoverage); 65 int numProcs = this->pipeline().numFragmentProcessors();
66 this->emitAndInstallFragProcs(0, this->pipeline().numColorFragmentProcessors (), inputColor);
67 this->emitAndInstallFragProcs(this->pipeline().numColorFragmentProcessors(), numProcs,
68 inputCoverage);
59 if (primProc.getPixelLocalStorageState() != 69 if (primProc.getPixelLocalStorageState() !=
60 GrPixelLocalStorageState::kDraw_GrPixelLocalStorageState) { 70 GrPixelLocalStorageState::kDraw_GrPixelLocalStorageState) {
61 this->emitAndInstallXferProc(this->pipeline().getXferProcessor(), *input Color, 71 this->emitAndInstallXferProc(this->pipeline().getXferProcessor(), *input Color,
62 *inputCoverage, this->pipeline().ignoresCov erage(), 72 *inputCoverage, this->pipeline().ignoresCov erage(),
63 primProc.getPixelLocalStorageState()); 73 primProc.getPixelLocalStorageState());
64 this->emitFSOutputSwizzle(this->pipeline().getXferProcessor().hasSeconda ryOutput()); 74 this->emitFSOutputSwizzle(this->pipeline().getXferProcessor().hasSeconda ryOutput());
65 } 75 }
66 76
67 return this->checkSamplerCounts(); 77 return this->checkSamplerCounts();
68 } 78 }
(...skipping 23 matching lines...) Expand all
92 fFS.codeAppend(openBrace.c_str()); 102 fFS.codeAppend(openBrace.c_str());
93 fVS.codeAppendf("// Primitive Processor %s\n", proc.name()); 103 fVS.codeAppendf("// Primitive Processor %s\n", proc.name());
94 104
95 SkASSERT(!fGeometryProcessor); 105 SkASSERT(!fGeometryProcessor);
96 fGeometryProcessor = proc.createGLSLInstance(*this->glslCaps()); 106 fGeometryProcessor = proc.createGLSLInstance(*this->glslCaps());
97 107
98 SkSTArray<4, SamplerHandle> texSamplers(proc.numTextures()); 108 SkSTArray<4, SamplerHandle> texSamplers(proc.numTextures());
99 SkSTArray<2, SamplerHandle> bufferSamplers(proc.numBuffers()); 109 SkSTArray<2, SamplerHandle> bufferSamplers(proc.numBuffers());
100 this->emitSamplers(proc, &texSamplers, &bufferSamplers); 110 this->emitSamplers(proc, &texSamplers, &bufferSamplers);
101 111
102 GrGLSLPrimitiveProcessor::FPCoordTransformHandler transformHandler(fPipeline ,
103 &fTransfo rmedCoordVars);
104 GrGLSLGeometryProcessor::EmitArgs args(&fVS, 112 GrGLSLGeometryProcessor::EmitArgs args(&fVS,
105 &fFS, 113 &fFS,
106 this->varyingHandler(), 114 this->varyingHandler(),
107 this->uniformHandler(), 115 this->uniformHandler(),
108 this->glslCaps(), 116 this->glslCaps(),
109 proc, 117 proc,
110 outputColor->c_str(), 118 outputColor->c_str(),
111 outputCoverage->c_str(), 119 outputCoverage->c_str(),
112 distanceVectorName, 120 distanceVectorName,
113 texSamplers.begin(), 121 texSamplers.begin(),
114 bufferSamplers.begin(), 122 bufferSamplers.begin(),
115 &transformHandler); 123 fCoordTransforms,
124 &fOutCoords);
116 fGeometryProcessor->emitCode(args); 125 fGeometryProcessor->emitCode(args);
117 126
118 // We have to check that effects and the code they emit are consistent, ie i f an effect 127 // 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 128 // asks for dst color, then the emit code needs to follow suit
120 SkDEBUGCODE(verify(proc);) 129 SkDEBUGCODE(verify(proc);)
121 130
122 fFS.codeAppend("}"); 131 fFS.codeAppend("}");
123 } 132 }
124 133
125 void GrGLSLProgramBuilder::emitAndInstallFragProcs(GrGLSLExpr4* color, GrGLSLExp r4* coverage) { 134 void GrGLSLProgramBuilder::emitAndInstallFragProcs(int procOffset,
126 int transformedCoordVarsIdx = 0; 135 int numProcs,
127 GrGLSLExpr4** inOut = &color; 136 GrGLSLExpr4* inOut) {
128 for (int i = 0; i < this->pipeline().numFragmentProcessors(); ++i) { 137 for (int i = procOffset; i < numProcs; ++i) {
129 if (i == this->pipeline().numColorFragmentProcessors()) {
130 inOut = &coverage;
131 }
132 GrGLSLExpr4 output; 138 GrGLSLExpr4 output;
133 const GrFragmentProcessor& fp = this->pipeline().getFragmentProcessor(i) ; 139 const GrFragmentProcessor& fp = this->pipeline().getFragmentProcessor(i) ;
134 this->emitAndInstallFragProc(fp, i, transformedCoordVarsIdx, **inOut, &o utput); 140 this->emitAndInstallFragProc(fp, i, *inOut, &output);
135 GrFragmentProcessor::Iter iter(&fp); 141 *inOut = output;
136 while (const GrFragmentProcessor* fp = iter.next()) {
137 transformedCoordVarsIdx += fp->numCoordTransforms();
138 }
139 **inOut = output;
140 } 142 }
141 } 143 }
142 144
143 // TODO Processors cannot output zeros because an empty string is all 1s 145 // TODO Processors cannot output zeros because an empty string is all 1s
144 // the fix is to allow effects to take the GrGLSLExpr4 directly 146 // the fix is to allow effects to take the GrGLSLExpr4 directly
145 void GrGLSLProgramBuilder::emitAndInstallFragProc(const GrFragmentProcessor& fp, 147 void GrGLSLProgramBuilder::emitAndInstallFragProc(const GrFragmentProcessor& fp,
146 int index, 148 int index,
147 int transformedCoordVarsIdx,
148 const GrGLSLExpr4& input, 149 const GrGLSLExpr4& input,
149 GrGLSLExpr4* output) { 150 GrGLSLExpr4* output) {
150 // Program builders have a bit of state we need to clear with each effect 151 // Program builders have a bit of state we need to clear with each effect
151 AutoStageAdvance adv(this); 152 AutoStageAdvance adv(this);
152 this->nameExpression(output, "output"); 153 this->nameExpression(output, "output");
153 154
154 // Enclose custom code in a block to avoid namespace conflicts 155 // Enclose custom code in a block to avoid namespace conflicts
155 SkString openBrace; 156 SkString openBrace;
156 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, fp.name()); 157 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, fp.name());
157 fFS.codeAppend(openBrace.c_str()); 158 fFS.codeAppend(openBrace.c_str());
158 159
159 GrGLSLFragmentProcessor* fragProc = fp.createGLSLInstance(); 160 GrGLSLFragmentProcessor* fragProc = fp.createGLSLInstance();
160 161
161 SkSTArray<4, SamplerHandle> texSamplers(fp.numTextures()); 162 SkSTArray<4, SamplerHandle> texSamplers(fp.numTextures());
162 SkSTArray<2, SamplerHandle> bufferSamplers(fp.numBuffers()); 163 SkSTArray<2, SamplerHandle> bufferSamplers(fp.numBuffers());
163 this->emitSamplers(fp, &texSamplers, &bufferSamplers); 164 this->emitSamplers(fp, &texSamplers, &bufferSamplers);
164 165
165 const GrShaderVar* coordVars = fTransformedCoordVars.begin() + transformedCo ordVarsIdx;
166 GrGLSLFragmentProcessor::TransformedCoordVars coords(&fp, coordVars);
167 GrGLSLFragmentProcessor::EmitArgs args(&fFS, 166 GrGLSLFragmentProcessor::EmitArgs args(&fFS,
168 this->uniformHandler(), 167 this->uniformHandler(),
169 this->glslCaps(), 168 this->glslCaps(),
170 fp, 169 fp,
171 output->c_str(), 170 output->c_str(),
172 input.isOnes() ? nullptr : input.c_st r(), 171 input.isOnes() ? nullptr : input.c_st r(),
173 coords, 172 fOutCoords[index],
174 texSamplers.begin(), 173 texSamplers.begin(),
175 bufferSamplers.begin(), 174 bufferSamplers.begin(),
176 this->primitiveProcessor().implements DistanceVector()); 175 this->primitiveProcessor().implements DistanceVector());
177 176
178 fragProc->emitCode(args); 177 fragProc->emitCode(args);
179 178
180 // We have to check that effects and the code they emit are consistent, ie i f an effect 179 // We have to check that effects and the code they emit are consistent, ie i f an effect
181 // asks for dst color, then the emit code needs to follow suit 180 // asks for dst color, then the emit code needs to follow suit
182 SkDEBUGCODE(verify(fp);) 181 SkDEBUGCODE(verify(fp);)
183 fFragmentProcessors.push_back(fragProc); 182 fFragmentProcessors.push_back(fragProc);
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 void GrGLSLProgramBuilder::cleanupFragmentProcessors() { 411 void GrGLSLProgramBuilder::cleanupFragmentProcessors() {
413 for (int i = 0; i < fFragmentProcessors.count(); ++i) { 412 for (int i = 0; i < fFragmentProcessors.count(); ++i) {
414 delete fFragmentProcessors[i]; 413 delete fFragmentProcessors[i];
415 } 414 }
416 } 415 }
417 416
418 void GrGLSLProgramBuilder::finalizeShaders() { 417 void GrGLSLProgramBuilder::finalizeShaders() {
419 this->varyingHandler()->finalize(); 418 this->varyingHandler()->finalize();
420 fVS.finalize(kVertex_GrShaderFlag); 419 fVS.finalize(kVertex_GrShaderFlag);
421 fFS.finalize(kFragment_GrShaderFlag); 420 fFS.finalize(kFragment_GrShaderFlag);
421
422 } 422 }
OLDNEW
« no previous file with comments | « src/gpu/glsl/GrGLSLProgramBuilder.h ('k') | src/gpu/instanced/InstanceProcessor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698