spirv: Rename vtn_pointer::ptr_type to vtn_pointer::type

Now there's a single vtn_type associated with a vtn_pointer, so
discard the qualifier.

After this and previous changes, here's a summary of where/what types
are:

```
struct vtn_pointer *p;
p->type;           // type of this pointer
p->deref;          // NIR deref of this pointer (unchanged)
p->type->pointed;  // type of the object pointed by this pointer
```

Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31069>
This commit is contained in:
Caio Oliveira 2024-09-06 11:24:04 -07:00 committed by Marge Bot
parent e9ba715710
commit c20552678a
5 changed files with 46 additions and 46 deletions

View file

@ -555,9 +555,9 @@ vtn_ssa_value(struct vtn_builder *b, uint32_t value_id)
return val->ssa;
case vtn_value_type_pointer:
vtn_assert(val->pointer->ptr_type && val->pointer->ptr_type->type);
vtn_assert(val->pointer->type && val->pointer->type->type);
struct vtn_ssa_value *ssa =
vtn_create_ssa_value(b, val->pointer->ptr_type->type);
vtn_create_ssa_value(b, val->pointer->type->type);
ssa->def = vtn_pointer_to_ssa(b, val->pointer);
return ssa;
@ -7313,8 +7313,8 @@ vtn_print_value(struct vtn_builder *b, struct vtn_value *val, FILE *f)
case vtn_value_type_pointer: {
struct vtn_pointer *pointer = val->pointer;
fprintf(f, " ptr_type=%u", vtn_id_for_type(b, pointer->ptr_type));
fprintf(f, " (pointed-)type=%u", vtn_id_for_type(b, val->pointer->ptr_type->pointed));
fprintf(f, " ptr_type=%u", vtn_id_for_type(b, pointer->type));
fprintf(f, " (pointed-)type=%u", vtn_id_for_type(b, val->pointer->type->pointed));
if (pointer->deref) {
fprintf(f, "\n NIR: ");

View file

@ -375,7 +375,7 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,
nir_ior(nb, signed_zero, nir_ffract(nb, abs)));
struct vtn_pointer *i_ptr = vtn_value(b, w[6], vtn_value_type_pointer)->pointer;
struct vtn_ssa_value *whole = vtn_create_ssa_value(b, i_ptr->ptr_type->pointed->type);
struct vtn_ssa_value *whole = vtn_create_ssa_value(b, i_ptr->type->pointed->type);
whole->def = nir_ior(nb, signed_zero, nir_ffloor(nb, abs));
vtn_variable_store(b, whole, i_ptr, 0);
break;
@ -614,7 +614,7 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,
dest->def = nir_frexp_sig(nb, src[0]);
struct vtn_pointer *i_ptr = vtn_value(b, w[6], vtn_value_type_pointer)->pointer;
struct vtn_ssa_value *exp = vtn_create_ssa_value(b, i_ptr->ptr_type->pointed->type);
struct vtn_ssa_value *exp = vtn_create_ssa_value(b, i_ptr->type->pointed->type);
exp->def = nir_frexp_exp(nb, src[0]);
vtn_variable_store(b, exp, i_ptr, 0);
break;

View file

@ -657,7 +657,7 @@ _handle_v_load_store(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode,
unsigned alignment = vec_aligned ? glsl_get_cl_alignment(type->type) :
glsl_get_bit_size(type->type) / 8;
enum glsl_base_type ptr_base_type =
glsl_get_base_type(p->pointer->ptr_type->pointed->type);
glsl_get_base_type(p->pointer->type->pointed->type);
if (base_type != ptr_base_type) {
vtn_fail_if(ptr_base_type != GLSL_TYPE_FLOAT16 ||
(base_type != GLSL_TYPE_FLOAT &&

View file

@ -484,7 +484,7 @@ struct vtn_pointer {
enum vtn_variable_mode mode;
/** The pointer type of this pointer */
struct vtn_type *ptr_type;
struct vtn_type *type;
/** The referenced variable, if known
*

View file

@ -339,7 +339,7 @@ vtn_pointer_dereference(struct vtn_builder *b,
struct vtn_pointer *base,
struct vtn_access_chain *deref_chain)
{
struct vtn_type *type = base->ptr_type->pointed;
struct vtn_type *type = base->type->pointed;
enum gl_access_qualifier access = base->access | deref_chain->access;
unsigned idx = 0;
@ -410,7 +410,7 @@ vtn_pointer_dereference(struct vtn_builder *b,
}
if (!block_index) {
vtn_assert(base->var && base->ptr_type->pointed);
vtn_assert(base->var && base->type->pointed);
block_index = vtn_variable_resource_index(b, base->var, desc_arr_idx);
} else if (desc_arr_idx) {
block_index = vtn_resource_reindex(b, base->mode,
@ -423,7 +423,7 @@ vtn_pointer_dereference(struct vtn_builder *b,
* will dereference deeper.
*/
struct vtn_pointer *ptr = vtn_zalloc(b, struct vtn_pointer);
ptr->ptr_type = vtn_create_internal_pointer_type(b, base->ptr_type, type);
ptr->type = vtn_create_internal_pointer_type(b, base->type, type);
ptr->mode = base->mode;
ptr->block_index = block_index;
ptr->access = access;
@ -445,7 +445,7 @@ vtn_pointer_dereference(struct vtn_builder *b,
tail = nir_build_deref_cast(&b->nb, desc, nir_mode,
vtn_type_get_nir_type(b, type, base->mode),
base->ptr_type->stride);
base->type->stride);
tail->cast.align_mul = align;
tail->cast.align_offset = 0;
@ -456,16 +456,16 @@ vtn_pointer_dereference(struct vtn_builder *b,
*/
tail = nir_build_deref_cast(&b->nb, nir_load_shader_record_ptr(&b->nb),
nir_var_mem_constant,
vtn_type_get_nir_type(b, base->ptr_type->pointed,
vtn_type_get_nir_type(b, base->type->pointed,
base->mode),
0 /* ptr_as_array stride */);
} else {
assert(base->var && base->var->var);
tail = nir_build_deref_var(&b->nb, base->var->var);
if (base->ptr_type && base->ptr_type->type) {
if (base->type && base->type->type) {
tail->def.num_components =
glsl_get_vector_elements(base->ptr_type->type);
tail->def.bit_size = glsl_get_bit_size(base->ptr_type->type);
glsl_get_vector_elements(base->type->type);
tail->def.bit_size = glsl_get_bit_size(base->type->type);
}
}
@ -474,7 +474,7 @@ vtn_pointer_dereference(struct vtn_builder *b,
* able to delete that cast eventually.
*/
tail = nir_build_deref_cast(&b->nb, &tail->def, tail->modes,
tail->type, base->ptr_type->stride);
tail->type, base->type->stride);
nir_def *index = vtn_access_link_as_ssa(b, deref_chain->link[0], 1,
tail->def.bit_size);
@ -508,7 +508,7 @@ vtn_pointer_dereference(struct vtn_builder *b,
}
struct vtn_pointer *ptr = vtn_zalloc(b, struct vtn_pointer);
ptr->ptr_type = vtn_create_internal_pointer_type(b, base->ptr_type, type);
ptr->type = vtn_create_internal_pointer_type(b, base->type, type);
ptr->mode = base->mode;
ptr->var = base->var;
ptr->deref = tail;
@ -682,13 +682,13 @@ _vtn_variable_load_store(struct vtn_builder *b, bool load,
{
if (ptr->mode == vtn_variable_mode_uniform ||
ptr->mode == vtn_variable_mode_image) {
if (ptr->ptr_type->pointed->base_type == vtn_base_type_image ||
ptr->ptr_type->pointed->base_type == vtn_base_type_sampler) {
if (ptr->type->pointed->base_type == vtn_base_type_image ||
ptr->type->pointed->base_type == vtn_base_type_sampler) {
/* See also our handling of OpTypeSampler and OpTypeImage */
vtn_assert(load);
(*inout)->def = vtn_pointer_to_ssa(b, ptr);
return;
} else if (ptr->ptr_type->pointed->base_type == vtn_base_type_sampled_image) {
} else if (ptr->type->pointed->base_type == vtn_base_type_sampled_image) {
/* See also our handling of OpTypeSampledImage */
vtn_assert(load);
struct vtn_sampled_image si = {
@ -704,7 +704,7 @@ _vtn_variable_load_store(struct vtn_builder *b, bool load,
return;
}
enum glsl_base_type base_type = glsl_get_base_type(ptr->ptr_type->pointed->type);
enum glsl_base_type base_type = glsl_get_base_type(ptr->type->pointed->type);
switch (base_type) {
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
@ -719,7 +719,7 @@ _vtn_variable_load_store(struct vtn_builder *b, bool load,
case GLSL_TYPE_BOOL:
case GLSL_TYPE_DOUBLE:
case GLSL_TYPE_COOPERATIVE_MATRIX:
if (glsl_type_is_vector_or_scalar(ptr->ptr_type->pointed->type)) {
if (glsl_type_is_vector_or_scalar(ptr->type->pointed->type)) {
/* We hit a vector or scalar; go ahead and emit the load[s] */
nir_deref_instr *deref = vtn_pointer_to_deref(b, ptr);
if (vtn_mode_is_cross_invocation(b, ptr->mode)) {
@ -734,16 +734,16 @@ _vtn_variable_load_store(struct vtn_builder *b, bool load,
*/
if (load) {
(*inout)->def = nir_load_deref_with_access(&b->nb, deref,
ptr->ptr_type->pointed->access | access);
ptr->type->pointed->access | access);
} else {
nir_store_deref_with_access(&b->nb, deref, (*inout)->def, ~0,
ptr->ptr_type->pointed->access | access);
ptr->type->pointed->access | access);
}
} else {
if (load) {
*inout = vtn_local_load(b, deref, ptr->ptr_type->pointed->access | access);
*inout = vtn_local_load(b, deref, ptr->type->pointed->access | access);
} else {
vtn_local_store(b, *inout, deref, ptr->ptr_type->pointed->access | access);
vtn_local_store(b, *inout, deref, ptr->type->pointed->access | access);
}
}
return;
@ -753,7 +753,7 @@ _vtn_variable_load_store(struct vtn_builder *b, bool load,
case GLSL_TYPE_INTERFACE:
case GLSL_TYPE_ARRAY:
case GLSL_TYPE_STRUCT: {
unsigned elems = glsl_get_length(ptr->ptr_type->pointed->type);
unsigned elems = glsl_get_length(ptr->type->pointed->type);
struct vtn_access_chain chain = {
.length = 1,
.link = {
@ -763,7 +763,7 @@ _vtn_variable_load_store(struct vtn_builder *b, bool load,
for (unsigned i = 0; i < elems; i++) {
chain.link[0].id = i;
struct vtn_pointer *elem = vtn_pointer_dereference(b, ptr, &chain);
_vtn_variable_load_store(b, load, elem, ptr->ptr_type->pointed->access | access,
_vtn_variable_load_store(b, load, elem, ptr->type->pointed->access | access,
&(*inout)->elems[i]);
}
return;
@ -778,7 +778,7 @@ struct vtn_ssa_value *
vtn_variable_load(struct vtn_builder *b, struct vtn_pointer *src,
enum gl_access_qualifier access)
{
struct vtn_ssa_value *val = vtn_create_ssa_value(b, src->ptr_type->pointed->type);
struct vtn_ssa_value *val = vtn_create_ssa_value(b, src->type->pointed->type);
_vtn_variable_load_store(b, true, src, src->access | access, &val);
return val;
}
@ -795,9 +795,9 @@ _vtn_variable_copy(struct vtn_builder *b, struct vtn_pointer *dest,
struct vtn_pointer *src, enum gl_access_qualifier dest_access,
enum gl_access_qualifier src_access)
{
vtn_assert(glsl_get_bare_type(src->ptr_type->pointed->type) ==
glsl_get_bare_type(dest->ptr_type->pointed->type));
enum glsl_base_type base_type = glsl_get_base_type(src->ptr_type->pointed->type);
vtn_assert(glsl_get_bare_type(src->type->pointed->type) ==
glsl_get_bare_type(dest->type->pointed->type));
enum glsl_base_type base_type = glsl_get_base_type(src->type->pointed->type);
switch (base_type) {
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
@ -829,7 +829,7 @@ _vtn_variable_copy(struct vtn_builder *b, struct vtn_pointer *dest,
{ .mode = vtn_access_mode_literal, },
}
};
unsigned elems = glsl_get_length(src->ptr_type->pointed->type);
unsigned elems = glsl_get_length(src->type->pointed->type);
for (unsigned i = 0; i < elems; i++) {
chain.link[0].id = i;
struct vtn_pointer *src_elem =
@ -1933,7 +1933,7 @@ nir_def *
vtn_pointer_to_ssa(struct vtn_builder *b, struct vtn_pointer *ptr)
{
if ((vtn_pointer_is_external_block(b, ptr) &&
vtn_type_contains_block(b, ptr->ptr_type->pointed) &&
vtn_type_contains_block(b, ptr->type->pointed) &&
ptr->mode != vtn_variable_mode_phys_ssbo) ||
ptr->mode == vtn_variable_mode_accel_struct) {
/* In this case, we're looking for a block index and not an actual
@ -1979,7 +1979,7 @@ vtn_pointer_from_ssa(struct vtn_builder *b, nir_def *ssa,
nir_variable_mode nir_mode;
ptr->mode = vtn_storage_class_to_mode(b, ptr_type->storage_class,
without_array, &nir_mode);
ptr->ptr_type = ptr_type;
ptr->type = ptr_type;
const struct glsl_type *deref_type =
vtn_type_get_nir_type(b, ptr_type->pointed, ptr->mode);
@ -1987,7 +1987,7 @@ vtn_pointer_from_ssa(struct vtn_builder *b, nir_def *ssa,
ptr->mode != vtn_variable_mode_accel_struct) {
ptr->deref = nir_build_deref_cast(&b->nb, ssa, nir_mode,
deref_type, ptr_type->stride);
} else if ((vtn_type_contains_block(b, ptr->ptr_type->pointed) &&
} else if ((vtn_type_contains_block(b, ptr->type->pointed) &&
ptr->mode != vtn_variable_mode_phys_ssbo) ||
ptr->mode == vtn_variable_mode_accel_struct) {
/* This is a pointer to somewhere in an array of blocks, not a
@ -2165,7 +2165,7 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val,
val->pointer = vtn_zalloc(b, struct vtn_pointer);
val->pointer->mode = var->mode;
val->pointer->ptr_type = ptr_type;
val->pointer->type = ptr_type;
val->pointer->var = var;
val->pointer->access = var->type->access;
@ -2746,7 +2746,7 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
access |= ACCESS_NON_UNIFORM;
struct vtn_pointer *ptr = vtn_pointer_dereference(b, base, chain);
ptr->ptr_type = ptr_type;
ptr->type = ptr_type;
ptr->access |= access;
vtn_push_pointer(b, w[2], ptr);
break;
@ -2842,10 +2842,10 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
struct vtn_value *src_val = vtn_untyped_value(b, w[2]);
/* OpStore requires us to actually have a storage type */
vtn_fail_if(dest->ptr_type->pointed->type == NULL,
vtn_fail_if(dest->type->pointed->type == NULL,
"Invalid destination type for OpStore");
if (glsl_get_base_type(dest->ptr_type->pointed->type) == GLSL_TYPE_BOOL &&
if (glsl_get_base_type(dest->type->pointed->type) == GLSL_TYPE_BOOL &&
glsl_get_base_type(src_val->type->type) == GLSL_TYPE_UINT) {
/* Early versions of GLSLang would use uint types for UBOs/SSBOs but
* would then store them to a local variable as bool. Work around
@ -2858,7 +2858,7 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
"OpTypeBool. Doing an implicit conversion to work around "
"the problem.");
struct vtn_ssa_value *bool_ssa =
vtn_create_ssa_value(b, dest->ptr_type->pointed->type);
vtn_create_ssa_value(b, dest->type->pointed->type);
bool_ssa->def = nir_i2b(&b->nb, vtn_ssa_value(b, w[2])->def);
vtn_variable_store(b, bool_ssa, dest, 0);
break;
@ -2883,10 +2883,10 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
struct vtn_pointer *ptr = vtn_pointer(b, w[3]);
const uint32_t field = w[4];
vtn_fail_if(ptr->ptr_type->pointed->base_type != vtn_base_type_struct,
vtn_fail_if(ptr->type->pointed->base_type != vtn_base_type_struct,
"OpArrayLength must take a pointer to a structure type");
vtn_fail_if(field != ptr->ptr_type->pointed->length - 1 ||
ptr->ptr_type->pointed->members[field]->base_type != vtn_base_type_array,
vtn_fail_if(field != ptr->type->pointed->length - 1 ||
ptr->type->pointed->members[field]->base_type != vtn_base_type_array,
"OpArrayLength must reference the last member of the "
"structure and that must be an array");
@ -2901,7 +2901,7 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
nir_def *array_length =
nir_deref_buffer_array_length(&b->nb, 32,
vtn_pointer_to_ssa(b, array),
.access=ptr->access | ptr->ptr_type->pointed->access);
.access=ptr->access | ptr->type->pointed->access);
vtn_push_nir_ssa(b, w[2], array_length);
break;