| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 107 } |
| 108 return false; | 108 return false; |
| 109 } | 109 } |
| 110 | 110 |
| 111 bool GrGLShaderBuilder::genProgram(const GrEffectStage* colorStages[], | 111 bool GrGLShaderBuilder::genProgram(const GrEffectStage* colorStages[], |
| 112 const GrEffectStage* coverageStages[]) { | 112 const GrEffectStage* coverageStages[]) { |
| 113 const GrGLProgramDesc::KeyHeader& header = this->desc().getHeader(); | 113 const GrGLProgramDesc::KeyHeader& header = this->desc().getHeader(); |
| 114 | 114 |
| 115 /////////////////////////////////////////////////////////////////////////// | 115 /////////////////////////////////////////////////////////////////////////// |
| 116 // emit code to read the dst copy texture, if necessary | 116 // emit code to read the dst copy texture, if necessary |
| 117 if (kNoDstRead_DstReadKey != header.fDstReadKey && | 117 if (kNoDstRead_DstReadKey != header.fDstReadKey && !fGpu->glCaps().fbFetchSu
pport()) { |
| 118 GrGLCaps::kNone_FBFetchType == fGpu->glCaps().fbFetchType()) { | |
| 119 bool topDown = SkToBool(kTopLeftOrigin_DstReadKeyBit & header.fDstReadKe
y); | 118 bool topDown = SkToBool(kTopLeftOrigin_DstReadKeyBit & header.fDstReadKe
y); |
| 120 const char* dstCopyTopLeftName; | 119 const char* dstCopyTopLeftName; |
| 121 const char* dstCopyCoordScaleName; | 120 const char* dstCopyCoordScaleName; |
| 122 const char* dstCopySamplerName; | 121 const char* dstCopySamplerName; |
| 123 uint32_t configMask; | 122 uint32_t configMask; |
| 124 if (SkToBool(kUseAlphaConfig_DstReadKeyBit & header.fDstReadKey)) { | 123 if (SkToBool(kUseAlphaConfig_DstReadKeyBit & header.fDstReadKey)) { |
| 125 configMask = kA_GrColorComponentFlag; | 124 configMask = kA_GrColorComponentFlag; |
| 126 } else { | 125 } else { |
| 127 configMask = kRGBA_GrColorComponentFlags; | 126 configMask = kRGBA_GrColorComponentFlags; |
| 128 } | 127 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 this->addFSFeature(1 << kStandardDerivatives_GLSLFeature, | 272 this->addFSFeature(1 << kStandardDerivatives_GLSLFeature, |
| 274 "GL_OES_standard_derivatives"); | 273 "GL_OES_standard_derivatives"); |
| 275 } | 274 } |
| 276 return true; | 275 return true; |
| 277 default: | 276 default: |
| 278 SkFAIL("Unexpected GLSLFeature requested."); | 277 SkFAIL("Unexpected GLSLFeature requested."); |
| 279 return false; | 278 return false; |
| 280 } | 279 } |
| 281 } | 280 } |
| 282 | 281 |
| 283 bool GrGLShaderBuilder::enablePrivateFeature(GLSLPrivateFeature feature) { | |
| 284 switch (feature) { | |
| 285 case kFragCoordConventions_GLSLPrivateFeature: | |
| 286 if (!fGpu->glCaps().fragCoordConventionsSupport()) { | |
| 287 return false; | |
| 288 } | |
| 289 if (fGpu->glslGeneration() < k150_GrGLSLGeneration) { | |
| 290 this->addFSFeature(1 << kFragCoordConventions_GLSLPrivateFeature
, | |
| 291 "GL_ARB_fragment_coord_conventions"); | |
| 292 } | |
| 293 return true; | |
| 294 case kEXTShaderFramebufferFetch_GLSLPrivateFeature: | |
| 295 if (GrGLCaps::kEXT_FBFetchType != fGpu->glCaps().fbFetchType()) { | |
| 296 return false; | |
| 297 } | |
| 298 this->addFSFeature(1 << kEXTShaderFramebufferFetch_GLSLPrivateFeatur
e, | |
| 299 "GL_EXT_shader_framebuffer_fetch"); | |
| 300 return true; | |
| 301 case kNVShaderFramebufferFetch_GLSLPrivateFeature: | |
| 302 if (GrGLCaps::kNV_FBFetchType != fGpu->glCaps().fbFetchType()) { | |
| 303 return false; | |
| 304 } | |
| 305 this->addFSFeature(1 << kNVShaderFramebufferFetch_GLSLPrivateFeature
, | |
| 306 "GL_NV_shader_framebuffer_fetch"); | |
| 307 return true; | |
| 308 default: | |
| 309 SkFAIL("Unexpected GLSLPrivateFeature requested."); | |
| 310 return false; | |
| 311 } | |
| 312 } | |
| 313 | |
| 314 void GrGLShaderBuilder::addFSFeature(uint32_t featureBit, const char* extensionN
ame) { | 282 void GrGLShaderBuilder::addFSFeature(uint32_t featureBit, const char* extensionN
ame) { |
| 315 if (!(featureBit & fFSFeaturesAddedMask)) { | 283 if (!(featureBit & fFSFeaturesAddedMask)) { |
| 316 fFSExtensions.appendf("#extension %s: require\n", extensionName); | 284 fFSExtensions.appendf("#extension %s: require\n", extensionName); |
| 317 fFSFeaturesAddedMask |= featureBit; | 285 fFSFeaturesAddedMask |= featureBit; |
| 318 } | 286 } |
| 319 } | 287 } |
| 320 | 288 |
| 321 void GrGLShaderBuilder::nameVariable(SkString* out, char prefix, const char* nam
e) { | 289 void GrGLShaderBuilder::nameVariable(SkString* out, char prefix, const char* nam
e) { |
| 322 if ('\0' == prefix) { | 290 if ('\0' == prefix) { |
| 323 *out = name; | 291 *out = name; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 335 | 303 |
| 336 const char* GrGLShaderBuilder::dstColor() { | 304 const char* GrGLShaderBuilder::dstColor() { |
| 337 if (fCodeStage.inStageCode()) { | 305 if (fCodeStage.inStageCode()) { |
| 338 const GrEffect* effect = fCodeStage.effectStage()->getEffect(); | 306 const GrEffect* effect = fCodeStage.effectStage()->getEffect(); |
| 339 if (!effect->willReadDstColor()) { | 307 if (!effect->willReadDstColor()) { |
| 340 SkDEBUGFAIL("GrGLEffect asked for dst color but its generating GrEff
ect " | 308 SkDEBUGFAIL("GrGLEffect asked for dst color but its generating GrEff
ect " |
| 341 "did not request access."); | 309 "did not request access."); |
| 342 return ""; | 310 return ""; |
| 343 } | 311 } |
| 344 } | 312 } |
| 345 static const char kFBFetchColorName[] = "gl_LastFragData[0]"; | 313 |
| 346 GrGLCaps::FBFetchType fetchType = fGpu->glCaps().fbFetchType(); | 314 if (fGpu->glCaps().fbFetchSupport()) { |
| 347 if (GrGLCaps::kEXT_FBFetchType == fetchType) { | 315 this->addFSFeature(1 << (kLastGLSLPrivateFeature + 1), |
| 348 SkAssertResult(this->enablePrivateFeature(kEXTShaderFramebufferFetch_GLS
LPrivateFeature)); | 316 fGpu->glCaps().fbFetchExtensionString()); |
| 349 return kFBFetchColorName; | 317 return fGpu->glCaps().fbFetchColorName(); |
| 350 } else if (GrGLCaps::kNV_FBFetchType == fetchType) { | |
| 351 SkAssertResult(this->enablePrivateFeature(kNVShaderFramebufferFetch_GLSL
PrivateFeature)); | |
| 352 return kFBFetchColorName; | |
| 353 } else if (fOutput.fUniformHandles.fDstCopySamplerUni.isValid()) { | 318 } else if (fOutput.fUniformHandles.fDstCopySamplerUni.isValid()) { |
| 354 return kDstCopyColorName; | 319 return kDstCopyColorName; |
| 355 } else { | 320 } else { |
| 356 return ""; | 321 return ""; |
| 357 } | 322 } |
| 358 } | 323 } |
| 359 | 324 |
| 360 void GrGLShaderBuilder::appendTextureLookup(SkString* out, | 325 void GrGLShaderBuilder::appendTextureLookup(SkString* out, |
| 361 const GrGLShaderBuilder::TextureSamp
ler& sampler, | 326 const GrGLShaderBuilder::TextureSamp
ler& sampler, |
| 362 const char* coordName, | 327 const char* coordName, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 382 const char* coordName, | 347 const char* coordName, |
| 383 GrSLType varyingType) { | 348 GrSLType varyingType) { |
| 384 SkString lookup; | 349 SkString lookup; |
| 385 this->appendTextureLookup(&lookup, sampler, coordName, varyingType); | 350 this->appendTextureLookup(&lookup, sampler, coordName, varyingType); |
| 386 fFSCode.append((GrGLSLExpr4(modulation) * GrGLSLExpr4(lookup)).c_str()); | 351 fFSCode.append((GrGLSLExpr4(modulation) * GrGLSLExpr4(lookup)).c_str()); |
| 387 } | 352 } |
| 388 | 353 |
| 389 GrGLShaderBuilder::DstReadKey GrGLShaderBuilder::KeyForDstRead(const GrTexture*
dstCopy, | 354 GrGLShaderBuilder::DstReadKey GrGLShaderBuilder::KeyForDstRead(const GrTexture*
dstCopy, |
| 390 const GrGLCaps& c
aps) { | 355 const GrGLCaps& c
aps) { |
| 391 uint32_t key = kYesDstRead_DstReadKeyBit; | 356 uint32_t key = kYesDstRead_DstReadKeyBit; |
| 392 if (GrGLCaps::kNone_FBFetchType != caps.fbFetchType()) { | 357 if (caps.fbFetchSupport()) { |
| 393 return key; | 358 return key; |
| 394 } | 359 } |
| 395 SkASSERT(NULL != dstCopy); | 360 SkASSERT(NULL != dstCopy); |
| 396 if (!caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(dstCopy->confi
g())) { | 361 if (!caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(dstCopy->confi
g())) { |
| 397 // The fact that the config is alpha-only must be considered when genera
ting code. | 362 // The fact that the config is alpha-only must be considered when genera
ting code. |
| 398 key |= kUseAlphaConfig_DstReadKeyBit; | 363 key |= kUseAlphaConfig_DstReadKeyBit; |
| 399 } | 364 } |
| 400 if (kTopLeft_GrSurfaceOrigin == dstCopy->origin()) { | 365 if (kTopLeft_GrSurfaceOrigin == dstCopy->origin()) { |
| 401 key |= kTopLeftOrigin_DstReadKeyBit; | 366 key |= kTopLeftOrigin_DstReadKeyBit; |
| 402 } | 367 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 } | 458 } |
| 494 } | 459 } |
| 495 // We only declare "gl_FragCoord" when we're in the case where we want to us
e layout qualifiers | 460 // We only declare "gl_FragCoord" when we're in the case where we want to us
e layout qualifiers |
| 496 // to reverse y. Otherwise it isn't necessary and whether the "in" qualifier
appears in the | 461 // to reverse y. Otherwise it isn't necessary and whether the "in" qualifier
appears in the |
| 497 // declaration varies in earlier GLSL specs. So it is simpler to omit it. | 462 // declaration varies in earlier GLSL specs. So it is simpler to omit it. |
| 498 if (fTopLeftFragPosRead) { | 463 if (fTopLeftFragPosRead) { |
| 499 fSetupFragPosition = true; | 464 fSetupFragPosition = true; |
| 500 return "gl_FragCoord"; | 465 return "gl_FragCoord"; |
| 501 } else if (fGpu->glCaps().fragCoordConventionsSupport()) { | 466 } else if (fGpu->glCaps().fragCoordConventionsSupport()) { |
| 502 if (!fSetupFragPosition) { | 467 if (!fSetupFragPosition) { |
| 503 SkAssertResult(this->enablePrivateFeature(kFragCoordConventions_GLSL
PrivateFeature)); | 468 if (fGpu->glslGeneration() < k150_GrGLSLGeneration) { |
| 469 this->addFSFeature(1 << kFragCoordConventions_GLSLPrivateFeature
, |
| 470 "GL_ARB_fragment_coord_conventions"); |
| 471 } |
| 504 fFSInputs.push_back().set(kVec4f_GrSLType, | 472 fFSInputs.push_back().set(kVec4f_GrSLType, |
| 505 GrGLShaderVar::kIn_TypeModifier, | 473 GrGLShaderVar::kIn_TypeModifier, |
| 506 "gl_FragCoord", | 474 "gl_FragCoord", |
| 507 GrGLShaderVar::kDefault_Precision, | 475 GrGLShaderVar::kDefault_Precision, |
| 508 GrGLShaderVar::kUpperLeft_Origin); | 476 GrGLShaderVar::kUpperLeft_Origin); |
| 509 fSetupFragPosition = true; | 477 fSetupFragPosition = true; |
| 510 } | 478 } |
| 511 return "gl_FragCoord"; | 479 return "gl_FragCoord"; |
| 512 } else { | 480 } else { |
| 513 static const char* kCoordName = "fragCoordYDown"; | 481 static const char* kCoordName = "fragCoordYDown"; |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 | 1065 |
| 1098 GrGLPathTexGenProgramEffectsBuilder pathTexGenEffectsBuilder(this, | 1066 GrGLPathTexGenProgramEffectsBuilder pathTexGenEffectsBuilder(this, |
| 1099 effectCnt); | 1067 effectCnt); |
| 1100 this->INHERITED::createAndEmitEffects(&pathTexGenEffectsBuilder, | 1068 this->INHERITED::createAndEmitEffects(&pathTexGenEffectsBuilder, |
| 1101 effectStages, | 1069 effectStages, |
| 1102 effectCnt, | 1070 effectCnt, |
| 1103 keyProvider, | 1071 keyProvider, |
| 1104 inOutFSColor); | 1072 inOutFSColor); |
| 1105 return pathTexGenEffectsBuilder.finish(); | 1073 return pathTexGenEffectsBuilder.finish(); |
| 1106 } | 1074 } |
| OLD | NEW |