@@ -1665,7 +1665,6 @@ bool VulkanRenderer::ImguiBegin(bool mainWindow)
1665
1665
draw_endRenderPass ();
1666
1666
m_state.currentPipeline = VK_NULL_HANDLE;
1667
1667
1668
- chainInfo.WaitAvailableFence ();
1669
1668
ImGui_ImplVulkan_CreateFontsTexture (m_state.currentCommandBuffer );
1670
1669
ImGui_ImplVulkan_NewFrame (m_state.currentCommandBuffer , chainInfo.m_swapchainFramebuffers [chainInfo.swapchainImageIndex ], chainInfo.getExtent ());
1671
1670
ImGui_UpdateWindowInformation (mainWindow);
@@ -1722,7 +1721,6 @@ bool VulkanRenderer::BeginFrame(bool mainWindow)
1722
1721
1723
1722
auto & chainInfo = GetChainInfo (mainWindow);
1724
1723
1725
- chainInfo.WaitAvailableFence ();
1726
1724
VkClearColorValue clearColor{ 0 , 0 , 0 , 0 };
1727
1725
ClearColorImageRaw (chainInfo.m_swapchainImages [chainInfo.swapchainImageIndex ], 0 , 0 , clearColor, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
1728
1726
@@ -1848,7 +1846,7 @@ void VulkanRenderer::WaitForNextFinishedCommandBuffer()
1848
1846
ProcessFinishedCommandBuffers ();
1849
1847
}
1850
1848
1851
- void VulkanRenderer::SubmitCommandBuffer (VkSemaphore* signalSemaphore, VkSemaphore* waitSemaphore)
1849
+ void VulkanRenderer::SubmitCommandBuffer (VkSemaphore signalSemaphore, VkSemaphore waitSemaphore)
1852
1850
{
1853
1851
draw_endRenderPass ();
1854
1852
@@ -1863,11 +1861,11 @@ void VulkanRenderer::SubmitCommandBuffer(VkSemaphore* signalSemaphore, VkSemapho
1863
1861
1864
1862
// signal current command buffer semaphore
1865
1863
VkSemaphore signalSemArray[2 ];
1866
- if (signalSemaphore)
1864
+ if (signalSemaphore != VK_NULL_HANDLE )
1867
1865
{
1868
1866
submitInfo.signalSemaphoreCount = 2 ;
1869
1867
signalSemArray[0 ] = m_commandBufferSemaphores[m_commandBufferIndex]; // signal current
1870
- signalSemArray[1 ] = * signalSemaphore; // signal current
1868
+ signalSemArray[1 ] = signalSemaphore; // signal current
1871
1869
submitInfo.pSignalSemaphores = signalSemArray;
1872
1870
}
1873
1871
else
@@ -1883,8 +1881,8 @@ void VulkanRenderer::SubmitCommandBuffer(VkSemaphore* signalSemaphore, VkSemapho
1883
1881
submitInfo.waitSemaphoreCount = 0 ;
1884
1882
if (m_numSubmittedCmdBuffers > 0 )
1885
1883
waitSemArray[submitInfo.waitSemaphoreCount ++] = prevSem; // wait on semaphore from previous submit
1886
- if (waitSemaphore)
1887
- waitSemArray[submitInfo.waitSemaphoreCount ++] = * waitSemaphore;
1884
+ if (waitSemaphore != VK_NULL_HANDLE )
1885
+ waitSemArray[submitInfo.waitSemaphoreCount ++] = waitSemaphore;
1888
1886
submitInfo.pWaitDstStageMask = semWaitStageMask;
1889
1887
submitInfo.pWaitSemaphores = waitSemArray;
1890
1888
@@ -2546,20 +2544,11 @@ bool VulkanRenderer::AcquireNextSwapchainImage(bool mainWindow)
2546
2544
if (!UpdateSwapchainProperties (mainWindow))
2547
2545
return false ;
2548
2546
2549
- vkResetFences (m_logicalDevice, 1 , &chainInfo.m_imageAvailableFence );
2550
- VkResult result = vkAcquireNextImageKHR (m_logicalDevice, chainInfo.swapchain , std::numeric_limits<uint64_t >::max (), VK_NULL_HANDLE, chainInfo.m_imageAvailableFence , &chainInfo.swapchainImageIndex );
2551
- if (result != VK_SUCCESS)
2552
- {
2553
- if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR)
2554
- chainInfo.m_shouldRecreate = true ;
2555
-
2556
- if (result == VK_ERROR_OUT_OF_DATE_KHR)
2557
- return false ;
2558
-
2559
- if (result != VK_ERROR_OUT_OF_DATE_KHR && result != VK_SUBOPTIMAL_KHR)
2560
- throw std::runtime_error (fmt::format (" Failed to acquire next image: {}" , result));
2561
- }
2547
+ bool result = chainInfo.AcquireImage (UINT64_MAX);
2548
+ if (!result)
2549
+ return false ;
2562
2550
2551
+ SubmitCommandBuffer (VK_NULL_HANDLE, chainInfo.ConsumeAcquireSemaphore ());
2563
2552
return true ;
2564
2553
}
2565
2554
@@ -2568,6 +2557,8 @@ void VulkanRenderer::RecreateSwapchain(bool mainWindow, bool skipCreate)
2568
2557
SubmitCommandBuffer ();
2569
2558
WaitDeviceIdle ();
2570
2559
auto & chainInfo = GetChainInfo (mainWindow);
2560
+ // make sure fence has no signal operation submitted
2561
+ chainInfo.WaitAvailableFence ();
2571
2562
2572
2563
Vector2i size;
2573
2564
if (mainWindow)
@@ -2633,14 +2624,13 @@ void VulkanRenderer::SwapBuffer(bool mainWindow)
2633
2624
2634
2625
if (!chainInfo.hasDefinedSwapchainImage )
2635
2626
{
2636
- chainInfo.WaitAvailableFence ();
2637
2627
// set the swapchain image to a defined state
2638
2628
VkClearColorValue clearColor{ 0 , 0 , 0 , 0 };
2639
2629
ClearColorImageRaw (chainInfo.m_swapchainImages [chainInfo.swapchainImageIndex ], 0 , 0 , clearColor, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
2640
2630
}
2641
2631
2642
- VkSemaphore presentSemaphore = chainInfo.m_swapchainPresentSemaphores [chainInfo.swapchainImageIndex ];
2643
- SubmitCommandBuffer (& presentSemaphore); // submit all command and signal semaphore
2632
+ VkSemaphore presentSemaphore = chainInfo.m_presentSemaphores [chainInfo.swapchainImageIndex ];
2633
+ SubmitCommandBuffer (presentSemaphore); // submit all command and signal semaphore
2644
2634
2645
2635
cemu_assert_debug (m_numSubmittedCmdBuffers > 0 );
2646
2636
@@ -2701,7 +2691,6 @@ void VulkanRenderer::ClearColorbuffer(bool padView)
2701
2691
if (chainInfo.swapchainImageIndex == -1 )
2702
2692
return ;
2703
2693
2704
- chainInfo.WaitAvailableFence ();
2705
2694
VkClearColorValue clearColor{ 0 , 0 , 0 , 0 };
2706
2695
ClearColorImageRaw (chainInfo.m_swapchainImages [chainInfo.swapchainImageIndex ], 0 , 0 , clearColor, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL);
2707
2696
}
@@ -2792,7 +2781,6 @@ void VulkanRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutpu
2792
2781
LatteTextureViewVk* texViewVk = (LatteTextureViewVk*)texView;
2793
2782
draw_endRenderPass ();
2794
2783
2795
- chainInfo.WaitAvailableFence ();
2796
2784
if (clearBackground)
2797
2785
ClearColorbuffer (padView);
2798
2786
0 commit comments