Commit 56db3789 by Clemen Deng Committed by Commit Bot

Use flat arrays instead of switches for function lookups

Current implementation of built in function lookup uses autogenerated switch statements. Instead, use the perfect hash mapping to have the lookup use arrays instead. This will improve runtime performance. Bug: angleproject:3805 Change-Id: I6d0ba62d79abd53a7fe818fe675282800781f256 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1756883 Commit-Queue: Clemen Deng <clemendeng@google.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 552f5fcb
{ {
"src/compiler/translator/ImmutableString_autogen.cpp": "src/compiler/translator/ImmutableString_autogen.cpp":
"0a96956b0168817b28032a567f606940", "81004ecca353bdce6999ba864615e10f",
"src/compiler/translator/ParseContext_autogen.h": "src/compiler/translator/ParseContext_autogen.h":
"48f878f5878e8ab239af7c14e5878b62", "48f878f5878e8ab239af7c14e5878b62",
"src/compiler/translator/SymbolTable_autogen.cpp": "src/compiler/translator/SymbolTable_autogen.cpp":
"e215cb47f2d21e9c2b4b4c8a224fda9d", "e101aa202c0397caf48482853bb90d02",
"src/compiler/translator/SymbolTable_autogen.h": "src/compiler/translator/SymbolTable_autogen.h":
"bdb3c8eab0d48267a2f264e3af635e1a", "3b7cc472d076136a048d6b6f9c28460c",
"src/compiler/translator/builtin_function_declarations.txt": "src/compiler/translator/builtin_function_declarations.txt":
"583e23ceaca8d2baeb07694049b68644", "fc9b0b050448d015482c9f13cab1df67",
"src/compiler/translator/builtin_variables.json": "src/compiler/translator/builtin_variables.json":
"802417116fe4b1391b2d80ad04479cf8", "34906b1c84fe40824e412607f9f1c501",
"src/compiler/translator/gen_builtin_symbols.py": "src/compiler/translator/gen_builtin_symbols.py":
"f8f1c8cc208f5f1bb64cf6921e28e966", "a671720ef20bf7d7a7f719a42f9ae7b6",
"src/compiler/translator/tree_util/BuiltIn_autogen.h": "src/compiler/translator/tree_util/BuiltIn_autogen.h":
"80a911c6701baded2fd8d5567c605669", "80a911c6701baded2fd8d5567c605669",
"src/tests/compiler_tests/ImmutableString_test_autogen.cpp": "src/tests/compiler_tests/ImmutableString_test_autogen.cpp":
"c7c54d5374ccf145a11bd91035b92a5c" "181c3209ad287d1a9477313ea0332445"
} }
\ No newline at end of file
...@@ -126,10 +126,9 @@ class ImmutableString ...@@ -126,10 +126,9 @@ class ImmutableString
} }
}; };
// This hash encodes the opening parentheses location (if any), name length and whether the name // Perfect hash functions
// contains { or [ characters in addition to a 19-bit hash. This way the hash is more useful for
// lookups. The string passed in should be at most 63 characters.
uint32_t mangledNameHash() const; uint32_t mangledNameHash() const;
uint32_t unmangledNameHash() const;
private: private:
const char *mData; const char *mData;
......
...@@ -133,7 +133,7 @@ bool TSymbolTable::setGlInArraySize(unsigned int inputArraySize) ...@@ -133,7 +133,7 @@ bool TSymbolTable::setGlInArraySize(unsigned int inputArraySize)
{ {
return mGlInVariableWithArraySize->getType().getOutermostArraySize() == inputArraySize; return mGlInVariableWithArraySize->getType().getOutermostArraySize() == inputArraySize;
} }
const TInterfaceBlock *glPerVertex = mVar_gl_PerVertex; const TInterfaceBlock *glPerVertex = static_cast<const TInterfaceBlock *>(mVar_gl_PerVertex);
TType *glInType = new TType(glPerVertex, EvqPerVertexIn, TLayoutQualifier::Create()); TType *glInType = new TType(glPerVertex, EvqPerVertexIn, TLayoutQualifier::Create());
glInType->makeArray(inputArraySize); glInType->makeArray(inputArraySize);
mGlInVariableWithArraySize = mGlInVariableWithArraySize =
...@@ -149,12 +149,12 @@ TVariable *TSymbolTable::getGlInVariableWithArraySize() const ...@@ -149,12 +149,12 @@ TVariable *TSymbolTable::getGlInVariableWithArraySize() const
const TVariable *TSymbolTable::gl_FragData() const const TVariable *TSymbolTable::gl_FragData() const
{ {
return mVar_gl_FragData; return static_cast<const TVariable *>(mVar_gl_FragData);
} }
const TVariable *TSymbolTable::gl_SecondaryFragDataEXT() const const TVariable *TSymbolTable::gl_SecondaryFragDataEXT() const
{ {
return mVar_gl_SecondaryFragDataEXT; return static_cast<const TVariable *>(mVar_gl_SecondaryFragDataEXT);
} }
TSymbolTable::VariableMetadata *TSymbolTable::getOrCreateVariableMetadata(const TVariable &variable) TSymbolTable::VariableMetadata *TSymbolTable::getOrCreateVariableMetadata(const TVariable &variable)
......
...@@ -41,6 +41,17 @@ ...@@ -41,6 +41,17 @@
#include "compiler/translator/Symbol.h" #include "compiler/translator/Symbol.h"
#include "compiler/translator/SymbolTable_autogen.h" #include "compiler/translator/SymbolTable_autogen.h"
enum class Shader
{
ALL,
FRAGMENT, // GL_FRAGMENT_SHADER
VERTEX, // GL_VERTEX_SHADER
COMPUTE, // GL_COMPUTE_SHADER
GEOMETRY, // GL_GEOMETRY_SHADER
GEOMETRY_EXT, // GL_GEOMETRY_SHADER_EXT
NOT_COMPUTE
};
namespace sh namespace sh
{ {
...@@ -51,6 +62,107 @@ struct UnmangledBuiltIn ...@@ -51,6 +62,107 @@ struct UnmangledBuiltIn
TExtension extension; TExtension extension;
}; };
using VarPointer = TSymbol *(TSymbolTableBase::*);
using ValidateExtension = int(ShBuiltInResources::*);
struct SymbolEntry
{
constexpr SymbolEntry(ImmutableString &&name,
const TSymbol *symbol,
VarPointer var,
int esslVersion,
int glslVersion,
Shader shaderType,
const TSymbol *esslExtSymbol,
VarPointer esslExtVar,
int esslExtVersion,
Shader esslExtShaderType,
ValidateExtension esslExtension,
const TSymbol *glslExtSymbol,
VarPointer glslExtVar,
int glslExtVersion,
Shader glslExtShaderType,
ValidateExtension glslExtension,
const TSymbol *esslExtSymbol2 = nullptr,
VarPointer esslExtVar2 = nullptr,
int esslExtVersion2 = -1,
Shader esslExtShaderType2 = Shader::ALL,
ValidateExtension esslExtension2 = nullptr)
: name(std::move(name)),
symbol(symbol),
var(var),
esslVersion(esslVersion),
glslVersion(glslVersion),
shaderType(shaderType),
esslExtSymbol(esslExtSymbol),
esslExtVar(esslExtVar),
esslExtVersion(esslExtVersion),
esslExtShaderType(esslExtShaderType),
esslExtension(esslExtension),
glslExtSymbol(glslExtSymbol),
glslExtVar(glslExtVar),
glslExtVersion(glslExtVersion),
glslExtShaderType(glslExtShaderType),
glslExtension(glslExtension),
esslExtSymbol2(esslExtSymbol2),
esslExtVar2(esslExtVar2),
esslExtVersion2(esslExtVersion2),
esslExtShaderType2(esslExtShaderType2),
esslExtension2(esslExtension2)
{}
ImmutableString name;
const TSymbol *symbol;
VarPointer var;
int esslVersion;
int glslVersion;
Shader shaderType;
const TSymbol *esslExtSymbol;
VarPointer esslExtVar;
int esslExtVersion;
Shader esslExtShaderType;
ValidateExtension esslExtension;
const TSymbol *glslExtSymbol;
VarPointer glslExtVar;
int glslExtVersion;
Shader glslExtShaderType;
ValidateExtension glslExtension;
const TSymbol *esslExtSymbol2;
VarPointer esslExtVar2;
int esslExtVersion2;
Shader esslExtShaderType2;
ValidateExtension esslExtension2;
};
struct UnmangledEntry
{
constexpr UnmangledEntry(ImmutableString &&name,
const UnmangledBuiltIn *esslUnmangled,
const UnmangledBuiltIn *glslUnmangled,
int esslVersion,
int glslVersion,
Shader shaderType)
: name(std::move(name)),
esslUnmangled(esslUnmangled),
glslUnmangled(glslUnmangled),
esslVersion(esslVersion),
glslVersion(glslVersion),
shaderType(shaderType)
{}
ImmutableString name;
const UnmangledBuiltIn *esslUnmangled;
const UnmangledBuiltIn *glslUnmangled;
int esslVersion;
int glslVersion;
Shader shaderType;
};
class TSymbolTable : angle::NonCopyable, TSymbolTableBase class TSymbolTable : angle::NonCopyable, TSymbolTableBase
{ {
public: public:
...@@ -161,6 +273,12 @@ class TSymbolTable : angle::NonCopyable, TSymbolTableBase ...@@ -161,6 +273,12 @@ class TSymbolTable : angle::NonCopyable, TSymbolTableBase
VariableMetadata *getOrCreateVariableMetadata(const TVariable &variable); VariableMetadata *getOrCreateVariableMetadata(const TVariable &variable);
const TSymbol *getSymbol(SymbolEntry entry, const ImmutableString &name, int version) const;
const UnmangledBuiltIn *getUnmangled(UnmangledEntry entry,
const ImmutableString &name,
int version) const;
std::vector<std::unique_ptr<TSymbolTableLevel>> mTable; std::vector<std::unique_ptr<TSymbolTableLevel>> mTable;
// There's one precision stack level for predefined precisions and then one level for each scope // There's one precision stack level for predefined precisions and then one level for each scope
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -17,60 +17,60 @@ namespace sh ...@@ -17,60 +17,60 @@ namespace sh
class TSymbolTableBase class TSymbolTableBase
{ {
protected: public:
TSymbolTableBase() = default; TSymbolTableBase() = default;
TStructure *mVar_gl_DepthRangeParameters = nullptr; TSymbol *mVar_gl_DepthRangeParameters = nullptr;
TVariable *mVar_gl_DepthRange = nullptr; TSymbol *mVar_gl_DepthRange = nullptr;
TVariable *mVar_gl_MaxVertexAttribs = nullptr; TSymbol *mVar_gl_MaxVertexAttribs = nullptr;
TVariable *mVar_gl_MaxVertexUniformVectors = nullptr; TSymbol *mVar_gl_MaxVertexUniformVectors = nullptr;
TVariable *mVar_gl_MaxVertexTextureImageUnits = nullptr; TSymbol *mVar_gl_MaxVertexTextureImageUnits = nullptr;
TVariable *mVar_gl_MaxCombinedTextureImageUnits = nullptr; TSymbol *mVar_gl_MaxCombinedTextureImageUnits = nullptr;
TVariable *mVar_gl_MaxTextureImageUnits = nullptr; TSymbol *mVar_gl_MaxTextureImageUnits = nullptr;
TVariable *mVar_gl_MaxFragmentUniformVectors = nullptr; TSymbol *mVar_gl_MaxFragmentUniformVectors = nullptr;
TVariable *mVar_gl_MaxVaryingVectors = nullptr; TSymbol *mVar_gl_MaxVaryingVectors = nullptr;
TVariable *mVar_gl_MaxDrawBuffers = nullptr; TSymbol *mVar_gl_MaxDrawBuffers = nullptr;
TVariable *mVar_gl_MaxDualSourceDrawBuffersEXT = nullptr; TSymbol *mVar_gl_MaxDualSourceDrawBuffersEXT = nullptr;
TVariable *mVar_gl_MaxVertexOutputVectors = nullptr; TSymbol *mVar_gl_MaxVertexOutputVectors = nullptr;
TVariable *mVar_gl_MaxFragmentInputVectors = nullptr; TSymbol *mVar_gl_MaxFragmentInputVectors = nullptr;
TVariable *mVar_gl_MinProgramTexelOffset = nullptr; TSymbol *mVar_gl_MinProgramTexelOffset = nullptr;
TVariable *mVar_gl_MaxProgramTexelOffset = nullptr; TSymbol *mVar_gl_MaxProgramTexelOffset = nullptr;
TVariable *mVar_gl_MaxImageUnits = nullptr; TSymbol *mVar_gl_MaxImageUnits = nullptr;
TVariable *mVar_gl_MaxVertexImageUniforms = nullptr; TSymbol *mVar_gl_MaxVertexImageUniforms = nullptr;
TVariable *mVar_gl_MaxFragmentImageUniforms = nullptr; TSymbol *mVar_gl_MaxFragmentImageUniforms = nullptr;
TVariable *mVar_gl_MaxComputeImageUniforms = nullptr; TSymbol *mVar_gl_MaxComputeImageUniforms = nullptr;
TVariable *mVar_gl_MaxCombinedImageUniforms = nullptr; TSymbol *mVar_gl_MaxCombinedImageUniforms = nullptr;
TVariable *mVar_gl_MaxCombinedShaderOutputResources = nullptr; TSymbol *mVar_gl_MaxCombinedShaderOutputResources = nullptr;
TVariable *mVar_gl_MaxComputeWorkGroupCount = nullptr; TSymbol *mVar_gl_MaxComputeWorkGroupCount = nullptr;
TVariable *mVar_gl_MaxComputeWorkGroupSize = nullptr; TSymbol *mVar_gl_MaxComputeWorkGroupSize = nullptr;
TVariable *mVar_gl_MaxComputeUniformComponents = nullptr; TSymbol *mVar_gl_MaxComputeUniformComponents = nullptr;
TVariable *mVar_gl_MaxComputeTextureImageUnits = nullptr; TSymbol *mVar_gl_MaxComputeTextureImageUnits = nullptr;
TVariable *mVar_gl_MaxComputeAtomicCounters = nullptr; TSymbol *mVar_gl_MaxComputeAtomicCounters = nullptr;
TVariable *mVar_gl_MaxComputeAtomicCounterBuffers = nullptr; TSymbol *mVar_gl_MaxComputeAtomicCounterBuffers = nullptr;
TVariable *mVar_gl_MaxVertexAtomicCounters = nullptr; TSymbol *mVar_gl_MaxVertexAtomicCounters = nullptr;
TVariable *mVar_gl_MaxFragmentAtomicCounters = nullptr; TSymbol *mVar_gl_MaxFragmentAtomicCounters = nullptr;
TVariable *mVar_gl_MaxCombinedAtomicCounters = nullptr; TSymbol *mVar_gl_MaxCombinedAtomicCounters = nullptr;
TVariable *mVar_gl_MaxAtomicCounterBindings = nullptr; TSymbol *mVar_gl_MaxAtomicCounterBindings = nullptr;
TVariable *mVar_gl_MaxVertexAtomicCounterBuffers = nullptr; TSymbol *mVar_gl_MaxVertexAtomicCounterBuffers = nullptr;
TVariable *mVar_gl_MaxFragmentAtomicCounterBuffers = nullptr; TSymbol *mVar_gl_MaxFragmentAtomicCounterBuffers = nullptr;
TVariable *mVar_gl_MaxCombinedAtomicCounterBuffers = nullptr; TSymbol *mVar_gl_MaxCombinedAtomicCounterBuffers = nullptr;
TVariable *mVar_gl_MaxAtomicCounterBufferSize = nullptr; TSymbol *mVar_gl_MaxAtomicCounterBufferSize = nullptr;
TVariable *mVar_gl_MaxGeometryInputComponents = nullptr; TSymbol *mVar_gl_MaxGeometryInputComponents = nullptr;
TVariable *mVar_gl_MaxGeometryOutputComponents = nullptr; TSymbol *mVar_gl_MaxGeometryOutputComponents = nullptr;
TVariable *mVar_gl_MaxGeometryImageUniforms = nullptr; TSymbol *mVar_gl_MaxGeometryImageUniforms = nullptr;
TVariable *mVar_gl_MaxGeometryTextureImageUnits = nullptr; TSymbol *mVar_gl_MaxGeometryTextureImageUnits = nullptr;
TVariable *mVar_gl_MaxGeometryOutputVertices = nullptr; TSymbol *mVar_gl_MaxGeometryOutputVertices = nullptr;
TVariable *mVar_gl_MaxGeometryTotalOutputComponents = nullptr; TSymbol *mVar_gl_MaxGeometryTotalOutputComponents = nullptr;
TVariable *mVar_gl_MaxGeometryUniformComponents = nullptr; TSymbol *mVar_gl_MaxGeometryUniformComponents = nullptr;
TVariable *mVar_gl_MaxGeometryAtomicCounters = nullptr; TSymbol *mVar_gl_MaxGeometryAtomicCounters = nullptr;
TVariable *mVar_gl_MaxGeometryAtomicCounterBuffers = nullptr; TSymbol *mVar_gl_MaxGeometryAtomicCounterBuffers = nullptr;
TVariable *mVar_gl_FragData = nullptr; TSymbol *mVar_gl_FragData = nullptr;
TVariable *mVar_gl_SecondaryFragDataEXT = nullptr; TSymbol *mVar_gl_SecondaryFragDataEXT = nullptr;
TVariable *mVar_gl_FragDepthEXT = nullptr; TSymbol *mVar_gl_FragDepthEXT = nullptr;
TVariable *mVar_gl_LastFragData = nullptr; TSymbol *mVar_gl_LastFragData = nullptr;
TVariable *mVar_gl_LastFragDataNV = nullptr; TSymbol *mVar_gl_LastFragDataNV = nullptr;
TInterfaceBlock *mVar_gl_PerVertex = nullptr; TSymbol *mVar_gl_PerVertex = nullptr;
TVariable *mVar_gl_in = nullptr; TSymbol *mVar_gl_in = nullptr;
TVariable *mVar_gl_PositionGS = nullptr; TSymbol *mVar_gl_PositionGS = nullptr;
}; };
} // namespace sh } // namespace sh
......
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