Commit a905cbcd by Jamie Madill Committed by Commit Bot

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 <jmadill@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com>
parent 49fd27d9
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
"src/compiler/translator/ParseContext_complete_autogen.h": "src/compiler/translator/ParseContext_complete_autogen.h":
"a4209c68899e9cf3bcce81be2cb5f39f", "a4209c68899e9cf3bcce81be2cb5f39f",
"src/compiler/translator/SymbolTable_ESSL_autogen.cpp": "src/compiler/translator/SymbolTable_ESSL_autogen.cpp":
"de7c9ea8f4f76a1d6597eb8a8314c419", "7714226af3c98c0ebce9e71ef181c3ea",
"src/compiler/translator/SymbolTable_autogen.cpp": "src/compiler/translator/SymbolTable_autogen.cpp":
"c52199fd8dc27c7eb0da78c6d0054c0f", "b0454c7771bda83e0ff0b39338bd3f66",
"src/compiler/translator/SymbolTable_autogen.h": "src/compiler/translator/SymbolTable_autogen.h":
"3ce7740b6ad93a86d198c3937b70c17e", "3ce7740b6ad93a86d198c3937b70c17e",
"src/compiler/translator/builtin_function_declarations.txt": "src/compiler/translator/builtin_function_declarations.txt":
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
"src/compiler/translator/builtin_variables.json": "src/compiler/translator/builtin_variables.json":
"e0155915c71991dee1c46358fdb7dd8b", "e0155915c71991dee1c46358fdb7dd8b",
"src/compiler/translator/gen_builtin_symbols.py": "src/compiler/translator/gen_builtin_symbols.py":
"f52b542220a3240cb92633ea2aa4b563", "1034aa779dc2f10458779b28863ec6e2",
"src/compiler/translator/tree_util/BuiltIn_ESSL_autogen.h": "src/compiler/translator/tree_util/BuiltIn_ESSL_autogen.h":
"3c7cdcb39ac0bd262a7d2c8edf8650c0", "3c7cdcb39ac0bd262a7d2c8edf8650c0",
"src/compiler/translator/tree_util/BuiltIn_complete_autogen.h": "src/compiler/translator/tree_util/BuiltIn_complete_autogen.h":
......
...@@ -3364,10 +3364,9 @@ TFunction *TParseContext::parseFunctionDeclarator(const TSourceLoc &location, TF ...@@ -3364,10 +3364,9 @@ TFunction *TParseContext::parseFunctionDeclarator(const TSourceLoc &location, TF
if (getShaderVersion() >= 300) if (getShaderVersion() >= 300)
{ {
const UnmangledBuiltIn *builtIn =
symbolTable.getUnmangledBuiltInForShaderVersion(function->name(), getShaderVersion()); if (symbolTable.isUnmangledBuiltInName(function->name(), getShaderVersion(),
if (builtIn && extensionBehavior()))
(builtIn->extension == TExtension::UNDEFINED || isExtensionEnabled(builtIn->extension)))
{ {
// With ESSL 3.00 and above, names of built-in functions cannot be redeclared as // With ESSL 3.00 and above, names of built-in functions cannot be redeclared as
// functions. Therefore overloading or redefining builtin functions is an error. // functions. Therefore overloading or redefining builtin functions is an error.
......
...@@ -21,6 +21,38 @@ ...@@ -21,6 +21,38 @@
namespace sh namespace sh
{ {
namespace
{
bool CheckShaderType(Shader expected, GLenum actual)
{
switch (expected)
{
case Shader::ALL:
return true;
case Shader::FRAGMENT:
return actual == GL_FRAGMENT_SHADER;
case Shader::VERTEX:
return actual == GL_VERTEX_SHADER;
case Shader::COMPUTE:
return actual == GL_COMPUTE_SHADER;
case Shader::GEOMETRY:
return actual == GL_GEOMETRY_SHADER;
case Shader::GEOMETRY_EXT:
return actual == GL_GEOMETRY_SHADER_EXT;
case Shader::NOT_COMPUTE:
return actual != GL_COMPUTE_SHADER;
default:
UNREACHABLE();
return false;
}
}
bool CheckExtension(uint32_t extensionIndex, const ShBuiltInResources &resources)
{
const int *resourcePtr = reinterpret_cast<const int *>(&resources);
return resourcePtr[extensionIndex] > 0;
}
} // namespace
class TSymbolTable::TSymbolTableLevel class TSymbolTable::TSymbolTableLevel
{ {
...@@ -416,4 +448,87 @@ void TSymbolTable::initSamplerDefaultPrecision(TBasicType samplerType) ...@@ -416,4 +448,87 @@ void TSymbolTable::initSamplerDefaultPrecision(TBasicType samplerType)
TSymbolTable::VariableMetadata::VariableMetadata() TSymbolTable::VariableMetadata::VariableMetadata()
: staticRead(false), staticWrite(false), invariant(false) : staticRead(false), staticWrite(false), invariant(false)
{} {}
const TSymbol *SymbolRule::get(ShShaderSpec shaderSpec,
int shaderVersion,
sh::GLenum shaderType,
const ShBuiltInResources &resources,
const TSymbolTableBase &symbolTable) const
{
if (IsDesktopGLSpec(shaderSpec) != (mIsDesktop == 1))
return nullptr;
if (mVersion == kESSL1Only && shaderVersion != static_cast<int>(kESSL1Only))
return nullptr;
if (mVersion > shaderVersion)
return nullptr;
if (!CheckShaderType(static_cast<Shader>(mShaders), shaderType))
return nullptr;
if (mExtensionIndex != 0 && !CheckExtension(mExtensionIndex, resources))
return nullptr;
return mIsVar > 0 ? symbolTable.*(mSymbolOrVar.var) : mSymbolOrVar.symbol;
}
const TSymbol *FindMangledBuiltIn(ShShaderSpec shaderSpec,
int shaderVersion,
sh::GLenum shaderType,
const ShBuiltInResources &resources,
const TSymbolTableBase &symbolTable,
const SymbolRule *rules,
uint16_t startIndex,
uint16_t endIndex)
{
for (uint32_t ruleIndex = startIndex; ruleIndex < endIndex; ++ruleIndex)
{
const TSymbol *symbol =
rules[ruleIndex].get(shaderSpec, shaderVersion, shaderType, resources, symbolTable);
if (symbol)
{
return symbol;
}
}
return nullptr;
}
bool UnmangledEntry::matches(const ImmutableString &name,
ShShaderSpec shaderSpec,
int shaderVersion,
sh::GLenum shaderType,
const TExtensionBehavior &extensions) const
{
if (name != mName)
return false;
if (!CheckShaderType(static_cast<Shader>(mShaderType), shaderType))
return false;
if (IsDesktopGLSpec(shaderSpec))
{
if (mGLSLVersion > shaderVersion)
return false;
if (static_cast<TExtension>(mGLSLExtension) == TExtension::UNDEFINED)
return true;
return IsExtensionEnabled(extensions, static_cast<TExtension>(mGLSLExtension));
}
else
{
if (mESSLVersion == kESSL1Only && shaderVersion != static_cast<int>(kESSL1Only))
return false;
if (mESSLVersion > shaderVersion)
return false;
if (static_cast<TExtension>(mESSLExtension) == TExtension::UNDEFINED)
return true;
return IsExtensionEnabled(extensions, static_cast<TExtension>(mESSLExtension));
}
}
} // namespace sh } // namespace sh
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment