From a267c5641203e36d4d10ddf75e94bbe33a9e6c7b Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Mon, 30 Sep 2024 22:00:41 -0500 Subject: [PATCH] VideoBackends:Vulkan: Wait until we've confirmed a successful AcquireNextImage before marking semaphores used --- .../VideoBackends/Vulkan/CommandBufferManager.h | 13 ++++++++++--- Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Source/Core/VideoBackends/Vulkan/CommandBufferManager.h b/Source/Core/VideoBackends/Vulkan/CommandBufferManager.h index d92cab4a49..c6f167cf38 100644 --- a/Source/Core/VideoBackends/Vulkan/CommandBufferManager.h +++ b/Source/Core/VideoBackends/Vulkan/CommandBufferManager.h @@ -63,11 +63,18 @@ public: // Returns the semaphore for the current command buffer, which can be used to ensure the // swap chain image is ready before the command buffer executes. + // Once you've confirmed that the semaphore will be signalled this frame, call + // `MarkCurrentCommandBufferSemaphoreUsed`. VkSemaphore GetCurrentCommandBufferSemaphore() { - auto& resources = m_command_buffers[m_current_cmd_buffer]; - resources.semaphore_used = true; - return resources.semaphore; + return m_command_buffers[m_current_cmd_buffer].semaphore; + } + + // Marks the current command buffer's semaphore as used, so we'll wait on it in the next + // command buffer submission. + void MarkCurrentCommandBufferSemaphoreUsed() + { + m_command_buffers[m_current_cmd_buffer].semaphore_used = true; } // Ensure that the worker thread has submitted any previous command buffers and is idle. diff --git a/Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp b/Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp index e94d8e52cb..1005cc034a 100644 --- a/Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp +++ b/Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp @@ -498,6 +498,8 @@ VkResult SwapChain::AcquireNextImage() g_command_buffer_mgr->GetCurrentCommandBufferSemaphore(), VK_NULL_HANDLE, &m_current_swap_chain_image_index); m_current_swap_chain_image_is_valid = res >= 0; + if (IsCurrentImageValid()) + g_command_buffer_mgr->MarkCurrentCommandBufferSemaphoreUsed(); if (res != VK_SUCCESS && res != VK_ERROR_OUT_OF_DATE_KHR && res != VK_SUBOPTIMAL_KHR) LOG_VULKAN_ERROR(res, "vkAcquireNextImageKHR failed: ");