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

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

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