Skip to content

Commit

Permalink
vk: work around acquire() on out of date swapchain
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Apr 15, 2024
1 parent 846cc31 commit 8007374
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
4 changes: 4 additions & 0 deletions blade-graphics/src/vulkan/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ impl super::CommandEncoder {
}

pub fn present(&mut self, frame: super::Frame) {
if frame.acquire_semaphore == vk::Semaphore::null() {
return;
}

assert_eq!(self.present, None);
let wa = &self.device.workarounds;
self.present = Some(super::Presentation {
Expand Down
35 changes: 24 additions & 11 deletions blade-graphics/src/vulkan/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,16 +806,29 @@ impl super::Context {
pub fn acquire_frame(&self) -> super::Frame {
let mut surface = self.surface.as_ref().unwrap().lock().unwrap();
let acquire_semaphore = surface.next_semaphore;
let (index, _suboptimal) = unsafe {
surface
.extension
.acquire_next_image(surface.swapchain, !0, acquire_semaphore, vk::Fence::null())
.unwrap()
};
surface.next_semaphore = mem::replace(
&mut surface.frames[index as usize].acquire_semaphore,
acquire_semaphore,
);
surface.frames[index as usize]
match unsafe {
surface.extension.acquire_next_image(
surface.swapchain,
!0,
acquire_semaphore,
vk::Fence::null(),
)
} {
Ok((index, _suboptimal)) => {
surface.next_semaphore = mem::replace(
&mut surface.frames[index as usize].acquire_semaphore,
acquire_semaphore,
);
surface.frames[index as usize]
}
Err(vk::Result::ERROR_OUT_OF_DATE_KHR) => {
log::warn!("Acquire failed because the surface is out of date");
super::Frame {
acquire_semaphore: vk::Semaphore::null(),
..surface.frames[0]
}
}
Err(other) => panic!("Aquire image error {}", other),
}
}
}

0 comments on commit 8007374

Please sign in to comment.