zink/spirv: support loading bool constants
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Wed, 30 Oct 2019 14:37:42 +0000 (15:37 +0100)
committerErik Faye-Lund <erik.faye-lund@collabora.com>
Wed, 6 Nov 2019 12:43:14 +0000 (13:43 +0100)
Seems I missed this before; let's add support for this.

src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c

index b72c731dd858769eb05ab037f9d38a2be9124034..47d93efc91071212bdfc6817156c597593297806 100644 (file)
@@ -1058,18 +1058,34 @@ emit_load_const(struct ntv_context *ctx, nir_load_const_instr *load_const)
    SpvId constant;
    if (num_components > 1) {
       SpvId components[num_components];
-      for (int i = 0; i < num_components; i++)
-         components[i] = emit_uint_const(ctx, bit_size,
-                                         load_const->value[i].u32);
+      SpvId type;
+      if (bit_size == 1) {
+         for (int i = 0; i < num_components; i++)
+            components[i] = spirv_builder_const_bool(&ctx->builder,
+                                                     load_const->value[i].b);
 
-      SpvId type = get_uvec_type(ctx, bit_size, num_components);
+         type = get_bvec_type(ctx, num_components);
+      } else {
+         for (int i = 0; i < num_components; i++)
+            components[i] = emit_uint_const(ctx, bit_size,
+                                            load_const->value[i].u32);
+
+         type = get_uvec_type(ctx, bit_size, num_components);
+      }
       constant = spirv_builder_const_composite(&ctx->builder, type,
                                                components, num_components);
    } else {
       assert(num_components == 1);
-      constant = emit_uint_const(ctx, bit_size, load_const->value[0].u32);
+      if (bit_size == 1)
+         constant = spirv_builder_const_bool(&ctx->builder,
+                                             load_const->value[0].b);
+      else
+         constant = emit_uint_const(ctx, bit_size, load_const->value[0].u32);
    }
 
+   if (bit_size == 1)
+      constant = bvec_to_uvec(ctx, constant, num_components);
+
    store_ssa_def_uint(ctx, &load_const->def, constant);
 }