From 2d2aeac84a75fd4507f612efd5677cb0afd7ba32 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Wed, 25 Oct 2023 20:02:19 +0200 Subject: [PATCH] extensions/nv: Add VK_NV_low_latency2 extension (#802) --- Changelog.md | 1 + ash/src/device.rs | 2 +- ash/src/extensions/nv/low_latency2.rs | 105 ++++++++++++++++++++++++++ ash/src/extensions/nv/mod.rs | 2 + 4 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 ash/src/extensions/nv/low_latency2.rs diff --git a/Changelog.md b/Changelog.md index 225d3eb..d98a3f2 100644 --- a/Changelog.md +++ b/Changelog.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added `VK_EXT_vertex_input_dynamic_state` device extension (#784) - Added `VK_KHR_sampler_ycbcr_conversion` device extension (#785) - Added `VK_EXT_swapchain_maintenance1` device extension (#786) +- Added `VK_NV_low_latency2` device extension (#802) ### Changed diff --git a/ash/src/device.rs b/ash/src/device.rs index 0ecea2c..817235f 100644 --- a/ash/src/device.rs +++ b/ash/src/device.rs @@ -518,7 +518,7 @@ impl Device { self.handle, memory_requirements, &mut count, - std::ptr::null_mut(), + ptr::null_mut(), ); count as usize } diff --git a/ash/src/extensions/nv/low_latency2.rs b/ash/src/extensions/nv/low_latency2.rs new file mode 100644 index 0000000..88a1f92 --- /dev/null +++ b/ash/src/extensions/nv/low_latency2.rs @@ -0,0 +1,105 @@ +use crate::prelude::*; +use crate::vk; +use crate::RawPtr; +use crate::{Device, Instance}; +use std::ffi::CStr; +use std::mem; +use std::ptr; + +/// +#[derive(Clone)] +pub struct LowLatency2 { + handle: vk::Device, + fp: vk::NvLowLatency2Fn, +} + +impl LowLatency2 { + pub fn new(instance: &Instance, device: &Device) -> Self { + let handle = device.handle(); + let fp = vk::NvLowLatency2Fn::load(|name| unsafe { + mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr())) + }); + Self { handle, fp } + } + + /// + #[inline] + pub unsafe fn set_latency_sleep_mode( + &self, + swapchain: vk::SwapchainKHR, + sleep_mode_info: Option<&vk::LatencySleepModeInfoNV<'_>>, + ) -> VkResult<()> { + (self.fp.set_latency_sleep_mode_nv)(self.handle, swapchain, sleep_mode_info.as_raw_ptr()) + .result() + } + + /// + #[inline] + pub unsafe fn latency_sleep( + &self, + swapchain: vk::SwapchainKHR, + sleep_info: &vk::LatencySleepInfoNV<'_>, + ) -> VkResult<()> { + (self.fp.latency_sleep_nv)(self.handle, swapchain, sleep_info).result() + } + + /// + #[inline] + pub unsafe fn set_latency_marker( + &self, + swapchain: vk::SwapchainKHR, + latency_marker_info: &vk::SetLatencyMarkerInfoNV<'_>, + ) { + (self.fp.set_latency_marker_nv)(self.handle, swapchain, latency_marker_info) + } + + /// Retrieve the number of elements to pass to [`get_latency_timings()`][Self::get_latency_timings()] + #[inline] + pub unsafe fn get_latency_timings_len(&self, swapchain: vk::SwapchainKHR) -> usize { + let mut count = 0; + (self.fp.get_latency_timings_nv)(self.handle, swapchain, &mut count, ptr::null_mut()); + count as usize + } + + /// + /// + /// Call [`get_latency_timings_len()`][Self::get_latency_timings_len()] to query the number of elements to pass to `latency_marker_info`. + /// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer. + #[inline] + pub unsafe fn get_latency_timings( + &self, + swapchain: vk::SwapchainKHR, + latency_marker_info: &mut [vk::GetLatencyMarkerInfoNV<'_>], + ) { + let mut count = latency_marker_info.len() as u32; + (self.fp.get_latency_timings_nv)( + self.handle, + swapchain, + &mut count, + latency_marker_info.as_mut_ptr(), + ); + assert_eq!(count as usize, latency_marker_info.len()); + } + + /// + #[inline] + pub unsafe fn queue_notify_out_of_band( + &self, + queue: vk::Queue, + queue_type_info: &vk::OutOfBandQueueTypeInfoNV<'_>, + ) { + (self.fp.queue_notify_out_of_band_nv)(queue, queue_type_info) + } + + pub const NAME: &'static CStr = vk::NvLowLatency2Fn::NAME; + + #[inline] + pub fn fp(&self) -> &vk::NvLowLatency2Fn { + &self.fp + } + + #[inline] + pub fn device(&self) -> vk::Device { + self.handle + } +} diff --git a/ash/src/extensions/nv/mod.rs b/ash/src/extensions/nv/mod.rs index 0065426..3b08ae3 100644 --- a/ash/src/extensions/nv/mod.rs +++ b/ash/src/extensions/nv/mod.rs @@ -1,6 +1,7 @@ pub use self::coverage_reduction_mode::CoverageReductionMode; pub use self::device_diagnostic_checkpoints::DeviceDiagnosticCheckpoints; pub use self::device_generated_commands_compute::DeviceGeneratedCommandsCompute; +pub use self::low_latency2::LowLatency2; pub use self::memory_decompression::MemoryDecompression; pub use self::mesh_shader::MeshShader; pub use self::ray_tracing::RayTracing; @@ -8,6 +9,7 @@ pub use self::ray_tracing::RayTracing; mod coverage_reduction_mode; mod device_diagnostic_checkpoints; mod device_generated_commands_compute; +mod low_latency2; mod memory_decompression; mod mesh_shader; mod ray_tracing;