Fix linkage.html failures on Mac.
The failure is due to when we initialize variables to 0, we re-create
the struct TType, and it contains a different unique id from the
original struct TType, thus leading to a different hashed name.
BUG=chromium:641129
TEST=webgl_conformance,webgl2_conformance
Change-Id: I267b97fa496f55ea59dacee93af8f6a90f3e66cb
Reviewed-on: https://chromium-review.googlesource.com/409602
Commit-Queue: Zhenyao Mo <zmo@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/InitializeVariables.cpp b/src/compiler/translator/InitializeVariables.cpp
index 576b64c..dafea1b 100644
--- a/src/compiler/translator/InitializeVariables.cpp
+++ b/src/compiler/translator/InitializeVariables.cpp
@@ -9,6 +9,7 @@
#include "angle_gl.h"
#include "common/debug.h"
#include "compiler/translator/IntermNode.h"
+#include "compiler/translator/SymbolTable.h"
#include "compiler/translator/util.h"
namespace sh
@@ -20,9 +21,13 @@
class VariableInitializer : public TIntermTraverser
{
public:
- VariableInitializer(const InitVariableList &vars)
- : TIntermTraverser(true, false, false), mVariables(vars), mCodeInserted(false)
+ VariableInitializer(const InitVariableList &vars, const TSymbolTable &symbolTable)
+ : TIntermTraverser(true, false, false),
+ mVariables(vars),
+ mSymbolTable(symbolTable),
+ mCodeInserted(false)
{
+ ASSERT(mSymbolTable.atGlobalLevel());
}
protected:
@@ -39,6 +44,7 @@
void insertInitCode(TIntermSequence *sequence);
const InitVariableList &mVariables;
+ const TSymbolTable &mSymbolTable;
bool mCodeInserted;
};
@@ -62,23 +68,23 @@
for (const auto &var : mVariables)
{
TString name = TString(var.name.c_str());
- TType type = sh::GetShaderVariableType(var);
- // Assign the array elements one by one to keep the AST compatible with ESSL 1.00 which
- // doesn't have array assignment.
if (var.isArray())
{
+ // Assign the array elements one by one to keep the AST compatible with ESSL 1.00 which
+ // doesn't have array assignment.
size_t pos = name.find_last_of('[');
if (pos != TString::npos)
{
name = name.substr(0, pos);
}
- TType elementType = type;
- elementType.clearArrayness();
+ TType elementType = sh::GetShaderVariableBasicType(var);
+ TType arrayType = elementType;
+ arrayType.setArraySize(var.elementCount());
for (unsigned int i = 0; i < var.arraySize; ++i)
{
- TIntermSymbol *arraySymbol = new TIntermSymbol(0, name, type);
+ TIntermSymbol *arraySymbol = new TIntermSymbol(0, name, arrayType);
TIntermBinary *element = new TIntermBinary(EOpIndexDirect, arraySymbol,
TIntermTyped::CreateIndexNode(i));
@@ -88,8 +94,20 @@
sequence->insert(sequence->begin(), assignment);
}
}
+ else if (var.isStruct())
+ {
+ TVariable *structInfo = reinterpret_cast<TVariable *>(mSymbolTable.findGlobal(name));
+ ASSERT(structInfo);
+
+ TIntermSymbol *symbol = new TIntermSymbol(0, name, structInfo->getType());
+ TIntermTyped *zero = TIntermTyped::CreateZero(structInfo->getType());
+
+ TIntermBinary *assign = new TIntermBinary(EOpAssign, symbol, zero);
+ sequence->insert(sequence->begin(), assign);
+ }
else
{
+ TType type = sh::GetShaderVariableBasicType(var);
TIntermSymbol *symbol = new TIntermSymbol(0, name, type);
TIntermTyped *zero = TIntermTyped::CreateZero(type);
@@ -101,9 +119,11 @@
} // namespace anonymous
-void InitializeVariables(TIntermNode *root, const InitVariableList &vars)
+void InitializeVariables(TIntermNode *root,
+ const InitVariableList &vars,
+ const TSymbolTable &symbolTable)
{
- VariableInitializer initializer(vars);
+ VariableInitializer initializer(vars, symbolTable);
root->traverse(&initializer);
}