Fix issue with semaphore being reused to early
This commit is contained in:
@@ -131,14 +131,7 @@ namespace openVulkanoCpp::Scene
|
||||
{
|
||||
descriptorSets.emplace_back();
|
||||
}
|
||||
if (setId == vertexInputDescriptions.size())
|
||||
{
|
||||
descriptorSets.emplace_back().push_back(binding);
|
||||
}
|
||||
else
|
||||
{
|
||||
descriptorSets[setId].push_back(binding);
|
||||
}
|
||||
descriptorSets[setId].push_back(binding);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace openVulkanoCpp::Vulkan
|
||||
cmdHelper->cmdBuffer.end();
|
||||
std::array<vk::PipelineStageFlags, 2> stateFlags = { vk::PipelineStageFlags(vk::PipelineStageFlagBits::eColorAttachmentOutput), vk::PipelineStageFlags(vk::PipelineStageFlagBits::eColorAttachmentOutput) };
|
||||
waitSemaphores[currentImageId].renderReady[0] = resourceManager.EndFrame();
|
||||
waitSemaphores[currentImageId].renderReady[1] = context.swapChain.imageAvailableSemaphore;
|
||||
waitSemaphores[currentImageId].renderReady[1] = context.swapChain.GetCurrentSemaphore();
|
||||
vk::SubmitInfo si = vk::SubmitInfo(
|
||||
waitSemaphores[currentImageId].renderReady.size(), waitSemaphores[currentImageId].renderReady.data(), stateFlags.data(),
|
||||
1, &cmdHelper->cmdBuffer,
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -43,6 +43,8 @@ namespace openVulkanoCpp
|
||||
vk::PresentModeKHR presentMode;
|
||||
vk::Viewport fullscreenViewport;
|
||||
vk::Rect2D fullscreenScissor;
|
||||
std::vector<vk::Semaphore> imageAvailableSemaphores;
|
||||
uint32_t currentSemaphoreId = 0;
|
||||
bool useVsync = false;
|
||||
|
||||
#ifdef __APPLE__
|
||||
@@ -54,7 +56,6 @@ namespace openVulkanoCpp
|
||||
|
||||
public:
|
||||
vk::SwapchainKHR swapChain;
|
||||
vk::Semaphore imageAvailableSemaphore;
|
||||
|
||||
SwapChain() = default;
|
||||
~SwapChain() override { if (device) SwapChain::Close(); }
|
||||
@@ -105,12 +106,14 @@ namespace openVulkanoCpp
|
||||
return images.size();
|
||||
}
|
||||
|
||||
vk::Semaphore& GetCurrentSemaphore() { return imageAvailableSemaphores[currentSemaphoreId]; }
|
||||
|
||||
private:
|
||||
void CreateSwapChain(vk::Extent2D size);
|
||||
|
||||
void CreateSwapChainImages();
|
||||
|
||||
void DestroySwapChain() const;
|
||||
void DestroySwapChain();
|
||||
|
||||
protected:
|
||||
vk::Format FindColorFormat() override
|
||||
|
||||
Reference in New Issue
Block a user