Module: Mesa
Branch: staging/23.2
Commit: 79d2996a3f8d95749d2c9e1d26c5d368355ae305
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=79d2996a3f8d95749d2c9e1d26c5d368355ae305

Author: Timothy Arceri <[email protected]>
Date:   Tue Jul 18 12:46:27 2023 +1000

glsl: fix validation of ES vertex attribs

>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 <[email protected]>

Fixes: 80c001013ce8 ("glsl: do vs attribute validation in NIR linker")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/9342
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24205>
(cherry picked from commit c64ad299e4dbf8cb8cc5e32d9083018b3c2207dd)

---

 .pick_status.json                 | 2 +-
 src/compiler/glsl/gl_nir_linker.c | 9 +++++----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 674dab4ac52..615625fad59 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -814,7 +814,7 @@
         "description": "glsl: fix validation of ES vertex attribs",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "80c001013ce83c679a3b9a59e27f9a72b70a45ea",
         "notes": null
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);
       }
    }

Reply via email to