From af3f6bf8274080272dc188405d050d9cd24ac352 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Thu, 14 Sep 2023 18:53:38 +0100 Subject: [PATCH] rendervulkan: ensure queue is idle before swapchain recreation The CVulkanDevice::waitIdle call at the beginning of vulkan_remake_swapchain only waits for the most recently submitted command buffer to complete. This is inadequate because it does not wait for any additional commands which may have been submitted by the driver during vkQueuePresentKHR. Such commands could reference resources associated with the old swapchain, so it is not safe to destroy it until they are also complete. To fix the issue, instead of calling CVulkanDevice::waitIdle, vulkan_remake_swapchain will call vkQueueWaitIdle. Fixes: #945 Co-authored-by: Erik Kurzinger --- src/rendervulkan.cpp | 1 + src/rendervulkan.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp index 262c771..a269a3b 100644 --- a/src/rendervulkan.cpp +++ b/src/rendervulkan.cpp @@ -2694,6 +2694,7 @@ bool vulkan_remake_swapchain( void ) { VulkanOutput_t *pOutput = &g_output; g_device.waitIdle(); + g_device.vk.QueueWaitIdle( g_device.queue() ); pOutput->outputImages.clear(); diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp index 68738a7..9081bf5 100644 --- a/src/rendervulkan.hpp +++ b/src/rendervulkan.hpp @@ -647,6 +647,7 @@ static inline uint32_t div_roundup(uint32_t x, uint32_t y) VK_FUNC(MapMemory) \ VK_FUNC(QueuePresentKHR) \ VK_FUNC(QueueSubmit) \ + VK_FUNC(QueueWaitIdle) \ VK_FUNC(ResetCommandBuffer) \ VK_FUNC(ResetFences) \ VK_FUNC(UnmapMemory) \