diff --git a/.pick_status.json b/.pick_status.json index 8bf2b21fc0bf..0c0f19d32fd0 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -2533,7 +2533,7 @@ "description": "zink: flag batch usage on swapchain images", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "dc8c9d20568360d6756dcd62610d818991f479d8" }, diff --git a/src/gallium/drivers/zink/zink_batch.c b/src/gallium/drivers/zink/zink_batch.c index 01ab10055cc2..ca311daa5858 100644 --- a/src/gallium/drivers/zink/zink_batch.c +++ b/src/gallium/drivers/zink/zink_batch.c @@ -48,6 +48,8 @@ reset_obj(struct zink_screen *screen, struct zink_batch_state *bs, struct zink_r obj->view_prune_count = 0; obj->view_prune_timeline = 0; simple_mtx_unlock(&obj->view_lock); + if (obj->dt) + zink_kopper_prune_batch_usage(obj->dt, &bs->usage); } else if (util_dynarray_num_elements(&obj->views, VkBufferView) > MAX_VIEW_COUNT && !zink_bo_has_unflushed_usage(obj->bo)) { /* avoid ballooning from too many views on always-used resources: */ simple_mtx_lock(&obj->view_lock); diff --git a/src/gallium/drivers/zink/zink_kopper.c b/src/gallium/drivers/zink/zink_kopper.c index 19ec729653f6..b709fb10cf87 100644 --- a/src/gallium/drivers/zink/zink_kopper.c +++ b/src/gallium/drivers/zink/zink_kopper.c @@ -174,6 +174,15 @@ prune_old_swapchains(struct zink_screen *screen, struct kopper_displaytarget *cd continue; return; } + struct zink_batch_usage *u = cswap->batch_uses; + if (!zink_screen_usage_check_completion(screen, u)) { + /* these can't ever be pruned */ + if (!wait || zink_batch_usage_is_unflushed(u)) + return; + + zink_screen_timeline_wait(screen, u->usage, UINT64_MAX); + cswap->batch_uses = NULL; + } cdt->old_swapchain = cswap->next; destroy_swapchain(screen, cswap); } @@ -597,7 +606,9 @@ zink_kopper_acquire(struct zink_context *ctx, struct zink_resource *res, uint64_ } else if (is_swapchain_kill(ret)) { kill_swapchain(ctx, res); } - return !is_swapchain_kill(ret); + bool is_kill = is_swapchain_kill(ret); + zink_batch_usage_set(&cdt->swapchain->batch_uses, ctx->batch.state); + return !is_kill; } VkSemaphore @@ -822,6 +833,7 @@ zink_kopper_acquire_readback(struct zink_context *ctx, struct zink_resource *res res->base.b.width0 = ctx->swapchain_size.width; res->base.b.height0 = ctx->swapchain_size.height; } + zink_batch_usage_set(&cdt->swapchain->batch_uses, ctx->batch.state); return true; } @@ -972,3 +984,19 @@ zink_kopper_query_buffer_age(struct pipe_context *pctx, struct pipe_resource *pr return cdt->swapchain->images[res->obj->dt_idx].age; } + +static void +swapchain_prune_batch_usage(struct kopper_swapchain *cswap, const struct zink_batch_usage *u) +{ + if (cswap->batch_uses == u) + cswap->batch_uses = NULL; +} + +void +zink_kopper_prune_batch_usage(struct kopper_displaytarget *cdt, const struct zink_batch_usage *u) +{ + struct kopper_swapchain *cswap = cdt->swapchain; + swapchain_prune_batch_usage(cswap, u); + for (cswap = cdt->old_swapchain; cswap; cswap = cswap->next) + swapchain_prune_batch_usage(cswap, u); +} diff --git a/src/gallium/drivers/zink/zink_kopper.h b/src/gallium/drivers/zink/zink_kopper.h index 857a9cd5a5d1..4b7d2d62ddfb 100644 --- a/src/gallium/drivers/zink/zink_kopper.h +++ b/src/gallium/drivers/zink/zink_kopper.h @@ -34,6 +34,8 @@ extern "C" { #endif +struct zink_batch_usage; + struct kopper_swapchain_image { bool init; bool acquired; @@ -56,6 +58,7 @@ struct kopper_swapchain { unsigned num_acquires; unsigned max_acquires; unsigned async_presents; + struct zink_batch_usage *batch_uses; struct kopper_swapchain_image *images; }; @@ -146,6 +149,8 @@ void zink_kopper_set_swap_interval(struct pipe_screen *pscreen, struct pipe_resource *pres, int interval); int zink_kopper_query_buffer_age(struct pipe_context *pctx, struct pipe_resource *pres); +void +zink_kopper_prune_batch_usage(struct kopper_displaytarget *cdt, const struct zink_batch_usage *u); #ifdef __cplusplus }