Mesa (staging/19.0): anv: destroy descriptor sets when pool gets destroyed

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Mar 12 22:15:01 UTC 2019


Module: Mesa
Branch: staging/19.0
Commit: ef8a38e0e689809a88364c574a57893368062931
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ef8a38e0e689809a88364c574a57893368062931

Author: Tapani Pälli <tapani.palli at intel.com>
Date:   Mon Mar  4 14:22:36 2019 +0200

anv: destroy descriptor sets when pool gets destroyed

Patch maintains a list of sets in the pool and destroys possible
remaining sets when pool is destroyed.

As stated in Vulkan spec:
   "When a pool is destroyed, all descriptor sets allocated from
    the pool are implicitly freed and become invalid."

This fixes memory leaks spotted with valgrind:

   ==19622== 96 bytes in 1 blocks are definitely lost in loss record 2 of 3
   ==19622==    at 0x483880B: malloc (vg_replace_malloc.c:309)
   ==19622==    by 0x495B67E: default_alloc_func (anv_device.c:547)
   ==19622==    by 0x4955E05: vk_alloc (vk_alloc.h:36)
   ==19622==    by 0x4956A8F: anv_multialloc_alloc (anv_private.h:538)
   ==19622==    by 0x4956A8F: anv_CreateDescriptorSetLayout (anv_descriptor_set.c:217)

Fixes: 14f6275c92f1 ("anv/descriptor_set: add reference counting for descriptor set layouts")
Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
(cherry picked from commit 105002bd2d6173b24f6955c22340b5bc77e029fa)
Conflicts resolved by Dylan and Jason

---

 src/intel/vulkan/anv_descriptor_set.c | 12 ++++++++++++
 src/intel/vulkan/anv_private.h        |  6 ++++++
 2 files changed, 18 insertions(+)

diff --git a/src/intel/vulkan/anv_descriptor_set.c b/src/intel/vulkan/anv_descriptor_set.c
index 0df0c3825e5..587e2132fca 100644
--- a/src/intel/vulkan/anv_descriptor_set.c
+++ b/src/intel/vulkan/anv_descriptor_set.c
@@ -461,6 +461,8 @@ VkResult anv_CreateDescriptorPool(
                          &device->surface_state_pool, 4096);
    pool->surface_state_free_list = NULL;
 
+   list_inithead(&pool->desc_sets);
+
    *pDescriptorPool = anv_descriptor_pool_to_handle(pool);
 
    return VK_SUCCESS;
@@ -478,6 +480,12 @@ void anv_DestroyDescriptorPool(
       return;
 
    anv_state_stream_finish(&pool->surface_state_stream);
+
+   list_for_each_entry_safe(struct anv_descriptor_set, set,
+                            &pool->desc_sets, pool_link) {
+      anv_descriptor_set_destroy(device, pool, set);
+   }
+
    vk_free2(&device->alloc, pAllocator, pool);
 }
 
@@ -633,6 +641,8 @@ anv_descriptor_set_destroy(struct anv_device *device,
       entry->size = set->size;
       pool->free_list = (char *) entry - pool->data;
    }
+
+   list_del(&set->pool_link);
 }
 
 VkResult anv_AllocateDescriptorSets(
@@ -655,6 +665,8 @@ VkResult anv_AllocateDescriptorSets(
       if (result != VK_SUCCESS)
          break;
 
+      list_addtail(&set->pool_link, &pool->desc_sets);
+
       pDescriptorSets[i] = anv_descriptor_set_to_handle(set);
    }
 
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 5f6973ebe81..1d42332a370 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -1581,6 +1581,10 @@ struct anv_descriptor_set {
    uint32_t size;
    uint32_t buffer_count;
    struct anv_buffer_view *buffer_views;
+
+   /* Link to descriptor pool's desc_sets list . */
+   struct list_head pool_link;
+
    struct anv_descriptor descriptors[0];
 };
 
@@ -1614,6 +1618,8 @@ struct anv_descriptor_pool {
    struct anv_state_stream surface_state_stream;
    void *surface_state_free_list;
 
+   struct list_head desc_sets;
+
    char data[0];
 };
 




More information about the mesa-commit mailing list