panfrost: Store transient BOs in a dynamic array
authorBoris Brezillon <boris.brezillon@collabora.com>
Mon, 24 Aug 2020 10:33:41 +0000 (12:33 +0200)
committerMarge Bot <eric+marge@anholt.net>
Fri, 28 Aug 2020 19:18:08 +0000 (19:18 +0000)
We clearly don't need a hash here since we're never searching for BOs
that are in a pool.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6494>

src/panfrost/lib/pan_pool.c
src/panfrost/lib/pan_pool.h

index 1188063772051855872082553f8917ec57f5ddb5..bea6eea0bc7a5769c53aea1c51017b42c11585a7 100644 (file)
@@ -23,7 +23,6 @@
  *
  */
 
-#include "util/hash_table.h"
 #include "pan_bo.h"
 #include "pan_pool.h"
 
@@ -43,13 +42,7 @@ panfrost_pool_alloc_backing(struct pan_pool *pool, size_t bo_sz)
         struct panfrost_bo *bo = panfrost_bo_create(pool->dev, bo_sz,
                         pool->create_flags);
 
-        uintptr_t flags = PAN_BO_ACCESS_PRIVATE |
-                PAN_BO_ACCESS_RW |
-                PAN_BO_ACCESS_VERTEX_TILER |
-                PAN_BO_ACCESS_FRAGMENT;
-
-        _mesa_hash_table_insert(pool->bos, bo, (void *) flags);
-
+        util_dynarray_append(&pool->bos, struct panfrost_bo *, bo);
         pool->transient_bo = bo;
         pool->transient_offset = 0;
 
@@ -64,33 +57,28 @@ panfrost_pool_init(struct pan_pool *pool, void *memctx,
         memset(pool, 0, sizeof(*pool));
         pool->dev = dev;
         pool->create_flags = create_flags;
-        pool->bos = _mesa_hash_table_create(memctx, _mesa_hash_pointer,
-                        _mesa_key_pointer_equal);
+        util_dynarray_init(&pool->bos, memctx);
 
         if (prealloc)
                 panfrost_pool_alloc_backing(pool, TRANSIENT_SLAB_SIZE);
 }
 
-static void delete_bo_entry(struct hash_entry *entry)
-{
-        panfrost_bo_unreference((struct panfrost_bo *)entry->key);
-}
-
 void
 panfrost_pool_cleanup(struct pan_pool *pool)
 {
-        _mesa_hash_table_destroy(pool->bos, delete_bo_entry);
+        util_dynarray_foreach(&pool->bos, struct panfrost_bo *, bo)
+                panfrost_bo_unreference(*bo);
+
+        util_dynarray_fini(&pool->bos);
 }
 
 void
 panfrost_pool_get_bo_handles(struct pan_pool *pool, uint32_t *handles)
 {
         unsigned idx = 0;
-        hash_table_foreach(pool->bos, entry) {
-                struct panfrost_bo *bo = (struct panfrost_bo *)entry->key;
-
-                assert(bo->gem_handle > 0);
-                handles[idx++] = bo->gem_handle;
+        util_dynarray_foreach(&pool->bos, struct panfrost_bo *, bo) {
+                assert((*bo)->gem_handle > 0);
+                handles[idx++] = (*bo)->gem_handle;
 
                /* Update the BO access flags so that panfrost_bo_wait() knows
                 * about all pending accesses.
@@ -99,7 +87,7 @@ panfrost_pool_get_bo_handles(struct pan_pool *pool, uint32_t *handles)
                 * We also preserve existing flags as this batch might not
                 * be the first one to access the BO.
                 */
-                bo->gpu_access |= PAN_BO_ACCESS_RW;
+                (*bo)->gpu_access |= PAN_BO_ACCESS_RW;
         }
 }
 
index c3fa2abd0490dc62ba629d79810d4c6eab022c32..1793badf35d26233ab5841436da86ec453d39bdc 100644 (file)
@@ -28,6 +28,8 @@
 #include <stddef.h>
 #include <midgard_pack.h>
 
+#include "util/u_dynarray.h"
+
 /* Represents a pool of memory that can only grow, used to allocate objects
  * with the same lifetime as the pool itself. In OpenGL, a pool is owned by the
  * batch for transient structures. In Vulkan, it may be owned by e.g. the
@@ -37,8 +39,8 @@ struct pan_pool {
         /* Parent device for allocation */
         struct panfrost_device *dev;
 
-        /* panfrost_bo -> access_flags owned by the pool */
-        struct hash_table *bos;
+        /* BOs allocated by this pool */
+        struct util_dynarray bos;
 
         /* Current transient BO */
         struct panfrost_bo *transient_bo;
@@ -61,7 +63,7 @@ panfrost_pool_cleanup(struct pan_pool *pool);
 static inline unsigned
 panfrost_pool_num_bos(struct pan_pool *pool)
 {
-        return pool->bos->entries;
+        return util_dynarray_num_elements(&pool->bos, struct panfrost_bo *);
 }
 
 void