nir_to_tgsi: Avoid swizzling from undefined channels in load_output.
authorEmma Anholt <emma@anholt.net>
Tue, 5 Apr 2022 03:32:47 +0000 (20:32 -0700)
committerMarge Bot <emma+marge@anholt.net>
Tue, 19 Apr 2022 20:05:41 +0000 (20:05 +0000)
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@itsqueeze.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16043>

src/gallium/auxiliary/nir/nir_to_tgsi.c

index d9ed3f0..8275dc1 100644 (file)
@@ -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