anv: Set alignments on UBO/SSBO root derefs
authorJason Ekstrand <jason@jlekstrand.net>
Fri, 28 Aug 2020 20:42:45 +0000 (15:42 -0500)
committerMarge Bot <eric+marge@anholt.net>
Thu, 3 Sep 2020 18:02:51 +0000 (18:02 +0000)
This doesn't really do anything for us today.  One day, I suppose we
could use it to do something with wide loads with non-uniform offsets.
The big reason to do this is to get better testing to make sure that NIR
doesn't blow up on the deref paths.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6472>

src/intel/vulkan/anv_device.c
src/intel/vulkan/anv_nir_apply_pipeline_layout.c
src/intel/vulkan/anv_private.h

index 789913d57b88cd1cff6a4fd4f7d1a189ad8fad7f..7cf8667420f9f4828f4dca5026aa5ba769a92779 100644 (file)
@@ -1587,7 +1587,7 @@ void anv_GetPhysicalDeviceProperties(
        */
       .minTexelBufferOffsetAlignment            = 16,
       .minUniformBufferOffsetAlignment          = ANV_UBO_ALIGNMENT,
-      .minStorageBufferOffsetAlignment          = 4,
+      .minStorageBufferOffsetAlignment          = ANV_SSBO_ALIGNMENT,
       .minTexelOffset                           = -8,
       .maxTexelOffset                           = 7,
       .minTexelGatherOffset                     = -32,
index 882d7cb6456900a20a6cac2fdf17b00a0753a117..4884ba325cdfb16d49b429447e9f9175dfe37f1b 100644 (file)
@@ -552,6 +552,31 @@ lower_load_vulkan_descriptor(nir_intrinsic_instr *intrin,
 
    const VkDescriptorType desc_type = nir_intrinsic_desc_type(intrin);
 
+   assert(intrin->dest.is_ssa);
+   nir_foreach_use(src, &intrin->dest.ssa) {
+      if (src->parent_instr->type != nir_instr_type_deref)
+         continue;
+
+      nir_deref_instr *cast = nir_instr_as_deref(src->parent_instr);
+      assert(cast->deref_type == nir_deref_type_cast);
+      switch (desc_type) {
+      case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
+      case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
+         cast->cast.align_mul = ANV_UBO_ALIGNMENT;
+         cast->cast.align_offset = 0;
+         break;
+
+      case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
+      case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
+         cast->cast.align_mul = ANV_SSBO_ALIGNMENT;
+         cast->cast.align_offset = 0;
+         break;
+
+      default:
+         break;
+      }
+   }
+
    assert(intrin->src[0].is_ssa);
    nir_ssa_def *index = intrin->src[0].ssa;
 
index 4787243ee7948e19cbacaf9eb431b85c15a34130..48283435a210c5dab302aa8d38ae0e263732353f 100644 (file)
@@ -181,6 +181,7 @@ struct gen_perf_query_result;
  * GEM object.
  */
 #define ANV_UBO_ALIGNMENT 64
+#define ANV_SSBO_ALIGNMENT 4
 #define ANV_SSBO_BOUNDS_CHECK_ALIGNMENT 4
 #define MAX_VIEWS_FOR_PRIMITIVE_REPLICATION 16