Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vk: fix handling of OutOfDate frame #237

Merged
merged 1 commit into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading