nir/spirv: Handle matrix decorations on arrays of matrices
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 12 Jan 2016 09:04:41 +0000 (01:04 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Tue, 12 Jan 2016 09:04:44 +0000 (01:04 -0800)
Connor's original shallow-copy plan works great except that a couple of the
decorations apply to a matrix which may be some levels down in an array.
We weren't properly unpacking that.  This fixes most of the remaining SSBO
and UBO layout tests.

src/glsl/nir/spirv/spirv_to_nir.c

index edf44f2849dc3b1ad0e3aeab6183d2b49129f936..78d5940a75ec18931d0a31485b8bd2e78b1e531d 100644 (file)
@@ -415,6 +415,23 @@ vtn_type_copy(struct vtn_builder *b, struct vtn_type *src)
    return dest;
 }
 
+static struct vtn_type *
+mutable_matrix_member(struct vtn_builder *b, struct vtn_type *type, int member)
+{
+   type->members[member] = vtn_type_copy(b, type->members[member]);
+   type = type->members[member];
+
+   /* We may have an array of matrices.... Oh, joy! */
+   while (glsl_type_is_array(type->type)) {
+      type->array_element = vtn_type_copy(b, type->array_element);
+      type = type->array_element;
+   }
+
+   assert(glsl_type_is_matrix(type->type));
+
+   return type;
+}
+
 static void
 struct_member_decoration_cb(struct vtn_builder *b,
                             struct vtn_value *val, int member,
@@ -444,8 +461,7 @@ struct_member_decoration_cb(struct vtn_builder *b,
       ctx->fields[member].location = dec->literals[0];
       break;
    case SpvDecorationBuiltIn:
-      ctx->type->members[member] = vtn_type_copy(b,
-                                                 ctx->type->members[member]);
+      ctx->type->members[member] = vtn_type_copy(b, ctx->type->members[member]);
       ctx->type->members[member]->is_builtin = true;
       ctx->type->members[member]->builtin = dec->literals[0];
       ctx->type->builtin_block = true;
@@ -454,12 +470,12 @@ struct_member_decoration_cb(struct vtn_builder *b,
       ctx->type->offsets[member] = dec->literals[0];
       break;
    case SpvDecorationMatrixStride:
-      ctx->type->members[member]->stride = dec->literals[0];
+      mutable_matrix_member(b, ctx->type, member)->stride = dec->literals[0];
       break;
    case SpvDecorationColMajor:
       break; /* Nothing to do here.  Column-major is the default. */
    case SpvDecorationRowMajor:
-      ctx->type->members[member]->row_major = true;
+      mutable_matrix_member(b, ctx->type, member)->row_major = true;
       break;
    default:
       unreachable("Unhandled member decoration");