From f6c6320a5f4379f92423c7d33e925818d2451a13 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Thu, 8 Oct 2020 14:16:40 -0400 Subject: [PATCH] zink: break out batch id finding for resource usage into util function this is generally helpful for figuring out the last batch a resource was used for Reviewed-by: Dave Airlie Part-of: --- src/gallium/drivers/zink/zink_resource.c | 31 ++++++++++++++++++++++++------- src/gallium/drivers/zink/zink_resource.h | 3 +++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/gallium/drivers/zink/zink_resource.c b/src/gallium/drivers/zink/zink_resource.c index a23361f..a7ce6e4 100644 --- a/src/gallium/drivers/zink/zink_resource.c +++ b/src/gallium/drivers/zink/zink_resource.c @@ -48,23 +48,40 @@ #endif static void -resource_sync_writes_from_batch_id(struct zink_context *ctx, uint32_t batch_uses, unsigned cur_batch) +resource_sync_writes_from_batch_usage(struct zink_context *ctx, uint32_t batch_uses) { + uint32_t write_mask = 0; + for (int i = 0; i < ZINK_NUM_GFX_BATCHES + ZINK_COMPUTE_BATCH_COUNT; i++) + write_mask |= ZINK_RESOURCE_ACCESS_WRITE << i; + while (batch_uses & write_mask) { + int batch_id = zink_get_resource_latest_batch_usage(ctx, batch_uses); + if (batch_id == -1) + break; + zink_wait_on_batch(ctx, batch_id); + batch_uses &= ~((ZINK_RESOURCE_ACCESS_READ | ZINK_RESOURCE_ACCESS_WRITE) << batch_id); + } +} + +int +zink_get_resource_latest_batch_usage(struct zink_context *ctx, uint32_t batch_uses) +{ + unsigned cur_batch = zink_curr_batch(ctx)->batch_id; + if (batch_uses & ZINK_RESOURCE_ACCESS_WRITE << ZINK_COMPUTE_BATCH_ID) - zink_wait_on_batch(ctx, ZINK_COMPUTE_BATCH_ID); + return ZINK_COMPUTE_BATCH_ID; batch_uses &= ~(ZINK_RESOURCE_ACCESS_WRITE << ZINK_COMPUTE_BATCH_ID); if (!batch_uses) - return; + return -1; for (unsigned i = 0; i < ZINK_NUM_BATCHES + 1; i++) { /* loop backwards and sync with highest batch id that has writes */ if (batch_uses & (ZINK_RESOURCE_ACCESS_WRITE << cur_batch)) { - zink_wait_on_batch(ctx, cur_batch); - break; + return cur_batch; } cur_batch--; if (cur_batch > ZINK_COMPUTE_BATCH_ID - 1) // underflowed past max batch id cur_batch = ZINK_COMPUTE_BATCH_ID - 1; } + return -1; } static uint32_t @@ -585,7 +602,7 @@ zink_transfer_map(struct pipe_context *pctx, zink_wait_on_batch(ctx, ZINK_COMPUTE_BATCH_ID); batch_uses &= ~(ZINK_RESOURCE_ACCESS_READ << ZINK_COMPUTE_BATCH_ID); if (usage & PIPE_MAP_READ && batch_uses >= ZINK_RESOURCE_ACCESS_WRITE) - resource_sync_writes_from_batch_id(ctx, batch_uses, zink_curr_batch(ctx)->batch_id); + resource_sync_writes_from_batch_usage(ctx, batch_uses); else if (usage & PIPE_MAP_WRITE && batch_uses) { /* need to wait for all rendering to finish * TODO: optimize/fix this to be much less obtrusive @@ -689,7 +706,7 @@ zink_transfer_map(struct pipe_context *pctx, batch_uses &= ~(ZINK_RESOURCE_ACCESS_READ << ZINK_COMPUTE_BATCH_ID); if (batch_uses >= ZINK_RESOURCE_ACCESS_WRITE) { if (usage & PIPE_MAP_READ) - resource_sync_writes_from_batch_id(ctx, batch_uses, zink_curr_batch(ctx)->batch_id); + resource_sync_writes_from_batch_usage(ctx, batch_uses); else zink_fence_wait(pctx); } diff --git a/src/gallium/drivers/zink/zink_resource.h b/src/gallium/drivers/zink/zink_resource.h index 9f2d023..36d35b1 100644 --- a/src/gallium/drivers/zink/zink_resource.h +++ b/src/gallium/drivers/zink/zink_resource.h @@ -106,6 +106,9 @@ zink_get_depth_stencil_resources(struct pipe_resource *res, void zink_resource_setup_transfer_layouts(struct zink_context *ctx, struct zink_resource *src, struct zink_resource *dst); +int +zink_get_resource_latest_batch_usage(struct zink_context *ctx, uint32_t batch_uses); + uint32_t zink_get_resource_usage(struct zink_resource *res); -- 2.7.4