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
diff --git a/src/libANGLE/Program.cpp b/src/libANGLE/Program.cpp
index a506dc8..0ecf1ff 100644
--- a/src/libANGLE/Program.cpp
+++ b/src/libANGLE/Program.cpp
@@ -727,6 +727,11 @@
return NoError();
}
+ if (!linkValidateGlobalNames(context, mInfoLog))
+ {
+ return NoError();
+ }
+
const auto &mergedVaryings = getMergedVaryings(context);
if (!linkValidateTransformFeedback(context, mInfoLog, mergedVaryings, caps))
@@ -2386,6 +2391,36 @@
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)
{
// Gather the linked varyings that are used for transform feedback, they should all exist.