diff --git a/Changelog.md b/Changelog.md index bfcd58b20..b7f34a902 100644 --- a/Changelog.md +++ b/Changelog.md @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added `Send`/`Sync` to all Vulkan structs (#869) - Added `VK_KHR_dynamic_rendering_local_read` device extension (#888) - Added `VK_KHR_line_rasterization` device extension (#889) +- Added `VK_KHR_calibrated_timestamps` device extension (#890) ### Changed diff --git a/ash/src/extensions/khr/calibrated_timestamps.rs b/ash/src/extensions/khr/calibrated_timestamps.rs new file mode 100644 index 000000000..fc8f31ff6 --- /dev/null +++ b/ash/src/extensions/khr/calibrated_timestamps.rs @@ -0,0 +1,87 @@ +//! + +use crate::prelude::*; +use crate::vk; +use alloc::vec::Vec; +use core::mem; +pub use vk::khr::calibrated_timestamps::NAME; + +/// High-level device function wrapper +#[derive(Clone)] +pub struct Device { + fp: vk::khr::calibrated_timestamps::DeviceFn, +} + +impl Device { + pub fn new(instance: &crate::Instance, device: &crate::Device) -> Self { + let handle = device.handle(); + let fp = vk::khr::calibrated_timestamps::DeviceFn::load(|name| unsafe { + mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr())) + }); + Self { fp } + } + + /// + /// + /// Returns a tuple containing `(timestamps, max_deviation)` + #[inline] + pub unsafe fn get_calibrated_timestamps( + &self, + device: vk::Device, + info: &[vk::CalibratedTimestampInfoKHR<'_>], + ) -> VkResult<(Vec, u64)> { + let mut timestamps = Vec::with_capacity(info.len()); + let mut max_deviation = mem::MaybeUninit::uninit(); + let max_deviation = (self.fp.get_calibrated_timestamps_khr)( + device, + info.len() as u32, + info.as_ptr(), + timestamps.as_mut_ptr(), + max_deviation.as_mut_ptr(), + ) + .assume_init_on_success(max_deviation)?; + timestamps.set_len(info.len()); + Ok((timestamps, max_deviation)) + } + + #[inline] + pub fn fp(&self) -> &vk::khr::calibrated_timestamps::DeviceFn { + &self.fp + } +} + +/// High-level instance function wrapper +#[derive(Clone)] +pub struct Instance { + fp: vk::khr::calibrated_timestamps::InstanceFn, +} + +impl Instance { + pub fn new(entry: &crate::Entry, instance: &crate::Instance) -> Self { + let handle = instance.handle(); + let fp = vk::khr::calibrated_timestamps::InstanceFn::load(|name| unsafe { + mem::transmute(entry.get_instance_proc_addr(handle, name.as_ptr())) + }); + Self { fp } + } + + /// + #[inline] + pub unsafe fn get_physical_device_calibrateable_time_domains( + &self, + physical_device: vk::PhysicalDevice, + ) -> VkResult> { + read_into_uninitialized_vector(|count, data| { + (self.fp.get_physical_device_calibrateable_time_domains_khr)( + physical_device, + count, + data, + ) + }) + } + + #[inline] + pub fn fp(&self) -> &vk::khr::calibrated_timestamps::InstanceFn { + &self.fp + } +} diff --git a/ash/src/extensions/khr/mod.rs b/ash/src/extensions/khr/mod.rs index 81ff8a11f..d2e064b77 100644 --- a/ash/src/extensions/khr/mod.rs +++ b/ash/src/extensions/khr/mod.rs @@ -1,5 +1,6 @@ pub mod android_surface; pub mod buffer_device_address; +pub mod calibrated_timestamps; pub mod cooperative_matrix; pub mod copy_commands2; pub mod create_render_pass2;