anv: Add a way to reserve states from a pool
authorIván Briano <ivan.briano@intel.com>
Thu, 23 Apr 2020 00:17:38 +0000 (17:17 -0700)
committerMarge Bot <eric+marge@anholt.net>
Wed, 13 May 2020 23:20:50 +0000 (23:20 +0000)
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4898>

src/intel/vulkan/anv_allocator.c
src/intel/vulkan/anv_private.h

index 9d90311d7df94cec116b01e5064f2b833eeb1924..703fa309aaceb5602250c665836c72185eca3aa9 100644 (file)
@@ -1268,6 +1268,46 @@ anv_state_stream_alloc(struct anv_state_stream *stream,
    return state;
 }
 
+void
+anv_state_reserved_pool_init(struct anv_state_reserved_pool *pool,
+                             struct anv_state_pool *parent,
+                             uint32_t count, uint32_t size, uint32_t alignment)
+{
+   pool->pool = parent;
+   pool->reserved_blocks = ANV_FREE_LIST_EMPTY;
+   pool->count = count;
+
+   for (unsigned i = 0; i < count; i++) {
+      struct anv_state state = anv_state_pool_alloc(pool->pool, size, alignment);
+      anv_free_list_push(&pool->reserved_blocks, &pool->pool->table, state.idx, 1);
+   }
+}
+
+void
+anv_state_reserved_pool_finish(struct anv_state_reserved_pool *pool)
+{
+   struct anv_state *state;
+
+   while ((state = anv_free_list_pop(&pool->reserved_blocks, &pool->pool->table))) {
+      anv_state_pool_free(pool->pool, *state);
+      pool->count--;
+   }
+   assert(pool->count == 0);
+}
+
+struct anv_state
+anv_state_reserved_pool_alloc(struct anv_state_reserved_pool *pool)
+{
+   return *anv_free_list_pop(&pool->reserved_blocks, &pool->pool->table);
+}
+
+void
+anv_state_reserved_pool_free(struct anv_state_reserved_pool *pool,
+                             struct anv_state state)
+{
+   anv_free_list_push(&pool->reserved_blocks, &pool->pool->table, state.idx, 1);
+}
+
 void
 anv_bo_pool_init(struct anv_bo_pool *pool, struct anv_device *device)
 {
index e2e33c96d0841f65ee5ce8e74c4560560951e8f9..e2914a2800fd06cf54854d6d03e391c39ed239ca 100644 (file)
@@ -897,6 +897,12 @@ struct anv_state_pool {
    struct anv_fixed_size_state_pool buckets[ANV_STATE_BUCKETS];
 };
 
+struct anv_state_reserved_pool {
+   struct anv_state_pool *pool;
+   union anv_free_list reserved_blocks;
+   uint32_t count;
+};
+
 struct anv_state_stream {
    struct anv_state_pool *state_pool;
 
@@ -945,6 +951,15 @@ void anv_state_stream_finish(struct anv_state_stream *stream);
 struct anv_state anv_state_stream_alloc(struct anv_state_stream *stream,
                                         uint32_t size, uint32_t alignment);
 
+void anv_state_reserved_pool_init(struct anv_state_reserved_pool *pool,
+                                      struct anv_state_pool *parent,
+                                      uint32_t count, uint32_t size,
+                                      uint32_t alignment);
+void anv_state_reserved_pool_finish(struct anv_state_reserved_pool *pool);
+struct anv_state anv_state_reserved_pool_alloc(struct anv_state_reserved_pool *pool);
+void anv_state_reserved_pool_free(struct anv_state_reserved_pool *pool,
+                                  struct anv_state state);
+
 VkResult anv_state_table_init(struct anv_state_table *table,
                              struct anv_device *device,
                              uint32_t initial_entries);