OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gl/GrGLShaderBuilder.h" | 8 #include "gl/GrGLShaderBuilder.h" |
9 #include "gl/GrGLProgram.h" | 9 #include "gl/GrGLProgram.h" |
10 #include "gl/GrGLUniformHandle.h" | 10 #include "gl/GrGLUniformHandle.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 swizzle = mangledSwizzle; | 80 swizzle = mangledSwizzle; |
81 } | 81 } |
82 // For shader prettiness we omit the swizzle rather than appending ".rgba". | 82 // For shader prettiness we omit the swizzle rather than appending ".rgba". |
83 if (memcmp(swizzle, "rgba", 4)) { | 83 if (memcmp(swizzle, "rgba", 4)) { |
84 outAppend->appendf(".%s", swizzle); | 84 outAppend->appendf(".%s", swizzle); |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 } | 88 } |
89 | 89 |
90 static const char kDstColorName[] = "_dstColor"; | 90 static const char kDstCopyColorName[] = "_dstColor"; |
91 | 91 |
92 /////////////////////////////////////////////////////////////////////////////// | 92 /////////////////////////////////////////////////////////////////////////////// |
93 | 93 |
94 GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctxInfo, | 94 GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctxInfo, |
95 GrGLUniformManager& uniformManager, | 95 GrGLUniformManager& uniformManager, |
96 const GrGLProgramDesc& desc) | 96 const GrGLProgramDesc& desc) |
97 : fUniforms(kVarsPerBlock) | 97 : fUniforms(kVarsPerBlock) |
98 , fVSAttrs(kVarsPerBlock) | 98 , fVSAttrs(kVarsPerBlock) |
99 , fVSOutputs(kVarsPerBlock) | 99 , fVSOutputs(kVarsPerBlock) |
100 , fGSInputs(kVarsPerBlock) | 100 , fGSInputs(kVarsPerBlock) |
(...skipping 17 matching lines...) Expand all Loading... |
118 fPositionVar = &fVSAttrs.push_back(); | 118 fPositionVar = &fVSAttrs.push_back(); |
119 fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "
aPosition"); | 119 fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "
aPosition"); |
120 if (-1 != desc.fLocalCoordAttributeIndex) { | 120 if (-1 != desc.fLocalCoordAttributeIndex) { |
121 fLocalCoordsVar = &fVSAttrs.push_back(); | 121 fLocalCoordsVar = &fVSAttrs.push_back(); |
122 fLocalCoordsVar->set(kVec2f_GrSLType, | 122 fLocalCoordsVar->set(kVec2f_GrSLType, |
123 GrGLShaderVar::kAttribute_TypeModifier, | 123 GrGLShaderVar::kAttribute_TypeModifier, |
124 "aLocalCoords"); | 124 "aLocalCoords"); |
125 } else { | 125 } else { |
126 fLocalCoordsVar = fPositionVar; | 126 fLocalCoordsVar = fPositionVar; |
127 } | 127 } |
128 if (kNoDstRead_DstReadKey != desc.fDstRead) { | 128 // Emit code to read the dst copy textue if necessary. |
| 129 if (kNoDstRead_DstReadKey != desc.fDstRead && |
| 130 GrGLCaps::kNone_FBFetchType == ctxInfo.caps()->fbFetchType()) { |
129 bool topDown = SkToBool(kTopLeftOrigin_DstReadKeyBit & desc.fDstRead); | 131 bool topDown = SkToBool(kTopLeftOrigin_DstReadKeyBit & desc.fDstRead); |
130 const char* dstCopyTopLeftName; | 132 const char* dstCopyTopLeftName; |
131 const char* dstCopyCoordScaleName; | 133 const char* dstCopyCoordScaleName; |
132 uint32_t configMask; | 134 uint32_t configMask; |
133 if (SkToBool(kUseAlphaConfig_DstReadKeyBit & desc.fDstRead)) { | 135 if (SkToBool(kUseAlphaConfig_DstReadKeyBit & desc.fDstRead)) { |
134 configMask = kA_GrColorComponentFlag; | 136 configMask = kA_GrColorComponentFlag; |
135 } else { | 137 } else { |
136 configMask = kRGBA_GrColorComponentFlags; | 138 configMask = kRGBA_GrColorComponentFlags; |
137 } | 139 } |
138 fDstCopySampler.init(this, configMask, "rgba", 0); | 140 fDstCopySampler.init(this, configMask, "rgba", 0); |
139 | 141 |
140 fDstCopyTopLeftUniform = this->addUniform(kFragment_ShaderType, | 142 fDstCopyTopLeftUniform = this->addUniform(kFragment_ShaderType, |
141 kVec2f_GrSLType, | 143 kVec2f_GrSLType, |
142 "DstCopyUpperLeft", | 144 "DstCopyUpperLeft", |
143 &dstCopyTopLeftName); | 145 &dstCopyTopLeftName); |
144 fDstCopyScaleUniform = this->addUniform(kFragment_ShaderType, | 146 fDstCopyScaleUniform = this->addUniform(kFragment_ShaderType, |
145 kVec2f_GrSLType, | 147 kVec2f_GrSLType, |
146 "DstCopyCoordScale", | 148 "DstCopyCoordScale", |
147 &dstCopyCoordScaleName); | 149 &dstCopyCoordScaleName); |
148 const char* fragPos = this->fragmentPosition(); | 150 const char* fragPos = this->fragmentPosition(); |
149 this->fsCodeAppend("\t// Read color from copy of the destination.\n"); | 151 this->fsCodeAppend("\t// Read color from copy of the destination.\n"); |
150 this->fsCodeAppendf("\tvec2 _dstTexCoord = (%s.xy - %s) * %s;\n", | 152 this->fsCodeAppendf("\tvec2 _dstTexCoord = (%s.xy - %s) * %s;\n", |
151 fragPos, dstCopyTopLeftName, dstCopyCoordScaleName); | 153 fragPos, dstCopyTopLeftName, dstCopyCoordScaleName); |
152 if (!topDown) { | 154 if (!topDown) { |
153 this->fsCodeAppend("\t_dstTexCoord.y = 1.0 - _dstTexCoord.y;\n"); | 155 this->fsCodeAppend("\t_dstTexCoord.y = 1.0 - _dstTexCoord.y;\n"); |
154 } | 156 } |
155 this->fsCodeAppendf("\tvec4 %s = ", kDstColorName); | 157 this->fsCodeAppendf("\tvec4 %s = ", kDstCopyColorName); |
156 this->appendTextureLookup(kFragment_ShaderType, fDstCopySampler, "_dstTe
xCoord"); | 158 this->appendTextureLookup(kFragment_ShaderType, fDstCopySampler, "_dstTe
xCoord"); |
157 this->fsCodeAppend(";\n\n"); | 159 this->fsCodeAppend(";\n\n"); |
158 } | 160 } |
159 } | 161 } |
160 | 162 |
161 bool GrGLShaderBuilder::enableFeature(GLSLFeature feature) { | 163 bool GrGLShaderBuilder::enableFeature(GLSLFeature feature) { |
162 switch (feature) { | 164 switch (feature) { |
163 case kStandardDerivatives_GLSLFeature: | 165 case kStandardDerivatives_GLSLFeature: |
164 if (!fCtxInfo.caps()->shaderDerivativeSupport()) { | 166 if (!fCtxInfo.caps()->shaderDerivativeSupport()) { |
165 return false; | 167 return false; |
(...skipping 13 matching lines...) Expand all Loading... |
179 switch (feature) { | 181 switch (feature) { |
180 case kFragCoordConventions_GLSLPrivateFeature: | 182 case kFragCoordConventions_GLSLPrivateFeature: |
181 if (!fCtxInfo.caps()->fragCoordConventionsSupport()) { | 183 if (!fCtxInfo.caps()->fragCoordConventionsSupport()) { |
182 return false; | 184 return false; |
183 } | 185 } |
184 if (fCtxInfo.glslGeneration() < k150_GrGLSLGeneration) { | 186 if (fCtxInfo.glslGeneration() < k150_GrGLSLGeneration) { |
185 this->addFSFeature(1 << kFragCoordConventions_GLSLPrivateFeature
, | 187 this->addFSFeature(1 << kFragCoordConventions_GLSLPrivateFeature
, |
186 "GL_ARB_fragment_coord_conventions"); | 188 "GL_ARB_fragment_coord_conventions"); |
187 } | 189 } |
188 return true; | 190 return true; |
| 191 case kEXTShaderFramebufferFetch_GLSLPrivateFeature: |
| 192 if (GrGLCaps::kEXT_FBFetchType != fCtxInfo.caps()->fbFetchType()) { |
| 193 return false; |
| 194 } |
| 195 this->addFSFeature(1 << kEXTShaderFramebufferFetch_GLSLPrivateFeatur
e, |
| 196 "GL_EXT_shader_framebuffer_fetch"); |
| 197 return true; |
| 198 case kNVShaderFramebufferFetch_GLSLPrivateFeature: |
| 199 if (GrGLCaps::kNV_FBFetchType != fCtxInfo.caps()->fbFetchType()) { |
| 200 return false; |
| 201 } |
| 202 this->addFSFeature(1 << kNVShaderFramebufferFetch_GLSLPrivateFeature
, |
| 203 "GL_NV_shader_framebuffer_fetch"); |
| 204 return true; |
189 default: | 205 default: |
190 GrCrash("Unexpected GLSLPrivateFeature requested."); | 206 GrCrash("Unexpected GLSLPrivateFeature requested."); |
191 return false; | 207 return false; |
192 } | 208 } |
193 } | 209 } |
194 | 210 |
195 void GrGLShaderBuilder::addFSFeature(uint32_t featureBit, const char* extensionN
ame) { | 211 void GrGLShaderBuilder::addFSFeature(uint32_t featureBit, const char* extensionN
ame) { |
196 if (!(featureBit & fFSFeaturesAddedMask)) { | 212 if (!(featureBit & fFSFeaturesAddedMask)) { |
197 fFSExtensions.appendf("#extension %s: require\n", extensionName); | 213 fFSExtensions.appendf("#extension %s: require\n", extensionName); |
198 fFSFeaturesAddedMask |= featureBit; | 214 fFSFeaturesAddedMask |= featureBit; |
199 } | 215 } |
200 } | 216 } |
201 | 217 |
202 const char* GrGLShaderBuilder::dstColor() const { | 218 const char* GrGLShaderBuilder::dstColor() { |
203 if (fDstCopySampler.isInitialized()) { | 219 static const char kFBFetchColorName[] = "gl_LastFragData[0]"; |
204 return kDstColorName; | 220 GrGLCaps::FBFetchType fetchType = fCtxInfo.caps()->fbFetchType(); |
| 221 if (GrGLCaps::kEXT_FBFetchType == fetchType) { |
| 222 SkAssertResult(this->enablePrivateFeature(kEXTShaderFramebufferFetch_GLS
LPrivateFeature)); |
| 223 return kFBFetchColorName; |
| 224 } else if (GrGLCaps::kNV_FBFetchType == fetchType) { |
| 225 SkAssertResult(this->enablePrivateFeature(kNVShaderFramebufferFetch_GLSL
PrivateFeature)); |
| 226 return kFBFetchColorName; |
| 227 } else if (fDstCopySampler.isInitialized()) { |
| 228 return kDstCopyColorName; |
205 } else { | 229 } else { |
206 return NULL; | 230 return NULL; |
207 } | 231 } |
208 } | 232 } |
209 | 233 |
210 void GrGLShaderBuilder::codeAppendf(ShaderType type, const char format[], va_lis
t args) { | 234 void GrGLShaderBuilder::codeAppendf(ShaderType type, const char format[], va_lis
t args) { |
211 SkString* string = NULL; | 235 SkString* string = NULL; |
212 switch (type) { | 236 switch (type) { |
213 case kVertex_ShaderType: | 237 case kVertex_ShaderType: |
214 string = &fVSCode; | 238 string = &fVSCode; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 if (swizzle_requires_alpha_remapping(caps, configComponentMask, access.swizz
leMask())) { | 307 if (swizzle_requires_alpha_remapping(caps, configComponentMask, access.swizz
leMask())) { |
284 return 1; | 308 return 1; |
285 } else { | 309 } else { |
286 return 0; | 310 return 0; |
287 } | 311 } |
288 } | 312 } |
289 | 313 |
290 GrGLShaderBuilder::DstReadKey GrGLShaderBuilder::KeyForDstRead(const GrTexture*
dstCopy, | 314 GrGLShaderBuilder::DstReadKey GrGLShaderBuilder::KeyForDstRead(const GrTexture*
dstCopy, |
291 const GrGLCaps& c
aps) { | 315 const GrGLCaps& c
aps) { |
292 uint32_t key = kYesDstRead_DstReadKeyBit; | 316 uint32_t key = kYesDstRead_DstReadKeyBit; |
| 317 if (GrGLCaps::kNone_FBFetchType != caps.fbFetchType()) { |
| 318 return key; |
| 319 } |
| 320 GrAssert(NULL != dstCopy); |
293 if (!caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(dstCopy->confi
g())) { | 321 if (!caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(dstCopy->confi
g())) { |
294 // The fact that the config is alpha-only must be considered when genera
ting code. | 322 // The fact that the config is alpha-only must be considered when genera
ting code. |
295 key |= kUseAlphaConfig_DstReadKeyBit; | 323 key |= kUseAlphaConfig_DstReadKeyBit; |
296 } | 324 } |
297 if (kTopLeft_GrSurfaceOrigin == dstCopy->origin()) { | 325 if (kTopLeft_GrSurfaceOrigin == dstCopy->origin()) { |
298 key |= kTopLeftOrigin_DstReadKeyBit; | 326 key |= kTopLeftOrigin_DstReadKeyBit; |
299 } | 327 } |
300 GrAssert(static_cast<DstReadKey>(key) == key); | 328 GrAssert(static_cast<DstReadKey>(key) == key); |
301 return static_cast<DstReadKey>(key); | 329 return static_cast<DstReadKey>(key); |
302 } | 330 } |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 for (const AttributePair* attrib = this->getEffectAttributes().begin(); | 676 for (const AttributePair* attrib = this->getEffectAttributes().begin(); |
649 attrib != attribEnd; | 677 attrib != attribEnd; |
650 ++attrib) { | 678 ++attrib) { |
651 if (attrib->fIndex == attributeIndex) { | 679 if (attrib->fIndex == attributeIndex) { |
652 return &attrib->fName; | 680 return &attrib->fName; |
653 } | 681 } |
654 } | 682 } |
655 | 683 |
656 return NULL; | 684 return NULL; |
657 } | 685 } |
OLD | NEW |