Module: Mesa Branch: main Commit: 70b03e96f9c7b5a8cbe6478917d239b32602147a URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=70b03e96f9c7b5a8cbe6478917d239b32602147a
Author: Yiwei Zhang <[email protected]> Date: Wed Aug 25 01:17:58 2021 +0000 venus: descriptor set to track descriptor count of last binding Track the descriptor count to be used instead of the variable descriptor count to avoid duplicate checks in later accounting. Signed-off-by: Yiwei Zhang <[email protected]> Reviewed-by: Chia-I Wu <[email protected]> Reviewed-by: Ryan Neph <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12501> --- src/virtio/vulkan/vn_descriptor_set.c | 42 ++++++++++++++++++++++++++++++----- src/virtio/vulkan/vn_descriptor_set.h | 2 ++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/virtio/vulkan/vn_descriptor_set.c b/src/virtio/vulkan/vn_descriptor_set.c index 4b104e1aaf4..dbf9a879996 100644 --- a/src/virtio/vulkan/vn_descriptor_set.c +++ b/src/virtio/vulkan/vn_descriptor_set.c @@ -312,12 +312,43 @@ vn_AllocateDescriptorSets(VkDevice device, struct vn_descriptor_pool *pool = vn_descriptor_pool_from_handle(pAllocateInfo->descriptorPool); const VkAllocationCallbacks *alloc = &pool->allocator; + const VkDescriptorSetVariableDescriptorCountAllocateInfo *variable_info = + NULL; VkResult result; + /* 14.2.3. Allocation of Descriptor Sets + * + * If descriptorSetCount is zero or this structure is not included in + * the pNext chain, then the variable lengths are considered to be zero. + */ + variable_info = vk_find_struct_const( + pAllocateInfo->pNext, + DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO); + + if (variable_info && !variable_info->descriptorSetCount) + variable_info = NULL; + for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) { - struct vn_descriptor_set *set = - vk_zalloc(alloc, sizeof(*set), VN_DEFAULT_ALIGN, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + const struct vn_descriptor_set_layout *layout = + vn_descriptor_set_layout_from_handle(pAllocateInfo->pSetLayouts[i]); + uint32_t last_binding_descriptor_count = 0; + struct vn_descriptor_set *set = NULL; + + /* 14.2.3. Allocation of Descriptor Sets + * + * If VkDescriptorSetAllocateInfo::pSetLayouts[i] does not include a + * variable count descriptor binding, then pDescriptorCounts[i] is + * ignored. + */ + if (!layout->has_variable_descriptor_count) { + last_binding_descriptor_count = + layout->bindings[layout->last_binding].count; + } else if (variable_info) { + last_binding_descriptor_count = variable_info->pDescriptorCounts[i]; + } + + set = vk_zalloc(alloc, sizeof(*set), VN_DEFAULT_ALIGN, + VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (!set) { pDescriptorSets[i] = VK_NULL_HANDLE; result = VK_ERROR_OUT_OF_HOST_MEMORY; @@ -326,8 +357,9 @@ vn_AllocateDescriptorSets(VkDevice device, vn_object_base_init(&set->base, VK_OBJECT_TYPE_DESCRIPTOR_SET, &dev->base); - set->layout = - vn_descriptor_set_layout_from_handle(pAllocateInfo->pSetLayouts[i]); + + set->layout = layout; + set->last_binding_descriptor_count = last_binding_descriptor_count; list_addtail(&set->head, &pool->descriptor_sets); VkDescriptorSet set_handle = vn_descriptor_set_to_handle(set); diff --git a/src/virtio/vulkan/vn_descriptor_set.h b/src/virtio/vulkan/vn_descriptor_set.h index 31611f74116..9eb100755aa 100644 --- a/src/virtio/vulkan/vn_descriptor_set.h +++ b/src/virtio/vulkan/vn_descriptor_set.h @@ -70,6 +70,8 @@ struct vn_descriptor_set { struct vn_object_base base; const struct vn_descriptor_set_layout *layout; + uint32_t last_binding_descriptor_count; + struct list_head head; }; VK_DEFINE_NONDISP_HANDLE_CASTS(vn_descriptor_set,
