Commit 29bda815 by Olli Etuaho Committed by Commit Bot

Move symbol table initialization to SymbolTable.cpp

This is needed in order to make symbol table symbols statically allocated. BUG=angleproject:2267 TEST=angle_unittests Change-Id: Ia2d44fb30d49dc5d5c67643fe01280c89127a3c3 Reviewed-on: https://chromium-review.googlesource.com/889299Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 57dd97aa
...@@ -708,56 +708,11 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources) ...@@ -708,56 +708,11 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
compileResources = resources; compileResources = resources;
setResourceString(); setResourceString();
ASSERT(symbolTable.isEmpty()); symbolTable.initializeBuiltIns(shaderType, shaderSpec, resources);
symbolTable.push(); // COMMON_BUILTINS
symbolTable.push(); // ESSL1_BUILTINS
symbolTable.push(); // ESSL3_BUILTINS
symbolTable.push(); // ESSL3_1_BUILTINS
symbolTable.push(); // GLSL_BUILTINS
switch (shaderType)
{
case GL_FRAGMENT_SHADER:
symbolTable.setDefaultPrecision(EbtInt, EbpMedium);
break;
case GL_VERTEX_SHADER:
case GL_COMPUTE_SHADER:
case GL_GEOMETRY_SHADER_EXT:
symbolTable.setDefaultPrecision(EbtInt, EbpHigh);
symbolTable.setDefaultPrecision(EbtFloat, EbpHigh);
break;
default:
UNREACHABLE();
}
// Set defaults for sampler types that have default precision, even those that are
// only available if an extension exists.
// New sampler types in ESSL3 don't have default precision. ESSL1 types do.
initSamplerDefaultPrecision(EbtSampler2D);
initSamplerDefaultPrecision(EbtSamplerCube);
// SamplerExternalOES is specified in the extension to have default precision.
initSamplerDefaultPrecision(EbtSamplerExternalOES);
// SamplerExternal2DY2YEXT is specified in the extension to have default precision.
initSamplerDefaultPrecision(EbtSamplerExternal2DY2YEXT);
// It isn't specified whether Sampler2DRect has default precision.
initSamplerDefaultPrecision(EbtSampler2DRect);
symbolTable.setDefaultPrecision(EbtAtomicCounter, EbpHigh);
InsertBuiltInFunctions(shaderType, shaderSpec, resources, symbolTable);
IdentifyBuiltIns(shaderType, shaderSpec, resources, symbolTable);
symbolTable.markBuiltInInitializationFinished();
return true; return true;
} }
void TCompiler::initSamplerDefaultPrecision(TBasicType samplerType)
{
ASSERT(samplerType > EbtGuardSamplerBegin && samplerType < EbtGuardSamplerEnd);
symbolTable.setDefaultPrecision(samplerType, EbpLow);
}
void TCompiler::setResourceString() void TCompiler::setResourceString()
{ {
std::ostringstream strstream; std::ostringstream strstream;
......
...@@ -14,16 +14,6 @@ ...@@ -14,16 +14,6 @@
namespace sh namespace sh
{ {
void InsertBuiltInFunctions(sh::GLenum type,
ShShaderSpec spec,
const ShBuiltInResources &resources,
TSymbolTable &table);
void IdentifyBuiltIns(sh::GLenum type,
ShShaderSpec spec,
const ShBuiltInResources &resources,
TSymbolTable &symbolTable);
void InitExtensionBehavior(const ShBuiltInResources &resources, void InitExtensionBehavior(const ShBuiltInResources &resources,
TExtensionBehavior &extensionBehavior); TExtensionBehavior &extensionBehavior);
......
...@@ -90,6 +90,66 @@ class TSymbolTable : angle::NonCopyable ...@@ -90,6 +90,66 @@ class TSymbolTable : angle::NonCopyable
// Functions are always declared at global scope. // Functions are always declared at global scope.
void declareUserDefinedFunction(TFunction *function, bool insertUnmangledName); void declareUserDefinedFunction(TFunction *function, bool insertUnmangledName);
// These return the TFunction pointer to keep using to refer to this function.
const TFunction *markUserDefinedFunctionHasPrototypeDeclaration(
const ImmutableString &mangledName,
bool *hadPrototypeDeclarationOut);
const TFunction *setUserDefinedFunctionParameterNamesFromDefinition(const TFunction *function,
bool *wasDefinedOut);
// find() is guaranteed not to retain a reference to the ImmutableString, so an ImmutableString
// with a reference to a short-lived char * is fine to pass here.
const TSymbol *find(const ImmutableString &name, int shaderVersion) const;
const TSymbol *findGlobal(const ImmutableString &name) const;
const TSymbol *findBuiltIn(const ImmutableString &name, int shaderVersion) const;
const TSymbol *findBuiltIn(const ImmutableString &name,
int shaderVersion,
bool includeGLSLBuiltins) const;
void setDefaultPrecision(TBasicType type, TPrecision prec)
{
int indexOfLastElement = static_cast<int>(precisionStack.size()) - 1;
// Uses map operator [], overwrites the current value
(*precisionStack[indexOfLastElement])[type] = prec;
}
// Searches down the precisionStack for a precision qualifier
// for the specified TBasicType
TPrecision getDefaultPrecision(TBasicType type) const;
// This records invariant varyings declared through
// "invariant varying_name;".
void addInvariantVarying(const std::string &originalName);
// If this returns false, the varying could still be invariant
// if it is set as invariant during the varying variable
// declaration - this piece of information is stored in the
// variable's type, not here.
bool isVaryingInvariant(const std::string &originalName) const;
void setGlobalInvariant(bool invariant);
const TSymbolUniqueId nextUniqueId() { return TSymbolUniqueId(this); }
// Checks whether there is a built-in accessible by a shader with the specified version.
bool hasUnmangledBuiltInForShaderVersion(const char *name, int shaderVersion);
void initializeBuiltIns(sh::GLenum type,
ShShaderSpec spec,
const ShBuiltInResources &resources);
void clearCompilationResults();
private:
friend class TSymbolUniqueId;
int nextUniqueIdValue();
class TSymbolTableLevel;
ESymbolLevel currentLevel() const { return static_cast<ESymbolLevel>(table.size() - 1); }
// The insert* entry points are used when initializing the symbol table with built-ins. // The insert* entry points are used when initializing the symbol table with built-ins.
// They return the created symbol / true in case the declaration was successful, and nullptr / // They return the created symbol / true in case the declaration was successful, and nullptr /
// false if the declaration failed due to redefinition. // false if the declaration failed due to redefinition.
...@@ -187,64 +247,6 @@ class TSymbolTable : angle::NonCopyable ...@@ -187,64 +247,6 @@ class TSymbolTable : angle::NonCopyable
const TType *rvalue, const TType *rvalue,
const char *name); const char *name);
// These return the TFunction pointer to keep using to refer to this function.
const TFunction *markUserDefinedFunctionHasPrototypeDeclaration(
const ImmutableString &mangledName,
bool *hadPrototypeDeclarationOut);
const TFunction *setUserDefinedFunctionParameterNamesFromDefinition(const TFunction *function,
bool *wasDefinedOut);
// find() is guaranteed not to retain a reference to the ImmutableString, so an ImmutableString
// with a reference to a short-lived char * is fine to pass here.
const TSymbol *find(const ImmutableString &name, int shaderVersion) const;
const TSymbol *findGlobal(const ImmutableString &name) const;
const TSymbol *findBuiltIn(const ImmutableString &name, int shaderVersion) const;
const TSymbol *findBuiltIn(const ImmutableString &name,
int shaderVersion,
bool includeGLSLBuiltins) const;
void setDefaultPrecision(TBasicType type, TPrecision prec)
{
int indexOfLastElement = static_cast<int>(precisionStack.size()) - 1;
// Uses map operator [], overwrites the current value
(*precisionStack[indexOfLastElement])[type] = prec;
}
// Searches down the precisionStack for a precision qualifier
// for the specified TBasicType
TPrecision getDefaultPrecision(TBasicType type) const;
// This records invariant varyings declared through
// "invariant varying_name;".
void addInvariantVarying(const std::string &originalName);
// If this returns false, the varying could still be invariant
// if it is set as invariant during the varying variable
// declaration - this piece of information is stored in the
// variable's type, not here.
bool isVaryingInvariant(const std::string &originalName) const;
void setGlobalInvariant(bool invariant);
const TSymbolUniqueId nextUniqueId() { return TSymbolUniqueId(this); }
// Checks whether there is a built-in accessible by a shader with the specified version.
bool hasUnmangledBuiltInForShaderVersion(const char *name, int shaderVersion);
void markBuiltInInitializationFinished();
void clearCompilationResults();
private:
friend class TSymbolUniqueId;
int nextUniqueIdValue();
class TSymbolTableLevel;
ESymbolLevel currentLevel() const { return static_cast<ESymbolLevel>(table.size() - 1); }
TVariable *insertVariable(ESymbolLevel level, TVariable *insertVariable(ESymbolLevel level,
const ImmutableString &name, const ImmutableString &name,
const TType *type, const TType *type,
...@@ -260,6 +262,16 @@ class TSymbolTable : angle::NonCopyable ...@@ -260,6 +262,16 @@ class TSymbolTable : angle::NonCopyable
bool hasUnmangledBuiltInAtLevel(const char *name, ESymbolLevel level); bool hasUnmangledBuiltInAtLevel(const char *name, ESymbolLevel level);
void initSamplerDefaultPrecision(TBasicType samplerType);
void initializeBuiltInFunctions(sh::GLenum type,
ShShaderSpec spec,
const ShBuiltInResources &resources);
void initializeBuiltInVariables(sh::GLenum type,
ShShaderSpec spec,
const ShBuiltInResources &resources);
void markBuiltInInitializationFinished();
std::vector<TSymbolTableLevel *> table; std::vector<TSymbolTableLevel *> table;
typedef TMap<TBasicType, TPrecision> PrecisionStackLevel; typedef TMap<TBasicType, TPrecision> PrecisionStackLevel;
std::vector<PrecisionStackLevel *> precisionStack; std::vector<PrecisionStackLevel *> precisionStack;
...@@ -272,49 +284,6 @@ class TSymbolTable : angle::NonCopyable ...@@ -272,49 +284,6 @@ class TSymbolTable : angle::NonCopyable
int mUserDefinedUniqueIdsStart; int mUserDefinedUniqueIdsStart;
}; };
template <TPrecision precision>
bool TSymbolTable::insertConstInt(ESymbolLevel level, const ImmutableString &name, int value)
{
TVariable *constant = new TVariable(
this, name, StaticType::Get<EbtInt, precision, EvqConst, 1, 1>(), SymbolType::BuiltIn);
TConstantUnion *unionArray = new TConstantUnion[1];
unionArray[0].setIConst(value);
constant->shareConstPointer(unionArray);
return insert(level, constant);
}
template <TPrecision precision>
bool TSymbolTable::insertConstIntExt(ESymbolLevel level,
TExtension ext,
const ImmutableString &name,
int value)
{
TVariable *constant = new TVariable(
this, name, StaticType::Get<EbtInt, precision, EvqConst, 1, 1>(), SymbolType::BuiltIn, ext);
TConstantUnion *unionArray = new TConstantUnion[1];
unionArray[0].setIConst(value);
constant->shareConstPointer(unionArray);
return insert(level, constant);
}
template <TPrecision precision>
bool TSymbolTable::insertConstIvec3(ESymbolLevel level,
const ImmutableString &name,
const std::array<int, 3> &values)
{
TVariable *constantIvec3 = new TVariable(
this, name, StaticType::Get<EbtInt, precision, EvqConst, 3, 1>(), SymbolType::BuiltIn);
TConstantUnion *unionArray = new TConstantUnion[3];
for (size_t index = 0u; index < 3u; ++index)
{
unionArray[index].setIConst(values[index]);
}
constantIvec3->shareConstPointer(unionArray);
return insert(level, constantIvec3);
}
} // namespace sh } // namespace sh
#endif // COMPILER_TRANSLATOR_SYMBOLTABLE_H_ #endif // COMPILER_TRANSLATOR_SYMBOLTABLE_H_
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