Skip to content

Commit

Permalink
Fixed semaphore handling in VulkanSwapChain (nadult#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
nadult authored Sep 22, 2024
1 parent bb0c8f1 commit b2e9cb7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion include/fwk/vulkan/vulkan_swap_chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ class VulkanSwapChain : public VulkanObjectBase<VulkanSwapChain> {
VWindowRef m_window;
VSwapChainSetup m_setup;
vector<PVImageView> m_image_views;
VkSemaphore m_semaphores[2] = {};
array<VkSemaphore, 4> m_semaphores = {};
VkQueue m_present_queue;
VkFormat m_format;
int2 m_size;
uint m_image_index = 0;
uint m_semaphore_index = 0;
Status m_status = Status::initialized;
};
}
12 changes: 7 additions & 5 deletions src/vulkan/vulkan_swap_chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ Ex<VkSemaphore> VulkanSwapChain::acquireImage() {
return nullptr;
}

VkResult result;
auto semaphore = m_semaphores[m_semaphore_index];
for(int retry = 0; retry < 2; retry++) {
result = vkAcquireNextImageKHR(deviceHandle(), m_handle, UINT64_MAX, m_semaphores[0],
VK_NULL_HANDLE, &m_image_index);
VkResult result = vkAcquireNextImageKHR(deviceHandle(), m_handle, UINT64_MAX, semaphore,
VK_NULL_HANDLE, &m_image_index);
if(result == VK_SUCCESS)
break;
EXPECT(recreate());
Expand All @@ -179,8 +179,10 @@ Ex<VkSemaphore> VulkanSwapChain::acquireImage() {
}

m_status = Status::image_acquired;
swap(m_semaphores[0], m_semaphores[1]);
return m_semaphores[1];
m_semaphore_index++;
if(m_semaphore_index >= m_semaphores.size())
m_semaphore_index = 0;
return semaphore;
}

PVImageView VulkanSwapChain::acquiredImage() const {
Expand Down

0 comments on commit b2e9cb7

Please sign in to comment.