spirv: Update vtn_pointer_to/from_ssa to handle deref pointers
Now that pointers can be derefs and derefs just produce SSA values, we can convert any pointer to/from SSA. Acked-by: Rob Clark <robdclark@gmail.com> Acked-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl> Acked-by: Dave Airlie <airlied@redhat.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
parent
d5930c222c
commit
2f9bfd7dd9
|
@ -1503,30 +1503,34 @@ vtn_storage_class_to_mode(struct vtn_builder *b,
|
||||||
nir_ssa_def *
|
nir_ssa_def *
|
||||||
vtn_pointer_to_ssa(struct vtn_builder *b, struct vtn_pointer *ptr)
|
vtn_pointer_to_ssa(struct vtn_builder *b, struct vtn_pointer *ptr)
|
||||||
{
|
{
|
||||||
/* This pointer needs to have a pointer type with actual storage */
|
if (vtn_pointer_uses_ssa_offset(b, ptr)) {
|
||||||
vtn_assert(ptr->ptr_type);
|
/* This pointer needs to have a pointer type with actual storage */
|
||||||
vtn_assert(ptr->ptr_type->type);
|
vtn_assert(ptr->ptr_type);
|
||||||
|
vtn_assert(ptr->ptr_type->type);
|
||||||
|
|
||||||
if (!ptr->offset) {
|
if (!ptr->offset) {
|
||||||
/* If we don't have an offset then we must be a pointer to the variable
|
/* If we don't have an offset then we must be a pointer to the variable
|
||||||
* itself.
|
* itself.
|
||||||
*/
|
*/
|
||||||
vtn_assert(!ptr->offset && !ptr->block_index);
|
vtn_assert(!ptr->offset && !ptr->block_index);
|
||||||
|
|
||||||
struct vtn_access_chain chain = {
|
struct vtn_access_chain chain = {
|
||||||
.length = 0,
|
.length = 0,
|
||||||
};
|
};
|
||||||
ptr = vtn_ssa_offset_pointer_dereference(b, ptr, &chain);
|
ptr = vtn_ssa_offset_pointer_dereference(b, ptr, &chain);
|
||||||
}
|
}
|
||||||
|
|
||||||
vtn_assert(ptr->offset);
|
vtn_assert(ptr->offset);
|
||||||
if (ptr->block_index) {
|
if (ptr->block_index) {
|
||||||
vtn_assert(ptr->mode == vtn_variable_mode_ubo ||
|
vtn_assert(ptr->mode == vtn_variable_mode_ubo ||
|
||||||
ptr->mode == vtn_variable_mode_ssbo);
|
ptr->mode == vtn_variable_mode_ssbo);
|
||||||
return nir_vec2(&b->nb, ptr->block_index, ptr->offset);
|
return nir_vec2(&b->nb, ptr->block_index, ptr->offset);
|
||||||
|
} else {
|
||||||
|
vtn_assert(ptr->mode == vtn_variable_mode_workgroup);
|
||||||
|
return ptr->offset;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
vtn_assert(ptr->mode == vtn_variable_mode_workgroup);
|
return &vtn_pointer_to_deref(b, ptr)->dest.ssa;
|
||||||
return ptr->offset;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1536,28 +1540,35 @@ vtn_pointer_from_ssa(struct vtn_builder *b, nir_ssa_def *ssa,
|
||||||
{
|
{
|
||||||
vtn_assert(ssa->num_components <= 2 && ssa->bit_size == 32);
|
vtn_assert(ssa->num_components <= 2 && ssa->bit_size == 32);
|
||||||
vtn_assert(ptr_type->base_type == vtn_base_type_pointer);
|
vtn_assert(ptr_type->base_type == vtn_base_type_pointer);
|
||||||
vtn_assert(ptr_type->deref->base_type != vtn_base_type_pointer);
|
|
||||||
/* This pointer type needs to have actual storage */
|
struct vtn_type *interface_type = ptr_type->deref;
|
||||||
vtn_assert(ptr_type->type);
|
while (interface_type->base_type == vtn_base_type_array)
|
||||||
|
interface_type = interface_type->array_element;
|
||||||
|
|
||||||
struct vtn_pointer *ptr = rzalloc(b, struct vtn_pointer);
|
struct vtn_pointer *ptr = rzalloc(b, struct vtn_pointer);
|
||||||
|
nir_variable_mode nir_mode;
|
||||||
ptr->mode = vtn_storage_class_to_mode(b, ptr_type->storage_class,
|
ptr->mode = vtn_storage_class_to_mode(b, ptr_type->storage_class,
|
||||||
ptr_type, NULL);
|
interface_type, &nir_mode);
|
||||||
ptr->type = ptr_type->deref;
|
ptr->type = ptr_type->deref;
|
||||||
ptr->ptr_type = ptr_type;
|
ptr->ptr_type = ptr_type;
|
||||||
|
|
||||||
if (ssa->num_components > 1) {
|
if (ptr->mode == vtn_variable_mode_ubo ||
|
||||||
|
ptr->mode == vtn_variable_mode_ssbo) {
|
||||||
|
/* This pointer type needs to have actual storage */
|
||||||
|
vtn_assert(ptr_type->type);
|
||||||
vtn_assert(ssa->num_components == 2);
|
vtn_assert(ssa->num_components == 2);
|
||||||
vtn_assert(ptr->mode == vtn_variable_mode_ubo ||
|
|
||||||
ptr->mode == vtn_variable_mode_ssbo);
|
|
||||||
ptr->block_index = nir_channel(&b->nb, ssa, 0);
|
ptr->block_index = nir_channel(&b->nb, ssa, 0);
|
||||||
ptr->offset = nir_channel(&b->nb, ssa, 1);
|
ptr->offset = nir_channel(&b->nb, ssa, 1);
|
||||||
} else {
|
} else if (ptr->mode == vtn_variable_mode_workgroup ||
|
||||||
|
ptr->mode == vtn_variable_mode_push_constant) {
|
||||||
|
/* This pointer type needs to have actual storage */
|
||||||
|
vtn_assert(ptr_type->type);
|
||||||
vtn_assert(ssa->num_components == 1);
|
vtn_assert(ssa->num_components == 1);
|
||||||
vtn_assert(ptr->mode == vtn_variable_mode_workgroup ||
|
|
||||||
ptr->mode == vtn_variable_mode_push_constant);
|
|
||||||
ptr->block_index = NULL;
|
ptr->block_index = NULL;
|
||||||
ptr->offset = ssa;
|
ptr->offset = ssa;
|
||||||
|
} else {
|
||||||
|
ptr->deref = nir_build_deref_cast(&b->nb, ssa, nir_mode,
|
||||||
|
ptr_type->deref->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
|
|
Loading…
Reference in New Issue