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

Side by Side Diff: src/gpu/gl/builders/GrGLProgramBuilder.cpp

Issue 551253004: Changes to remove program effects builder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 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/gl/builders/GrGLProgramBuilder.h ('k') | src/gpu/gl/builders/GrGLShaderBuilder.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 2014 Google Inc. 2 * Copyright 2014 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 "gl/GrGLProgram.h" 8 #include "gl/GrGLProgram.h"
9 #include "gl/GrGLSLPrettyPrint.h" 9 #include "gl/GrGLSLPrettyPrint.h"
10 #include "gl/GrGLUniformHandle.h" 10 #include "gl/GrGLUniformHandle.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 fUniformHandles.fCoverageUni = 60 fUniformHandles.fCoverageUni =
61 this->addUniform(GrGLProgramBuilder::kFragment_Visibility, 61 this->addUniform(GrGLProgramBuilder::kFragment_Visibility,
62 kVec4f_GrSLType, 62 kVec4f_GrSLType,
63 "Coverage", 63 "Coverage",
64 &name); 64 &name);
65 inputCoverage = GrGLSLExpr4(name); 65 inputCoverage = GrGLSLExpr4(name);
66 } else if (GrGLProgramDesc::kAllOnes_ColorInput == header.fCoverageInput) { 66 } else if (GrGLProgramDesc::kAllOnes_ColorInput == header.fCoverageInput) {
67 inputCoverage = GrGLSLExpr4(1); 67 inputCoverage = GrGLSLExpr4(1);
68 } 68 }
69 69
70 this->emitCodeBeforeEffects(&inputColor, &inputCoverage); 70 // Subclasses drive effect emitting
71 71 this->createAndEmitEffects(geometryProcessor, colorStages, coverageStages, & inputColor,
72 /////////////////////////////////////////////////////////////////////////// 72 &inputCoverage);
73 // emit the per-effect code for both color and coverage effects
74
75 GrGLProgramDesc::EffectKeyProvider colorKeyProvider(
76 &this->desc(), GrGLProgramDesc::EffectKeyProvider::kColor_EffectType);
77 fColorEffects.reset(this->createAndEmitEffects(colorStages,
78 this->desc().numColorEffects( ),
79 colorKeyProvider,
80 &inputColor));
81
82 this->emitGeometryProcessor(geometryProcessor, &inputCoverage);
83
84 GrGLProgramDesc::EffectKeyProvider coverageKeyProvider(
85 &this->desc(), GrGLProgramDesc::EffectKeyProvider::kCoverage_EffectType) ;
86 fCoverageEffects.reset(this->createAndEmitEffects(coverageStages,
87 this->desc().numCoverageEf fects(),
88 coverageKeyProvider,
89 &inputCoverage));
90
91 this->emitCodeAfterEffects();
92 73
93 fFS.emitCodeAfterEffects(inputColor, inputCoverage); 74 fFS.emitCodeAfterEffects(inputColor, inputCoverage);
94 75
95 if (!this->finish()) { 76 if (!this->finish()) {
96 return false; 77 return false;
97 } 78 }
98 79
99 return true; 80 return true;
100 } 81 }
101 82
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 void GrGLProgramBuilder::appendUniformDecls(ShaderVisibility visibility, 152 void GrGLProgramBuilder::appendUniformDecls(ShaderVisibility visibility,
172 SkString* out) const { 153 SkString* out) const {
173 for (int i = 0; i < fUniforms.count(); ++i) { 154 for (int i = 0; i < fUniforms.count(); ++i) {
174 if (fUniforms[i].fVisibility & visibility) { 155 if (fUniforms[i].fVisibility & visibility) {
175 fUniforms[i].fVariable.appendDecl(this->ctxInfo(), out); 156 fUniforms[i].fVariable.appendDecl(this->ctxInfo(), out);
176 out->append(";\n"); 157 out->append(";\n");
177 } 158 }
178 } 159 }
179 } 160 }
180 161
181 void GrGLProgramBuilder::createAndEmitEffects(GrGLProgramEffectsBuilder* program EffectsBuilder, 162 void GrGLProgramBuilder::createAndEmitEffects(const GrEffectStage* effectStages[ ],
182 const GrEffectStage* effectStages[ ],
183 int effectCnt, 163 int effectCnt,
184 const GrGLProgramDesc::EffectKeyPr ovider& keyProvider, 164 const GrGLProgramDesc::EffectKeyPr ovider& keyProvider,
185 GrGLSLExpr4* fsInOutColor) { 165 GrGLSLExpr4* fsInOutColor) {
186 bool effectEmitted = false; 166 bool effectEmitted = false;
187 167
188 GrGLSLExpr4 inColor = *fsInOutColor; 168 GrGLSLExpr4 inColor = *fsInOutColor;
189 GrGLSLExpr4 outColor; 169 GrGLSLExpr4 outColor;
190 170
191 for (int e = 0; e < effectCnt; ++e) { 171 for (int e = 0; e < effectCnt; ++e) {
192 SkASSERT(effectStages[e] && effectStages[e]->getEffect()); 172 // calls into the subclass to emit the actual effect into the program ef fect object
193 const GrEffectStage& stage = *effectStages[e]; 173 this->emitEffect(*effectStages[e], e, keyProvider, &inColor, &outColor);
194
195 CodeStage::AutoStageRestore csar(&fCodeStage, &stage);
196
197 if (inColor.isZeros()) {
198 SkString inColorName;
199
200 // Effects have no way to communicate zeros, they treat an empty str ing as ones.
201 this->nameVariable(&inColorName, '\0', "input");
202 fFS.codeAppendf("\tvec4 %s = %s;\n", inColorName.c_str(), inColor.c_ str());
203 inColor = inColorName;
204 }
205
206 // create var to hold stage result
207 SkString outColorName;
208 this->nameVariable(&outColorName, '\0', "output");
209 fFS.codeAppendf("\tvec4 %s;\n", outColorName.c_str());
210 outColor = outColorName;
211
212
213 programEffectsBuilder->emitEffect(stage,
214 keyProvider.get(e),
215 outColor.c_str(),
216 inColor.isOnes() ? NULL : inColor.c_st r(),
217 fCodeStage.stageIndex());
218
219 inColor = outColor;
220 effectEmitted = true; 174 effectEmitted = true;
221 } 175 }
222 176
223 if (effectEmitted) { 177 if (effectEmitted) {
224 *fsInOutColor = outColor; 178 *fsInOutColor = outColor;
225 } 179 }
226 } 180 }
227 181
182 void GrGLProgramBuilder::emitEffect(const GrEffectStage& effectStage,
183 int effectIndex,
184 const GrGLProgramDesc::EffectKeyProvider& ke yProvider,
185 GrGLSLExpr4* inColor,
186 GrGLSLExpr4* outColor) {
187 SkASSERT(effectStage.getEffect());
188 CodeStage::AutoStageRestore csar(&fCodeStage, &effectStage);
189
190 if (inColor->isZeros()) {
191 SkString inColorName;
192
193 // Effects have no way to communicate zeros, they treat an empty string as ones.
194 this->nameVariable(&inColorName, '\0', "input");
195 fFS.codeAppendf("\tvec4 %s = %s;\n", inColorName.c_str(), inColor->c_str ());
196 *inColor = inColorName;
197 }
198
199 // create var to hold stage result
200 SkString outColorName;
201 this->nameVariable(&outColorName, '\0', "output");
202 fFS.codeAppendf("\tvec4 %s;\n", outColorName.c_str());
203 *outColor = outColorName;
204
205 this->emitEffect(effectStage, keyProvider.get(effectIndex), outColor->c_str( ),
206 inColor->isOnes() ? NULL : inColor->c_str(), fCodeStage.sta geIndex());
207
208 *inColor = *outColor;
209 }
210
211 void GrGLProgramBuilder::emitSamplers(const GrEffect& effect,
212 GrGLEffect::TextureSamplerArray* outSample rs) {
213 SkTArray<GrGLProgramEffects::Sampler, true>& samplers =
214 this->getProgramEffects()->addSamplers();
215 int numTextures = effect.numTextures();
216 samplers.push_back_n(numTextures);
217 SkString name;
218 for (int t = 0; t < numTextures; ++t) {
219 name.printf("Sampler%d", t);
220 samplers[t].fUniform = this->addUniform(GrGLProgramBuilder::kFragment_Vi sibility,
221 kSampler2D_GrSLType,
222 name.c_str());
223 SkNEW_APPEND_TO_TARRAY(outSamplers, GrGLEffect::TextureSampler,
224 (samplers[t].fUniform, effect.textureAccess(t)));
225 }
226 }
227
228 bool GrGLProgramBuilder::finish() { 228 bool GrGLProgramBuilder::finish() {
229 SkASSERT(0 == fProgramID); 229 SkASSERT(0 == fProgramID);
230 GL_CALL_RET(fProgramID, CreateProgram()); 230 GL_CALL_RET(fProgramID, CreateProgram());
231 if (!fProgramID) { 231 if (!fProgramID) {
232 return false; 232 return false;
233 } 233 }
234 234
235 SkTDArray<GrGLuint> shadersToDelete; 235 SkTDArray<GrGLuint> shadersToDelete;
236 236
237 if (!this->compileAndAttachShaders(fProgramID, &shadersToDelete)) { 237 if (!this->compileAndAttachShaders(fProgramID, &shadersToDelete)) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 GetProgramResourceLocation(programId, 319 GetProgramResourceLocation(programId,
320 GR_GL_FRAGMENT_INPUT, 320 GR_GL_FRAGMENT_INPUT,
321 fSeparableVaryingInfos[i].fVariab le.c_str())); 321 fSeparableVaryingInfos[i].fVariab le.c_str()));
322 fSeparableVaryingInfos[i].fLocation = location; 322 fSeparableVaryingInfos[i].fLocation = location;
323 } 323 }
324 } 324 }
325 325
326 const GrGLContextInfo& GrGLProgramBuilder::ctxInfo() const { 326 const GrGLContextInfo& GrGLProgramBuilder::ctxInfo() const {
327 return fGpu->ctxInfo(); 327 return fGpu->ctxInfo();
328 } 328 }
OLDNEW
« no previous file with comments | « src/gpu/gl/builders/GrGLProgramBuilder.h ('k') | src/gpu/gl/builders/GrGLShaderBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698