Commit 6c79df68 by Mohan Maiya Committed by Commit Bot

Allow attributes and uniforms to have the same name

It is valid for an attribute and a uniform to have the same name as long as they are declared in different stages. Prior to this patch, if any shader stage declares a uniform we disallowed reusing that name for an attribute. From GLSL ES Spec 3.00.6, section 4.3.5: If a uniform variable name is declared in one stage (e.g., a vertex shader) but not in another (e.g., a fragment shader), then that name is still available in the other stage for a different use. This change allows Egginc game to work with ANGLE Bug: angleproject:5497 Tests: angle_end2end_tests - *UniformVariableNameReuseAcrossStages* *GlobalNamesConflict* Change-Id: I8f5657d40a213600d6fb48f63e37e4cdbae120b2 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2608865Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Mohan Maiya <m.maiya@samsung.com>
parent 70d8561d
......@@ -1572,9 +1572,18 @@ bool LinkValidateProgramGlobalNames(InfoLog &infoLog, const HasAttachedShaders &
Shader *vertexShader = programOrPipeline.getAttachedShader(ShaderType::Vertex);
if (vertexShader)
{
// ESSL 3.00.6 section 4.3.5:
// If a uniform variable name is declared in one stage (e.g., a vertex shader)
// but not in another (e.g., a fragment shader), then that name is still
// available in the other stage for a different use.
std::unordered_set<std::string> uniforms;
for (const sh::ShaderVariable &uniform : vertexShader->getUniforms())
{
uniforms.insert(uniform.name);
}
for (const auto &attrib : vertexShader->getActiveAttributes())
{
if (uniformMap.count(attrib.name))
if (uniforms.count(attrib.name))
{
infoLog << "Name conflicts between a uniform and an attribute: " << attrib.name;
return false;
......
......@@ -8808,6 +8808,32 @@ void main() {
EXPECT_NE(0u, program);
}
// Test that reusing the same uniform variable name for different uses across stages links fine.
TEST_P(GLSLTest_ES31, UniformVariableNameReuseAcrossStages)
{
constexpr char kVS[] = R"(#version 310 es
precision mediump float;
in highp vec4 variableWithSameName;
void main() {
gl_Position = variableWithSameName;
}
)";
constexpr char kFS[] = R"(#version 310 es
precision mediump float;
uniform vec4 variableWithSameName;
out vec4 col;
void main() {
col = vec4(variableWithSameName);
}
)";
GLuint program = CompileProgram(kVS, kFS);
EXPECT_NE(0u, program);
}
// Verify that precision match validation of uniforms is performed only if they are statically used
TEST_P(GLSLTest_ES31, UniformPrecisionMatchValidation)
{
......
......@@ -2968,7 +2968,7 @@ void main()
})";
GLuint program = CompileProgram(kVS, kFS);
EXPECT_EQ(0u, program);
EXPECT_NE(0u, program);
}
// Test dimension and image size validation of compressed textures
......
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