renderer_vulkan: Address vulkan surface recreation issues (#198)

This commit is contained in:
PabloMK7
2024-07-16 23:54:02 +02:00
parent 59ca96da97
commit 70221780ef
9 changed files with 24 additions and 34 deletions

View File

@@ -473,7 +473,7 @@ void PresentWindow::CopyToSwapchain(Frame* frame) {
.pSignalSemaphores = &present_ready,
};
std::scoped_lock submit_lock{scheduler.submit_mutex};
std::scoped_lock submit_lock{scheduler.submit_mutex, recreate_surface_mutex};
try {
graphics_queue.submit(submit_info, frame->present_done);

View File

@@ -78,9 +78,13 @@ void Swapchain::Create(u32 width_, u32 height_, vk::SurfaceKHR surface_) {
}
bool Swapchain::AcquireNextImage() {
if (needs_recreation) {
return false;
}
MICROPROFILE_SCOPE(Vulkan_Acquire);
vk::Device device = instance.GetDevice();
vk::Result result =
const vk::Device device = instance.GetDevice();
const vk::Result result =
device.acquireNextImageKHR(swapchain, std::numeric_limits<u64>::max(),
image_acquired[frame_index], VK_NULL_HANDLE, &image_index);
@@ -102,10 +106,6 @@ bool Swapchain::AcquireNextImage() {
}
void Swapchain::Present() {
if (needs_recreation) {
return;
}
const vk::PresentInfoKHR present_info = {
.waitSemaphoreCount = 1,
.pWaitSemaphores = &present_ready[image_index],
@@ -119,6 +119,10 @@ void Swapchain::Present() {
[[maybe_unused]] vk::Result result = instance.GetPresentQueue().presentKHR(present_info);
} catch (vk::OutOfDateKHRError&) {
needs_recreation = true;
return;
} catch (vk::SurfaceLostKHRError&) {
needs_recreation = true;
return;
} catch (const vk::SystemError& err) {
LOG_CRITICAL(Render_Vulkan, "Swapchain presentation failed {}", err.what());
UNREACHABLE();
@@ -268,4 +272,4 @@ void Swapchain::SetupImages() {
}
}
} // namespace Vulkan
} // namespace Vulkan