Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extensions/khr: Add VK_KHR_calibrated_timestamps #890

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
87 changes: 87 additions & 0 deletions ash/src/extensions/khr/calibrated_timestamps.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//! <https://registry.khronos.org//vulkan/specs/1.3-extensions/man/html/VK_KHR_calibrated_timestamps.html>

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

/// <https://registry.khronos.org//vulkan/specs/1.3-extensions/man/html/vkGetCalibratedTimestampsKHR.html>
///
/// Returns a tuple containing `(timestamps, max_deviation)`
#[inline]
pub unsafe fn get_calibrated_timestamps(
&self,
device: vk::Device,
info: &[vk::CalibratedTimestampInfoKHR<'_>],
) -> VkResult<(Vec<u64>, 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 }
}

/// <https://registry.khronos.org//vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceCalibrateableTimeDomainsKHR.html>
#[inline]
pub unsafe fn get_physical_device_calibrateable_time_domains(
&self,
physical_device: vk::PhysicalDevice,
) -> VkResult<Vec<vk::TimeDomainKHR>> {
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
}
}
1 change: 1 addition & 0 deletions ash/src/extensions/khr/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down