diff --git a/include/vkcv/SyncResources.hpp b/include/vkcv/SyncResources.hpp index e65a9bf5817a13d2d5bc467ff5d343623488e26e..c41019cc46ee1375a83323a6ecc877ecc1c1727a 100644 --- a/include/vkcv/SyncResources.hpp +++ b/include/vkcv/SyncResources.hpp @@ -4,7 +4,7 @@ namespace vkcv { struct SyncResources { vk::Semaphore renderFinished; - vk::Fence swapchainImageAcquired; + vk::Semaphore swapchainImageAcquired; vk::Fence presentFinished; }; diff --git a/src/vkcv/Core.cpp b/src/vkcv/Core.cpp index ea263bb53e373e057e03528a4438f883df35d32b..d6785892ff2566d81671059cae1313354c17ea2e 100644 --- a/src/vkcv/Core.cpp +++ b/src/vkcv/Core.cpp @@ -125,25 +125,17 @@ namespace vkcv uint32_t imageIndex; const auto& acquireResult = m_Context.getDevice().acquireNextImageKHR( - m_swapchain.getSwapchain(), std::numeric_limits<uint64_t>::max(), nullptr, - m_SyncResources.swapchainImageAcquired, &imageIndex, {} + m_swapchain.getSwapchain(), + std::numeric_limits<uint64_t>::max(), + m_SyncResources.swapchainImageAcquired, + nullptr, + &imageIndex, {} ); if (acquireResult != vk::Result::eSuccess) { return Result::ERROR; } - const auto& result = m_Context.getDevice().waitForFences( - m_SyncResources.swapchainImageAcquired, true, - std::numeric_limits<uint64_t>::max() - ); - - m_Context.getDevice().resetFences(m_SyncResources.swapchainImageAcquired); - - if (result != vk::Result::eSuccess) { - return Result::ERROR; - } - m_currentSwapchainImageIndex = imageIndex; return Result::SUCCESS; } @@ -205,11 +197,17 @@ namespace vkcv const vk::Image presentImage = swapchainImages[m_currentSwapchainImageIndex]; const auto& queueManager = m_Context.getQueueManager(); + std::array<vk::Semaphore, 2> waitSemaphores{ + m_SyncResources.renderFinished, + m_SyncResources.swapchainImageAcquired }; vk::Result presentResult; const vk::SwapchainKHR& swapchain = m_swapchain.getSwapchain(); - const vk::PresentInfoKHR presentInfo(1, &m_SyncResources.renderFinished, 1, &swapchain, - &m_currentSwapchainImageIndex, &presentResult); + const vk::PresentInfoKHR presentInfo( + waitSemaphores, + swapchain, + m_currentSwapchainImageIndex, + presentResult); queueManager.getPresentQueue().handle.presentKHR(presentInfo); if (presentResult != vk::Result::eSuccess) { std::cout << "Error: swapchain present failed" << std::endl; diff --git a/src/vkcv/SyncResources.cpp b/src/vkcv/SyncResources.cpp index 8871a2b8c7d38b2ee21814b880bda57fcfa7fa2d..9c27fe32452e0ae648565020d92891764ececb3f 100644 --- a/src/vkcv/SyncResources.cpp +++ b/src/vkcv/SyncResources.cpp @@ -6,18 +6,18 @@ namespace vkcv { const vk::SemaphoreCreateFlags semaphoreFlags = vk::SemaphoreCreateFlagBits(); const vk::SemaphoreCreateInfo semaphoreInfo(semaphoreFlags); - resources.renderFinished = device.createSemaphore(semaphoreInfo, nullptr, {}); + resources.renderFinished = device.createSemaphore(semaphoreInfo, nullptr, {}); + resources.swapchainImageAcquired = device.createSemaphore(semaphoreInfo); resources.presentFinished = createFence(device); - resources.swapchainImageAcquired = createFence(device); - + return resources; } void destroySyncResources(const vk::Device& device, const SyncResources& resources) { device.destroySemaphore(resources.renderFinished); + device.destroySemaphore(resources.swapchainImageAcquired); device.destroyFence(resources.presentFinished); - device.destroyFence(resources.swapchainImageAcquired); } vk::Fence createFence(const vk::Device& device) {