nir/spirv: handle OpConstantComposites with OpUndef members
authorKarol Herbst <kherbst@redhat.com>
Fri, 4 May 2018 14:28:03 +0000 (16:28 +0200)
committerKarol Herbst <kherbst@redhat.com>
Thu, 12 Jul 2018 11:09:00 +0000 (13:09 +0200)
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Signed-off-by: Karol Herbst <kherbst@redhat.com>
src/compiler/spirv/spirv_to_nir.c

index 413fbf481c18c77a7fe5edba514c6cae10aa482b..235003e872a1525e2d331d3c0b2cfa613e13eea7 100644 (file)
@@ -1494,8 +1494,19 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
                   spirv_op_to_string(opcode), elem_count, val->type->length);
 
       nir_constant **elems = ralloc_array(b, nir_constant *, elem_count);
-      for (unsigned i = 0; i < elem_count; i++)
-         elems[i] = vtn_value(b, w[i + 3], vtn_value_type_constant)->constant;
+      for (unsigned i = 0; i < elem_count; i++) {
+         struct vtn_value *val = vtn_untyped_value(b, w[i + 3]);
+
+         if (val->value_type == vtn_value_type_constant) {
+            elems[i] = val->constant;
+         } else {
+            vtn_fail_if(val->value_type != vtn_value_type_undef,
+                        "only constants or undefs allowed for "
+                        "SpvOpConstantComposite");
+            /* to make it easier, just insert a NULL constant for now */
+            elems[i] = vtn_null_constant(b, val->type->type);
+         }
+      }
 
       switch (val->type->base_type) {
       case vtn_base_type_vector: {