From 7b4d1bb9be1f6e94649a0b09abcb1d05b822cf38 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Fri, 8 Dec 2023 10:02:44 +0100 Subject: [PATCH] panfrost: Make pan_pool.h panfrost_{device,bo} agnostic Signed-off-by: Boris Brezillon Reviewed-by: Constantine Shablya Reviewed-by: Erik Faye-Lund Part-of: --- src/gallium/drivers/panfrost/pan_cmdstream.c | 2 +- src/gallium/drivers/panfrost/pan_mempool.c | 13 +++++++---- src/gallium/drivers/panfrost/pan_mempool.h | 10 ++++++++ src/panfrost/lib/pan_bo.h | 10 ++------ src/panfrost/lib/pan_pool.h | 24 ++++++++------------ src/panfrost/vulkan/panvk_mempool.c | 9 +++++--- src/panfrost/vulkan/panvk_mempool.h | 10 ++++++++ 7 files changed, 46 insertions(+), 32 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index d582b46945d..54ad958facb 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -2292,7 +2292,7 @@ panfrost_emit_varying_descs(struct panfrost_pool *pool, struct panfrost_compiled_shader *consumer, uint16_t point_coord_mask, struct pan_linkage *out) { - struct panfrost_device *dev = pool->base.dev; + struct panfrost_device *dev = pool->dev; unsigned producer_count = producer->info.varyings.output_count; unsigned consumer_count = consumer->info.varyings.input_count; diff --git a/src/gallium/drivers/panfrost/pan_mempool.c b/src/gallium/drivers/panfrost/pan_mempool.c index 23791cb06f5..e3a54f51c9e 100644 --- a/src/gallium/drivers/panfrost/pan_mempool.c +++ b/src/gallium/drivers/panfrost/pan_mempool.c @@ -52,8 +52,8 @@ panfrost_pool_alloc_backing(struct panfrost_pool *pool, size_t bo_sz) * flags to this function and keep the read/write, * fragment/vertex+tiler pools separate. */ - struct panfrost_bo *bo = panfrost_bo_create( - pool->base.dev, bo_sz, pool->base.create_flags, pool->base.label); + struct panfrost_bo *bo = + panfrost_bo_create(pool->dev, bo_sz, pool->create_flags, pool->label); if (pool->owned) util_dynarray_append(&pool->bos, struct panfrost_bo *, bo); @@ -73,7 +73,10 @@ panfrost_pool_init(struct panfrost_pool *pool, void *memctx, bool owned) { memset(pool, 0, sizeof(*pool)); - pan_pool_init(&pool->base, dev, create_flags, slab_size, label); + pan_pool_init(&pool->base, slab_size); + pool->dev = dev; + pool->create_flags = create_flags; + pool->label = label; pool->owned = owned; if (owned) @@ -131,8 +134,8 @@ panfrost_pool_alloc_aligned(struct panfrost_pool *pool, size_t sz, unsigned offset = ALIGN_POT(pool->transient_offset, alignment); #ifdef PAN_DBG_OVERFLOW - if (unlikely(pool->base.dev->debug & PAN_DBG_OVERFLOW) && - !(pool->base.create_flags & PAN_BO_INVISIBLE)) { + if (unlikely(pool->dev->debug & PAN_DBG_OVERFLOW) && + !(pool->create_flags & PAN_BO_INVISIBLE)) { unsigned aligned = ALIGN_POT(sz, sysconf(_SC_PAGESIZE)); unsigned bo_size = aligned + PAN_GUARD_SIZE; diff --git a/src/gallium/drivers/panfrost/pan_mempool.h b/src/gallium/drivers/panfrost/pan_mempool.h index e864176f373..ae61aba84ef 100644 --- a/src/gallium/drivers/panfrost/pan_mempool.h +++ b/src/gallium/drivers/panfrost/pan_mempool.h @@ -25,6 +25,7 @@ #ifndef __PAN_MEMPOOL_H__ #define __PAN_MEMPOOL_H__ +#include "pan_bo.h" #include "pan_pool.h" /* Represents grow-only memory. It may be owned by the batch (OpenGL), or may @@ -34,6 +35,15 @@ struct panfrost_pool { /* Inherit from pan_pool */ struct pan_pool base; + /* Parent device for allocation */ + struct panfrost_device *dev; + + /* Label for created BOs */ + const char *label; + + /* BO flags to use in the pool */ + unsigned create_flags; + /* BOs allocated by this pool */ struct util_dynarray bos; diff --git a/src/panfrost/lib/pan_bo.h b/src/panfrost/lib/pan_bo.h index 51fed3149a4..c9e016eeff7 100644 --- a/src/panfrost/lib/pan_bo.h +++ b/src/panfrost/lib/pan_bo.h @@ -30,6 +30,8 @@ #include "util/list.h" #include "panfrost-job.h" +#include "pan_pool.h" + #include "kmod/pan_kmod.h" /* Flags for allocated memory */ @@ -78,14 +80,6 @@ typedef uint8_t pan_bo_access; struct panfrost_device; -struct panfrost_ptr { - /* CPU address */ - void *cpu; - - /* GPU address */ - mali_ptr gpu; -}; - struct panfrost_bo { /* Must be first for casting */ struct list_head bucket_link; diff --git a/src/panfrost/lib/pan_pool.h b/src/panfrost/lib/pan_pool.h index c499994399a..3a9098e65bb 100644 --- a/src/panfrost/lib/pan_pool.h +++ b/src/panfrost/lib/pan_pool.h @@ -27,34 +27,28 @@ #include #include -#include "pan_bo.h" #include "util/u_dynarray.h" +struct panfrost_ptr { + /* CPU address */ + void *cpu; + + /* GPU address */ + mali_ptr gpu; +}; + /* Represents grow-only memory. */ struct pan_pool { - /* Parent device for allocation */ - struct panfrost_device *dev; - - /* Label for created BOs */ - const char *label; - - /* BO flags to use in the pool */ - unsigned create_flags; - /* Minimum size for allocated BOs. */ size_t slab_size; }; static inline void -pan_pool_init(struct pan_pool *pool, struct panfrost_device *dev, - unsigned create_flags, size_t slab_size, const char *label) +pan_pool_init(struct pan_pool *pool, size_t slab_size) { - pool->dev = dev; - pool->create_flags = create_flags; pool->slab_size = slab_size; - pool->label = label; } /* Represents a fat pointer for GPU-mapped memory, returned from the transient diff --git a/src/panfrost/vulkan/panvk_mempool.c b/src/panfrost/vulkan/panvk_mempool.c index 7e76b8dea2d..361586964b7 100644 --- a/src/panfrost/vulkan/panvk_mempool.c +++ b/src/panfrost/vulkan/panvk_mempool.c @@ -57,8 +57,8 @@ panvk_pool_alloc_backing(struct panvk_pool *pool, size_t bo_sz) * flags to this function and keep the read/write, * fragment/vertex+tiler pools separate. */ - bo = panfrost_bo_create(pool->base.dev, bo_sz, pool->base.create_flags, - pool->base.label); + bo = + panfrost_bo_create(pool->dev, bo_sz, pool->create_flags, pool->label); } if (panfrost_bo_size(bo) == pool->base.slab_size) @@ -104,7 +104,10 @@ panvk_pool_init(struct panvk_pool *pool, struct panfrost_device *dev, size_t slab_size, const char *label, bool prealloc) { memset(pool, 0, sizeof(*pool)); - pan_pool_init(&pool->base, dev, create_flags, slab_size, label); + pan_pool_init(&pool->base, slab_size); + pool->dev = dev; + pool->create_flags = create_flags; + pool->label = label; pool->bo_pool = bo_pool; util_dynarray_init(&pool->bos, NULL); diff --git a/src/panfrost/vulkan/panvk_mempool.h b/src/panfrost/vulkan/panvk_mempool.h index 056993c092f..2aa3156138d 100644 --- a/src/panfrost/vulkan/panvk_mempool.h +++ b/src/panfrost/vulkan/panvk_mempool.h @@ -26,6 +26,7 @@ #define __PANVK_POOL_H__ #include "pan_pool.h" +#include "pan_bo.h" struct panvk_bo_pool { struct util_dynarray free_bos; @@ -52,6 +53,15 @@ struct panvk_pool { /* Inherit from pan_pool */ struct pan_pool base; + /* Parent device for allocation */ + struct panfrost_device *dev; + + /* Label for created BOs */ + const char *label; + + /* BO flags to use in the pool */ + unsigned create_flags; + /* Before allocating a new BO, check if the BO pool has free BOs. * When returning BOs, if bo_pool != NULL, return them to this bo_pool. */