diff --git a/Changelog.md b/Changelog.md index ca0c677..2060046 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Added `VK_EXT_calibrated_timestamps` device extension (#556) - Added `VK_KHR_get_surface_capabilities2` device extension (#530) ### Changed diff --git a/ash/src/extensions/ext/calibrated_timestamps.rs b/ash/src/extensions/ext/calibrated_timestamps.rs new file mode 100644 index 0000000..7b29ef6 --- /dev/null +++ b/ash/src/extensions/ext/calibrated_timestamps.rs @@ -0,0 +1,65 @@ +use crate::prelude::{read_into_uninitialized_vector, VkResult}; +use crate::vk; +use crate::{Entry, Instance}; +use std::ffi::CStr; +use std::mem; + +#[derive(Clone)] +pub struct CalibratedTimestamps { + handle: vk::Instance, + fp: vk::ExtCalibratedTimestampsFn, +} + +impl CalibratedTimestamps { + pub fn new(entry: &Entry, instance: &Instance) -> Self { + let handle = instance.handle(); + let fp = vk::ExtCalibratedTimestampsFn::load(|name| unsafe { + mem::transmute(entry.get_instance_proc_addr(handle, name.as_ptr())) + }); + Self { handle, fp } + } + + #[doc = ""] + 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_ext(physical_device, count, data) + }) + } + + #[doc = ""] + /// + /// Returns a tuple containing `(timestamps, max_deviation)` + pub unsafe fn get_calibrated_timestamps( + &self, + device: vk::Device, + info: &[vk::CalibratedTimestampInfoEXT], + ) -> VkResult<(Vec, Vec)> { + let mut timestamps = vec![0u64; info.len()]; + let mut max_deviation = vec![0u64; info.len()]; + self.fp + .get_calibrated_timestamps_ext( + device, + info.len() as u32, + info.as_ptr(), + timestamps.as_mut_ptr(), + max_deviation.as_mut_ptr(), + ) + .result_with_success((timestamps, max_deviation)) + } + + pub fn name() -> &'static CStr { + vk::ExtCalibratedTimestampsFn::name() + } + + pub fn fp(&self) -> &vk::ExtCalibratedTimestampsFn { + &self.fp + } + + pub fn instance(&self) -> vk::Instance { + self.handle + } +} diff --git a/ash/src/extensions/ext/mod.rs b/ash/src/extensions/ext/mod.rs index e25806e..529358f 100644 --- a/ash/src/extensions/ext/mod.rs +++ b/ash/src/extensions/ext/mod.rs @@ -1,4 +1,5 @@ pub use self::buffer_device_address::BufferDeviceAddress; +pub use self::calibrated_timestamps::CalibratedTimestamps; #[allow(deprecated)] pub use self::debug_marker::DebugMarker; #[allow(deprecated)] @@ -11,6 +12,7 @@ pub use self::physical_device_drm::PhysicalDeviceDrm; pub use self::tooling_info::ToolingInfo; mod buffer_device_address; +mod calibrated_timestamps; #[deprecated(note = "Please use the [DebugUtils](struct.DebugUtils.html) extension instead.")] mod debug_marker; #[deprecated(note = "Please use the [DebugUtils](struct.DebugUtils.html) extension instead.")]