summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCaio Marcelo de Oliveira Filho <[email protected]>2019-05-01 14:15:32 -0700
committerCaio Marcelo de Oliveira Filho <[email protected]>2019-05-20 10:53:38 -0700
commit31a7476335f911ae4fc95b77b6badc83bacacfb3 (patch)
treedc957d0bb9d821b2471d7327bd50d07e07fb4225 /src
parent6bc9cdb1b70cadd628e441cec63b82152c93980e (diff)
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 <[email protected]> Reviewed-by: Bas Nieuwenhuizen <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/amd/vulkan/radv_shader.c10
-rw-r--r--src/compiler/spirv/nir_spirv.h16
-rw-r--r--src/compiler/spirv/spirv_to_nir.c30
-rw-r--r--src/compiler/spirv/vtn_variables.c8
-rw-r--r--src/intel/vulkan/anv_pipeline.c18
5 files changed, 46 insertions, 36 deletions
diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c
index c585bac860f..e16e5bf7676 100644
--- a/src/amd/vulkan/radv_shader.c
+++ b/src/amd/vulkan/radv_shader.c
@@ -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,
diff --git a/src/compiler/spirv/nir_spirv.h b/src/compiler/spirv/nir_spirv.h
index 7a16422b291..1e9e0727b63 100644
--- a/src/compiler/spirv/nir_spirv.h
+++ b/src/compiler/spirv/nir_spirv.h
@@ -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,
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 5e91f8815e8..fdea592e8c2 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -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,
diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c
index 6fbe6900e48..91f7002734e 100644
--- a/src/compiler/spirv/vtn_variables.c
+++ b/src/compiler/spirv/vtn_variables.c
@@ -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 *
diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c
index 4012a6d5a71..e04f1acab4a 100644
--- a/src/intel/vulkan/anv_pipeline.c
+++ b/src/intel/vulkan/anv_pipeline.c
@@ -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,
};