Commit 75d577fb by Natasha Lee Committed by Commit Bot

Fixed Bug where array initialized with same name of

previously declared variable fails on DirectX. Combined user defined variables with their unique ids to avoid overwriting same name variables of different scope. Bug: angleproject:2126 Change-Id: If9ad9e48f629d83b105d43ee28a50b8176d0e0a1 Reviewed-on: https://chromium-review.googlesource.com/c/1456484Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com>
parent 238c19e1
......@@ -11,6 +11,7 @@
#include "compiler/translator/IntermNode.h"
#include "compiler/translator/StructureHLSL.h"
#include "compiler/translator/SymbolTable.h"
#include "compiler/translator/util.h"
namespace sh
{
......@@ -857,6 +858,13 @@ TString DecorateVariableIfNeeded(const TVariable &variable)
ASSERT(!name.beginsWith("_"));
return TString(name.data());
}
// For user defined variables, combine variable name with unique id
// so variables of the same name in different scopes do not get overwritten.
else if (variable.symbolType() == SymbolType::UserDefined &&
variable.getType().getQualifier() == EvqTemporary)
{
return Decorate(variable.name()) + str(variable.uniqueId().get());
}
else
{
return Decorate(variable.name());
......
......@@ -197,5 +197,30 @@ TEST_F(HLSLOutputTest, Array)
}
})";
compile(shaderString);
EXPECT_TRUE(foundInCode("_arr[2]"));
// The unique id of arr is 1030, which is given to the symbol when parsed and inserted to the
// symbol table
EXPECT_TRUE(foundInCode("_arr1030[2]"));
}
// Test that initializing array with previously declared array will not be overwritten
TEST_F(HLSLOutputTest, SameNameArray)
{
const std::string &shaderString =
R"(#version 300 es
precision highp float;
out vec4 my_FragColor;
void main()
{
float arr[2] = float[2](1.0, 1.0);
{
float arr[2] = arr;
my_FragColor = vec4(0.0, arr[0], 0.0, arr[1]);
}
})";
compile(shaderString);
// The unique id of the original array, arr, is 1029
EXPECT_TRUE(foundInCode("_arr1029[2]"));
// The unique id of the new array, arr, is 1030
EXPECT_TRUE(foundInCode("_arr1030[2]"));
}
\ No newline at end of file
......@@ -5095,6 +5095,27 @@ void main()
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
// Test initializing an array with the same name of previously declared array
TEST_P(GLSLTest_ES3, InitSameNameArray)
{
constexpr char kFS[] = R"(#version 300 es
precision highp float;
out vec4 my_FragColor;
void main()
{
float arr[2] = float[2](1.0, 1.0);
{
float arr[2] = arr;
my_FragColor = vec4(0.0, arr[0], 0.0, arr[1]);
}
})";
ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS);
drawQuad(program, essl31_shaders::PositionAttrib(), 0.5f, 1.0f, true);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these
// tests should be run against.
ANGLE_INSTANTIATE_TEST(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