spirv, radv, anv: Replace ptr_type with addr_format
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Wed, 1 May 2019 21:15:32 +0000 (14:15 -0700)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Mon, 20 May 2019 17:53:38 +0000 (10:53 -0700)
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 <jason@jlekstrand.net>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/vulkan/radv_shader.c
src/compiler/spirv/nir_spirv.h
src/compiler/spirv/spirv_to_nir.c
src/compiler/spirv/vtn_variables.c
src/intel/vulkan/anv_pipeline.c

index c585bac860f03784a5f87d81947e782d8e6e44ca..e16e5bf7676b119977c49b3b5ea13e30f40003f6 100644 (file)
@@ -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,
index 7a16422b291e43b86930b06e596f70a7109e0053..1e9e0727b63bb8ff3d570be4a16c8e869ce57df5 100644 (file)
@@ -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,
index 5e91f8815e8140671967670a347255701e056673..fdea592e8c2dd49817491ce05b9f8f2b23a10c7d 100644 (file)
@@ -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,
index 6fbe6900e484dcff5f56451c10d0beb404a686ad..91f7002734e49b79a36ae5e0de23629d26de37df 100644 (file)
@@ -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 *
index 4012a6d5a71098dc601f18d0d45bf94056910f55..e04f1acab4a78783d04bf88c0d460f902cdf25e1 100644 (file)
@@ -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,
    };