nir: fix lowering to scratch with boolean access
authorRhys Perry <pendingchaos02@gmail.com>
Tue, 26 May 2020 17:08:17 +0000 (18:08 +0100)
committerMarge Bot <eric+marge@anholt.net>
Tue, 26 May 2020 18:54:17 +0000 (18:54 +0000)
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Fixes: 18ed82b084c79bf63666f2da22e5d675fb01aa26
   ('nir: Add a pass for selectively lowering variables to scratch space')

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5214>

src/compiler/nir/nir_lower_scratch.c

index aacc2ddca08934786cb6b05b3c8ad97e6160f4c4..0301afd3dcbe06a121be9d20f9af8f88dd86f749 100644 (file)
@@ -57,24 +57,25 @@ lower_load_store(nir_builder *b,
       load->num_components = intrin->num_components;
       load->src[0] = nir_src_for_ssa(offset);
       nir_intrinsic_set_align(load, align, 0);
+      unsigned bit_size = intrin->dest.ssa.bit_size;
       nir_ssa_dest_init(&load->instr, &load->dest,
                         intrin->dest.ssa.num_components,
-                        intrin->dest.ssa.bit_size, NULL);
+                        bit_size == 1 ? 32 : bit_size, NULL);
       nir_builder_instr_insert(b, &load->instr);
 
       nir_ssa_def *value = &load->dest.ssa;
-      if (glsl_type_is_boolean(deref->type))
-         value = nir_b2i32(b, value);
+      if (bit_size == 1)
+         value = nir_b2b1(b, value);
 
       nir_ssa_def_rewrite_uses(&intrin->dest.ssa,
-                               nir_src_for_ssa(&load->dest.ssa));
+                               nir_src_for_ssa(value));
    } else {
       assert(intrin->intrinsic == nir_intrinsic_store_deref);
 
       assert(intrin->src[1].is_ssa);
       nir_ssa_def *value = intrin->src[1].ssa;
-      if (glsl_type_is_boolean(deref->type))
-         value = nir_i2b(b, value);
+      if (value->bit_size == 1)
+         value = nir_b2b32(b, value);
 
       nir_intrinsic_instr *store =
          nir_intrinsic_instr_create(b->shader, nir_intrinsic_store_scratch);