From 445dd1906fa728964ab1c7799b4d76f2bb2378df Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Sun, 6 Sep 2020 11:57:06 -0400 Subject: [PATCH] zink: handle PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE in transfer_map for buffers when discarding the whole resource on an unused resource, we can deinit the buffer range here in the future, ideally we should be doing something like creating a new vk buffer/image entirely here and demoting the existing one to a queue that destroys/caches it when the batch finishes in order to avoid fencing Reviewed-by: Dave Airlie Part-of: --- src/gallium/drivers/zink/zink_resource.c | 30 ++++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/gallium/drivers/zink/zink_resource.c b/src/gallium/drivers/zink/zink_resource.c index a7f11ed7c23..7930a281518 100644 --- a/src/gallium/drivers/zink/zink_resource.c +++ b/src/gallium/drivers/zink/zink_resource.c @@ -568,21 +568,25 @@ zink_transfer_map(struct pipe_context *pctx, void *ptr; if (pres->target == PIPE_BUFFER) { - if (!(usage & PIPE_MAP_UNSYNCHRONIZED) && util_ranges_intersect(&res->valid_buffer_range, box->x, box->x + box->width)) { - /* special case compute reads since they aren't handled by zink_fence_wait() */ - if (usage & PIPE_MAP_WRITE && (batch_uses & (ZINK_RESOURCE_ACCESS_READ << ZINK_COMPUTE_BATCH_ID))) - 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); - 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 - * mesa/mesa#2966 - */ + if (!(usage & PIPE_MAP_UNSYNCHRONIZED)) { + if (util_ranges_intersect(&res->valid_buffer_range, box->x, box->x + box->width)) { + /* special case compute reads since they aren't handled by zink_fence_wait() */ + if (usage & PIPE_MAP_WRITE && (batch_uses & (ZINK_RESOURCE_ACCESS_READ << ZINK_COMPUTE_BATCH_ID))) + 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); + 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 + * mesa/mesa#2966 + */ - zink_fence_wait(pctx); + zink_fence_wait(pctx); + } } + if (usage & PIPE_MAP_DISCARD_WHOLE_RESOURCE) + util_range_set_empty(&res->valid_buffer_range); }