From caf2a7724fc1720cd7191726bf05ff897c98ef7e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 13 Oct 2024 14:19:53 -0400 Subject: [PATCH] vulkan: Avoid a validation error If vkAcquireNextImageKHR returns VK_SUBOPTIMAL_KHR, the semaphore is in use, but vkDeviceWaitIdle will not wait for it, since it is not associated with a queue. Make sure that is the case, so we don't run into a validation error when we try vkAcquireNextImageKHR with the same semaphore, after recreating the swap chain. See https://github.com/KhronosGroup/Vulkan-Docs/issues/1059 for some related discussion. Fixes: #7079 --- gdk/gdkvulkancontext.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gdk/gdkvulkancontext.c b/gdk/gdkvulkancontext.c index e7214a9be7..919f01dfc3 100644 --- a/gdk/gdkvulkancontext.c +++ b/gdk/gdkvulkancontext.c @@ -698,6 +698,22 @@ gdk_vulkan_context_begin_frame (GdkDrawContext *draw_context, { GError *error = NULL; + if (acquire_result == VK_SUBOPTIMAL_KHR) + { + const VkPipelineStageFlags mask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; + + vkQueueSubmit (gdk_vulkan_context_get_queue (context), + 1, + &(VkSubmitInfo) { + .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, + .waitSemaphoreCount = 1, + .pWaitSemaphores = &priv->draw_semaphore, + .pWaitDstStageMask = &mask, + }, + VK_NULL_HANDLE); + vkQueueWaitIdle (gdk_vulkan_context_get_queue (context)); + } + if (gdk_vulkan_context_check_swapchain (context, &error)) continue;