Commit b391ec40 by Olli Etuaho Committed by Commit Bot

Generate code for looking up built-ins

Instead of storing built-ins in a std::unordered_map, we now generate a series of switch statements using the hash value of the look-up string. This works similarly to earlier implementation of looking up unmangled built-ins. Those built-ins that need to be initialized at run-time are stored as member variables of TSymbolTable. This increases compiler init performance significantly, as well as increasing compiler perf test scores around 1-2%. Binary size is larger than before though. BUG=angleproject:2267 TEST=angle_unittests Change-Id: If1dcd36f0d2b30c2ed315cdcf6e831ae9fe70c94 Reviewed-on: https://chromium-review.googlesource.com/960031Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent aa5d883e
......@@ -165,6 +165,7 @@ generators = {
'src/compiler/translator/BuiltIn_autogen.h',
'src/compiler/translator/ParseContext_autogen.h',
'src/compiler/translator/SymbolTable_autogen.cpp',
'src/compiler/translator/SymbolTable_autogen.h',
'src/tests/compiler_tests/ImmutableString_test_autogen.cpp',
],
'script': 'src/compiler/translator/gen_builtin_symbols.py',
......
......@@ -59,22 +59,6 @@ class TSymbolTable::TSymbolTableLevel
bool mGlobalInvariant;
};
class TSymbolTable::TSymbolTableBuiltInLevel
{
public:
TSymbolTableBuiltInLevel() = default;
void insert(const TSymbol *symbol);
const TSymbol *find(const ImmutableString &name) const;
private:
using tLevel = TUnorderedMap<ImmutableString,
const TSymbol *,
ImmutableString::FowlerNollVoHash<sizeof(size_t)>>;
using tLevelPair = const tLevel::value_type;
tLevel mLevel;
};
bool TSymbolTable::TSymbolTableLevel::insert(TSymbol *symbol)
{
// returning true means symbol was added to the table
......@@ -96,20 +80,6 @@ TSymbol *TSymbolTable::TSymbolTableLevel::find(const ImmutableString &name) cons
return (*it).second;
}
void TSymbolTable::TSymbolTableBuiltInLevel::insert(const TSymbol *symbol)
{
mLevel.insert(tLevelPair(symbol->getMangledName(), symbol));
}
const TSymbol *TSymbolTable::TSymbolTableBuiltInLevel::find(const ImmutableString &name) const
{
tLevel::const_iterator it = mLevel.find(name);
if (it == mLevel.end())
return nullptr;
else
return (*it).second;
}
TSymbolTable::TSymbolTable() : mUniqueIdCounter(0), mShaderType(GL_FRAGMENT_SHADER)
{
}
......@@ -126,12 +96,6 @@ bool TSymbolTable::atGlobalLevel() const
return mTable.size() == 1u;
}
void TSymbolTable::pushBuiltInLevel()
{
mBuiltInTable.push_back(
std::unique_ptr<TSymbolTableBuiltInLevel>(new TSymbolTableBuiltInLevel));
}
void TSymbolTable::push()
{
mTable.push_back(std::unique_ptr<TSymbolTableLevel>(new TSymbolTableLevel));
......@@ -208,31 +172,6 @@ const TSymbol *TSymbolTable::findBuiltIn(const ImmutableString &name, int shader
return findBuiltIn(name, shaderVersion, false);
}
const TSymbol *TSymbolTable::findBuiltIn(const ImmutableString &name,
int shaderVersion,
bool includeGLSLBuiltins) const
{
for (int level = LAST_BUILTIN_LEVEL; level >= 0; level--)
{
if (level == GLSL_BUILTINS && !includeGLSLBuiltins)
level--;
if (level == ESSL3_1_BUILTINS && shaderVersion != 310)
level--;
if (level == ESSL3_BUILTINS && shaderVersion < 300)
level--;
if (level == ESSL1_BUILTINS && shaderVersion != 100)
level--;
const TSymbol *symbol = mBuiltInTable[level]->find(name);
if (symbol)
return symbol;
}
return nullptr;
}
bool TSymbolTable::declare(TSymbol *symbol)
{
ASSERT(!mTable.empty());
......@@ -252,14 +191,6 @@ void TSymbolTable::declareUserDefinedFunction(TFunction *function, bool insertUn
mTable[0]->insert(function);
}
void TSymbolTable::insertBuiltIn(ESymbolLevel level, const TSymbol *symbol)
{
ASSERT(symbol);
ASSERT(level <= LAST_BUILTIN_LEVEL);
mBuiltInTable[level]->insert(symbol);
}
void TSymbolTable::setDefaultPrecision(TBasicType type, TPrecision prec)
{
int indexOfLastElement = static_cast<int>(mPrecisionStack.size()) - 1;
......@@ -329,13 +260,7 @@ void TSymbolTable::initializeBuiltIns(sh::GLenum type,
const ShBuiltInResources &resources)
{
mShaderType = type;
ASSERT(isEmpty());
pushBuiltInLevel(); // COMMON_BUILTINS
pushBuiltInLevel(); // ESSL1_BUILTINS
pushBuiltInLevel(); // ESSL3_BUILTINS
pushBuiltInLevel(); // ESSL3_1_BUILTINS
pushBuiltInLevel(); // GLSL_BUILTINS
mResources = resources;
// We need just one precision stack level for predefined precisions.
mPrecisionStack.push_back(std::unique_ptr<PrecisionStackLevel>(new PrecisionStackLevel));
......@@ -368,8 +293,7 @@ void TSymbolTable::initializeBuiltIns(sh::GLenum type,
setDefaultPrecision(EbtAtomicCounter, EbpHigh);
insertBuiltInFunctions(type);
insertBuiltInVariables(type, spec, resources);
initializeBuiltInVariables(type, spec, resources);
mUniqueIdCounter = kLastBuiltInId + 1;
}
......
......@@ -38,6 +38,7 @@
#include "compiler/translator/InfoSink.h"
#include "compiler/translator/IntermNode.h"
#include "compiler/translator/Symbol.h"
#include "compiler/translator/SymbolTable_autogen.h"
namespace sh
{
......@@ -60,7 +61,7 @@ struct UnmangledBuiltIn
TExtension extension;
};
class TSymbolTable : angle::NonCopyable
class TSymbolTable : angle::NonCopyable, TSymbolTableBase
{
public:
TSymbolTable();
......@@ -134,23 +135,16 @@ class TSymbolTable : angle::NonCopyable
friend class TSymbolUniqueId;
int nextUniqueIdValue();
class TSymbolTableBuiltInLevel;
class TSymbolTableLevel;
void pushBuiltInLevel();
void insertBuiltIn(ESymbolLevel level, const TSymbol *symbol);
TFunction *findUserDefinedFunction(const ImmutableString &name) const;
void initSamplerDefaultPrecision(TBasicType samplerType);
void insertBuiltInFunctions(sh::GLenum shaderType);
void insertBuiltInVariables(sh::GLenum shaderType,
ShShaderSpec spec,
const ShBuiltInResources &resources);
void initializeBuiltInVariables(sh::GLenum shaderType,
ShShaderSpec spec,
const ShBuiltInResources &resources);
std::vector<std::unique_ptr<TSymbolTableBuiltInLevel>> mBuiltInTable;
std::vector<std::unique_ptr<TSymbolTableLevel>> mTable;
// There's one precision stack level for predefined precisions and then one level for each scope
......@@ -163,6 +157,7 @@ class TSymbolTable : angle::NonCopyable
static const int kLastBuiltInId;
sh::GLenum mShaderType;
ShBuiltInResources mResources;
};
} // namespace sh
......
This source diff could not be displayed because it is too large. You can view the blob instead.
// GENERATED FILE - DO NOT EDIT.
// Generated by gen_builtin_symbols.py using data from builtin_variables.json and
// builtin_function_declarations.txt.
//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// SymbolTable_autogen.h:
// Autogenerated member variables of TSymbolTable.
#ifndef COMPILER_TRANSLATOR_SYMBOLTABLE_AUTOGEN_H_
#define COMPILER_TRANSLATOR_SYMBOLTABLE_AUTOGEN_H_
namespace sh
{
class TSymbolTableBase
{
protected:
TSymbolTableBase() = default;
TStructure *mVar_gl_DepthRangeParameters = nullptr;
TVariable *mVar_gl_DepthRange = nullptr;
TVariable *mVar_gl_MaxVertexAttribs = nullptr;
TVariable *mVar_gl_MaxVertexUniformVectors = nullptr;
TVariable *mVar_gl_MaxVertexTextureImageUnits = nullptr;
TVariable *mVar_gl_MaxCombinedTextureImageUnits = nullptr;
TVariable *mVar_gl_MaxTextureImageUnits = nullptr;
TVariable *mVar_gl_MaxFragmentUniformVectors = nullptr;
TVariable *mVar_gl_MaxVaryingVectors = nullptr;
TVariable *mVar_gl_MaxDrawBuffers = nullptr;
TVariable *mVar_gl_MaxDualSourceDrawBuffersEXT = nullptr;
TVariable *mVar_gl_MaxVertexOutputVectors = nullptr;
TVariable *mVar_gl_MaxFragmentInputVectors = nullptr;
TVariable *mVar_gl_MinProgramTexelOffset = nullptr;
TVariable *mVar_gl_MaxProgramTexelOffset = nullptr;
TVariable *mVar_gl_MaxImageUnits = nullptr;
TVariable *mVar_gl_MaxVertexImageUniforms = nullptr;
TVariable *mVar_gl_MaxFragmentImageUniforms = nullptr;
TVariable *mVar_gl_MaxComputeImageUniforms = nullptr;
TVariable *mVar_gl_MaxCombinedImageUniforms = nullptr;
TVariable *mVar_gl_MaxCombinedShaderOutputResources = nullptr;
TVariable *mVar_gl_MaxComputeWorkGroupCount = nullptr;
TVariable *mVar_gl_MaxComputeWorkGroupSize = nullptr;
TVariable *mVar_gl_MaxComputeUniformComponents = nullptr;
TVariable *mVar_gl_MaxComputeTextureImageUnits = nullptr;
TVariable *mVar_gl_MaxComputeAtomicCounters = nullptr;
TVariable *mVar_gl_MaxComputeAtomicCounterBuffers = nullptr;
TVariable *mVar_gl_MaxVertexAtomicCounters = nullptr;
TVariable *mVar_gl_MaxFragmentAtomicCounters = nullptr;
TVariable *mVar_gl_MaxCombinedAtomicCounters = nullptr;
TVariable *mVar_gl_MaxAtomicCounterBindings = nullptr;
TVariable *mVar_gl_MaxVertexAtomicCounterBuffers = nullptr;
TVariable *mVar_gl_MaxFragmentAtomicCounterBuffers = nullptr;
TVariable *mVar_gl_MaxCombinedAtomicCounterBuffers = nullptr;
TVariable *mVar_gl_MaxAtomicCounterBufferSize = nullptr;
TVariable *mVar_gl_MaxGeometryInputComponents = nullptr;
TVariable *mVar_gl_MaxGeometryOutputComponents = nullptr;
TVariable *mVar_gl_MaxGeometryImageUniforms = nullptr;
TVariable *mVar_gl_MaxGeometryTextureImageUnits = nullptr;
TVariable *mVar_gl_MaxGeometryOutputVertices = nullptr;
TVariable *mVar_gl_MaxGeometryTotalOutputComponents = nullptr;
TVariable *mVar_gl_MaxGeometryUniformComponents = nullptr;
TVariable *mVar_gl_MaxGeometryAtomicCounters = nullptr;
TVariable *mVar_gl_MaxGeometryAtomicCounterBuffers = nullptr;
TVariable *mVar_gl_FragData = nullptr;
TVariable *mVar_gl_SecondaryFragDataEXT = nullptr;
TVariable *mVar_gl_FragDepthEXT = nullptr;
TVariable *mVar_gl_LastFragData = nullptr;
TVariable *mVar_gl_LastFragDataNV = nullptr;
TInterfaceBlock *mVar_gl_PerVertex = nullptr;
TVariable *mVar_gl_in = nullptr;
TVariable *mVar_gl_PositionGS = nullptr;
};
} // namespace sh
#endif // COMPILER_TRANSLATOR_SYMBOLTABLE_AUTOGEN_H_
......@@ -516,7 +516,7 @@
},
"subgroups":{
"EXTBlendFuncExtended":{
"condition":"resources.EXT_blend_func_extended",
"condition":"mResources.EXT_blend_func_extended",
"variables":{
"gl_SecondaryFragColorEXT":{
"level":"ESSL1_BUILTINS",
......@@ -536,7 +536,7 @@
}
},
"EXTFragDepth":{
"condition":"resources.EXT_frag_depth",
"condition":"mResources.EXT_frag_depth",
"variables":{
"gl_FragDepthEXT":{
"level":"ESSL1_BUILTINS",
......@@ -546,7 +546,7 @@
}
},
"EXTShaderFramebufferFetch":{
"condition":"resources.EXT_shader_framebuffer_fetch",
"condition":"mResources.EXT_shader_framebuffer_fetch",
"variables":{
"gl_LastFragData":{
"level":"ESSL1_BUILTINS",
......@@ -556,7 +556,7 @@
}
},
"NVShaderFramebufferFetch":{
"condition":"resources.NV_shader_framebuffer_fetch",
"condition":"mResources.NV_shader_framebuffer_fetch",
"variables":{
"gl_LastFragColor":{
"level":"ESSL1_BUILTINS",
......@@ -577,7 +577,7 @@
}
},
"ARMShaderFramebufferFetch":{
"condition":"!resources.EXT_shader_framebuffer_fetch && !resources.NV_shader_framebuffer_fetch && resources.ARM_shader_framebuffer_fetch",
"condition":"!mResources.EXT_shader_framebuffer_fetch && !mResources.NV_shader_framebuffer_fetch && mResources.ARM_shader_framebuffer_fetch",
"variables":{
"gl_LastFragColorARM":{
"level":"ESSL1_BUILTINS",
......@@ -592,7 +592,7 @@
}
},
"GeometryShaderSupported":{
"condition":"resources.EXT_geometry_shader",
"condition":"mResources.EXT_geometry_shader",
"variables":{
"gl_PrimitiveID":{
"level":"ESSL3_1_BUILTINS",
......@@ -821,7 +821,7 @@
}
},
"Multiview":{
"condition":"resources.OVR_multiview && shaderType != GL_COMPUTE_SHADER",
"condition":"mResources.OVR_multiview && shaderType != GL_COMPUTE_SHADER",
"subgroups":{
"ESSL3":{
"variables":{
......
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