meson: Add build Intel "anv" vulkan driver
[mesa.git] / src / compiler / spirv / vtn_private.h
index 3c048fa327d01468a619cdf57c9507ac7f37e059..84584620fc1d55b4b8be56f800240ddc25349ac4 100644 (file)
@@ -196,21 +196,39 @@ struct vtn_ssa_value {
    const struct glsl_type *type;
 };
 
+enum vtn_base_type {
+   vtn_base_type_void,
+   vtn_base_type_scalar,
+   vtn_base_type_vector,
+   vtn_base_type_matrix,
+   vtn_base_type_array,
+   vtn_base_type_struct,
+   vtn_base_type_pointer,
+   vtn_base_type_image,
+   vtn_base_type_sampler,
+   vtn_base_type_function,
+};
+
 struct vtn_type {
+   enum vtn_base_type base_type;
+
    const struct glsl_type *type;
 
    /* The value that declares this type.  Used for finding decorations */
    struct vtn_value *val;
 
+   /* Specifies the length of complex types. */
+   unsigned length;
+
+   /* for arrays, matrices and pointers, the array stride */
+   unsigned stride;
+
    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 arrays and matrices, the array stride */
-         unsigned stride;
-
          /* for matrices, whether the matrix is stored row-major */
          bool row_major:1;
 
@@ -243,14 +261,35 @@ struct vtn_type {
          bool builtin_block:1;
       };
 
+      /* Members for pointer types */
+      struct {
+         /* For pointers, the vtn_type for dereferenced type */
+         struct vtn_type *deref;
+
+         /* Storage class for pointers */
+         SpvStorageClass storage_class;
+      };
+
       /* Members for image types */
       struct {
+         /* For images, indicates whether it's sampled or storage */
+         bool sampled;
+
          /* Image format for image_load_store type images */
          unsigned image_format;
 
          /* Access qualifier for storage images */
          SpvAccessQualifier access_qualifier;
       };
+
+      /* Members for function types */
+      struct {
+         /* For functions, the vtn_type for each parameter */
+         struct vtn_type **params;
+
+         /* Return type for functions */
+         struct vtn_type *return_type;
+      };
    };
 };
 
@@ -269,6 +308,11 @@ struct vtn_access_link {
 struct vtn_access_chain {
    uint32_t length;
 
+   /** Whether or not to treat the base pointer as an array.  This is only
+    * true if this access chain came from an OpPtrAccessChain.
+    */
+   bool ptr_as_array;
+
    /** Struct elements and array offsets.
     *
     * This is an array of 1 so that it can conveniently be created on the
@@ -298,6 +342,14 @@ struct vtn_pointer {
    /** The dereferenced type of this pointer */
    struct vtn_type *type;
 
+   /** The pointer type of this pointer
+    *
+    * This may be NULL for some temporary pointers constructed as part of a
+    * large load, store, or copy.  It MUST be valid for all pointers which are
+    * stored as SPIR-V SSA values.
+    */
+   struct vtn_type *ptr_type;
+
    /** The referenced variable, if known
     *
     * This field may be NULL if the pointer uses a (block_index, offset) pair
@@ -317,6 +369,13 @@ struct vtn_pointer {
    struct nir_ssa_def *offset;
 };
 
+static inline bool
+vtn_pointer_uses_ssa_offset(struct vtn_pointer *ptr)
+{
+   return ptr->mode == vtn_variable_mode_ubo ||
+          ptr->mode == vtn_variable_mode_ssbo;
+}
+
 struct vtn_variable {
    enum vtn_variable_mode mode;
 
@@ -449,6 +508,12 @@ struct vtn_builder {
    bool has_loop_continue;
 };
 
+nir_ssa_def *
+vtn_pointer_to_ssa(struct vtn_builder *b, struct vtn_pointer *ptr);
+struct vtn_pointer *
+vtn_pointer_from_ssa(struct vtn_builder *b, nir_ssa_def *ssa,
+                     struct vtn_type *ptr_type);
+
 static inline struct vtn_value *
 vtn_push_value(struct vtn_builder *b, uint32_t value_id,
                enum vtn_value_type value_type)
@@ -461,6 +526,21 @@ vtn_push_value(struct vtn_builder *b, uint32_t value_id,
    return &b->values[value_id];
 }
 
+static inline struct vtn_value *
+vtn_push_ssa(struct vtn_builder *b, uint32_t value_id,
+             struct vtn_type *type, struct vtn_ssa_value *ssa)
+{
+   struct vtn_value *val;
+   if (type->base_type == vtn_base_type_pointer) {
+      val = vtn_push_value(b, value_id, vtn_value_type_pointer);
+      val->pointer = vtn_pointer_from_ssa(b, ssa->def, type);
+   } else {
+      val = vtn_push_value(b, value_id, vtn_value_type_ssa);
+      val->ssa = ssa;
+   }
+   return val;
+}
+
 static inline struct vtn_value *
 vtn_untyped_value(struct vtn_builder *b, uint32_t value_id)
 {
@@ -500,7 +580,8 @@ nir_ssa_def *vtn_vector_insert_dynamic(struct vtn_builder *b, nir_ssa_def *src,
 nir_deref_var *vtn_nir_deref(struct vtn_builder *b, uint32_t id);
 
 struct vtn_pointer *vtn_pointer_for_variable(struct vtn_builder *b,
-                                             struct vtn_variable *var);
+                                             struct vtn_variable *var,
+                                             struct vtn_type *ptr_type);
 
 nir_deref_var *vtn_pointer_to_deref(struct vtn_builder *b,
                                     struct vtn_pointer *ptr);