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

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

Issue 628293002: Plumb OptDrawState down to VertexShaderBuilder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Clean up 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
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 GrGeometryStage* geometryProcessor, 33 bool GrGLProgramBuilder::genProgram(const GrOptDrawState& optState,
34 const GrGeometryStage* geometryProcessor,
34 const GrFragmentStage* colorStages[], 35 const GrFragmentStage* colorStages[],
35 const GrFragmentStage* coverageStages[]) { 36 const GrFragmentStage* coverageStages[]) {
36 const GrGLProgramDesc::KeyHeader& header = this->desc().getHeader(); 37 const GrGLProgramDesc::KeyHeader& header = this->desc().getHeader();
37 38
38 fFS.emitCodeBeforeEffects(); 39 fFS.emitCodeBeforeEffects();
39 40
40 /////////////////////////////////////////////////////////////////////////// 41 ///////////////////////////////////////////////////////////////////////////
41 // get the initial color and coverage to feed into the first effect in each effect chain 42 // get the initial color and coverage to feed into the first effect in each effect chain
42 43
43 GrGLSLExpr4 inputColor; 44 GrGLSLExpr4 inputColor;
(...skipping 22 matching lines...) Expand all
66 } else if (GrGLProgramDesc::kAllOnes_ColorInput == header.fCoverageInput) { 67 } else if (GrGLProgramDesc::kAllOnes_ColorInput == header.fCoverageInput) {
67 inputCoverage = GrGLSLExpr4(1); 68 inputCoverage = GrGLSLExpr4(1);
68 } 69 }
69 70
70 // Subclasses drive effect emitting 71 // Subclasses drive effect emitting
71 this->createAndEmitEffects(geometryProcessor, colorStages, coverageStages, & inputColor, 72 this->createAndEmitEffects(geometryProcessor, colorStages, coverageStages, & inputColor,
72 &inputCoverage); 73 &inputCoverage);
73 74
74 fFS.emitCodeAfterEffects(inputColor, inputCoverage); 75 fFS.emitCodeAfterEffects(inputColor, inputCoverage);
75 76
76 if (!this->finish()) { 77 if (!this->finish(optState)) {
77 return false; 78 return false;
78 } 79 }
79 80
80 return true; 81 return true;
81 } 82 }
82 83
83 ////////////////////////////////////////////////////////////////////////////// 84 //////////////////////////////////////////////////////////////////////////////
84 85
85 GrGLProgramBuilder::GrGLProgramBuilder(GrGpuGL* gpu, 86 GrGLProgramBuilder::GrGLProgramBuilder(GrGpuGL* gpu,
86 const GrGLProgramDesc& desc) 87 const GrGLProgramDesc& desc)
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 for (int t = 0; t < numTextures; ++t) { 221 for (int t = 0; t < numTextures; ++t) {
221 name.printf("Sampler%d", t); 222 name.printf("Sampler%d", t);
222 samplers[t].fUniform = this->addUniform(GrGLProgramBuilder::kFragment_Vi sibility, 223 samplers[t].fUniform = this->addUniform(GrGLProgramBuilder::kFragment_Vi sibility,
223 kSampler2D_GrSLType, 224 kSampler2D_GrSLType,
224 name.c_str()); 225 name.c_str());
225 SkNEW_APPEND_TO_TARRAY(outSamplers, GrGLProcessor::TextureSampler, 226 SkNEW_APPEND_TO_TARRAY(outSamplers, GrGLProcessor::TextureSampler,
226 (samplers[t].fUniform, effect.textureAccess(t))); 227 (samplers[t].fUniform, effect.textureAccess(t)));
227 } 228 }
228 } 229 }
229 230
230 bool GrGLProgramBuilder::finish() { 231 bool GrGLProgramBuilder::finish(const GrOptDrawState& optState) {
231 SkASSERT(0 == fProgramID); 232 SkASSERT(0 == fProgramID);
232 GL_CALL_RET(fProgramID, CreateProgram()); 233 GL_CALL_RET(fProgramID, CreateProgram());
233 if (!fProgramID) { 234 if (!fProgramID) {
234 return false; 235 return false;
235 } 236 }
236 237
237 SkTDArray<GrGLuint> shadersToDelete; 238 SkTDArray<GrGLuint> shadersToDelete;
238 239
239 if (!this->compileAndAttachShaders(fProgramID, &shadersToDelete)) { 240 if (!this->compileAndAttachShaders(fProgramID, &shadersToDelete)) {
240 GL_CALL(DeleteProgram(fProgramID)); 241 GL_CALL(DeleteProgram(fProgramID));
241 return false; 242 return false;
242 } 243 }
243 244
244 this->bindProgramLocations(fProgramID); 245 this->bindProgramLocations(optState, fProgramID);
245 246
246 GL_CALL(LinkProgram(fProgramID)); 247 GL_CALL(LinkProgram(fProgramID));
247 248
248 // Calling GetProgramiv is expensive in Chromium. Assume success in release builds. 249 // Calling GetProgramiv is expensive in Chromium. Assume success in release builds.
249 bool checkLinked = !fGpu->ctxInfo().isChromium(); 250 bool checkLinked = !fGpu->ctxInfo().isChromium();
250 #ifdef SK_DEBUG 251 #ifdef SK_DEBUG
251 checkLinked = true; 252 checkLinked = true;
252 #endif 253 #endif
253 if (checkLinked) { 254 if (checkLinked) {
254 GrGLint linked = GR_GL_INIT_ZERO; 255 GrGLint linked = GR_GL_INIT_ZERO;
(...skipping 26 matching lines...) Expand all
281 } 282 }
282 283
283 return true; 284 return true;
284 } 285 }
285 286
286 bool GrGLProgramBuilder::compileAndAttachShaders(GrGLuint programId, 287 bool GrGLProgramBuilder::compileAndAttachShaders(GrGLuint programId,
287 SkTDArray<GrGLuint>* shaderIds) const { 288 SkTDArray<GrGLuint>* shaderIds) const {
288 return fFS.compileAndAttachShaders(programId, shaderIds); 289 return fFS.compileAndAttachShaders(programId, shaderIds);
289 } 290 }
290 291
291 void GrGLProgramBuilder::bindProgramLocations(GrGLuint programId) { 292 void GrGLProgramBuilder::bindProgramLocations(const GrOptDrawState& optState,
293 GrGLuint programId) {
292 fFS.bindProgramLocations(programId); 294 fFS.bindProgramLocations(programId);
293 295
294 // skbug.com/2056 296 // skbug.com/2056
295 bool usingBindUniform = fGpu->glInterface()->fFunctions.fBindUniformLocation != NULL; 297 bool usingBindUniform = fGpu->glInterface()->fFunctions.fBindUniformLocation != NULL;
296 if (usingBindUniform) { 298 if (usingBindUniform) {
297 int count = fUniforms.count(); 299 int count = fUniforms.count();
298 for (int i = 0; i < count; ++i) { 300 for (int i = 0; i < count; ++i) {
299 GL_CALL(BindUniformLocation(programId, i, fUniforms[i].fVariable.c_s tr())); 301 GL_CALL(BindUniformLocation(programId, i, fUniforms[i].fVariable.c_s tr()));
300 fUniforms[i].fLocation = i; 302 fUniforms[i].fLocation = i;
301 } 303 }
(...skipping 19 matching lines...) Expand all
321 GetProgramResourceLocation(programId, 323 GetProgramResourceLocation(programId,
322 GR_GL_FRAGMENT_INPUT, 324 GR_GL_FRAGMENT_INPUT,
323 fSeparableVaryingInfos[i].fVariab le.c_str())); 325 fSeparableVaryingInfos[i].fVariab le.c_str()));
324 fSeparableVaryingInfos[i].fLocation = location; 326 fSeparableVaryingInfos[i].fLocation = location;
325 } 327 }
326 } 328 }
327 329
328 const GrGLContextInfo& GrGLProgramBuilder::ctxInfo() const { 330 const GrGLContextInfo& GrGLProgramBuilder::ctxInfo() const {
329 return fGpu->ctxInfo(); 331 return fGpu->ctxInfo();
330 } 332 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698