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

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

Issue 582963002: Solo gp (Closed) Base URL: https://skia.googlesource.com/skia.git@no_peb
Patch Set: rebase Created 6 years, 2 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 12 matching lines...) Expand all
23 23
24 // number of each input/output type in a single allocation block 24 // number of each input/output type in a single allocation block
25 static const int kVarsPerBlock = 8; 25 static const int kVarsPerBlock = 8;
26 26
27 // ES2 FS only guarantees mediump and lowp support 27 // ES2 FS only guarantees mediump and lowp support
28 static const GrGLShaderVar::Precision kDefaultFragmentPrecision = GrGLShaderVar: :kMedium_Precision; 28 static const GrGLShaderVar::Precision kDefaultFragmentPrecision = GrGLShaderVar: :kMedium_Precision;
29 } 29 }
30 30
31 //////////////////////////////////////////////////////////////////////////////// /////////////////// 31 //////////////////////////////////////////////////////////////////////////////// ///////////////////
32 32
33 bool GrGLProgramBuilder::genProgram(const GrEffectStage* geometryProcessor, 33 bool GrGLProgramBuilder::genProgram(const GrGeometryStage* geometryProcessor,
34 const GrEffectStage* colorStages[], 34 const GrFragmentStage* colorStages[],
35 const GrEffectStage* coverageStages[]) { 35 const GrFragmentStage* coverageStages[]) {
36 const GrGLProgramDesc::KeyHeader& header = this->desc().getHeader(); 36 const GrGLProgramDesc::KeyHeader& header = this->desc().getHeader();
37 37
38 fFS.emitCodeBeforeEffects(); 38 fFS.emitCodeBeforeEffects();
39 39
40 /////////////////////////////////////////////////////////////////////////// 40 ///////////////////////////////////////////////////////////////////////////
41 // get the initial color and coverage to feed into the first effect in each effect chain 41 // get the initial color and coverage to feed into the first effect in each effect chain
42 42
43 GrGLSLExpr4 inputColor; 43 GrGLSLExpr4 inputColor;
44 GrGLSLExpr4 inputCoverage; 44 GrGLSLExpr4 inputCoverage;
45 45
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 return false; 77 return false;
78 } 78 }
79 79
80 return true; 80 return true;
81 } 81 }
82 82
83 ////////////////////////////////////////////////////////////////////////////// 83 //////////////////////////////////////////////////////////////////////////////
84 84
85 GrGLProgramBuilder::GrGLProgramBuilder(GrGpuGL* gpu, 85 GrGLProgramBuilder::GrGLProgramBuilder(GrGpuGL* gpu,
86 const GrGLProgramDesc& desc) 86 const GrGLProgramDesc& desc)
87 : fFragOnly(SkToBool(desc.getHeader().fUseFragShaderOnly)) 87 : fEffectEmitter(NULL)
88 , fFragOnly(SkToBool(desc.getHeader().fUseFragShaderOnly))
88 , fTexCoordSetCnt(0) 89 , fTexCoordSetCnt(0)
89 , fProgramID(0) 90 , fProgramID(0)
90 , fFS(this, desc) 91 , fFS(this, desc)
91 , fSeparableVaryingInfos(kVarsPerBlock) 92 , fSeparableVaryingInfos(kVarsPerBlock)
93 , fGrProcessorEmitter(this)
92 , fDesc(desc) 94 , fDesc(desc)
93 , fGpu(gpu) 95 , fGpu(gpu)
94 , fUniforms(kVarsPerBlock) { 96 , fUniforms(kVarsPerBlock) {
95 } 97 }
96 98
97 void GrGLProgramBuilder::nameVariable(SkString* out, char prefix, const char* na me) { 99 void GrGLProgramBuilder::nameVariable(SkString* out, char prefix, const char* na me) {
98 if ('\0' == prefix) { 100 if ('\0' == prefix) {
99 *out = name; 101 *out = name;
100 } else { 102 } else {
101 out->printf("%c%s", prefix, name); 103 out->printf("%c%s", prefix, name);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 void GrGLProgramBuilder::appendUniformDecls(ShaderVisibility visibility, 152 void GrGLProgramBuilder::appendUniformDecls(ShaderVisibility visibility,
151 SkString* out) const { 153 SkString* out) const {
152 for (int i = 0; i < fUniforms.count(); ++i) { 154 for (int i = 0; i < fUniforms.count(); ++i) {
153 if (fUniforms[i].fVisibility & visibility) { 155 if (fUniforms[i].fVisibility & visibility) {
154 fUniforms[i].fVariable.appendDecl(this->ctxInfo(), out); 156 fUniforms[i].fVariable.appendDecl(this->ctxInfo(), out);
155 out->append(";\n"); 157 out->append(";\n");
156 } 158 }
157 } 159 }
158 } 160 }
159 161
160 void GrGLProgramBuilder::createAndEmitEffects(const GrEffectStage* effectStages[ ], 162 void GrGLProgramBuilder::createAndEmitEffects(const GrFragmentStage* effectStage s[],
161 int effectCnt, 163 int effectCnt,
162 const GrGLProgramDesc::EffectKeyPr ovider& keyProvider, 164 const GrGLProgramDesc::EffectKeyPr ovider& keyProvider,
163 GrGLSLExpr4* fsInOutColor) { 165 GrGLSLExpr4* fsInOutColor) {
164 bool effectEmitted = false; 166 bool effectEmitted = false;
165 167
166 GrGLSLExpr4 inColor = *fsInOutColor; 168 GrGLSLExpr4 inColor = *fsInOutColor;
167 GrGLSLExpr4 outColor; 169 GrGLSLExpr4 outColor;
168 170
169 for (int e = 0; e < effectCnt; ++e) { 171 for (int e = 0; e < effectCnt; ++e) {
172 fGrProcessorEmitter.set(effectStages[e]->getFragmentProcessor());
173 fEffectEmitter = &fGrProcessorEmitter;
170 // calls into the subclass to emit the actual effect into the program ef fect object 174 // calls into the subclass to emit the actual effect into the program ef fect object
171 this->emitEffect(*effectStages[e], e, keyProvider, &inColor, &outColor); 175 this->emitEffect(*effectStages[e], e, keyProvider, &inColor, &outColor);
172 effectEmitted = true; 176 effectEmitted = true;
173 } 177 }
174 178
175 if (effectEmitted) { 179 if (effectEmitted) {
176 *fsInOutColor = outColor; 180 *fsInOutColor = outColor;
177 } 181 }
178 } 182 }
179 183
180 void GrGLProgramBuilder::emitEffect(const GrEffectStage& effectStage, 184 void GrGLProgramBuilder::emitEffect(const GrProcessorStage& effectStage,
181 int effectIndex, 185 int effectIndex,
182 const GrGLProgramDesc::EffectKeyProvider& ke yProvider, 186 const GrGLProgramDesc::EffectKeyProvider& ke yProvider,
183 GrGLSLExpr4* inColor, 187 GrGLSLExpr4* inColor,
184 GrGLSLExpr4* outColor) { 188 GrGLSLExpr4* outColor) {
185 SkASSERT(effectStage.getEffect()); 189 SkASSERT(effectStage.getProcessor());
186 CodeStage::AutoStageRestore csar(&fCodeStage, &effectStage); 190 CodeStage::AutoStageRestore csar(&fCodeStage, &effectStage);
187 191
188 if (inColor->isZeros()) { 192 if (inColor->isZeros()) {
189 SkString inColorName; 193 SkString inColorName;
190 194
191 // Effects have no way to communicate zeros, they treat an empty string as ones. 195 // Effects have no way to communicate zeros, they treat an empty string as ones.
192 this->nameVariable(&inColorName, '\0', "input"); 196 this->nameVariable(&inColorName, '\0', "input");
193 fFS.codeAppendf("\tvec4 %s = %s;\n", inColorName.c_str(), inColor->c_str ()); 197 fFS.codeAppendf("\tvec4 %s = %s;\n", inColorName.c_str(), inColor->c_str ());
194 *inColor = inColorName; 198 *inColor = inColorName;
195 } 199 }
196 200
197 // create var to hold stage result 201 // create var to hold stage result
198 SkString outColorName; 202 SkString outColorName;
199 this->nameVariable(&outColorName, '\0', "output"); 203 this->nameVariable(&outColorName, '\0', "output");
200 fFS.codeAppendf("\tvec4 %s;\n", outColorName.c_str()); 204 fFS.codeAppendf("\tvec4 %s;\n", outColorName.c_str());
201 *outColor = outColorName; 205 *outColor = outColorName;
202 206
203 this->emitEffect(effectStage, keyProvider.get(effectIndex), outColor->c_str( ), 207 this->emitEffect(effectStage, keyProvider.get(effectIndex), outColor->c_str( ),
204 inColor->isOnes() ? NULL : inColor->c_str(), fCodeStage.sta geIndex()); 208 inColor->isOnes() ? NULL : inColor->c_str(), fCodeStage.sta geIndex());
205 209
206 *inColor = *outColor; 210 *inColor = *outColor;
207 } 211 }
208 212
209 void GrGLProgramBuilder::emitSamplers(const GrEffect& effect, 213 void GrGLProgramBuilder::emitSamplers(const GrProcessor& effect,
210 GrGLEffect::TextureSamplerArray* outSample rs) { 214 GrGLProcessor::TextureSamplerArray* outSam plers) {
211 SkTArray<GrGLProgramEffects::Sampler, true>& samplers = 215 SkTArray<GrGLProgramEffects::Sampler, true>& samplers =
212 this->getProgramEffects()->addSamplers(); 216 this->getProgramEffects()->addSamplers();
213 int numTextures = effect.numTextures(); 217 int numTextures = effect.numTextures();
214 samplers.push_back_n(numTextures); 218 samplers.push_back_n(numTextures);
215 SkString name; 219 SkString name;
216 for (int t = 0; t < numTextures; ++t) { 220 for (int t = 0; t < numTextures; ++t) {
217 name.printf("Sampler%d", t); 221 name.printf("Sampler%d", t);
218 samplers[t].fUniform = this->addUniform(GrGLProgramBuilder::kFragment_Vi sibility, 222 samplers[t].fUniform = this->addUniform(GrGLProgramBuilder::kFragment_Vi sibility,
219 kSampler2D_GrSLType, 223 kSampler2D_GrSLType,
220 name.c_str()); 224 name.c_str());
221 SkNEW_APPEND_TO_TARRAY(outSamplers, GrGLEffect::TextureSampler, 225 SkNEW_APPEND_TO_TARRAY(outSamplers, GrGLProcessor::TextureSampler,
222 (samplers[t].fUniform, effect.textureAccess(t))); 226 (samplers[t].fUniform, effect.textureAccess(t)));
223 } 227 }
224 } 228 }
225 229
226 bool GrGLProgramBuilder::finish() { 230 bool GrGLProgramBuilder::finish() {
227 SkASSERT(0 == fProgramID); 231 SkASSERT(0 == fProgramID);
228 GL_CALL_RET(fProgramID, CreateProgram()); 232 GL_CALL_RET(fProgramID, CreateProgram());
229 if (!fProgramID) { 233 if (!fProgramID) {
230 return false; 234 return false;
231 } 235 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 GetProgramResourceLocation(programId, 321 GetProgramResourceLocation(programId,
318 GR_GL_FRAGMENT_INPUT, 322 GR_GL_FRAGMENT_INPUT,
319 fSeparableVaryingInfos[i].fVariab le.c_str())); 323 fSeparableVaryingInfos[i].fVariab le.c_str()));
320 fSeparableVaryingInfos[i].fLocation = location; 324 fSeparableVaryingInfos[i].fLocation = location;
321 } 325 }
322 } 326 }
323 327
324 const GrGLContextInfo& GrGLProgramBuilder::ctxInfo() const { 328 const GrGLContextInfo& GrGLProgramBuilder::ctxInfo() const {
325 return fGpu->ctxInfo(); 329 return fGpu->ctxInfo();
326 } 330 }
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