Commit 2bf8b372 by Jamie Madill

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/203777Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent adfffe46
...@@ -3792,7 +3792,7 @@ TString OutputHLSL::structNameString(const TStructure &structure) ...@@ -3792,7 +3792,7 @@ TString OutputHLSL::structNameString(const TStructure &structure)
TString OutputHLSL::decorate(const TString &string) 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; return "_" + string;
} }
......
...@@ -549,7 +549,7 @@ bool DynamicHLSL::generateShaderLinkHLSL(InfoLog &infoLog, int registers, const ...@@ -549,7 +549,7 @@ bool DynamicHLSL::generateShaderLinkHLSL(InfoLog &infoLog, int registers, const
if (shaderModel < 4) if (shaderModel < 4)
{ {
vertexHLSL += " float4 _dx_Position : " + dxPositionSemantic + ";\n"; vertexHLSL += " float4 dx_Position : " + dxPositionSemantic + ";\n";
vertexHLSL += " float4 gl_Position : " + glPositionSemantic + Str(glPositionSemanticIndex) + ";\n"; vertexHLSL += " float4 gl_Position : " + glPositionSemantic + Str(glPositionSemanticIndex) + ";\n";
linkedVaryings->push_back(LinkedVarying("gl_Position", GL_FLOAT_VEC4, 1, glPositionSemantic, glPositionSemanticIndex, 1)); linkedVaryings->push_back(LinkedVarying("gl_Position", GL_FLOAT_VEC4, 1, glPositionSemantic, glPositionSemanticIndex, 1));
...@@ -571,7 +571,7 @@ bool DynamicHLSL::generateShaderLinkHLSL(InfoLog &infoLog, int registers, const ...@@ -571,7 +571,7 @@ bool DynamicHLSL::generateShaderLinkHLSL(InfoLog &infoLog, int registers, const
if (shaderModel >= 4) if (shaderModel >= 4)
{ {
vertexHLSL += " float4 _dx_Position : " + dxPositionSemantic + ";\n"; vertexHLSL += " float4 dx_Position : " + dxPositionSemantic + ";\n";
vertexHLSL += " float4 gl_Position : " + glPositionSemantic + Str(glPositionSemanticIndex) + ";\n"; vertexHLSL += " float4 gl_Position : " + glPositionSemantic + Str(glPositionSemanticIndex) + ";\n";
linkedVaryings->push_back(LinkedVarying("gl_Position", GL_FLOAT_VEC4, 1, glPositionSemantic, glPositionSemanticIndex, 1)); linkedVaryings->push_back(LinkedVarying("gl_Position", GL_FLOAT_VEC4, 1, glPositionSemantic, glPositionSemanticIndex, 1));
} }
...@@ -589,10 +589,10 @@ bool DynamicHLSL::generateShaderLinkHLSL(InfoLog &infoLog, int registers, const ...@@ -589,10 +589,10 @@ bool DynamicHLSL::generateShaderLinkHLSL(InfoLog &infoLog, int registers, const
"\n" "\n"
" VS_OUTPUT output;\n" " VS_OUTPUT output;\n"
" output.gl_Position = gl_Position;\n" " output.gl_Position = gl_Position;\n"
" output._dx_Position.x = gl_Position.x;\n" " output.dx_Position.x = gl_Position.x;\n"
" output._dx_Position.y = -gl_Position.y;\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.z = (gl_Position.z + gl_Position.w) * 0.5;\n"
" output._dx_Position.w = gl_Position.w;\n"; " output.dx_Position.w = gl_Position.w;\n";
} }
else else
{ {
...@@ -601,10 +601,10 @@ bool DynamicHLSL::generateShaderLinkHLSL(InfoLog &infoLog, int registers, const ...@@ -601,10 +601,10 @@ bool DynamicHLSL::generateShaderLinkHLSL(InfoLog &infoLog, int registers, const
"\n" "\n"
" VS_OUTPUT output;\n" " VS_OUTPUT output;\n"
" output.gl_Position = gl_Position;\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.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.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.z = (gl_Position.z + gl_Position.w) * 0.5;\n"
" output._dx_Position.w = gl_Position.w;\n"; " output.dx_Position.w = gl_Position.w;\n";
} }
if (vertexShader->mUsesPointSize && shaderModel >= 3) if (vertexShader->mUsesPointSize && shaderModel >= 3)
......
...@@ -1944,7 +1944,7 @@ unsigned int Renderer11::getReservedFragmentUniformBuffers() const ...@@ -1944,7 +1944,7 @@ unsigned int Renderer11::getReservedFragmentUniformBuffers() const
unsigned int Renderer11::getReservedVaryings() const 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; return 4;
} }
......
#include "ANGLETest.h" #include "ANGLETest.h"
class GLSLStructTest : public ANGLETest class GLSLTest : public ANGLETest
{ {
protected: protected:
GLSLStructTest() GLSLTest()
{ {
setWindowWidth(128); setWindowWidth(128);
setWindowHeight(128); setWindowHeight(128);
...@@ -17,7 +17,7 @@ protected: ...@@ -17,7 +17,7 @@ protected:
{ {
ANGLETest::SetUp(); ANGLETest::SetUp();
mVertexShaderSource = SHADER_SOURCE mSimpleVSSource = SHADER_SOURCE
( (
attribute vec4 inputAttribute; attribute vec4 inputAttribute;
void main() void main()
...@@ -27,10 +27,10 @@ protected: ...@@ -27,10 +27,10 @@ protected:
); );
} }
std::string mVertexShaderSource; std::string mSimpleVSSource;
}; };
TEST_F(GLSLStructTest, nameless_scoped_structs) TEST_F(GLSLTest, nameless_scoped_structs)
{ {
const std::string fragmentShaderSource = SHADER_SOURCE const std::string fragmentShaderSource = SHADER_SOURCE
( (
...@@ -48,10 +48,10 @@ TEST_F(GLSLStructTest, nameless_scoped_structs) ...@@ -48,10 +48,10 @@ TEST_F(GLSLStructTest, nameless_scoped_structs)
} }
); );
GLuint program = compileProgram(mVertexShaderSource, fragmentShaderSource); GLuint program = compileProgram(mSimpleVSSource, fragmentShaderSource);
EXPECT_NE(0u, program); EXPECT_NE(0u, program);
} }
TEST_F(GLSLStructTest, scoped_structs_order_bug) TEST_F(GLSLTest, scoped_structs_order_bug)
{ {
const std::string fragmentShaderSource = SHADER_SOURCE const std::string fragmentShaderSource = SHADER_SOURCE
( (
...@@ -79,11 +79,11 @@ TEST_F(GLSLStructTest, scoped_structs_order_bug) ...@@ -79,11 +79,11 @@ TEST_F(GLSLStructTest, scoped_structs_order_bug)
} }
); );
GLuint program = compileProgram(mVertexShaderSource, fragmentShaderSource); GLuint program = compileProgram(mSimpleVSSource, fragmentShaderSource);
EXPECT_NE(0u, program); EXPECT_NE(0u, program);
} }
TEST_F(GLSLStructTest, scoped_structs_bug) TEST_F(GLSLTest, scoped_structs_bug)
{ {
const std::string fragmentShaderSource = SHADER_SOURCE const std::string fragmentShaderSource = SHADER_SOURCE
( (
...@@ -111,6 +111,35 @@ TEST_F(GLSLStructTest, scoped_structs_bug) ...@@ -111,6 +111,35 @@ TEST_F(GLSLStructTest, scoped_structs_bug)
} }
); );
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); EXPECT_NE(0u, program);
} }
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