spirv, radv, anv: Replace ptr_type with addr_format

Instead of setting the glsl types of the pointers for each resource,
set the nir_address_format, from which we can derive the glsl_type,
and in the future the bit pattern representing a NULL pointer.
Reviewed-by: Jason Ekstrand's avatarJason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Bas Nieuwenhuizen's avatarBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
parent 6bc9cdb1
......@@ -284,11 +284,11 @@ radv_shader_compile_to_nir(struct radv_device *device,
.trinary_minmax = true,
.variable_pointers = true,
},
.ubo_ptr_type = glsl_vector_type(GLSL_TYPE_UINT, 2),
.ssbo_ptr_type = glsl_vector_type(GLSL_TYPE_UINT, 2),
.phys_ssbo_ptr_type = glsl_vector_type(GLSL_TYPE_UINT64, 1),
.push_const_ptr_type = glsl_uint_type(),
.shared_ptr_type = glsl_uint_type(),
.ubo_addr_format = nir_address_format_32bit_index_offset,
.ssbo_addr_format = nir_address_format_32bit_index_offset,
.phys_ssbo_addr_format = nir_address_format_64bit_global,
.push_const_addr_format = nir_address_format_logical,
.shared_addr_format = nir_address_format_32bit_offset,
};
entry_point = spirv_to_nir(spirv, module->size / 4,
spec_entries, num_spec_entries,
......
......@@ -72,14 +72,14 @@ struct spirv_to_nir_options {
struct spirv_supported_capabilities caps;
/* Storage types for various kinds of pointers. */
const struct glsl_type *ubo_ptr_type;
const struct glsl_type *ssbo_ptr_type;
const struct glsl_type *phys_ssbo_ptr_type;
const struct glsl_type *push_const_ptr_type;
const struct glsl_type *shared_ptr_type;
const struct glsl_type *global_ptr_type;
const struct glsl_type *temp_ptr_type;
/* Address format for various kinds of pointers. */
nir_address_format ubo_addr_format;
nir_address_format ssbo_addr_format;
nir_address_format phys_ssbo_addr_format;
nir_address_format push_const_addr_format;
nir_address_format shared_addr_format;
nir_address_format global_addr_format;
nir_address_format temp_addr_format;
struct {
void (*func)(void *private_data,
......
......@@ -1364,36 +1364,38 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
/* These can actually be stored to nir_variables and used as SSA
* values so they need a real glsl_type.
*/
nir_address_format addr_format = nir_address_format_logical;
switch (storage_class) {
case SpvStorageClassUniform:
val->type->type = b->options->ubo_ptr_type;
addr_format = b->options->ubo_addr_format;
break;
case SpvStorageClassStorageBuffer:
val->type->type = b->options->ssbo_ptr_type;
addr_format = b->options->ssbo_addr_format;
break;
case SpvStorageClassPhysicalStorageBufferEXT:
val->type->type = b->options->phys_ssbo_ptr_type;
addr_format = b->options->phys_ssbo_addr_format;
break;
case SpvStorageClassPushConstant:
val->type->type = b->options->push_const_ptr_type;
addr_format = b->options->push_const_addr_format;
break;
case SpvStorageClassWorkgroup:
val->type->type = b->options->shared_ptr_type;
addr_format = b->options->shared_addr_format;
break;
case SpvStorageClassCrossWorkgroup:
val->type->type = b->options->global_ptr_type;
addr_format = b->options->global_addr_format;
break;
case SpvStorageClassFunction:
if (b->physical_ptrs)
val->type->type = b->options->temp_ptr_type;
addr_format = b->options->temp_addr_format;
break;
default:
/* In this case, no variable pointers are allowed so all deref
* chains are complete back to the variable and it doesn't matter
* what type gets used so we leave it NULL.
* what type gets.
*/
break;
}
val->type->type = nir_address_format_to_glsl_type(addr_format);
} else {
vtn_fail_if(val->type->storage_class != storage_class,
"The storage classes of an OpTypePointer and any "
......@@ -3774,18 +3776,18 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
"AddressingModelPhysical32 only supported for kernels");
b->shader->info.cs.ptr_size = 32;
b->physical_ptrs = true;
b->options->shared_ptr_type = glsl_uint_type();
b->options->global_ptr_type = glsl_uint_type();
b->options->temp_ptr_type = glsl_uint_type();
b->options->shared_addr_format = nir_address_format_32bit_global;
b->options->global_addr_format = nir_address_format_32bit_global;
b->options->temp_addr_format = nir_address_format_32bit_global;
break;
case SpvAddressingModelPhysical64:
vtn_fail_if(b->shader->info.stage != MESA_SHADER_KERNEL,
"AddressingModelPhysical64 only supported for kernels");
b->shader->info.cs.ptr_size = 64;
b->physical_ptrs = true;
b->options->shared_ptr_type = glsl_uint64_t_type();
b->options->global_ptr_type = glsl_uint64_t_type();
b->options->temp_ptr_type = glsl_uint64_t_type();
b->options->shared_addr_format = nir_address_format_64bit_global;
b->options->global_addr_format = nir_address_format_64bit_global;
b->options->temp_addr_format = nir_address_format_64bit_global;
break;
case SpvAddressingModelLogical:
vtn_fail_if(b->shader->info.stage >= MESA_SHADER_STAGES,
......
......@@ -99,14 +99,18 @@ vk_desc_type_for_mode(struct vtn_builder *b, enum vtn_variable_mode mode)
static const struct glsl_type *
vtn_ptr_type_for_mode(struct vtn_builder *b, enum vtn_variable_mode mode)
{
nir_address_format addr_format;
switch (mode) {
case vtn_variable_mode_ubo:
return b->options->ubo_ptr_type;
addr_format = b->options->ubo_addr_format;
break;
case vtn_variable_mode_ssbo:
return b->options->ssbo_ptr_type;
addr_format = b->options->ssbo_addr_format;
break;
default:
vtn_fail("Invalid mode for vulkan_resource_index");
}
return nir_address_format_to_glsl_type(addr_format);
}
static nir_ssa_def *
......
......@@ -134,8 +134,6 @@ anv_shader_compile_to_nir(struct anv_device *device,
}
}
nir_address_format ssbo_addr_format =
anv_nir_ssbo_addr_format(pdevice, device->robust_buffer_access);
struct spirv_to_nir_options spirv_options = {
.lower_workgroup_access_to_offsets = true,
.caps = {
......@@ -172,11 +170,17 @@ anv_shader_compile_to_nir(struct anv_device *device,
.transform_feedback = pdevice->info.gen >= 8,
.variable_pointers = true,
},
.ubo_ptr_type = glsl_vector_type(GLSL_TYPE_UINT, 2),
.ssbo_ptr_type = nir_address_format_to_glsl_type(ssbo_addr_format),
.phys_ssbo_ptr_type = glsl_vector_type(GLSL_TYPE_UINT64, 1),
.push_const_ptr_type = glsl_uint_type(),
.shared_ptr_type = glsl_uint_type(),
.ubo_addr_format = nir_address_format_32bit_index_offset,
.ssbo_addr_format =
anv_nir_ssbo_addr_format(pdevice, device->robust_buffer_access),
.phys_ssbo_addr_format = nir_address_format_64bit_global,
.push_const_addr_format = nir_address_format_logical,
/* TODO: Consider changing this to an address format that has the NULL
* pointer equals to 0. That might be a better format to play nice
* with certain code / code generators.
*/
.shared_addr_format = nir_address_format_32bit_offset,
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment