Fix variable vs. function name conflict in HLSL output
GLSL ES spec accepts the case where an initializer of a variable calls
a function with the same name as the variable. The HLSL compiler
doesn't accept that. Work around this limitation in the HLSL compiler
by disambiguating user-defined functions from variables with a
different prefix.
BUG=angleproject:2095
TEST=angle_end2end_test, angle_unittests
Change-Id: I41b32a3fcc6fd4c548e8dc3aa680d1b07fcf8719
Reviewed-on: https://chromium-review.googlesource.com/557872
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/tests/gl_tests/GLSLTest.cpp b/src/tests/gl_tests/GLSLTest.cpp
index f608a67..5dd3094 100644
--- a/src/tests/gl_tests/GLSLTest.cpp
+++ b/src/tests/gl_tests/GLSLTest.cpp
@@ -3110,6 +3110,29 @@
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
+// Test that a variable hides a user-defined function with the same name after its initializer.
+// GLSL ES 1.00.17 section 4.2.2: "A variable declaration is visible immediately following the
+// initializer if present, otherwise immediately following the identifier"
+TEST_P(GLSLTest, VariableHidesUserDefinedFunctionAfterInitializer)
+{
+ const std::string &fragmentShader =
+ "precision mediump float;\n"
+ "uniform vec4 u;\n"
+ "vec4 foo()\n"
+ "{\n"
+ " return u;\n"
+ "}\n"
+ "void main()\n"
+ "{\n"
+ " vec4 foo = foo();\n"
+ " gl_FragColor = foo + vec4(0, 1, 0, 1);\n"
+ "}\n";
+
+ ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
+ drawQuad(program.get(), "inputAttribute", 0.5f);
+ 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,
ES2_D3D9(),