From 335546af80583e3f1c70569c4614b5c37b6124f1 Mon Sep 17 00:00:00 2001 From: Colin Marc Date: Sat, 30 Nov 2024 18:40:13 +0100 Subject: [PATCH] extensions/khr: add VK_KHR_video_encode_queue --- Changelog.md | 1 + ash/src/extensions/khr/mod.rs | 1 + ash/src/extensions/khr/video_decode_queue.rs | 5 +- ash/src/extensions/khr/video_encode_queue.rs | 58 ++++++++ ash/src/extensions/khr/video_queue.rs | 140 +++++++++++++------ 5 files changed, 164 insertions(+), 41 deletions(-) create mode 100644 ash/src/extensions/khr/video_encode_queue.rs diff --git a/Changelog.md b/Changelog.md index e3f4c3e7..443b99c1 100644 --- a/Changelog.md +++ b/Changelog.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Update Vulkan-Headers to 1.3.296 (#910) - Added `VK_KHR_get_display_properties2` instance extension (#932) - Added `VK_EXT_metal_objects` device extension (#942) +- Added `VK_KHR_video_{encode,decode}_queue` extensions (#965) ## [0.38.0] - 2024-04-01 diff --git a/ash/src/extensions/khr/mod.rs b/ash/src/extensions/khr/mod.rs index d222759f..b5313cdb 100644 --- a/ash/src/extensions/khr/mod.rs +++ b/ash/src/extensions/khr/mod.rs @@ -41,6 +41,7 @@ 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; diff --git a/ash/src/extensions/khr/video_decode_queue.rs b/ash/src/extensions/khr/video_decode_queue.rs index 6d66baad..1a5972bf 100644 --- a/ash/src/extensions/khr/video_decode_queue.rs +++ b/ash/src/extensions/khr/video_decode_queue.rs @@ -3,13 +3,14 @@ use crate::vk; impl crate::khr::video_decode_queue::Device { - #[inline] /// + #[doc(alias = "vkCmdDecodeVideoKHR")] + #[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); + (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 00000000..22d73534 --- /dev/null +++ b/ash/src/extensions/khr/video_encode_queue.rs @@ -0,0 +1,58 @@ +//! + +use crate::prelude::*; +use crate::vk; + +impl crate::khr::video_encode_queue::Device { + /// + #[doc(alias = "vkCmdEncodeVideoKHR")] + #[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) + } + + /// + #[doc(alias = "vkGetEncodedVideoSessionParametersKHR")] + #[inline] + pub unsafe fn get_encoded_video_session_parameters( + &self, + session_parameters_info: &vk::VideoEncodeSessionParametersGetInfoKHR<'_>, + info: &mut vk::VideoEncodeSessionParametersFeedbackInfoKHR<'_>, + ) -> VkResult> { + let ptr: *mut _ = info; + read_into_uninitialized_vector(|count, data: *mut u8| { + (self.fp.get_encoded_video_session_parameters_khr)( + self.handle, + session_parameters_info, + ptr, + count, + data.cast(), + ) + }) + } +} + +impl crate::khr::video_encode_queue::Instance { + /// + #[doc(alias = "vkGetPhysicalDeviceVideoEncodeQualityLevelPropertiesKHR")] + #[inline] + pub unsafe fn get_physical_device_video_encode_quality_level_properties( + &self, + physical_device: vk::PhysicalDevice, + quality_level_info: &vk::PhysicalDeviceVideoEncodeQualityLevelInfoKHR<'_>, + quality_level_properties: &mut vk::VideoEncodeQualityLevelPropertiesKHR<'_>, + ) -> VkResult<()> { + (self + .fp + .get_physical_device_video_encode_quality_level_properties_khr)( + physical_device, + quality_level_info, + quality_level_properties, + ) + .result() + } +} diff --git a/ash/src/extensions/khr/video_queue.rs b/ash/src/extensions/khr/video_queue.rs index a3be16c6..00518eff 100644 --- a/ash/src/extensions/khr/video_queue.rs +++ b/ash/src/extensions/khr/video_queue.rs @@ -4,10 +4,12 @@ use crate::prelude::*; use crate::vk; use crate::RawPtr as _; use core::mem; +use core::ptr; impl crate::khr::video_queue::Device { - #[inline] /// + #[doc(alias = "vkBindVideoSessionMemoryKHR")] + #[inline] pub unsafe fn bind_video_session_memory( &self, video_session: vk::VideoSessionKHR, @@ -22,72 +24,78 @@ impl crate::khr::video_queue::Device { .result() } - #[inline] /// + #[doc(alias = "vkCmdBeginVideoCodingKHR")] + #[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); + (self.fp.cmd_begin_video_coding_khr)(command_buffer, begin_info) } - #[inline] /// + #[doc(alias = "vkCmdControlVideoCodingKHR")] + #[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); + (self.fp.cmd_control_video_coding_khr)(command_buffer, coding_control_info) } - #[inline] /// + #[doc(alias = "vkCmdEndVideoCodingKHR")] + #[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); + (self.fp.cmd_end_video_coding_khr)(command_buffer, end_coding_info) } - #[inline] /// + #[doc(alias = "vkCreateVideoSessionKHR")] + #[inline] pub unsafe fn create_video_session( &self, create_info: &vk::VideoSessionCreateInfoKHR<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut video_session = mem::zeroed(); + let mut video_session = mem::MaybeUninit::uninit(); (self.fp.create_video_session_khr)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut video_session, + video_session.as_mut_ptr(), ) - .result_with_success(video_session) + .assume_init_on_success(video_session) } - #[inline] /// + #[doc(alias = "vkCreateVideoSessionParametersKHR")] + #[inline] pub unsafe fn create_video_session_parameters( &self, create_info: &vk::VideoSessionParametersCreateInfoKHR<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut video_session_parameters = mem::zeroed(); + let mut video_session_parameters = mem::MaybeUninit::uninit(); (self.fp.create_video_session_parameters_khr)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut video_session_parameters, + video_session_parameters.as_mut_ptr(), ) - .result_with_success(video_session_parameters) + .assume_init_on_success(video_session_parameters) } - #[inline] /// + #[doc(alias = "vkDestroyVideoSessionKHR")] + #[inline] pub unsafe fn destroy_video_session( &self, video_session: vk::VideoSessionKHR, @@ -97,11 +105,12 @@ impl crate::khr::video_queue::Device { self.handle, video_session, allocation_callbacks.as_raw_ptr(), - ); + ) } - #[inline] /// + #[doc(alias = "vkDestroyVideoSessionParametersKHR")] + #[inline] pub unsafe fn destroy_video_session_parameters( &self, video_session_parameters: vk::VideoSessionParametersKHR, @@ -111,27 +120,53 @@ impl crate::khr::video_queue::Device { self.handle, video_session_parameters, allocation_callbacks.as_raw_ptr(), - ); + ) } + /// 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, + ) -> VkResult { + let mut req_count = mem::MaybeUninit::uninit(); + (self.fp.get_video_session_memory_requirements_khr)( + self.handle, + video_session, + req_count.as_mut_ptr(), + ptr::null_mut(), + ) + .assume_init_on_success(req_count) + .map(|c| c as usize) + } + /// + /// + /// 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. + #[doc(alias = "vkGetVideoSessionMemoryRequirementsKHR")] + #[inline] pub unsafe fn get_video_session_memory_requirements( &self, video_session: vk::VideoSessionKHR, - ) -> VkResult>> { - read_into_defaulted_vector(|count, data| { - (self.fp.get_video_session_memory_requirements_khr)( - self.handle, - video_session, - count, - data, - ) - }) + out: &mut [vk::VideoSessionMemoryRequirementsKHR<'_>], + ) -> VkResult<()> { + let mut req_count = out.len() as u32; + (self.fp.get_video_session_memory_requirements_khr)( + self.handle, + video_session, + &mut req_count, + out.as_mut_ptr(), + ) + .result()?; + + assert_eq!(req_count as usize, out.len()); + Ok(()) } - #[inline] /// + #[doc(alias = "vkUpdateVideoSessionParametersKHR")] + #[inline] pub unsafe fn update_video_session_parameters( &self, video_session_parameters: vk::VideoSessionParametersKHR, @@ -147,8 +182,9 @@ impl crate::khr::video_queue::Device { } impl crate::khr::video_queue::Instance { - #[inline] /// + #[doc(alias = "vkGetPhysicalDeviceVideoCapabilitiesKHR")] + #[inline] pub unsafe fn get_physical_device_video_capabilities( &self, physical_device: vk::PhysicalDevice, @@ -163,20 +199,46 @@ impl crate::khr::video_queue::Instance { .result() } + /// 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, + video_format_info: &vk::PhysicalDeviceVideoFormatInfoKHR<'_>, + ) -> VkResult { + let mut format_count = mem::MaybeUninit::uninit(); + (self.fp.get_physical_device_video_format_properties_khr)( + physical_device, + video_format_info, + format_count.as_mut_ptr(), + ptr::null_mut(), + ) + .assume_init_on_success(format_count) + .map(|c| c as usize) + } + /// + /// + /// 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. + #[doc(alias = "vkGetPhysicalDeviceVideoFormatPropertiesKHR")] + #[inline] pub unsafe fn get_physical_device_video_format_properties( &self, physical_device: vk::PhysicalDevice, video_format_info: &vk::PhysicalDeviceVideoFormatInfoKHR<'_>, - ) -> VkResult>> { - read_into_defaulted_vector(|count, data| { - (self.fp.get_physical_device_video_format_properties_khr)( - physical_device, - video_format_info, - count, - data, - ) - }) + out: &mut [vk::VideoFormatPropertiesKHR<'_>], + ) -> VkResult<()> { + let mut format_count = out.len() as u32; + (self.fp.get_physical_device_video_format_properties_khr)( + physical_device, + video_format_info, + &mut format_count, + out.as_mut_ptr(), + ) + .result()?; + + assert_eq!(format_count as usize, out.len()); + Ok(()) } }