Simplify acquire next image function

This commit is contained in:
hodasemi 2023-04-09 23:19:41 +02:00
parent 5db1d534a6
commit ac4dcf2518

View file

@ -8,6 +8,23 @@ use std::sync::{
Arc, Mutex,
};
pub enum NextImageSynchronization<'a> {
Semaphore(&'a Arc<Semaphore>),
Fence(&'a Arc<Fence>),
}
impl<'a> From<&'a Arc<Semaphore>> for NextImageSynchronization<'a> {
fn from(value: &'a Arc<Semaphore>) -> Self {
Self::Semaphore(value)
}
}
impl<'a> From<&'a Arc<Fence>> for NextImageSynchronization<'a> {
fn from(value: &'a Arc<Fence>) -> Self {
Self::Fence(value)
}
}
#[derive(Debug)]
pub struct Swapchain {
width: AtomicU32,
@ -187,17 +204,24 @@ impl Swapchain {
Ok(())
}
pub fn acquire_next_image(
pub fn acquire_next_image<'a>(
&self,
time_out: u64,
present_complete_semaphore: Option<&Arc<Semaphore>>,
fence: Option<&Arc<Fence>>,
synchro: impl Into<NextImageSynchronization<'a>>,
) -> Result<OutOfDate<u32>> {
let synchro = synchro.into();
let res = self.device.acquire_next_image(
*self.swapchain.lock().unwrap(),
time_out,
present_complete_semaphore.map(|sem| sem.vk_handle()),
fence.map(|fence| fence.vk_handle()),
match synchro {
NextImageSynchronization::Semaphore(semaphore) => Some(semaphore.vk_handle()),
NextImageSynchronization::Fence(_) => None,
},
match synchro {
NextImageSynchronization::Semaphore(_) => None,
NextImageSynchronization::Fence(fence) => Some(fence.vk_handle()),
},
);
if let Ok(r) = &res {