Skip to content

Commit

Permalink
extensions/khr: add VK_KHR_video_encode_queue
Browse files Browse the repository at this point in the history
  • Loading branch information
colinmarc committed Dec 2, 2024
1 parent 82e45e7 commit 4f4dff2
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 40 deletions.
1 change: 1 addition & 0 deletions ash/src/extensions/khr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion ash/src/extensions/khr/video_decode_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
use crate::vk;

impl crate::khr::video_decode_queue::Device {
#[inline]
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdDecodeVideoKHR.html>
#[doc(alias = "vkCmdDecodeVideoKHR")]
#[inline]
pub unsafe fn cmd_decode_video(
&self,
command_buffer: vk::CommandBuffer,
Expand Down
58 changes: 58 additions & 0 deletions ash/src/extensions/khr/video_encode_queue.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//! <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_video_encode_queue.html>
use crate::prelude::*;
use crate::vk;

impl crate::khr::video_encode_queue::Device {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdEncodeVideoKHR.html>
#[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);
}

/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetEncodedVideoSessionParametersKHR.html>
#[doc(alias = "vkGetEncodedVideoSessionParametersKHR")]
#[inline]
pub unsafe fn get_encoded_video_session_parameters(
&self,
session_parameters_info: &vk::VideoEncodeSessionParametersGetInfoKHR<'_>,
info: &mut vk::VideoEncodeSessionParametersFeedbackInfoKHR<'_>,
) -> VkResult<Vec<u8>> {
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 {
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceVideoEncodeQualityLevelPropertiesKHR.html>
#[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()
}
}
140 changes: 101 additions & 39 deletions ash/src/extensions/khr/video_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkBindVideoSessionMemoryKHR.html>
#[doc(alias = "vkBindVideoSessionMemoryKHR")]
#[inline]
pub unsafe fn bind_video_session_memory(
&self,
video_session: vk::VideoSessionKHR,
Expand All @@ -22,72 +24,78 @@ impl crate::khr::video_queue::Device {
.result()
}

#[inline]
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdBeginVideoCodingKHR.html>
#[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]
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdControlVideoCodingKHR.html>
#[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]
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdEndVideoCodingKHR.html>
#[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]
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCreateVideoSessionKHR.html>
#[doc(alias = "vkCreateVideoSessionKHR")]
#[inline]
pub unsafe fn create_video_session(
&self,
create_info: &vk::VideoSessionCreateInfoKHR<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::VideoSessionKHR> {
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]
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCreateVideoSessionParametersKHR.html>
#[doc(alias = "vkCreateVideoSessionParametersKHR")]
#[inline]
pub unsafe fn create_video_session_parameters(
&self,
create_info: &vk::VideoSessionParametersCreateInfoKHR<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::VideoSessionParametersKHR> {
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]
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkDestroyVideoSessionKHR.html>
#[doc(alias = "vkDestroyVideoSessionKHR")]
#[inline]
pub unsafe fn destroy_video_session(
&self,
video_session: vk::VideoSessionKHR,
Expand All @@ -97,11 +105,12 @@ impl crate::khr::video_queue::Device {
self.handle,
video_session,
allocation_callbacks.as_raw_ptr(),
);
)
}

#[inline]
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkDestroyVideoSessionParametersKHR.html>
#[doc(alias = "vkDestroyVideoSessionParametersKHR")]
#[inline]
pub unsafe fn destroy_video_session_parameters(
&self,
video_session_parameters: vk::VideoSessionParametersKHR,
Expand All @@ -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<usize> {
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)
}

/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetVideoSessionMemoryRequirementsKHR.html>
///
/// 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<Vec<vk::VideoSessionMemoryRequirementsKHR<'_>>> {
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]
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkUpdateVideoSessionParametersKHR.html>
#[doc(alias = "vkUpdateVideoSessionParametersKHR")]
#[inline]
pub unsafe fn update_video_session_parameters(
&self,
video_session_parameters: vk::VideoSessionParametersKHR,
Expand All @@ -147,8 +182,9 @@ impl crate::khr::video_queue::Device {
}

impl crate::khr::video_queue::Instance {
#[inline]
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceVideoCapabilitiesKHR.html>
#[doc(alias = "vkGetPhysicalDeviceVideoCapabilitiesKHR")]
#[inline]
pub unsafe fn get_physical_device_video_capabilities(
&self,
physical_device: vk::PhysicalDevice,
Expand All @@ -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<usize> {
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)
}

/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceVideoFormatPropertiesKHR.html>
///
/// 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<Vec<vk::VideoFormatPropertiesKHR<'_>>> {
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(())
}
}

0 comments on commit 4f4dff2

Please sign in to comment.