From bc2b137df949a257d55e2175359e209cee11feb3 Mon Sep 17 00:00:00 2001 From: Giovanni Mascellani Date: Fri, 18 Oct 2024 22:13:23 +0200 Subject: [PATCH] vkd3d: Only put the mutable descriptor set once in the pipeline layout. Currently the mutable descriptor set is repeated many times in the pipeline layout in order to cover the indices for all the descriptor types that would be present if mutable descriptors were not used. This is useless and wasteful, but was necessary before the descriptor sets backing the SRV-UAV-CBV heap were moved at the end of the allocation table because descriptor set indices are currently a compile-time constant in many places. Now this is not needed any more and we can just avoid putting many copies of the mutable descriptor set in the pipeline layout, making it easier to meet Vulkan implementation limits. --- libs/vkd3d/state.c | 11 +++++++---- libs/vkd3d/vkd3d_private.h | 10 ++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index bff36990..e7476a01 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -1482,8 +1482,8 @@ static unsigned int d3d12_root_signature_copy_descriptor_set_layouts(const struc VkDescriptorSetLayout *vk_set_layouts) { const struct d3d12_device *device = root_signature->device; - VkDescriptorSetLayout mutable_layout, vk_set_layout; enum vkd3d_vk_descriptor_set_index set; + VkDescriptorSetLayout vk_set_layout; unsigned int i; for (i = 0; i < root_signature->vk_set_count; ++i) @@ -1492,12 +1492,15 @@ static unsigned int d3d12_root_signature_copy_descriptor_set_layouts(const struc if (!device->use_vk_heaps) return i; - mutable_layout = device->vk_descriptor_heap_layouts[VKD3D_SET_INDEX_MUTABLE].vk_set_layout; for (set = 0; set < ARRAY_SIZE(device->vk_descriptor_heap_layouts); ++set) { vk_set_layout = device->vk_descriptor_heap_layouts[set].vk_set_layout; - /* All layouts must be valid, so if null, just set it to the mutable one. */ - vk_set_layouts[i++] = vk_set_layout ? vk_set_layout : mutable_layout; + + VKD3D_ASSERT(vk_set_layout); + vk_set_layouts[i++] = vk_set_layout; + + if (device->vk_info.EXT_mutable_descriptor_type && set == VKD3D_SET_INDEX_MUTABLE) + break; } return i; diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 3048b075..eb57c3d4 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -774,12 +774,18 @@ enum vkd3d_vk_descriptor_set_index { VKD3D_SET_INDEX_SAMPLER, VKD3D_SET_INDEX_UAV_COUNTER, - VKD3D_SET_INDEX_UNIFORM_BUFFER, - VKD3D_SET_INDEX_MUTABLE = VKD3D_SET_INDEX_UNIFORM_BUFFER, + VKD3D_SET_INDEX_MUTABLE, + + /* These are used when mutable descriptors are not available to back + * SRV-UAV-CBV descriptor heaps. They must stay at the end of this + * enumeration, so that they can be ignored when mutable descriptors are + * used. */ + VKD3D_SET_INDEX_UNIFORM_BUFFER = VKD3D_SET_INDEX_MUTABLE, VKD3D_SET_INDEX_UNIFORM_TEXEL_BUFFER, VKD3D_SET_INDEX_SAMPLED_IMAGE, VKD3D_SET_INDEX_STORAGE_TEXEL_BUFFER, VKD3D_SET_INDEX_STORAGE_IMAGE, + VKD3D_SET_INDEX_COUNT };