Fix link error when using varyings with "dx_".
Varyings beginning with "dx_" would not get decorated properly, or
at all, which could cause potential internal variables and certainly
caused link errors. Fix this by no longer treating the "dx_" prefix
differently.
Also fix our naming of "dx_Position" to be consistent with our other
internal types.
BUG=angle:678
Change-Id: I03da0494a3d934d82ae7b3f8f12a576ff9bc3869
Reviewed-on: https://chromium-review.googlesource.com/203777
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/OutputHLSL.cpp b/src/compiler/translator/OutputHLSL.cpp
index dc79c51..7e835c4 100644
--- a/src/compiler/translator/OutputHLSL.cpp
+++ b/src/compiler/translator/OutputHLSL.cpp
@@ -3792,7 +3792,7 @@
TString OutputHLSL::decorate(const TString &string)
{
- if (string.compare(0, 3, "gl_") != 0 && string.compare(0, 3, "dx_") != 0)
+ if (string.compare(0, 3, "gl_") != 0)
{
return "_" + string;
}
diff --git a/src/libGLESv2/DynamicHLSL.cpp b/src/libGLESv2/DynamicHLSL.cpp
index b75a549..935d841 100644
--- a/src/libGLESv2/DynamicHLSL.cpp
+++ b/src/libGLESv2/DynamicHLSL.cpp
@@ -549,7 +549,7 @@
if (shaderModel < 4)
{
- vertexHLSL += " float4 _dx_Position : " + dxPositionSemantic + ";\n";
+ vertexHLSL += " float4 dx_Position : " + dxPositionSemantic + ";\n";
vertexHLSL += " float4 gl_Position : " + glPositionSemantic + Str(glPositionSemanticIndex) + ";\n";
linkedVaryings->push_back(LinkedVarying("gl_Position", GL_FLOAT_VEC4, 1, glPositionSemantic, glPositionSemanticIndex, 1));
@@ -571,7 +571,7 @@
if (shaderModel >= 4)
{
- vertexHLSL += " float4 _dx_Position : " + dxPositionSemantic + ";\n";
+ vertexHLSL += " float4 dx_Position : " + dxPositionSemantic + ";\n";
vertexHLSL += " float4 gl_Position : " + glPositionSemantic + Str(glPositionSemanticIndex) + ";\n";
linkedVaryings->push_back(LinkedVarying("gl_Position", GL_FLOAT_VEC4, 1, glPositionSemantic, glPositionSemanticIndex, 1));
}
@@ -589,10 +589,10 @@
"\n"
" VS_OUTPUT output;\n"
" output.gl_Position = gl_Position;\n"
- " output._dx_Position.x = gl_Position.x;\n"
- " output._dx_Position.y = -gl_Position.y;\n"
- " output._dx_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n"
- " output._dx_Position.w = gl_Position.w;\n";
+ " output.dx_Position.x = gl_Position.x;\n"
+ " output.dx_Position.y = -gl_Position.y;\n"
+ " output.dx_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n"
+ " output.dx_Position.w = gl_Position.w;\n";
}
else
{
@@ -601,10 +601,10 @@
"\n"
" VS_OUTPUT output;\n"
" output.gl_Position = gl_Position;\n"
- " output._dx_Position.x = gl_Position.x * dx_ViewAdjust.z + dx_ViewAdjust.x * gl_Position.w;\n"
- " output._dx_Position.y = -(gl_Position.y * dx_ViewAdjust.w + dx_ViewAdjust.y * gl_Position.w);\n"
- " output._dx_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n"
- " output._dx_Position.w = gl_Position.w;\n";
+ " output.dx_Position.x = gl_Position.x * dx_ViewAdjust.z + dx_ViewAdjust.x * gl_Position.w;\n"
+ " output.dx_Position.y = -(gl_Position.y * dx_ViewAdjust.w + dx_ViewAdjust.y * gl_Position.w);\n"
+ " output.dx_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n"
+ " output.dx_Position.w = gl_Position.w;\n";
}
if (vertexShader->mUsesPointSize && shaderModel >= 3)
diff --git a/src/libGLESv2/renderer/d3d11/Renderer11.cpp b/src/libGLESv2/renderer/d3d11/Renderer11.cpp
index a90b2cd..bd54252 100644
--- a/src/libGLESv2/renderer/d3d11/Renderer11.cpp
+++ b/src/libGLESv2/renderer/d3d11/Renderer11.cpp
@@ -1944,7 +1944,7 @@
unsigned int Renderer11::getReservedVaryings() const
{
- // We potentially reserve varyings for gl_Position, _dx_Position, gl_FragCoord and gl_PointSize
+ // We potentially reserve varyings for gl_Position, dx_Position, gl_FragCoord and gl_PointSize
return 4;
}
diff --git a/tests/angle_tests/GLSLStructTest.cpp b/tests/angle_tests/GLSLTest.cpp
similarity index 60%
rename from tests/angle_tests/GLSLStructTest.cpp
rename to tests/angle_tests/GLSLTest.cpp
index 531afe1..7f4983e 100644
--- a/tests/angle_tests/GLSLStructTest.cpp
+++ b/tests/angle_tests/GLSLTest.cpp
@@ -1,9 +1,9 @@
#include "ANGLETest.h"
-class GLSLStructTest : public ANGLETest
+class GLSLTest : public ANGLETest
{
protected:
- GLSLStructTest()
+ GLSLTest()
{
setWindowWidth(128);
setWindowHeight(128);
@@ -17,7 +17,7 @@
{
ANGLETest::SetUp();
- mVertexShaderSource = SHADER_SOURCE
+ mSimpleVSSource = SHADER_SOURCE
(
attribute vec4 inputAttribute;
void main()
@@ -27,10 +27,10 @@
);
}
- std::string mVertexShaderSource;
+ std::string mSimpleVSSource;
};
-TEST_F(GLSLStructTest, nameless_scoped_structs)
+TEST_F(GLSLTest, nameless_scoped_structs)
{
const std::string fragmentShaderSource = SHADER_SOURCE
(
@@ -48,10 +48,10 @@
}
);
- GLuint program = compileProgram(mVertexShaderSource, fragmentShaderSource);
+ GLuint program = compileProgram(mSimpleVSSource, fragmentShaderSource);
EXPECT_NE(0u, program);
}
-TEST_F(GLSLStructTest, scoped_structs_order_bug)
+TEST_F(GLSLTest, scoped_structs_order_bug)
{
const std::string fragmentShaderSource = SHADER_SOURCE
(
@@ -79,11 +79,11 @@
}
);
- GLuint program = compileProgram(mVertexShaderSource, fragmentShaderSource);
+ GLuint program = compileProgram(mSimpleVSSource, fragmentShaderSource);
EXPECT_NE(0u, program);
}
-TEST_F(GLSLStructTest, scoped_structs_bug)
+TEST_F(GLSLTest, scoped_structs_bug)
{
const std::string fragmentShaderSource = SHADER_SOURCE
(
@@ -111,6 +111,35 @@
}
);
- GLuint program = compileProgram(mVertexShaderSource, fragmentShaderSource);
+ GLuint program = compileProgram(mSimpleVSSource, fragmentShaderSource);
+ EXPECT_NE(0u, program);
+}
+
+TEST_F(GLSLTest, dx_position_bug)
+{
+ const std::string &vertexShaderSource = SHADER_SOURCE
+ (
+ attribute vec4 inputAttribute;
+ varying float dx_Position;
+ void main()
+ {
+ gl_Position = vec4(inputAttribute);
+ dx_Position = 0.0;
+ }
+ );
+
+ const std::string &fragmentShaderSource = SHADER_SOURCE
+ (
+ precision mediump float;
+
+ varying float dx_Position;
+
+ void main()
+ {
+ gl_FragColor = vec4(dx_Position, 0, 0, 1);
+ }
+ );
+
+ GLuint program = compileProgram(vertexShaderSource, fragmentShaderSource);
EXPECT_NE(0u, program);
}