Skip to content

Commit

Permalink
- recreate Vulkan swapchain in case of surface lost error
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alexey-lysiuk committed Aug 2, 2019
1 parent 154af34 commit 5870cb7
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/rendering/vulkan/system/vk_swapchain.cpp
Expand Up @@ -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.
Expand All @@ -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");
Expand All @@ -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;
Expand All @@ -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");
Expand Down

0 comments on commit 5870cb7

Please sign in to comment.