From c64ad299e4dbf8cb8cc5e32d9083018b3c2207dd Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Tue, 18 Jul 2023 12:46:27 +1000 Subject: [PATCH] glsl: fix validation of ES vertex attribs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From OpenGL ES 3.0 spec, page 56: "Binding more than one attribute name to the same location is referred to as aliasing, and is not permitted in OpenGL ES Shading Language 3.00 vertex shaders. LinkProgram will fail when this condition exists. However, aliasing is possible in OpenGL ES Shading Language 1.00 vertex shaders. This will only work if only one of the aliased attributes is active in the executable program, or if no path through the shader consumes more than one attribute of a set of attributes aliased to the same location. A link error can occur if the linker determines that every path through the shader consumes multiple aliased attributes, but implemen- tations are not required to generate an error in this case." So here we make sure to allow the optimisations before validation for earlier ES shader versions. Reviewed-by: Marek Olšák Fixes: 80c001013ce8 ("glsl: do vs attribute validation in NIR linker") Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/9342 Part-of: --- src/compiler/glsl/gl_nir_linker.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/compiler/glsl/gl_nir_linker.c b/src/compiler/glsl/gl_nir_linker.c index 871feea5a76..d9787d79e89 100644 --- a/src/compiler/glsl/gl_nir_linker.c +++ b/src/compiler/glsl/gl_nir_linker.c @@ -1082,10 +1082,11 @@ prelink_lowering(const struct gl_constants *consts, consts->ShaderCompilerOptions[shader->Stage].NirOptions; struct gl_program *prog = shader->Program; - /* ES vertex shaders still have dead varyings but its now safe to remove - * them as validation is now done according to the spec. + /* ES 3.0+ vertex shaders may still have dead varyings but its now safe + * to remove them as validation is now done according to the spec. */ - if (shader_program->IsES && i == MESA_SHADER_VERTEX) + if (shader_program->IsES && shader_program->GLSL_Version >= 300 && + i == MESA_SHADER_VERTEX) remove_dead_varyings_pre_linking(prog->nir); preprocess_shader(consts, exts, prog, shader_program, shader->Stage); @@ -1348,7 +1349,7 @@ gl_nir_link_glsl(const struct gl_constants *consts, * Because of this rule, we don't remove dead attributes before * attribute assignment for vertex shader inputs here. */ - if (!(prog->IsES && i == MESA_SHADER_VERTEX)) + if (!(prog->IsES && prog->GLSL_Version >= 300 && i == MESA_SHADER_VERTEX)) remove_dead_varyings_pre_linking(prog->_LinkedShaders[i]->Program->nir); } }