|
21 | 21 |
|
22 | 22 | namespace sh
|
23 | 23 | {
|
| 24 | +namespace |
| 25 | +{ |
| 26 | +bool CheckShaderType(Shader expected, GLenum actual) |
| 27 | +{ |
| 28 | + switch (expected) |
| 29 | + { |
| 30 | + case Shader::ALL: |
| 31 | + return true; |
| 32 | + case Shader::FRAGMENT: |
| 33 | + return actual == GL_FRAGMENT_SHADER; |
| 34 | + case Shader::VERTEX: |
| 35 | + return actual == GL_VERTEX_SHADER; |
| 36 | + case Shader::COMPUTE: |
| 37 | + return actual == GL_COMPUTE_SHADER; |
| 38 | + case Shader::GEOMETRY: |
| 39 | + return actual == GL_GEOMETRY_SHADER; |
| 40 | + case Shader::GEOMETRY_EXT: |
| 41 | + return actual == GL_GEOMETRY_SHADER_EXT; |
| 42 | + case Shader::NOT_COMPUTE: |
| 43 | + return actual != GL_COMPUTE_SHADER; |
| 44 | + default: |
| 45 | + UNREACHABLE(); |
| 46 | + return false; |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +bool CheckExtension(uint32_t extensionIndex, const ShBuiltInResources &resources) |
| 51 | +{ |
| 52 | + const int *resourcePtr = reinterpret_cast<const int *>(&resources); |
| 53 | + return resourcePtr[extensionIndex] > 0; |
| 54 | +} |
| 55 | +} // namespace |
24 | 56 |
|
25 | 57 | class TSymbolTable::TSymbolTableLevel
|
26 | 58 | {
|
@@ -416,4 +448,87 @@ void TSymbolTable::initSamplerDefaultPrecision(TBasicType samplerType)
|
416 | 448 | TSymbolTable::VariableMetadata::VariableMetadata()
|
417 | 449 | : staticRead(false), staticWrite(false), invariant(false)
|
418 | 450 | {}
|
| 451 | + |
| 452 | +const TSymbol *SymbolRule::get(ShShaderSpec shaderSpec, |
| 453 | + int shaderVersion, |
| 454 | + sh::GLenum shaderType, |
| 455 | + const ShBuiltInResources &resources, |
| 456 | + const TSymbolTableBase &symbolTable) const |
| 457 | +{ |
| 458 | + if (IsDesktopGLSpec(shaderSpec) != (mIsDesktop == 1)) |
| 459 | + return nullptr; |
| 460 | + |
| 461 | + if (mVersion == kESSL1Only && shaderVersion != static_cast<int>(kESSL1Only)) |
| 462 | + return nullptr; |
| 463 | + |
| 464 | + if (mVersion > shaderVersion) |
| 465 | + return nullptr; |
| 466 | + |
| 467 | + if (!CheckShaderType(static_cast<Shader>(mShaders), shaderType)) |
| 468 | + return nullptr; |
| 469 | + |
| 470 | + if (mExtensionIndex != 0 && !CheckExtension(mExtensionIndex, resources)) |
| 471 | + return nullptr; |
| 472 | + |
| 473 | + return mIsVar > 0 ? symbolTable.*(mSymbolOrVar.var) : mSymbolOrVar.symbol; |
| 474 | +} |
| 475 | + |
| 476 | +const TSymbol *FindMangledBuiltIn(ShShaderSpec shaderSpec, |
| 477 | + int shaderVersion, |
| 478 | + sh::GLenum shaderType, |
| 479 | + const ShBuiltInResources &resources, |
| 480 | + const TSymbolTableBase &symbolTable, |
| 481 | + const SymbolRule *rules, |
| 482 | + uint16_t startIndex, |
| 483 | + uint16_t endIndex) |
| 484 | +{ |
| 485 | + for (uint32_t ruleIndex = startIndex; ruleIndex < endIndex; ++ruleIndex) |
| 486 | + { |
| 487 | + const TSymbol *symbol = |
| 488 | + rules[ruleIndex].get(shaderSpec, shaderVersion, shaderType, resources, symbolTable); |
| 489 | + if (symbol) |
| 490 | + { |
| 491 | + return symbol; |
| 492 | + } |
| 493 | + } |
| 494 | + |
| 495 | + return nullptr; |
| 496 | +} |
| 497 | + |
| 498 | +bool UnmangledEntry::matches(const ImmutableString &name, |
| 499 | + ShShaderSpec shaderSpec, |
| 500 | + int shaderVersion, |
| 501 | + sh::GLenum shaderType, |
| 502 | + const TExtensionBehavior &extensions) const |
| 503 | +{ |
| 504 | + if (name != mName) |
| 505 | + return false; |
| 506 | + |
| 507 | + if (!CheckShaderType(static_cast<Shader>(mShaderType), shaderType)) |
| 508 | + return false; |
| 509 | + |
| 510 | + if (IsDesktopGLSpec(shaderSpec)) |
| 511 | + { |
| 512 | + if (mGLSLVersion > shaderVersion) |
| 513 | + return false; |
| 514 | + |
| 515 | + if (static_cast<TExtension>(mGLSLExtension) == TExtension::UNDEFINED) |
| 516 | + return true; |
| 517 | + |
| 518 | + return IsExtensionEnabled(extensions, static_cast<TExtension>(mGLSLExtension)); |
| 519 | + } |
| 520 | + else |
| 521 | + { |
| 522 | + if (mESSLVersion == kESSL1Only && shaderVersion != static_cast<int>(kESSL1Only)) |
| 523 | + return false; |
| 524 | + |
| 525 | + if (mESSLVersion > shaderVersion) |
| 526 | + return false; |
| 527 | + |
| 528 | + if (static_cast<TExtension>(mESSLExtension) == TExtension::UNDEFINED) |
| 529 | + return true; |
| 530 | + |
| 531 | + return IsExtensionEnabled(extensions, static_cast<TExtension>(mESSLExtension)); |
| 532 | + } |
| 533 | +} |
419 | 534 | } // namespace sh
|
0 commit comments