From babf9474c4373c22f05dbfabbfe04634dd469b12 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Wed, 21 Sep 2022 09:07:35 -0400 Subject: [PATCH] zink: rework flush_frontbuffer to always flush previously this would no-op unacquired swapchains and then try to execute a copy from the last-presented swapchain image to the current image to avoid presenting garbage data instead, just present garbage like the app requested fixes #7165 Tested-By: Matti Hamalainen Reviewed-by: Adam Jackson Part-of: --- src/gallium/drivers/zink/zink_screen.c | 27 ++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/gallium/drivers/zink/zink_screen.c b/src/gallium/drivers/zink/zink_screen.c index f7a84f2c879..52ca07929fc 100644 --- a/src/gallium/drivers/zink/zink_screen.c +++ b/src/gallium/drivers/zink/zink_screen.c @@ -1496,12 +1496,21 @@ zink_flush_frontbuffer(struct pipe_screen *pscreen, struct zink_resource *res = zink_resource(pres); struct zink_context *ctx = zink_context(pctx); - /* if the surface has never been acquired, there's nothing to present, - * so this is a no-op */ - if (!zink_is_swapchain(res) || (!zink_kopper_acquired(res->obj->dt, res->obj->dt_idx) && res->obj->last_dt_idx == UINT32_MAX)) + /* if the surface is no longer a swapchain, this is a no-op */ + if (!zink_is_swapchain(res)) return; ctx = zink_tc_context_unwrap(pctx); + + if (!zink_kopper_acquired(res->obj->dt, res->obj->dt_idx)) { + /* swapbuffers to an undefined surface: acquire and present garbage */ + zink_kopper_acquire(ctx, res, UINT64_MAX); + ctx->needs_present = res; + /* set batch usage to submit acquire semaphore */ + zink_batch_resource_usage_set(&ctx->batch, res, true, false); + } + + /* handle any outstanding acquire submits (not just from above) */ if (ctx->batch.swapchain || ctx->needs_present) { ctx->batch.has_work = true; pctx->flush(pctx, NULL, PIPE_FLUSH_END_OF_FRAME); @@ -1511,15 +1520,9 @@ zink_flush_frontbuffer(struct pipe_screen *pscreen, } } - if (zink_kopper_acquired(res->obj->dt, res->obj->dt_idx)) - zink_kopper_present_queue(screen, res); - else { - assert(res->obj->last_dt_idx != UINT32_MAX); - if (!zink_kopper_last_present_eq(res->obj->dt, res->obj->last_dt_idx)) { - zink_kopper_acquire_readback(ctx, res); - zink_kopper_present_readback(ctx, res); - } - } + /* always verify that this was acquired */ + assert(zink_kopper_acquired(res->obj->dt, res->obj->dt_idx)); + zink_kopper_present_queue(screen, res); } bool