blob: 2c41312cd9546557c88b6d5464ba96d69c4ce8cc [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 "include/gpu/GrRenderTarget.h"
11#include "src/gpu/GrCaps.h"
12#include "src/gpu/GrPipeline.h"
13#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 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)
Chris Daltond7291ba2019-03-07 14:17:03 -070032 , fRenderTarget(renderTarget)
Robert Phillipsd0fe8752019-01-31 14:13:59 -050033 , fOrigin(origin)
Brian Salomonff168d92018-06-23 15:17:27 -040034 , fPipeline(pipeline)
35 , fPrimProc(primProc)
Greg Daniel9a51a862018-11-30 10:18:14 -050036 , fPrimProcProxies(primProcProxies)
Brian Salomonff168d92018-06-23 15:17:27 -040037 , fDesc(desc)
38 , fGeometryProcessor(nullptr)
39 , fXferProcessor(nullptr)
Brian Salomonff168d92018-06-23 15:17:27 -040040 , fNumFragmentSamplers(0) {}
cdalton9c3f1432016-03-11 10:07:37 -080041
42void GrGLSLProgramBuilder::addFeature(GrShaderFlags shaders,
43 uint32_t featureBit,
44 const char* extensionName) {
45 if (shaders & kVertex_GrShaderFlag) {
46 fVS.addFeature(featureBit, extensionName);
47 }
48 if (shaders & kGeometry_GrShaderFlag) {
csmartdalton276cc412016-11-21 11:55:00 -070049 SkASSERT(this->primitiveProcessor().willUseGeoShader());
cdalton9c3f1432016-03-11 10:07:37 -080050 fGS.addFeature(featureBit, extensionName);
51 }
52 if (shaders & kFragment_GrShaderFlag) {
53 fFS.addFeature(featureBit, extensionName);
54 }
egdanielfa896322016-01-13 12:19:30 -080055}
56
Ethan Nicholas2983f402017-05-08 09:36:08 -040057bool GrGLSLProgramBuilder::emitAndInstallProcs() {
egdanielfa896322016-01-13 12:19:30 -080058 // First we loop over all of the installed processors and collect coord transforms. These will
59 // be sent to the GrGLSLPrimitiveProcessor in its emitCode function
Ethan Nicholas2983f402017-05-08 09:36:08 -040060 SkString inputColor;
61 SkString inputCoverage;
Greg Daniel9a51a862018-11-30 10:18:14 -050062 this->emitAndInstallPrimProc(&inputColor, &inputCoverage);
Ethan Nicholas2983f402017-05-08 09:36:08 -040063 this->emitAndInstallFragProcs(&inputColor, &inputCoverage);
64 this->emitAndInstallXferProc(inputColor, inputCoverage);
cdalton9c3f1432016-03-11 10:07:37 -080065
Brian Salomon559f5562017-11-15 14:28:33 -050066 return this->checkSamplerCounts();
egdanielfa896322016-01-13 12:19:30 -080067}
68
Greg Daniel9a51a862018-11-30 10:18:14 -050069void GrGLSLProgramBuilder::emitAndInstallPrimProc(SkString* outputColor,
Ethan Nicholas2983f402017-05-08 09:36:08 -040070 SkString* outputCoverage) {
Greg Daniel9a51a862018-11-30 10:18:14 -050071 const GrPrimitiveProcessor& proc = this->primitiveProcessor();
72 const GrTextureProxy* const* primProcProxies = this->primProcProxies();
73
egdanielfa896322016-01-13 12:19:30 -080074 // Program builders have a bit of state we need to clear with each effect
75 AutoStageAdvance adv(this);
76 this->nameExpression(outputColor, "outputColor");
77 this->nameExpression(outputCoverage, "outputCoverage");
78
csmartdalton936f81b2017-02-13 15:45:35 -070079 SkASSERT(!fUniformHandles.fRTAdjustmentUni.isValid());
Robert Phillipsfe8da172018-01-24 14:52:02 +000080 GrShaderFlags rtAdjustVisibility;
csmartdalton936f81b2017-02-13 15:45:35 -070081 if (proc.willUseGeoShader()) {
Robert Phillipsfe8da172018-01-24 14:52:02 +000082 rtAdjustVisibility = kGeometry_GrShaderFlag;
83 } else {
84 rtAdjustVisibility = kVertex_GrShaderFlag;
csmartdalton936f81b2017-02-13 15:45:35 -070085 }
Robert Phillipsfe8da172018-01-24 14:52:02 +000086 fUniformHandles.fRTAdjustmentUni = this->uniformHandler()->addUniform(
87 rtAdjustVisibility,
88 kFloat4_GrSLType,
89 SkSL::Compiler::RTADJUST_NAME);
csmartdalton936f81b2017-02-13 15:45:35 -070090 const char* rtAdjustName =
91 this->uniformHandler()->getUniformCStr(fUniformHandles.fRTAdjustmentUni);
92
egdanielfa896322016-01-13 12:19:30 -080093 // Enclose custom code in a block to avoid namespace conflicts
94 SkString openBrace;
95 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, proc.name());
96 fFS.codeAppend(openBrace.c_str());
97 fVS.codeAppendf("// Primitive Processor %s\n", proc.name());
98
99 SkASSERT(!fGeometryProcessor);
Robert Phillips369e8b72017-08-01 16:13:04 -0400100 fGeometryProcessor.reset(proc.createGLSLInstance(*this->shaderCaps()));
egdanielfa896322016-01-13 12:19:30 -0800101
Brian Salomone782f842018-07-31 13:53:11 -0400102 SkAutoSTMalloc<4, SamplerHandle> texSamplers(proc.numTextureSamplers());
103 for (int i = 0; i < proc.numTextureSamplers(); ++i) {
104 SkString name;
105 name.printf("TextureSampler_%d", i);
106 const auto& sampler = proc.textureSampler(i);
Greg Daniel9a51a862018-11-30 10:18:14 -0500107 const GrTexture* texture = primProcProxies[i]->peekTexture();
108 SkASSERT(sampler.textureType() == texture->texturePriv().textureType());
Greg Daniel9a51a862018-11-30 10:18:14 -0500109 texSamplers[i] = this->emitSampler(texture,
110 sampler.samplerState(),
Greg Daniel2c3398d2019-06-19 11:58:01 -0400111 sampler.swizzle(),
Greg Daniel9a51a862018-11-30 10:18:14 -0500112 name.c_str());
Brian Salomone782f842018-07-31 13:53:11 -0400113 }
egdanielfa896322016-01-13 12:19:30 -0800114
bsalomona624bf32016-09-20 09:12:47 -0700115 GrGLSLPrimitiveProcessor::FPCoordTransformHandler transformHandler(fPipeline,
116 &fTransformedCoordVars);
egdanielfa896322016-01-13 12:19:30 -0800117 GrGLSLGeometryProcessor::EmitArgs args(&fVS,
csmartdalton276cc412016-11-21 11:55:00 -0700118 proc.willUseGeoShader() ? &fGS : nullptr,
egdanielfa896322016-01-13 12:19:30 -0800119 &fFS,
120 this->varyingHandler(),
121 this->uniformHandler(),
Brian Salomon94efbf52016-11-29 13:43:05 -0500122 this->shaderCaps(),
egdanielfa896322016-01-13 12:19:30 -0800123 proc,
124 outputColor->c_str(),
125 outputCoverage->c_str(),
csmartdalton936f81b2017-02-13 15:45:35 -0700126 rtAdjustName,
Brian Salomone782f842018-07-31 13:53:11 -0400127 texSamplers.get(),
bsalomona624bf32016-09-20 09:12:47 -0700128 &transformHandler);
egdanielfa896322016-01-13 12:19:30 -0800129 fGeometryProcessor->emitCode(args);
130
131 // We have to check that effects and the code they emit are consistent, ie if an effect
132 // asks for dst color, then the emit code needs to follow suit
cdalton87332102016-02-26 12:22:02 -0800133 SkDEBUGCODE(verify(proc);)
egdanielfa896322016-01-13 12:19:30 -0800134
135 fFS.codeAppend("}");
136}
137
Ethan Nicholas2983f402017-05-08 09:36:08 -0400138void GrGLSLProgramBuilder::emitAndInstallFragProcs(SkString* color, SkString* coverage) {
bsalomona624bf32016-09-20 09:12:47 -0700139 int transformedCoordVarsIdx = 0;
Ethan Nicholas2983f402017-05-08 09:36:08 -0400140 SkString** inOut = &color;
Brian Salomon4d3f5172018-06-07 14:42:52 -0400141 SkSTArray<8, std::unique_ptr<GrGLSLFragmentProcessor>> glslFragmentProcessors;
bsalomona624bf32016-09-20 09:12:47 -0700142 for (int i = 0; i < this->pipeline().numFragmentProcessors(); ++i) {
143 if (i == this->pipeline().numColorFragmentProcessors()) {
144 inOut = &coverage;
145 }
Ethan Nicholas2983f402017-05-08 09:36:08 -0400146 SkString output;
egdanielfa896322016-01-13 12:19:30 -0800147 const GrFragmentProcessor& fp = this->pipeline().getFragmentProcessor(i);
Brian Salomon4d3f5172018-06-07 14:42:52 -0400148 output = this->emitAndInstallFragProc(fp, i, transformedCoordVarsIdx, **inOut, output,
149 &glslFragmentProcessors);
bsalomona624bf32016-09-20 09:12:47 -0700150 GrFragmentProcessor::Iter iter(&fp);
151 while (const GrFragmentProcessor* fp = iter.next()) {
152 transformedCoordVarsIdx += fp->numCoordTransforms();
153 }
154 **inOut = output;
egdanielfa896322016-01-13 12:19:30 -0800155 }
Brian Salomon4d3f5172018-06-07 14:42:52 -0400156 fFragmentProcessorCnt = glslFragmentProcessors.count();
157 fFragmentProcessors.reset(new std::unique_ptr<GrGLSLFragmentProcessor>[fFragmentProcessorCnt]);
158 for (int i = 0; i < fFragmentProcessorCnt; ++i) {
159 fFragmentProcessors[i] = std::move(glslFragmentProcessors[i]);
160 }
egdanielfa896322016-01-13 12:19:30 -0800161}
162
163// TODO Processors cannot output zeros because an empty string is all 1s
Ethan Nicholas2983f402017-05-08 09:36:08 -0400164// the fix is to allow effects to take the SkString directly
Brian Salomon4d3f5172018-06-07 14:42:52 -0400165SkString GrGLSLProgramBuilder::emitAndInstallFragProc(
166 const GrFragmentProcessor& fp,
167 int index,
168 int transformedCoordVarsIdx,
169 const SkString& input,
170 SkString output,
171 SkTArray<std::unique_ptr<GrGLSLFragmentProcessor>>* glslFragmentProcessors) {
Ethan Nicholas2983f402017-05-08 09:36:08 -0400172 SkASSERT(input.size());
egdanielfa896322016-01-13 12:19:30 -0800173 // Program builders have a bit of state we need to clear with each effect
174 AutoStageAdvance adv(this);
Ethan Nicholas2983f402017-05-08 09:36:08 -0400175 this->nameExpression(&output, "output");
egdanielfa896322016-01-13 12:19:30 -0800176
177 // Enclose custom code in a block to avoid namespace conflicts
178 SkString openBrace;
179 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, fp.name());
180 fFS.codeAppend(openBrace.c_str());
181
182 GrGLSLFragmentProcessor* fragProc = fp.createGLSLInstance();
183
Brian Salomone782f842018-07-31 13:53:11 -0400184 SkSTArray<4, SamplerHandle> texSamplers;
185 GrFragmentProcessor::Iter fpIter(&fp);
186 int samplerIdx = 0;
187 while (const auto* subFP = fpIter.next()) {
188 for (int i = 0; i < subFP->numTextureSamplers(); ++i) {
189 SkString name;
190 name.printf("TextureSampler_%d", samplerIdx++);
191 const auto& sampler = subFP->textureSampler(i);
Greg Daniel9a51a862018-11-30 10:18:14 -0500192 texSamplers.emplace_back(this->emitSampler(sampler.peekTexture(),
193 sampler.samplerState(),
Greg Daniel2c3398d2019-06-19 11:58:01 -0400194 sampler.swizzle(),
Greg Daniel0f70be82018-10-08 17:35:08 +0000195 name.c_str()));
Brian Salomone782f842018-07-31 13:53:11 -0400196 }
bsalomonb58a2b42016-09-26 06:55:02 -0700197 }
egdanielfa896322016-01-13 12:19:30 -0800198
bsalomona624bf32016-09-20 09:12:47 -0700199 const GrShaderVar* coordVars = fTransformedCoordVars.begin() + transformedCoordVarsIdx;
200 GrGLSLFragmentProcessor::TransformedCoordVars coords(&fp, coordVars);
Brian Salomone782f842018-07-31 13:53:11 -0400201 GrGLSLFragmentProcessor::TextureSamplers textureSamplers(&fp, texSamplers.begin());
egdanielfa896322016-01-13 12:19:30 -0800202 GrGLSLFragmentProcessor::EmitArgs args(&fFS,
203 this->uniformHandler(),
Brian Salomon94efbf52016-11-29 13:43:05 -0500204 this->shaderCaps(),
egdanielfa896322016-01-13 12:19:30 -0800205 fp,
Ethan Nicholas2983f402017-05-08 09:36:08 -0400206 output.c_str(),
207 input.c_str(),
bsalomona624bf32016-09-20 09:12:47 -0700208 coords,
Brian Salomon662ea4b2018-07-12 14:53:49 -0400209 textureSamplers);
Ethan Nicholas6ad52892019-05-03 13:13:42 +0000210
211 fragProc->emitCode(args);
egdanielfa896322016-01-13 12:19:30 -0800212
213 // We have to check that effects and the code they emit are consistent, ie if an effect
214 // asks for dst color, then the emit code needs to follow suit
cdalton87332102016-02-26 12:22:02 -0800215 SkDEBUGCODE(verify(fp);)
Brian Salomon4d3f5172018-06-07 14:42:52 -0400216 glslFragmentProcessors->emplace_back(fragProc);
egdanielfa896322016-01-13 12:19:30 -0800217
218 fFS.codeAppend("}");
Ethan Nicholas2983f402017-05-08 09:36:08 -0400219 return output;
egdanielfa896322016-01-13 12:19:30 -0800220}
221
Ethan Nicholas2983f402017-05-08 09:36:08 -0400222void GrGLSLProgramBuilder::emitAndInstallXferProc(const SkString& colorIn,
223 const SkString& coverageIn) {
egdanielfa896322016-01-13 12:19:30 -0800224 // Program builders have a bit of state we need to clear with each effect
225 AutoStageAdvance adv(this);
226
227 SkASSERT(!fXferProcessor);
Brian Salomon18dfa982017-04-03 16:57:43 -0400228 const GrXferProcessor& xp = fPipeline.getXferProcessor();
Robert Phillips369e8b72017-08-01 16:13:04 -0400229 fXferProcessor.reset(xp.createGLSLInstance());
egdanielfa896322016-01-13 12:19:30 -0800230
231 // Enable dual source secondary output if we have one
232 if (xp.hasSecondaryOutput()) {
233 fFS.enableSecondaryOutput();
234 }
235
Brian Salomon94efbf52016-11-29 13:43:05 -0500236 if (this->shaderCaps()->mustDeclareFragmentShaderOutput()) {
egdanielfa896322016-01-13 12:19:30 -0800237 fFS.enableCustomOutput();
238 }
239
240 SkString openBrace;
241 openBrace.printf("{ // Xfer Processor: %s\n", xp.name());
242 fFS.codeAppend(openBrace.c_str());
243
Brian Salomon18dfa982017-04-03 16:57:43 -0400244 SamplerHandle dstTextureSamplerHandle;
245 GrSurfaceOrigin dstTextureOrigin = kTopLeft_GrSurfaceOrigin;
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400246
247 if (GrTexture* dstTexture = fPipeline.peekDstTexture()) {
Brian Salomon18dfa982017-04-03 16:57:43 -0400248 // GrProcessor::TextureSampler sampler(dstTexture);
Greg Daniel2c3398d2019-06-19 11:58:01 -0400249 SkASSERT(fPipeline.dstTextureProxy());
250 const GrSwizzle& swizzle = fPipeline.dstTextureProxy()->textureSwizzle();
Brian Salomon18dfa982017-04-03 16:57:43 -0400251 dstTextureSamplerHandle =
Greg Daniel2c3398d2019-06-19 11:58:01 -0400252 this->emitSampler(dstTexture, GrSamplerState(), swizzle, "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
Brian Osman65cdd612019-03-14 17:01:57 -0400257 SkString finalInColor;
258 if (colorIn.size()) {
259 if (this->desc()->header().fClampBlendInput) {
260 finalInColor.printf("saturate(%s)", colorIn.c_str());
261 } else {
262 finalInColor = colorIn;
263 }
264 } else {
265 finalInColor = "float4(1)";
266 }
267
egdanielfa896322016-01-13 12:19:30 -0800268 GrGLSLXferProcessor::EmitArgs args(&fFS,
269 this->uniformHandler(),
Brian Salomon94efbf52016-11-29 13:43:05 -0500270 this->shaderCaps(),
Brian Salomon18dfa982017-04-03 16:57:43 -0400271 xp,
Brian Osman65cdd612019-03-14 17:01:57 -0400272 finalInColor.c_str(),
Ethan Nicholas5af9ea32017-07-28 15:19:46 -0400273 coverageIn.size() ? coverageIn.c_str() : "float4(1)",
egdanielfa896322016-01-13 12:19:30 -0800274 fFS.getPrimaryColorOutputName(),
275 fFS.getSecondaryColorOutputName(),
Brian Salomon18dfa982017-04-03 16:57:43 -0400276 dstTextureSamplerHandle,
Chris Dalton6b76df02019-04-08 11:01:34 -0600277 dstTextureOrigin,
278 this->desc()->header().fOutputSwizzle);
egdanielfa896322016-01-13 12:19:30 -0800279 fXferProcessor->emitCode(args);
280
281 // We have to check that effects and the code they emit are consistent, ie if an effect
282 // asks for dst color, then the emit code needs to follow suit
cdalton87332102016-02-26 12:22:02 -0800283 SkDEBUGCODE(verify(xp);)
egdanielfa896322016-01-13 12:19:30 -0800284 fFS.codeAppend("}");
285}
286
Greg Daniel9a51a862018-11-30 10:18:14 -0500287GrGLSLProgramBuilder::SamplerHandle GrGLSLProgramBuilder::emitSampler(const GrTexture* texture,
288 const GrSamplerState& state,
Greg Daniel2c3398d2019-06-19 11:58:01 -0400289 const GrSwizzle& swizzle,
Greg Daniel0f70be82018-10-08 17:35:08 +0000290 const char* name) {
291 ++fNumFragmentSamplers;
Greg Daniel2c3398d2019-06-19 11:58:01 -0400292 return this->uniformHandler()->addSampler(texture, state, swizzle, name, this->shaderCaps());
Brian Salomonf9f45122016-11-29 11:59:17 -0500293}
294
cdalton9c3f1432016-03-11 10:07:37 -0800295bool GrGLSLProgramBuilder::checkSamplerCounts() {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500296 const GrShaderCaps& shaderCaps = *this->shaderCaps();
Brian Salomon1edc5b92016-11-29 13:43:46 -0500297 if (fNumFragmentSamplers > shaderCaps.maxFragmentSamplers()) {
cdalton9c3f1432016-03-11 10:07:37 -0800298 GrCapsDebugf(this->caps(), "Program would use too many fragment samplers\n");
299 return false;
300 }
cdalton9c3f1432016-03-11 10:07:37 -0800301 return true;
302}
303
cdalton87332102016-02-26 12:22:02 -0800304#ifdef SK_DEBUG
egdanielfa896322016-01-13 12:19:30 -0800305void GrGLSLProgramBuilder::verify(const GrPrimitiveProcessor& gp) {
Chris Daltond7291ba2019-03-07 14:17:03 -0700306 SkASSERT(!fFS.fHasReadDstColorThisStage_DebugOnly);
307 SkASSERT(fFS.fUsedProcessorFeaturesThisStage_DebugOnly == gp.requestedFeatures());
egdanielfa896322016-01-13 12:19:30 -0800308}
309
310void GrGLSLProgramBuilder::verify(const GrFragmentProcessor& fp) {
Chris Daltond7291ba2019-03-07 14:17:03 -0700311 SkASSERT(!fFS.fHasReadDstColorThisStage_DebugOnly);
312 SkASSERT(fFS.fUsedProcessorFeaturesThisStage_DebugOnly == fp.requestedFeatures());
313}
314
315void GrGLSLProgramBuilder::verify(const GrXferProcessor& xp) {
316 SkASSERT(xp.willReadDstColor() == fFS.fHasReadDstColorThisStage_DebugOnly);
317 SkASSERT(fFS.fUsedProcessorFeaturesThisStage_DebugOnly == xp.requestedFeatures());
egdaniel8dcdedc2015-11-11 06:27:20 -0800318}
cdalton87332102016-02-26 12:22:02 -0800319#endif
egdaniel8dcdedc2015-11-11 06:27:20 -0800320
321void GrGLSLProgramBuilder::nameVariable(SkString* out, char prefix, const char* name, bool mangle) {
322 if ('\0' == prefix) {
323 *out = name;
324 } else {
325 out->printf("%c%s", prefix, name);
326 }
327 if (mangle) {
328 if (out->endsWith('_')) {
329 // Names containing "__" are reserved.
330 out->append("x");
331 }
332 out->appendf("_Stage%d%s", fStageIndex, fFS.getMangleString().c_str());
333 }
334}
335
Ethan Nicholas2983f402017-05-08 09:36:08 -0400336void GrGLSLProgramBuilder::nameExpression(SkString* output, const char* baseName) {
egdanielfa896322016-01-13 12:19:30 -0800337 // create var to hold stage result. If we already have a valid output name, just use that
338 // otherwise create a new mangled one. This name is only valid if we are reordering stages
339 // and have to tell stage exactly where to put its output.
340 SkString outName;
Ethan Nicholas2983f402017-05-08 09:36:08 -0400341 if (output->size()) {
egdanielfa896322016-01-13 12:19:30 -0800342 outName = output->c_str();
343 } else {
344 this->nameVariable(&outName, '\0', baseName);
345 }
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400346 fFS.codeAppendf("half4 %s;", outName.c_str());
egdanielfa896322016-01-13 12:19:30 -0800347 *output = outName;
348}
349
cdalton5e58cee2016-02-11 12:49:47 -0800350void GrGLSLProgramBuilder::appendUniformDecls(GrShaderFlags visibility, SkString* out) const {
egdaniel7ea439b2015-12-03 09:20:44 -0800351 this->uniformHandler()->appendUniformDecls(visibility, out);
352}
353
Ethan Nicholascd700e92018-08-24 16:43:57 -0400354void GrGLSLProgramBuilder::addRTWidthUniform(const char* name) {
355 SkASSERT(!fUniformHandles.fRTWidthUni.isValid());
356 GrGLSLUniformHandler* uniformHandler = this->uniformHandler();
357 fUniformHandles.fRTWidthUni =
Ethan Nicholas858fecc2019-03-07 13:19:18 -0500358 uniformHandler->internalAddUniformArray(kFragment_GrShaderFlag, kHalf_GrSLType, name,
359 false, 0, nullptr);
Ethan Nicholascd700e92018-08-24 16:43:57 -0400360}
361
Greg Daniele6ab9982018-08-22 13:56:32 +0000362void GrGLSLProgramBuilder::addRTHeightUniform(const char* name) {
363 SkASSERT(!fUniformHandles.fRTHeightUni.isValid());
egdaniel7ea439b2015-12-03 09:20:44 -0800364 GrGLSLUniformHandler* uniformHandler = this->uniformHandler();
Greg Daniele6ab9982018-08-22 13:56:32 +0000365 fUniformHandles.fRTHeightUni =
Ethan Nicholas858fecc2019-03-07 13:19:18 -0500366 uniformHandler->internalAddUniformArray(kFragment_GrShaderFlag, kHalf_GrSLType, name,
367 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}