X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fcompiler%2Fspirv%2Fvtn_private.h;h=84584620fc1d55b4b8be56f800240ddc25349ac4;hb=d1992255bb29054fa51763376d125183a9f602f3;hp=4426c957c309228a0fab6eda010a5bb9c3cf71de;hpb=604eda3712879ae21c56336fe890092732afebc6;p=mesa.git diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h index 4426c957c30..84584620fc1 100644 --- a/src/compiler/spirv/vtn_private.h +++ b/src/compiler/spirv/vtn_private.h @@ -196,48 +196,101 @@ 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; - /* 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; @@ -255,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 @@ -284,16 +342,40 @@ struct vtn_pointer { /** 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; @@ -426,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) @@ -438,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) { @@ -477,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);