Refactor GLSL scoped structure handling.
With a unique ID, similar to how we handle scoped structures
in the HLSL translator, we can simplify the declared structure
check.
BUG=angle:618
Change-Id: I5fe61c8d353650ac67a7c7ecdf53a70b91a9b717
Reviewed-on: https://chromium-review.googlesource.com/202500
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/OutputGLSLBase.cpp b/src/compiler/translator/OutputGLSLBase.cpp
index 6995594..6eaadd2 100644
--- a/src/compiler/translator/OutputGLSLBase.cpp
+++ b/src/compiler/translator/OutputGLSLBase.cpp
@@ -55,8 +55,6 @@
mSymbolTable(symbolTable),
mShaderVersion(shaderVersion)
{
- // Set up global scope.
- mDeclaredStructs.push_back(ScopedDeclaredStructs());
}
void TOutputGLSLBase::writeTriplet(
@@ -89,8 +87,14 @@
// Declare the struct if we have not done so already.
if (type.getBasicType() == EbtStruct && !structDeclared(type.getStruct()))
{
- declareStruct(type.getStruct());
- mDeclaredStructs[mDeclaredStructs.size() - 1].push_back(type.getStruct());
+ TStructure *structure = type.getStruct();
+
+ declareStruct(structure);
+
+ if (!structure->name().empty())
+ {
+ mDeclaredStructs.insert(structure->uniqueId());
+ }
}
else
{
@@ -604,7 +608,6 @@
if (depth > 0)
{
out << "{\n";
- pushDeclaredStructsScope();
}
incrementDepth(node);
@@ -623,7 +626,6 @@
// Scope the sequences except when at the global scope.
if (depth > 0)
{
- popDeclaredStructsScope();
out << "}\n";
}
visitChildren = false;
@@ -1035,17 +1037,12 @@
bool TOutputGLSLBase::structDeclared(const TStructure *structure) const
{
ASSERT(structure);
- ASSERT(mDeclaredStructs.size() > 0);
- for (size_t ii = mDeclaredStructs.size(); ii > 0; --ii)
+ if (structure->name().empty())
{
- const ScopedDeclaredStructs &scope = mDeclaredStructs[ii - 1];
- for (size_t jj = 0; jj < scope.size(); ++jj)
- {
- if (scope[jj]->equals(*structure))
- return true;
- }
+ return false;
}
- return false;
+
+ return (mDeclaredStructs.count(structure->uniqueId()) > 0);
}
void TOutputGLSLBase::declareStruct(const TStructure *structure)
@@ -1067,14 +1064,3 @@
out << "}";
}
-void TOutputGLSLBase::pushDeclaredStructsScope()
-{
- mDeclaredStructs.push_back(ScopedDeclaredStructs());
-}
-
-void TOutputGLSLBase::popDeclaredStructsScope()
-{
- // We should never pop the global scope.
- ASSERT(mDeclaredStructs.size() >= 2);
- mDeclaredStructs.pop_back();
-}