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

Author: Faith Ekstrand <[email protected]>
Date:   Tue Oct 24 13:43:07 2023 -0500

nir/lower_bit_size: Use b2b for boolean subgroup ops

Without this, we replace vote_ieq(b) with vote_ieq(u2u32(b)) which is
wonky because we're doing a u2u on a 1-bit type. With this, we now
replace it with vote_ieq(b2b32(b)).  For other subgroup ops, we replace
things like *scan[op](b) with *scan[op](b2b32(b)).  For scan ops, this
assumes that b2b1(op(b1b32(x), b2b32(y))) = op(x, y) for all of the ops
iand, ior, and ixor.  This is true on all the back-ends I'm aware of.

Reviewed-by: Daniel Schürmann <[email protected]>
Reviewed-by: Timur Kristóf <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25894>

---

 src/compiler/nir/nir_lower_bit_size.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/compiler/nir/nir_lower_bit_size.c 
b/src/compiler/nir/nir_lower_bit_size.c
index 964d4177c09..14340b0b7d7 100644
--- a/src/compiler/nir/nir_lower_bit_size.c
+++ b/src/compiler/nir/nir_lower_bit_size.c
@@ -148,7 +148,9 @@ lower_intrinsic_instr(nir_builder *b, nir_intrinsic_instr 
*intrin,
       assert(old_bit_size < bit_size);
 
       nir_alu_type type = nir_type_uint;
-      if (nir_intrinsic_has_reduction_op(intrin))
+      if (old_bit_size == 1)
+         type = nir_type_bool;
+      else if (nir_intrinsic_has_reduction_op(intrin))
          type = 
nir_op_infos[nir_intrinsic_reduction_op(intrin)].input_types[0];
 
       b->cursor = nir_before_instr(&intrin->instr);
@@ -205,6 +207,8 @@ lower_intrinsic_instr(nir_builder *b, nir_intrinsic_instr 
*intrin,
       nir_alu_type type = nir_type_uint;
       if (intrin->intrinsic == nir_intrinsic_vote_feq)
          type = nir_type_float;
+      else if (intrin->src[0].ssa->bit_size == 1)
+         type = nir_type_bool;
 
       b->cursor = nir_before_instr(&intrin->instr);
       nir_def *new_src = nir_convert_to_bit_size(b, intrin->src[0].ssa,

Reply via email to