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

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

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