blob: 02eb64ecd3767af79bdf56070a93d2525ab29dd3 [file] [log] [blame]
joshualitt30ba4362014-08-21 20:18:45 -07001/*
2 * Copyright 2014 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
Brian Salomon201cdbb2019-08-14 17:00:30 -04008#include "src/gpu/GrRenderTarget.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "src/gpu/GrShaderCaps.h"
10#include "src/gpu/gl/GrGLGpu.h"
11#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
12#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
13#include "src/gpu/glsl/GrGLSLUniformHandler.h"
14#include "src/gpu/glsl/GrGLSLVarying.h"
joshualitt47bb3822014-10-07 16:43:25 -070015
egdaniel138c2632016-08-17 10:59:00 -070016const char* GrGLSLFragmentShaderBuilder::kDstColorName = "_dstColor";
joshualitt30ba4362014-08-21 20:18:45 -070017
cdalton8917d622015-05-06 13:40:21 -070018static const char* specific_layout_qualifier_name(GrBlendEquation equation) {
19 SkASSERT(GrBlendEquationIsAdvanced(equation));
20
21 static const char* kLayoutQualifierNames[] = {
22 "blend_support_screen",
23 "blend_support_overlay",
24 "blend_support_darken",
25 "blend_support_lighten",
26 "blend_support_colordodge",
27 "blend_support_colorburn",
28 "blend_support_hardlight",
29 "blend_support_softlight",
30 "blend_support_difference",
31 "blend_support_exclusion",
32 "blend_support_multiply",
33 "blend_support_hsl_hue",
34 "blend_support_hsl_saturation",
35 "blend_support_hsl_color",
36 "blend_support_hsl_luminosity"
37 };
38 return kLayoutQualifierNames[equation - kFirstAdvancedGrBlendEquation];
39
Brian Salomon4dea72a2019-12-18 10:43:10 -050040 static_assert(0 == kScreen_GrBlendEquation - kFirstAdvancedGrBlendEquation);
41 static_assert(1 == kOverlay_GrBlendEquation - kFirstAdvancedGrBlendEquation);
42 static_assert(2 == kDarken_GrBlendEquation - kFirstAdvancedGrBlendEquation);
43 static_assert(3 == kLighten_GrBlendEquation - kFirstAdvancedGrBlendEquation);
44 static_assert(4 == kColorDodge_GrBlendEquation - kFirstAdvancedGrBlendEquation);
45 static_assert(5 == kColorBurn_GrBlendEquation - kFirstAdvancedGrBlendEquation);
46 static_assert(6 == kHardLight_GrBlendEquation - kFirstAdvancedGrBlendEquation);
47 static_assert(7 == kSoftLight_GrBlendEquation - kFirstAdvancedGrBlendEquation);
48 static_assert(8 == kDifference_GrBlendEquation - kFirstAdvancedGrBlendEquation);
49 static_assert(9 == kExclusion_GrBlendEquation - kFirstAdvancedGrBlendEquation);
50 static_assert(10 == kMultiply_GrBlendEquation - kFirstAdvancedGrBlendEquation);
51 static_assert(11 == kHSLHue_GrBlendEquation - kFirstAdvancedGrBlendEquation);
52 static_assert(12 == kHSLSaturation_GrBlendEquation - kFirstAdvancedGrBlendEquation);
53 static_assert(13 == kHSLColor_GrBlendEquation - kFirstAdvancedGrBlendEquation);
54 static_assert(14 == kHSLLuminosity_GrBlendEquation - kFirstAdvancedGrBlendEquation);
Mike Klein36743362018-11-06 08:23:30 -050055 // There's an illegal GrBlendEquation at the end there, hence the -1.
Brian Salomon4dea72a2019-12-18 10:43:10 -050056 static_assert(SK_ARRAY_COUNT(kLayoutQualifierNames) ==
57 kGrBlendEquationCnt - kFirstAdvancedGrBlendEquation - 1);
cdalton8917d622015-05-06 13:40:21 -070058}
59
Robert Phillips7f861922018-01-30 13:13:42 +000060uint8_t GrGLSLFragmentShaderBuilder::KeyForSurfaceOrigin(GrSurfaceOrigin origin) {
61 SkASSERT(kTopLeft_GrSurfaceOrigin == origin || kBottomLeft_GrSurfaceOrigin == origin);
62 return origin + 1;
63
Brian Salomon4dea72a2019-12-18 10:43:10 -050064 static_assert(0 == kTopLeft_GrSurfaceOrigin);
65 static_assert(1 == kBottomLeft_GrSurfaceOrigin);
Robert Phillips7f861922018-01-30 13:13:42 +000066}
67
cdalton28f45b92016-03-07 13:58:26 -080068GrGLSLFragmentShaderBuilder::GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder* program)
Brian Salomonffd15ea2020-07-01 16:48:20 -040069 : GrGLSLShaderBuilder(program) {
cdalton85285412016-02-18 12:37:07 -080070 fSubstageIndices.push_back(0);
cdalton87332102016-02-26 12:22:02 -080071}
72
Chris Daltond7291ba2019-03-07 14:17:03 -070073const char* GrGLSLFragmentShaderBuilder::sampleOffsets() {
Robert Phillips7de13332019-10-09 15:44:54 -040074 SkASSERT(CustomFeatures::kSampleLocations & fProgramBuilder->processorFeatures());
Chris Daltond7291ba2019-03-07 14:17:03 -070075 SkDEBUGCODE(fUsedProcessorFeaturesThisStage_DebugOnly |= CustomFeatures::kSampleLocations);
76 SkDEBUGCODE(fUsedProcessorFeaturesAllStages_DebugOnly |= CustomFeatures::kSampleLocations);
77 return "_sampleOffsets";
78}
79
Chris Dalton0dffbab2019-03-27 13:08:50 -060080void GrGLSLFragmentShaderBuilder::maskOffMultisampleCoverage(
81 const char* mask, ScopeFlags scopeFlags) {
Chris Daltond31b5e72019-02-26 18:02:16 -070082 const GrShaderCaps& shaderCaps = *fProgramBuilder->shaderCaps();
Chris Dalton8a64a442019-10-29 18:54:58 -060083 if (!shaderCaps.sampleMaskSupport()) {
Chris Daltond31b5e72019-02-26 18:02:16 -070084 SkDEBUGFAIL("Attempted to mask sample coverage without support.");
85 return;
86 }
87 if (const char* extension = shaderCaps.sampleVariablesExtensionString()) {
88 this->addFeature(1 << kSampleVariables_GLSLPrivateFeature, extension);
89 }
90
Chris Dalton0dffbab2019-03-27 13:08:50 -060091 if (!fHasModifiedSampleMask) {
92 fHasModifiedSampleMask = true;
93 if (ScopeFlags::kTopLevel != scopeFlags) {
Chris Daltonb0fd4b12019-10-29 13:41:22 -060094 this->codePrependf("sk_SampleMask[0] = ~0;");
Chris Dalton0dffbab2019-03-27 13:08:50 -060095 }
96 if (!(ScopeFlags::kInsideLoop & scopeFlags)) {
Chris Daltonb0fd4b12019-10-29 13:41:22 -060097 this->codeAppendf("sk_SampleMask[0] = (%s);", mask);
Chris Dalton0dffbab2019-03-27 13:08:50 -060098 return;
99 }
Chris Daltond31b5e72019-02-26 18:02:16 -0700100 }
Chris Dalton0dffbab2019-03-27 13:08:50 -0600101
Chris Daltonb0fd4b12019-10-29 13:41:22 -0600102 this->codeAppendf("sk_SampleMask[0] &= (%s);", mask);
Chris Daltond31b5e72019-02-26 18:02:16 -0700103}
104
Chris Dalton0dffbab2019-03-27 13:08:50 -0600105void GrGLSLFragmentShaderBuilder::applyFnToMultisampleMask(
106 const char* fn, const char* grad, ScopeFlags scopeFlags) {
Robert Phillips7de13332019-10-09 15:44:54 -0400107 SkASSERT(CustomFeatures::kSampleLocations & fProgramBuilder->processorFeatures());
Chris Dalton0dffbab2019-03-27 13:08:50 -0600108 SkDEBUGCODE(fUsedProcessorFeaturesThisStage_DebugOnly |= CustomFeatures::kSampleLocations);
109 SkDEBUGCODE(fUsedProcessorFeaturesAllStages_DebugOnly |= CustomFeatures::kSampleLocations);
110
111 int sampleCnt = fProgramBuilder->effectiveSampleCnt();
112 SkASSERT(sampleCnt > 1);
113
114 this->codeAppendf("{");
115
116 if (!grad) {
117 SkASSERT(fProgramBuilder->shaderCaps()->shaderDerivativeSupport());
118 // In order to use HW derivatives, our neighbors within the same primitive must also be
119 // executing the same code. A per-pixel branch makes this pre-condition impossible to
120 // fulfill.
121 SkASSERT(!(ScopeFlags::kInsidePerPixelBranch & scopeFlags));
Chris Daltonc3318f02019-07-19 14:20:53 -0600122 this->codeAppendf("float2 grad = float2(dFdx(%s), dFdy(%s));", fn, fn);
123 this->codeAppendf("float fnwidth = fwidth(%s);", fn);
Chris Dalton0dffbab2019-03-27 13:08:50 -0600124 grad = "grad";
125 } else {
126 this->codeAppendf("float fnwidth = abs(%s.x) + abs(%s.y);", grad, grad);
127 }
128
129 this->codeAppendf("int mask = 0;");
130 this->codeAppendf("if (%s*2 < fnwidth) {", fn); // Are ANY samples inside the implicit fn?
131 this->codeAppendf( "if (%s*-2 >= fnwidth) {", fn); // Are ALL samples inside the implicit?
132 this->codeAppendf( "mask = ~0;");
133 this->codeAppendf( "} else for (int i = 0; i < %i; ++i) {", sampleCnt);
134 this->codeAppendf( "float fnsample = dot(%s, _sampleOffsets[i]) + %s;", grad, fn);
135 this->codeAppendf( "if (fnsample < 0) {");
136 this->codeAppendf( "mask |= (1 << i);");
137 this->codeAppendf( "}");
138 this->codeAppendf( "}");
139 this->codeAppendf("}");
140 this->maskOffMultisampleCoverage("mask", scopeFlags);
141
142 this->codeAppendf("}");
143}
144
Ethan Nicholasc6dce5a2019-07-24 16:51:36 -0400145SkString GrGLSLFPFragmentBuilder::writeProcessorFunction(GrGLSLFragmentProcessor* fp,
146 GrGLSLFragmentProcessor::EmitArgs& args) {
147 this->onBeforeChildProcEmitCode();
148 this->nextStage();
Michael Ludwige88320b2020-06-24 09:04:56 -0400149
150 // An FP's function signature is theoretically always main(half4 color, float2 _coords).
Brian Osman1298bc42020-06-30 13:39:35 -0400151 // However, if it is only sampled by a chain of uniform matrix expressions (or legacy coord
Michael Ludwige88320b2020-06-24 09:04:56 -0400152 // transforms), the value that would have been passed to _coords is lifted to the vertex shader
153 // and stored in a unique varying. In that case it uses that variable and does not have a
154 // second actual argument for _coords.
Michael Ludwige7e25ac2020-06-26 12:53:03 -0400155 // FIXME: An alternative would be to have all FP functions have a float2 argument, and the
156 // parent FP invokes it with the varying reference when it's been lifted to the vertex shader.
157 int paramCount = 2;
Michael Ludwige88320b2020-06-24 09:04:56 -0400158 GrShaderVar params[] = { GrShaderVar(args.fInputColor, kHalf4_GrSLType),
159 GrShaderVar(args.fSampleCoord, kFloat2_GrSLType) };
160
Michael Ludwige7e25ac2020-06-26 12:53:03 -0400161 if (!args.fFp.isSampledWithExplicitCoords()) {
Brian Osman1298bc42020-06-30 13:39:35 -0400162 // Sampled with a uniform matrix expression and/or a legacy coord transform. The actual
Michael Ludwige88320b2020-06-24 09:04:56 -0400163 // transformation code is emitted in the vertex shader, so this only has to access it.
164 // Add a float2 _coords variable that maps to the associated varying and replaces the
165 // absent 2nd argument to the fp's function.
166 paramCount = 1;
167
168 if (args.fFp.referencesSampleCoords()) {
Brian Osman9cf98dc2020-07-01 17:21:27 -0400169 const GrShaderVar& varying = args.fTransformedCoords[0];
Michael Ludwige88320b2020-06-24 09:04:56 -0400170 switch(varying.getType()) {
171 case kFloat2_GrSLType:
172 // Just point the local coords to the varying
173 args.fSampleCoord = varying.getName().c_str();
174 break;
175 case kFloat3_GrSLType:
176 // Must perform the perspective divide in the frag shader based on the varying,
177 // and since we won't actually have a function parameter for local coords, add
178 // it as a local variable.
179 this->codeAppendf("float2 %s = %s.xy / %s.z;\n", args.fSampleCoord,
Michael Ludwige7e25ac2020-06-26 12:53:03 -0400180 varying.getName().c_str(), varying.getName().c_str());
Michael Ludwige88320b2020-06-24 09:04:56 -0400181 break;
182 default:
183 SkDEBUGFAILF("Unexpected varying type for coord: %s %d\n",
184 varying.getName().c_str(), (int) varying.getType());
185 break;
186 }
Ethan Nicholas58430122020-04-14 09:54:02 -0400187 }
Michael Ludwige7e25ac2020-06-26 12:53:03 -0400188 } // else the function keeps its two arguments
Ethan Nicholas58430122020-04-14 09:54:02 -0400189
Ethan Nicholasc6dce5a2019-07-24 16:51:36 -0400190 this->codeAppendf("half4 %s;\n", args.fOutputColor);
191 fp->emitCode(args);
Brian Osman767f4442020-08-13 16:59:48 -0400192 if (args.fFp.usesExplicitReturn()) {
193 // Some FPs explicitly return their output, so no need to do anything further
194 SkASSERT(SkStrContains(this->code().c_str(), "return"));
195 } else {
196 // Most FPs still just write their output to fOutputColor, so we need to inject the return
197 this->codeAppendf("return %s;\n", args.fOutputColor);
198 }
Michael Ludwige88320b2020-06-24 09:04:56 -0400199
Ethan Nicholasc6dce5a2019-07-24 16:51:36 -0400200 SkString result;
Michael Ludwige88320b2020-06-24 09:04:56 -0400201 this->emitFunction(kHalf4_GrSLType, args.fFp.name(), paramCount, params,
John Stiles9e506ee2020-08-26 10:22:50 -0400202 this->code().c_str(), &result, args.fForceInline);
Ethan Nicholasc6dce5a2019-07-24 16:51:36 -0400203 this->deleteStage();
204 this->onAfterChildProcEmitCode();
205 return result;
206}
207
egdaniel2d721d32015-11-11 13:06:05 -0800208const char* GrGLSLFragmentShaderBuilder::dstColor() {
Chris Daltond7291ba2019-03-07 14:17:03 -0700209 SkDEBUGCODE(fHasReadDstColorThisStage_DebugOnly = true;)
joshualitt47bb3822014-10-07 16:43:25 -0700210
Brian Salomon1edc5b92016-11-29 13:43:46 -0500211 const GrShaderCaps* shaderCaps = fProgramBuilder->shaderCaps();
212 if (shaderCaps->fbFetchSupport()) {
cdaltonc08f1962016-02-12 12:14:06 -0800213 this->addFeature(1 << kFramebufferFetch_GLSLPrivateFeature,
Brian Salomon1edc5b92016-11-29 13:43:46 -0500214 shaderCaps->fbFetchExtensionString());
joshualittb4384b92014-10-21 12:53:15 -0700215
joshualitt3c1096f2015-01-13 13:13:59 -0800216 // Some versions of this extension string require declaring custom color output on ES 3.0+
Ethan Nicholaseab2baa2018-04-13 15:16:27 -0400217 const char* fbFetchColorName = "sk_LastFragColor";
Brian Salomon1edc5b92016-11-29 13:43:46 -0500218 if (shaderCaps->fbFetchNeedsCustomOutput()) {
joshualittb4384b92014-10-21 12:53:15 -0700219 this->enableCustomOutput();
Ben Wagnerdabd98c2020-03-25 15:17:18 -0400220 fCustomColorOutput->setTypeModifier(GrShaderVar::TypeModifier::InOut);
egdaniel8dcdedc2015-11-11 06:27:20 -0800221 fbFetchColorName = DeclaredColorOutputName();
egdaniel138c2632016-08-17 10:59:00 -0700222 // Set the dstColor to an intermediate variable so we don't override it with the output
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400223 this->codeAppendf("half4 %s = %s;", kDstColorName, fbFetchColorName);
egdanielbd4121a2016-08-17 12:55:30 -0700224 } else {
225 return fbFetchColorName;
joshualittb4384b92014-10-21 12:53:15 -0700226 }
halcanary9d524f22016-03-29 09:03:52 -0700227 }
egdaniel138c2632016-08-17 10:59:00 -0700228 return kDstColorName;
joshualitt47bb3822014-10-07 16:43:25 -0700229}
230
egdaniel2d721d32015-11-11 13:06:05 -0800231void GrGLSLFragmentShaderBuilder::enableAdvancedBlendEquationIfNeeded(GrBlendEquation equation) {
cdalton8917d622015-05-06 13:40:21 -0700232 SkASSERT(GrBlendEquationIsAdvanced(equation));
233
Brian Salomon94efbf52016-11-29 13:43:05 -0500234 const GrShaderCaps& caps = *fProgramBuilder->shaderCaps();
cdalton8917d622015-05-06 13:40:21 -0700235 if (!caps.mustEnableAdvBlendEqs()) {
236 return;
237 }
238
239 this->addFeature(1 << kBlendEquationAdvanced_GLSLPrivateFeature,
240 "GL_KHR_blend_equation_advanced");
241 if (caps.mustEnableSpecificAdvBlendEqs()) {
242 this->addLayoutQualifier(specific_layout_qualifier_name(equation), kOut_InterfaceQualifier);
243 } else {
244 this->addLayoutQualifier("blend_support_all_equations", kOut_InterfaceQualifier);
245 }
246}
247
egdaniel2d721d32015-11-11 13:06:05 -0800248void GrGLSLFragmentShaderBuilder::enableCustomOutput() {
Michael Ludwig45191342020-03-24 12:29:39 -0400249 if (!fCustomColorOutput) {
Ben Wagnerdabd98c2020-03-25 15:17:18 -0400250 fCustomColorOutput = &fOutputs.emplace_back(DeclaredColorOutputName(), kHalf4_GrSLType,
251 GrShaderVar::TypeModifier::Out);
Ben Wagner63fd7602017-10-09 15:45:33 -0400252 fProgramBuilder->finalizeFragmentOutputColor(fOutputs.back());
joshualittb4384b92014-10-21 12:53:15 -0700253 }
joshualitt47bb3822014-10-07 16:43:25 -0700254}
255
egdaniel2d721d32015-11-11 13:06:05 -0800256void GrGLSLFragmentShaderBuilder::enableSecondaryOutput() {
joshualitt47bb3822014-10-07 16:43:25 -0700257 SkASSERT(!fHasSecondaryOutput);
258 fHasSecondaryOutput = true;
Brian Salomon94efbf52016-11-29 13:43:05 -0500259 const GrShaderCaps& caps = *fProgramBuilder->shaderCaps();
egdaniel8dcdedc2015-11-11 06:27:20 -0800260 if (const char* extension = caps.secondaryOutputExtensionString()) {
261 this->addFeature(1 << kBlendFuncExtended_GLSLPrivateFeature, extension);
kkinnunend94708e2015-07-30 22:47:04 -0700262 }
263
264 // If the primary output is declared, we must declare also the secondary output
265 // and vice versa, since it is not allowed to use a built-in gl_FragColor and a custom
266 // output. The condition also co-incides with the condition in whici GLES SL 2.0
267 // requires the built-in gl_SecondaryFragColorEXT, where as 3.0 requires a custom output.
kkinnunend94708e2015-07-30 22:47:04 -0700268 if (caps.mustDeclareFragmentShaderOutput()) {
Ben Wagnerdabd98c2020-03-25 15:17:18 -0400269 fOutputs.emplace_back(DeclaredSecondaryColorOutputName(), kHalf4_GrSLType,
270 GrShaderVar::TypeModifier::Out);
egdanielb80ec8b2016-02-09 09:54:43 -0800271 fProgramBuilder->finalizeFragmentSecondaryColor(fOutputs.back());
kkinnunend94708e2015-07-30 22:47:04 -0700272 }
joshualitt47bb3822014-10-07 16:43:25 -0700273}
274
egdaniel2d721d32015-11-11 13:06:05 -0800275const char* GrGLSLFragmentShaderBuilder::getPrimaryColorOutputName() const {
Michael Ludwig45191342020-03-24 12:29:39 -0400276 return this->hasCustomColorOutput() ? DeclaredColorOutputName() : "sk_FragColor";
joshualitt47bb3822014-10-07 16:43:25 -0700277}
278
Brian Salomondc092132018-04-04 10:14:16 -0400279bool GrGLSLFragmentShaderBuilder::primaryColorOutputIsInOut() const {
Michael Ludwig45191342020-03-24 12:29:39 -0400280 return fCustomColorOutput &&
Ben Wagnerdabd98c2020-03-25 15:17:18 -0400281 fCustomColorOutput->getTypeModifier() == GrShaderVar::TypeModifier::InOut;
Brian Salomondc092132018-04-04 10:14:16 -0400282}
283
egdaniel2d721d32015-11-11 13:06:05 -0800284const char* GrGLSLFragmentShaderBuilder::getSecondaryColorOutputName() const {
Chris Dalton6b76df02019-04-08 11:01:34 -0600285 if (this->hasSecondaryOutput()) {
286 return (fProgramBuilder->shaderCaps()->mustDeclareFragmentShaderOutput())
287 ? DeclaredSecondaryColorOutputName()
288 : "gl_SecondaryFragColorEXT";
289 }
290 return nullptr;
joshualitt47bb3822014-10-07 16:43:25 -0700291}
292
cdalton28f45b92016-03-07 13:58:26 -0800293GrSurfaceOrigin GrGLSLFragmentShaderBuilder::getSurfaceOrigin() const {
Robert Phillips7de13332019-10-09 15:44:54 -0400294 return fProgramBuilder->origin();
cdalton28f45b92016-03-07 13:58:26 -0800295}
296
egdaniel2d721d32015-11-11 13:06:05 -0800297void GrGLSLFragmentShaderBuilder::onFinalize() {
Robert Phillips7de13332019-10-09 15:44:54 -0400298 SkASSERT(fProgramBuilder->processorFeatures() == fUsedProcessorFeaturesAllStages_DebugOnly);
Chris Daltond7291ba2019-03-07 14:17:03 -0700299
Robert Phillips7de13332019-10-09 15:44:54 -0400300 if (CustomFeatures::kSampleLocations & fProgramBuilder->processorFeatures()) {
Robert Phillips65a77752019-10-02 15:22:24 -0400301 const SkTArray<SkPoint>& sampleLocations = fProgramBuilder->getSampleLocations();
Chris Dalton2284aab2019-11-15 11:02:24 -0700302 this->definitions().appendf("const float2 _sampleOffsets[%i] = float2[%i](",
303 sampleLocations.count(), sampleLocations.count());
Chris Daltond7291ba2019-03-07 14:17:03 -0700304 for (int i = 0; i < sampleLocations.count(); ++i) {
305 SkPoint offset = sampleLocations[i] - SkPoint::Make(.5f, .5f);
306 if (kBottomLeft_GrSurfaceOrigin == this->getSurfaceOrigin()) {
307 offset.fY = -offset.fY;
308 }
309 this->definitions().appendf("float2(%f, %f)", offset.x(), offset.y());
310 this->definitions().append((i + 1 != sampleLocations.count()) ? ", " : ");");
311 }
312 }
313
egdaniel0eafe792015-11-20 14:01:22 -0800314 fProgramBuilder->varyingHandler()->getFragDecls(&this->inputs(), &this->outputs());
joshualitt30ba4362014-08-21 20:18:45 -0700315}
316
cdalton85285412016-02-18 12:37:07 -0800317void GrGLSLFragmentShaderBuilder::onBeforeChildProcEmitCode() {
wangyix54a6b1a2015-09-08 08:41:51 -0700318 SkASSERT(fSubstageIndices.count() >= 1);
wangyix7ef45a12015-08-13 06:51:35 -0700319 fSubstageIndices.push_back(0);
wangyix54a6b1a2015-09-08 08:41:51 -0700320 // second-to-last value in the fSubstageIndices stack is the index of the child proc
321 // at that level which is currently emitting code.
322 fMangleString.appendf("_c%d", fSubstageIndices[fSubstageIndices.count() - 2]);
wangyix7ef45a12015-08-13 06:51:35 -0700323}
324
cdalton85285412016-02-18 12:37:07 -0800325void GrGLSLFragmentShaderBuilder::onAfterChildProcEmitCode() {
wangyix54a6b1a2015-09-08 08:41:51 -0700326 SkASSERT(fSubstageIndices.count() >= 2);
wangyix7ef45a12015-08-13 06:51:35 -0700327 fSubstageIndices.pop_back();
wangyix54a6b1a2015-09-08 08:41:51 -0700328 fSubstageIndices.back()++;
wangyix7ef45a12015-08-13 06:51:35 -0700329 int removeAt = fMangleString.findLastOf('_');
330 fMangleString.remove(removeAt, fMangleString.size() - removeAt);
331}