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/ext: Add VK_EXT_calibrated_timestamps extension #556

Merged
merged 1 commit into from
Jan 17, 2022
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 @@ -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)
Ralith marked this conversation as resolved.
Show resolved Hide resolved
})
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetCalibratedTimestampsEXT.html>"]
///
MarijnS95 marked this conversation as resolved.
Show resolved Hide resolved
/// 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