VulkanDevice: Actually use all the swap chain semaphores

This commit is contained in:
Stenzek 2024-03-01 00:50:22 +10:00
parent edeaaebc7d
commit b060edc61b
No known key found for this signature in database
3 changed files with 9 additions and 5 deletions

View File

@ -1272,7 +1272,7 @@ void VulkanDevice::SubmitCommandBuffer(VulkanSwapChain* present_swap_chain /* =
{ {
DoSubmitCommandBuffer(m_current_frame, present_swap_chain); DoSubmitCommandBuffer(m_current_frame, present_swap_chain);
if (present_swap_chain) if (present_swap_chain)
DoPresent(present_swap_chain); DoPresent(present_swap_chain, false);
return; return;
} }
@ -1317,7 +1317,7 @@ void VulkanDevice::DoSubmitCommandBuffer(u32 index, VulkanSwapChain* present_swa
} }
} }
void VulkanDevice::DoPresent(VulkanSwapChain* present_swap_chain) void VulkanDevice::DoPresent(VulkanSwapChain* present_swap_chain, bool acquire_next)
{ {
const VkPresentInfoKHR present_info = {VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, const VkPresentInfoKHR present_info = {VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
nullptr, nullptr,
@ -1344,7 +1344,8 @@ void VulkanDevice::DoPresent(VulkanSwapChain* present_swap_chain)
// Grab the next image as soon as possible, that way we spend less time blocked on the next // Grab the next image as soon as possible, that way we spend less time blocked on the next
// submission. Don't care if it fails, we'll deal with that at the presentation call site. // submission. Don't care if it fails, we'll deal with that at the presentation call site.
// Credit to dxvk for the idea. // Credit to dxvk for the idea.
present_swap_chain->AcquireNextImage(); if (acquire_next)
present_swap_chain->AcquireNextImage();
} }
void VulkanDevice::WaitForPresentComplete() void VulkanDevice::WaitForPresentComplete()
@ -1378,7 +1379,7 @@ void VulkanDevice::PresentThread()
DoSubmitCommandBuffer(m_queued_present.command_buffer_index, m_queued_present.swap_chain); DoSubmitCommandBuffer(m_queued_present.command_buffer_index, m_queued_present.swap_chain);
if (m_queued_present.swap_chain) if (m_queued_present.swap_chain)
DoPresent(m_queued_present.swap_chain); DoPresent(m_queued_present.swap_chain, true);
m_present_done.store(true, std::memory_order_release); m_present_done.store(true, std::memory_order_release);
m_present_done_cv.notify_one(); m_present_done_cv.notify_one();
} }

View File

@ -379,7 +379,7 @@ private:
void WaitForCommandBufferCompletion(u32 index); void WaitForCommandBufferCompletion(u32 index);
void DoSubmitCommandBuffer(u32 index, VulkanSwapChain* present_swap_chain); void DoSubmitCommandBuffer(u32 index, VulkanSwapChain* present_swap_chain);
void DoPresent(VulkanSwapChain* present_swap_chain); void DoPresent(VulkanSwapChain* present_swap_chain, bool acquire_next);
void WaitForPresentComplete(std::unique_lock<std::mutex>& lock); void WaitForPresentComplete(std::unique_lock<std::mutex>& lock);
void PresentThread(); void PresentThread();
void StartPresentThread(); void StartPresentThread();

View File

@ -598,6 +598,9 @@ VkResult VulkanSwapChain::AcquireNextImage()
if (!m_swap_chain) if (!m_swap_chain)
return VK_ERROR_SURFACE_LOST_KHR; return VK_ERROR_SURFACE_LOST_KHR;
// Use a different semaphore for each image.
m_current_semaphore = (m_current_semaphore + 1) % static_cast<u32>(m_semaphores.size());
const VkResult res = const VkResult res =
vkAcquireNextImageKHR(VulkanDevice::GetInstance().GetVulkanDevice(), m_swap_chain, UINT64_MAX, vkAcquireNextImageKHR(VulkanDevice::GetInstance().GetVulkanDevice(), m_swap_chain, UINT64_MAX,
m_semaphores[m_current_semaphore].available_semaphore, VK_NULL_HANDLE, &m_current_image); m_semaphores[m_current_semaphore].available_semaphore, VK_NULL_HANDLE, &m_current_image);