panfrost: Rewrite allocate_transient with new abstraction
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 12 Jul 2019 19:49:23 +0000 (12:49 -0700)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 12 Jul 2019 22:31:48 +0000 (15:31 -0700)
We use a fixed size slab if we can, otherwise we create a dedicated
("oversized") BO and add that to the job. In the latter case we'll get
reference counting for free so we can forget about this corner case for
the rest of the series.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/gallium/drivers/panfrost/pan_allocate.c

index 73da1ec5ed055e8ea975bf27b509219a1a238269..15c5f8aa671820a82c956d47b28ab555dc7a64ff 100644 (file)
@@ -80,47 +80,38 @@ panfrost_create_slab(struct panfrost_screen *screen)
 struct panfrost_transfer
 panfrost_allocate_transient(struct panfrost_context *ctx, size_t sz)
 {
+        struct panfrost_screen *screen = pan_screen(ctx->base.screen);
+
         /* Pad the size */
         sz = ALIGN_POT(sz, ALIGNMENT);
 
-        /* Check if there is room in the current entry */
-        struct panfrost_transient_pool *pool = &ctx->transient_pools[ctx->cmdstream_i];
-
-        if ((pool->entry_offset + sz) > pool->entry_size) {
-                /* Don't overflow this entry -- advance to the next */
-
-                pool->entry_offset = 0;
-
-                pool->entry_index++;
-                assert(pool->entry_index < PANFROST_MAX_TRANSIENT_ENTRIES);
+        /* Find or create a suitable BO */
+        struct panfrost_bo *bo = NULL;
 
-                /* Check if this entry exists */
+        unsigned offset = 0;
+        bool update_offset = false;
 
-                if (pool->entry_index >= pool->entry_count) {
-                        /* Don't overflow the pool -- allocate a new one */
-                        struct pipe_context *gallium = (struct pipe_context *) ctx;
-                        struct panfrost_screen *screen = pan_screen(gallium->screen);
-                        struct pb_slab_entry *entry = pb_slab_alloc(&screen->slabs, pool->entry_size, HEAP_TRANSIENT);
+        if (sz < TRANSIENT_SLAB_SIZE) {
+                /* TODO: Lookup free */
 
-                        pool->entry_count++;
-                        pool->entries[pool->entry_index] = (struct panfrost_memory_entry *) entry;
-                }
+                if (!bo)
+                        bo = panfrost_create_slab(screen);
 
-                /* Make sure we -still- won't overflow */
-                assert(sz < pool->entry_size);
+                update_offset = true;
+        } else {
+                /* Create a new BO and reference it */
+                bo = panfrost_drm_create_bo(screen, ALIGN_POT(sz, 4096), 0);
+                panfrost_job_add_bo(batch, bo);
         }
 
-        /* We have an entry we can write to, so do the upload! */
-        struct panfrost_memory_entry *p_entry = pool->entries[pool->entry_index];
-        struct panfrost_memory *backing = (struct panfrost_memory *) p_entry->base.slab;
-
         struct panfrost_transfer ret = {
-                .cpu = backing->bo->cpu + p_entry->offset + pool->entry_offset,
-                .gpu = backing->bo->gpu + p_entry->offset + pool->entry_offset
+                .cpu = bo->cpu + offset,
+                .gpu = bo->gpu + offset,
         };
 
-        /* Advance the pointer */
-        pool->entry_offset += sz;
+        if (update_offset) {
+                /* TODO: Update the offset */
+        }
 
         return ret;