From 369fe05e79d4db201404f51aaac302efc776861d Mon Sep 17 00:00:00 2001 From: Chris Spencer Date: Tue, 11 Jul 2023 14:45:04 +0100 Subject: [PATCH] extensions/google: Add VK_GOOGLE_display_timing (#765) --- Changelog.md | 1 + ash/src/extensions/google/display_timing.rs | 56 +++++++++++++++++++++ ash/src/extensions/google/mod.rs | 3 ++ ash/src/extensions/mod.rs | 1 + 4 files changed, 61 insertions(+) create mode 100644 ash/src/extensions/google/display_timing.rs create mode 100644 ash/src/extensions/google/mod.rs diff --git a/Changelog.md b/Changelog.md index d2d69e1..5decd99 100644 --- a/Changelog.md +++ b/Changelog.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Allow building `Entry`/`Instance`/`Device` from handle+fns (see their `from_parts_1_x()` associated functions) (#748) - Update Vulkan-Headers to 1.3.254 (#760) - Added `VK_NV_memory_decompression` device extension (#761) +- Added `VK_GOOGLE_display_timing` device extension (#765) ### Changed diff --git a/ash/src/extensions/google/display_timing.rs b/ash/src/extensions/google/display_timing.rs new file mode 100644 index 0000000..6b912cf --- /dev/null +++ b/ash/src/extensions/google/display_timing.rs @@ -0,0 +1,56 @@ +use crate::prelude::*; +use crate::vk; +use crate::{Device, Instance}; +use std::ffi::CStr; +use std::mem; + +/// +#[derive(Clone)] +pub struct DisplayTiming { + handle: vk::Device, + fp: vk::GoogleDisplayTimingFn, +} + +impl DisplayTiming { + pub fn new(instance: &Instance, device: &Device) -> Self { + let handle = device.handle(); + let fp = vk::GoogleDisplayTimingFn::load(|name| unsafe { + mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr())) + }); + Self { handle, fp } + } + + /// + #[inline] + pub unsafe fn get_past_presentation_timing( + &self, + swapchain: vk::SwapchainKHR, + ) -> VkResult> { + read_into_uninitialized_vector(|count, data| { + (self.fp.get_past_presentation_timing_google)(self.handle, swapchain, count, data) + }) + } + + /// + #[inline] + pub unsafe fn get_refresh_cycle_duration( + &self, + swapchain: vk::SwapchainKHR, + ) -> VkResult { + let mut properties = mem::zeroed(); + (self.fp.get_refresh_cycle_duration_google)(self.handle, swapchain, &mut properties) + .result_with_success(properties) + } + + pub const NAME: &'static CStr = vk::GoogleDisplayTimingFn::NAME; + + #[inline] + pub fn fp(&self) -> &vk::GoogleDisplayTimingFn { + &self.fp + } + + #[inline] + pub fn device(&self) -> vk::Device { + self.handle + } +} diff --git a/ash/src/extensions/google/mod.rs b/ash/src/extensions/google/mod.rs new file mode 100644 index 0000000..7763d50 --- /dev/null +++ b/ash/src/extensions/google/mod.rs @@ -0,0 +1,3 @@ +pub use self::display_timing::DisplayTiming; + +mod display_timing; diff --git a/ash/src/extensions/mod.rs b/ash/src/extensions/mod.rs index 0e164d0..99d0c1f 100644 --- a/ash/src/extensions/mod.rs +++ b/ash/src/extensions/mod.rs @@ -1,4 +1,5 @@ pub mod ext; +pub mod google; pub mod khr; pub mod mvk; pub mod nn;