blob: 7e6b8f771cd37ca1fc007d3b541bc4c0f45f7547 [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)
89 , fDefaultPrecision(kMedium_GrSLPrecision) {
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 Nicholas27185a92017-09-18 02:41:08 +0000115 if (kVec3f_GrSLType != coords.getType()) {
116 SkASSERT(kVec2f_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 Nicholas27185a92017-09-18 02:41:08 +0000122 this->codeAppendf("\tfloat2 %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
Ethan Nicholas27185a92017-09-18 02:41:08 +0000178void GrGLSLFragmentShaderBuilder::elevateDefaultPrecision(GrSLPrecision precision) {
179 fDefaultPrecision = SkTMax(fDefaultPrecision, precision);
180}
181
egdaniel2d721d32015-11-11 13:06:05 -0800182const char* GrGLSLFragmentShaderBuilder::dstColor() {
cdalton87332102016-02-26 12:22:02 -0800183 SkDEBUGCODE(fHasReadDstColor = true;)
joshualitt47bb3822014-10-07 16:43:25 -0700184
ethannicholas22793252016-01-30 09:59:10 -0800185 const char* override = fProgramBuilder->primitiveProcessor().getDestColorOverride();
186 if (override != nullptr) {
187 return override;
188 }
189
Brian Salomon1edc5b92016-11-29 13:43:46 -0500190 const GrShaderCaps* shaderCaps = fProgramBuilder->shaderCaps();
191 if (shaderCaps->fbFetchSupport()) {
cdaltonc08f1962016-02-12 12:14:06 -0800192 this->addFeature(1 << kFramebufferFetch_GLSLPrivateFeature,
Brian Salomon1edc5b92016-11-29 13:43:46 -0500193 shaderCaps->fbFetchExtensionString());
joshualittb4384b92014-10-21 12:53:15 -0700194
joshualitt3c1096f2015-01-13 13:13:59 -0800195 // Some versions of this extension string require declaring custom color output on ES 3.0+
Brian Salomon1edc5b92016-11-29 13:43:46 -0500196 const char* fbFetchColorName = shaderCaps->fbFetchColorName();
197 if (shaderCaps->fbFetchNeedsCustomOutput()) {
joshualittb4384b92014-10-21 12:53:15 -0700198 this->enableCustomOutput();
199 fOutputs[fCustomColorOutputIndex].setTypeModifier(GrShaderVar::kInOut_TypeModifier);
egdaniel8dcdedc2015-11-11 06:27:20 -0800200 fbFetchColorName = DeclaredColorOutputName();
egdaniel138c2632016-08-17 10:59:00 -0700201 // Set the dstColor to an intermediate variable so we don't override it with the output
Ethan Nicholas27185a92017-09-18 02:41:08 +0000202 this->codeAppendf("float4 %s = %s;", kDstColorName, fbFetchColorName);
egdanielbd4121a2016-08-17 12:55:30 -0700203 } else {
204 return fbFetchColorName;
joshualittb4384b92014-10-21 12:53:15 -0700205 }
halcanary9d524f22016-03-29 09:03:52 -0700206 }
egdaniel138c2632016-08-17 10:59:00 -0700207 return kDstColorName;
joshualitt47bb3822014-10-07 16:43:25 -0700208}
209
egdaniel2d721d32015-11-11 13:06:05 -0800210void GrGLSLFragmentShaderBuilder::enableAdvancedBlendEquationIfNeeded(GrBlendEquation equation) {
cdalton8917d622015-05-06 13:40:21 -0700211 SkASSERT(GrBlendEquationIsAdvanced(equation));
212
Brian Salomon94efbf52016-11-29 13:43:05 -0500213 const GrShaderCaps& caps = *fProgramBuilder->shaderCaps();
cdalton8917d622015-05-06 13:40:21 -0700214 if (!caps.mustEnableAdvBlendEqs()) {
215 return;
216 }
217
218 this->addFeature(1 << kBlendEquationAdvanced_GLSLPrivateFeature,
219 "GL_KHR_blend_equation_advanced");
220 if (caps.mustEnableSpecificAdvBlendEqs()) {
221 this->addLayoutQualifier(specific_layout_qualifier_name(equation), kOut_InterfaceQualifier);
222 } else {
223 this->addLayoutQualifier("blend_support_all_equations", kOut_InterfaceQualifier);
224 }
225}
226
egdaniel2d721d32015-11-11 13:06:05 -0800227void GrGLSLFragmentShaderBuilder::enableCustomOutput() {
joshualittb4384b92014-10-21 12:53:15 -0700228 if (!fHasCustomColorOutput) {
229 fHasCustomColorOutput = true;
230 fCustomColorOutputIndex = fOutputs.count();
Ethan Nicholas27185a92017-09-18 02:41:08 +0000231 fOutputs.push_back().set(kVec4f_GrSLType, DeclaredColorOutputName(),
Brian Salomon99938a82016-11-21 13:41:08 -0500232 GrShaderVar::kOut_TypeModifier);
ethannicholas5961bc92016-10-12 06:39:56 -0700233 fProgramBuilder->finalizeFragmentOutputColor(fOutputs.back());
joshualittb4384b92014-10-21 12:53:15 -0700234 }
joshualitt47bb3822014-10-07 16:43:25 -0700235}
236
egdaniel2d721d32015-11-11 13:06:05 -0800237void GrGLSLFragmentShaderBuilder::enableSecondaryOutput() {
joshualitt47bb3822014-10-07 16:43:25 -0700238 SkASSERT(!fHasSecondaryOutput);
239 fHasSecondaryOutput = true;
Brian Salomon94efbf52016-11-29 13:43:05 -0500240 const GrShaderCaps& caps = *fProgramBuilder->shaderCaps();
egdaniel8dcdedc2015-11-11 06:27:20 -0800241 if (const char* extension = caps.secondaryOutputExtensionString()) {
242 this->addFeature(1 << kBlendFuncExtended_GLSLPrivateFeature, extension);
kkinnunend94708e2015-07-30 22:47:04 -0700243 }
244
245 // If the primary output is declared, we must declare also the secondary output
246 // and vice versa, since it is not allowed to use a built-in gl_FragColor and a custom
247 // output. The condition also co-incides with the condition in whici GLES SL 2.0
248 // requires the built-in gl_SecondaryFragColorEXT, where as 3.0 requires a custom output.
kkinnunend94708e2015-07-30 22:47:04 -0700249 if (caps.mustDeclareFragmentShaderOutput()) {
Ethan Nicholas27185a92017-09-18 02:41:08 +0000250 fOutputs.push_back().set(kVec4f_GrSLType, DeclaredSecondaryColorOutputName(),
Brian Salomon99938a82016-11-21 13:41:08 -0500251 GrShaderVar::kOut_TypeModifier);
egdanielb80ec8b2016-02-09 09:54:43 -0800252 fProgramBuilder->finalizeFragmentSecondaryColor(fOutputs.back());
kkinnunend94708e2015-07-30 22:47:04 -0700253 }
joshualitt47bb3822014-10-07 16:43:25 -0700254}
255
egdaniel2d721d32015-11-11 13:06:05 -0800256const char* GrGLSLFragmentShaderBuilder::getPrimaryColorOutputName() const {
ethannicholas5961bc92016-10-12 06:39:56 -0700257 return fHasCustomColorOutput ? DeclaredColorOutputName() : "sk_FragColor";
joshualitt47bb3822014-10-07 16:43:25 -0700258}
259
ethannicholas22793252016-01-30 09:59:10 -0800260void GrGLSLFragmentBuilder::declAppendf(const char* fmt, ...) {
261 va_list argp;
262 va_start(argp, fmt);
263 inputs().appendVAList(fmt, argp);
halcanary9d524f22016-03-29 09:03:52 -0700264 va_end(argp);
ethannicholas22793252016-01-30 09:59:10 -0800265}
266
egdaniel2d721d32015-11-11 13:06:05 -0800267const char* GrGLSLFragmentShaderBuilder::getSecondaryColorOutputName() const {
Brian Salomon94efbf52016-11-29 13:43:05 -0500268 const GrShaderCaps& caps = *fProgramBuilder->shaderCaps();
egdaniel8dcdedc2015-11-11 06:27:20 -0800269 return caps.mustDeclareFragmentShaderOutput() ? DeclaredSecondaryColorOutputName()
kkinnunend94708e2015-07-30 22:47:04 -0700270 : "gl_SecondaryFragColorEXT";
joshualitt47bb3822014-10-07 16:43:25 -0700271}
272
cdalton28f45b92016-03-07 13:58:26 -0800273GrSurfaceOrigin GrGLSLFragmentShaderBuilder::getSurfaceOrigin() const {
274 SkASSERT(fProgramBuilder->header().fSurfaceOriginKey);
Robert Phillipsfb4a20c2017-08-29 14:46:43 -0400275 return static_cast<GrSurfaceOrigin>(fProgramBuilder->header().fSurfaceOriginKey-1);
cdalton28f45b92016-03-07 13:58:26 -0800276
Robert Phillipsfb4a20c2017-08-29 14:46:43 -0400277 GR_STATIC_ASSERT(0 == kTopLeft_GrSurfaceOrigin);
278 GR_STATIC_ASSERT(1 == kBottomLeft_GrSurfaceOrigin);
cdalton28f45b92016-03-07 13:58:26 -0800279}
280
egdaniel2d721d32015-11-11 13:06:05 -0800281void GrGLSLFragmentShaderBuilder::onFinalize() {
egdaniel0eafe792015-11-20 14:01:22 -0800282 fProgramBuilder->varyingHandler()->getFragDecls(&this->inputs(), &this->outputs());
Ethan Nicholas27185a92017-09-18 02:41:08 +0000283 GrGLSLAppendDefaultFloatPrecisionDeclaration(fDefaultPrecision,
284 *fProgramBuilder->shaderCaps(),
285 &this->precisionQualifier());
cdalton28f45b92016-03-07 13:58:26 -0800286 if (fUsedSampleOffsetArrays & (1 << kSkiaDevice_Coordinates)) {
287 this->defineSampleOffsetArray(sample_offset_array_name(kSkiaDevice_Coordinates),
288 SkMatrix::MakeTrans(-0.5f, -0.5f));
289 }
290 if (fUsedSampleOffsetArrays & (1 << kGLSLWindow_Coordinates)) {
291 // With a top left origin, device and window space are equal, so we only use device coords.
292 SkASSERT(kBottomLeft_GrSurfaceOrigin == this->getSurfaceOrigin());
293 SkMatrix m;
294 m.setScale(1, -1);
295 m.preTranslate(-0.5f, -0.5f);
296 this->defineSampleOffsetArray(sample_offset_array_name(kGLSLWindow_Coordinates), m);
297 }
298}
299
300void GrGLSLFragmentShaderBuilder::defineSampleOffsetArray(const char* name, const SkMatrix& m) {
301 SkASSERT(fProgramBuilder->caps()->sampleLocationsSupport());
302 const GrPipeline& pipeline = fProgramBuilder->pipeline();
Robert Phillips2890fbf2017-07-26 15:48:41 -0400303 const GrRenderTargetPriv& rtp = pipeline.renderTarget()->renderTargetPriv();
csmartdaltonc633abb2016-11-01 08:55:55 -0700304 const GrGpu::MultisampleSpecs& specs = rtp.getMultisampleSpecs(pipeline);
cdalton28f45b92016-03-07 13:58:26 -0800305 SkSTArray<16, SkPoint, true> offsets;
306 offsets.push_back_n(specs.fEffectiveSampleCnt);
csmartdalton0d28e572016-07-06 09:59:43 -0700307 m.mapPoints(offsets.begin(), specs.fSampleLocations, specs.fEffectiveSampleCnt);
Ethan Nicholas27185a92017-09-18 02:41:08 +0000308 this->definitions().appendf("const highp float2 %s[] = float2[](", name);
cdalton28f45b92016-03-07 13:58:26 -0800309 for (int i = 0; i < specs.fEffectiveSampleCnt; ++i) {
Ethan Nicholas27185a92017-09-18 02:41:08 +0000310 this->definitions().appendf("float2(%f, %f)", offsets[i].x(), offsets[i].y());
cdalton28f45b92016-03-07 13:58:26 -0800311 this->definitions().append(i + 1 != specs.fEffectiveSampleCnt ? ", " : ");\n");
312 }
joshualitt30ba4362014-08-21 20:18:45 -0700313}
314
cdalton85285412016-02-18 12:37:07 -0800315void GrGLSLFragmentShaderBuilder::onBeforeChildProcEmitCode() {
wangyix54a6b1a2015-09-08 08:41:51 -0700316 SkASSERT(fSubstageIndices.count() >= 1);
wangyix7ef45a12015-08-13 06:51:35 -0700317 fSubstageIndices.push_back(0);
wangyix54a6b1a2015-09-08 08:41:51 -0700318 // second-to-last value in the fSubstageIndices stack is the index of the child proc
319 // at that level which is currently emitting code.
320 fMangleString.appendf("_c%d", fSubstageIndices[fSubstageIndices.count() - 2]);
wangyix7ef45a12015-08-13 06:51:35 -0700321}
322
cdalton85285412016-02-18 12:37:07 -0800323void GrGLSLFragmentShaderBuilder::onAfterChildProcEmitCode() {
wangyix54a6b1a2015-09-08 08:41:51 -0700324 SkASSERT(fSubstageIndices.count() >= 2);
wangyix7ef45a12015-08-13 06:51:35 -0700325 fSubstageIndices.pop_back();
wangyix54a6b1a2015-09-08 08:41:51 -0700326 fSubstageIndices.back()++;
wangyix7ef45a12015-08-13 06:51:35 -0700327 int removeAt = fMangleString.findLastOf('_');
328 fMangleString.remove(removeAt, fMangleString.size() - removeAt);
329}