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

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

Issue 815643005: Move program descriptor and primitive processor off of optstate (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: bug fix Created 5 years, 11 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 "GrGLProgramBuilder.h" 8 #include "GrGLProgramBuilder.h"
9 #include "gl/GrGLProgram.h" 9 #include "gl/GrGLProgram.h"
10 #include "gl/GrGLSLPrettyPrint.h" 10 #include "gl/GrGLSLPrettyPrint.h"
11 #include "gl/GrGLUniformHandle.h" 11 #include "gl/GrGLUniformHandle.h"
12 #include "../GrGLXferProcessor.h" 12 #include "../GrGLXferProcessor.h"
13 #include "../GrGLGpu.h" 13 #include "../GrGLGpu.h"
14 #include "GrCoordTransform.h" 14 #include "GrCoordTransform.h"
15 #include "GrGLProgramBuilder.h" 15 #include "GrGLProgramBuilder.h"
16 #include "GrTexture.h" 16 #include "GrTexture.h"
17 #include "SkRTConf.h" 17 #include "SkRTConf.h"
18 #include "SkTraceEvent.h" 18 #include "SkTraceEvent.h"
19 19
20 #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X) 20 #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X)
21 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X) 21 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X)
22 22
23 //////////////////////////////////////////////////////////////////////////////// /////////////////// 23 //////////////////////////////////////////////////////////////////////////////// ///////////////////
24 24
25 class GrGLNvprProgramBuilder : public GrGLProgramBuilder { 25 class GrGLNvprProgramBuilder : public GrGLProgramBuilder {
26 public: 26 public:
27 GrGLNvprProgramBuilder(GrGLGpu* gpu, const GrOptDrawState& optState) 27 GrGLNvprProgramBuilder(GrGLGpu* gpu, const DrawArgs& args)
28 : INHERITED(gpu, optState) {} 28 : INHERITED(gpu, args) {}
29 29
30 GrGLProgram* createProgram(GrGLuint programID) SK_OVERRIDE { 30 GrGLProgram* createProgram(GrGLuint programID) SK_OVERRIDE {
31 // this is just for nvpr es, which has separable varyings that are plugg ed in after 31 // this is just for nvpr es, which has separable varyings that are plugg ed in after
32 // building 32 // building
33 GrGLPathProcessor* pathProc = 33 GrGLPathProcessor* pathProc =
34 static_cast<GrGLPathProcessor*>(fGeometryProcessor->fGLProc.get( )); 34 static_cast<GrGLPathProcessor*>(fGeometryProcessor->fGLProc.get( ));
35 pathProc->resolveSeparableVaryings(fGpu, programID); 35 pathProc->resolveSeparableVaryings(fGpu, programID);
36 return SkNEW_ARGS(GrGLNvprProgram, (fGpu, fDesc, fUniformHandles, progra mID, fUniforms, 36 return SkNEW_ARGS(GrGLNvprProgram, (fGpu, this->desc(), fUniformHandles, programID,
37 fUniforms,
37 fGeometryProcessor, 38 fGeometryProcessor,
38 fXferProcessor, fFragmentProcessors. get())); 39 fXferProcessor, fFragmentProcessors. get()));
39 } 40 }
40 41
41 private: 42 private:
42 typedef GrGLProgramBuilder INHERITED; 43 typedef GrGLProgramBuilder INHERITED;
43 }; 44 };
44 45
45 46
46 47
47 ////////////////////////////////////////////////////////////////////////////// 48 //////////////////////////////////////////////////////////////////////////////
48 49
49 const int GrGLProgramBuilder::kVarsPerBlock = 8; 50 const int GrGLProgramBuilder::kVarsPerBlock = 8;
50 51
51 GrGLProgram* GrGLProgramBuilder::CreateProgram(const GrOptDrawState& optState, G rGLGpu* gpu) { 52 GrGLProgram* GrGLProgramBuilder::CreateProgram(const DrawArgs& args, GrGLGpu* gp u) {
52 // create a builder. This will be handed off to effects so they can use it to add 53 // create a builder. This will be handed off to effects so they can use it to add
53 // uniforms, varyings, textures, etc 54 // uniforms, varyings, textures, etc
54 SkAutoTDelete<GrGLProgramBuilder> builder(CreateProgramBuilder(optState, gpu )); 55 SkAutoTDelete<GrGLProgramBuilder> builder(CreateProgramBuilder(args, gpu));
55 56
56 GrGLProgramBuilder* pb = builder.get(); 57 GrGLProgramBuilder* pb = builder.get();
57 58
58 // emit code to read the dst copy texture, if necessary 59 // emit code to read the dst copy texture, if necessary
59 if (GrGLFragmentShaderBuilder::kNoDstRead_DstReadKey != pb->header().fDstRea dKey && 60 if (GrGLFragmentShaderBuilder::kNoDstRead_DstReadKey != pb->header().fDstRea dKey &&
60 !gpu->glCaps().fbFetchSupport()) { 61 !gpu->glCaps().fbFetchSupport()) {
61 pb->fFS.emitCodeToReadDstTexture(); 62 pb->fFS.emitCodeToReadDstTexture();
62 } 63 }
63 64
64 // TODO: Once all stages can handle taking a float or vec4 and correctly han dling them we can 65 // TODO: Once all stages can handle taking a float or vec4 and correctly han dling them we can
65 // seed correctly here 66 // seed correctly here
66 GrGLSLExpr4 inputColor; 67 GrGLSLExpr4 inputColor;
67 GrGLSLExpr4 inputCoverage; 68 GrGLSLExpr4 inputCoverage;
68 69
69 pb->emitAndInstallProcs(&inputColor, &inputCoverage); 70 pb->emitAndInstallProcs(&inputColor, &inputCoverage);
70 71
71 return pb->finalize(); 72 return pb->finalize();
72 } 73 }
73 74
74 GrGLProgramBuilder* GrGLProgramBuilder::CreateProgramBuilder(const GrOptDrawStat e& optState, 75 GrGLProgramBuilder* GrGLProgramBuilder::CreateProgramBuilder(const DrawArgs& arg s,
75 GrGLGpu* gpu) { 76 GrGLGpu* gpu) {
76 if (GrGpu::IsPathRenderingDrawType(optState.drawType())) { 77 if (GrGpu::IsPathRenderingDrawType(args.fOptState->drawType())) {
77 SkASSERT(gpu->glCaps().pathRenderingSupport() && 78 SkASSERT(gpu->glCaps().pathRenderingSupport() &&
78 !optState.getPrimitiveProcessor()->willUseGeoShader() && 79 !args.fPrimitiveProcessor->willUseGeoShader() &&
79 optState.getPrimitiveProcessor()->numAttribs() == 0); 80 args.fPrimitiveProcessor->numAttribs() == 0);
80 return SkNEW_ARGS(GrGLNvprProgramBuilder, (gpu, optState)); 81 return SkNEW_ARGS(GrGLNvprProgramBuilder, (gpu, args));
81 } else { 82 } else {
82 return SkNEW_ARGS(GrGLProgramBuilder, (gpu, optState)); 83 return SkNEW_ARGS(GrGLProgramBuilder, (gpu, args));
83 } 84 }
84 } 85 }
85 86
86 ///////////////////////////////////////////////////////////////////////////// 87 /////////////////////////////////////////////////////////////////////////////
87 88
88 GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu, const GrOptDrawState& optSt ate) 89 GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu, const DrawArgs& args)
89 : fVS(this) 90 : fVS(this)
90 , fGS(this) 91 , fGS(this)
91 , fFS(this, optState.programDesc().header().fFragPosKey) 92 , fFS(this, args.fDesc->header().fFragPosKey)
92 , fOutOfStage(true) 93 , fOutOfStage(true)
93 , fStageIndex(-1) 94 , fStageIndex(-1)
94 , fGeometryProcessor(NULL) 95 , fGeometryProcessor(NULL)
95 , fXferProcessor(NULL) 96 , fXferProcessor(NULL)
96 , fOptState(optState) 97 , fArgs(args)
97 , fDesc(optState.programDesc())
98 , fGpu(gpu) 98 , fGpu(gpu)
99 , fUniforms(kVarsPerBlock) { 99 , fUniforms(kVarsPerBlock) {
100 } 100 }
101 101
102 void GrGLProgramBuilder::addVarying(const char* name, 102 void GrGLProgramBuilder::addVarying(const char* name,
103 GrGLVarying* varying, 103 GrGLVarying* varying,
104 GrSLPrecision fsPrecision) { 104 GrSLPrecision fsPrecision) {
105 SkASSERT(varying); 105 SkASSERT(varying);
106 if (varying->vsVarying()) { 106 if (varying->vsVarying()) {
107 fVS.addVarying(name, varying); 107 fVS.addVarying(name, varying);
108 } 108 }
109 if (fOptState.getPrimitiveProcessor()->willUseGeoShader()) { 109 if (this->primitiveProcessor().willUseGeoShader()) {
110 fGS.addVarying(name, varying); 110 fGS.addVarying(name, varying);
111 } 111 }
112 if (varying->fsVarying()) { 112 if (varying->fsVarying()) {
113 fFS.addVarying(varying, fsPrecision); 113 fFS.addVarying(varying, fsPrecision);
114 } 114 }
115 } 115 }
116 116
117 void GrGLProgramBuilder::addPassThroughAttribute(const GrPrimitiveProcessor::Att ribute* input, 117 void GrGLProgramBuilder::addPassThroughAttribute(const GrPrimitiveProcessor::Att ribute* input,
118 const char* output) { 118 const char* output) {
119 GrSLType type = GrVertexAttribTypeToSLType(input->fType); 119 GrSLType type = GrVertexAttribTypeToSLType(input->fType);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 186 }
187 187
188 const GrGLContextInfo& GrGLProgramBuilder::ctxInfo() const { 188 const GrGLContextInfo& GrGLProgramBuilder::ctxInfo() const {
189 return fGpu->ctxInfo(); 189 return fGpu->ctxInfo();
190 } 190 }
191 191
192 void GrGLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr 4* inputCoverage) { 192 void GrGLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr 4* inputCoverage) {
193 // First we loop over all of the installed processors and collect coord tran sforms. These will 193 // First we loop over all of the installed processors and collect coord tran sforms. These will
194 // be sent to the GrGLPrimitiveProcessor in its emitCode function 194 // be sent to the GrGLPrimitiveProcessor in its emitCode function
195 SkSTArray<8, GrGLProcessor::TransformedCoordsArray> outCoords; 195 SkSTArray<8, GrGLProcessor::TransformedCoordsArray> outCoords;
196 for (int i = 0; i < fOptState.numFragmentStages(); i++) { 196 for (int i = 0; i < this->optState().numFragmentStages(); i++) {
197 const GrFragmentProcessor* processor = fOptState.getFragmentStage(i).pro cessor(); 197 const GrFragmentProcessor* processor = this->optState().getFragmentStage (i).processor();
198 SkSTArray<2, const GrCoordTransform*, true>& procCoords = fCoordTransfor ms.push_back(); 198 SkSTArray<2, const GrCoordTransform*, true>& procCoords = fCoordTransfor ms.push_back();
199 for (int t = 0; t < processor->numTransforms(); t++) { 199 for (int t = 0; t < processor->numTransforms(); t++) {
200 procCoords.push_back(&processor->coordTransform(t)); 200 procCoords.push_back(&processor->coordTransform(t));
201 } 201 }
202 } 202 }
203 203
204 const GrPrimitiveProcessor& primProc = *fOptState.getPrimitiveProcessor(); 204 const GrPrimitiveProcessor& primProc = this->primitiveProcessor();
205 this->emitAndInstallProc(primProc, inputColor, inputCoverage); 205 this->emitAndInstallProc(primProc, inputColor, inputCoverage);
206 206
207 fFragmentProcessors.reset(SkNEW(GrGLInstalledFragProcs)); 207 fFragmentProcessors.reset(SkNEW(GrGLInstalledFragProcs));
208 int numProcs = fOptState.numFragmentStages(); 208 int numProcs = this->optState().numFragmentStages();
209 this->emitAndInstallFragProcs(0, fOptState.numColorStages(), inputColor); 209 this->emitAndInstallFragProcs(0, this->optState().numColorStages(), inputCol or);
210 this->emitAndInstallFragProcs(fOptState.numColorStages(), numProcs, inputCo verage); 210 this->emitAndInstallFragProcs(this->optState().numColorStages(), numProcs, inputCoverage);
211 this->emitAndInstallXferProc(*fOptState.getXferProcessor(), *inputColor, *in putCoverage); 211 this->emitAndInstallXferProc(*this->optState().getXferProcessor(), *inputCol or, *inputCoverage);
212 } 212 }
213 213
214 void GrGLProgramBuilder::emitAndInstallFragProcs(int procOffset, 214 void GrGLProgramBuilder::emitAndInstallFragProcs(int procOffset,
215 int numProcs, 215 int numProcs,
216 GrGLSLExpr4* inOut) { 216 GrGLSLExpr4* inOut) {
217 for (int e = procOffset; e < numProcs; ++e) { 217 for (int e = procOffset; e < numProcs; ++e) {
218 GrGLSLExpr4 output; 218 GrGLSLExpr4 output;
219 const GrPendingFragmentStage& stage = fOptState.getFragmentStage(e); 219 const GrPendingFragmentStage& stage = this->optState().getFragmentStage( e);
220 this->emitAndInstallProc(stage, e, *inOut, &output); 220 this->emitAndInstallProc(stage, e, *inOut, &output);
221 *inOut = output; 221 *inOut = output;
222 } 222 }
223 } 223 }
224 224
225 void GrGLProgramBuilder::nameExpression(GrGLSLExpr4* output, const char* baseNam e) { 225 void GrGLProgramBuilder::nameExpression(GrGLSLExpr4* output, const char* baseNam e) {
226 // create var to hold stage result. If we already have a valid output name, just use that 226 // create var to hold stage result. If we already have a valid output name, just use that
227 // otherwise create a new mangled one. This name is only valid if we are re ordering stages 227 // otherwise create a new mangled one. This name is only valid if we are re ordering stages
228 // and have to tell stage exactly where to put its output. 228 // and have to tell stage exactly where to put its output.
229 SkString outName; 229 SkString outName;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 verify(fp); 293 verify(fp);
294 fFragmentProcessors->fProcs.push_back(ifp); 294 fFragmentProcessors->fProcs.push_back(ifp);
295 } 295 }
296 296
297 void GrGLProgramBuilder::emitAndInstallProc(const GrPrimitiveProcessor& gp, 297 void GrGLProgramBuilder::emitAndInstallProc(const GrPrimitiveProcessor& gp,
298 const char* outColor, 298 const char* outColor,
299 const char* outCoverage) { 299 const char* outCoverage) {
300 SkASSERT(!fGeometryProcessor); 300 SkASSERT(!fGeometryProcessor);
301 fGeometryProcessor = SkNEW(GrGLInstalledGeoProc); 301 fGeometryProcessor = SkNEW(GrGLInstalledGeoProc);
302 302
303 const GrBatchTracker& bt = fOptState.getBatchTracker(); 303 const GrBatchTracker& bt = this->batchTracker();
304 fGeometryProcessor->fGLProc.reset(gp.createGLInstance(bt, fGpu->glCaps())); 304 fGeometryProcessor->fGLProc.reset(gp.createGLInstance(bt, fGpu->glCaps()));
305 305
306 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(gp.numTextures()); 306 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(gp.numTextures());
307 this->emitSamplers(gp, &samplers, fGeometryProcessor); 307 this->emitSamplers(gp, &samplers, fGeometryProcessor);
308 308
309 GrGLGeometryProcessor::EmitArgs args(this, gp, bt, outColor, outCoverage, sa mplers, 309 GrGLGeometryProcessor::EmitArgs args(this, gp, bt, outColor, outCoverage, sa mplers,
310 fCoordTransforms, &fOutCoords); 310 fCoordTransforms, &fOutCoords);
311 fGeometryProcessor->fGLProc->emitCode(args); 311 fGeometryProcessor->fGLProc->emitCode(args);
312 312
313 // We have to check that effects and the code they emit are consistent, ie i f an effect 313 // We have to check that effects and the code they emit are consistent, ie i f an effect
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 GL_CALL_RET(programID, CreateProgram()); 389 GL_CALL_RET(programID, CreateProgram());
390 if (0 == programID) { 390 if (0 == programID) {
391 return NULL; 391 return NULL;
392 } 392 }
393 393
394 // compile shaders and bind attributes / uniforms 394 // compile shaders and bind attributes / uniforms
395 SkTDArray<GrGLuint> shadersToDelete; 395 SkTDArray<GrGLuint> shadersToDelete;
396 396
397 // Legacy nvpr will not compile with a vertex shader, but newer nvpr require s a dummy vertex 397 // Legacy nvpr will not compile with a vertex shader, but newer nvpr require s a dummy vertex
398 // shader 398 // shader
399 bool useNvpr = GrGpu::IsPathRenderingDrawType(fOptState.drawType()); 399 bool useNvpr = GrGpu::IsPathRenderingDrawType(this->optState().drawType());
400 if (!(useNvpr && fGpu->glCaps().nvprSupport() == GrGLCaps::kLegacy_NvprSuppo rt)) { 400 if (!(useNvpr && fGpu->glCaps().nvprSupport() == GrGLCaps::kLegacy_NvprSuppo rt)) {
401 if (!fVS.compileAndAttachShaders(programID, &shadersToDelete)) { 401 if (!fVS.compileAndAttachShaders(programID, &shadersToDelete)) {
402 this->cleanupProgram(programID, shadersToDelete); 402 this->cleanupProgram(programID, shadersToDelete);
403 return NULL; 403 return NULL;
404 } 404 }
405 405
406 // Non fixed function NVPR actually requires a vertex shader to compile 406 // Non fixed function NVPR actually requires a vertex shader to compile
407 if (!useNvpr) { 407 if (!useNvpr) {
408 fVS.bindVertexAttributes(programID); 408 fVS.bindVertexAttributes(programID);
409 } 409 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 GL_CALL(DeleteProgram(programID)); 483 GL_CALL(DeleteProgram(programID));
484 cleanupShaders(shaderIDs); 484 cleanupShaders(shaderIDs);
485 } 485 }
486 void GrGLProgramBuilder::cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs) { 486 void GrGLProgramBuilder::cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs) {
487 for (int i = 0; i < shaderIDs.count(); ++i) { 487 for (int i = 0; i < shaderIDs.count(); ++i) {
488 GL_CALL(DeleteShader(shaderIDs[i])); 488 GL_CALL(DeleteShader(shaderIDs[i]));
489 } 489 }
490 } 490 }
491 491
492 GrGLProgram* GrGLProgramBuilder::createProgram(GrGLuint programID) { 492 GrGLProgram* GrGLProgramBuilder::createProgram(GrGLuint programID) {
493 return SkNEW_ARGS(GrGLProgram, (fGpu, fDesc, fUniformHandles, programID, fUn iforms, 493 return SkNEW_ARGS(GrGLProgram, (fGpu, this->desc(), fUniformHandles, program ID, fUniforms,
494 fGeometryProcessor, fXferProcessor, fFragmen tProcessors.get())); 494 fGeometryProcessor, fXferProcessor, fFragmen tProcessors.get()));
495 } 495 }
496 496
497 //////////////////////////////////////////////////////////////////////////////// /////////////////// 497 //////////////////////////////////////////////////////////////////////////////// ///////////////////
498 498
499 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { 499 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() {
500 int numProcs = fProcs.count(); 500 int numProcs = fProcs.count();
501 for (int e = 0; e < numProcs; ++e) { 501 for (int e = 0; e < numProcs; ++e) {
502 SkDELETE(fProcs[e]); 502 SkDELETE(fProcs[e]);
503 } 503 }
504 } 504 }
OLDNEW
« no previous file with comments | « src/gpu/gl/builders/GrGLProgramBuilder.h ('k') | src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698