2023-01-10 11:17:13 +11:00
|
|
|
use ash::prelude::VkResult;
|
|
|
|
use ash::vk;
|
|
|
|
|
|
|
|
pub struct SyncObjects {
|
2023-01-13 14:10:25 +11:00
|
|
|
pub image_available: Vec<vk::Semaphore>,
|
|
|
|
pub render_finished: Vec<vk::Semaphore>,
|
|
|
|
pub in_flight: Vec<vk::Fence>,
|
2023-01-10 11:17:13 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
impl SyncObjects {
|
2023-01-13 14:10:25 +11:00
|
|
|
pub fn new(device: &ash::Device, frames_in_flight: usize) -> VkResult<SyncObjects> {
|
2023-01-10 11:17:13 +11:00
|
|
|
unsafe {
|
2023-01-13 14:10:25 +11:00
|
|
|
let mut image_available = Vec::new();
|
|
|
|
let mut render_finished = Vec::new();
|
|
|
|
let mut in_flight = Vec::new();
|
|
|
|
|
|
|
|
for _ in 0..frames_in_flight {
|
2023-01-13 17:48:04 +11:00
|
|
|
image_available
|
|
|
|
.push(device.create_semaphore(&vk::SemaphoreCreateInfo::default(), None)?);
|
|
|
|
render_finished
|
|
|
|
.push(device.create_semaphore(&vk::SemaphoreCreateInfo::default(), None)?);
|
|
|
|
in_flight.push(
|
|
|
|
device.create_fence(
|
|
|
|
&vk::FenceCreateInfo::builder()
|
|
|
|
.flags(vk::FenceCreateFlags::SIGNALED)
|
2023-02-16 14:57:20 +11:00
|
|
|
,
|
2023-01-13 17:48:04 +11:00
|
|
|
None,
|
|
|
|
)?,
|
|
|
|
)
|
2023-01-13 14:10:25 +11:00
|
|
|
}
|
2023-01-10 11:17:13 +11:00
|
|
|
|
|
|
|
Ok(SyncObjects {
|
|
|
|
image_available,
|
|
|
|
render_finished,
|
2023-01-10 14:54:54 +11:00
|
|
|
in_flight,
|
2023-01-10 11:17:13 +11:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-01-10 14:54:54 +11:00
|
|
|
}
|