Add logic to prevent Vulkan restart loops.

So far I haven't seen a restart loop, but at least in theory they'e
possible. Because its hard to break out of such loop, especially on
Windows were interaction with the taskmanager is required, play save
and restart max. 3 times in a row.
This commit is contained in:
Yamagi 2021-04-25 09:55:05 +02:00
parent 950ec0d67e
commit 2e8e6088b3

View file

@ -2071,9 +2071,19 @@ VkResult QVk_BeginFrame(const VkViewport* viewport, const VkRect2D* scissor)
ReleaseSwapBuffers();
static int restartcount;
VkResult result = vkAcquireNextImageKHR(vk_device.logical, vk_swapchain.sc, 500000000, vk_imageAvailableSemaphores[vk_activeBufferIdx], VK_NULL_HANDLE, &vk_imageIndex);
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || result == VK_ERROR_SURFACE_LOST_KHR || result == VK_TIMEOUT)
{
if (restartcount > 2)
{
Sys_Error("%s(): tried to restart 3 times after vkAcquireNextImageKHR: %s", __func__, QVk_GetError(result));
}
else
{
restartcount++;
}
// for VK_OUT_OF_DATE_KHR and VK_SUBOPTIMAL_KHR it'd be fine to just rebuild the swapchain but let's take the easy way out and restart Vulkan.
R_Printf(PRINT_ALL, "%s(): received %s after vkAcquireNextImageKHR - restarting video!\n", __func__, QVk_GetError(result));
return result;
@ -2083,6 +2093,7 @@ VkResult QVk_BeginFrame(const VkViewport* viewport, const VkRect2D* scissor)
Sys_Error("%s(): unexpected error after vkAcquireNextImageKHR: %s", __func__, QVk_GetError(result));
}
restartcount = 0;
vk_activeCmdbuffer = vk_commandbuffers[vk_activeBufferIdx];
// swap dynamic buffers