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 <lionel.g.landwerlin@intel.com>
Reviewed-by: Danylo Piliaiev <danylo.piliaiev@globallogic.com>
Cc: <mesa-stable@lists.freedesktop.org>
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3324
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6084>
(cherry picked from commit 1cdd161a30)
This commit is contained in:
Lionel Landwerlin 2020-07-27 12:06:17 +03:00 committed by Eric Engestrom
parent 370bd3ba47
commit b1442e2a6b
3 changed files with 7 additions and 2 deletions

View file

@ -2713,7 +2713,7 @@
"description": "anv: fix descriptor set free",
"nominated": true,
"nomination_type": 0,
"resolution": 0,
"resolution": 1,
"master_sha": null,
"because_sha": null
},

View file

@ -833,6 +833,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 {
@ -843,6 +844,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;
@ -960,7 +962,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;

View file

@ -1953,6 +1953,10 @@ struct anv_descriptor {
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 */