OLD | NEW |
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 Loading... |
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 GrGLShaderVar::Precision fsPrecision) { | 100 GrGLShaderVar::Precision fsPrecision) { |
107 SkASSERT(varying); | 101 SkASSERT(varying); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 } | 249 } |
256 | 250 |
257 fFragmentProcessors.reset(SkNEW(GrGLInstalledFragProcs)); | 251 fFragmentProcessors.reset(SkNEW(GrGLInstalledFragProcs)); |
258 int numProcs = fOptState.numFragmentStages(); | 252 int numProcs = fOptState.numFragmentStages(); |
259 this->emitAndInstallFragProcs(0, fOptState.numColorStages(), inputColor); | 253 this->emitAndInstallFragProcs(0, fOptState.numColorStages(), inputColor); |
260 this->emitAndInstallFragProcs(fOptState.numColorStages(), numProcs, inputCo
verage); | 254 this->emitAndInstallFragProcs(fOptState.numColorStages(), numProcs, inputCo
verage); |
261 | 255 |
262 if (fOptState.hasGeometryProcessor()) { | 256 if (fOptState.hasGeometryProcessor()) { |
263 fVS.transformToNormalizedDeviceSpace(); | 257 fVS.transformToNormalizedDeviceSpace(); |
264 } | 258 } |
| 259 |
| 260 this->emitAndInstallXferProc(*fOptState.getXferProcessor(), *inputColor, *in
putCoverage); |
265 } | 261 } |
266 | 262 |
267 void GrGLProgramBuilder::emitAndInstallFragProcs(int procOffset, | 263 void GrGLProgramBuilder::emitAndInstallFragProcs(int procOffset, |
268 int numProcs, | 264 int numProcs, |
269 GrGLSLExpr4* inOut) { | 265 GrGLSLExpr4* inOut) { |
270 for (int e = procOffset; e < numProcs; ++e) { | 266 for (int e = procOffset; e < numProcs; ++e) { |
271 GrGLSLExpr4 output; | 267 GrGLSLExpr4 output; |
272 const GrPendingFragmentStage& stage = fOptState.getFragmentStage(e); | 268 const GrPendingFragmentStage& stage = fOptState.getFragmentStage(e); |
273 this->emitAndInstallProc(stage, e, *inOut, &output); | 269 this->emitAndInstallProc(stage, e, *inOut, &output); |
274 *inOut = output; | 270 *inOut = output; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 this->emitSamplers(gp, &samplers, fGeometryProcessor); | 359 this->emitSamplers(gp, &samplers, fGeometryProcessor); |
364 | 360 |
365 GrGLGeometryProcessor::EmitArgs args(this, gp, bt, outColor, outCoverage, sa
mplers); | 361 GrGLGeometryProcessor::EmitArgs args(this, gp, bt, outColor, outCoverage, sa
mplers); |
366 fGeometryProcessor->fGLProc->emitCode(args); | 362 fGeometryProcessor->fGLProc->emitCode(args); |
367 | 363 |
368 // We have to check that effects and the code they emit are consistent, ie i
f an effect | 364 // We have to check that effects and the code they emit are consistent, ie i
f an effect |
369 // asks for dst color, then the emit code needs to follow suit | 365 // asks for dst color, then the emit code needs to follow suit |
370 verify(gp); | 366 verify(gp); |
371 } | 367 } |
372 | 368 |
| 369 void GrGLProgramBuilder::emitAndInstallXferProc(const GrXferProcessor& xp, |
| 370 const GrGLSLExpr4& colorIn, |
| 371 const GrGLSLExpr4& coverageIn) { |
| 372 // Program builders have a bit of state we need to clear with each effect |
| 373 AutoStageAdvance adv(this); |
| 374 |
| 375 SkASSERT(!fXferProcessor); |
| 376 fXferProcessor = SkNEW(GrGLInstalledXferProc); |
| 377 |
| 378 fXferProcessor->fGLProc.reset(xp.createGLInstance()); |
| 379 |
| 380 // Enable dual source secondary output if we have one |
| 381 if (xp.hasSecondaryOutput()) { |
| 382 fFS.enableSecondaryOutput(); |
| 383 } |
| 384 |
| 385 // On any post 1.10 GLSL supporting GPU, we declare custom output |
| 386 if (k110_GrGLSLGeneration != fFS.fProgramBuilder->gpu()->glslGeneration()) { |
| 387 fFS.enableCustomOutput(); |
| 388 } |
| 389 |
| 390 SkString openBrace; |
| 391 openBrace.printf("{ // Xfer Processor: %s\n", xp.name()); |
| 392 fFS.codeAppend(openBrace.c_str()); |
| 393 |
| 394 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(xp.numTextures()); |
| 395 this->emitSamplers(xp, &samplers, fXferProcessor); |
| 396 |
| 397 GrGLXferProcessor::EmitArgs args(this, xp, colorIn.c_str(), coverageIn.c_str
(), |
| 398 fFS.getPrimaryColorOutputName(), |
| 399 fFS.getSecondaryColorOutputName(), samplers
); |
| 400 fXferProcessor->fGLProc->emitCode(args); |
| 401 |
| 402 // We have to check that effects and the code they emit are consistent, ie i
f an effect |
| 403 // asks for dst color, then the emit code needs to follow suit |
| 404 verify(xp); |
| 405 fFS.codeAppend("}"); |
| 406 } |
| 407 |
373 void GrGLProgramBuilder::verify(const GrGeometryProcessor& gp) { | 408 void GrGLProgramBuilder::verify(const GrGeometryProcessor& gp) { |
374 SkASSERT(fFS.hasReadFragmentPosition() == gp.willReadFragmentPosition()); | 409 SkASSERT(fFS.hasReadFragmentPosition() == gp.willReadFragmentPosition()); |
375 } | 410 } |
376 | 411 |
| 412 void GrGLProgramBuilder::verify(const GrXferProcessor& xp) { |
| 413 // TODO: Once will readDst is only xp enable this assert and remove it from
the |
| 414 // FragmentProcessor verify() |
| 415 //SkASSERT(fFS.hasReadDstColor() == xp.willReadDstColor()); |
| 416 } |
| 417 |
377 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) { | 418 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) { |
378 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition()); | 419 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition()); |
379 SkASSERT(fFS.hasReadDstColor() == fp.willReadDstColor()); | 420 SkASSERT(fFS.hasReadDstColor() == fp.willReadDstColor()); |
380 } | 421 } |
381 | 422 |
382 void GrGLProgramBuilder::emitTransforms(const GrPendingFragmentStage& stage, | 423 void GrGLProgramBuilder::emitTransforms(const GrPendingFragmentStage& stage, |
383 GrGLProcessor::TransformedCoordsArray* o
utCoords, | 424 GrGLProcessor::TransformedCoordsArray* o
utCoords, |
384 GrGLInstalledFragProc* ifp) { | 425 GrGLInstalledFragProc* ifp) { |
385 const GrFragmentProcessor* processor = stage.getProcessor(); | 426 const GrFragmentProcessor* processor = stage.getProcessor(); |
386 int numTransforms = processor->numTransforms(); | 427 int numTransforms = processor->numTransforms(); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 cleanupShaders(shaderIDs); | 576 cleanupShaders(shaderIDs); |
536 } | 577 } |
537 void GrGLProgramBuilder::cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs) { | 578 void GrGLProgramBuilder::cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs) { |
538 for (int i = 0; i < shaderIDs.count(); ++i) { | 579 for (int i = 0; i < shaderIDs.count(); ++i) { |
539 GL_CALL(DeleteShader(shaderIDs[i])); | 580 GL_CALL(DeleteShader(shaderIDs[i])); |
540 } | 581 } |
541 } | 582 } |
542 | 583 |
543 GrGLProgram* GrGLProgramBuilder::createProgram(GrGLuint programID) { | 584 GrGLProgram* GrGLProgramBuilder::createProgram(GrGLuint programID) { |
544 return SkNEW_ARGS(GrGLProgram, (fGpu, fDesc, fUniformHandles, programID, fUn
iforms, | 585 return SkNEW_ARGS(GrGLProgram, (fGpu, fDesc, fUniformHandles, programID, fUn
iforms, |
545 fGeometryProcessor, fFragmentProcessors.get(
))); | 586 fGeometryProcessor, fXferProcessor, fFragmen
tProcessors.get())); |
546 } | 587 } |
547 | 588 |
548 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 589 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
549 | 590 |
550 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { | 591 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { |
551 int numProcs = fProcs.count(); | 592 int numProcs = fProcs.count(); |
552 for (int e = 0; e < numProcs; ++e) { | 593 for (int e = 0; e < numProcs; ++e) { |
553 SkDELETE(fProcs[e]); | 594 SkDELETE(fProcs[e]); |
554 } | 595 } |
555 } | 596 } |
OLD | NEW |