From 81bec8b63bc1c4c49109b008b1043b6107b99bd6 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Thu, 13 Jul 2023 19:06:20 -0500 Subject: [PATCH] nvk: Use the max descriptor alignemtn in GetDescriptorSetLayoutSupport Part-of: --- .../vulkan/nvk_descriptor_set_layout.c | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/nouveau/vulkan/nvk_descriptor_set_layout.c b/src/nouveau/vulkan/nvk_descriptor_set_layout.c index 67bc85051a9..68ee7aebab5 100644 --- a/src/nouveau/vulkan/nvk_descriptor_set_layout.c +++ b/src/nouveau/vulkan/nvk_descriptor_set_layout.c @@ -257,6 +257,23 @@ nvk_GetDescriptorSetLayoutSupport(VkDevice _device, vk_find_struct_const(pCreateInfo->pNext, MUTABLE_DESCRIPTOR_TYPE_CREATE_INFO_EXT); + /* Figure out the maximum alignment up-front. Otherwise, we need to sort + * the list of descriptors by binding number in order to get the size + * accumulation right. + */ + uint32_t max_align = 0; + for (uint32_t i = 0; i < pCreateInfo->bindingCount; i++) { + const VkDescriptorSetLayoutBinding *binding = &pCreateInfo->pBindings[i]; + const VkMutableDescriptorTypeListEXT *type_list = + nvk_descriptor_get_type_list(binding->descriptorType, + mutable_info, i); + + uint32_t stride, align; + nvk_descriptor_stride_align_for_type(binding->descriptorType, type_list, + &stride, &align); + max_align = MAX2(max_align, align); + } + uint32_t buffer_size = 0; uint8_t dynamic_buffer_count = 0; for (uint32_t i = 0; i < pCreateInfo->bindingCount; i++) { @@ -285,8 +302,13 @@ nvk_GetDescriptorSetLayoutSupport(VkDevice _device, if (stride > 0) { assert(stride <= UINT8_MAX); assert(util_is_power_of_two_nonzero(align)); - buffer_size = ALIGN_POT(buffer_size, align); + + /* Since we're aligning to the maximum and since this is just a + * check for whether or not the max buffer size is big enough, we + * keep buffer_size aligned to max_align. + */ buffer_size += stride * binding->descriptorCount; + buffer_size = ALIGN_POT(buffer_size, max_align); } }