From ef3e459e1c89157cda8de320847337a545cb7f0c Mon Sep 17 00:00:00 2001 From: cach30verfl0w Date: Thu, 9 May 2024 20:54:52 +0200 Subject: [PATCH 01/11] Add support for vulkan video extensions --- ash/src/extensions/khr/mod.rs | 3 + ash/src/extensions/khr/video_decode_queue.rs | 15 ++ ash/src/extensions/khr/video_encode_queue.rs | 47 ++++++ ash/src/extensions/khr/video_queue.rs | 146 +++++++++++++++++++ 4 files changed, 211 insertions(+) create mode 100644 ash/src/extensions/khr/video_decode_queue.rs create mode 100644 ash/src/extensions/khr/video_encode_queue.rs create mode 100644 ash/src/extensions/khr/video_queue.rs diff --git a/ash/src/extensions/khr/mod.rs b/ash/src/extensions/khr/mod.rs index 5552598be..ac8798331 100644 --- a/ash/src/extensions/khr/mod.rs +++ b/ash/src/extensions/khr/mod.rs @@ -39,6 +39,9 @@ pub mod surface; pub mod swapchain; pub mod synchronization2; pub mod timeline_semaphore; +pub mod video_decode_queue; +pub mod video_encode_queue; +pub mod video_queue; pub mod wayland_surface; pub mod win32_surface; pub mod xcb_surface; diff --git a/ash/src/extensions/khr/video_decode_queue.rs b/ash/src/extensions/khr/video_decode_queue.rs new file mode 100644 index 000000000..bd2007ff7 --- /dev/null +++ b/ash/src/extensions/khr/video_decode_queue.rs @@ -0,0 +1,15 @@ +//! + +use crate::vk; + +impl crate::khr::video_decode_queue::Device { + /// + #[inline] + pub unsafe fn cmd_decode_video( + &self, + command_buffer: vk::CommandBuffer, + decode_info: &vk::VideoDecodeInfoKHR<'_>, + ) { + (self.fp.cmd_decode_video_khr)(command_buffer, decode_info) + } +} diff --git a/ash/src/extensions/khr/video_encode_queue.rs b/ash/src/extensions/khr/video_encode_queue.rs new file mode 100644 index 000000000..3f79bff70 --- /dev/null +++ b/ash/src/extensions/khr/video_encode_queue.rs @@ -0,0 +1,47 @@ +//! + +use crate::prelude::VkResult; +use crate::vk; +use core::mem; + +impl crate::khr::video_encode_queue::Device { + /// + pub unsafe fn get_encoded_video_session_parameters( + &self, + video_session_parameters_info: &vk::VideoEncodeSessionParametersGetInfoKHR<'_>, + ) -> VkResult<(vk::VideoEncodeSessionParametersFeedbackInfoKHR<'_>, Vec)> { + loop { + let mut count: usize = 0; + let _ = (self.fp.get_encoded_video_session_parameters_khr)( + self.handle, + video_session_parameters_info, + core::ptr::null_mut(), + &mut count, + core::ptr::null_mut(), + ); + + let mut data: Vec = Vec::with_capacity(count); + let mut feedback_info = mem::MaybeUninit::uninit(); + let result = (self.fp.get_encoded_video_session_parameters_khr)( + self.handle, + video_session_parameters_info, + feedback_info.as_mut_ptr(), + &mut count, + data.as_mut_ptr() as _, + ); + if result != vk::Result::INCOMPLETE { + break result.assume_init_on_success(feedback_info).map(|value| (value, data)); + } + } + } + + /// + #[inline] + pub unsafe fn cmd_encode_video( + &self, + command_buffer: vk::CommandBuffer, + encode_info: &vk::VideoEncodeInfoKHR<'_>, + ) { + (self.fp.cmd_encode_video_khr)(command_buffer, encode_info) + } +} diff --git a/ash/src/extensions/khr/video_queue.rs b/ash/src/extensions/khr/video_queue.rs new file mode 100644 index 000000000..2e3686310 --- /dev/null +++ b/ash/src/extensions/khr/video_queue.rs @@ -0,0 +1,146 @@ +//! + +use crate::prelude::{read_into_uninitialized_vector, VkResult}; +use crate::{vk, RawPtr}; +use core::mem; + +impl crate::khr::video_queue::Device { + /// + #[inline] + pub unsafe fn create_video_session( + &self, + create_info: &vk::VideoSessionCreateInfoKHR<'_>, + allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, + ) -> VkResult { + let mut video_session = mem::MaybeUninit::uninit(); + (self.fp.create_video_session_khr)( + self.handle, + create_info, + allocation_callbacks.as_raw_ptr(), + video_session.as_mut_ptr(), + ) + .assume_init_on_success(video_session) + } + + /// + #[inline] + pub unsafe fn destroy_video_session( + &self, + video_session: vk::VideoSessionKHR, + allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, + ) { + (self.fp.destroy_video_session_khr)( + self.handle, + video_session, + allocation_callbacks.as_raw_ptr(), + ) + } + + /// + #[inline] + pub unsafe fn get_video_session_memory_requirements( + &self, + video_session: vk::VideoSessionKHR, + ) -> VkResult>> { + read_into_uninitialized_vector(|count, data| { + (self.fp.get_video_session_memory_requirements_khr)( + self.handle, + video_session, + count, + data, + ) + }) + } + + /// + #[inline] + pub unsafe fn bind_video_session_memory( + &self, + video_session: vk::VideoSessionKHR, + bind_session_memory_infos: &[vk::BindVideoSessionMemoryInfoKHR<'_>], + ) -> VkResult<()> { + (self.fp.bind_video_session_memory_khr)( + self.handle, + video_session, + bind_session_memory_infos.len() as _, + bind_session_memory_infos.as_ptr(), + ) + .result() + } + + /// + #[inline] + pub unsafe fn create_video_session_parameters( + &self, + create_info: &vk::VideoSessionParametersCreateInfoKHR<'_>, + allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, + ) -> VkResult { + let mut parameters = mem::MaybeUninit::uninit(); + (self.fp.create_video_session_parameters_khr)( + self.handle, + create_info, + allocation_callbacks.as_raw_ptr(), + parameters.as_mut_ptr(), + ) + .assume_init_on_success(parameters) + } + + /// + #[inline] + pub unsafe fn update_video_session_parameters( + &self, + video_session_parameters: vk::VideoSessionParametersKHR, + update_info: &vk::VideoSessionParametersUpdateInfoKHR<'_>, + ) -> VkResult<()> { + (self.fp.update_video_session_parameters_khr)( + self.handle, + video_session_parameters, + update_info, + ) + .result() + } + + /// + #[inline] + pub unsafe fn destroy_video_session_parameters( + &self, + video_session_parameters: vk::VideoSessionParametersKHR, + allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, + ) { + (self.fp.destroy_video_session_parameters_khr)( + self.handle, + video_session_parameters, + allocation_callbacks.as_raw_ptr(), + ) + } + + /// + #[inline] + pub unsafe fn cmd_begin_video_coding( + &self, + command_buffer: vk::CommandBuffer, + begin_info: &vk::VideoBeginCodingInfoKHR<'_>, + ) { + (self.fp.cmd_begin_video_coding_khr)(command_buffer, begin_info) + } + + /// + #[inline] + pub unsafe fn cmd_end_video_coding( + &self, + command_buffer: vk::CommandBuffer, + end_coding_info: &vk::VideoEndCodingInfoKHR<'_>, + ) { + (self.fp.cmd_end_video_coding_khr)(command_buffer, end_coding_info) + } + + /// + #[inline] + pub unsafe fn cmd_control_video_coding( + &self, + command_buffer: vk::CommandBuffer, + coding_control_info: &vk::VideoCodingControlInfoKHR<'_>, + ) { + (self.fp.cmd_control_video_coding_khr)(command_buffer, coding_control_info) + } +} From fd5650a485747ff0189eb78f5f50ef04318260f5 Mon Sep 17 00:00:00 2001 From: cach30verfl0w Date: Thu, 9 May 2024 22:31:54 +0200 Subject: [PATCH 02/11] Split get_video_session_memory_requirements in 2 functions --- ash/src/extensions/khr/video_queue.rs | 40 ++++++++++++++++++++------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/ash/src/extensions/khr/video_queue.rs b/ash/src/extensions/khr/video_queue.rs index 2e3686310..d947e1418 100644 --- a/ash/src/extensions/khr/video_queue.rs +++ b/ash/src/extensions/khr/video_queue.rs @@ -1,8 +1,9 @@ //! -use crate::prelude::{read_into_uninitialized_vector, VkResult}; +use crate::prelude::VkResult; use crate::{vk, RawPtr}; use core::mem; +use std::ptr; impl crate::khr::video_queue::Device { /// @@ -36,20 +37,39 @@ impl crate::khr::video_queue::Device { ) } + // Retrieve the number of elements to pass to [`get_video_session_memory_requirements`][Self::get_video_session_memory_requirements] + pub unsafe fn get_video_session_memory_requirements_len( + &self, + video_session: vk::VideoSessionKHR + ) -> usize { + let mut memory_requirements_count = mem::MaybeUninit::uninit(); + let _ = (self.fp.get_video_session_memory_requirements_khr)( + self.handle, + video_session, + memory_requirements_count.as_mut_ptr(), + ptr::null_mut() + ); + memory_requirements_count.assume_init() as _ + } + /// + /// + /// Call [`get_video_session_memory_requirements_len()`][Self::get_video_session_memory_requirements_len()] to query the number of elements to pass to `out`. + /// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer. #[inline] pub unsafe fn get_video_session_memory_requirements( &self, video_session: vk::VideoSessionKHR, - ) -> VkResult>> { - read_into_uninitialized_vector(|count, data| { - (self.fp.get_video_session_memory_requirements_khr)( - self.handle, - video_session, - count, - data, - ) - }) + out: &mut [vk::VideoSessionMemoryRequirementsKHR<'_>] + ) { + let mut count = out.len() as u32; + let _ = (self.fp.get_video_session_memory_requirements_khr)( + self.handle, + video_session, + &mut count, + out.as_mut_ptr() + ); + assert_eq!(count, out.len()); } /// From eafc3d18d0bd7a65b026f93e54b1727ce57953b7 Mon Sep 17 00:00:00 2001 From: cach30verfl0w Date: Thu, 9 May 2024 22:35:57 +0200 Subject: [PATCH 03/11] Update Changelog.md --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 6eca17243..f717a5df1 100644 --- a/Changelog.md +++ b/Changelog.md @@ -90,6 +90,7 @@ By disabling the default `std` feature, this crate compiles in a [`no_std` envir - Added `VK_KHR_calibrated_timestamps` device extension (#890) - Added `VK_KHR_maintenance6` device extension (#891) - Added `VK_NV_copy_memory_indirect` device extension (#892) +- Added support for vulkan video extensions (#916) ### Changed From 463b8d66e3192b56984424121b73d1633819cddc Mon Sep 17 00:00:00 2001 From: cach30verfl0w Date: Thu, 9 May 2024 22:38:52 +0200 Subject: [PATCH 04/11] Run fmt and clippy --- ash/src/extensions/khr/video_encode_queue.rs | 4 +++- ash/src/extensions/khr/video_queue.rs | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ash/src/extensions/khr/video_encode_queue.rs b/ash/src/extensions/khr/video_encode_queue.rs index 3f79bff70..0a689922a 100644 --- a/ash/src/extensions/khr/video_encode_queue.rs +++ b/ash/src/extensions/khr/video_encode_queue.rs @@ -30,7 +30,9 @@ impl crate::khr::video_encode_queue::Device { data.as_mut_ptr() as _, ); if result != vk::Result::INCOMPLETE { - break result.assume_init_on_success(feedback_info).map(|value| (value, data)); + break result + .assume_init_on_success(feedback_info) + .map(|value| (value, data)); } } } diff --git a/ash/src/extensions/khr/video_queue.rs b/ash/src/extensions/khr/video_queue.rs index d947e1418..3f789e1e3 100644 --- a/ash/src/extensions/khr/video_queue.rs +++ b/ash/src/extensions/khr/video_queue.rs @@ -40,14 +40,14 @@ impl crate::khr::video_queue::Device { // Retrieve the number of elements to pass to [`get_video_session_memory_requirements`][Self::get_video_session_memory_requirements] pub unsafe fn get_video_session_memory_requirements_len( &self, - video_session: vk::VideoSessionKHR + video_session: vk::VideoSessionKHR, ) -> usize { let mut memory_requirements_count = mem::MaybeUninit::uninit(); let _ = (self.fp.get_video_session_memory_requirements_khr)( self.handle, video_session, memory_requirements_count.as_mut_ptr(), - ptr::null_mut() + ptr::null_mut(), ); memory_requirements_count.assume_init() as _ } @@ -60,16 +60,16 @@ impl crate::khr::video_queue::Device { pub unsafe fn get_video_session_memory_requirements( &self, video_session: vk::VideoSessionKHR, - out: &mut [vk::VideoSessionMemoryRequirementsKHR<'_>] + out: &mut [vk::VideoSessionMemoryRequirementsKHR<'_>], ) { let mut count = out.len() as u32; let _ = (self.fp.get_video_session_memory_requirements_khr)( self.handle, video_session, &mut count, - out.as_mut_ptr() + out.as_mut_ptr(), ); - assert_eq!(count, out.len()); + assert_eq!(count as usize, out.len()); } /// From 3a1d446fe6d0c54e6cf12efbd54f853646b1cde5 Mon Sep 17 00:00:00 2001 From: cach30verfl0w Date: Fri, 10 May 2024 00:45:36 +0200 Subject: [PATCH 05/11] Add instance functions to video_queue.rs --- ash/src/extensions/khr/video_queue.rs | 55 +++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/ash/src/extensions/khr/video_queue.rs b/ash/src/extensions/khr/video_queue.rs index 3f789e1e3..38b9ff55c 100644 --- a/ash/src/extensions/khr/video_queue.rs +++ b/ash/src/extensions/khr/video_queue.rs @@ -5,6 +5,61 @@ use crate::{vk, RawPtr}; use core::mem; use std::ptr; +impl crate::khr::video_queue::Instance { + /// + #[inline] + pub unsafe fn get_physical_device_video_capabilities( + &self, + physical_device: vk::PhysicalDevice, + video_profile: &vk::VideoProfileInfoKHR<'_>, + ) -> VkResult { + let mut video_capabilities = mem::MaybeUninit::uninit(); + (self.fp.get_physical_device_video_capabilities_khr)( + physical_device, + video_profile, + video_capabilities.as_mut_ptr(), + ) + .assume_init_on_success(video_capabilities) + } + + // Retrieve the number of elements to pass to [`get_physical_device_video_format_properties`][Self::get_physical_device_video_format_properties] + pub unsafe fn get_physical_device_video_format_properties_len( + &self, + physical_device: vk::PhysicalDevice, + video_format_info: &vk::PhysicalDeviceVideoFormatInfoKHR<'_>, + ) -> usize { + let mut memory_requirements_count = mem::MaybeUninit::uninit(); + let _ = (self.fp.get_physical_device_video_format_properties_khr)( + physical_device, + video_format_info, + memory_requirements_count.as_mut_ptr(), + ptr::null_mut(), + ); + memory_requirements_count.assume_init() as _ + } + + /// + /// + /// Call [`get_physical_device_video_format_properties_len()`][Self::get_physical_device_video_format_properties_len()] to query the number of elements to pass to `out`. + /// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer. + #[inline] + pub unsafe fn get_video_session_memory_requirements( + &self, + physical_device: vk::PhysicalDevice, + video_format_info: &vk::PhysicalDeviceVideoFormatInfoKHR<'_>, + out: &mut [vk::VideoFormatPropertiesKHR<'_>], + ) { + let mut count = out.len() as u32; + let _ = (self.fp.get_physical_device_video_format_properties_khr)( + physical_device, + video_format_info, + &mut count, + out.as_mut_ptr(), + ); + assert_eq!(count as usize, out.len()); + } +} + impl crate::khr::video_queue::Device { /// #[inline] From 058cee4c2ff6914c7391947484eaa63a3c04f0dd Mon Sep 17 00:00:00 2001 From: cach30verfl0w Date: Fri, 10 May 2024 00:48:35 +0200 Subject: [PATCH 06/11] Rename function --- ash/src/extensions/khr/video_queue.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ash/src/extensions/khr/video_queue.rs b/ash/src/extensions/khr/video_queue.rs index 38b9ff55c..b583c89f8 100644 --- a/ash/src/extensions/khr/video_queue.rs +++ b/ash/src/extensions/khr/video_queue.rs @@ -43,7 +43,7 @@ impl crate::khr::video_queue::Instance { /// Call [`get_physical_device_video_format_properties_len()`][Self::get_physical_device_video_format_properties_len()] to query the number of elements to pass to `out`. /// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer. #[inline] - pub unsafe fn get_video_session_memory_requirements( + pub unsafe fn get_physical_device_video_format_properties( &self, physical_device: vk::PhysicalDevice, video_format_info: &vk::PhysicalDeviceVideoFormatInfoKHR<'_>, From ef7ae0c9b9f3e6816873e7b2dcad46989c5b423d Mon Sep 17 00:00:00 2001 From: cach30verfl0w Date: Fri, 10 May 2024 13:05:07 +0200 Subject: [PATCH 07/11] Add missing inlines --- ash/src/extensions/khr/video_queue.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ash/src/extensions/khr/video_queue.rs b/ash/src/extensions/khr/video_queue.rs index b583c89f8..afb948b31 100644 --- a/ash/src/extensions/khr/video_queue.rs +++ b/ash/src/extensions/khr/video_queue.rs @@ -23,6 +23,7 @@ impl crate::khr::video_queue::Instance { } // Retrieve the number of elements to pass to [`get_physical_device_video_format_properties`][Self::get_physical_device_video_format_properties] + #[inline] pub unsafe fn get_physical_device_video_format_properties_len( &self, physical_device: vk::PhysicalDevice, @@ -93,6 +94,7 @@ impl crate::khr::video_queue::Device { } // Retrieve the number of elements to pass to [`get_video_session_memory_requirements`][Self::get_video_session_memory_requirements] + #[inline] pub unsafe fn get_video_session_memory_requirements_len( &self, video_session: vk::VideoSessionKHR, From 82984efa919afb0de9eac4c541717aca44cab4b1 Mon Sep 17 00:00:00 2001 From: cach30verfl0w Date: Fri, 10 May 2024 13:39:39 +0200 Subject: [PATCH 08/11] Fix warning --- ash/src/extensions/khr/video_queue.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ash/src/extensions/khr/video_queue.rs b/ash/src/extensions/khr/video_queue.rs index afb948b31..c14ab5e9b 100644 --- a/ash/src/extensions/khr/video_queue.rs +++ b/ash/src/extensions/khr/video_queue.rs @@ -12,7 +12,7 @@ impl crate::khr::video_queue::Instance { &self, physical_device: vk::PhysicalDevice, video_profile: &vk::VideoProfileInfoKHR<'_>, - ) -> VkResult { + ) -> VkResult> { let mut video_capabilities = mem::MaybeUninit::uninit(); (self.fp.get_physical_device_video_capabilities_khr)( physical_device, From e5793b82988498063865f82cb24f8646b080c251 Mon Sep 17 00:00:00 2001 From: cach30verfl0w Date: Fri, 10 May 2024 16:26:08 +0200 Subject: [PATCH 09/11] Fix get_physical_device_video_capabilities --- ash/src/extensions/khr/video_queue.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ash/src/extensions/khr/video_queue.rs b/ash/src/extensions/khr/video_queue.rs index c14ab5e9b..9e7ac6772 100644 --- a/ash/src/extensions/khr/video_queue.rs +++ b/ash/src/extensions/khr/video_queue.rs @@ -12,14 +12,13 @@ impl crate::khr::video_queue::Instance { &self, physical_device: vk::PhysicalDevice, video_profile: &vk::VideoProfileInfoKHR<'_>, - ) -> VkResult> { - let mut video_capabilities = mem::MaybeUninit::uninit(); + capabilities: &mut vk::VideoCapabilitiesKHR<'_> + ) -> VkResult<()> { (self.fp.get_physical_device_video_capabilities_khr)( physical_device, video_profile, - video_capabilities.as_mut_ptr(), - ) - .assume_init_on_success(video_capabilities) + capabilities, + ).result() } // Retrieve the number of elements to pass to [`get_physical_device_video_format_properties`][Self::get_physical_device_video_format_properties] From c4dd27fc5fe5b39b14e1703963d8671d1db71169 Mon Sep 17 00:00:00 2001 From: cach30verfl0w Date: Fri, 10 May 2024 18:08:39 +0200 Subject: [PATCH 10/11] Fix some functions --- ash/src/extensions/khr/video_queue.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/ash/src/extensions/khr/video_queue.rs b/ash/src/extensions/khr/video_queue.rs index 9e7ac6772..aedc1c240 100644 --- a/ash/src/extensions/khr/video_queue.rs +++ b/ash/src/extensions/khr/video_queue.rs @@ -48,15 +48,14 @@ impl crate::khr::video_queue::Instance { physical_device: vk::PhysicalDevice, video_format_info: &vk::PhysicalDeviceVideoFormatInfoKHR<'_>, out: &mut [vk::VideoFormatPropertiesKHR<'_>], - ) { + ) -> VkResult<()> { let mut count = out.len() as u32; - let _ = (self.fp.get_physical_device_video_format_properties_khr)( + (self.fp.get_physical_device_video_format_properties_khr)( physical_device, video_format_info, &mut count, out.as_mut_ptr(), - ); - assert_eq!(count as usize, out.len()); + ).result() } } @@ -117,15 +116,14 @@ impl crate::khr::video_queue::Device { &self, video_session: vk::VideoSessionKHR, out: &mut [vk::VideoSessionMemoryRequirementsKHR<'_>], - ) { + ) -> VkResult<()> { let mut count = out.len() as u32; - let _ = (self.fp.get_video_session_memory_requirements_khr)( + self.fp.get_video_session_memory_requirements_khr)( self.handle, video_session, &mut count, out.as_mut_ptr(), - ); - assert_eq!(count as usize, out.len()); + ).result() } /// From 930fd970aff09557a4a7e413775e05a934295c29 Mon Sep 17 00:00:00 2001 From: cach30verfl0w Date: Fri, 10 May 2024 18:13:01 +0200 Subject: [PATCH 11/11] Push latest changes --- ash/src/extensions/khr/video_queue.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ash/src/extensions/khr/video_queue.rs b/ash/src/extensions/khr/video_queue.rs index aedc1c240..93cbd5811 100644 --- a/ash/src/extensions/khr/video_queue.rs +++ b/ash/src/extensions/khr/video_queue.rs @@ -118,7 +118,7 @@ impl crate::khr::video_queue::Device { out: &mut [vk::VideoSessionMemoryRequirementsKHR<'_>], ) -> VkResult<()> { let mut count = out.len() as u32; - self.fp.get_video_session_memory_requirements_khr)( + (self.fp.get_video_session_memory_requirements_khr)( self.handle, video_session, &mut count,