Vulkan: Remove unecessary present fence (#1166)

This commit is contained in:
goeiecool9999 2024-04-11 06:41:57 +02:00 committed by GitHub
parent 391533dbe5
commit 84cad8b280
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 10 additions and 51 deletions

View File

@ -875,11 +875,6 @@ void LatteRenderTarget_getScreenImageArea(sint32* x, sint32* y, sint32* width, s
void LatteRenderTarget_copyToBackbuffer(LatteTextureView* textureView, bool isPadView) void LatteRenderTarget_copyToBackbuffer(LatteTextureView* textureView, bool isPadView)
{ {
if (g_renderer->GetType() == RendererAPI::Vulkan)
{
((VulkanRenderer*)g_renderer.get())->PreparePresentationFrame(!isPadView);
}
// make sure texture is updated to latest data in cache // make sure texture is updated to latest data in cache
LatteTexture_UpdateDataToLatest(textureView->baseTexture); LatteTexture_UpdateDataToLatest(textureView->baseTexture);
// mark source texture as still in use // mark source texture as still in use

View File

@ -146,13 +146,6 @@ void SwapchainInfoVk::Create()
UnrecoverableError("Failed to create semaphore for swapchain acquire"); UnrecoverableError("Failed to create semaphore for swapchain acquire");
} }
VkFenceCreateInfo fenceInfo = {};
fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
result = vkCreateFence(m_logicalDevice, &fenceInfo, nullptr, &m_imageAvailableFence);
if (result != VK_SUCCESS)
UnrecoverableError("Failed to create fence for swapchain");
m_acquireIndex = 0; m_acquireIndex = 0;
hasDefinedSwapchainImage = false; hasDefinedSwapchainImage = false;
} }
@ -184,12 +177,6 @@ void SwapchainInfoVk::Cleanup()
m_swapchainFramebuffers.clear(); m_swapchainFramebuffers.clear();
if (m_imageAvailableFence)
{
WaitAvailableFence();
vkDestroyFence(m_logicalDevice, m_imageAvailableFence, nullptr);
m_imageAvailableFence = nullptr;
}
if (m_swapchain) if (m_swapchain)
{ {
vkDestroySwapchainKHR(m_logicalDevice, m_swapchain, nullptr); vkDestroySwapchainKHR(m_logicalDevice, m_swapchain, nullptr);
@ -202,18 +189,6 @@ bool SwapchainInfoVk::IsValid() const
return m_swapchain && !m_acquireSemaphores.empty(); return m_swapchain && !m_acquireSemaphores.empty();
} }
void SwapchainInfoVk::WaitAvailableFence()
{
if(m_awaitableFence != VK_NULL_HANDLE)
vkWaitForFences(m_logicalDevice, 1, &m_awaitableFence, VK_TRUE, UINT64_MAX);
m_awaitableFence = VK_NULL_HANDLE;
}
void SwapchainInfoVk::ResetAvailableFence() const
{
vkResetFences(m_logicalDevice, 1, &m_imageAvailableFence);
}
VkSemaphore SwapchainInfoVk::ConsumeAcquireSemaphore() VkSemaphore SwapchainInfoVk::ConsumeAcquireSemaphore()
{ {
VkSemaphore ret = m_currentSemaphore; VkSemaphore ret = m_currentSemaphore;
@ -221,15 +196,18 @@ VkSemaphore SwapchainInfoVk::ConsumeAcquireSemaphore()
return ret; return ret;
} }
bool SwapchainInfoVk::AcquireImage(uint64 timeout) bool SwapchainInfoVk::AcquireImage()
{ {
WaitAvailableFence();
ResetAvailableFence();
VkSemaphore acquireSemaphore = m_acquireSemaphores[m_acquireIndex]; VkSemaphore acquireSemaphore = m_acquireSemaphores[m_acquireIndex];
VkResult result = vkAcquireNextImageKHR(m_logicalDevice, m_swapchain, timeout, acquireSemaphore, m_imageAvailableFence, &swapchainImageIndex); VkResult result = vkAcquireNextImageKHR(m_logicalDevice, m_swapchain, 1'000'000'000, acquireSemaphore, nullptr, &swapchainImageIndex);
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR)
m_shouldRecreate = true; m_shouldRecreate = true;
if (result == VK_TIMEOUT)
{
swapchainImageIndex = -1;
return false;
}
if (result < 0) if (result < 0)
{ {
swapchainImageIndex = -1; swapchainImageIndex = -1;
@ -238,7 +216,6 @@ bool SwapchainInfoVk::AcquireImage(uint64 timeout)
return false; return false;
} }
m_currentSemaphore = acquireSemaphore; m_currentSemaphore = acquireSemaphore;
m_awaitableFence = m_imageAvailableFence;
m_acquireIndex = (m_acquireIndex + 1) % m_swapchainImages.size(); m_acquireIndex = (m_acquireIndex + 1) % m_swapchainImages.size();
return true; return true;

View File

@ -26,10 +26,7 @@ struct SwapchainInfoVk
bool IsValid() const; bool IsValid() const;
void WaitAvailableFence(); bool AcquireImage();
void ResetAvailableFence() const;
bool AcquireImage(uint64 timeout);
// retrieve semaphore of last acquire for submitting a wait operation // retrieve semaphore of last acquire for submitting a wait operation
// only one wait operation must be submitted per acquire (which submits a single signal operation) // only one wait operation must be submitted per acquire (which submits a single signal operation)
// therefore subsequent calls will return a NULL handle // therefore subsequent calls will return a NULL handle
@ -84,9 +81,7 @@ struct SwapchainInfoVk
private: private:
uint32 m_acquireIndex = 0; uint32 m_acquireIndex = 0;
std::vector<VkSemaphore> m_acquireSemaphores; // indexed by m_acquireIndex std::vector<VkSemaphore> m_acquireSemaphores; // indexed by m_acquireIndex
VkFence m_imageAvailableFence{};
VkSemaphore m_currentSemaphore = VK_NULL_HANDLE; VkSemaphore m_currentSemaphore = VK_NULL_HANDLE;
VkFence m_awaitableFence = VK_NULL_HANDLE;
std::array<uint32, 2> m_swapchainQueueFamilyIndices; std::array<uint32, 2> m_swapchainQueueFamilyIndices;
VkExtent2D m_actualExtent{}; VkExtent2D m_actualExtent{};

View File

@ -1824,11 +1824,6 @@ void VulkanRenderer::DrawEmptyFrame(bool mainWindow)
SwapBuffers(mainWindow, !mainWindow); SwapBuffers(mainWindow, !mainWindow);
} }
void VulkanRenderer::PreparePresentationFrame(bool mainWindow)
{
AcquireNextSwapchainImage(mainWindow);
}
void VulkanRenderer::InitFirstCommandBuffer() void VulkanRenderer::InitFirstCommandBuffer()
{ {
cemu_assert_debug(m_state.currentCommandBuffer == nullptr); cemu_assert_debug(m_state.currentCommandBuffer == nullptr);
@ -2599,7 +2594,7 @@ bool VulkanRenderer::AcquireNextSwapchainImage(bool mainWindow)
if (!UpdateSwapchainProperties(mainWindow)) if (!UpdateSwapchainProperties(mainWindow))
return false; return false;
bool result = chainInfo.AcquireImage(UINT64_MAX); bool result = chainInfo.AcquireImage();
if (!result) if (!result)
return false; return false;
@ -2612,8 +2607,6 @@ void VulkanRenderer::RecreateSwapchain(bool mainWindow, bool skipCreate)
SubmitCommandBuffer(); SubmitCommandBuffer();
WaitDeviceIdle(); WaitDeviceIdle();
auto& chainInfo = GetChainInfo(mainWindow); auto& chainInfo = GetChainInfo(mainWindow);
// make sure fence has no signal operation submitted
chainInfo.WaitAvailableFence();
Vector2i size; Vector2i size;
if (mainWindow) if (mainWindow)

View File

@ -228,7 +228,6 @@ public:
uint64 GenUniqueId(); // return unique id (uses incrementing counter) uint64 GenUniqueId(); // return unique id (uses incrementing counter)
void DrawEmptyFrame(bool mainWindow) override; void DrawEmptyFrame(bool mainWindow) override;
void PreparePresentationFrame(bool mainWindow);
void InitFirstCommandBuffer(); void InitFirstCommandBuffer();
void ProcessFinishedCommandBuffers(); void ProcessFinishedCommandBuffers();