From b3f1b91f8cb88fcfcd1fc08c61b35f43d7b0f00b Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 24 Dec 2024 21:08:33 -0800 Subject: [PATCH] vk: return dummy swapchain image on OutOfDate (#234) --- blade-graphics/src/vulkan/command.rs | 4 ---- blade-graphics/src/vulkan/surface.rs | 30 ++++++++++++---------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/blade-graphics/src/vulkan/command.rs b/blade-graphics/src/vulkan/command.rs index 85dba2c..0cecebd 100644 --- a/blade-graphics/src/vulkan/command.rs +++ b/blade-graphics/src/vulkan/command.rs @@ -539,10 +539,6 @@ impl crate::traits::CommandEncoder for super::CommandEncoder { } fn present(&mut self, frame: super::Frame) { - if frame.internal.acquire_semaphore == vk::Semaphore::null() { - return; - } - assert_eq!(self.present, None); let wa = &self.device.workarounds; self.present = Some(super::Presentation { diff --git a/blade-graphics/src/vulkan/surface.rs b/blade-graphics/src/vulkan/surface.rs index de06120..d795d95 100644 --- a/blade-graphics/src/vulkan/surface.rs +++ b/blade-graphics/src/vulkan/surface.rs @@ -20,7 +20,7 @@ impl super::Surface { pub fn acquire_frame(&mut self) -> super::Frame { let acquire_semaphore = self.next_semaphore; - match unsafe { + let index = match unsafe { self.device.acquire_next_image( self.swapchain.raw, !0, @@ -28,26 +28,22 @@ impl super::Surface { vk::Fence::null(), ) } { - Ok((index, _suboptimal)) => { - self.next_semaphore = mem::replace( - &mut self.frames[index as usize].acquire_semaphore, - acquire_semaphore, - ); - super::Frame { - internal: self.frames[index as usize], - swapchain: self.swapchain, - image_index: index, - } - } + Ok((index, _suboptimal)) => index, Err(vk::Result::ERROR_OUT_OF_DATE_KHR) => { log::warn!("Acquire failed because the surface is out of date"); - super::Frame { - internal: super::InternalFrame::default(), - swapchain: self.swapchain, - image_index: 0, - } + 0 } Err(other) => panic!("Aquire image error {}", other), + }; + + self.next_semaphore = mem::replace( + &mut self.frames[index as usize].acquire_semaphore, + acquire_semaphore, + ); + super::Frame { + internal: self.frames[index as usize], + swapchain: self.swapchain, + image_index: index, } } }