From 1cdd161a30297c13908134d8d205a7a377ec807a Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Mon, 27 Jul 2020 12:06:17 +0300 Subject: [PATCH] anv: fix descriptor set free Once we start going through the free list of the descriptor set pool, we might use a free entry larger than the descriptor set we want to allocate. When we free that descriptor set, we use the size of the set rather than the size of the entry that was picked. This leads to leaks of some amount of descriptor set pool. This fix saves the size of the entry in the descriptor set so we know what amount of the pool needs to freed. v2: Don't bother adding a new size field Signed-off-by: Lionel Landwerlin Reviewed-by: Danylo Piliaiev Cc: Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3324 Part-of: --- src/intel/vulkan/anv_descriptor_set.c | 3 ++- src/intel/vulkan/anv_private.h | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/intel/vulkan/anv_descriptor_set.c b/src/intel/vulkan/anv_descriptor_set.c index cb6fa40b368..961d5c2ad52 100644 --- a/src/intel/vulkan/anv_descriptor_set.c +++ b/src/intel/vulkan/anv_descriptor_set.c @@ -850,6 +850,7 @@ anv_descriptor_pool_alloc_set(struct anv_descriptor_pool *pool, { if (size <= pool->size - pool->next) { *set = (struct anv_descriptor_set *) (pool->data + pool->next); + (*set)->size = size; pool->next += size; return VK_SUCCESS; } else { @@ -860,6 +861,7 @@ anv_descriptor_pool_alloc_set(struct anv_descriptor_pool *pool, if (size <= entry->size) { *link = entry->next; *set = (struct anv_descriptor_set *) entry; + (*set)->size = entry->size; return VK_SUCCESS; } link = &entry->next; @@ -979,7 +981,6 @@ anv_descriptor_set_create(struct anv_device *device, set->layout = layout; anv_descriptor_set_layout_ref(layout); - set->size = size; set->buffer_views = (struct anv_buffer_view *) &set->descriptors[layout->size]; set->buffer_view_count = layout->buffer_view_count; diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 9500b41dead..270d2e8a3a6 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -2026,6 +2026,10 @@ struct anv_descriptor_set { struct anv_descriptor_pool *pool; struct anv_descriptor_set_layout *layout; + + /* Amount of space occupied in the the pool by this descriptor set. It can + * be larger than the size of the descriptor set. + */ uint32_t size; /* State relative to anv_descriptor_pool::bo */ -- 2.30.2