Mesa (main): nir_to_tgsi: Avoid swizzling from undefined channels in load_output.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Apr 19 20:44:23 UTC 2022


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

Author: Emma Anholt <emma at anholt.net>
Date:   Mon Apr  4 20:32:47 2022 -0700

nir_to_tgsi: Avoid swizzling from undefined channels in load_output.

virglrenderer emits GLSL referencing all the swizzles, even if the write
mask doesn't contain them.  This is a problem when the output is
TessLevelInner, which has only 2 elements.

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

---

 src/gallium/auxiliary/nir/nir_to_tgsi.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/gallium/auxiliary/nir/nir_to_tgsi.c b/src/gallium/auxiliary/nir/nir_to_tgsi.c
index d9ed3f0aeea..8275dc11b28 100644
--- a/src/gallium/auxiliary/nir/nir_to_tgsi.c
+++ b/src/gallium/auxiliary/nir/nir_to_tgsi.c
@@ -2315,10 +2315,24 @@ ntt_emit_load_output(struct ntt_compile *c, nir_intrinsic_instr *instr)
       out = ntt_ureg_dst_indirect(c, out, instr->src[0]);
    }
 
+   struct ureg_dst dst = ntt_get_dest(c, &instr->dest);
+   struct ureg_src out_src = ureg_src(out);
+
+   /* Don't swizzling unavailable channels of the output in the writemasked-out
+    * components. Avoids compile failures in virglrenderer with
+    * TESS_LEVEL_INNER.
+    */
+   int fill_channel = ffs(dst.WriteMask) - 1;
+   uint8_t swizzles[4] = { 0, 1, 2, 3 };
+   for (int i = 0; i < 4; i++)
+      if (!(dst.WriteMask & (1 << i)))
+         swizzles[i] = fill_channel;
+   out_src = ureg_swizzle(out_src, swizzles[0], swizzles[1], swizzles[2], swizzles[3]);
+
    if (semantics.fb_fetch_output)
-      ntt_FBFETCH(c, ntt_get_dest(c, &instr->dest), ureg_src(out));
+      ntt_FBFETCH(c, dst, out_src);
    else
-      ntt_MOV(c, ntt_get_dest(c, &instr->dest), ureg_src(out));
+      ntt_MOV(c, dst, out_src);
 }
 
 static void



More information about the mesa-commit mailing list