Mesa (main): nir: abort io info gathering if location is not set or is a temp value

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon May 16 04:43:32 UTC 2022


Module: Mesa
Branch: main
Commit: 99ab53061736d0f7559d0bd2f3ff0d4d1aa8e192
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=99ab53061736d0f7559d0bd2f3ff0d4d1aa8e192

Author: Timothy Arceri <tarceri at itsqueeze.com>
Date:   Wed Mar 16 16:58:02 2022 +1100

nir: abort io info gathering if location is not set or is a temp value

Unlike spirv glsl varyings might not have explicit locations set.
nir_shader_gather_info() was once only called at the end of linking
but these days it even gets called in NIR optimisation loops via
nir_opt_phi_precision.

In the following patches we implement a NIR version of the GLSL
varying linker which means we will have varyings with no location
set when nir_shader_gather_info() gets called the first few times,
and temp values set only for the purpose of removing unmatched
varyings between shaders for some calls after that.

Here rather than asserting we simply abort the io info gathering,
when we hit these values.

Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15731>

---

 src/compiler/nir/nir_gather_info.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/compiler/nir/nir_gather_info.c b/src/compiler/nir/nir_gather_info.c
index f0e0262e58f..d372ac49ad6 100644
--- a/src/compiler/nir/nir_gather_info.c
+++ b/src/compiler/nir/nir_gather_info.c
@@ -79,7 +79,9 @@ set_io_mask(nir_shader *shader, nir_variable *var, int offset, int len,
             nir_deref_instr *deref, bool is_output_read)
 {
    for (int i = 0; i < len; i++) {
-      assert(var->data.location != -1);
+      /* Varyings might not have been assigned values yet so abort. */
+      if (var->data.location == -1)
+         return;
 
       int idx = var->data.location + offset + i;
       bool is_patch_generic = var->data.patch &&
@@ -90,11 +92,17 @@ set_io_mask(nir_shader *shader, nir_variable *var, int offset, int len,
       uint64_t bitfield;
 
       if (is_patch_generic) {
-         assert(idx >= VARYING_SLOT_PATCH0 && idx < VARYING_SLOT_TESS_MAX);
+         /* Varyings might still have temp locations so abort */
+         if (idx < VARYING_SLOT_PATCH0 || idx >= VARYING_SLOT_TESS_MAX)
+            return;
+
          bitfield = BITFIELD64_BIT(idx - VARYING_SLOT_PATCH0);
       }
       else {
-         assert(idx < VARYING_SLOT_MAX);
+         /* Varyings might still have temp locations so abort */
+         if (idx >= VARYING_SLOT_MAX)
+            return;
+
          bitfield = BITFIELD64_BIT(idx);
       }
 



More information about the mesa-commit mailing list