blob: 8cdf43dfa2cf17abfda97ec8df15059f788908e9 [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();
Robert Phillips66ae3042019-10-10 12:57:58 -040067
68 // Because all the texture properties must be consistent between all the dynamic and fixed
69 // primProc proxies, we just deal w/ the first set of dynamic proxies or the set of fixed
70 // proxies here.
71 const GrTextureProxy* const* primProcProxies = nullptr;
72 if (fProgramInfo.hasDynamicPrimProcTextures()) {
73 primProcProxies = fProgramInfo.dynamicPrimProcTextures(0);
74 } else if (fProgramInfo.hasFixedPrimProcTextures()) {
75 primProcProxies = fProgramInfo.fixedPrimProcTextures();
76 }
Greg Daniel9a51a862018-11-30 10:18:14 -050077
egdanielfa896322016-01-13 12:19:30 -080078 // Program builders have a bit of state we need to clear with each effect
79 AutoStageAdvance adv(this);
80 this->nameExpression(outputColor, "outputColor");
81 this->nameExpression(outputCoverage, "outputCoverage");
82
csmartdalton936f81b2017-02-13 15:45:35 -070083 SkASSERT(!fUniformHandles.fRTAdjustmentUni.isValid());
Robert Phillipsfe8da172018-01-24 14:52:02 +000084 GrShaderFlags rtAdjustVisibility;
csmartdalton936f81b2017-02-13 15:45:35 -070085 if (proc.willUseGeoShader()) {
Robert Phillipsfe8da172018-01-24 14:52:02 +000086 rtAdjustVisibility = kGeometry_GrShaderFlag;
87 } else {
88 rtAdjustVisibility = kVertex_GrShaderFlag;
csmartdalton936f81b2017-02-13 15:45:35 -070089 }
Robert Phillipsfe8da172018-01-24 14:52:02 +000090 fUniformHandles.fRTAdjustmentUni = this->uniformHandler()->addUniform(
91 rtAdjustVisibility,
92 kFloat4_GrSLType,
93 SkSL::Compiler::RTADJUST_NAME);
csmartdalton936f81b2017-02-13 15:45:35 -070094 const char* rtAdjustName =
95 this->uniformHandler()->getUniformCStr(fUniformHandles.fRTAdjustmentUni);
96
egdanielfa896322016-01-13 12:19:30 -080097 // Enclose custom code in a block to avoid namespace conflicts
98 SkString openBrace;
99 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, proc.name());
100 fFS.codeAppend(openBrace.c_str());
101 fVS.codeAppendf("// Primitive Processor %s\n", proc.name());
102
103 SkASSERT(!fGeometryProcessor);
Robert Phillips369e8b72017-08-01 16:13:04 -0400104 fGeometryProcessor.reset(proc.createGLSLInstance(*this->shaderCaps()));
egdanielfa896322016-01-13 12:19:30 -0800105
Brian Salomone782f842018-07-31 13:53:11 -0400106 SkAutoSTMalloc<4, SamplerHandle> texSamplers(proc.numTextureSamplers());
107 for (int i = 0; i < proc.numTextureSamplers(); ++i) {
108 SkString name;
109 name.printf("TextureSampler_%d", i);
110 const auto& sampler = proc.textureSampler(i);
Robert Phillips66ae3042019-10-10 12:57:58 -0400111 SkASSERT(sampler.textureType() == primProcProxies[i]->textureType());
112 texSamplers[i] = this->emitSampler(primProcProxies[i],
Greg Daniel9a51a862018-11-30 10:18:14 -0500113 sampler.samplerState(),
Greg Daniel2c3398d2019-06-19 11:58:01 -0400114 sampler.swizzle(),
Greg Daniel9a51a862018-11-30 10:18:14 -0500115 name.c_str());
Brian Salomone782f842018-07-31 13:53:11 -0400116 }
egdanielfa896322016-01-13 12:19:30 -0800117
Robert Phillips901aff02019-10-08 12:32:56 -0400118 GrGLSLPrimitiveProcessor::FPCoordTransformHandler transformHandler(this->pipeline(),
bsalomona624bf32016-09-20 09:12:47 -0700119 &fTransformedCoordVars);
egdanielfa896322016-01-13 12:19:30 -0800120 GrGLSLGeometryProcessor::EmitArgs args(&fVS,
csmartdalton276cc412016-11-21 11:55:00 -0700121 proc.willUseGeoShader() ? &fGS : nullptr,
egdanielfa896322016-01-13 12:19:30 -0800122 &fFS,
123 this->varyingHandler(),
124 this->uniformHandler(),
Brian Salomon94efbf52016-11-29 13:43:05 -0500125 this->shaderCaps(),
egdanielfa896322016-01-13 12:19:30 -0800126 proc,
127 outputColor->c_str(),
128 outputCoverage->c_str(),
csmartdalton936f81b2017-02-13 15:45:35 -0700129 rtAdjustName,
Brian Salomone782f842018-07-31 13:53:11 -0400130 texSamplers.get(),
bsalomona624bf32016-09-20 09:12:47 -0700131 &transformHandler);
egdanielfa896322016-01-13 12:19:30 -0800132 fGeometryProcessor->emitCode(args);
133
134 // We have to check that effects and the code they emit are consistent, ie if an effect
135 // asks for dst color, then the emit code needs to follow suit
cdalton87332102016-02-26 12:22:02 -0800136 SkDEBUGCODE(verify(proc);)
egdanielfa896322016-01-13 12:19:30 -0800137
138 fFS.codeAppend("}");
139}
140
Ethan Nicholas2983f402017-05-08 09:36:08 -0400141void GrGLSLProgramBuilder::emitAndInstallFragProcs(SkString* color, SkString* coverage) {
bsalomona624bf32016-09-20 09:12:47 -0700142 int transformedCoordVarsIdx = 0;
Ethan Nicholas2983f402017-05-08 09:36:08 -0400143 SkString** inOut = &color;
Brian Salomon4d3f5172018-06-07 14:42:52 -0400144 SkSTArray<8, std::unique_ptr<GrGLSLFragmentProcessor>> glslFragmentProcessors;
bsalomona624bf32016-09-20 09:12:47 -0700145 for (int i = 0; i < this->pipeline().numFragmentProcessors(); ++i) {
146 if (i == this->pipeline().numColorFragmentProcessors()) {
147 inOut = &coverage;
148 }
Ethan Nicholas2983f402017-05-08 09:36:08 -0400149 SkString output;
egdanielfa896322016-01-13 12:19:30 -0800150 const GrFragmentProcessor& fp = this->pipeline().getFragmentProcessor(i);
Brian Salomon4d3f5172018-06-07 14:42:52 -0400151 output = this->emitAndInstallFragProc(fp, i, transformedCoordVarsIdx, **inOut, output,
152 &glslFragmentProcessors);
bsalomona624bf32016-09-20 09:12:47 -0700153 GrFragmentProcessor::Iter iter(&fp);
154 while (const GrFragmentProcessor* fp = iter.next()) {
155 transformedCoordVarsIdx += fp->numCoordTransforms();
156 }
157 **inOut = output;
egdanielfa896322016-01-13 12:19:30 -0800158 }
Brian Salomon4d3f5172018-06-07 14:42:52 -0400159 fFragmentProcessorCnt = glslFragmentProcessors.count();
160 fFragmentProcessors.reset(new std::unique_ptr<GrGLSLFragmentProcessor>[fFragmentProcessorCnt]);
161 for (int i = 0; i < fFragmentProcessorCnt; ++i) {
162 fFragmentProcessors[i] = std::move(glslFragmentProcessors[i]);
163 }
egdanielfa896322016-01-13 12:19:30 -0800164}
165
166// TODO Processors cannot output zeros because an empty string is all 1s
Ethan Nicholas2983f402017-05-08 09:36:08 -0400167// the fix is to allow effects to take the SkString directly
Brian Salomon4d3f5172018-06-07 14:42:52 -0400168SkString GrGLSLProgramBuilder::emitAndInstallFragProc(
169 const GrFragmentProcessor& fp,
170 int index,
171 int transformedCoordVarsIdx,
172 const SkString& input,
173 SkString output,
174 SkTArray<std::unique_ptr<GrGLSLFragmentProcessor>>* glslFragmentProcessors) {
Ethan Nicholas2983f402017-05-08 09:36:08 -0400175 SkASSERT(input.size());
egdanielfa896322016-01-13 12:19:30 -0800176 // Program builders have a bit of state we need to clear with each effect
177 AutoStageAdvance adv(this);
Ethan Nicholas2983f402017-05-08 09:36:08 -0400178 this->nameExpression(&output, "output");
egdanielfa896322016-01-13 12:19:30 -0800179
180 // Enclose custom code in a block to avoid namespace conflicts
181 SkString openBrace;
182 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, fp.name());
183 fFS.codeAppend(openBrace.c_str());
184
185 GrGLSLFragmentProcessor* fragProc = fp.createGLSLInstance();
186
Brian Salomone782f842018-07-31 13:53:11 -0400187 SkSTArray<4, SamplerHandle> texSamplers;
188 GrFragmentProcessor::Iter fpIter(&fp);
189 int samplerIdx = 0;
190 while (const auto* subFP = fpIter.next()) {
191 for (int i = 0; i < subFP->numTextureSamplers(); ++i) {
192 SkString name;
193 name.printf("TextureSampler_%d", samplerIdx++);
194 const auto& sampler = subFP->textureSampler(i);
Robert Phillips66ae3042019-10-10 12:57:58 -0400195 texSamplers.emplace_back(this->emitSampler(sampler.proxy(),
Greg Daniel9a51a862018-11-30 10:18:14 -0500196 sampler.samplerState(),
Greg Daniel2c3398d2019-06-19 11:58:01 -0400197 sampler.swizzle(),
Greg Daniel0f70be82018-10-08 17:35:08 +0000198 name.c_str()));
Brian Salomone782f842018-07-31 13:53:11 -0400199 }
bsalomonb58a2b42016-09-26 06:55:02 -0700200 }
egdanielfa896322016-01-13 12:19:30 -0800201
Ethan Nicholasd4efe682019-08-29 16:10:13 -0400202 const GrGLSLPrimitiveProcessor::TransformVar* coordVars = fTransformedCoordVars.begin() +
203 transformedCoordVarsIdx;
bsalomona624bf32016-09-20 09:12:47 -0700204 GrGLSLFragmentProcessor::TransformedCoordVars coords(&fp, coordVars);
Brian Salomone782f842018-07-31 13:53:11 -0400205 GrGLSLFragmentProcessor::TextureSamplers textureSamplers(&fp, texSamplers.begin());
egdanielfa896322016-01-13 12:19:30 -0800206 GrGLSLFragmentProcessor::EmitArgs args(&fFS,
207 this->uniformHandler(),
Brian Salomon94efbf52016-11-29 13:43:05 -0500208 this->shaderCaps(),
egdanielfa896322016-01-13 12:19:30 -0800209 fp,
Ethan Nicholas2983f402017-05-08 09:36:08 -0400210 output.c_str(),
211 input.c_str(),
bsalomona624bf32016-09-20 09:12:47 -0700212 coords,
Brian Salomon662ea4b2018-07-12 14:53:49 -0400213 textureSamplers);
Ethan Nicholas6ad52892019-05-03 13:13:42 +0000214
215 fragProc->emitCode(args);
egdanielfa896322016-01-13 12:19:30 -0800216
217 // We have to check that effects and the code they emit are consistent, ie if an effect
218 // asks for dst color, then the emit code needs to follow suit
cdalton87332102016-02-26 12:22:02 -0800219 SkDEBUGCODE(verify(fp);)
Brian Salomon4d3f5172018-06-07 14:42:52 -0400220 glslFragmentProcessors->emplace_back(fragProc);
egdanielfa896322016-01-13 12:19:30 -0800221
222 fFS.codeAppend("}");
Ethan Nicholas2983f402017-05-08 09:36:08 -0400223 return output;
egdanielfa896322016-01-13 12:19:30 -0800224}
225
Ethan Nicholas2983f402017-05-08 09:36:08 -0400226void GrGLSLProgramBuilder::emitAndInstallXferProc(const SkString& colorIn,
227 const SkString& coverageIn) {
egdanielfa896322016-01-13 12:19:30 -0800228 // Program builders have a bit of state we need to clear with each effect
229 AutoStageAdvance adv(this);
230
231 SkASSERT(!fXferProcessor);
Robert Phillips901aff02019-10-08 12:32:56 -0400232 const GrXferProcessor& xp = this->pipeline().getXferProcessor();
Robert Phillips369e8b72017-08-01 16:13:04 -0400233 fXferProcessor.reset(xp.createGLSLInstance());
egdanielfa896322016-01-13 12:19:30 -0800234
235 // Enable dual source secondary output if we have one
236 if (xp.hasSecondaryOutput()) {
237 fFS.enableSecondaryOutput();
238 }
239
Brian Salomon94efbf52016-11-29 13:43:05 -0500240 if (this->shaderCaps()->mustDeclareFragmentShaderOutput()) {
egdanielfa896322016-01-13 12:19:30 -0800241 fFS.enableCustomOutput();
242 }
243
244 SkString openBrace;
245 openBrace.printf("{ // Xfer Processor: %s\n", xp.name());
246 fFS.codeAppend(openBrace.c_str());
247
Brian Salomon18dfa982017-04-03 16:57:43 -0400248 SamplerHandle dstTextureSamplerHandle;
249 GrSurfaceOrigin dstTextureOrigin = kTopLeft_GrSurfaceOrigin;
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400250
Robert Phillips66ae3042019-10-10 12:57:58 -0400251 if (GrTextureProxy* dstTextureProxy = this->pipeline().dstTextureProxy()) {
Brian Salomon18dfa982017-04-03 16:57:43 -0400252 // GrProcessor::TextureSampler sampler(dstTexture);
Robert Phillips66ae3042019-10-10 12:57:58 -0400253 const GrSwizzle& swizzle = dstTextureProxy->textureSwizzle();
254 dstTextureSamplerHandle = this->emitSampler(dstTextureProxy, GrSamplerState(),
255 swizzle, "DstTextureSampler");
256 dstTextureOrigin = dstTextureProxy->origin();
257 SkASSERT(dstTextureProxy->textureType() != GrTextureType::kExternal);
Brian Salomon18dfa982017-04-03 16:57:43 -0400258 }
egdanielfa896322016-01-13 12:19:30 -0800259
Brian Salomonf19f9ca2019-09-18 15:54:26 -0400260 SkString finalInColor = colorIn.size() ? colorIn : SkString("float4(1)");
Brian Osman65cdd612019-03-14 17:01:57 -0400261
egdanielfa896322016-01-13 12:19:30 -0800262 GrGLSLXferProcessor::EmitArgs args(&fFS,
263 this->uniformHandler(),
Brian Salomon94efbf52016-11-29 13:43:05 -0500264 this->shaderCaps(),
Brian Salomon18dfa982017-04-03 16:57:43 -0400265 xp,
Brian Osman65cdd612019-03-14 17:01:57 -0400266 finalInColor.c_str(),
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400267 coverageIn.size() ? coverageIn.c_str() : "float4(1)",
egdanielfa896322016-01-13 12:19:30 -0800268 fFS.getPrimaryColorOutputName(),
269 fFS.getSecondaryColorOutputName(),
Brian Salomon18dfa982017-04-03 16:57:43 -0400270 dstTextureSamplerHandle,
Chris Dalton6b76df02019-04-08 11:01:34 -0600271 dstTextureOrigin,
Robert Phillipsd5c1f342019-10-14 09:50:05 -0400272 this->pipeline().outputSwizzle());
egdanielfa896322016-01-13 12:19:30 -0800273 fXferProcessor->emitCode(args);
274
275 // We have to check that effects and the code they emit are consistent, ie if an effect
276 // asks for dst color, then the emit code needs to follow suit
cdalton87332102016-02-26 12:22:02 -0800277 SkDEBUGCODE(verify(xp);)
egdanielfa896322016-01-13 12:19:30 -0800278 fFS.codeAppend("}");
279}
280
Robert Phillips66ae3042019-10-10 12:57:58 -0400281GrGLSLProgramBuilder::SamplerHandle GrGLSLProgramBuilder::emitSampler(const GrTextureProxy* texture,
Greg Daniel9a51a862018-11-30 10:18:14 -0500282 const GrSamplerState& state,
Greg Daniel2c3398d2019-06-19 11:58:01 -0400283 const GrSwizzle& swizzle,
Greg Daniel0f70be82018-10-08 17:35:08 +0000284 const char* name) {
285 ++fNumFragmentSamplers;
Greg Daniel2c3398d2019-06-19 11:58:01 -0400286 return this->uniformHandler()->addSampler(texture, state, swizzle, name, this->shaderCaps());
Brian Salomonf9f45122016-11-29 11:59:17 -0500287}
288
cdalton9c3f1432016-03-11 10:07:37 -0800289bool GrGLSLProgramBuilder::checkSamplerCounts() {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500290 const GrShaderCaps& shaderCaps = *this->shaderCaps();
Brian Salomon1edc5b92016-11-29 13:43:46 -0500291 if (fNumFragmentSamplers > shaderCaps.maxFragmentSamplers()) {
cdalton9c3f1432016-03-11 10:07:37 -0800292 GrCapsDebugf(this->caps(), "Program would use too many fragment samplers\n");
293 return false;
294 }
cdalton9c3f1432016-03-11 10:07:37 -0800295 return true;
296}
297
cdalton87332102016-02-26 12:22:02 -0800298#ifdef SK_DEBUG
egdanielfa896322016-01-13 12:19:30 -0800299void GrGLSLProgramBuilder::verify(const GrPrimitiveProcessor& gp) {
Chris Daltond7291ba2019-03-07 14:17:03 -0700300 SkASSERT(!fFS.fHasReadDstColorThisStage_DebugOnly);
301 SkASSERT(fFS.fUsedProcessorFeaturesThisStage_DebugOnly == gp.requestedFeatures());
egdanielfa896322016-01-13 12:19:30 -0800302}
303
304void GrGLSLProgramBuilder::verify(const GrFragmentProcessor& fp) {
Chris Daltond7291ba2019-03-07 14:17:03 -0700305 SkASSERT(!fFS.fHasReadDstColorThisStage_DebugOnly);
306 SkASSERT(fFS.fUsedProcessorFeaturesThisStage_DebugOnly == fp.requestedFeatures());
307}
308
309void GrGLSLProgramBuilder::verify(const GrXferProcessor& xp) {
310 SkASSERT(xp.willReadDstColor() == fFS.fHasReadDstColorThisStage_DebugOnly);
311 SkASSERT(fFS.fUsedProcessorFeaturesThisStage_DebugOnly == xp.requestedFeatures());
egdaniel8dcdedc2015-11-11 06:27:20 -0800312}
cdalton87332102016-02-26 12:22:02 -0800313#endif
egdaniel8dcdedc2015-11-11 06:27:20 -0800314
315void GrGLSLProgramBuilder::nameVariable(SkString* out, char prefix, const char* name, bool mangle) {
316 if ('\0' == prefix) {
317 *out = name;
318 } else {
319 out->printf("%c%s", prefix, name);
320 }
321 if (mangle) {
322 if (out->endsWith('_')) {
323 // Names containing "__" are reserved.
324 out->append("x");
325 }
326 out->appendf("_Stage%d%s", fStageIndex, fFS.getMangleString().c_str());
327 }
328}
329
Ethan Nicholas2983f402017-05-08 09:36:08 -0400330void GrGLSLProgramBuilder::nameExpression(SkString* output, const char* baseName) {
egdanielfa896322016-01-13 12:19:30 -0800331 // create var to hold stage result. If we already have a valid output name, just use that
332 // otherwise create a new mangled one. This name is only valid if we are reordering stages
333 // and have to tell stage exactly where to put its output.
334 SkString outName;
Ethan Nicholas2983f402017-05-08 09:36:08 -0400335 if (output->size()) {
egdanielfa896322016-01-13 12:19:30 -0800336 outName = output->c_str();
337 } else {
338 this->nameVariable(&outName, '\0', baseName);
339 }
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400340 fFS.codeAppendf("half4 %s;", outName.c_str());
egdanielfa896322016-01-13 12:19:30 -0800341 *output = outName;
342}
343
cdalton5e58cee2016-02-11 12:49:47 -0800344void GrGLSLProgramBuilder::appendUniformDecls(GrShaderFlags visibility, SkString* out) const {
egdaniel7ea439b2015-12-03 09:20:44 -0800345 this->uniformHandler()->appendUniformDecls(visibility, out);
346}
347
Ethan Nicholascd700e92018-08-24 16:43:57 -0400348void GrGLSLProgramBuilder::addRTWidthUniform(const char* name) {
Brian Osmanf7924452019-09-24 10:44:37 -0400349 SkASSERT(!fUniformHandles.fRTWidthUni.isValid());
350 GrGLSLUniformHandler* uniformHandler = this->uniformHandler();
351 fUniformHandles.fRTWidthUni =
Ethan Nicholas858fecc2019-03-07 13:19:18 -0500352 uniformHandler->internalAddUniformArray(kFragment_GrShaderFlag, kHalf_GrSLType, name,
353 false, 0, nullptr);
Ethan Nicholascd700e92018-08-24 16:43:57 -0400354}
355
Greg Daniele6ab9982018-08-22 13:56:32 +0000356void GrGLSLProgramBuilder::addRTHeightUniform(const char* name) {
Brian Osmanf7924452019-09-24 10:44:37 -0400357 SkASSERT(!fUniformHandles.fRTHeightUni.isValid());
358 GrGLSLUniformHandler* uniformHandler = this->uniformHandler();
359 fUniformHandles.fRTHeightUni =
Ethan Nicholas858fecc2019-03-07 13:19:18 -0500360 uniformHandler->internalAddUniformArray(kFragment_GrShaderFlag, kHalf_GrSLType, name,
361 false, 0, nullptr);
egdaniel8dcdedc2015-11-11 06:27:20 -0800362}
363
egdaniel9f1d4152016-02-10 09:50:38 -0800364void GrGLSLProgramBuilder::finalizeShaders() {
365 this->varyingHandler()->finalize();
cdalton5e58cee2016-02-11 12:49:47 -0800366 fVS.finalize(kVertex_GrShaderFlag);
csmartdalton276cc412016-11-21 11:55:00 -0700367 if (this->primitiveProcessor().willUseGeoShader()) {
Brian Salomon94efbf52016-11-29 13:43:05 -0500368 SkASSERT(this->shaderCaps()->geometryShaderSupport());
csmartdalton276cc412016-11-21 11:55:00 -0700369 fGS.finalize(kGeometry_GrShaderFlag);
370 }
cdalton5e58cee2016-02-11 12:49:47 -0800371 fFS.finalize(kFragment_GrShaderFlag);
egdaniel9f1d4152016-02-10 09:50:38 -0800372}