spirv: Reuse helpers in vtn_handle_type()
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Wed, 8 May 2019 20:16:13 +0000 (13:16 -0700)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Mon, 20 May 2019 17:53:38 +0000 (10:53 -0700)
And change vtn_storage_class_to_mode() to accept NULL as
interface_type.  In this case, if we have a SpvStorageClassUniform, we
assume it is uses an ubo_addr_format, like the code being replaced by
the helper.

That assumption is a problem, but no different than the previous
code.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/compiler/spirv/spirv_to_nir.c
src/compiler/spirv/vtn_variables.c

index 7072f8a3fc3c8f2c95ff813227be992f314e20c2..720999b9286597c52b502a6e605f236061a04511 100644 (file)
@@ -1372,38 +1372,10 @@ 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:
-            addr_format = b->options->ubo_addr_format;
-            break;
-         case SpvStorageClassStorageBuffer:
-            addr_format = b->options->ssbo_addr_format;
-            break;
-         case SpvStorageClassPhysicalStorageBufferEXT:
-            addr_format = b->options->phys_ssbo_addr_format;
-            break;
-         case SpvStorageClassPushConstant:
-            addr_format = b->options->push_const_addr_format;
-            break;
-         case SpvStorageClassWorkgroup:
-            addr_format = b->options->shared_addr_format;
-            break;
-         case SpvStorageClassCrossWorkgroup:
-            addr_format = b->options->global_addr_format;
-            break;
-         case SpvStorageClassFunction:
-            if (b->physical_ptrs)
-               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.
-             */
-            break;
-         }
-         val->type->type = nir_address_format_to_glsl_type(addr_format);
+         enum vtn_variable_mode mode = vtn_storage_class_to_mode(
+            b, storage_class, NULL, NULL);
+         val->type->type = nir_address_format_to_glsl_type(
+            vtn_mode_to_address_format(b, mode));
       } else {
          vtn_fail_if(val->type->storage_class != storage_class,
                      "The storage classes of an OpTypePointer and any "
index 198557f2eaf21d2ad7f105fec31bfd8cf927c4d2..50d1d3f4813cfcec145aa9c2116d7423f276d04c 100644 (file)
@@ -1723,7 +1723,8 @@ vtn_storage_class_to_mode(struct vtn_builder *b,
    nir_variable_mode nir_mode;
    switch (class) {
    case SpvStorageClassUniform:
-      if (interface_type->block) {
+      /* Assume it's an UBO if we lack the interface_type. */
+      if (!interface_type || interface_type->block) {
          mode = vtn_variable_mode_ubo;
          nir_mode = nir_var_mem_ubo;
       } else if (interface_type->buffer_block) {