diff options
author | Jamie Madill <jmadill@chromium.org> | 2014-05-29 14:33:27 -0400 |
---|---|---|
committer | Jamie Madill <jmadill@chromium.org> | 2014-06-02 14:26:11 +0000 |
commit | 96509e47ecd94f8992d7a737dbe011050e4f0783 (patch) | |
tree | e1e3bacb43ae9f9f021b965ff9f8e2837c1051cf | |
parent | d7e7d735ec75a6b0ff855447b20691c7fbb6c97e (diff) | |
download | angle-96509e47ecd94f8992d7a737dbe011050e4f0783.tar.gz |
Fix edge case scoped structures name conflict.
Structures with names ending in "_#" such as "_0" could conflict
with the internally rewritten scoped structures. Fix this by using
a prepending rule instead of appending.
Also includes a test, and fixes a WebGL test in Firefox. (Chrome is
not affected because of the variable hashing step.)
BUG=angle:618
Change-Id: I3d441f1de268b6d7e74a0834b43e889b7bfe578c
Reviewed-on: https://chromium-review.googlesource.com/201468
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Nicolas Capens <nicolascapens@chromium.org>
-rw-r--r-- | src/compiler/translator/OutputHLSL.cpp | 20 | ||||
-rw-r--r-- | tests/angle_tests/GLSLStructTest.cpp | 56 |
2 files changed, 65 insertions, 11 deletions
diff --git a/src/compiler/translator/OutputHLSL.cpp b/src/compiler/translator/OutputHLSL.cpp index 2d7818b6..3cea64fb 100644 --- a/src/compiler/translator/OutputHLSL.cpp +++ b/src/compiler/translator/OutputHLSL.cpp @@ -3537,7 +3537,7 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI return; // Nameless structures don't have constructors } - if (type.getStruct() && mStructNames.find(decorate(name)) != mStructNames.end()) + if (type.getStruct() && mStructNames.find(name) != mStructNames.end()) { return; // Already added } @@ -3547,15 +3547,13 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI ctorType.setPrecision(EbpHigh); ctorType.setQualifier(EvqTemporary); - TString ctorName = type.getStruct() ? decorate(name) : name; - typedef std::vector<TType> ParameterArray; ParameterArray ctorParameters; const TStructure* structure = type.getStruct(); if (structure) { - mStructNames.insert(decorate(name)); + mStructNames.insert(name); const TString &structString = structureString(*structure, false, false); @@ -3596,11 +3594,11 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI if (ctorType.getStruct()) { - constructor += ctorName + " " + ctorName + "_ctor("; + constructor += name + " " + name + "_ctor("; } else // Built-in type { - constructor += typeString(ctorType) + " " + ctorName + "("; + constructor += typeString(ctorType) + " " + name + "("; } for (unsigned int parameter = 0; parameter < ctorParameters.size(); parameter++) @@ -3620,7 +3618,7 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI if (ctorType.getStruct()) { - constructor += " " + ctorName + " structure = {"; + constructor += " " + name + " structure = {"; } else { @@ -3814,10 +3812,10 @@ TString OutputHLSL::scopeString(unsigned int depthLimit) for (unsigned int i = 0; i < mScopeBracket.size() && i < depthLimit; i++) { - string += "_" + str(mScopeBracket[i]); + string += str(mScopeBracket[i]) + "_"; } - return string; + return "ss_" + string; } TString OutputHLSL::scopedStruct(const TString &typeName) @@ -3827,14 +3825,14 @@ TString OutputHLSL::scopedStruct(const TString &typeName) return typeName; } - return typeName + scopeString(mScopeDepth); + return scopeString(mScopeDepth) + typeName; } TString OutputHLSL::structLookup(const TString &typeName) { for (int depth = mScopeDepth; depth >= 0; depth--) { - TString scopedName = decorate(typeName + scopeString(depth)); + TString scopedName = scopeString(depth) + typeName; for (StructNames::iterator structName = mStructNames.begin(); structName != mStructNames.end(); structName++) { diff --git a/tests/angle_tests/GLSLStructTest.cpp b/tests/angle_tests/GLSLStructTest.cpp new file mode 100644 index 00000000..318f41d3 --- /dev/null +++ b/tests/angle_tests/GLSLStructTest.cpp @@ -0,0 +1,56 @@ +#include "ANGLETest.h" + +class GLSLStructTest : public ANGLETest +{ +protected: + GLSLStructTest() + { + setWindowWidth(128); + setWindowHeight(128); + setConfigRedBits(8); + setConfigGreenBits(8); + setConfigBlueBits(8); + setConfigAlphaBits(8); + } +}; + +TEST_F(GLSLStructTest, scoped_structs_bug) +{ + const std::string vertexShaderSource = SHADER_SOURCE + ( + attribute vec4 inputAttribute; + void main() + { + gl_Position = inputAttribute; + } + ); + + const std::string fragmentShaderSource = SHADER_SOURCE + ( + precision mediump float; + + struct T_0 + { + float f; + }; + + void main() + { + gl_FragColor = vec4(1, 0, 0, 1); + + struct T + { + vec2 v; + }; + + T_0 a; + T b; + + gl_FragColor.a += a.f; + gl_FragColor.a += b.v.x; + } + ); + + GLuint program = compileProgram(vertexShaderSource, fragmentShaderSource); + EXPECT_NE(0u, program); +} |