blob: 9621e146e038d694b50f53e60cea719d0cfe3774 [file] [log] [blame]
egdaniel8dcdedc2015-11-11 06:27:20 -08001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
egdaniel8dcdedc2015-11-11 06:27:20 -08009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "src/gpu/GrCaps.h"
11#include "src/gpu/GrPipeline.h"
Brian Salomon201cdbb2019-08-14 17:00:30 -040012#include "src/gpu/GrRenderTarget.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/gpu/GrShaderCaps.h"
14#include "src/gpu/GrTexturePriv.h"
15#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
16#include "src/gpu/glsl/GrGLSLGeometryProcessor.h"
17#include "src/gpu/glsl/GrGLSLVarying.h"
18#include "src/gpu/glsl/GrGLSLXferProcessor.h"
19#include "src/sksl/SkSLCompiler.h"
egdanielfa896322016-01-13 12:19:30 -080020
egdaniel8dcdedc2015-11-11 06:27:20 -080021const int GrGLSLProgramBuilder::kVarsPerBlock = 8;
22
Robert Phillips65a77752019-10-02 15:22:24 -040023GrGLSLProgramBuilder::GrGLSLProgramBuilder(GrRenderTarget* renderTarget,
Robert Phillips901aff02019-10-08 12:32:56 -040024 const GrProgramInfo& programInfo,
25 const GrProgramDesc* desc)
Brian Salomonff168d92018-06-23 15:17:27 -040026 : fVS(this)
27 , fGS(this)
28 , fFS(this)
29 , fStageIndex(-1)
Chris Daltond7291ba2019-03-07 14:17:03 -070030 , fRenderTarget(renderTarget)
Robert Phillips901aff02019-10-08 12:32:56 -040031 , fProgramInfo(programInfo)
Brian Salomonff168d92018-06-23 15:17:27 -040032 , fDesc(desc)
33 , fGeometryProcessor(nullptr)
34 , fXferProcessor(nullptr)
Brian Salomonff168d92018-06-23 15:17:27 -040035 , fNumFragmentSamplers(0) {}
cdalton9c3f1432016-03-11 10:07:37 -080036
37void GrGLSLProgramBuilder::addFeature(GrShaderFlags shaders,
38 uint32_t featureBit,
39 const char* extensionName) {
40 if (shaders & kVertex_GrShaderFlag) {
41 fVS.addFeature(featureBit, extensionName);
42 }
43 if (shaders & kGeometry_GrShaderFlag) {
csmartdalton276cc412016-11-21 11:55:00 -070044 SkASSERT(this->primitiveProcessor().willUseGeoShader());
cdalton9c3f1432016-03-11 10:07:37 -080045 fGS.addFeature(featureBit, extensionName);
46 }
47 if (shaders & kFragment_GrShaderFlag) {
48 fFS.addFeature(featureBit, extensionName);
49 }
egdanielfa896322016-01-13 12:19:30 -080050}
51
Ethan Nicholas2983f402017-05-08 09:36:08 -040052bool GrGLSLProgramBuilder::emitAndInstallProcs() {
egdanielfa896322016-01-13 12:19:30 -080053 // First we loop over all of the installed processors and collect coord transforms. These will
54 // be sent to the GrGLSLPrimitiveProcessor in its emitCode function
Ethan Nicholas2983f402017-05-08 09:36:08 -040055 SkString inputColor;
56 SkString inputCoverage;
Greg Daniel9a51a862018-11-30 10:18:14 -050057 this->emitAndInstallPrimProc(&inputColor, &inputCoverage);
Ethan Nicholas2983f402017-05-08 09:36:08 -040058 this->emitAndInstallFragProcs(&inputColor, &inputCoverage);
59 this->emitAndInstallXferProc(inputColor, inputCoverage);
cdalton9c3f1432016-03-11 10:07:37 -080060
Brian Salomon559f5562017-11-15 14:28:33 -050061 return this->checkSamplerCounts();
egdanielfa896322016-01-13 12:19:30 -080062}
63
Greg Daniel9a51a862018-11-30 10:18:14 -050064void GrGLSLProgramBuilder::emitAndInstallPrimProc(SkString* outputColor,
Ethan Nicholas2983f402017-05-08 09:36:08 -040065 SkString* outputCoverage) {
Greg Daniel9a51a862018-11-30 10:18:14 -050066 const GrPrimitiveProcessor& proc = this->primitiveProcessor();
67 const GrTextureProxy* const* primProcProxies = this->primProcProxies();
68
egdanielfa896322016-01-13 12:19:30 -080069 // Program builders have a bit of state we need to clear with each effect
70 AutoStageAdvance adv(this);
71 this->nameExpression(outputColor, "outputColor");
72 this->nameExpression(outputCoverage, "outputCoverage");
73
csmartdalton936f81b2017-02-13 15:45:35 -070074 SkASSERT(!fUniformHandles.fRTAdjustmentUni.isValid());
Robert Phillipsfe8da172018-01-24 14:52:02 +000075 GrShaderFlags rtAdjustVisibility;
csmartdalton936f81b2017-02-13 15:45:35 -070076 if (proc.willUseGeoShader()) {
Robert Phillipsfe8da172018-01-24 14:52:02 +000077 rtAdjustVisibility = kGeometry_GrShaderFlag;
78 } else {
79 rtAdjustVisibility = kVertex_GrShaderFlag;
csmartdalton936f81b2017-02-13 15:45:35 -070080 }
Robert Phillipsfe8da172018-01-24 14:52:02 +000081 fUniformHandles.fRTAdjustmentUni = this->uniformHandler()->addUniform(
82 rtAdjustVisibility,
83 kFloat4_GrSLType,
84 SkSL::Compiler::RTADJUST_NAME);
csmartdalton936f81b2017-02-13 15:45:35 -070085 const char* rtAdjustName =
86 this->uniformHandler()->getUniformCStr(fUniformHandles.fRTAdjustmentUni);
87
egdanielfa896322016-01-13 12:19:30 -080088 // Enclose custom code in a block to avoid namespace conflicts
89 SkString openBrace;
90 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, proc.name());
91 fFS.codeAppend(openBrace.c_str());
92 fVS.codeAppendf("// Primitive Processor %s\n", proc.name());
93
94 SkASSERT(!fGeometryProcessor);
Robert Phillips369e8b72017-08-01 16:13:04 -040095 fGeometryProcessor.reset(proc.createGLSLInstance(*this->shaderCaps()));
egdanielfa896322016-01-13 12:19:30 -080096
Brian Salomone782f842018-07-31 13:53:11 -040097 SkAutoSTMalloc<4, SamplerHandle> texSamplers(proc.numTextureSamplers());
98 for (int i = 0; i < proc.numTextureSamplers(); ++i) {
99 SkString name;
100 name.printf("TextureSampler_%d", i);
101 const auto& sampler = proc.textureSampler(i);
Greg Daniel9a51a862018-11-30 10:18:14 -0500102 const GrTexture* texture = primProcProxies[i]->peekTexture();
103 SkASSERT(sampler.textureType() == texture->texturePriv().textureType());
Greg Daniel9a51a862018-11-30 10:18:14 -0500104 texSamplers[i] = this->emitSampler(texture,
105 sampler.samplerState(),
Greg Daniel2c3398d2019-06-19 11:58:01 -0400106 sampler.swizzle(),
Greg Daniel9a51a862018-11-30 10:18:14 -0500107 name.c_str());
Brian Salomone782f842018-07-31 13:53:11 -0400108 }
egdanielfa896322016-01-13 12:19:30 -0800109
Robert Phillips901aff02019-10-08 12:32:56 -0400110 GrGLSLPrimitiveProcessor::FPCoordTransformHandler transformHandler(this->pipeline(),
bsalomona624bf32016-09-20 09:12:47 -0700111 &fTransformedCoordVars);
egdanielfa896322016-01-13 12:19:30 -0800112 GrGLSLGeometryProcessor::EmitArgs args(&fVS,
csmartdalton276cc412016-11-21 11:55:00 -0700113 proc.willUseGeoShader() ? &fGS : nullptr,
egdanielfa896322016-01-13 12:19:30 -0800114 &fFS,
115 this->varyingHandler(),
116 this->uniformHandler(),
Brian Salomon94efbf52016-11-29 13:43:05 -0500117 this->shaderCaps(),
egdanielfa896322016-01-13 12:19:30 -0800118 proc,
119 outputColor->c_str(),
120 outputCoverage->c_str(),
csmartdalton936f81b2017-02-13 15:45:35 -0700121 rtAdjustName,
Brian Salomone782f842018-07-31 13:53:11 -0400122 texSamplers.get(),
bsalomona624bf32016-09-20 09:12:47 -0700123 &transformHandler);
egdanielfa896322016-01-13 12:19:30 -0800124 fGeometryProcessor->emitCode(args);
125
126 // We have to check that effects and the code they emit are consistent, ie if an effect
127 // asks for dst color, then the emit code needs to follow suit
cdalton87332102016-02-26 12:22:02 -0800128 SkDEBUGCODE(verify(proc);)
egdanielfa896322016-01-13 12:19:30 -0800129
130 fFS.codeAppend("}");
131}
132
Ethan Nicholas2983f402017-05-08 09:36:08 -0400133void GrGLSLProgramBuilder::emitAndInstallFragProcs(SkString* color, SkString* coverage) {
bsalomona624bf32016-09-20 09:12:47 -0700134 int transformedCoordVarsIdx = 0;
Ethan Nicholas2983f402017-05-08 09:36:08 -0400135 SkString** inOut = &color;
Brian Salomon4d3f5172018-06-07 14:42:52 -0400136 SkSTArray<8, std::unique_ptr<GrGLSLFragmentProcessor>> glslFragmentProcessors;
bsalomona624bf32016-09-20 09:12:47 -0700137 for (int i = 0; i < this->pipeline().numFragmentProcessors(); ++i) {
138 if (i == this->pipeline().numColorFragmentProcessors()) {
139 inOut = &coverage;
140 }
Ethan Nicholas2983f402017-05-08 09:36:08 -0400141 SkString output;
egdanielfa896322016-01-13 12:19:30 -0800142 const GrFragmentProcessor& fp = this->pipeline().getFragmentProcessor(i);
Brian Salomon4d3f5172018-06-07 14:42:52 -0400143 output = this->emitAndInstallFragProc(fp, i, transformedCoordVarsIdx, **inOut, output,
144 &glslFragmentProcessors);
bsalomona624bf32016-09-20 09:12:47 -0700145 GrFragmentProcessor::Iter iter(&fp);
146 while (const GrFragmentProcessor* fp = iter.next()) {
147 transformedCoordVarsIdx += fp->numCoordTransforms();
148 }
149 **inOut = output;
egdanielfa896322016-01-13 12:19:30 -0800150 }
Brian Salomon4d3f5172018-06-07 14:42:52 -0400151 fFragmentProcessorCnt = glslFragmentProcessors.count();
152 fFragmentProcessors.reset(new std::unique_ptr<GrGLSLFragmentProcessor>[fFragmentProcessorCnt]);
153 for (int i = 0; i < fFragmentProcessorCnt; ++i) {
154 fFragmentProcessors[i] = std::move(glslFragmentProcessors[i]);
155 }
egdanielfa896322016-01-13 12:19:30 -0800156}
157
158// TODO Processors cannot output zeros because an empty string is all 1s
Ethan Nicholas2983f402017-05-08 09:36:08 -0400159// the fix is to allow effects to take the SkString directly
Brian Salomon4d3f5172018-06-07 14:42:52 -0400160SkString GrGLSLProgramBuilder::emitAndInstallFragProc(
161 const GrFragmentProcessor& fp,
162 int index,
163 int transformedCoordVarsIdx,
164 const SkString& input,
165 SkString output,
166 SkTArray<std::unique_ptr<GrGLSLFragmentProcessor>>* glslFragmentProcessors) {
Ethan Nicholas2983f402017-05-08 09:36:08 -0400167 SkASSERT(input.size());
egdanielfa896322016-01-13 12:19:30 -0800168 // Program builders have a bit of state we need to clear with each effect
169 AutoStageAdvance adv(this);
Ethan Nicholas2983f402017-05-08 09:36:08 -0400170 this->nameExpression(&output, "output");
egdanielfa896322016-01-13 12:19:30 -0800171
172 // Enclose custom code in a block to avoid namespace conflicts
173 SkString openBrace;
174 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, fp.name());
175 fFS.codeAppend(openBrace.c_str());
176
177 GrGLSLFragmentProcessor* fragProc = fp.createGLSLInstance();
178
Brian Salomone782f842018-07-31 13:53:11 -0400179 SkSTArray<4, SamplerHandle> texSamplers;
180 GrFragmentProcessor::Iter fpIter(&fp);
181 int samplerIdx = 0;
182 while (const auto* subFP = fpIter.next()) {
183 for (int i = 0; i < subFP->numTextureSamplers(); ++i) {
184 SkString name;
185 name.printf("TextureSampler_%d", samplerIdx++);
186 const auto& sampler = subFP->textureSampler(i);
Greg Daniel9a51a862018-11-30 10:18:14 -0500187 texSamplers.emplace_back(this->emitSampler(sampler.peekTexture(),
188 sampler.samplerState(),
Greg Daniel2c3398d2019-06-19 11:58:01 -0400189 sampler.swizzle(),
Greg Daniel0f70be82018-10-08 17:35:08 +0000190 name.c_str()));
Brian Salomone782f842018-07-31 13:53:11 -0400191 }
bsalomonb58a2b42016-09-26 06:55:02 -0700192 }
egdanielfa896322016-01-13 12:19:30 -0800193
Ethan Nicholasd4efe682019-08-29 16:10:13 -0400194 const GrGLSLPrimitiveProcessor::TransformVar* coordVars = fTransformedCoordVars.begin() +
195 transformedCoordVarsIdx;
bsalomona624bf32016-09-20 09:12:47 -0700196 GrGLSLFragmentProcessor::TransformedCoordVars coords(&fp, coordVars);
Brian Salomone782f842018-07-31 13:53:11 -0400197 GrGLSLFragmentProcessor::TextureSamplers textureSamplers(&fp, texSamplers.begin());
egdanielfa896322016-01-13 12:19:30 -0800198 GrGLSLFragmentProcessor::EmitArgs args(&fFS,
199 this->uniformHandler(),
Brian Salomon94efbf52016-11-29 13:43:05 -0500200 this->shaderCaps(),
egdanielfa896322016-01-13 12:19:30 -0800201 fp,
Ethan Nicholas2983f402017-05-08 09:36:08 -0400202 output.c_str(),
203 input.c_str(),
bsalomona624bf32016-09-20 09:12:47 -0700204 coords,
Brian Salomon662ea4b2018-07-12 14:53:49 -0400205 textureSamplers);
Ethan Nicholas6ad52892019-05-03 13:13:42 +0000206
207 fragProc->emitCode(args);
egdanielfa896322016-01-13 12:19:30 -0800208
209 // We have to check that effects and the code they emit are consistent, ie if an effect
210 // asks for dst color, then the emit code needs to follow suit
cdalton87332102016-02-26 12:22:02 -0800211 SkDEBUGCODE(verify(fp);)
Brian Salomon4d3f5172018-06-07 14:42:52 -0400212 glslFragmentProcessors->emplace_back(fragProc);
egdanielfa896322016-01-13 12:19:30 -0800213
214 fFS.codeAppend("}");
Ethan Nicholas2983f402017-05-08 09:36:08 -0400215 return output;
egdanielfa896322016-01-13 12:19:30 -0800216}
217
Ethan Nicholas2983f402017-05-08 09:36:08 -0400218void GrGLSLProgramBuilder::emitAndInstallXferProc(const SkString& colorIn,
219 const SkString& coverageIn) {
egdanielfa896322016-01-13 12:19:30 -0800220 // Program builders have a bit of state we need to clear with each effect
221 AutoStageAdvance adv(this);
222
223 SkASSERT(!fXferProcessor);
Robert Phillips901aff02019-10-08 12:32:56 -0400224 const GrXferProcessor& xp = this->pipeline().getXferProcessor();
Robert Phillips369e8b72017-08-01 16:13:04 -0400225 fXferProcessor.reset(xp.createGLSLInstance());
egdanielfa896322016-01-13 12:19:30 -0800226
227 // Enable dual source secondary output if we have one
228 if (xp.hasSecondaryOutput()) {
229 fFS.enableSecondaryOutput();
230 }
231
Brian Salomon94efbf52016-11-29 13:43:05 -0500232 if (this->shaderCaps()->mustDeclareFragmentShaderOutput()) {
egdanielfa896322016-01-13 12:19:30 -0800233 fFS.enableCustomOutput();
234 }
235
236 SkString openBrace;
237 openBrace.printf("{ // Xfer Processor: %s\n", xp.name());
238 fFS.codeAppend(openBrace.c_str());
239
Brian Salomon18dfa982017-04-03 16:57:43 -0400240 SamplerHandle dstTextureSamplerHandle;
241 GrSurfaceOrigin dstTextureOrigin = kTopLeft_GrSurfaceOrigin;
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400242
Robert Phillips901aff02019-10-08 12:32:56 -0400243 if (GrTexture* dstTexture = this->pipeline().peekDstTexture()) {
Brian Salomon18dfa982017-04-03 16:57:43 -0400244 // GrProcessor::TextureSampler sampler(dstTexture);
Robert Phillips901aff02019-10-08 12:32:56 -0400245 SkASSERT(this->pipeline().dstTextureProxy());
246 const GrSwizzle& swizzle = this->pipeline().dstTextureProxy()->textureSwizzle();
Brian Salomon18dfa982017-04-03 16:57:43 -0400247 dstTextureSamplerHandle =
Greg Daniel2c3398d2019-06-19 11:58:01 -0400248 this->emitSampler(dstTexture, GrSamplerState(), swizzle, "DstTextureSampler");
Robert Phillips901aff02019-10-08 12:32:56 -0400249 dstTextureOrigin = this->pipeline().dstTextureProxy()->origin();
Brian Salomon60dd8c72018-07-30 10:24:13 -0400250 SkASSERT(dstTexture->texturePriv().textureType() != GrTextureType::kExternal);
Brian Salomon18dfa982017-04-03 16:57:43 -0400251 }
egdanielfa896322016-01-13 12:19:30 -0800252
Brian Salomonf19f9ca2019-09-18 15:54:26 -0400253 SkString finalInColor = colorIn.size() ? colorIn : SkString("float4(1)");
Brian Osman65cdd612019-03-14 17:01:57 -0400254
egdanielfa896322016-01-13 12:19:30 -0800255 GrGLSLXferProcessor::EmitArgs args(&fFS,
256 this->uniformHandler(),
Brian Salomon94efbf52016-11-29 13:43:05 -0500257 this->shaderCaps(),
Brian Salomon18dfa982017-04-03 16:57:43 -0400258 xp,
Brian Osman65cdd612019-03-14 17:01:57 -0400259 finalInColor.c_str(),
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400260 coverageIn.size() ? coverageIn.c_str() : "float4(1)",
egdanielfa896322016-01-13 12:19:30 -0800261 fFS.getPrimaryColorOutputName(),
262 fFS.getSecondaryColorOutputName(),
Brian Salomon18dfa982017-04-03 16:57:43 -0400263 dstTextureSamplerHandle,
Chris Dalton6b76df02019-04-08 11:01:34 -0600264 dstTextureOrigin,
Robert Phillips901aff02019-10-08 12:32:56 -0400265 this->header().fOutputSwizzle);
egdanielfa896322016-01-13 12:19:30 -0800266 fXferProcessor->emitCode(args);
267
268 // We have to check that effects and the code they emit are consistent, ie if an effect
269 // asks for dst color, then the emit code needs to follow suit
cdalton87332102016-02-26 12:22:02 -0800270 SkDEBUGCODE(verify(xp);)
egdanielfa896322016-01-13 12:19:30 -0800271 fFS.codeAppend("}");
272}
273
Greg Daniel9a51a862018-11-30 10:18:14 -0500274GrGLSLProgramBuilder::SamplerHandle GrGLSLProgramBuilder::emitSampler(const GrTexture* texture,
275 const GrSamplerState& state,
Greg Daniel2c3398d2019-06-19 11:58:01 -0400276 const GrSwizzle& swizzle,
Greg Daniel0f70be82018-10-08 17:35:08 +0000277 const char* name) {
278 ++fNumFragmentSamplers;
Greg Daniel2c3398d2019-06-19 11:58:01 -0400279 return this->uniformHandler()->addSampler(texture, state, swizzle, name, this->shaderCaps());
Brian Salomonf9f45122016-11-29 11:59:17 -0500280}
281
cdalton9c3f1432016-03-11 10:07:37 -0800282bool GrGLSLProgramBuilder::checkSamplerCounts() {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500283 const GrShaderCaps& shaderCaps = *this->shaderCaps();
Brian Salomon1edc5b92016-11-29 13:43:46 -0500284 if (fNumFragmentSamplers > shaderCaps.maxFragmentSamplers()) {
cdalton9c3f1432016-03-11 10:07:37 -0800285 GrCapsDebugf(this->caps(), "Program would use too many fragment samplers\n");
286 return false;
287 }
cdalton9c3f1432016-03-11 10:07:37 -0800288 return true;
289}
290
cdalton87332102016-02-26 12:22:02 -0800291#ifdef SK_DEBUG
egdanielfa896322016-01-13 12:19:30 -0800292void GrGLSLProgramBuilder::verify(const GrPrimitiveProcessor& gp) {
Chris Daltond7291ba2019-03-07 14:17:03 -0700293 SkASSERT(!fFS.fHasReadDstColorThisStage_DebugOnly);
294 SkASSERT(fFS.fUsedProcessorFeaturesThisStage_DebugOnly == gp.requestedFeatures());
egdanielfa896322016-01-13 12:19:30 -0800295}
296
297void GrGLSLProgramBuilder::verify(const GrFragmentProcessor& fp) {
Chris Daltond7291ba2019-03-07 14:17:03 -0700298 SkASSERT(!fFS.fHasReadDstColorThisStage_DebugOnly);
299 SkASSERT(fFS.fUsedProcessorFeaturesThisStage_DebugOnly == fp.requestedFeatures());
300}
301
302void GrGLSLProgramBuilder::verify(const GrXferProcessor& xp) {
303 SkASSERT(xp.willReadDstColor() == fFS.fHasReadDstColorThisStage_DebugOnly);
304 SkASSERT(fFS.fUsedProcessorFeaturesThisStage_DebugOnly == xp.requestedFeatures());
egdaniel8dcdedc2015-11-11 06:27:20 -0800305}
cdalton87332102016-02-26 12:22:02 -0800306#endif
egdaniel8dcdedc2015-11-11 06:27:20 -0800307
308void GrGLSLProgramBuilder::nameVariable(SkString* out, char prefix, const char* name, bool mangle) {
309 if ('\0' == prefix) {
310 *out = name;
311 } else {
312 out->printf("%c%s", prefix, name);
313 }
314 if (mangle) {
315 if (out->endsWith('_')) {
316 // Names containing "__" are reserved.
317 out->append("x");
318 }
319 out->appendf("_Stage%d%s", fStageIndex, fFS.getMangleString().c_str());
320 }
321}
322
Ethan Nicholas2983f402017-05-08 09:36:08 -0400323void GrGLSLProgramBuilder::nameExpression(SkString* output, const char* baseName) {
egdanielfa896322016-01-13 12:19:30 -0800324 // create var to hold stage result. If we already have a valid output name, just use that
325 // otherwise create a new mangled one. This name is only valid if we are reordering stages
326 // and have to tell stage exactly where to put its output.
327 SkString outName;
Ethan Nicholas2983f402017-05-08 09:36:08 -0400328 if (output->size()) {
egdanielfa896322016-01-13 12:19:30 -0800329 outName = output->c_str();
330 } else {
331 this->nameVariable(&outName, '\0', baseName);
332 }
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400333 fFS.codeAppendf("half4 %s;", outName.c_str());
egdanielfa896322016-01-13 12:19:30 -0800334 *output = outName;
335}
336
cdalton5e58cee2016-02-11 12:49:47 -0800337void GrGLSLProgramBuilder::appendUniformDecls(GrShaderFlags visibility, SkString* out) const {
egdaniel7ea439b2015-12-03 09:20:44 -0800338 this->uniformHandler()->appendUniformDecls(visibility, out);
339}
340
Ethan Nicholascd700e92018-08-24 16:43:57 -0400341void GrGLSLProgramBuilder::addRTWidthUniform(const char* name) {
Brian Osmanf7924452019-09-24 10:44:37 -0400342 SkASSERT(!fUniformHandles.fRTWidthUni.isValid());
343 GrGLSLUniformHandler* uniformHandler = this->uniformHandler();
344 fUniformHandles.fRTWidthUni =
Ethan Nicholas858fecc2019-03-07 13:19:18 -0500345 uniformHandler->internalAddUniformArray(kFragment_GrShaderFlag, kHalf_GrSLType, name,
346 false, 0, nullptr);
Ethan Nicholascd700e92018-08-24 16:43:57 -0400347}
348
Greg Daniele6ab9982018-08-22 13:56:32 +0000349void GrGLSLProgramBuilder::addRTHeightUniform(const char* name) {
Brian Osmanf7924452019-09-24 10:44:37 -0400350 SkASSERT(!fUniformHandles.fRTHeightUni.isValid());
351 GrGLSLUniformHandler* uniformHandler = this->uniformHandler();
352 fUniformHandles.fRTHeightUni =
Ethan Nicholas858fecc2019-03-07 13:19:18 -0500353 uniformHandler->internalAddUniformArray(kFragment_GrShaderFlag, kHalf_GrSLType, name,
354 false, 0, nullptr);
egdaniel8dcdedc2015-11-11 06:27:20 -0800355}
356
egdaniel9f1d4152016-02-10 09:50:38 -0800357void GrGLSLProgramBuilder::finalizeShaders() {
358 this->varyingHandler()->finalize();
cdalton5e58cee2016-02-11 12:49:47 -0800359 fVS.finalize(kVertex_GrShaderFlag);
csmartdalton276cc412016-11-21 11:55:00 -0700360 if (this->primitiveProcessor().willUseGeoShader()) {
Brian Salomon94efbf52016-11-29 13:43:05 -0500361 SkASSERT(this->shaderCaps()->geometryShaderSupport());
csmartdalton276cc412016-11-21 11:55:00 -0700362 fGS.finalize(kGeometry_GrShaderFlag);
363 }
cdalton5e58cee2016-02-11 12:49:47 -0800364 fFS.finalize(kFragment_GrShaderFlag);
egdaniel9f1d4152016-02-10 09:50:38 -0800365}