Skip to content
Snippets Groups Projects
Verified Commit 8a5b686e authored by Tobias Frisch's avatar Tobias Frisch
Browse files

[#18] Drop the frame while you can!

parent b209cd87
No related branches found
No related tags found
1 merge request!12Resolve "Swapchain Class"
Pipeline #24810 passed
...@@ -314,8 +314,13 @@ namespace vkcv ...@@ -314,8 +314,13 @@ namespace vkcv
m_Context.getDevice().acquireNextImageKHR(m_swapchain.getSwapchain(), 0, nullptr, m_Context.getDevice().acquireNextImageKHR(m_swapchain.getSwapchain(), 0, nullptr,
m_SyncResources.swapchainImageAcquired, &index, {}); m_SyncResources.swapchainImageAcquired, &index, {});
const uint64_t timeoutPeriodNs = 1000; // TODO: think if is adequate const uint64_t timeoutPeriodNs = 1000; // TODO: think if is adequate
m_Context.getDevice().waitForFences(m_SyncResources.swapchainImageAcquired, true, timeoutPeriodNs); const auto& result = m_Context.getDevice().waitForFences(m_SyncResources.swapchainImageAcquired, true, timeoutPeriodNs);
m_Context.getDevice().resetFences(m_SyncResources.swapchainImageAcquired); m_Context.getDevice().resetFences(m_SyncResources.swapchainImageAcquired);
if (result == vk::Result::eTimeout) {
index = std::numeric_limits<uint32_t>::max();
}
return index; return index;
} }
...@@ -328,6 +333,12 @@ namespace vkcv ...@@ -328,6 +333,12 @@ namespace vkcv
void Core::beginFrame() { void Core::beginFrame() {
m_currentSwapchainImageIndex = acquireSwapchainImage(); m_currentSwapchainImageIndex = acquireSwapchainImage();
if (m_currentSwapchainImageIndex == std::numeric_limits<uint32_t>::max()) {
std::cerr << "Drop frame!" << std::endl;
return;
}
m_Context.getDevice().waitIdle(); // FIMXE: this is a sin against graphics programming, but its getting late - Alex m_Context.getDevice().waitIdle(); // FIMXE: this is a sin against graphics programming, but its getting late - Alex
destroyTemporaryFramebuffers(); destroyTemporaryFramebuffers();
const vk::CommandBufferUsageFlags beginFlags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit; const vk::CommandBufferUsageFlags beginFlags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit;
...@@ -337,6 +348,10 @@ namespace vkcv ...@@ -337,6 +348,10 @@ namespace vkcv
void Core::renderTriangle(const PassHandle renderpassHandle, const PipelineHandle pipelineHandle, void Core::renderTriangle(const PassHandle renderpassHandle, const PipelineHandle pipelineHandle,
const int width, const int height) { const int width, const int height) {
if (m_currentSwapchainImageIndex == std::numeric_limits<uint32_t>::max()) {
return;
}
const vk::RenderPass renderpass = m_PassManager->getVkPass(renderpassHandle); const vk::RenderPass renderpass = m_PassManager->getVkPass(renderpassHandle);
const std::array<float, 4> clearColor = { 1.f, 1.f, 0.f, 1.f }; const std::array<float, 4> clearColor = { 1.f, 1.f, 0.f, 1.f };
const vk::ClearValue clearValues(clearColor); const vk::ClearValue clearValues(clearColor);
...@@ -351,6 +366,10 @@ namespace vkcv ...@@ -351,6 +366,10 @@ namespace vkcv
} }
void Core::endFrame() { void Core::endFrame() {
if (m_currentSwapchainImageIndex == std::numeric_limits<uint32_t>::max()) {
return;
}
const auto swapchainImages = m_Context.getDevice().getSwapchainImagesKHR(m_swapchain.getSwapchain()); const auto swapchainImages = m_Context.getDevice().getSwapchainImagesKHR(m_swapchain.getSwapchain());
const vk::Image presentImage = swapchainImages[m_currentSwapchainImageIndex]; const vk::Image presentImage = swapchainImages[m_currentSwapchainImageIndex];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment