@@ -1665,7 +1665,6 @@ bool VulkanRenderer::ImguiBegin(bool mainWindow)
16651665 draw_endRenderPass ();
16661666 m_state.currentPipeline = VK_NULL_HANDLE;
16671667
1668- chainInfo.WaitAvailableFence ();
16691668 ImGui_ImplVulkan_CreateFontsTexture (m_state.currentCommandBuffer );
16701669 ImGui_ImplVulkan_NewFrame (m_state.currentCommandBuffer , chainInfo.m_swapchainFramebuffers [chainInfo.swapchainImageIndex ], chainInfo.getExtent ());
16711670 ImGui_UpdateWindowInformation (mainWindow);
@@ -1722,7 +1721,6 @@ bool VulkanRenderer::BeginFrame(bool mainWindow)
17221721
17231722 auto & chainInfo = GetChainInfo (mainWindow);
17241723
1725- chainInfo.WaitAvailableFence ();
17261724 VkClearColorValue clearColor{ 0 , 0 , 0 , 0 };
17271725 ClearColorImageRaw (chainInfo.m_swapchainImages [chainInfo.swapchainImageIndex ], 0 , 0 , clearColor, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
17281726
@@ -1848,7 +1846,7 @@ void VulkanRenderer::WaitForNextFinishedCommandBuffer()
18481846 ProcessFinishedCommandBuffers ();
18491847}
18501848
1851- void VulkanRenderer::SubmitCommandBuffer (VkSemaphore* signalSemaphore, VkSemaphore* waitSemaphore)
1849+ void VulkanRenderer::SubmitCommandBuffer (VkSemaphore signalSemaphore, VkSemaphore waitSemaphore)
18521850{
18531851 draw_endRenderPass ();
18541852
@@ -1863,11 +1861,11 @@ void VulkanRenderer::SubmitCommandBuffer(VkSemaphore* signalSemaphore, VkSemapho
18631861
18641862 // signal current command buffer semaphore
18651863 VkSemaphore signalSemArray[2 ];
1866- if (signalSemaphore)
1864+ if (signalSemaphore != VK_NULL_HANDLE )
18671865 {
18681866 submitInfo.signalSemaphoreCount = 2 ;
18691867 signalSemArray[0 ] = m_commandBufferSemaphores[m_commandBufferIndex]; // signal current
1870- signalSemArray[1 ] = * signalSemaphore; // signal current
1868+ signalSemArray[1 ] = signalSemaphore; // signal current
18711869 submitInfo.pSignalSemaphores = signalSemArray;
18721870 }
18731871 else
@@ -1883,8 +1881,8 @@ void VulkanRenderer::SubmitCommandBuffer(VkSemaphore* signalSemaphore, VkSemapho
18831881 submitInfo.waitSemaphoreCount = 0 ;
18841882 if (m_numSubmittedCmdBuffers > 0 )
18851883 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;
18881886 submitInfo.pWaitDstStageMask = semWaitStageMask;
18891887 submitInfo.pWaitSemaphores = waitSemArray;
18901888
@@ -2546,20 +2544,11 @@ bool VulkanRenderer::AcquireNextSwapchainImage(bool mainWindow)
25462544 if (!UpdateSwapchainProperties (mainWindow))
25472545 return false ;
25482546
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 ;
25622550
2551+ SubmitCommandBuffer (VK_NULL_HANDLE, chainInfo.ConsumeAcquireSemaphore ());
25632552 return true ;
25642553}
25652554
@@ -2568,6 +2557,8 @@ void VulkanRenderer::RecreateSwapchain(bool mainWindow, bool skipCreate)
25682557 SubmitCommandBuffer ();
25692558 WaitDeviceIdle ();
25702559 auto & chainInfo = GetChainInfo (mainWindow);
2560+ // make sure fence has no signal operation submitted
2561+ chainInfo.WaitAvailableFence ();
25712562
25722563 Vector2i size;
25732564 if (mainWindow)
@@ -2633,14 +2624,13 @@ void VulkanRenderer::SwapBuffer(bool mainWindow)
26332624
26342625 if (!chainInfo.hasDefinedSwapchainImage )
26352626 {
2636- chainInfo.WaitAvailableFence ();
26372627 // set the swapchain image to a defined state
26382628 VkClearColorValue clearColor{ 0 , 0 , 0 , 0 };
26392629 ClearColorImageRaw (chainInfo.m_swapchainImages [chainInfo.swapchainImageIndex ], 0 , 0 , clearColor, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
26402630 }
26412631
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
26442634
26452635 cemu_assert_debug (m_numSubmittedCmdBuffers > 0 );
26462636
@@ -2701,7 +2691,6 @@ void VulkanRenderer::ClearColorbuffer(bool padView)
27012691 if (chainInfo.swapchainImageIndex == -1 )
27022692 return ;
27032693
2704- chainInfo.WaitAvailableFence ();
27052694 VkClearColorValue clearColor{ 0 , 0 , 0 , 0 };
27062695 ClearColorImageRaw (chainInfo.m_swapchainImages [chainInfo.swapchainImageIndex ], 0 , 0 , clearColor, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL);
27072696}
@@ -2792,7 +2781,6 @@ void VulkanRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutpu
27922781 LatteTextureViewVk* texViewVk = (LatteTextureViewVk*)texView;
27932782 draw_endRenderPass ();
27942783
2795- chainInfo.WaitAvailableFence ();
27962784 if (clearBackground)
27972785 ClearColorbuffer (padView);
27982786
0 commit comments