Commit 71a151fd by Jamie Madill Committed by Commit Bot

Vulkan: Use TSymbolTable in ExtractStructSamplers.

This will enable more code reuse when handling sampler struct as function arguments. We can add the sampler structs to the symbol table stack when they are function arguments. Bug: angleproject:2494 Change-Id: I9eeb1d3822e34cd43535e1b16a98864545755d22 Reviewed-on: https://chromium-review.googlesource.com/1117322 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent cdf50444
...@@ -24,7 +24,7 @@ namespace sh ...@@ -24,7 +24,7 @@ namespace sh
class TSymbolTable::TSymbolTableLevel class TSymbolTable::TSymbolTableLevel
{ {
public: public:
TSymbolTableLevel() {} TSymbolTableLevel() = default;
bool insert(TSymbol *symbol); bool insert(TSymbol *symbol);
...@@ -86,8 +86,8 @@ bool TSymbolTable::atGlobalLevel() const ...@@ -86,8 +86,8 @@ bool TSymbolTable::atGlobalLevel() const
void TSymbolTable::push() void TSymbolTable::push()
{ {
mTable.push_back(std::unique_ptr<TSymbolTableLevel>(new TSymbolTableLevel)); mTable.emplace_back(new TSymbolTableLevel);
mPrecisionStack.push_back(std::unique_ptr<PrecisionStackLevel>(new PrecisionStackLevel)); mPrecisionStack.emplace_back(new PrecisionStackLevel);
} }
void TSymbolTable::pop() void TSymbolTable::pop()
...@@ -98,7 +98,7 @@ void TSymbolTable::pop() ...@@ -98,7 +98,7 @@ void TSymbolTable::pop()
const TFunction *TSymbolTable::markFunctionHasPrototypeDeclaration( const TFunction *TSymbolTable::markFunctionHasPrototypeDeclaration(
const ImmutableString &mangledName, const ImmutableString &mangledName,
bool *hadPrototypeDeclarationOut) bool *hadPrototypeDeclarationOut) const
{ {
TFunction *function = findUserDefinedFunction(mangledName); TFunction *function = findUserDefinedFunction(mangledName);
*hadPrototypeDeclarationOut = function->hasPrototypeDeclaration(); *hadPrototypeDeclarationOut = function->hasPrototypeDeclaration();
...@@ -107,7 +107,7 @@ const TFunction *TSymbolTable::markFunctionHasPrototypeDeclaration( ...@@ -107,7 +107,7 @@ const TFunction *TSymbolTable::markFunctionHasPrototypeDeclaration(
} }
const TFunction *TSymbolTable::setFunctionParameterNamesFromDefinition(const TFunction *function, const TFunction *TSymbolTable::setFunctionParameterNamesFromDefinition(const TFunction *function,
bool *wasDefinedOut) bool *wasDefinedOut) const
{ {
TFunction *firstDeclaration = findUserDefinedFunction(function->getMangledName()); TFunction *firstDeclaration = findUserDefinedFunction(function->getMangledName());
ASSERT(firstDeclaration); ASSERT(firstDeclaration);
...@@ -213,6 +213,17 @@ void TSymbolTable::setGlobalInvariant(bool invariant) ...@@ -213,6 +213,17 @@ void TSymbolTable::setGlobalInvariant(bool invariant)
const TSymbol *TSymbolTable::find(const ImmutableString &name, int shaderVersion) const const TSymbol *TSymbolTable::find(const ImmutableString &name, int shaderVersion) const
{ {
const TSymbol *userSymbol = findUserDefined(name);
if (userSymbol)
{
return userSymbol;
}
return findBuiltIn(name, shaderVersion);
}
const TSymbol *TSymbolTable::findUserDefined(const ImmutableString &name) const
{
int userDefinedLevel = static_cast<int>(mTable.size()) - 1; int userDefinedLevel = static_cast<int>(mTable.size()) - 1;
while (userDefinedLevel >= 0) while (userDefinedLevel >= 0)
{ {
...@@ -224,7 +235,7 @@ const TSymbol *TSymbolTable::find(const ImmutableString &name, int shaderVersion ...@@ -224,7 +235,7 @@ const TSymbol *TSymbolTable::find(const ImmutableString &name, int shaderVersion
userDefinedLevel--; userDefinedLevel--;
} }
return findBuiltIn(name, shaderVersion); return nullptr;
} }
TFunction *TSymbolTable::findUserDefinedFunction(const ImmutableString &name) const TFunction *TSymbolTable::findUserDefinedFunction(const ImmutableString &name) const
...@@ -248,6 +259,14 @@ bool TSymbolTable::declare(TSymbol *symbol) ...@@ -248,6 +259,14 @@ bool TSymbolTable::declare(TSymbol *symbol)
return mTable.back()->insert(symbol); return mTable.back()->insert(symbol);
} }
bool TSymbolTable::declareInternal(TSymbol *symbol)
{
ASSERT(!mTable.empty());
ASSERT(symbol->symbolType() == SymbolType::AngleInternal);
ASSERT(!symbol->isFunction());
return mTable.back()->insert(symbol);
}
void TSymbolTable::declareUserDefinedFunction(TFunction *function, bool insertUnmangledName) void TSymbolTable::declareUserDefinedFunction(TFunction *function, bool insertUnmangledName)
{ {
ASSERT(!mTable.empty()); ASSERT(!mTable.empty());
...@@ -299,7 +318,7 @@ void TSymbolTable::clearCompilationResults() ...@@ -299,7 +318,7 @@ void TSymbolTable::clearCompilationResults()
mGlInVariableWithArraySize = nullptr; mGlInVariableWithArraySize = nullptr;
// User-defined scopes should have already been cleared when the compilation finished. // User-defined scopes should have already been cleared when the compilation finished.
ASSERT(mTable.size() == 0u); ASSERT(mTable.empty());
} }
int TSymbolTable::nextUniqueIdValue() int TSymbolTable::nextUniqueIdValue()
...@@ -316,7 +335,7 @@ void TSymbolTable::initializeBuiltIns(sh::GLenum type, ...@@ -316,7 +335,7 @@ void TSymbolTable::initializeBuiltIns(sh::GLenum type,
mResources = resources; mResources = resources;
// We need just one precision stack level for predefined precisions. // We need just one precision stack level for predefined precisions.
mPrecisionStack.push_back(std::unique_ptr<PrecisionStackLevel>(new PrecisionStackLevel)); mPrecisionStack.emplace_back(new PrecisionStackLevel);
switch (type) switch (type)
{ {
...@@ -359,5 +378,4 @@ void TSymbolTable::initSamplerDefaultPrecision(TBasicType samplerType) ...@@ -359,5 +378,4 @@ void TSymbolTable::initSamplerDefaultPrecision(TBasicType samplerType)
TSymbolTable::VariableMetadata::VariableMetadata() : staticRead(false), staticWrite(false), invariant(false) TSymbolTable::VariableMetadata::VariableMetadata() : staticRead(false), staticWrite(false), invariant(false)
{ {
} }
} // namespace sh } // namespace sh
...@@ -82,14 +82,17 @@ class TSymbolTable : angle::NonCopyable, TSymbolTableBase ...@@ -82,14 +82,17 @@ class TSymbolTable : angle::NonCopyable, TSymbolTableBase
// successful, and false if the declaration failed due to redefinition. // successful, and false if the declaration failed due to redefinition.
bool declare(TSymbol *symbol); bool declare(TSymbol *symbol);
// Only used to declare internal variables.
bool declareInternal(TSymbol *symbol);
// 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. // These return the TFunction pointer to keep using to refer to this function.
const TFunction *markFunctionHasPrototypeDeclaration(const ImmutableString &mangledName, const TFunction *markFunctionHasPrototypeDeclaration(const ImmutableString &mangledName,
bool *hadPrototypeDeclarationOut); bool *hadPrototypeDeclarationOut) const;
const TFunction *setFunctionParameterNamesFromDefinition(const TFunction *function, const TFunction *setFunctionParameterNamesFromDefinition(const TFunction *function,
bool *wasDefinedOut); bool *wasDefinedOut) const;
// Return false if the gl_in array size has already been initialized with a mismatching value. // Return false if the gl_in array size has already been initialized with a mismatching value.
bool setGlInArraySize(unsigned int inputArraySize); bool setGlInArraySize(unsigned int inputArraySize);
...@@ -108,6 +111,8 @@ class TSymbolTable : angle::NonCopyable, TSymbolTableBase ...@@ -108,6 +111,8 @@ class TSymbolTable : angle::NonCopyable, TSymbolTableBase
// with a reference to a short-lived char * is fine to pass here. // with a reference to a short-lived char * is fine to pass here.
const TSymbol *find(const ImmutableString &name, int shaderVersion) const; const TSymbol *find(const ImmutableString &name, int shaderVersion) const;
const TSymbol *findUserDefined(const ImmutableString &name) const;
const TSymbol *findGlobal(const ImmutableString &name) 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) const;
......
...@@ -22,8 +22,11 @@ class Traverser final : public TIntermTraverser ...@@ -22,8 +22,11 @@ class Traverser final : public TIntermTraverser
explicit Traverser(TSymbolTable *symbolTable) explicit Traverser(TSymbolTable *symbolTable)
: TIntermTraverser(true, false, false, symbolTable), mRemovedUniformsCount(0) : TIntermTraverser(true, false, false, symbolTable), mRemovedUniformsCount(0)
{ {
mSymbolTable->push();
} }
~Traverser() override { mSymbolTable->pop(); }
int removedUniformsCount() const { return mRemovedUniformsCount; } int removedUniformsCount() const { return mRemovedUniformsCount; }
bool visitDeclaration(Visit visit, TIntermDeclaration *decl) override bool visitDeclaration(Visit visit, TIntermDeclaration *decl) override
...@@ -103,7 +106,8 @@ class Traverser final : public TIntermTraverser ...@@ -103,7 +106,8 @@ class Traverser final : public TIntermTraverser
ImmutableString newName(stringBuilder); ImmutableString newName(stringBuilder);
TVariable *samplerReplacement = mExtractedSamplers[newName]; const TVariable *samplerReplacement =
static_cast<const TVariable *>(mSymbolTable->findUserDefined(newName));
ASSERT(samplerReplacement); ASSERT(samplerReplacement);
TIntermSymbol *replacement = new TIntermSymbol(samplerReplacement); TIntermSymbol *replacement = new TIntermSymbol(samplerReplacement);
...@@ -260,11 +264,10 @@ class Traverser final : public TIntermTraverser ...@@ -260,11 +264,10 @@ class Traverser final : public TIntermTraverser
newSequence->push_back(samplerDecl); newSequence->push_back(samplerDecl);
mExtractedSamplers[newName] = newVariable; mSymbolTable->declareInternal(newVariable);
} }
int mRemovedUniformsCount; int mRemovedUniformsCount;
std::map<ImmutableString, TVariable *> mExtractedSamplers;
std::set<ImmutableString> mRemovedStructs; std::set<ImmutableString> mRemovedStructs;
}; };
} // anonymous namespace } // anonymous namespace
......
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