From 3104b1aaaf934ad5bef5dda129d516c72c5065c0 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 17 Nov 2022 13:37:36 -0500 Subject: [PATCH] asahi: Factor out prepare_for_map This will be expanded, let's expand in the direction of less spaghetti. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/asahi/agx_pipe.c | 29 +++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/gallium/drivers/asahi/agx_pipe.c b/src/gallium/drivers/asahi/agx_pipe.c index 707f63fd654..5d449bd2e63 100644 --- a/src/gallium/drivers/asahi/agx_pipe.c +++ b/src/gallium/drivers/asahi/agx_pipe.c @@ -527,6 +527,27 @@ agx_transfer_flush_region(struct pipe_context *pipe, { } +/* + * Perform the required synchronization before a transfer_map operation can + * complete. This may require flushing batches. + */ +static void +agx_prepare_for_map(struct agx_context *ctx, + struct agx_resource *rsrc, + unsigned level, + unsigned usage, /* a combination of PIPE_MAP_x */ + const struct pipe_box *box) +{ + /* If the access is unsynchronized, there's nothing to do */ + if (usage & PIPE_MAP_UNSYNCHRONIZED) + return; + + agx_flush_writer(ctx, rsrc, "Unsynchronized transfer"); + + if (usage & PIPE_MAP_WRITE) + agx_flush_readers(ctx, rsrc, "Unsynchronized read"); +} + static void * agx_transfer_map(struct pipe_context *pctx, struct pipe_resource *resource, @@ -542,13 +563,7 @@ agx_transfer_map(struct pipe_context *pctx, if ((usage & PIPE_MAP_DIRECTLY) && rsrc->modifier != DRM_FORMAT_MOD_LINEAR) return NULL; - /* Synchronize */ - if (!(usage & PIPE_MAP_UNSYNCHRONIZED)) { - agx_flush_writer(ctx, rsrc, "Unsynchronized transfer"); - - if (usage & PIPE_MAP_WRITE) - agx_flush_readers(ctx, rsrc, "Unsynchronized read"); - } + agx_prepare_for_map(ctx, rsrc, level, usage, box); struct agx_transfer *transfer = CALLOC_STRUCT(agx_transfer); transfer->base.level = level;