diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/SwapchainInfoVk.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/SwapchainInfoVk.cpp index 3007ea1a7..e76f95294 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/SwapchainInfoVk.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/SwapchainInfoVk.cpp @@ -149,7 +149,7 @@ void SwapchainInfoVk::Create() m_acquireIndex = 0; hasDefinedSwapchainImage = false; - m_numQueued = 0; + m_queueDepth = 0; } void SwapchainInfoVk::Cleanup() @@ -348,7 +348,7 @@ VkPresentModeKHR SwapchainInfoVk::ChoosePresentMode(const std::vector= chainInfo.m_maxQueued) + { + uint64 waitFrameId = chainInfo.m_presentId - chainInfo.m_queueDepth; + vkWaitForPresentKHR(m_logicalDevice, chainInfo.m_swapchain, waitFrameId, 40'000'000); + chainInfo.m_queueDepth--; + } + } + bool result = chainInfo.AcquireImage(); if (!result) return false; @@ -2677,6 +2687,11 @@ void VulkanRenderer::RecreateSwapchain(bool mainWindow, bool skipCreate) ImguiInit(); } +bool VulkanRenderer::UsePresentWait(const SwapchainInfoVk& chain) const +{ + return m_featureControl.deviceExtensions.present_wait && chain.m_maxQueued > 0; +} + bool VulkanRenderer::UpdateSwapchainProperties(bool mainWindow) { auto& chainInfo = GetChainInfo(mainWindow); @@ -2748,10 +2763,8 @@ void VulkanRenderer::SwapBuffer(bool mainWindow) presentInfo.waitSemaphoreCount = 1; presentInfo.pWaitSemaphores = &presentSemaphore; - const bool enablePresentWait = m_featureControl.deviceExtensions.present_wait && chainInfo.m_maxQueued != 0; - - // if present_wait is available, use it to limit CPU run-ahead - if (enablePresentWait) + // if present_wait is available and enabled, add frame markers to present requests + if (UsePresentWait(chainInfo)) { presentId.sType = VK_STRUCTURE_TYPE_PRESENT_ID_KHR; presentId.swapchainCount = 1; @@ -2768,16 +2781,10 @@ void VulkanRenderer::SwapBuffer(bool mainWindow) if(result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) chainInfo.m_shouldRecreate = true; - if(enablePresentWait && result == VK_SUCCESS) + if(result == VK_SUCCESS) { - chainInfo.m_numQueued++; + chainInfo.m_queueDepth++; chainInfo.m_presentId++; - if (chainInfo.m_numQueued > chainInfo.m_maxQueued) - { - uint64 waitFrameId = chainInfo.m_presentId - chainInfo.m_numQueued; - vkWaitForPresentKHR(m_logicalDevice, chainInfo.m_swapchain, waitFrameId, 40'000'000); - chainInfo.m_numQueued--; - } } diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h index 4111db532..f92048b5f 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h @@ -552,6 +552,7 @@ class VulkanRenderer : public Renderer VkPipeline backbufferBlit_createGraphicsPipeline(VkDescriptorSetLayout descriptorLayout, bool padView, RendererOutputShader* shader); bool AcquireNextSwapchainImage(bool mainWindow); void RecreateSwapchain(bool mainWindow, bool skipCreate = false); + bool UsePresentWait(const SwapchainInfoVk& chain) const; // streamout void streamout_setupXfbBuffer(uint32 bufferIndex, sint32 ringBufferOffset, uint32 rangeAddr, uint32 rangeSize) override;