From 59904faff43d87b264931ff8a483380e8a017ed2 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 11 Apr 2019 05:28:37 +0200 Subject: [PATCH] - slightly adjust AcquireImage to avoid border cases in the spec --- src/rendering/vulkan/system/vk_swapchain.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/rendering/vulkan/system/vk_swapchain.cpp b/src/rendering/vulkan/system/vk_swapchain.cpp index bcdb1c36a..473d256ee 100644 --- a/src/rendering/vulkan/system/vk_swapchain.cpp +++ b/src/rendering/vulkan/system/vk_swapchain.cpp @@ -40,15 +40,23 @@ uint32_t VulkanSwapChain::AcquireImage(int width, int height, VulkanSemaphore *s } VkResult result = vkAcquireNextImageKHR(device->device, swapChain, 1'000'000'000, semaphore ? semaphore->semaphore : VK_NULL_HANDLE, fence ? fence->fence : VK_NULL_HANDLE, &imageIndex); - if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || result == VK_TIMEOUT) - { - Recreate(); - } - else if (result == VK_SUCCESS) + if (result == VK_SUCCESS) { break; } - else if (result == VK_NOT_READY) + else if (result == VK_SUBOPTIMAL_KHR) + { + // Force the recreate to happen next frame. + // The spec is not very clear about what happens to the semaphore or the acquired image if the swapchain is recreated before the image is released with a call to vkQueuePresentKHR. + lastSwapWidth = 0; + lastSwapHeight = 0; + break; + } + else if (result == VK_ERROR_OUT_OF_DATE_KHR) + { + Recreate(); + } + else if (result == VK_NOT_READY || result == VK_TIMEOUT) { imageIndex = 0xffffffff; break;