Skip to content

Commit 84cad8b

Browse files
Vulkan: Remove unecessary present fence (#1166)
1 parent 391533d commit 84cad8b

File tree

5 files changed

+10
-51
lines changed

5 files changed

+10
-51
lines changed

src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -875,11 +875,6 @@ void LatteRenderTarget_getScreenImageArea(sint32* x, sint32* y, sint32* width, s
875875

876876
void LatteRenderTarget_copyToBackbuffer(LatteTextureView* textureView, bool isPadView)
877877
{
878-
if (g_renderer->GetType() == RendererAPI::Vulkan)
879-
{
880-
((VulkanRenderer*)g_renderer.get())->PreparePresentationFrame(!isPadView);
881-
}
882-
883878
// make sure texture is updated to latest data in cache
884879
LatteTexture_UpdateDataToLatest(textureView->baseTexture);
885880
// mark source texture as still in use

src/Cafe/HW/Latte/Renderer/Vulkan/SwapchainInfoVk.cpp

+8-31
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,6 @@ void SwapchainInfoVk::Create()
146146
UnrecoverableError("Failed to create semaphore for swapchain acquire");
147147
}
148148

149-
VkFenceCreateInfo fenceInfo = {};
150-
fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
151-
fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
152-
result = vkCreateFence(m_logicalDevice, &fenceInfo, nullptr, &m_imageAvailableFence);
153-
if (result != VK_SUCCESS)
154-
UnrecoverableError("Failed to create fence for swapchain");
155-
156149
m_acquireIndex = 0;
157150
hasDefinedSwapchainImage = false;
158151
}
@@ -184,12 +177,6 @@ void SwapchainInfoVk::Cleanup()
184177
m_swapchainFramebuffers.clear();
185178

186179

187-
if (m_imageAvailableFence)
188-
{
189-
WaitAvailableFence();
190-
vkDestroyFence(m_logicalDevice, m_imageAvailableFence, nullptr);
191-
m_imageAvailableFence = nullptr;
192-
}
193180
if (m_swapchain)
194181
{
195182
vkDestroySwapchainKHR(m_logicalDevice, m_swapchain, nullptr);
@@ -202,34 +189,25 @@ bool SwapchainInfoVk::IsValid() const
202189
return m_swapchain && !m_acquireSemaphores.empty();
203190
}
204191

205-
void SwapchainInfoVk::WaitAvailableFence()
206-
{
207-
if(m_awaitableFence != VK_NULL_HANDLE)
208-
vkWaitForFences(m_logicalDevice, 1, &m_awaitableFence, VK_TRUE, UINT64_MAX);
209-
m_awaitableFence = VK_NULL_HANDLE;
210-
}
211-
212-
void SwapchainInfoVk::ResetAvailableFence() const
213-
{
214-
vkResetFences(m_logicalDevice, 1, &m_imageAvailableFence);
215-
}
216-
217192
VkSemaphore SwapchainInfoVk::ConsumeAcquireSemaphore()
218193
{
219194
VkSemaphore ret = m_currentSemaphore;
220195
m_currentSemaphore = VK_NULL_HANDLE;
221196
return ret;
222197
}
223198

224-
bool SwapchainInfoVk::AcquireImage(uint64 timeout)
199+
bool SwapchainInfoVk::AcquireImage()
225200
{
226-
WaitAvailableFence();
227-
ResetAvailableFence();
228-
229201
VkSemaphore acquireSemaphore = m_acquireSemaphores[m_acquireIndex];
230-
VkResult result = vkAcquireNextImageKHR(m_logicalDevice, m_swapchain, timeout, acquireSemaphore, m_imageAvailableFence, &swapchainImageIndex);
202+
VkResult result = vkAcquireNextImageKHR(m_logicalDevice, m_swapchain, 1'000'000'000, acquireSemaphore, nullptr, &swapchainImageIndex);
231203
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR)
232204
m_shouldRecreate = true;
205+
if (result == VK_TIMEOUT)
206+
{
207+
swapchainImageIndex = -1;
208+
return false;
209+
}
210+
233211
if (result < 0)
234212
{
235213
swapchainImageIndex = -1;
@@ -238,7 +216,6 @@ bool SwapchainInfoVk::AcquireImage(uint64 timeout)
238216
return false;
239217
}
240218
m_currentSemaphore = acquireSemaphore;
241-
m_awaitableFence = m_imageAvailableFence;
242219
m_acquireIndex = (m_acquireIndex + 1) % m_swapchainImages.size();
243220

244221
return true;

src/Cafe/HW/Latte/Renderer/Vulkan/SwapchainInfoVk.h

+1-6
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ struct SwapchainInfoVk
2626

2727
bool IsValid() const;
2828

29-
void WaitAvailableFence();
30-
void ResetAvailableFence() const;
31-
32-
bool AcquireImage(uint64 timeout);
29+
bool AcquireImage();
3330
// retrieve semaphore of last acquire for submitting a wait operation
3431
// only one wait operation must be submitted per acquire (which submits a single signal operation)
3532
// therefore subsequent calls will return a NULL handle
@@ -84,9 +81,7 @@ struct SwapchainInfoVk
8481
private:
8582
uint32 m_acquireIndex = 0;
8683
std::vector<VkSemaphore> m_acquireSemaphores; // indexed by m_acquireIndex
87-
VkFence m_imageAvailableFence{};
8884
VkSemaphore m_currentSemaphore = VK_NULL_HANDLE;
89-
VkFence m_awaitableFence = VK_NULL_HANDLE;
9085

9186
std::array<uint32, 2> m_swapchainQueueFamilyIndices;
9287
VkExtent2D m_actualExtent{};

src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -1824,11 +1824,6 @@ void VulkanRenderer::DrawEmptyFrame(bool mainWindow)
18241824
SwapBuffers(mainWindow, !mainWindow);
18251825
}
18261826

1827-
void VulkanRenderer::PreparePresentationFrame(bool mainWindow)
1828-
{
1829-
AcquireNextSwapchainImage(mainWindow);
1830-
}
1831-
18321827
void VulkanRenderer::InitFirstCommandBuffer()
18331828
{
18341829
cemu_assert_debug(m_state.currentCommandBuffer == nullptr);
@@ -2599,7 +2594,7 @@ bool VulkanRenderer::AcquireNextSwapchainImage(bool mainWindow)
25992594
if (!UpdateSwapchainProperties(mainWindow))
26002595
return false;
26012596

2602-
bool result = chainInfo.AcquireImage(UINT64_MAX);
2597+
bool result = chainInfo.AcquireImage();
26032598
if (!result)
26042599
return false;
26052600

@@ -2612,8 +2607,6 @@ void VulkanRenderer::RecreateSwapchain(bool mainWindow, bool skipCreate)
26122607
SubmitCommandBuffer();
26132608
WaitDeviceIdle();
26142609
auto& chainInfo = GetChainInfo(mainWindow);
2615-
// make sure fence has no signal operation submitted
2616-
chainInfo.WaitAvailableFence();
26172610

26182611
Vector2i size;
26192612
if (mainWindow)

src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h

-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ class VulkanRenderer : public Renderer
228228
uint64 GenUniqueId(); // return unique id (uses incrementing counter)
229229

230230
void DrawEmptyFrame(bool mainWindow) override;
231-
void PreparePresentationFrame(bool mainWindow);
232231

233232
void InitFirstCommandBuffer();
234233
void ProcessFinishedCommandBuffers();

0 commit comments

Comments
 (0)