diff --git a/ash/src/extensions/khr/mod.rs b/ash/src/extensions/khr/mod.rs index 3f0e032..31a40a7 100644 --- a/ash/src/extensions/khr/mod.rs +++ b/ash/src/extensions/khr/mod.rs @@ -6,6 +6,7 @@ pub use self::push_descriptor::PushDescriptor; pub use self::ray_tracing::RayTracing; pub use self::surface::Surface; pub use self::swapchain::Swapchain; +pub use self::timeline_semaphore::TimelineSemaphore; pub use self::wayland_surface::WaylandSurface; pub use self::win32_surface::Win32Surface; pub use self::xcb_surface::XcbSurface; @@ -19,6 +20,7 @@ mod push_descriptor; mod ray_tracing; mod surface; mod swapchain; +mod timeline_semaphore; mod wayland_surface; mod win32_surface; mod xcb_surface; diff --git a/ash/src/extensions/khr/timeline_semaphore.rs b/ash/src/extensions/khr/timeline_semaphore.rs new file mode 100644 index 0000000..09190ea --- /dev/null +++ b/ash/src/extensions/khr/timeline_semaphore.rs @@ -0,0 +1,87 @@ +#![allow(dead_code)] +use crate::prelude::*; +use crate::version::{EntryV1_0, InstanceV1_0}; +use crate::vk; +use std::ffi::CStr; +use std::mem; + +#[derive(Clone)] +pub struct TimelineSemaphore { + handle: vk::Instance, + timeline_semaphore_fn: vk::KhrTimelineSemaphoreFn, +} + +impl TimelineSemaphore { + pub fn new(entry: &E, instance: &I) -> TimelineSemaphore { + let timeline_semaphore_fn = vk::KhrTimelineSemaphoreFn::load(|name| unsafe { + mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) + }); + + TimelineSemaphore { + handle: instance.handle(), + timeline_semaphore_fn, + } + } + + pub fn name() -> &'static CStr { + vk::KhrTimelineSemaphoreFn::name() + } + + #[doc = ""] + pub unsafe fn get_semaphore_counter_value( + &self, + device: vk::Device, + semaphore: vk::Semaphore, + ) -> VkResult { + let mut value = 0; + let err_code = self + .timeline_semaphore_fn + .get_semaphore_counter_value_khr(device, semaphore, &mut value); + + match err_code { + vk::Result::SUCCESS => Ok(value), + _ => Err(err_code), + } + } + + #[doc = ""] + pub unsafe fn wait_semaphores( + &self, + device: vk::Device, + wait_info: &vk::SemaphoreWaitInfo, + timeout: u64, + ) -> VkResult<()> { + let err_code = self + .timeline_semaphore_fn + .wait_semaphores_khr(device, wait_info, timeout); + + match err_code { + vk::Result::SUCCESS => Ok(()), + _ => Err(err_code), + } + } + + #[doc = ""] + pub unsafe fn signal_semaphore( + &self, + device: vk::Device, + signal_info: &vk::SemaphoreSignalInfo, + ) -> VkResult<()> { + let err_code = self + .timeline_semaphore_fn + .signal_semaphore_khr(device, signal_info); + + match err_code { + vk::Result::SUCCESS => Ok(()), + _ => Err(err_code), + } + } + + pub fn fp(&self) -> &vk::KhrTimelineSemaphoreFn { + &self.timeline_semaphore_fn + } + + pub fn instance(&self) -> vk::Instance { + self.handle + } +}