Commit caa5cda0 by Yuly Novikov Committed by Geoff Lang

Validate uniforms and attributes name conflicts when linking

Uniforms and attribute names have global scope, according to: GLSL 1.017 sections 4.2.6, 4.3.3 and 4.3.4. Thus, they can't have same names. BUG=angleproject:2014 Change-Id: Ibeb064aca877e404a67b9e3e9b57a0cc42e86f9f
parent 6fc8c9b9
...@@ -727,6 +727,11 @@ Error Program::link(const gl::Context *context) ...@@ -727,6 +727,11 @@ Error Program::link(const gl::Context *context)
return NoError(); return NoError();
} }
if (!linkValidateGlobalNames(context, mInfoLog))
{
return NoError();
}
const auto &mergedVaryings = getMergedVaryings(context); const auto &mergedVaryings = getMergedVaryings(context);
if (!linkValidateTransformFeedback(context, mInfoLog, mergedVaryings, caps)) if (!linkValidateTransformFeedback(context, mInfoLog, mergedVaryings, caps))
...@@ -2386,6 +2391,36 @@ bool Program::linkValidateTransformFeedback(const gl::Context *context, ...@@ -2386,6 +2391,36 @@ bool Program::linkValidateTransformFeedback(const gl::Context *context,
return true; return true;
} }
bool Program::linkValidateGlobalNames(const Context *context, InfoLog &infoLog) const
{
const std::vector<sh::Uniform> &vertexUniforms =
mState.mAttachedVertexShader->getUniforms(context);
const std::vector<sh::Uniform> &fragmentUniforms =
mState.mAttachedFragmentShader->getUniforms(context);
const std::vector<sh::Attribute> &attributes =
mState.mAttachedVertexShader->getActiveAttributes(context);
for (const auto &attrib : attributes)
{
for (const auto &uniform : vertexUniforms)
{
if (uniform.name == attrib.name)
{
infoLog << "Name conflicts between a uniform and an attribute: " << attrib.name;
return false;
}
}
for (const auto &uniform : fragmentUniforms)
{
if (uniform.name == attrib.name)
{
infoLog << "Name conflicts between a uniform and an attribute: " << attrib.name;
return false;
}
}
}
return true;
}
void Program::gatherTransformFeedbackVaryings(const Program::MergedVaryings &varyings) void Program::gatherTransformFeedbackVaryings(const Program::MergedVaryings &varyings)
{ {
// Gather the linked varyings that are used for transform feedback, they should all exist. // Gather the linked varyings that are used for transform feedback, they should all exist.
......
...@@ -566,6 +566,7 @@ class Program final : angle::NonCopyable, public LabeledObject ...@@ -566,6 +566,7 @@ class Program final : angle::NonCopyable, public LabeledObject
InfoLog &infoLog, InfoLog &infoLog,
const MergedVaryings &linkedVaryings, const MergedVaryings &linkedVaryings,
const Caps &caps) const; const Caps &caps) const;
bool linkValidateGlobalNames(const Context *context, InfoLog &infoLog) const;
void gatherTransformFeedbackVaryings(const MergedVaryings &varyings); void gatherTransformFeedbackVaryings(const MergedVaryings &varyings);
......
...@@ -1511,6 +1511,28 @@ TEST_P(WebGLCompatibilityTest, BuiltInInvariant) ...@@ -1511,6 +1511,28 @@ TEST_P(WebGLCompatibilityTest, BuiltInInvariant)
EXPECT_EQ(0u, program); EXPECT_EQ(0u, program);
} }
// Tests global namespace conflicts between uniforms and attributes.
// Based on WebGL test conformance/glsl/misc/shaders-with-name-conflicts.html.
TEST_P(WebGLCompatibilityTest, GlobalNamesConflict)
{
const std::string vertexShader =
"attribute vec4 foo;\n"
"void main()\n"
"{\n"
" gl_Position = foo;\n"
"}";
const std::string fragmentShader =
"precision mediump float;\n"
"uniform vec4 foo;\n"
"void main()\n"
"{\n"
" gl_FragColor = foo;\n"
"}";
GLuint program = CompileProgram(vertexShader, fragmentShader);
EXPECT_EQ(0u, program);
}
// Test dimension and image size validation of compressed textures // Test dimension and image size validation of compressed textures
TEST_P(WebGLCompatibilityTest, CompressedTextureS3TC) TEST_P(WebGLCompatibilityTest, CompressedTextureS3TC)
{ {
......
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