Skip to content

Commit

Permalink
extensions/ext: Add VK_EXT_calibrated_timestamps extension (#556)
Browse files Browse the repository at this point in the history
This extension can be used to correlate timestamps on the GPU timeline
(`vkCmdWriteTimestamp`, `vkCmdWriteTimestamp2KHR`) to the CPU timeline
(ie. `CLOCK_MONOTONIC` and friends).
  • Loading branch information
MarijnS95 committed Jan 17, 2022
1 parent 98192d1 commit 5169862
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
65 changes: 65 additions & 0 deletions ash/src/extensions/ext/calibrated_timestamps.rs
Original file line number Diff line number Diff line change
@@ -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 = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceCalibrateableTimeDomainsEXT.html>"]
pub unsafe fn get_physical_device_calibrateable_time_domains(
&self,
physical_device: vk::PhysicalDevice,
) -> VkResult<Vec<vk::TimeDomainEXT>> {
read_into_uninitialized_vector(|count, data| {
self.fp
.get_physical_device_calibrateable_time_domains_ext(physical_device, count, data)
})
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetCalibratedTimestampsEXT.html>"]
///
/// Returns a tuple containing `(timestamps, max_deviation)`
pub unsafe fn get_calibrated_timestamps(
&self,
device: vk::Device,
info: &[vk::CalibratedTimestampInfoEXT],
) -> VkResult<(Vec<u64>, Vec<u64>)> {
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
}
}
2 changes: 2 additions & 0 deletions ash/src/extensions/ext/mod.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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.")]
Expand Down

0 comments on commit 5169862

Please sign in to comment.