Skip to content

Commit

Permalink
I've made up my mind. This is right.
Browse files Browse the repository at this point in the history
  • Loading branch information
goeiecool9999 committed Aug 14, 2024
1 parent 32c57f6 commit 3bcbb0a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Cafe/HW/Latte/Renderer/Vulkan/SwapchainInfoVk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ VkPresentModeKHR SwapchainInfoVk::ChoosePresentMode(const std::vector<VkPresentM
return VK_PRESENT_MODE_FIFO_KHR;
}

m_maxQueued = 2;
m_maxQueued = 1;
return VK_PRESENT_MODE_FIFO_KHR;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Cafe/HW/Latte/Renderer/Vulkan/SwapchainInfoVk.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ struct SwapchainInfoVk
Vector2i m_desiredExtent{};
uint32 swapchainImageIndex = (uint32)-1;
uint64 m_presentId = 1;
uint64 m_queueDepth = 0; // number of frames finished on the CPU, with submitted work and presentation requests
uint64 m_maxQueued = 0; // maximum number of frames that should be "in-flight" at a time
uint64 m_queueDepth = 0; // number of frames with pending presentation requests
uint64 m_maxQueued = 0; // the maximum number of frames with presentation requests.


// swapchain image ringbuffer (indexed by swapchainImageIndex)
Expand Down
26 changes: 9 additions & 17 deletions src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2640,16 +2640,6 @@ bool VulkanRenderer::AcquireNextSwapchainImage(bool mainWindow)
if (!UpdateSwapchainProperties(mainWindow))
return false;

if(UsePresentWait(chainInfo))
{
if(chainInfo.m_queueDepth + 1 >= 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;
Expand Down Expand Up @@ -2687,11 +2677,6 @@ 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);
Expand Down Expand Up @@ -2764,13 +2749,21 @@ void VulkanRenderer::SwapBuffer(bool mainWindow)
presentInfo.pWaitSemaphores = &presentSemaphore;

// if present_wait is available and enabled, add frame markers to present requests
if (UsePresentWait(chainInfo))
// and limit the number of queued present operations
if (m_featureControl.deviceExtensions.present_wait && chainInfo.m_maxQueued > 0)
{
presentId.sType = VK_STRUCTURE_TYPE_PRESENT_ID_KHR;
presentId.swapchainCount = 1;
presentId.pPresentIds = &chainInfo.m_presentId;

presentInfo.pNext = &presentId;

if(chainInfo.m_queueDepth + 1 >= chainInfo.m_maxQueued)
{
uint64 waitFrameId = chainInfo.m_presentId - chainInfo.m_queueDepth;
vkWaitForPresentKHR(m_logicalDevice, chainInfo.m_swapchain, waitFrameId, 40'000'000);
chainInfo.m_queueDepth--;
}
}

VkResult result = vkQueuePresentKHR(m_presentQueue, &presentInfo);
Expand All @@ -2787,7 +2780,6 @@ void VulkanRenderer::SwapBuffer(bool mainWindow)
chainInfo.m_presentId++;
}


chainInfo.hasDefinedSwapchainImage = false;

chainInfo.swapchainImageIndex = -1;
Expand Down
1 change: 0 additions & 1 deletion src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ 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;
Expand Down

0 comments on commit 3bcbb0a

Please sign in to comment.