Skip to content

Commit

Permalink
vk: fix handling of OutOfDate frame
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Dec 25, 2024
1 parent 98300ac commit 091a840
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
10 changes: 9 additions & 1 deletion blade-graphics/src/vulkan/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,20 @@ impl crate::traits::CommandEncoder for super::CommandEncoder {
}

fn present(&mut self, frame: super::Frame) {
let image_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 {
Expand Down
2 changes: 1 addition & 1 deletion blade-graphics/src/vulkan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ struct Presentation {
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Frame {
swapchain: Swapchain,
image_index: u32,
image_index: Option<u32>,
internal: InternalFrame,
}

Expand Down
30 changes: 17 additions & 13 deletions blade-graphics/src/vulkan/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,34 @@ 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,
acquire_semaphore,
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,
}
}
}
Expand Down

0 comments on commit 091a840

Please sign in to comment.