Fix issue with semaphore being reused to early
This commit is contained in:
@@ -22,7 +22,6 @@ namespace openVulkanoCpp::Vulkan
|
||||
this->surface = surface;
|
||||
this->window = window;
|
||||
|
||||
imageAvailableSemaphore = device->device.createSemaphore({});
|
||||
CreateSwapChain({window->GetWidth(), window->GetHeight() });
|
||||
|
||||
FrameBuffer::Init(device, vk::Extent3D(size, 1));
|
||||
@@ -31,7 +30,6 @@ namespace openVulkanoCpp::Vulkan
|
||||
void SwapChain::Close()
|
||||
{
|
||||
DestroySwapChain();
|
||||
device->device.destroySemaphore(imageAvailableSemaphore);
|
||||
device = nullptr;
|
||||
FrameBuffer::Close();
|
||||
}
|
||||
@@ -46,7 +44,8 @@ namespace openVulkanoCpp::Vulkan
|
||||
|
||||
uint32_t SwapChain::AcquireNextImage(const vk::Fence& fence)
|
||||
{
|
||||
const auto resultValue = device->device.acquireNextImageKHR(swapChain, UINT64_MAX, imageAvailableSemaphore, fence);
|
||||
currentSemaphoreId = (currentSemaphoreId + 1) % imageAvailableSemaphores.size();
|
||||
const auto resultValue = device->device.acquireNextImageKHR(swapChain, UINT64_MAX, imageAvailableSemaphores[currentSemaphoreId], fence);
|
||||
const vk::Result result = resultValue.result;
|
||||
if (result != vk::Result::eSuccess && result != vk::Result::eSuboptimalKHR) throw std::error_code(result);
|
||||
SetCurrentFrameId(resultValue.value);
|
||||
@@ -96,6 +95,10 @@ namespace openVulkanoCpp::Vulkan
|
||||
|
||||
CreateSwapChainImages();
|
||||
|
||||
// We use one extra semaphore to prevent reusing them before they have been consumed
|
||||
for (size_t i = 0; i < images.size() + 1; i++)
|
||||
imageAvailableSemaphores.emplace_back(device->device.createSemaphore({}));
|
||||
|
||||
fullscreenViewport = vk::Viewport{ 0, 0, (float)size.width, (float)size.height, 0, 1 };
|
||||
fullscreenScissor = vk::Rect2D{ {0,0}, size };
|
||||
Logger::RENDER->debug("Swap chain for window {0} created", window->GetWindowId());
|
||||
@@ -122,7 +125,7 @@ namespace openVulkanoCpp::Vulkan
|
||||
}
|
||||
}
|
||||
|
||||
void SwapChain::DestroySwapChain() const
|
||||
void SwapChain::DestroySwapChain()
|
||||
{
|
||||
for(auto& image : images)
|
||||
{
|
||||
@@ -130,6 +133,9 @@ namespace openVulkanoCpp::Vulkan
|
||||
device->device.destroyFence(image.fence);
|
||||
}
|
||||
device->device.destroySwapchainKHR(swapChain);
|
||||
for (auto& semaphore : imageAvailableSemaphores)
|
||||
device->device.destroySemaphore(semaphore);
|
||||
imageAvailableSemaphores.clear();
|
||||
}
|
||||
|
||||
vk::PresentModeKHR SwapChain::ChosePresentMode()
|
||||
|
||||
Reference in New Issue
Block a user