Mesa (master): compiler/spirv: use undefs when extending image coords

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Mar 24 19:53:09 UTC 2021


Module: Mesa
Branch: master
Commit: 674132dee8057c39b31a9184d2d72891285e2ce1
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=674132dee8057c39b31a9184d2d72891285e2ce1

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Fri Mar 19 18:48:53 2021 -0400

compiler/spirv: use undefs when extending image coords

we need 4 components for the nir ops, but swizzling one value to multiple
channels like this gets confusing when trying to debug image ops that don't
require 4 channels

Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9723>

---

 src/compiler/spirv/spirv_to_nir.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 270a3a24eea..8c7e90a4d38 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -3056,28 +3056,28 @@ fill_common_atomic_sources(struct vtn_builder *b, SpvOp opcode,
 }
 
 static nir_ssa_def *
-get_image_coord(struct vtn_builder *b, uint32_t value)
+expand_to_vec4(nir_builder *b, nir_ssa_def *value)
 {
-   nir_ssa_def *coord = vtn_get_nir_ssa(b, value);
-
-   /* The image_load_store intrinsics assume a 4-dim coordinate */
-   unsigned swizzle[4];
-   for (unsigned i = 0; i < 4; i++)
-      swizzle[i] = MIN2(i, coord->num_components - 1);
+   nir_ssa_def *components[4];
+   if (value->num_components == 4)
+      return value;
 
-   return nir_swizzle(&b->nb, coord, swizzle, 4);
+   nir_ssa_def *undef = nir_ssa_undef(b, 1, value->bit_size);
+   for (unsigned i = 0; i < 4; i++) {
+      if (i < value->num_components)
+         components[i] = nir_channel(b, value, i);
+      else
+         components[i] = undef;
+   }
+   return nir_vec(b, components, 4);
 }
 
 static nir_ssa_def *
-expand_to_vec4(nir_builder *b, nir_ssa_def *value)
+get_image_coord(struct vtn_builder *b, uint32_t value)
 {
-   if (value->num_components == 4)
-      return value;
-
-   unsigned swiz[4];
-   for (unsigned i = 0; i < 4; i++)
-      swiz[i] = i < value->num_components ? i : 0;
-   return nir_swizzle(b, value, swiz, 4);
+   nir_ssa_def *coord = vtn_get_nir_ssa(b, value);
+   /* The image_load_store intrinsics assume a 4-dim coordinate */
+   return expand_to_vec4(&b->nb, coord);
 }
 
 static void



More information about the mesa-commit mailing list