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, 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)] #[derive(Debug)]
pub struct Swapchain { pub struct Swapchain {
width: AtomicU32, width: AtomicU32,
@ -187,17 +204,24 @@ impl Swapchain {
Ok(()) Ok(())
} }
pub fn acquire_next_image( pub fn acquire_next_image<'a>(
&self, &self,
time_out: u64, time_out: u64,
present_complete_semaphore: Option<&Arc<Semaphore>>, synchro: impl Into<NextImageSynchronization<'a>>,
fence: Option<&Arc<Fence>>,
) -> Result<OutOfDate<u32>> { ) -> Result<OutOfDate<u32>> {
let synchro = synchro.into();
let res = self.device.acquire_next_image( let res = self.device.acquire_next_image(
*self.swapchain.lock().unwrap(), *self.swapchain.lock().unwrap(),
time_out, time_out,
present_complete_semaphore.map(|sem| sem.vk_handle()), match synchro {
fence.map(|fence| fence.vk_handle()), 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 { if let Ok(r) = &res {