diff --git a/blade-graphics/src/vulkan/command.rs b/blade-graphics/src/vulkan/command.rs index 15a218f..8fc0de0 100644 --- a/blade-graphics/src/vulkan/command.rs +++ b/blade-graphics/src/vulkan/command.rs @@ -539,12 +539,20 @@ impl crate::traits::CommandEncoder for super::CommandEncoder { } fn present(&mut self, frame: super::Frame) { + let iamge_index = match frame.image_index { + Some(index) => index, + None => { + //Note: image was out of date, we can't present it + return; + } + }; + assert_eq!(self.present, None); let wa = &self.device.workarounds; self.present = Some(super::Presentation { acquire_semaphore: frame.internal.acquire_semaphore, swapchain: frame.swapchain.raw, - image_index: frame.image_index, + image_index, }); let barrier = vk::ImageMemoryBarrier { diff --git a/blade-graphics/src/vulkan/mod.rs b/blade-graphics/src/vulkan/mod.rs index 28ee3b5..dea449b 100644 --- a/blade-graphics/src/vulkan/mod.rs +++ b/blade-graphics/src/vulkan/mod.rs @@ -107,7 +107,7 @@ struct Presentation { #[derive(Clone, Copy, Debug, PartialEq)] pub struct Frame { swapchain: Swapchain, - image_index: u32, + image_index: Option, internal: InternalFrame, } diff --git a/blade-graphics/src/vulkan/surface.rs b/blade-graphics/src/vulkan/surface.rs index d795d95..c53d109 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; - let index = match unsafe { + match unsafe { self.device.acquire_next_image( self.swapchain.raw, !0, @@ -28,22 +28,26 @@ impl super::Surface { vk::Fence::null(), ) } { - Ok((index, _suboptimal)) => index, + 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: Some(index), + } + } Err(vk::Result::ERROR_OUT_OF_DATE_KHR) => { log::warn!("Acquire failed because the surface is out of date"); - 0 + super::Frame { + internal: self.frames[0], + swapchain: self.swapchain, + image_index: None, + } } 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, } } }