zink/spirv: fixup b2i32
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Fri, 19 Jul 2019 15:35:27 +0000 (17:35 +0200)
committerErik Faye-Lund <erik.faye-lund@collabora.com>
Mon, 28 Oct 2019 08:51:47 +0000 (08:51 +0000)
Acked-by: Jordan Justen <jordan.l.justen@intel.com>
src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c

index 0f5e9d4f9f1c978621e1b0766e05261bc5564689..3e4612fe1a99a7eb1e599901c926071ed0dffd56 100644 (file)
@@ -66,6 +66,10 @@ static SpvId
 get_uvec_constant(struct ntv_context *ctx, unsigned bit_size,
                   unsigned num_components, uint32_t value);
 
+static SpvId
+get_ivec_constant(struct ntv_context *ctx, unsigned bit_size,
+                  unsigned num_components, int32_t value);
+
 static SpvId
 emit_unop(struct ntv_context *ctx, SpvOp op, SpvId type, SpvId src);
 
@@ -110,6 +114,13 @@ emit_uint_const(struct ntv_context *ctx, int bit_size, uint32_t value)
    return spirv_builder_const_uint(&ctx->builder, bit_size, value);
 }
 
+static SpvId
+emit_int_const(struct ntv_context *ctx, int bit_size, int32_t value)
+{
+   assert(bit_size == 32);
+   return spirv_builder_const_int(&ctx->builder, bit_size, value);
+}
+
 static SpvId
 get_fvec_type(struct ntv_context *ctx, unsigned bit_size, unsigned num_components)
 {
@@ -719,6 +730,26 @@ get_uvec_constant(struct ntv_context *ctx, unsigned bit_size,
                                         num_components);
 }
 
+static SpvId
+get_ivec_constant(struct ntv_context *ctx, unsigned bit_size,
+                  unsigned num_components, int32_t value)
+{
+   assert(bit_size == 32);
+
+   SpvId result = emit_int_const(ctx, bit_size, value);
+   if (num_components == 1)
+      return result;
+
+   assert(num_components > 1);
+   SpvId components[num_components];
+   for (int i = 0; i < num_components; i++)
+      components[i] = result;
+
+   SpvId type = get_ivec_type(ctx, bit_size, num_components);
+   return spirv_builder_const_composite(&ctx->builder, type, components,
+                                        num_components);
+}
+
 static inline unsigned
 alu_instr_src_components(const nir_alu_instr *instr, unsigned src)
 {
@@ -829,8 +860,8 @@ emit_alu(struct ntv_context *ctx, nir_alu_instr *alu)
    case nir_op_b2i32:
       assert(nir_op_infos[alu->op].num_inputs == 1);
       result = emit_select(ctx, dest_type, src[0],
-                           get_uvec_constant(ctx, 32, num_components, 1),
-                           get_uvec_constant(ctx, 32, num_components, 0));
+                           get_ivec_constant(ctx, 32, num_components, 1),
+                           get_ivec_constant(ctx, 32, num_components, 0));
       break;
 
    case nir_op_b2f32: