From 5870cb7ea1ff5a4d902a7e77c12737b841b0997a Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Fri, 2 Aug 2019 10:21:06 +0300 Subject: [PATCH] - recreate Vulkan swapchain in case of surface lost error Do not abort with fatal error when VK_ERROR_SURFACE_LOST_KHR was returned from vkAcquireNextImageKHR() or vkQueuePresentKHR() So far, only gfx-portability implementation is reporting this error from time to time, usually on startup, entering the game, or task switching --- src/rendering/vulkan/system/vk_swapchain.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/rendering/vulkan/system/vk_swapchain.cpp b/src/rendering/vulkan/system/vk_swapchain.cpp index f5ca6599b..5f331bedc 100644 --- a/src/rendering/vulkan/system/vk_swapchain.cpp +++ b/src/rendering/vulkan/system/vk_swapchain.cpp @@ -44,7 +44,7 @@ uint32_t VulkanSwapChain::AcquireImage(int width, int height, VulkanSemaphore *s { break; } - else if (result == VK_SUBOPTIMAL_KHR) + else if (result == VK_SUBOPTIMAL_KHR || result == VK_ERROR_SURFACE_LOST_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. @@ -69,10 +69,6 @@ uint32_t VulkanSwapChain::AcquireImage(int width, int height, VulkanSemaphore *s { VulkanError("vkAcquireNextImageKHR failed: device lost"); } - else if (result == VK_ERROR_SURFACE_LOST_KHR) - { - VulkanError("vkAcquireNextImageKHR failed: surface lost"); - } else { VulkanError("vkAcquireNextImageKHR failed"); @@ -92,7 +88,7 @@ void VulkanSwapChain::QueuePresent(uint32_t imageIndex, VulkanSemaphore *semapho presentInfo.pImageIndices = &imageIndex; presentInfo.pResults = nullptr; VkResult result = vkQueuePresentKHR(device->presentQueue, &presentInfo); - if (result == VK_SUBOPTIMAL_KHR || result == VK_ERROR_OUT_OF_DATE_KHR) + if (result == VK_SUBOPTIMAL_KHR || result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_ERROR_SURFACE_LOST_KHR) { lastSwapWidth = 0; lastSwapHeight = 0; @@ -108,10 +104,6 @@ void VulkanSwapChain::QueuePresent(uint32_t imageIndex, VulkanSemaphore *semapho { VulkanError("vkQueuePresentKHR failed: device lost"); } - else if (result == VK_ERROR_SURFACE_LOST_KHR) - { - VulkanError("vkQueuePresentKHR failed: surface lost"); - } else if (result != VK_SUCCESS) { VulkanError("vkQueuePresentKHR failed");