mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-03 21:41:19 +12:00
Vulkan: return to more conventional swapchain sync method, encapsulate more code (#525)
This commit is contained in:
parent
8162477dc1
commit
bc104859f3
4 changed files with 102 additions and 39 deletions
|
@ -1665,7 +1665,6 @@ bool VulkanRenderer::ImguiBegin(bool mainWindow)
|
|||
draw_endRenderPass();
|
||||
m_state.currentPipeline = VK_NULL_HANDLE;
|
||||
|
||||
chainInfo.WaitAvailableFence();
|
||||
ImGui_ImplVulkan_CreateFontsTexture(m_state.currentCommandBuffer);
|
||||
ImGui_ImplVulkan_NewFrame(m_state.currentCommandBuffer, chainInfo.m_swapchainFramebuffers[chainInfo.swapchainImageIndex], chainInfo.getExtent());
|
||||
ImGui_UpdateWindowInformation(mainWindow);
|
||||
|
@ -1722,7 +1721,6 @@ bool VulkanRenderer::BeginFrame(bool mainWindow)
|
|||
|
||||
auto& chainInfo = GetChainInfo(mainWindow);
|
||||
|
||||
chainInfo.WaitAvailableFence();
|
||||
VkClearColorValue clearColor{ 0, 0, 0, 0 };
|
||||
ClearColorImageRaw(chainInfo.m_swapchainImages[chainInfo.swapchainImageIndex], 0, 0, clearColor, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
||||
|
||||
|
@ -1848,7 +1846,7 @@ void VulkanRenderer::WaitForNextFinishedCommandBuffer()
|
|||
ProcessFinishedCommandBuffers();
|
||||
}
|
||||
|
||||
void VulkanRenderer::SubmitCommandBuffer(VkSemaphore* signalSemaphore, VkSemaphore* waitSemaphore)
|
||||
void VulkanRenderer::SubmitCommandBuffer(VkSemaphore signalSemaphore, VkSemaphore waitSemaphore)
|
||||
{
|
||||
draw_endRenderPass();
|
||||
|
||||
|
@ -1863,11 +1861,11 @@ void VulkanRenderer::SubmitCommandBuffer(VkSemaphore* signalSemaphore, VkSemapho
|
|||
|
||||
// signal current command buffer semaphore
|
||||
VkSemaphore signalSemArray[2];
|
||||
if (signalSemaphore)
|
||||
if (signalSemaphore != VK_NULL_HANDLE)
|
||||
{
|
||||
submitInfo.signalSemaphoreCount = 2;
|
||||
signalSemArray[0] = m_commandBufferSemaphores[m_commandBufferIndex]; // signal current
|
||||
signalSemArray[1] = *signalSemaphore; // signal current
|
||||
signalSemArray[1] = signalSemaphore; // signal current
|
||||
submitInfo.pSignalSemaphores = signalSemArray;
|
||||
}
|
||||
else
|
||||
|
@ -1883,8 +1881,8 @@ void VulkanRenderer::SubmitCommandBuffer(VkSemaphore* signalSemaphore, VkSemapho
|
|||
submitInfo.waitSemaphoreCount = 0;
|
||||
if (m_numSubmittedCmdBuffers > 0)
|
||||
waitSemArray[submitInfo.waitSemaphoreCount++] = prevSem; // wait on semaphore from previous submit
|
||||
if (waitSemaphore)
|
||||
waitSemArray[submitInfo.waitSemaphoreCount++] = *waitSemaphore;
|
||||
if (waitSemaphore != VK_NULL_HANDLE)
|
||||
waitSemArray[submitInfo.waitSemaphoreCount++] = waitSemaphore;
|
||||
submitInfo.pWaitDstStageMask = semWaitStageMask;
|
||||
submitInfo.pWaitSemaphores = waitSemArray;
|
||||
|
||||
|
@ -2546,20 +2544,11 @@ bool VulkanRenderer::AcquireNextSwapchainImage(bool mainWindow)
|
|||
if (!UpdateSwapchainProperties(mainWindow))
|
||||
return false;
|
||||
|
||||
vkResetFences(m_logicalDevice, 1, &chainInfo.m_imageAvailableFence);
|
||||
VkResult result = vkAcquireNextImageKHR(m_logicalDevice, chainInfo.swapchain, std::numeric_limits<uint64_t>::max(), VK_NULL_HANDLE, chainInfo.m_imageAvailableFence, &chainInfo.swapchainImageIndex);
|
||||
if (result != VK_SUCCESS)
|
||||
{
|
||||
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR)
|
||||
chainInfo.m_shouldRecreate = true;
|
||||
|
||||
if (result == VK_ERROR_OUT_OF_DATE_KHR)
|
||||
return false;
|
||||
|
||||
if (result != VK_ERROR_OUT_OF_DATE_KHR && result != VK_SUBOPTIMAL_KHR)
|
||||
throw std::runtime_error(fmt::format("Failed to acquire next image: {}", result));
|
||||
}
|
||||
bool result = chainInfo.AcquireImage(UINT64_MAX);
|
||||
if (!result)
|
||||
return false;
|
||||
|
||||
SubmitCommandBuffer(VK_NULL_HANDLE, chainInfo.ConsumeAcquireSemaphore());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2568,6 +2557,8 @@ void VulkanRenderer::RecreateSwapchain(bool mainWindow, bool skipCreate)
|
|||
SubmitCommandBuffer();
|
||||
WaitDeviceIdle();
|
||||
auto& chainInfo = GetChainInfo(mainWindow);
|
||||
// make sure fence has no signal operation submitted
|
||||
chainInfo.WaitAvailableFence();
|
||||
|
||||
Vector2i size;
|
||||
if (mainWindow)
|
||||
|
@ -2633,14 +2624,13 @@ void VulkanRenderer::SwapBuffer(bool mainWindow)
|
|||
|
||||
if (!chainInfo.hasDefinedSwapchainImage)
|
||||
{
|
||||
chainInfo.WaitAvailableFence();
|
||||
// set the swapchain image to a defined state
|
||||
VkClearColorValue clearColor{ 0, 0, 0, 0 };
|
||||
ClearColorImageRaw(chainInfo.m_swapchainImages[chainInfo.swapchainImageIndex], 0, 0, clearColor, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
||||
}
|
||||
|
||||
VkSemaphore presentSemaphore = chainInfo.m_swapchainPresentSemaphores[chainInfo.swapchainImageIndex];
|
||||
SubmitCommandBuffer(&presentSemaphore); // submit all command and signal semaphore
|
||||
VkSemaphore presentSemaphore = chainInfo.m_presentSemaphores[chainInfo.swapchainImageIndex];
|
||||
SubmitCommandBuffer(presentSemaphore); // submit all command and signal semaphore
|
||||
|
||||
cemu_assert_debug(m_numSubmittedCmdBuffers > 0);
|
||||
|
||||
|
@ -2701,7 +2691,6 @@ void VulkanRenderer::ClearColorbuffer(bool padView)
|
|||
if (chainInfo.swapchainImageIndex == -1)
|
||||
return;
|
||||
|
||||
chainInfo.WaitAvailableFence();
|
||||
VkClearColorValue clearColor{ 0, 0, 0, 0 };
|
||||
ClearColorImageRaw(chainInfo.m_swapchainImages[chainInfo.swapchainImageIndex], 0, 0, clearColor, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL);
|
||||
}
|
||||
|
@ -2792,7 +2781,6 @@ void VulkanRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutpu
|
|||
LatteTextureViewVk* texViewVk = (LatteTextureViewVk*)texView;
|
||||
draw_endRenderPass();
|
||||
|
||||
chainInfo.WaitAvailableFence();
|
||||
if (clearBackground)
|
||||
ClearColorbuffer(padView);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue