zink/kopper: Wait for last QueuePresentKHR to finish before acquiring for readback

When a job is submitted to the flush_queue the resource dt_idx is reset,
and if a readback is requested then we have to make sure that the
corresponding kopper_preset has finished before we can acquire the image
for readback, so wait for the according fence in this case.

This fixes the validation error UNASSIGNED-Threading-MultipleThreads-Write
    triggered by piglit "read-front" lavapipe.

    Fixes: 8ade5588e3
        zink: add kopper api

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28127>
This commit is contained in:
Gert Wollny 2024-04-08 22:28:52 +02:00 committed by Marge Bot
parent fd392745c2
commit 811ed62865

View file

@ -954,8 +954,21 @@ zink_kopper_acquire_readback(struct zink_context *ctx, struct zink_resource *res
}
while (res->obj->dt_idx != last_dt_idx) {
cdt->age_locked = true;
if (res->obj->dt_idx != UINT32_MAX && !zink_kopper_present_readback(ctx, res))
break;
if (res->obj->dt_idx != UINT32_MAX) {
if (!zink_kopper_present_readback(ctx, res))
break;
} else if (util_queue_is_initialized(&screen->flush_queue)) {
/* AcquireNextImageKHR and QueuePresentKHR both access the swapchain, and
* if res->obj->dt_idx == UINT32_MAX then zink_kopper_present_readback is
* not called and we don't wait for the cdt->swapchain->present_fence.
* Still, a kopper_present might have been called in another thread, like
* e.g. with spec@!opengl 1.1@read-front, so we have to wait until the
* last call to QueuePresentKHR is finished to avoid an
* UNASSIGNED-Threading-MultipleThreads-Write
* validation error that indicats a race condition when accessing the swapchain.
*/
util_queue_fence_wait(&cdt->swapchain->present_fence);
}
cdt->age_locked = true;
do {
ret = kopper_acquire(screen, res, 0);