extensions/ext: Add VK_EXT_calibrated_timestamps extension (#556)

This extension can be used to correlate timestamps on the GPU timeline
(`vkCmdWriteTimestamp`, `vkCmdWriteTimestamp2KHR`) to the CPU timeline
(ie. `CLOCK_MONOTONIC` and friends).
This commit is contained in:
Marijn Suijten 2022-01-17 16:32:05 +01:00 committed by GitHub
parent 98192d11f2
commit 5169862dbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 0 deletions

View file

@ -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

View file

@ -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
}
}

View file

@ -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.")]