dzn: Align descriptor sets in the bindless buffer
authorJesse Natalie <jenatali@microsoft.com>
Mon, 27 Mar 2023 18:08:50 +0000 (11:08 -0700)
committerMarge Bot <emma+marge@anholt.net>
Thu, 6 Apr 2023 22:08:28 +0000 (22:08 +0000)
Fixes: 5d2b4ee4 ("dzn: Allocate descriptor sets in buffers for bindless mode")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22225>

src/microsoft/vulkan/dzn_descriptor_set.c

index e822a46..7a83d77 100644 (file)
@@ -1591,8 +1591,10 @@ dzn_descriptor_set_init(struct dzn_descriptor_set *set,
    if (!reuse) {
       dzn_foreach_pool_type(type) {
          set->heap_offsets[type] = pool->free_offset[type];
+         if (device->bindless)
+            set->heap_offsets[type] = ALIGN(set->heap_offsets[type], 2);
          set->heap_sizes[type] = layout->range_desc_count[type] + variable_descriptor_count[type];
-         set->pool->free_offset[type] += set->heap_sizes[type];
+         set->pool->free_offset[type] = set->heap_offsets[type] + set->heap_sizes[type];
       }
    }
 
@@ -1725,6 +1727,12 @@ dzn_descriptor_pool_create(struct dzn_device *device,
 
    if (device->bindless) {
       if (pool->desc_count[0]) {
+         /* Include extra descriptors so that we can align each allocated descriptor set to a 16-byte boundary */
+         static_assert(D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT / sizeof(struct dxil_spirv_bindless_entry) == 2,
+                       "Ensure only one extra descriptor is needed to produce correct alignments");
+         uint32_t extra_descriptors = pool->set_count - 1;
+         pool->desc_count[0] += extra_descriptors;
+
          /* Going to raw APIs to avoid allocating descriptors for this */
          D3D12_RESOURCE_DESC buf_desc = {
             .Dimension = D3D12_RESOURCE_DIMENSION_BUFFER,