Commit 96509e47 by Jamie Madill

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/201468Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarNicolas Capens <nicolascapens@chromium.org>
parent d7e7d735
......@@ -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++)
{
......
#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);
}
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