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;
- /* for matrices, whether the matrix is stored row-major */
- bool row_major;
+ /* Specifies the length of complex types. */
+ unsigned length;
- /* for structs, the offset of each member */
- unsigned *offsets;
+ /* for arrays, matrices and pointers, the array stride */
+ unsigned stride;
- /* for structs, whether it was decorated as a "non-SSBO-like" block */
- bool block;
+ 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, whether it was decorated as an "SSBO-like" block */
- bool buffer_block;
+ /* for matrices, whether the matrix is stored row-major */
+ bool row_major:1;
- /* for structs with block == true, whether this is a builtin block (i.e. a
- * block that contains only builtins).
- */
- bool builtin_block;
+ /* Whether this type, or a parent type, has been decorated as a
+ * builtin
+ */
+ bool is_builtin:1;
- /* Image format for image_load_store type images */
- unsigned image_format;
+ /* Which built-in to use */
+ SpvBuiltIn builtin;
+ };
- /* Access qualifier for storage images */
- SpvAccessQualifier access_qualifier;
+ /* Members for struct types */
+ struct {
+ /* for structures, the vtn_type for each member */
+ struct vtn_type **members;
- /* for arrays and matrices, the array stride */
- unsigned stride;
+ /* for structs, the offset of each member */
+ unsigned *offsets;
+
+ /* 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;
+ };
+
+ /* Members for pointer types */
+ struct {
+ /* For pointers, the vtn_type for dereferenced type */
+ struct vtn_type *deref;
- /* Whether this type, or a parent type, has been decorated as a builtin */
- bool is_builtin;
+ /* 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;
- SpvBuiltIn builtin;
+ /* Return type for functions */
+ struct vtn_type *return_type;
+ };
+ };
};
struct vtn_variable;
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
/** The dereferenced type of this pointer */
struct vtn_type *type;
- /** The referenced variable */
+ /** 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
+ * instead of an access chain.
+ */
struct vtn_variable *var;
/** An access chain describing how to get from var to the referenced data
*
- * This field may be NULL if the pointer references the entire variable.
+ * This field may be NULL if the pointer references the entire variable or
+ * if a (block_index, offset) pair is used instead of an access chain.
*/
struct vtn_access_chain *chain;
+
+ /** A (block_index, offset) pair representing a UBO or SSBO position. */
+ struct nir_ssa_def *block_index;
+ 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;
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)
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)
{
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);