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" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X) | 22 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X) |
23 | 23 |
24 // ES2 FS only guarantees mediump and lowp support | 24 // ES2 FS only guarantees mediump and lowp support |
25 static const GrGLShaderVar::Precision kDefaultFragmentPrecision = GrGLShaderVar:
:kMedium_Precision; | 25 static const GrGLShaderVar::Precision kDefaultFragmentPrecision = GrGLShaderVar:
:kMedium_Precision; |
26 | 26 |
27 ////////////////////////////////////////////////////////////////////////////// | 27 ////////////////////////////////////////////////////////////////////////////// |
28 | 28 |
29 const int GrGLProgramBuilder::kVarsPerBlock = 8; | 29 const int GrGLProgramBuilder::kVarsPerBlock = 8; |
30 | 30 |
31 GrGLProgram* GrGLProgramBuilder::CreateProgram(const GrOptDrawState& optState, | 31 GrGLProgram* GrGLProgramBuilder::CreateProgram(const GrOptDrawState& optState, |
32 const GrGLProgramDesc& desc, | |
33 GrGpu::DrawType drawType, | 32 GrGpu::DrawType drawType, |
34 GrGpuGL* gpu) { | 33 GrGpuGL* gpu) { |
35 // create a builder. This will be handed off to effects so they can use it
to add | 34 // create a builder. This will be handed off to effects so they can use it
to add |
36 // uniforms, varyings, textures, etc | 35 // uniforms, varyings, textures, etc |
37 SkAutoTDelete<GrGLProgramBuilder> builder(CreateProgramBuilder(desc, | 36 SkAutoTDelete<GrGLProgramBuilder> builder(CreateProgramBuilder(optState, |
38 optState, | |
39 drawType, | 37 drawType, |
40 optState.hasG
eometryProcessor(), | 38 optState.hasG
eometryProcessor(), |
41 gpu)); | 39 gpu)); |
42 | 40 |
43 GrGLProgramBuilder* pb = builder.get(); | 41 GrGLProgramBuilder* pb = builder.get(); |
44 const GrGLProgramDesc::KeyHeader& header = pb->header(); | 42 const GrGLProgramDesc::GLKeyHeader& header = pb->header(); |
45 | 43 |
46 // emit code to read the dst copy texture, if necessary | 44 // emit code to read the dst copy texture, if necessary |
47 if (GrGLFragmentShaderBuilder::kNoDstRead_DstReadKey != header.fDstReadKey | 45 if (GrGLFragmentShaderBuilder::kNoDstRead_DstReadKey != header.fDstReadKey |
48 && !gpu->glCaps().fbFetchSupport()) { | 46 && !gpu->glCaps().fbFetchSupport()) { |
49 pb->fFS.emitCodeToReadDstTexture(); | 47 pb->fFS.emitCodeToReadDstTexture(); |
50 } | 48 } |
51 | 49 |
52 // get the initial color and coverage to feed into the first effect in each
effect chain | 50 // get the initial color and coverage to feed into the first effect in each
effect chain |
53 GrGLSLExpr4 inputColor, inputCoverage; | 51 GrGLSLExpr4 inputColor, inputCoverage; |
54 pb->setupUniformColorAndCoverageIfNeeded(&inputColor, &inputCoverage); | 52 pb->setupUniformColorAndCoverageIfNeeded(&inputColor, &inputCoverage); |
(...skipping 15 matching lines...) Expand all Loading... |
70 } | 68 } |
71 } | 69 } |
72 | 70 |
73 pb->emitAndInstallProcs(optState, &inputColor, &inputCoverage); | 71 pb->emitAndInstallProcs(optState, &inputColor, &inputCoverage); |
74 | 72 |
75 if (hasVertexShader) { | 73 if (hasVertexShader) { |
76 pb->fVS.transformSkiaToGLCoords(); | 74 pb->fVS.transformSkiaToGLCoords(); |
77 } | 75 } |
78 | 76 |
79 // write the secondary color output if necessary | 77 // write the secondary color output if necessary |
80 if (GrOptDrawState::kNone_SecondaryOutputType != header.fSecondaryOutputType
) { | 78 if (GrGLProgramDesc::kNone_SecondaryOutputType != header.fSecondaryOutputTyp
e) { |
81 pb->fFS.enableSecondaryOutput(inputColor, inputCoverage); | 79 pb->fFS.enableSecondaryOutput(inputColor, inputCoverage); |
82 } | 80 } |
83 | 81 |
84 pb->fFS.combineColorAndCoverage(inputColor, inputCoverage); | 82 pb->fFS.combineColorAndCoverage(inputColor, inputCoverage); |
85 | 83 |
86 return pb->finalize(); | 84 return pb->finalize(); |
87 } | 85 } |
88 | 86 |
89 GrGLProgramBuilder* | 87 GrGLProgramBuilder* |
90 GrGLProgramBuilder::CreateProgramBuilder(const GrGLProgramDesc& desc, | 88 GrGLProgramBuilder::CreateProgramBuilder(const GrOptDrawState& optState, |
91 const GrOptDrawState& optState, | |
92 GrGpu::DrawType drawType, | 89 GrGpu::DrawType drawType, |
93 bool hasGeometryProcessor, | 90 bool hasGeometryProcessor, |
94 GrGpuGL* gpu) { | 91 GrGpuGL* gpu) { |
95 if (desc.getHeader().fUseFragShaderOnly) { | 92 const GrGLProgramDesc& desc = optState.desc().cast<GrGLProgramDesc>(); |
| 93 if (desc.header().fUseFragShaderOnly) { |
96 SkASSERT(gpu->glCaps().pathRenderingSupport()); | 94 SkASSERT(gpu->glCaps().pathRenderingSupport()); |
97 SkASSERT(gpu->glPathRendering()->texturingMode() == | 95 SkASSERT(gpu->glPathRendering()->texturingMode() == |
98 GrGLPathRendering::FixedFunction_TexturingMode); | 96 GrGLPathRendering::FixedFunction_TexturingMode); |
| 97 SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.header().fColorI
nput); |
| 98 SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.header().fCovera
geInput); |
99 SkASSERT(!hasGeometryProcessor); | 99 SkASSERT(!hasGeometryProcessor); |
100 return SkNEW_ARGS(GrGLLegacyNvprProgramBuilder, (gpu, optState, desc)); | 100 return SkNEW_ARGS(GrGLLegacyNvprProgramBuilder, (gpu, optState)); |
101 } else if (GrGpu::IsPathRenderingDrawType(drawType)) { | 101 } else if (GrGpu::IsPathRenderingDrawType(drawType)) { |
102 SkASSERT(gpu->glCaps().pathRenderingSupport()); | 102 SkASSERT(gpu->glCaps().pathRenderingSupport()); |
103 SkASSERT(gpu->glPathRendering()->texturingMode() == | 103 SkASSERT(gpu->glPathRendering()->texturingMode() == |
104 GrGLPathRendering::SeparableShaders_TexturingMode); | 104 GrGLPathRendering::SeparableShaders_TexturingMode); |
105 SkASSERT(!hasGeometryProcessor); | 105 SkASSERT(!hasGeometryProcessor); |
106 return SkNEW_ARGS(GrGLNvprProgramBuilder, (gpu, optState, desc)); | 106 return SkNEW_ARGS(GrGLNvprProgramBuilder, (gpu, optState)); |
107 } else { | 107 } else { |
108 return SkNEW_ARGS(GrGLProgramBuilder, (gpu, optState, desc)); | 108 return SkNEW_ARGS(GrGLProgramBuilder, (gpu, optState)); |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 ///////////////////////////////////////////////////////////////////////////// | 112 ///////////////////////////////////////////////////////////////////////////// |
113 | 113 |
114 GrGLProgramBuilder::GrGLProgramBuilder(GrGpuGL* gpu, | 114 GrGLProgramBuilder::GrGLProgramBuilder(GrGpuGL* gpu, const GrOptDrawState& optSt
ate) |
115 const GrOptDrawState& optState, | |
116 const GrGLProgramDesc& desc) | |
117 : fVS(this) | 115 : fVS(this) |
118 , fGS(this) | 116 , fGS(this) |
119 , fFS(this, desc) | 117 , fFS(this, optState.desc().cast<GrGLProgramDesc>().header().fFragPosKey) |
120 , fOutOfStage(true) | 118 , fOutOfStage(true) |
121 , fStageIndex(-1) | 119 , fStageIndex(-1) |
122 , fGeometryProcessor(NULL) | 120 , fGeometryProcessor(NULL) |
123 , fOptState(optState) | 121 , fOptState(optState) |
124 , fDesc(desc) | 122 , fDesc(optState.desc().cast<GrGLProgramDesc>()) |
125 , fGpu(gpu) | 123 , fGpu(gpu) |
126 , fUniforms(kVarsPerBlock) { | 124 , fUniforms(kVarsPerBlock) { |
127 } | 125 } |
128 | 126 |
129 void GrGLProgramBuilder::addVarying(GrSLType type, | 127 void GrGLProgramBuilder::addVarying(GrSLType type, |
130 const char* name, | 128 const char* name, |
131 const char** vsOutName, | 129 const char** vsOutName, |
132 const char** fsInName, | 130 const char** fsInName, |
133 GrGLShaderVar::Precision fsPrecision) { | 131 GrGLShaderVar::Precision fsPrecision) { |
134 SkString* fsInputName = fVS.addVarying(type, name, vsOutName); | 132 SkString* fsInputName = fVS.addVarying(type, name, vsOutName); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 222 |
225 void GrGLProgramBuilder::emitAndInstallProcs(const GrOptDrawState& optState, | 223 void GrGLProgramBuilder::emitAndInstallProcs(const GrOptDrawState& optState, |
226 GrGLSLExpr4* inputColor, | 224 GrGLSLExpr4* inputColor, |
227 GrGLSLExpr4* inputCoverage) { | 225 GrGLSLExpr4* inputCoverage) { |
228 fFragmentProcessors.reset(SkNEW(GrGLInstalledFragProcs)); | 226 fFragmentProcessors.reset(SkNEW(GrGLInstalledFragProcs)); |
229 int numProcs = optState.numFragmentStages(); | 227 int numProcs = optState.numFragmentStages(); |
230 this->emitAndInstallFragProcs(0, optState.numColorStages(), inputColor); | 228 this->emitAndInstallFragProcs(0, optState.numColorStages(), inputColor); |
231 if (optState.hasGeometryProcessor()) { | 229 if (optState.hasGeometryProcessor()) { |
232 const GrGeometryProcessor& gp = *optState.getGeometryProcessor(); | 230 const GrGeometryProcessor& gp = *optState.getGeometryProcessor(); |
233 fVS.emitAttributes(gp); | 231 fVS.emitAttributes(gp); |
234 ProcKeyProvider keyProvider(&fDesc, ProcKeyProvider::kGeometry_Processor
Type); | 232 ProcKeyProvider keyProvider(&fDesc, |
| 233 ProcKeyProvider::kGeometry_ProcessorType, |
| 234 GrGLProgramDesc::kEffectKeyOffsetsAndLengthO
ffset); |
235 GrGLSLExpr4 output; | 235 GrGLSLExpr4 output; |
236 this->emitAndInstallProc<GrGeometryProcessor>(gp, 0, keyProvider, *input
Coverage, &output); | 236 this->emitAndInstallProc<GrGeometryProcessor>(gp, 0, keyProvider, *input
Coverage, &output); |
237 *inputCoverage = output; | 237 *inputCoverage = output; |
238 } | 238 } |
239 this->emitAndInstallFragProcs(optState.numColorStages(), numProcs, inputCov
erage); | 239 this->emitAndInstallFragProcs(optState.numColorStages(), numProcs, inputCov
erage); |
240 } | 240 } |
241 | 241 |
242 void GrGLProgramBuilder::emitAndInstallFragProcs(int procOffset, int numProcs, G
rGLSLExpr4* inOut) { | 242 void GrGLProgramBuilder::emitAndInstallFragProcs(int procOffset, int numProcs, G
rGLSLExpr4* inOut) { |
243 ProcKeyProvider keyProvider(&fDesc, ProcKeyProvider::kFragment_ProcessorType
); | 243 ProcKeyProvider keyProvider(&fDesc, |
| 244 ProcKeyProvider::kFragment_ProcessorType, |
| 245 GrGLProgramDesc::kEffectKeyOffsetsAndLengthOffse
t); |
244 for (int e = procOffset; e < numProcs; ++e) { | 246 for (int e = procOffset; e < numProcs; ++e) { |
245 GrGLSLExpr4 output; | 247 GrGLSLExpr4 output; |
246 const GrFragmentStage& stage = fOptState.getFragmentStage(e); | 248 const GrFragmentStage& stage = fOptState.getFragmentStage(e); |
247 this->emitAndInstallProc<GrFragmentStage>(stage, e, keyProvider, *inOut,
&output); | 249 this->emitAndInstallProc<GrFragmentStage>(stage, e, keyProvider, *inOut,
&output); |
248 *inOut = output; | 250 *inOut = output; |
249 } | 251 } |
250 } | 252 } |
251 | 253 |
252 // TODO Processors cannot output zeros because an empty string is all 1s | 254 // TODO Processors cannot output zeros because an empty string is all 1s |
253 // the fix is to allow effects to take the GrGLSLExpr4 directly | 255 // the fix is to allow effects to take the GrGLSLExpr4 directly |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 } | 505 } |
504 | 506 |
505 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 507 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
506 | 508 |
507 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { | 509 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { |
508 int numProcs = fProcs.count(); | 510 int numProcs = fProcs.count(); |
509 for (int e = 0; e < numProcs; ++e) { | 511 for (int e = 0; e < numProcs; ++e) { |
510 SkDELETE(fProcs[e]); | 512 SkDELETE(fProcs[e]); |
511 } | 513 } |
512 } | 514 } |
OLD | NEW |