joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame^] | 8 | #include "GrGLSLFragmentShaderBuilder.h" |
egdaniel | 574a4c1 | 2015-11-02 06:22:44 -0800 | [diff] [blame] | 9 | #include "GrRenderTarget.h" |
egdaniel | cb7ba1e | 2015-10-26 08:38:25 -0700 | [diff] [blame] | 10 | #include "glsl/GrGLSL.h" |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 11 | #include "glsl/GrGLSLCaps.h" |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 12 | #include "glsl/GrGLSLProgramBuilder.h" |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 13 | |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame^] | 14 | const char* GrGLSLFragmentShaderBuilder::kDstTextureColorName = "_dstColor"; |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 15 | |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 16 | static const char* specific_layout_qualifier_name(GrBlendEquation equation) { |
| 17 | SkASSERT(GrBlendEquationIsAdvanced(equation)); |
| 18 | |
| 19 | static const char* kLayoutQualifierNames[] = { |
| 20 | "blend_support_screen", |
| 21 | "blend_support_overlay", |
| 22 | "blend_support_darken", |
| 23 | "blend_support_lighten", |
| 24 | "blend_support_colordodge", |
| 25 | "blend_support_colorburn", |
| 26 | "blend_support_hardlight", |
| 27 | "blend_support_softlight", |
| 28 | "blend_support_difference", |
| 29 | "blend_support_exclusion", |
| 30 | "blend_support_multiply", |
| 31 | "blend_support_hsl_hue", |
| 32 | "blend_support_hsl_saturation", |
| 33 | "blend_support_hsl_color", |
| 34 | "blend_support_hsl_luminosity" |
| 35 | }; |
| 36 | return kLayoutQualifierNames[equation - kFirstAdvancedGrBlendEquation]; |
| 37 | |
| 38 | GR_STATIC_ASSERT(0 == kScreen_GrBlendEquation - kFirstAdvancedGrBlendEquation); |
| 39 | GR_STATIC_ASSERT(1 == kOverlay_GrBlendEquation - kFirstAdvancedGrBlendEquation); |
| 40 | GR_STATIC_ASSERT(2 == kDarken_GrBlendEquation - kFirstAdvancedGrBlendEquation); |
| 41 | GR_STATIC_ASSERT(3 == kLighten_GrBlendEquation - kFirstAdvancedGrBlendEquation); |
| 42 | GR_STATIC_ASSERT(4 == kColorDodge_GrBlendEquation - kFirstAdvancedGrBlendEquation); |
| 43 | GR_STATIC_ASSERT(5 == kColorBurn_GrBlendEquation - kFirstAdvancedGrBlendEquation); |
| 44 | GR_STATIC_ASSERT(6 == kHardLight_GrBlendEquation - kFirstAdvancedGrBlendEquation); |
| 45 | GR_STATIC_ASSERT(7 == kSoftLight_GrBlendEquation - kFirstAdvancedGrBlendEquation); |
| 46 | GR_STATIC_ASSERT(8 == kDifference_GrBlendEquation - kFirstAdvancedGrBlendEquation); |
| 47 | GR_STATIC_ASSERT(9 == kExclusion_GrBlendEquation - kFirstAdvancedGrBlendEquation); |
| 48 | GR_STATIC_ASSERT(10 == kMultiply_GrBlendEquation - kFirstAdvancedGrBlendEquation); |
| 49 | GR_STATIC_ASSERT(11 == kHSLHue_GrBlendEquation - kFirstAdvancedGrBlendEquation); |
| 50 | GR_STATIC_ASSERT(12 == kHSLSaturation_GrBlendEquation - kFirstAdvancedGrBlendEquation); |
| 51 | GR_STATIC_ASSERT(13 == kHSLColor_GrBlendEquation - kFirstAdvancedGrBlendEquation); |
| 52 | GR_STATIC_ASSERT(14 == kHSLLuminosity_GrBlendEquation - kFirstAdvancedGrBlendEquation); |
| 53 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kLayoutQualifierNames) == |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 54 | kGrBlendEquationCnt - kFirstAdvancedGrBlendEquation); |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 55 | } |
| 56 | |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame^] | 57 | GrGLSLFragmentShaderBuilder::FragPosKey |
| 58 | GrGLSLFragmentShaderBuilder::KeyForFragmentPosition(const GrRenderTarget* dst) { |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 59 | if (kTopLeft_GrSurfaceOrigin == dst->origin()) { |
| 60 | return kTopLeftFragPosRead_FragPosKey; |
| 61 | } else { |
| 62 | return kBottomLeftFragPosRead_FragPosKey; |
| 63 | } |
| 64 | } |
| 65 | |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame^] | 66 | GrGLSLFragmentShaderBuilder::GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder* program, |
| 67 | uint8_t fragPosKey) |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 68 | : INHERITED(program) |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 69 | , fSetupFragPosition(false) |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 70 | , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == fragPosKey) |
joshualitt | b4384b9 | 2014-10-21 12:53:15 -0700 | [diff] [blame] | 71 | , fCustomColorOutputIndex(-1) |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 72 | , fHasReadDstColor(false) |
| 73 | , fHasReadFragmentPosition(false) { |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 74 | } |
| 75 | |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame^] | 76 | bool GrGLSLFragmentShaderBuilder::enableFeature(GLSLFeature feature) { |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 77 | switch (feature) { |
| 78 | case kStandardDerivatives_GLSLFeature: { |
egdaniel | 574a4c1 | 2015-11-02 06:22:44 -0800 | [diff] [blame] | 79 | if (!fProgramBuilder->glslCaps()->shaderDerivativeSupport()) { |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 80 | return false; |
| 81 | } |
egdaniel | 574a4c1 | 2015-11-02 06:22:44 -0800 | [diff] [blame] | 82 | const char* extension = fProgramBuilder->glslCaps()->shaderDerivativeExtensionString(); |
| 83 | if (extension) { |
| 84 | this->addFeature(1 << kStandardDerivatives_GLSLFeature, extension); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 85 | } |
| 86 | return true; |
| 87 | } |
| 88 | default: |
| 89 | SkFAIL("Unexpected GLSLFeature requested."); |
| 90 | return false; |
| 91 | } |
| 92 | } |
| 93 | |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame^] | 94 | SkString GrGLSLFragmentShaderBuilder::ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords, |
| 95 | int index) { |
joshualitt | 23e280d | 2014-09-18 12:26:38 -0700 | [diff] [blame] | 96 | if (kVec3f_GrSLType != coords[index].getType()) { |
| 97 | SkASSERT(kVec2f_GrSLType == coords[index].getType()); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 98 | return coords[index].getName(); |
| 99 | } |
| 100 | |
| 101 | SkString coords2D("coords2D"); |
| 102 | if (0 != index) { |
| 103 | coords2D.appendf("_%i", index); |
| 104 | } |
| 105 | this->codeAppendf("\tvec2 %s = %s.xy / %s.z;", |
| 106 | coords2D.c_str(), coords[index].c_str(), coords[index].c_str()); |
| 107 | return coords2D; |
| 108 | } |
| 109 | |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame^] | 110 | const char* GrGLSLFragmentShaderBuilder::fragmentPosition() { |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 111 | fHasReadFragmentPosition = true; |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 112 | |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 113 | const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps(); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 114 | // We only declare "gl_FragCoord" when we're in the case where we want to use layout qualifiers |
| 115 | // to reverse y. Otherwise it isn't necessary and whether the "in" qualifier appears in the |
| 116 | // declaration varies in earlier GLSL specs. So it is simpler to omit it. |
| 117 | if (fTopLeftFragPosRead) { |
| 118 | fSetupFragPosition = true; |
| 119 | return "gl_FragCoord"; |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 120 | } else if (const char* extension = glslCaps->fragCoordConventionsExtensionString()) { |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 121 | if (!fSetupFragPosition) { |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 122 | if (glslCaps->generation() < k150_GrGLSLGeneration) { |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 123 | this->addFeature(1 << kFragCoordConventions_GLSLPrivateFeature, |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 124 | extension); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 125 | } |
| 126 | fInputs.push_back().set(kVec4f_GrSLType, |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 127 | GrGLSLShaderVar::kIn_TypeModifier, |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 128 | "gl_FragCoord", |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 129 | kDefault_GrSLPrecision, |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 130 | GrGLSLShaderVar::kUpperLeft_Origin); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 131 | fSetupFragPosition = true; |
| 132 | } |
| 133 | return "gl_FragCoord"; |
| 134 | } else { |
robertphillips | 18c58c7 | 2015-07-21 12:06:52 -0700 | [diff] [blame] | 135 | static const char* kTempName = "tmpXYFragCoord"; |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 136 | static const char* kCoordName = "fragCoordYDown"; |
| 137 | if (!fSetupFragPosition) { |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 138 | SkASSERT(!fProgramBuilder->fUniformHandles.fRTHeightUni.isValid()); |
| 139 | const char* rtHeightName; |
| 140 | |
| 141 | fProgramBuilder->fUniformHandles.fRTHeightUni = |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 142 | fProgramBuilder->addFragPosUniform(GrGLSLProgramBuilder::kFragment_Visibility, |
egdaniel | f3bace9 | 2015-11-06 06:57:12 -0800 | [diff] [blame] | 143 | kFloat_GrSLType, |
| 144 | kDefault_GrSLPrecision, |
| 145 | "RTHeight", |
| 146 | &rtHeightName); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 147 | |
robertphillips | 18c58c7 | 2015-07-21 12:06:52 -0700 | [diff] [blame] | 148 | // The Adreno compiler seems to be very touchy about access to "gl_FragCoord". |
| 149 | // Accessing glFragCoord.zw can cause a program to fail to link. Additionally, |
| 150 | // depending on the surrounding code, accessing .xy with a uniform involved can |
| 151 | // do the same thing. Copying gl_FragCoord.xy into a temp vec2 beforehand |
| 152 | // (and only accessing .xy) seems to "fix" things. |
| 153 | this->codePrependf("\tvec4 %s = vec4(%s.x, %s - %s.y, 1.0, 1.0);\n", |
| 154 | kCoordName, kTempName, rtHeightName, kTempName); |
| 155 | this->codePrependf("vec2 %s = gl_FragCoord.xy;", kTempName); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 156 | fSetupFragPosition = true; |
| 157 | } |
| 158 | SkASSERT(fProgramBuilder->fUniformHandles.fRTHeightUni.isValid()); |
| 159 | return kCoordName; |
| 160 | } |
| 161 | } |
| 162 | |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame^] | 163 | const char* GrGLSLFragmentShaderBuilder::dstColor() { |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 164 | fHasReadDstColor = true; |
| 165 | |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 166 | const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps(); |
| 167 | if (glslCaps->fbFetchSupport()) { |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame^] | 168 | this->addFeature(1 << (GrGLSLFragmentShaderBuilder::kLastGLSLPrivateFeature + 1), |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 169 | glslCaps->fbFetchExtensionString()); |
joshualitt | b4384b9 | 2014-10-21 12:53:15 -0700 | [diff] [blame] | 170 | |
joshualitt | 3c1096f | 2015-01-13 13:13:59 -0800 | [diff] [blame] | 171 | // Some versions of this extension string require declaring custom color output on ES 3.0+ |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 172 | const char* fbFetchColorName = glslCaps->fbFetchColorName(); |
| 173 | if (glslCaps->fbFetchNeedsCustomOutput()) { |
joshualitt | b4384b9 | 2014-10-21 12:53:15 -0700 | [diff] [blame] | 174 | this->enableCustomOutput(); |
| 175 | fOutputs[fCustomColorOutputIndex].setTypeModifier(GrShaderVar::kInOut_TypeModifier); |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 176 | fbFetchColorName = DeclaredColorOutputName(); |
joshualitt | b4384b9 | 2014-10-21 12:53:15 -0700 | [diff] [blame] | 177 | } |
| 178 | return fbFetchColorName; |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 179 | } else { |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 180 | return kDstTextureColorName; |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 181 | } |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 182 | } |
| 183 | |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame^] | 184 | void GrGLSLFragmentShaderBuilder::enableAdvancedBlendEquationIfNeeded(GrBlendEquation equation) { |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 185 | SkASSERT(GrBlendEquationIsAdvanced(equation)); |
| 186 | |
egdaniel | 472d44e | 2015-10-22 08:20:00 -0700 | [diff] [blame] | 187 | const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 188 | if (!caps.mustEnableAdvBlendEqs()) { |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | this->addFeature(1 << kBlendEquationAdvanced_GLSLPrivateFeature, |
| 193 | "GL_KHR_blend_equation_advanced"); |
| 194 | if (caps.mustEnableSpecificAdvBlendEqs()) { |
| 195 | this->addLayoutQualifier(specific_layout_qualifier_name(equation), kOut_InterfaceQualifier); |
| 196 | } else { |
| 197 | this->addLayoutQualifier("blend_support_all_equations", kOut_InterfaceQualifier); |
| 198 | } |
| 199 | } |
| 200 | |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame^] | 201 | void GrGLSLFragmentShaderBuilder::enableCustomOutput() { |
joshualitt | b4384b9 | 2014-10-21 12:53:15 -0700 | [diff] [blame] | 202 | if (!fHasCustomColorOutput) { |
| 203 | fHasCustomColorOutput = true; |
| 204 | fCustomColorOutputIndex = fOutputs.count(); |
| 205 | fOutputs.push_back().set(kVec4f_GrSLType, |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 206 | GrGLSLShaderVar::kOut_TypeModifier, |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 207 | DeclaredColorOutputName()); |
joshualitt | b4384b9 | 2014-10-21 12:53:15 -0700 | [diff] [blame] | 208 | } |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 209 | } |
| 210 | |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame^] | 211 | void GrGLSLFragmentShaderBuilder::enableSecondaryOutput() { |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 212 | SkASSERT(!fHasSecondaryOutput); |
| 213 | fHasSecondaryOutput = true; |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 214 | const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); |
| 215 | if (const char* extension = caps.secondaryOutputExtensionString()) { |
| 216 | this->addFeature(1 << kBlendFuncExtended_GLSLPrivateFeature, extension); |
kkinnunen | d94708e | 2015-07-30 22:47:04 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | // If the primary output is declared, we must declare also the secondary output |
| 220 | // and vice versa, since it is not allowed to use a built-in gl_FragColor and a custom |
| 221 | // output. The condition also co-incides with the condition in whici GLES SL 2.0 |
| 222 | // requires the built-in gl_SecondaryFragColorEXT, where as 3.0 requires a custom output. |
kkinnunen | d94708e | 2015-07-30 22:47:04 -0700 | [diff] [blame] | 223 | if (caps.mustDeclareFragmentShaderOutput()) { |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 224 | fOutputs.push_back().set(kVec4f_GrSLType, GrGLSLShaderVar::kOut_TypeModifier, |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 225 | DeclaredSecondaryColorOutputName()); |
kkinnunen | d94708e | 2015-07-30 22:47:04 -0700 | [diff] [blame] | 226 | } |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 227 | } |
| 228 | |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame^] | 229 | const char* GrGLSLFragmentShaderBuilder::getPrimaryColorOutputName() const { |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 230 | return fHasCustomColorOutput ? DeclaredColorOutputName() : "gl_FragColor"; |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 231 | } |
| 232 | |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame^] | 233 | const char* GrGLSLFragmentShaderBuilder::getSecondaryColorOutputName() const { |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 234 | const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); |
| 235 | return caps.mustDeclareFragmentShaderOutput() ? DeclaredSecondaryColorOutputName() |
kkinnunen | d94708e | 2015-07-30 22:47:04 -0700 | [diff] [blame] | 236 | : "gl_SecondaryFragColorEXT"; |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 237 | } |
| 238 | |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame^] | 239 | void GrGLSLFragmentShaderBuilder::onFinalize() { |
egdaniel | cb7ba1e | 2015-10-26 08:38:25 -0700 | [diff] [blame] | 240 | GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, |
| 241 | *fProgramBuilder->glslCaps(), |
| 242 | &this->precisionQualifier()); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 243 | } |
| 244 | |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame^] | 245 | void GrGLSLFragmentShaderBuilder::addVarying(GrGLSLVarying* v, GrSLPrecision fsPrec) { |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 246 | v->fFsIn = v->fVsOut; |
| 247 | if (v->fGsOut) { |
| 248 | v->fFsIn = v->fGsOut; |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 249 | } |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 250 | fInputs.push_back().set(v->fType, GrGLSLShaderVar::kVaryingIn_TypeModifier, v->fFsIn, fsPrec); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 251 | } |
wangyix | 7ef45a1 | 2015-08-13 06:51:35 -0700 | [diff] [blame] | 252 | |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame^] | 253 | void GrGLSLFragmentBuilder::onBeforeChildProcEmitCode() { |
wangyix | 54a6b1a | 2015-09-08 08:41:51 -0700 | [diff] [blame] | 254 | SkASSERT(fSubstageIndices.count() >= 1); |
wangyix | 7ef45a1 | 2015-08-13 06:51:35 -0700 | [diff] [blame] | 255 | fSubstageIndices.push_back(0); |
wangyix | 54a6b1a | 2015-09-08 08:41:51 -0700 | [diff] [blame] | 256 | // second-to-last value in the fSubstageIndices stack is the index of the child proc |
| 257 | // at that level which is currently emitting code. |
| 258 | fMangleString.appendf("_c%d", fSubstageIndices[fSubstageIndices.count() - 2]); |
wangyix | 7ef45a1 | 2015-08-13 06:51:35 -0700 | [diff] [blame] | 259 | } |
| 260 | |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame^] | 261 | void GrGLSLFragmentBuilder::onAfterChildProcEmitCode() { |
wangyix | 54a6b1a | 2015-09-08 08:41:51 -0700 | [diff] [blame] | 262 | SkASSERT(fSubstageIndices.count() >= 2); |
wangyix | 7ef45a1 | 2015-08-13 06:51:35 -0700 | [diff] [blame] | 263 | fSubstageIndices.pop_back(); |
wangyix | 54a6b1a | 2015-09-08 08:41:51 -0700 | [diff] [blame] | 264 | fSubstageIndices.back()++; |
wangyix | 7ef45a1 | 2015-08-13 06:51:35 -0700 | [diff] [blame] | 265 | int removeAt = fMangleString.findLastOf('_'); |
| 266 | fMangleString.remove(removeAt, fMangleString.size() - removeAt); |
| 267 | } |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 268 | |