-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extensions/ext: Add VK_EXT_calibrated_timestamps extension
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
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters