blob: de892b58d07133e3eff7e560fed7ad9203961267 [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
8#include "glsl/GrGLSLProgramBuilder.h"
9
Brian Salomon94efbf52016-11-29 13:43:05 -050010#include "GrCaps.h"
egdanielfa896322016-01-13 12:19:30 -080011#include "GrPipeline.h"
Robert Phillipsd0fe8752019-01-31 14:13:59 -050012#include "GrRenderTarget.h"
Brian Salomon94efbf52016-11-29 13:43:05 -050013#include "GrShaderCaps.h"
Brian Salomon739c5bf2016-11-07 09:53:44 -050014#include "GrTexturePriv.h"
egdanielfa896322016-01-13 12:19:30 -080015#include "glsl/GrGLSLFragmentProcessor.h"
16#include "glsl/GrGLSLGeometryProcessor.h"
egdaniel9f1d4152016-02-10 09:50:38 -080017#include "glsl/GrGLSLVarying.h"
egdanielfa896322016-01-13 12:19:30 -080018#include "glsl/GrGLSLXferProcessor.h"
Robert Phillipsfe8da172018-01-24 14:52:02 +000019#include "SkSLCompiler.h"
egdanielfa896322016-01-13 12:19:30 -080020
egdaniel8dcdedc2015-11-11 06:27:20 -080021const int GrGLSLProgramBuilder::kVarsPerBlock = 8;
22
Robert Phillipsd0fe8752019-01-31 14:13:59 -050023GrGLSLProgramBuilder::GrGLSLProgramBuilder(GrRenderTarget* renderTarget, GrSurfaceOrigin origin,
24 const GrPrimitiveProcessor& primProc,
Greg Daniel9a51a862018-11-30 10:18:14 -050025 const GrTextureProxy* const primProcProxies[],
Brian Salomonff168d92018-06-23 15:17:27 -040026 const GrPipeline& pipeline,
Ethan Nicholas38657112017-02-09 17:01:22 -050027 GrProgramDesc* desc)
Brian Salomonff168d92018-06-23 15:17:27 -040028 : fVS(this)
29 , fGS(this)
30 , fFS(this)
31 , fStageIndex(-1)
Robert Phillipsd0fe8752019-01-31 14:13:59 -050032 , fConfig(renderTarget->config())
33 , fNumColorSamples(renderTarget->numColorSamples())
34 , fOrigin(origin)
Brian Salomonff168d92018-06-23 15:17:27 -040035 , fPipeline(pipeline)
36 , fPrimProc(primProc)
Greg Daniel9a51a862018-11-30 10:18:14 -050037 , fPrimProcProxies(primProcProxies)
Brian Salomonff168d92018-06-23 15:17:27 -040038 , fDesc(desc)
39 , fGeometryProcessor(nullptr)
40 , fXferProcessor(nullptr)
Brian Salomonff168d92018-06-23 15:17:27 -040041 , fNumFragmentSamplers(0) {}
cdalton9c3f1432016-03-11 10:07:37 -080042
43void GrGLSLProgramBuilder::addFeature(GrShaderFlags shaders,
44 uint32_t featureBit,
45 const char* extensionName) {
46 if (shaders & kVertex_GrShaderFlag) {
47 fVS.addFeature(featureBit, extensionName);
48 }
49 if (shaders & kGeometry_GrShaderFlag) {
csmartdalton276cc412016-11-21 11:55:00 -070050 SkASSERT(this->primitiveProcessor().willUseGeoShader());
cdalton9c3f1432016-03-11 10:07:37 -080051 fGS.addFeature(featureBit, extensionName);
52 }
53 if (shaders & kFragment_GrShaderFlag) {
54 fFS.addFeature(featureBit, extensionName);
55 }
egdanielfa896322016-01-13 12:19:30 -080056}
57
Ethan Nicholas2983f402017-05-08 09:36:08 -040058bool GrGLSLProgramBuilder::emitAndInstallProcs() {
egdanielfa896322016-01-13 12:19:30 -080059 // First we loop over all of the installed processors and collect coord transforms. These will
60 // be sent to the GrGLSLPrimitiveProcessor in its emitCode function
Ethan Nicholas2983f402017-05-08 09:36:08 -040061 SkString inputColor;
62 SkString inputCoverage;
Greg Daniel9a51a862018-11-30 10:18:14 -050063 this->emitAndInstallPrimProc(&inputColor, &inputCoverage);
Ethan Nicholas2983f402017-05-08 09:36:08 -040064 this->emitAndInstallFragProcs(&inputColor, &inputCoverage);
65 this->emitAndInstallXferProc(inputColor, inputCoverage);
Brian Salomon42c456f2017-03-06 11:29:48 -050066 this->emitFSOutputSwizzle(this->pipeline().getXferProcessor().hasSecondaryOutput());
cdalton9c3f1432016-03-11 10:07:37 -080067
Brian Salomon559f5562017-11-15 14:28:33 -050068 return this->checkSamplerCounts();
egdanielfa896322016-01-13 12:19:30 -080069}
70
Greg Daniel9a51a862018-11-30 10:18:14 -050071void GrGLSLProgramBuilder::emitAndInstallPrimProc(SkString* outputColor,
Ethan Nicholas2983f402017-05-08 09:36:08 -040072 SkString* outputCoverage) {
Greg Daniel9a51a862018-11-30 10:18:14 -050073 const GrPrimitiveProcessor& proc = this->primitiveProcessor();
74 const GrTextureProxy* const* primProcProxies = this->primProcProxies();
75
egdanielfa896322016-01-13 12:19:30 -080076 // Program builders have a bit of state we need to clear with each effect
77 AutoStageAdvance adv(this);
78 this->nameExpression(outputColor, "outputColor");
79 this->nameExpression(outputCoverage, "outputCoverage");
80
csmartdalton936f81b2017-02-13 15:45:35 -070081 SkASSERT(!fUniformHandles.fRTAdjustmentUni.isValid());
Robert Phillipsfe8da172018-01-24 14:52:02 +000082 GrShaderFlags rtAdjustVisibility;
csmartdalton936f81b2017-02-13 15:45:35 -070083 if (proc.willUseGeoShader()) {
Robert Phillipsfe8da172018-01-24 14:52:02 +000084 rtAdjustVisibility = kGeometry_GrShaderFlag;
85 } else {
86 rtAdjustVisibility = kVertex_GrShaderFlag;
csmartdalton936f81b2017-02-13 15:45:35 -070087 }
Robert Phillipsfe8da172018-01-24 14:52:02 +000088 fUniformHandles.fRTAdjustmentUni = this->uniformHandler()->addUniform(
89 rtAdjustVisibility,
90 kFloat4_GrSLType,
91 SkSL::Compiler::RTADJUST_NAME);
csmartdalton936f81b2017-02-13 15:45:35 -070092 const char* rtAdjustName =
93 this->uniformHandler()->getUniformCStr(fUniformHandles.fRTAdjustmentUni);
94
egdanielfa896322016-01-13 12:19:30 -080095 // Enclose custom code in a block to avoid namespace conflicts
96 SkString openBrace;
97 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, proc.name());
98 fFS.codeAppend(openBrace.c_str());
99 fVS.codeAppendf("// Primitive Processor %s\n", proc.name());
100
101 SkASSERT(!fGeometryProcessor);
Robert Phillips369e8b72017-08-01 16:13:04 -0400102 fGeometryProcessor.reset(proc.createGLSLInstance(*this->shaderCaps()));
egdanielfa896322016-01-13 12:19:30 -0800103
Brian Salomone782f842018-07-31 13:53:11 -0400104 SkAutoSTMalloc<4, SamplerHandle> texSamplers(proc.numTextureSamplers());
105 for (int i = 0; i < proc.numTextureSamplers(); ++i) {
106 SkString name;
107 name.printf("TextureSampler_%d", i);
108 const auto& sampler = proc.textureSampler(i);
Greg Daniel9a51a862018-11-30 10:18:14 -0500109 const GrTexture* texture = primProcProxies[i]->peekTexture();
110 SkASSERT(sampler.textureType() == texture->texturePriv().textureType());
111 SkASSERT(sampler.config() == texture->config());
112 texSamplers[i] = this->emitSampler(texture,
113 sampler.samplerState(),
114 name.c_str());
Brian Salomone782f842018-07-31 13:53:11 -0400115 }
egdanielfa896322016-01-13 12:19:30 -0800116
bsalomona624bf32016-09-20 09:12:47 -0700117 GrGLSLPrimitiveProcessor::FPCoordTransformHandler transformHandler(fPipeline,
118 &fTransformedCoordVars);
egdanielfa896322016-01-13 12:19:30 -0800119 GrGLSLGeometryProcessor::EmitArgs args(&fVS,
csmartdalton276cc412016-11-21 11:55:00 -0700120 proc.willUseGeoShader() ? &fGS : nullptr,
egdanielfa896322016-01-13 12:19:30 -0800121 &fFS,
122 this->varyingHandler(),
123 this->uniformHandler(),
Brian Salomon94efbf52016-11-29 13:43:05 -0500124 this->shaderCaps(),
egdanielfa896322016-01-13 12:19:30 -0800125 proc,
126 outputColor->c_str(),
127 outputCoverage->c_str(),
csmartdalton936f81b2017-02-13 15:45:35 -0700128 rtAdjustName,
Brian Salomone782f842018-07-31 13:53:11 -0400129 texSamplers.get(),
bsalomona624bf32016-09-20 09:12:47 -0700130 &transformHandler);
egdanielfa896322016-01-13 12:19:30 -0800131 fGeometryProcessor->emitCode(args);
132
133 // We have to check that effects and the code they emit are consistent, ie if an effect
134 // asks for dst color, then the emit code needs to follow suit
cdalton87332102016-02-26 12:22:02 -0800135 SkDEBUGCODE(verify(proc);)
egdanielfa896322016-01-13 12:19:30 -0800136
137 fFS.codeAppend("}");
138}
139
Ethan Nicholas2983f402017-05-08 09:36:08 -0400140void GrGLSLProgramBuilder::emitAndInstallFragProcs(SkString* color, SkString* coverage) {
bsalomona624bf32016-09-20 09:12:47 -0700141 int transformedCoordVarsIdx = 0;
Ethan Nicholas2983f402017-05-08 09:36:08 -0400142 SkString** inOut = &color;
Brian Salomon4d3f5172018-06-07 14:42:52 -0400143 SkSTArray<8, std::unique_ptr<GrGLSLFragmentProcessor>> glslFragmentProcessors;
bsalomona624bf32016-09-20 09:12:47 -0700144 for (int i = 0; i < this->pipeline().numFragmentProcessors(); ++i) {
145 if (i == this->pipeline().numColorFragmentProcessors()) {
146 inOut = &coverage;
147 }
Ethan Nicholas2983f402017-05-08 09:36:08 -0400148 SkString output;
egdanielfa896322016-01-13 12:19:30 -0800149 const GrFragmentProcessor& fp = this->pipeline().getFragmentProcessor(i);
Brian Salomon4d3f5172018-06-07 14:42:52 -0400150 output = this->emitAndInstallFragProc(fp, i, transformedCoordVarsIdx, **inOut, output,
151 &glslFragmentProcessors);
bsalomona624bf32016-09-20 09:12:47 -0700152 GrFragmentProcessor::Iter iter(&fp);
153 while (const GrFragmentProcessor* fp = iter.next()) {
154 transformedCoordVarsIdx += fp->numCoordTransforms();
155 }
156 **inOut = output;
egdanielfa896322016-01-13 12:19:30 -0800157 }
Brian Salomon4d3f5172018-06-07 14:42:52 -0400158 fFragmentProcessorCnt = glslFragmentProcessors.count();
159 fFragmentProcessors.reset(new std::unique_ptr<GrGLSLFragmentProcessor>[fFragmentProcessorCnt]);
160 for (int i = 0; i < fFragmentProcessorCnt; ++i) {
161 fFragmentProcessors[i] = std::move(glslFragmentProcessors[i]);
162 }
egdanielfa896322016-01-13 12:19:30 -0800163}
164
165// TODO Processors cannot output zeros because an empty string is all 1s
Ethan Nicholas2983f402017-05-08 09:36:08 -0400166// the fix is to allow effects to take the SkString directly
Brian Salomon4d3f5172018-06-07 14:42:52 -0400167SkString GrGLSLProgramBuilder::emitAndInstallFragProc(
168 const GrFragmentProcessor& fp,
169 int index,
170 int transformedCoordVarsIdx,
171 const SkString& input,
172 SkString output,
173 SkTArray<std::unique_ptr<GrGLSLFragmentProcessor>>* glslFragmentProcessors) {
Ethan Nicholas2983f402017-05-08 09:36:08 -0400174 SkASSERT(input.size());
egdanielfa896322016-01-13 12:19:30 -0800175 // Program builders have a bit of state we need to clear with each effect
176 AutoStageAdvance adv(this);
Ethan Nicholas2983f402017-05-08 09:36:08 -0400177 this->nameExpression(&output, "output");
egdanielfa896322016-01-13 12:19:30 -0800178
179 // Enclose custom code in a block to avoid namespace conflicts
180 SkString openBrace;
181 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, fp.name());
182 fFS.codeAppend(openBrace.c_str());
183
184 GrGLSLFragmentProcessor* fragProc = fp.createGLSLInstance();
185
Brian Salomone782f842018-07-31 13:53:11 -0400186 SkSTArray<4, SamplerHandle> texSamplers;
187 GrFragmentProcessor::Iter fpIter(&fp);
188 int samplerIdx = 0;
189 while (const auto* subFP = fpIter.next()) {
190 for (int i = 0; i < subFP->numTextureSamplers(); ++i) {
191 SkString name;
192 name.printf("TextureSampler_%d", samplerIdx++);
193 const auto& sampler = subFP->textureSampler(i);
Greg Daniel9a51a862018-11-30 10:18:14 -0500194 texSamplers.emplace_back(this->emitSampler(sampler.peekTexture(),
195 sampler.samplerState(),
Greg Daniel0f70be82018-10-08 17:35:08 +0000196 name.c_str()));
Brian Salomone782f842018-07-31 13:53:11 -0400197 }
bsalomonb58a2b42016-09-26 06:55:02 -0700198 }
egdanielfa896322016-01-13 12:19:30 -0800199
bsalomona624bf32016-09-20 09:12:47 -0700200 const GrShaderVar* coordVars = fTransformedCoordVars.begin() + transformedCoordVarsIdx;
201 GrGLSLFragmentProcessor::TransformedCoordVars coords(&fp, coordVars);
Brian Salomone782f842018-07-31 13:53:11 -0400202 GrGLSLFragmentProcessor::TextureSamplers textureSamplers(&fp, texSamplers.begin());
egdanielfa896322016-01-13 12:19:30 -0800203 GrGLSLFragmentProcessor::EmitArgs args(&fFS,
204 this->uniformHandler(),
Brian Salomon94efbf52016-11-29 13:43:05 -0500205 this->shaderCaps(),
egdanielfa896322016-01-13 12:19:30 -0800206 fp,
Ethan Nicholas2983f402017-05-08 09:36:08 -0400207 output.c_str(),
208 input.c_str(),
bsalomona624bf32016-09-20 09:12:47 -0700209 coords,
Brian Salomon662ea4b2018-07-12 14:53:49 -0400210 textureSamplers);
dvonbeck9b03e7b2016-08-01 11:01:56 -0700211
egdanielfa896322016-01-13 12:19:30 -0800212 fragProc->emitCode(args);
213
214 // We have to check that effects and the code they emit are consistent, ie if an effect
215 // asks for dst color, then the emit code needs to follow suit
cdalton87332102016-02-26 12:22:02 -0800216 SkDEBUGCODE(verify(fp);)
Brian Salomon4d3f5172018-06-07 14:42:52 -0400217 glslFragmentProcessors->emplace_back(fragProc);
egdanielfa896322016-01-13 12:19:30 -0800218
219 fFS.codeAppend("}");
Ethan Nicholas2983f402017-05-08 09:36:08 -0400220 return output;
egdanielfa896322016-01-13 12:19:30 -0800221}
222
Ethan Nicholas2983f402017-05-08 09:36:08 -0400223void GrGLSLProgramBuilder::emitAndInstallXferProc(const SkString& colorIn,
224 const SkString& coverageIn) {
egdanielfa896322016-01-13 12:19:30 -0800225 // Program builders have a bit of state we need to clear with each effect
226 AutoStageAdvance adv(this);
227
228 SkASSERT(!fXferProcessor);
Brian Salomon18dfa982017-04-03 16:57:43 -0400229 const GrXferProcessor& xp = fPipeline.getXferProcessor();
Robert Phillips369e8b72017-08-01 16:13:04 -0400230 fXferProcessor.reset(xp.createGLSLInstance());
egdanielfa896322016-01-13 12:19:30 -0800231
232 // Enable dual source secondary output if we have one
233 if (xp.hasSecondaryOutput()) {
234 fFS.enableSecondaryOutput();
235 }
236
Brian Salomon94efbf52016-11-29 13:43:05 -0500237 if (this->shaderCaps()->mustDeclareFragmentShaderOutput()) {
egdanielfa896322016-01-13 12:19:30 -0800238 fFS.enableCustomOutput();
239 }
240
241 SkString openBrace;
242 openBrace.printf("{ // Xfer Processor: %s\n", xp.name());
243 fFS.codeAppend(openBrace.c_str());
244
Brian Salomon18dfa982017-04-03 16:57:43 -0400245 SamplerHandle dstTextureSamplerHandle;
246 GrSurfaceOrigin dstTextureOrigin = kTopLeft_GrSurfaceOrigin;
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400247
248 if (GrTexture* dstTexture = fPipeline.peekDstTexture()) {
Brian Salomon18dfa982017-04-03 16:57:43 -0400249 // GrProcessor::TextureSampler sampler(dstTexture);
250 SkString name("DstTextureSampler");
251 dstTextureSamplerHandle =
Greg Daniel9a51a862018-11-30 10:18:14 -0500252 this->emitSampler(dstTexture, GrSamplerState(), "DstTextureSampler");
Robert Phillips16d8ec62017-07-27 16:16:25 -0400253 dstTextureOrigin = fPipeline.dstTextureProxy()->origin();
Brian Salomon60dd8c72018-07-30 10:24:13 -0400254 SkASSERT(dstTexture->texturePriv().textureType() != GrTextureType::kExternal);
Brian Salomon18dfa982017-04-03 16:57:43 -0400255 }
egdanielfa896322016-01-13 12:19:30 -0800256
257 GrGLSLXferProcessor::EmitArgs args(&fFS,
258 this->uniformHandler(),
Brian Salomon94efbf52016-11-29 13:43:05 -0500259 this->shaderCaps(),
Brian Salomon18dfa982017-04-03 16:57:43 -0400260 xp,
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400261 colorIn.size() ? colorIn.c_str() : "float4(1)",
262 coverageIn.size() ? coverageIn.c_str() : "float4(1)",
egdanielfa896322016-01-13 12:19:30 -0800263 fFS.getPrimaryColorOutputName(),
264 fFS.getSecondaryColorOutputName(),
Brian Salomon18dfa982017-04-03 16:57:43 -0400265 dstTextureSamplerHandle,
266 dstTextureOrigin);
egdanielfa896322016-01-13 12:19:30 -0800267 fXferProcessor->emitCode(args);
268
269 // We have to check that effects and the code they emit are consistent, ie if an effect
270 // asks for dst color, then the emit code needs to follow suit
cdalton87332102016-02-26 12:22:02 -0800271 SkDEBUGCODE(verify(xp);)
egdanielfa896322016-01-13 12:19:30 -0800272 fFS.codeAppend("}");
273}
274
Greg Daniel9a51a862018-11-30 10:18:14 -0500275GrGLSLProgramBuilder::SamplerHandle GrGLSLProgramBuilder::emitSampler(const GrTexture* texture,
276 const GrSamplerState& state,
Greg Daniel0f70be82018-10-08 17:35:08 +0000277 const char* name) {
278 ++fNumFragmentSamplers;
Greg Daniel9a51a862018-11-30 10:18:14 -0500279 return this->uniformHandler()->addSampler(texture, state, name, this->shaderCaps());
Brian Salomonf9f45122016-11-29 11:59:17 -0500280}
281
egdanielfa896322016-01-13 12:19:30 -0800282void GrGLSLProgramBuilder::emitFSOutputSwizzle(bool hasSecondaryOutput) {
283 // Swizzle the fragment shader outputs if necessary.
284 GrSwizzle swizzle;
Ethan Nicholas38657112017-02-09 17:01:22 -0500285 swizzle.setFromKey(this->desc()->header().fOutputSwizzle);
egdanielfa896322016-01-13 12:19:30 -0800286 if (swizzle != GrSwizzle::RGBA()) {
287 fFS.codeAppendf("%s = %s.%s;", fFS.getPrimaryColorOutputName(),
288 fFS.getPrimaryColorOutputName(),
289 swizzle.c_str());
290 if (hasSecondaryOutput) {
291 fFS.codeAppendf("%s = %s.%s;", fFS.getSecondaryColorOutputName(),
292 fFS.getSecondaryColorOutputName(),
293 swizzle.c_str());
294 }
295 }
296}
297
cdalton9c3f1432016-03-11 10:07:37 -0800298bool GrGLSLProgramBuilder::checkSamplerCounts() {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500299 const GrShaderCaps& shaderCaps = *this->shaderCaps();
Brian Salomon1edc5b92016-11-29 13:43:46 -0500300 if (fNumFragmentSamplers > shaderCaps.maxFragmentSamplers()) {
cdalton9c3f1432016-03-11 10:07:37 -0800301 GrCapsDebugf(this->caps(), "Program would use too many fragment samplers\n");
302 return false;
303 }
cdalton9c3f1432016-03-11 10:07:37 -0800304 return true;
305}
306
cdalton87332102016-02-26 12:22:02 -0800307#ifdef SK_DEBUG
egdanielfa896322016-01-13 12:19:30 -0800308void GrGLSLProgramBuilder::verify(const GrPrimitiveProcessor& gp) {
egdanielfa896322016-01-13 12:19:30 -0800309}
310
311void GrGLSLProgramBuilder::verify(const GrXferProcessor& xp) {
312 SkASSERT(fFS.hasReadDstColor() == xp.willReadDstColor());
313}
314
315void GrGLSLProgramBuilder::verify(const GrFragmentProcessor& fp) {
egdaniel8dcdedc2015-11-11 06:27:20 -0800316}
cdalton87332102016-02-26 12:22:02 -0800317#endif
egdaniel8dcdedc2015-11-11 06:27:20 -0800318
319void GrGLSLProgramBuilder::nameVariable(SkString* out, char prefix, const char* name, bool mangle) {
320 if ('\0' == prefix) {
321 *out = name;
322 } else {
323 out->printf("%c%s", prefix, name);
324 }
325 if (mangle) {
326 if (out->endsWith('_')) {
327 // Names containing "__" are reserved.
328 out->append("x");
329 }
330 out->appendf("_Stage%d%s", fStageIndex, fFS.getMangleString().c_str());
331 }
332}
333
Ethan Nicholas2983f402017-05-08 09:36:08 -0400334void GrGLSLProgramBuilder::nameExpression(SkString* output, const char* baseName) {
egdanielfa896322016-01-13 12:19:30 -0800335 // create var to hold stage result. If we already have a valid output name, just use that
336 // otherwise create a new mangled one. This name is only valid if we are reordering stages
337 // and have to tell stage exactly where to put its output.
338 SkString outName;
Ethan Nicholas2983f402017-05-08 09:36:08 -0400339 if (output->size()) {
egdanielfa896322016-01-13 12:19:30 -0800340 outName = output->c_str();
341 } else {
342 this->nameVariable(&outName, '\0', baseName);
343 }
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400344 fFS.codeAppendf("half4 %s;", outName.c_str());
egdanielfa896322016-01-13 12:19:30 -0800345 *output = outName;
346}
347
cdalton5e58cee2016-02-11 12:49:47 -0800348void GrGLSLProgramBuilder::appendUniformDecls(GrShaderFlags visibility, SkString* out) const {
egdaniel7ea439b2015-12-03 09:20:44 -0800349 this->uniformHandler()->appendUniformDecls(visibility, out);
350}
351
Ethan Nicholascd700e92018-08-24 16:43:57 -0400352void GrGLSLProgramBuilder::addRTWidthUniform(const char* name) {
353 SkASSERT(!fUniformHandles.fRTWidthUni.isValid());
354 GrGLSLUniformHandler* uniformHandler = this->uniformHandler();
355 fUniformHandles.fRTWidthUni =
356 uniformHandler->internalAddUniformArray(kFragment_GrShaderFlag,
357 kHalf_GrSLType, kDefault_GrSLPrecision,
358 name, false, 0, nullptr);
359}
360
Greg Daniele6ab9982018-08-22 13:56:32 +0000361void GrGLSLProgramBuilder::addRTHeightUniform(const char* name) {
362 SkASSERT(!fUniformHandles.fRTHeightUni.isValid());
egdaniel7ea439b2015-12-03 09:20:44 -0800363 GrGLSLUniformHandler* uniformHandler = this->uniformHandler();
Greg Daniele6ab9982018-08-22 13:56:32 +0000364 fUniformHandles.fRTHeightUni =
cdalton5e58cee2016-02-11 12:49:47 -0800365 uniformHandler->internalAddUniformArray(kFragment_GrShaderFlag,
Greg Daniele6ab9982018-08-22 13:56:32 +0000366 kHalf_GrSLType, kDefault_GrSLPrecision,
Ethan Nicholas941e7e22016-12-12 15:33:30 -0500367 name, false, 0, nullptr);
egdaniel8dcdedc2015-11-11 06:27:20 -0800368}
369
egdaniel9f1d4152016-02-10 09:50:38 -0800370void GrGLSLProgramBuilder::finalizeShaders() {
371 this->varyingHandler()->finalize();
cdalton5e58cee2016-02-11 12:49:47 -0800372 fVS.finalize(kVertex_GrShaderFlag);
csmartdalton276cc412016-11-21 11:55:00 -0700373 if (this->primitiveProcessor().willUseGeoShader()) {
Brian Salomon94efbf52016-11-29 13:43:05 -0500374 SkASSERT(this->shaderCaps()->geometryShaderSupport());
csmartdalton276cc412016-11-21 11:55:00 -0700375 fGS.finalize(kGeometry_GrShaderFlag);
376 }
cdalton5e58cee2016-02-11 12:49:47 -0800377 fFS.finalize(kFragment_GrShaderFlag);
egdaniel9f1d4152016-02-10 09:50:38 -0800378}