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

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

Issue 789343002: Revert of Create xfer processor backend. (Closed) Base URL: https://skia.googlesource.com/skia.git@xferBlendSolo
Patch Set: Created 6 years 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') | tests/GLProgramsTest.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 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"
13 #include "../GrGpuGL.h" 12 #include "../GrGpuGL.h"
14 #include "GrCoordTransform.h" 13 #include "GrCoordTransform.h"
15 #include "GrGLLegacyNvprProgramBuilder.h" 14 #include "GrGLLegacyNvprProgramBuilder.h"
16 #include "GrGLNvprProgramBuilder.h" 15 #include "GrGLNvprProgramBuilder.h"
17 #include "GrGLProgramBuilder.h" 16 #include "GrGLProgramBuilder.h"
18 #include "GrTexture.h" 17 #include "GrTexture.h"
19 #include "SkRTConf.h" 18 #include "SkRTConf.h"
20 #include "SkTraceEvent.h" 19 #include "SkTraceEvent.h"
21 20
22 #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X) 21 #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X)
(...skipping 26 matching lines...) Expand all
49 48
50 // TODO: Once all stages can handle taking a float or vec4 and correctly han dling them we can 49 // TODO: Once all stages can handle taking a float or vec4 and correctly han dling them we can
51 // remove this cast to a vec4. 50 // remove this cast to a vec4.
52 GrGLSLExpr4 inputCoverageVec4; 51 GrGLSLExpr4 inputCoverageVec4;
53 if (inputCoverage.isValid()) { 52 if (inputCoverage.isValid()) {
54 inputCoverageVec4 = GrGLSLExpr4::VectorCast(inputCoverage); 53 inputCoverageVec4 = GrGLSLExpr4::VectorCast(inputCoverage);
55 } 54 }
56 55
57 pb->emitAndInstallProcs(&inputColor, &inputCoverageVec4); 56 pb->emitAndInstallProcs(&inputColor, &inputCoverageVec4);
58 57
58 // write the secondary color output if necessary
59 if (GrProgramDesc::kNone_SecondaryOutputType != header.fSecondaryOutputType) {
60 pb->fFS.enableSecondaryOutput(inputColor, inputCoverageVec4);
61 }
62
63 pb->fFS.combineColorAndCoverage(inputColor, inputCoverageVec4);
64
59 return pb->finalize(); 65 return pb->finalize();
60 } 66 }
61 67
62 GrGLProgramBuilder* GrGLProgramBuilder::CreateProgramBuilder(const GrOptDrawStat e& optState, 68 GrGLProgramBuilder*
63 bool hasGeometryPro cessor, 69 GrGLProgramBuilder::CreateProgramBuilder(const GrOptDrawState& optState,
64 GrGpuGL* gpu) { 70 bool hasGeometryProcessor,
71 GrGpuGL* gpu) {
65 const GrProgramDesc& desc = optState.programDesc(); 72 const GrProgramDesc& desc = optState.programDesc();
66 if (GrGLProgramDescBuilder::GetHeader(desc).fUseNvpr) { 73 if (GrGLProgramDescBuilder::GetHeader(desc).fUseNvpr) {
67 SkASSERT(gpu->glCaps().pathRenderingSupport()); 74 SkASSERT(gpu->glCaps().pathRenderingSupport());
68 SkASSERT(GrProgramDesc::kAttribute_ColorInput != desc.header().fColorInp ut); 75 SkASSERT(GrProgramDesc::kAttribute_ColorInput != desc.header().fColorInp ut);
69 SkASSERT(GrProgramDesc::kAttribute_ColorInput != desc.header().fCoverage Input); 76 SkASSERT(GrProgramDesc::kAttribute_ColorInput != desc.header().fCoverage Input);
70 SkASSERT(!hasGeometryProcessor); 77 SkASSERT(!hasGeometryProcessor);
71 if (gpu->glPathRendering()->texturingMode() == 78 if (gpu->glPathRendering()->texturingMode() ==
72 GrGLPathRendering::FixedFunction_TexturingMode) { 79 GrGLPathRendering::FixedFunction_TexturingMode) {
73 return SkNEW_ARGS(GrGLLegacyNvprProgramBuilder, (gpu, optState)); 80 return SkNEW_ARGS(GrGLLegacyNvprProgramBuilder, (gpu, optState));
74 } else { 81 } else {
75 return SkNEW_ARGS(GrGLNvprProgramBuilder, (gpu, optState)); 82 return SkNEW_ARGS(GrGLNvprProgramBuilder, (gpu, optState));
76 } 83 }
77 } else { 84 } else {
78 return SkNEW_ARGS(GrGLProgramBuilder, (gpu, optState)); 85 return SkNEW_ARGS(GrGLProgramBuilder, (gpu, optState));
79 } 86 }
80 } 87 }
81 88
82 ///////////////////////////////////////////////////////////////////////////// 89 /////////////////////////////////////////////////////////////////////////////
83 90
84 GrGLProgramBuilder::GrGLProgramBuilder(GrGpuGL* gpu, const GrOptDrawState& optSt ate) 91 GrGLProgramBuilder::GrGLProgramBuilder(GrGpuGL* gpu, const GrOptDrawState& optSt ate)
85 : fVS(this) 92 : fVS(this)
86 , fGS(this) 93 , fGS(this)
87 , fFS(this, optState.programDesc().header().fFragPosKey) 94 , fFS(this, optState.programDesc().header().fFragPosKey)
88 , fOutOfStage(true) 95 , fOutOfStage(true)
89 , fStageIndex(-1) 96 , fStageIndex(-1)
90 , fGeometryProcessor(NULL) 97 , fGeometryProcessor(NULL)
91 , fXferProcessor(NULL)
92 , fOptState(optState) 98 , fOptState(optState)
93 , fDesc(optState.programDesc()) 99 , fDesc(optState.programDesc())
94 , fGpu(gpu) 100 , fGpu(gpu)
95 , fUniforms(kVarsPerBlock) { 101 , fUniforms(kVarsPerBlock) {
96 } 102 }
97 103
98 void GrGLProgramBuilder::addVarying(const char* name, 104 void GrGLProgramBuilder::addVarying(const char* name,
99 GrGLVarying* varying, 105 GrGLVarying* varying,
100 GrSLPrecision fsPrecision) { 106 GrSLPrecision fsPrecision) {
101 SkASSERT(varying); 107 SkASSERT(varying);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 249 }
244 250
245 fFragmentProcessors.reset(SkNEW(GrGLInstalledFragProcs)); 251 fFragmentProcessors.reset(SkNEW(GrGLInstalledFragProcs));
246 int numProcs = fOptState.numFragmentStages(); 252 int numProcs = fOptState.numFragmentStages();
247 this->emitAndInstallFragProcs(0, fOptState.numColorStages(), inputColor); 253 this->emitAndInstallFragProcs(0, fOptState.numColorStages(), inputColor);
248 this->emitAndInstallFragProcs(fOptState.numColorStages(), numProcs, inputCo verage); 254 this->emitAndInstallFragProcs(fOptState.numColorStages(), numProcs, inputCo verage);
249 255
250 if (fOptState.hasGeometryProcessor()) { 256 if (fOptState.hasGeometryProcessor()) {
251 fVS.transformToNormalizedDeviceSpace(); 257 fVS.transformToNormalizedDeviceSpace();
252 } 258 }
253
254 this->emitAndInstallXferProc(*fOptState.getXferProcessor(), *inputColor, *in putCoverage);
255 } 259 }
256 260
257 void GrGLProgramBuilder::emitAndInstallFragProcs(int procOffset, 261 void GrGLProgramBuilder::emitAndInstallFragProcs(int procOffset,
258 int numProcs, 262 int numProcs,
259 GrGLSLExpr4* inOut) { 263 GrGLSLExpr4* inOut) {
260 for (int e = procOffset; e < numProcs; ++e) { 264 for (int e = procOffset; e < numProcs; ++e) {
261 GrGLSLExpr4 output; 265 GrGLSLExpr4 output;
262 const GrPendingFragmentStage& stage = fOptState.getFragmentStage(e); 266 const GrPendingFragmentStage& stage = fOptState.getFragmentStage(e);
263 this->emitAndInstallProc(stage, e, *inOut, &output); 267 this->emitAndInstallProc(stage, e, *inOut, &output);
264 *inOut = output; 268 *inOut = output;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 this->emitSamplers(gp, &samplers, fGeometryProcessor); 357 this->emitSamplers(gp, &samplers, fGeometryProcessor);
354 358
355 GrGLGeometryProcessor::EmitArgs args(this, gp, bt, outColor, outCoverage, sa mplers); 359 GrGLGeometryProcessor::EmitArgs args(this, gp, bt, outColor, outCoverage, sa mplers);
356 fGeometryProcessor->fGLProc->emitCode(args); 360 fGeometryProcessor->fGLProc->emitCode(args);
357 361
358 // We have to check that effects and the code they emit are consistent, ie i f an effect 362 // We have to check that effects and the code they emit are consistent, ie i f an effect
359 // asks for dst color, then the emit code needs to follow suit 363 // asks for dst color, then the emit code needs to follow suit
360 verify(gp); 364 verify(gp);
361 } 365 }
362 366
363 void GrGLProgramBuilder::emitAndInstallXferProc(const GrXferProcessor& xp,
364 const GrGLSLExpr4& colorIn,
365 const GrGLSLExpr4& coverageIn) {
366 // Program builders have a bit of state we need to clear with each effect
367 AutoStageAdvance adv(this);
368
369 SkASSERT(!fXferProcessor);
370 fXferProcessor = SkNEW(GrGLInstalledXferProc);
371
372 fXferProcessor->fGLProc.reset(xp.createGLInstance());
373
374 // Enable dual source secondary output if we have one
375 if (xp.hasSecondaryOutput()) {
376 fFS.enableSecondaryOutput();
377 }
378
379 // On any post 1.10 GLSL supporting GPU, we declare custom output
380 if (k110_GrGLSLGeneration != fFS.fProgramBuilder->gpu()->glslGeneration()) {
381 fFS.enableCustomOutput();
382 }
383
384 SkString openBrace;
385 openBrace.printf("{ // Xfer Processor: %s\n", xp.name());
386 fFS.codeAppend(openBrace.c_str());
387
388 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(xp.numTextures());
389 this->emitSamplers(xp, &samplers, fXferProcessor);
390
391 GrGLXferProcessor::EmitArgs args(this, xp, colorIn.c_str(), coverageIn.c_str (),
392 fFS.getPrimaryColorOutputName(),
393 fFS.getSecondaryColorOutputName(), samplers );
394 fXferProcessor->fGLProc->emitCode(args);
395
396 // We have to check that effects and the code they emit are consistent, ie i f an effect
397 // asks for dst color, then the emit code needs to follow suit
398 verify(xp);
399 fFS.codeAppend("}");
400 }
401
402 void GrGLProgramBuilder::verify(const GrGeometryProcessor& gp) { 367 void GrGLProgramBuilder::verify(const GrGeometryProcessor& gp) {
403 SkASSERT(fFS.hasReadFragmentPosition() == gp.willReadFragmentPosition()); 368 SkASSERT(fFS.hasReadFragmentPosition() == gp.willReadFragmentPosition());
404 } 369 }
405 370
406 void GrGLProgramBuilder::verify(const GrXferProcessor& xp) {
407 // TODO: Once will readDst is only xp enable this assert and remove it from the
408 // FragmentProcessor verify()
409 //SkASSERT(fFS.hasReadDstColor() == xp.willReadDstColor());
410 }
411
412 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) { 371 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) {
413 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition()); 372 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition());
414 SkASSERT(fFS.hasReadDstColor() == fp.willReadDstColor()); 373 SkASSERT(fFS.hasReadDstColor() == fp.willReadDstColor());
415 } 374 }
416 375
417 void GrGLProgramBuilder::emitTransforms(const GrPendingFragmentStage& stage, 376 void GrGLProgramBuilder::emitTransforms(const GrPendingFragmentStage& stage,
418 GrGLProcessor::TransformedCoordsArray* o utCoords, 377 GrGLProcessor::TransformedCoordsArray* o utCoords,
419 GrGLInstalledFragProc* ifp) { 378 GrGLInstalledFragProc* ifp) {
420 const GrFragmentProcessor* processor = stage.getProcessor(); 379 const GrFragmentProcessor* processor = stage.getProcessor();
421 int numTransforms = processor->numTransforms(); 380 int numTransforms = processor->numTransforms();
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 cleanupShaders(shaderIDs); 532 cleanupShaders(shaderIDs);
574 } 533 }
575 void GrGLProgramBuilder::cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs) { 534 void GrGLProgramBuilder::cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs) {
576 for (int i = 0; i < shaderIDs.count(); ++i) { 535 for (int i = 0; i < shaderIDs.count(); ++i) {
577 GL_CALL(DeleteShader(shaderIDs[i])); 536 GL_CALL(DeleteShader(shaderIDs[i]));
578 } 537 }
579 } 538 }
580 539
581 GrGLProgram* GrGLProgramBuilder::createProgram(GrGLuint programID) { 540 GrGLProgram* GrGLProgramBuilder::createProgram(GrGLuint programID) {
582 return SkNEW_ARGS(GrGLProgram, (fGpu, fDesc, fUniformHandles, programID, fUn iforms, 541 return SkNEW_ARGS(GrGLProgram, (fGpu, fDesc, fUniformHandles, programID, fUn iforms,
583 fGeometryProcessor, fXferProcessor, fFragmen tProcessors.get())); 542 fGeometryProcessor, fFragmentProcessors.get( )));
584 } 543 }
585 544
586 //////////////////////////////////////////////////////////////////////////////// /////////////////// 545 //////////////////////////////////////////////////////////////////////////////// ///////////////////
587 546
588 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { 547 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() {
589 int numProcs = fProcs.count(); 548 int numProcs = fProcs.count();
590 for (int e = 0; e < numProcs; ++e) { 549 for (int e = 0; e < numProcs; ++e) {
591 SkDELETE(fProcs[e]); 550 SkDELETE(fProcs[e]);
592 } 551 }
593 } 552 }
OLDNEW
« no previous file with comments | « src/gpu/gl/builders/GrGLProgramBuilder.h ('k') | tests/GLProgramsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698