Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a905cbc

Browse files
null77Commit Bot
authored andcommitted
Compact built-in symbol table.
Should reduce the binary size bloat from the perfect hashing. Local testing on Windows shows a significant size reduction. Bug: chromium:998535 Change-Id: I411cc5a917036d2239d15353d760f44e40faa26c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1814725 Commit-Queue: Jamie Madill <[email protected]> Reviewed-by: Tim Van Patten <[email protected]>
1 parent 49fd27d commit a905cbc

File tree

7 files changed

+11949
-51977
lines changed

7 files changed

+11949
-51977
lines changed

scripts/code_generation_hashes/Static_builtins.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
"src/compiler/translator/ParseContext_complete_autogen.h":
99
"a4209c68899e9cf3bcce81be2cb5f39f",
1010
"src/compiler/translator/SymbolTable_ESSL_autogen.cpp":
11-
"de7c9ea8f4f76a1d6597eb8a8314c419",
11+
"7714226af3c98c0ebce9e71ef181c3ea",
1212
"src/compiler/translator/SymbolTable_autogen.cpp":
13-
"c52199fd8dc27c7eb0da78c6d0054c0f",
13+
"b0454c7771bda83e0ff0b39338bd3f66",
1414
"src/compiler/translator/SymbolTable_autogen.h":
1515
"3ce7740b6ad93a86d198c3937b70c17e",
1616
"src/compiler/translator/builtin_function_declarations.txt":
1717
"fc9b0b050448d015482c9f13cab1df67",
1818
"src/compiler/translator/builtin_variables.json":
1919
"e0155915c71991dee1c46358fdb7dd8b",
2020
"src/compiler/translator/gen_builtin_symbols.py":
21-
"f52b542220a3240cb92633ea2aa4b563",
21+
"1034aa779dc2f10458779b28863ec6e2",
2222
"src/compiler/translator/tree_util/BuiltIn_ESSL_autogen.h":
2323
"3c7cdcb39ac0bd262a7d2c8edf8650c0",
2424
"src/compiler/translator/tree_util/BuiltIn_complete_autogen.h":

src/compiler/translator/ParseContext.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,10 +3364,9 @@ TFunction *TParseContext::parseFunctionDeclarator(const TSourceLoc &location, TF
33643364

33653365
if (getShaderVersion() >= 300)
33663366
{
3367-
const UnmangledBuiltIn *builtIn =
3368-
symbolTable.getUnmangledBuiltInForShaderVersion(function->name(), getShaderVersion());
3369-
if (builtIn &&
3370-
(builtIn->extension == TExtension::UNDEFINED || isExtensionEnabled(builtIn->extension)))
3367+
3368+
if (symbolTable.isUnmangledBuiltInName(function->name(), getShaderVersion(),
3369+
extensionBehavior()))
33713370
{
33723371
// With ESSL 3.00 and above, names of built-in functions cannot be redeclared as
33733372
// functions. Therefore overloading or redefining builtin functions is an error.

src/compiler/translator/SymbolTable.cpp

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,38 @@
2121

2222
namespace sh
2323
{
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
2456

2557
class TSymbolTable::TSymbolTableLevel
2658
{
@@ -416,4 +448,87 @@ void TSymbolTable::initSamplerDefaultPrecision(TBasicType samplerType)
416448
TSymbolTable::VariableMetadata::VariableMetadata()
417449
: staticRead(false), staticWrite(false), invariant(false)
418450
{}
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+
}
419534
} // namespace sh

0 commit comments

Comments
 (0)