Mesa (master): nir/spirv: Compact vtn_type

Jason Ekstrand jekstrand at kemper.freedesktop.org
Wed Jul 5 22:27:10 UTC 2017


Module: Mesa
Branch: master
Commit: ad4519696d07953c16fcc023220a913cf25d3645
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ad4519696d07953c16fcc023220a913cf25d3645

Author: Jason Ekstrand <jason at jlekstrand.net>
Date:   Thu Jun 29 10:33:36 2017 -0700

nir/spirv: Compact vtn_type

Use an anonymous union of structs to help keep the structure small and
better organized.

Reviewed-by: Connor Abbott <cwabbott0 at gmail.com>

---

 src/compiler/spirv/spirv_to_nir.c |  1 -
 src/compiler/spirv/vtn_private.h  | 64 ++++++++++++++++++++++++---------------
 2 files changed, 39 insertions(+), 26 deletions(-)

diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index c69cb8c8a8..58e316dcd4 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -728,7 +728,6 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
    struct vtn_value *val = vtn_push_value(b, w[1], vtn_value_type_type);
 
    val->type = rzalloc(b, struct vtn_type);
-   val->type->is_builtin = false;
    val->type->val = val;
 
    switch (opcode) {
diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h
index 84d5f51906..3c048fa327 100644
--- a/src/compiler/spirv/vtn_private.h
+++ b/src/compiler/spirv/vtn_private.h
@@ -202,42 +202,56 @@ struct vtn_type {
    /* The value that declares this type.  Used for finding decorations */
    struct vtn_value *val;
 
-   /* for matrices, whether the matrix is stored row-major */
-   bool row_major;
+   union {
+      /* Members for scalar, vector, and array-like types */
+      struct {
+         /* for arrays, the vtn_type for the elements of the array */
+         struct vtn_type *array_element;
 
-   /* for structs, the offset of each member */
-   unsigned *offsets;
+         /* for arrays and matrices, the array stride */
+         unsigned stride;
 
-   /* for structs, whether it was decorated as a "non-SSBO-like" block */
-   bool block;
+         /* for matrices, whether the matrix is stored row-major */
+         bool row_major:1;
 
-   /* for structs, whether it was decorated as an "SSBO-like" block */
-   bool buffer_block;
+         /* Whether this type, or a parent type, has been decorated as a
+          * builtin
+          */
+         bool is_builtin:1;
 
-   /* for structs with block == true, whether this is a builtin block (i.e. a
-    * block that contains only builtins).
-    */
-   bool builtin_block;
+         /* Which built-in to use */
+         SpvBuiltIn builtin;
+      };
 
-   /* Image format for image_load_store type images */
-   unsigned image_format;
+      /* Members for struct types */
+      struct {
+         /* for structures, the vtn_type for each member */
+         struct vtn_type **members;
 
-   /* Access qualifier for storage images */
-   SpvAccessQualifier access_qualifier;
+         /* for structs, the offset of each member */
+         unsigned *offsets;
 
-   /* for arrays and matrices, the array stride */
-   unsigned stride;
+         /* for structs, whether it was decorated as a "non-SSBO-like" block */
+         bool block:1;
 
-   /* for arrays, the vtn_type for the elements of the array */
-   struct vtn_type *array_element;
+         /* for structs, whether it was decorated as an "SSBO-like" block */
+         bool buffer_block:1;
 
-   /* for structures, the vtn_type for each member */
-   struct vtn_type **members;
+         /* for structs with block == true, whether this is a builtin block
+          * (i.e. a block that contains only builtins).
+          */
+         bool builtin_block:1;
+      };
 
-   /* Whether this type, or a parent type, has been decorated as a builtin */
-   bool is_builtin;
+      /* Members for image types */
+      struct {
+         /* Image format for image_load_store type images */
+         unsigned image_format;
 
-   SpvBuiltIn builtin;
+         /* Access qualifier for storage images */
+         SpvAccessQualifier access_qualifier;
+      };
+   };
 };
 
 struct vtn_variable;




More information about the mesa-commit mailing list