From 2e8e6088b3628e570e84975b252da39911841365 Mon Sep 17 00:00:00 2001 From: Yamagi Date: Sun, 25 Apr 2021 09:55:05 +0200 Subject: [PATCH] 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. --- src/client/refresh/vk/vk_common.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/client/refresh/vk/vk_common.c b/src/client/refresh/vk/vk_common.c index b2308113..ecb68768 100644 --- a/src/client/refresh/vk/vk_common.c +++ b/src/client/refresh/vk/vk_common.c @@ -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