From ea112c510425da398217bd428c3ea5e4f6ebfd2c Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Thu, 15 Apr 2021 13:22:23 -0700 Subject: [PATCH] freedreno: Implement TC resource_busy Signed-off-by: Rob Clark Part-of: --- src/gallium/drivers/freedreno/freedreno_context.c | 2 +- src/gallium/drivers/freedreno/freedreno_resource.c | 58 +++++++++++++++------- src/gallium/drivers/freedreno/freedreno_resource.h | 3 ++ src/gallium/drivers/freedreno/freedreno_screen.c | 4 ++ src/gallium/drivers/freedreno/freedreno_screen.h | 2 + 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/src/gallium/drivers/freedreno/freedreno_context.c b/src/gallium/drivers/freedreno/freedreno_context.c index 2127e24..4063d7a 100644 --- a/src/gallium/drivers/freedreno/freedreno_context.c +++ b/src/gallium/drivers/freedreno/freedreno_context.c @@ -698,7 +698,7 @@ fd_context_init_tc(struct pipe_context *pctx, unsigned flags) pctx, &ctx->screen->transfer_pool, fd_replace_buffer_storage, fd_fence_create_unflushed, - NULL, + fd_resource_busy, false, &ctx->tc); diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c index 3fdb3c3..8a6d22d 100644 --- a/src/gallium/drivers/freedreno/freedreno_resource.c +++ b/src/gallium/drivers/freedreno/freedreno_resource.c @@ -277,6 +277,8 @@ fd_replace_buffer_storage(struct pipe_context *pctx, struct pipe_resource *pdst, fd_bc_invalidate_resource(dst, true); rebind_resource(dst); + util_idalloc_mt_free(&ctx->screen->buffer_ids, delete_buffer_id); + fd_screen_lock(ctx->screen); fd_bo_del(dst->bo); @@ -290,6 +292,35 @@ fd_replace_buffer_storage(struct pipe_context *pctx, struct pipe_resource *pdst, fd_screen_unlock(ctx->screen); } +static unsigned +translate_usage(unsigned usage) +{ + uint32_t op = 0; + + if (usage & PIPE_MAP_READ) + op |= FD_BO_PREP_READ; + + if (usage & PIPE_MAP_WRITE) + op |= FD_BO_PREP_WRITE; + + return op; +} + +bool +fd_resource_busy(struct pipe_screen *pscreen, struct pipe_resource *prsc, + unsigned usage) +{ + struct fd_resource *rsc = fd_resource(prsc); + + if (pending(rsc, !!(usage & PIPE_MAP_WRITE))) + return true; + + if (resource_busy(rsc, translate_usage(usage))) + return true; + + return false; +} + static void flush_resource(struct fd_context *ctx, struct fd_resource *rsc, unsigned usage); @@ -687,20 +718,6 @@ fd_resource_transfer_unmap(struct pipe_context *pctx, slab_free(&ctx->transfer_pool, ptrans); } -static unsigned -translate_usage(unsigned usage) -{ - uint32_t op = 0; - - if (usage & PIPE_MAP_READ) - op |= FD_BO_PREP_READ; - - if (usage & PIPE_MAP_WRITE) - op |= FD_BO_PREP_WRITE; - - return op; -} - static void invalidate_resource(struct fd_resource *rsc, unsigned usage) assert_dt { @@ -977,6 +994,7 @@ fd_resource_transfer_map(struct pipe_context *pctx, struct pipe_resource *prsc, static void fd_resource_destroy(struct pipe_screen *pscreen, struct pipe_resource *prsc) { + struct fd_screen *screen = fd_screen(prsc->screen); struct fd_resource *rsc = fd_resource(prsc); if (!rsc->is_replacement) @@ -988,6 +1006,9 @@ fd_resource_destroy(struct pipe_screen *pscreen, struct pipe_resource *prsc) if (rsc->scanout) renderonly_scanout_destroy(rsc->scanout, fd_screen(pscreen)->ro); + if (prsc->target == PIPE_BUFFER) + util_idalloc_mt_free(&screen->buffer_ids, rsc->b.buffer_id_unique); + threaded_resource_deinit(prsc); util_range_destroy(&rsc->valid_buffer_range); @@ -1062,6 +1083,7 @@ static struct fd_resource * alloc_resource_struct(struct pipe_screen *pscreen, const struct pipe_resource *tmpl) { + struct fd_screen *screen = fd_screen(pscreen); struct fd_resource *rsc = CALLOC_STRUCT(fd_resource); if (!rsc) @@ -1084,6 +1106,11 @@ alloc_resource_struct(struct pipe_screen *pscreen, pipe_reference_init(&rsc->track->reference, 1); + threaded_resource_init(prsc); + + if (tmpl->target == PIPE_BUFFER) + rsc->b.buffer_id_unique = util_idalloc_mt_alloc(&screen->buffer_ids); + return rsc; } @@ -1114,8 +1141,6 @@ fd_resource_allocate_and_resolve(struct pipe_screen *pscreen, DBG("%" PRSC_FMT, PRSC_ARGS(prsc)); - threaded_resource_init(prsc); - if (tmpl->bind & PIPE_BIND_SHARED) rsc->b.is_shared = true; @@ -1299,7 +1324,6 @@ fd_resource_from_handle(struct pipe_screen *pscreen, DBG("%" PRSC_FMT ", modifier=%" PRIx64, PRSC_ARGS(prsc), handle->modifier); - threaded_resource_init(prsc); rsc->b.is_shared = true; fd_resource_layout_init(prsc); diff --git a/src/gallium/drivers/freedreno/freedreno_resource.h b/src/gallium/drivers/freedreno/freedreno_resource.h index 2e1eca4..5047417 100644 --- a/src/gallium/drivers/freedreno/freedreno_resource.h +++ b/src/gallium/drivers/freedreno/freedreno_resource.h @@ -346,6 +346,9 @@ void fd_replace_buffer_storage(struct pipe_context *ctx, struct pipe_resource *dst, struct pipe_resource *src, uint32_t delete_buffer_id) in_dt; +bool fd_resource_busy(struct pipe_screen *pscreen, struct pipe_resource *prsc, + unsigned usage); + void fd_resource_uncompress(struct fd_context *ctx, struct fd_resource *rsc) assert_dt; void fd_resource_dump(struct fd_resource *rsc, const char *name); diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c b/src/gallium/drivers/freedreno/freedreno_screen.c index 70a2cae..9f47b6d 100644 --- a/src/gallium/drivers/freedreno/freedreno_screen.c +++ b/src/gallium/drivers/freedreno/freedreno_screen.c @@ -163,6 +163,8 @@ fd_screen_destroy(struct pipe_screen *pscreen) simple_mtx_destroy(&screen->lock); + util_idalloc_mt_fini(&screen->buffer_ids); + u_transfer_helper_destroy(pscreen->transfer_helper); if (screen->compiler) @@ -1083,6 +1085,8 @@ fd_screen_create(struct fd_device *dev, struct renderonly *ro) list_inithead(&screen->context_list); + util_idalloc_mt_init_tc(&screen->buffer_ids); + (void)simple_mtx_init(&screen->lock, mtx_plain); pscreen->destroy = fd_screen_destroy; diff --git a/src/gallium/drivers/freedreno/freedreno_screen.h b/src/gallium/drivers/freedreno/freedreno_screen.h index cf8b2dd..4ffcf53 100644 --- a/src/gallium/drivers/freedreno/freedreno_screen.h +++ b/src/gallium/drivers/freedreno/freedreno_screen.h @@ -37,6 +37,7 @@ #include "util/debug.h" #include "util/simple_mtx.h" #include "util/slab.h" +#include "util/u_idalloc.h" #include "util/u_memory.h" #include "util/u_queue.h" @@ -137,6 +138,7 @@ struct fd_screen { uint16_t rsc_seqno; uint16_t ctx_seqno; + struct util_idalloc_mt buffer_ids; unsigned num_supported_modifiers; const uint64_t *supported_modifiers; -- 2.7.4