From 460ee81913e5f440215cfe43894eb27e3b6eea5c Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Mon, 27 Mar 2023 11:08:50 -0700 Subject: [PATCH] dzn: Align descriptor sets in the bindless buffer Fixes: 5d2b4ee4 ("dzn: Allocate descriptor sets in buffers for bindless mode") Part-of: --- src/microsoft/vulkan/dzn_descriptor_set.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/microsoft/vulkan/dzn_descriptor_set.c b/src/microsoft/vulkan/dzn_descriptor_set.c index e822a46..7a83d77 100644 --- a/src/microsoft/vulkan/dzn_descriptor_set.c +++ b/src/microsoft/vulkan/dzn_descriptor_set.c @@ -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, -- 2.7.4