blob: ad39497392e49505a915db5483b75ed1ce8a1d0a [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
egdaniel2d721d32015-11-11 13:06:05 -08008#include "GrGLSLFragmentShaderBuilder.h"
egdaniel574a4c12015-11-02 06:22:44 -08009#include "GrRenderTarget.h"
cdalton28f45b92016-03-07 13:58:26 -080010#include "GrRenderTargetPriv.h"
Brian Salomon94efbf52016-11-29 13:43:05 -050011#include "GrShaderCaps.h"
ethannicholas22793252016-01-30 09:59:10 -080012#include "gl/GrGLGpu.h"
egdaniel8dcdedc2015-11-11 06:27:20 -080013#include "glsl/GrGLSLProgramBuilder.h"
egdaniel7ea439b2015-12-03 09:20:44 -080014#include "glsl/GrGLSLUniformHandler.h"
egdaniel0eafe792015-11-20 14:01:22 -080015#include "glsl/GrGLSLVarying.h"
Brian Salomon94efbf52016-11-29 13:43:05 -050016#include "../private/GrGLSL.h"
joshualitt47bb3822014-10-07 16:43:25 -070017
egdaniel138c2632016-08-17 10:59:00 -070018const char* GrGLSLFragmentShaderBuilder::kDstColorName = "_dstColor";
joshualitt30ba4362014-08-21 20:18:45 -070019
cdalton28f45b92016-03-07 13:58:26 -080020static const char* sample_offset_array_name(GrGLSLFPFragmentBuilder::Coordinates coords) {
21 static const char* kArrayNames[] = {
22 "deviceSpaceSampleOffsets",
23 "windowSpaceSampleOffsets"
24 };
25 return kArrayNames[coords];
26
27 GR_STATIC_ASSERT(0 == GrGLSLFPFragmentBuilder::kSkiaDevice_Coordinates);
28 GR_STATIC_ASSERT(1 == GrGLSLFPFragmentBuilder::kGLSLWindow_Coordinates);
29 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kArrayNames) == GrGLSLFPFragmentBuilder::kLast_Coordinates + 1);
30}
31
cdalton8917d622015-05-06 13:40:21 -070032static const char* specific_layout_qualifier_name(GrBlendEquation equation) {
33 SkASSERT(GrBlendEquationIsAdvanced(equation));
34
35 static const char* kLayoutQualifierNames[] = {
36 "blend_support_screen",
37 "blend_support_overlay",
38 "blend_support_darken",
39 "blend_support_lighten",
40 "blend_support_colordodge",
41 "blend_support_colorburn",
42 "blend_support_hardlight",
43 "blend_support_softlight",
44 "blend_support_difference",
45 "blend_support_exclusion",
46 "blend_support_multiply",
47 "blend_support_hsl_hue",
48 "blend_support_hsl_saturation",
49 "blend_support_hsl_color",
50 "blend_support_hsl_luminosity"
51 };
52 return kLayoutQualifierNames[equation - kFirstAdvancedGrBlendEquation];
53
54 GR_STATIC_ASSERT(0 == kScreen_GrBlendEquation - kFirstAdvancedGrBlendEquation);
55 GR_STATIC_ASSERT(1 == kOverlay_GrBlendEquation - kFirstAdvancedGrBlendEquation);
56 GR_STATIC_ASSERT(2 == kDarken_GrBlendEquation - kFirstAdvancedGrBlendEquation);
57 GR_STATIC_ASSERT(3 == kLighten_GrBlendEquation - kFirstAdvancedGrBlendEquation);
58 GR_STATIC_ASSERT(4 == kColorDodge_GrBlendEquation - kFirstAdvancedGrBlendEquation);
59 GR_STATIC_ASSERT(5 == kColorBurn_GrBlendEquation - kFirstAdvancedGrBlendEquation);
60 GR_STATIC_ASSERT(6 == kHardLight_GrBlendEquation - kFirstAdvancedGrBlendEquation);
61 GR_STATIC_ASSERT(7 == kSoftLight_GrBlendEquation - kFirstAdvancedGrBlendEquation);
62 GR_STATIC_ASSERT(8 == kDifference_GrBlendEquation - kFirstAdvancedGrBlendEquation);
63 GR_STATIC_ASSERT(9 == kExclusion_GrBlendEquation - kFirstAdvancedGrBlendEquation);
64 GR_STATIC_ASSERT(10 == kMultiply_GrBlendEquation - kFirstAdvancedGrBlendEquation);
65 GR_STATIC_ASSERT(11 == kHSLHue_GrBlendEquation - kFirstAdvancedGrBlendEquation);
66 GR_STATIC_ASSERT(12 == kHSLSaturation_GrBlendEquation - kFirstAdvancedGrBlendEquation);
67 GR_STATIC_ASSERT(13 == kHSLColor_GrBlendEquation - kFirstAdvancedGrBlendEquation);
68 GR_STATIC_ASSERT(14 == kHSLLuminosity_GrBlendEquation - kFirstAdvancedGrBlendEquation);
69 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kLayoutQualifierNames) ==
bsalomonf7cc8772015-05-11 11:21:14 -070070 kGrBlendEquationCnt - kFirstAdvancedGrBlendEquation);
cdalton8917d622015-05-06 13:40:21 -070071}
72
cdalton28f45b92016-03-07 13:58:26 -080073uint8_t GrGLSLFragmentShaderBuilder::KeyForSurfaceOrigin(GrSurfaceOrigin origin) {
74 SkASSERT(kTopLeft_GrSurfaceOrigin == origin || kBottomLeft_GrSurfaceOrigin == origin);
Robert Phillipsfb4a20c2017-08-29 14:46:43 -040075 return origin + 1;
cdalton28f45b92016-03-07 13:58:26 -080076
Robert Phillipsfb4a20c2017-08-29 14:46:43 -040077 GR_STATIC_ASSERT(0 == kTopLeft_GrSurfaceOrigin);
78 GR_STATIC_ASSERT(1 == kBottomLeft_GrSurfaceOrigin);
joshualitt30ba4362014-08-21 20:18:45 -070079}
80
cdalton28f45b92016-03-07 13:58:26 -080081GrGLSLFragmentShaderBuilder::GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder* program)
cdalton85285412016-02-18 12:37:07 -080082 : GrGLSLFragmentBuilder(program)
joshualitt30ba4362014-08-21 20:18:45 -070083 , fSetupFragPosition(false)
cdalton85285412016-02-18 12:37:07 -080084 , fHasCustomColorOutput(false)
joshualittb4384b92014-10-21 12:53:15 -070085 , fCustomColorOutputIndex(-1)
cdalton85285412016-02-18 12:37:07 -080086 , fHasSecondaryOutput(false)
cdalton28f45b92016-03-07 13:58:26 -080087 , fUsedSampleOffsetArrays(0)
Ethan Nicholas27185a92017-09-18 02:41:08 +000088 , fHasInitializedSampleMask(false)
Ethan Nicholasf7b88202017-09-18 14:10:39 -040089 , fForceHighPrecision(false) {
cdalton85285412016-02-18 12:37:07 -080090 fSubstageIndices.push_back(0);
cdalton87332102016-02-26 12:22:02 -080091#ifdef SK_DEBUG
92 fUsedProcessorFeatures = GrProcessor::kNone_RequiredFeatures;
93 fHasReadDstColor = false;
94#endif
95}
96
egdaniel2d721d32015-11-11 13:06:05 -080097bool GrGLSLFragmentShaderBuilder::enableFeature(GLSLFeature feature) {
Brian Salomon1edc5b92016-11-29 13:43:46 -050098 const GrShaderCaps& shaderCaps = *fProgramBuilder->shaderCaps();
joshualitt30ba4362014-08-21 20:18:45 -070099 switch (feature) {
cdalton4a98cdb2016-03-01 12:12:20 -0800100 case kMultisampleInterpolation_GLSLFeature:
Brian Salomon1edc5b92016-11-29 13:43:46 -0500101 if (!shaderCaps.multisampleInterpolationSupport()) {
cdalton4a98cdb2016-03-01 12:12:20 -0800102 return false;
103 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500104 if (const char* extension = shaderCaps.multisampleInterpolationExtensionString()) {
cdalton4a98cdb2016-03-01 12:12:20 -0800105 this->addFeature(1 << kMultisampleInterpolation_GLSLFeature, extension);
106 }
107 return true;
joshualitt30ba4362014-08-21 20:18:45 -0700108 default:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400109 SK_ABORT("Unexpected GLSLFeature requested.");
joshualitt30ba4362014-08-21 20:18:45 -0700110 return false;
111 }
112}
113
bsalomon1a1aa932016-09-12 09:30:36 -0700114SkString GrGLSLFragmentShaderBuilder::ensureCoords2D(const GrShaderVar& coords) {
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400115 if (kHighFloat3_GrSLType != coords.getType() && kHalf3_GrSLType != coords.getType()) {
116 SkASSERT(kHighFloat2_GrSLType == coords.getType() || kHalf2_GrSLType == coords.getType());
bsalomon1a1aa932016-09-12 09:30:36 -0700117 return coords.getName();
joshualitt30ba4362014-08-21 20:18:45 -0700118 }
119
bsalomon1a1aa932016-09-12 09:30:36 -0700120 SkString coords2D;
121 coords2D.printf("%s_ensure2D", coords.c_str());
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400122 this->codeAppendf("\thighfloat2 %s = %s.xy / %s.z;", coords2D.c_str(), coords.c_str(),
bsalomon1a1aa932016-09-12 09:30:36 -0700123 coords.c_str());
joshualitt30ba4362014-08-21 20:18:45 -0700124 return coords2D;
125}
126
cdalton28f45b92016-03-07 13:58:26 -0800127void GrGLSLFragmentShaderBuilder::appendOffsetToSample(const char* sampleIdx, Coordinates coords) {
128 SkASSERT(fProgramBuilder->header().fSamplePatternKey);
129 SkDEBUGCODE(fUsedProcessorFeatures |= GrProcessor::kSampleLocations_RequiredFeature);
130 if (kTopLeft_GrSurfaceOrigin == this->getSurfaceOrigin()) {
131 // With a top left origin, device and window space are equal, so we only use device coords.
132 coords = kSkiaDevice_Coordinates;
133 }
134 this->codeAppendf("%s[%s]", sample_offset_array_name(coords), sampleIdx);
135 fUsedSampleOffsetArrays |= (1 << coords);
136}
137
cdalton33ad7012016-02-22 07:55:44 -0800138void GrGLSLFragmentShaderBuilder::maskSampleCoverage(const char* mask, bool invert) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500139 const GrShaderCaps& shaderCaps = *fProgramBuilder->shaderCaps();
140 if (!shaderCaps.sampleVariablesSupport()) {
cdalton33ad7012016-02-22 07:55:44 -0800141 SkDEBUGFAIL("Attempted to mask sample coverage without support.");
142 return;
143 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500144 if (const char* extension = shaderCaps.sampleVariablesExtensionString()) {
cdalton33ad7012016-02-22 07:55:44 -0800145 this->addFeature(1 << kSampleVariables_GLSLPrivateFeature, extension);
146 }
147 if (!fHasInitializedSampleMask) {
148 this->codePrependf("gl_SampleMask[0] = -1;");
149 fHasInitializedSampleMask = true;
150 }
151 if (invert) {
152 this->codeAppendf("gl_SampleMask[0] &= ~(%s);", mask);
153 } else {
154 this->codeAppendf("gl_SampleMask[0] &= %s;", mask);
155 }
156}
157
158void GrGLSLFragmentShaderBuilder::overrideSampleCoverage(const char* mask) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500159 const GrShaderCaps& shaderCaps = *fProgramBuilder->shaderCaps();
160 if (!shaderCaps.sampleMaskOverrideCoverageSupport()) {
cdalton33ad7012016-02-22 07:55:44 -0800161 SkDEBUGFAIL("Attempted to override sample coverage without support.");
162 return;
163 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500164 SkASSERT(shaderCaps.sampleVariablesSupport());
165 if (const char* extension = shaderCaps.sampleVariablesExtensionString()) {
cdalton33ad7012016-02-22 07:55:44 -0800166 this->addFeature(1 << kSampleVariables_GLSLPrivateFeature, extension);
167 }
168 if (this->addFeature(1 << kSampleMaskOverrideCoverage_GLSLPrivateFeature,
169 "GL_NV_sample_mask_override_coverage")) {
170 // Redeclare gl_SampleMask with layout(override_coverage) if we haven't already.
Brian Salomon99938a82016-11-21 13:41:08 -0500171 fOutputs.push_back().set(kInt_GrSLType, "gl_SampleMask", 1, GrShaderVar::kOut_TypeModifier,
172 kHigh_GrSLPrecision, "override_coverage");
cdalton33ad7012016-02-22 07:55:44 -0800173 }
174 this->codeAppendf("gl_SampleMask[0] = %s;", mask);
175 fHasInitializedSampleMask = true;
176}
177
egdaniel2d721d32015-11-11 13:06:05 -0800178const char* GrGLSLFragmentShaderBuilder::dstColor() {
cdalton87332102016-02-26 12:22:02 -0800179 SkDEBUGCODE(fHasReadDstColor = true;)
joshualitt47bb3822014-10-07 16:43:25 -0700180
ethannicholas22793252016-01-30 09:59:10 -0800181 const char* override = fProgramBuilder->primitiveProcessor().getDestColorOverride();
182 if (override != nullptr) {
183 return override;
184 }
185
Brian Salomon1edc5b92016-11-29 13:43:46 -0500186 const GrShaderCaps* shaderCaps = fProgramBuilder->shaderCaps();
187 if (shaderCaps->fbFetchSupport()) {
cdaltonc08f1962016-02-12 12:14:06 -0800188 this->addFeature(1 << kFramebufferFetch_GLSLPrivateFeature,
Brian Salomon1edc5b92016-11-29 13:43:46 -0500189 shaderCaps->fbFetchExtensionString());
joshualittb4384b92014-10-21 12:53:15 -0700190
joshualitt3c1096f2015-01-13 13:13:59 -0800191 // Some versions of this extension string require declaring custom color output on ES 3.0+
Brian Salomon1edc5b92016-11-29 13:43:46 -0500192 const char* fbFetchColorName = shaderCaps->fbFetchColorName();
193 if (shaderCaps->fbFetchNeedsCustomOutput()) {
joshualittb4384b92014-10-21 12:53:15 -0700194 this->enableCustomOutput();
195 fOutputs[fCustomColorOutputIndex].setTypeModifier(GrShaderVar::kInOut_TypeModifier);
egdaniel8dcdedc2015-11-11 06:27:20 -0800196 fbFetchColorName = DeclaredColorOutputName();
egdaniel138c2632016-08-17 10:59:00 -0700197 // Set the dstColor to an intermediate variable so we don't override it with the output
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400198 this->codeAppendf("half4 %s = %s;", kDstColorName, fbFetchColorName);
egdanielbd4121a2016-08-17 12:55:30 -0700199 } else {
200 return fbFetchColorName;
joshualittb4384b92014-10-21 12:53:15 -0700201 }
halcanary9d524f22016-03-29 09:03:52 -0700202 }
egdaniel138c2632016-08-17 10:59:00 -0700203 return kDstColorName;
joshualitt47bb3822014-10-07 16:43:25 -0700204}
205
egdaniel2d721d32015-11-11 13:06:05 -0800206void GrGLSLFragmentShaderBuilder::enableAdvancedBlendEquationIfNeeded(GrBlendEquation equation) {
cdalton8917d622015-05-06 13:40:21 -0700207 SkASSERT(GrBlendEquationIsAdvanced(equation));
208
Brian Salomon94efbf52016-11-29 13:43:05 -0500209 const GrShaderCaps& caps = *fProgramBuilder->shaderCaps();
cdalton8917d622015-05-06 13:40:21 -0700210 if (!caps.mustEnableAdvBlendEqs()) {
211 return;
212 }
213
214 this->addFeature(1 << kBlendEquationAdvanced_GLSLPrivateFeature,
215 "GL_KHR_blend_equation_advanced");
216 if (caps.mustEnableSpecificAdvBlendEqs()) {
217 this->addLayoutQualifier(specific_layout_qualifier_name(equation), kOut_InterfaceQualifier);
218 } else {
219 this->addLayoutQualifier("blend_support_all_equations", kOut_InterfaceQualifier);
220 }
221}
222
egdaniel2d721d32015-11-11 13:06:05 -0800223void GrGLSLFragmentShaderBuilder::enableCustomOutput() {
joshualittb4384b92014-10-21 12:53:15 -0700224 if (!fHasCustomColorOutput) {
225 fHasCustomColorOutput = true;
226 fCustomColorOutputIndex = fOutputs.count();
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400227 fOutputs.push_back().set(kHalf4_GrSLType, DeclaredColorOutputName(),
Brian Salomon99938a82016-11-21 13:41:08 -0500228 GrShaderVar::kOut_TypeModifier);
ethannicholas5961bc92016-10-12 06:39:56 -0700229 fProgramBuilder->finalizeFragmentOutputColor(fOutputs.back());
joshualittb4384b92014-10-21 12:53:15 -0700230 }
joshualitt47bb3822014-10-07 16:43:25 -0700231}
232
egdaniel2d721d32015-11-11 13:06:05 -0800233void GrGLSLFragmentShaderBuilder::enableSecondaryOutput() {
joshualitt47bb3822014-10-07 16:43:25 -0700234 SkASSERT(!fHasSecondaryOutput);
235 fHasSecondaryOutput = true;
Brian Salomon94efbf52016-11-29 13:43:05 -0500236 const GrShaderCaps& caps = *fProgramBuilder->shaderCaps();
egdaniel8dcdedc2015-11-11 06:27:20 -0800237 if (const char* extension = caps.secondaryOutputExtensionString()) {
238 this->addFeature(1 << kBlendFuncExtended_GLSLPrivateFeature, extension);
kkinnunend94708e2015-07-30 22:47:04 -0700239 }
240
241 // If the primary output is declared, we must declare also the secondary output
242 // and vice versa, since it is not allowed to use a built-in gl_FragColor and a custom
243 // output. The condition also co-incides with the condition in whici GLES SL 2.0
244 // requires the built-in gl_SecondaryFragColorEXT, where as 3.0 requires a custom output.
kkinnunend94708e2015-07-30 22:47:04 -0700245 if (caps.mustDeclareFragmentShaderOutput()) {
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400246 fOutputs.push_back().set(kHalf4_GrSLType, DeclaredSecondaryColorOutputName(),
Brian Salomon99938a82016-11-21 13:41:08 -0500247 GrShaderVar::kOut_TypeModifier);
egdanielb80ec8b2016-02-09 09:54:43 -0800248 fProgramBuilder->finalizeFragmentSecondaryColor(fOutputs.back());
kkinnunend94708e2015-07-30 22:47:04 -0700249 }
joshualitt47bb3822014-10-07 16:43:25 -0700250}
251
egdaniel2d721d32015-11-11 13:06:05 -0800252const char* GrGLSLFragmentShaderBuilder::getPrimaryColorOutputName() const {
ethannicholas5961bc92016-10-12 06:39:56 -0700253 return fHasCustomColorOutput ? DeclaredColorOutputName() : "sk_FragColor";
joshualitt47bb3822014-10-07 16:43:25 -0700254}
255
ethannicholas22793252016-01-30 09:59:10 -0800256void GrGLSLFragmentBuilder::declAppendf(const char* fmt, ...) {
257 va_list argp;
258 va_start(argp, fmt);
259 inputs().appendVAList(fmt, argp);
halcanary9d524f22016-03-29 09:03:52 -0700260 va_end(argp);
ethannicholas22793252016-01-30 09:59:10 -0800261}
262
egdaniel2d721d32015-11-11 13:06:05 -0800263const char* GrGLSLFragmentShaderBuilder::getSecondaryColorOutputName() const {
Brian Salomon94efbf52016-11-29 13:43:05 -0500264 const GrShaderCaps& caps = *fProgramBuilder->shaderCaps();
egdaniel8dcdedc2015-11-11 06:27:20 -0800265 return caps.mustDeclareFragmentShaderOutput() ? DeclaredSecondaryColorOutputName()
kkinnunend94708e2015-07-30 22:47:04 -0700266 : "gl_SecondaryFragColorEXT";
joshualitt47bb3822014-10-07 16:43:25 -0700267}
268
cdalton28f45b92016-03-07 13:58:26 -0800269GrSurfaceOrigin GrGLSLFragmentShaderBuilder::getSurfaceOrigin() const {
270 SkASSERT(fProgramBuilder->header().fSurfaceOriginKey);
Robert Phillipsfb4a20c2017-08-29 14:46:43 -0400271 return static_cast<GrSurfaceOrigin>(fProgramBuilder->header().fSurfaceOriginKey-1);
cdalton28f45b92016-03-07 13:58:26 -0800272
Robert Phillipsfb4a20c2017-08-29 14:46:43 -0400273 GR_STATIC_ASSERT(0 == kTopLeft_GrSurfaceOrigin);
274 GR_STATIC_ASSERT(1 == kBottomLeft_GrSurfaceOrigin);
cdalton28f45b92016-03-07 13:58:26 -0800275}
276
egdaniel2d721d32015-11-11 13:06:05 -0800277void GrGLSLFragmentShaderBuilder::onFinalize() {
egdaniel0eafe792015-11-20 14:01:22 -0800278 fProgramBuilder->varyingHandler()->getFragDecls(&this->inputs(), &this->outputs());
cdalton28f45b92016-03-07 13:58:26 -0800279 if (fUsedSampleOffsetArrays & (1 << kSkiaDevice_Coordinates)) {
280 this->defineSampleOffsetArray(sample_offset_array_name(kSkiaDevice_Coordinates),
281 SkMatrix::MakeTrans(-0.5f, -0.5f));
282 }
283 if (fUsedSampleOffsetArrays & (1 << kGLSLWindow_Coordinates)) {
284 // With a top left origin, device and window space are equal, so we only use device coords.
285 SkASSERT(kBottomLeft_GrSurfaceOrigin == this->getSurfaceOrigin());
286 SkMatrix m;
287 m.setScale(1, -1);
288 m.preTranslate(-0.5f, -0.5f);
289 this->defineSampleOffsetArray(sample_offset_array_name(kGLSLWindow_Coordinates), m);
290 }
291}
292
293void GrGLSLFragmentShaderBuilder::defineSampleOffsetArray(const char* name, const SkMatrix& m) {
294 SkASSERT(fProgramBuilder->caps()->sampleLocationsSupport());
295 const GrPipeline& pipeline = fProgramBuilder->pipeline();
Robert Phillips2890fbf2017-07-26 15:48:41 -0400296 const GrRenderTargetPriv& rtp = pipeline.renderTarget()->renderTargetPriv();
csmartdaltonc633abb2016-11-01 08:55:55 -0700297 const GrGpu::MultisampleSpecs& specs = rtp.getMultisampleSpecs(pipeline);
cdalton28f45b92016-03-07 13:58:26 -0800298 SkSTArray<16, SkPoint, true> offsets;
299 offsets.push_back_n(specs.fEffectiveSampleCnt);
csmartdalton0d28e572016-07-06 09:59:43 -0700300 m.mapPoints(offsets.begin(), specs.fSampleLocations, specs.fEffectiveSampleCnt);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400301 this->definitions().appendf("const highfloat2 %s[] = highfloat2[](", name);
cdalton28f45b92016-03-07 13:58:26 -0800302 for (int i = 0; i < specs.fEffectiveSampleCnt; ++i) {
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400303 this->definitions().appendf("highfloat2(%f, %f)", offsets[i].x(), offsets[i].y());
cdalton28f45b92016-03-07 13:58:26 -0800304 this->definitions().append(i + 1 != specs.fEffectiveSampleCnt ? ", " : ");\n");
305 }
joshualitt30ba4362014-08-21 20:18:45 -0700306}
307
cdalton85285412016-02-18 12:37:07 -0800308void GrGLSLFragmentShaderBuilder::onBeforeChildProcEmitCode() {
wangyix54a6b1a2015-09-08 08:41:51 -0700309 SkASSERT(fSubstageIndices.count() >= 1);
wangyix7ef45a12015-08-13 06:51:35 -0700310 fSubstageIndices.push_back(0);
wangyix54a6b1a2015-09-08 08:41:51 -0700311 // second-to-last value in the fSubstageIndices stack is the index of the child proc
312 // at that level which is currently emitting code.
313 fMangleString.appendf("_c%d", fSubstageIndices[fSubstageIndices.count() - 2]);
wangyix7ef45a12015-08-13 06:51:35 -0700314}
315
cdalton85285412016-02-18 12:37:07 -0800316void GrGLSLFragmentShaderBuilder::onAfterChildProcEmitCode() {
wangyix54a6b1a2015-09-08 08:41:51 -0700317 SkASSERT(fSubstageIndices.count() >= 2);
wangyix7ef45a12015-08-13 06:51:35 -0700318 fSubstageIndices.pop_back();
wangyix54a6b1a2015-09-08 08:41:51 -0700319 fSubstageIndices.back()++;
wangyix7ef45a12015-08-13 06:51:35 -0700320 int removeAt = fMangleString.findLastOf('_');
321 fMangleString.remove(removeAt, fMangleString.size() - removeAt);
322}