Commit 39ee3640 by Shahbaz Youssefi Committed by Commit Bot

Translator: Fix struct/uniform separation w.r.t to arrays

When a uniform of struct type was redeclared, the arrayness information was not transferred. Bug: chromium:1204861 Change-Id: Ic3f461a4aa349a73bc48568ee14b5418f0556238 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2889599 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com>
parent b0c217ba
...@@ -41,7 +41,7 @@ class Traverser : public TIntermTraverser ...@@ -41,7 +41,7 @@ class Traverser : public TIntermTraverser
if (type.isStructSpecifier() && type.getQualifier() == EvqUniform) if (type.isStructSpecifier() && type.getQualifier() == EvqUniform)
{ {
doReplacement(decl, declarator, type.getStruct()); doReplacement(decl, declarator, type);
} }
return false; return false;
...@@ -57,15 +57,13 @@ class Traverser : public TIntermTraverser ...@@ -57,15 +57,13 @@ class Traverser : public TIntermTraverser
} }
private: private:
void doReplacement(TIntermDeclaration *decl, void doReplacement(TIntermDeclaration *decl, TIntermTyped *declarator, const TType &oldType)
TIntermTyped *declarator,
const TStructure *oldStructure)
{ {
const TStructure *structure = oldStructure; const TStructure *structure = oldType.getStruct();
if (oldStructure->symbolType() == SymbolType::Empty) if (structure->symbolType() == SymbolType::Empty)
{ {
// Handle nameless structs: uniform struct { ... } variable; // Handle nameless structs: uniform struct { ... } variable;
structure = new TStructure(mSymbolTable, kEmptyImmutableString, &oldStructure->fields(), structure = new TStructure(mSymbolTable, kEmptyImmutableString, &structure->fields(),
SymbolType::AngleInternal); SymbolType::AngleInternal);
} }
TType *namedType = new TType(structure, true); TType *namedType = new TType(structure, true);
...@@ -87,6 +85,7 @@ class Traverser : public TIntermTraverser ...@@ -87,6 +85,7 @@ class Traverser : public TIntermTraverser
TIntermDeclaration *namedDecl = new TIntermDeclaration; TIntermDeclaration *namedDecl = new TIntermDeclaration;
TType *uniformType = new TType(structure, false); TType *uniformType = new TType(structure, false);
uniformType->setQualifier(EvqUniform); uniformType->setQualifier(EvqUniform);
uniformType->makeArrays(oldType.getArraySizes());
TVariable *newVar = new TVariable(mSymbolTable, asSymbol->getName(), uniformType, TVariable *newVar = new TVariable(mSymbolTable, asSymbol->getName(), uniformType,
asSymbol->variable().symbolType()); asSymbol->variable().symbolType());
......
...@@ -10717,6 +10717,37 @@ void main() { ...@@ -10717,6 +10717,37 @@ void main() {
EXPECT_NE(compileResult, 0); EXPECT_NE(compileResult, 0);
} }
// Regression test for transformation bug which separates struct declarations from uniform
// declarations. The bug was that the arrayness of the declaration was not being applied to the
// replaced uniform variable.
TEST_P(GLSLTest_ES31, UniformStructBug2)
{
constexpr char kVS[] = R"(#version 310 es
precision highp float;
uniform struct Global
{
float x;
} u_global[2][3];
void main() {
float y = u_global[0][0].x;
gl_Position = vec4(y);
})";
GLuint shader = glCreateShader(GL_VERTEX_SHADER);
const char *sourceArray[1] = {kVS};
GLint lengths[1] = {static_cast<GLint>(sizeof(kVS) - 1)};
glShaderSource(shader, 1, sourceArray, lengths);
glCompileShader(shader);
GLint compileResult;
glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
EXPECT_NE(compileResult, 0);
}
} // anonymous namespace } // anonymous namespace
ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(GLSLTest); ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(GLSLTest);
......
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