[Mesa-dev] [PATCH 1/2] anv: descriptors: split allocation function

Lionel Landwerlin lionel.g.landwerlin at intel.com
Tue Sep 11 20:22:53 UTC 2018


The following commits will make the allocation more complicated so
split the free list allocation logic out.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
---
 src/intel/vulkan/anv_descriptor_set.c | 68 +++++++++++++++------------
 src/intel/vulkan/anv_private.h        |  5 +-
 2 files changed, 42 insertions(+), 31 deletions(-)

diff --git a/src/intel/vulkan/anv_descriptor_set.c b/src/intel/vulkan/anv_descriptor_set.c
index 2bd1d86f4d4..3439f828900 100644
--- a/src/intel/vulkan/anv_descriptor_set.c
+++ b/src/intel/vulkan/anv_descriptor_set.c
@@ -432,8 +432,8 @@ VkResult anv_CreateDescriptorPool(
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
    pool->size = pool_size;
-   pool->next = 0;
-   pool->free_list = EMPTY;
+   pool->next_set = 0;
+   pool->free_set_list = EMPTY;
 
    anv_state_stream_init(&pool->surface_state_stream,
                          &device->surface_state_pool, 4096);
@@ -467,8 +467,8 @@ VkResult anv_ResetDescriptorPool(
    ANV_FROM_HANDLE(anv_device, device, _device);
    ANV_FROM_HANDLE(anv_descriptor_pool, pool, descriptorPool);
 
-   pool->next = 0;
-   pool->free_list = EMPTY;
+   pool->next_set = 0;
+   pool->free_set_list = EMPTY;
    anv_state_stream_finish(&pool->surface_state_stream);
    anv_state_stream_init(&pool->surface_state_stream,
                          &device->surface_state_pool, 4096);
@@ -496,35 +496,45 @@ struct surface_state_free_list_entry {
    struct anv_state state;
 };
 
+static struct anv_descriptor_set *
+anv_descriptor_alloc(struct anv_descriptor_pool *pool,
+                     struct anv_descriptor_set_layout *layout,
+                     size_t size)
+{
+   struct anv_descriptor_set *set = NULL;
+
+   if (size <= pool->size - pool->next_set) {
+      set = (struct anv_descriptor_set *) (pool->data + pool->next_set);
+      pool->next_set += size;
+      return set;
+   }
+
+   struct pool_free_list_entry *entry;
+   uint32_t *link = &pool->free_set_list;
+   for (uint32_t f = pool->free_set_list; f != EMPTY; f = entry->next) {
+      entry = (struct pool_free_list_entry *) (pool->data + f);
+      if (size <= entry->size) {
+         uint32_t next = entry->next;
+         set = (struct anv_descriptor_set *) entry;
+         *link = next;
+         return set;
+      }
+      link = &entry->next;
+   }
+
+   return NULL;
+}
+
 VkResult
 anv_descriptor_set_create(struct anv_device *device,
                           struct anv_descriptor_pool *pool,
                           struct anv_descriptor_set_layout *layout,
                           struct anv_descriptor_set **out_set)
 {
-   struct anv_descriptor_set *set;
    const size_t size = anv_descriptor_set_layout_size(layout);
-
-   set = NULL;
-   if (size <= pool->size - pool->next) {
-      set = (struct anv_descriptor_set *) (pool->data + pool->next);
-      pool->next += size;
-   } else {
-      struct pool_free_list_entry *entry;
-      uint32_t *link = &pool->free_list;
-      for (uint32_t f = pool->free_list; f != EMPTY; f = entry->next) {
-         entry = (struct pool_free_list_entry *) (pool->data + f);
-         if (size <= entry->size) {
-            *link = entry->next;
-            set = (struct anv_descriptor_set *) entry;
-            break;
-         }
-         link = &entry->next;
-      }
-   }
-
+   struct anv_descriptor_set *set = anv_descriptor_alloc(pool, layout, size);
    if (set == NULL) {
-      if (pool->free_list != EMPTY) {
+      if (pool->free_set_list != EMPTY) {
          return vk_error(VK_ERROR_FRAGMENTED_POOL);
       } else {
          return vk_error(VK_ERROR_OUT_OF_POOL_MEMORY);
@@ -603,13 +613,13 @@ anv_descriptor_set_destroy(struct anv_device *device,
 
    /* Put the descriptor set allocation back on the free list. */
    const uint32_t index = (char *) set - pool->data;
-   if (index + set->size == pool->next) {
-      pool->next = index;
+   if (index + set->size == pool->next_set) {
+      pool->next_set = index;
    } else {
       struct pool_free_list_entry *entry = (struct pool_free_list_entry *) set;
-      entry->next = pool->free_list;
+      entry->next = pool->free_set_list;
       entry->size = set->size;
-      pool->free_list = (char *) entry - pool->data;
+      pool->free_set_list = (char *) entry - pool->data;
    }
 }
 
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index d15a91dd014..372b7c69635 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -1500,8 +1500,9 @@ struct anv_push_descriptor_set {
 
 struct anv_descriptor_pool {
    uint32_t size;
-   uint32_t next;
-   uint32_t free_list;
+
+   uint32_t free_set_list;
+   uint32_t next_set;
 
    struct anv_state_stream surface_state_stream;
    void *surface_state_free_list;
-- 
2.19.0.rc1



More information about the mesa-dev mailing list