pub unsafe fn fill_vk_out_array<T, U>(
out: &[T],
p_count: NonNull<U>,
p_out: *mut T,
) -> ResultExpand description
Clone the slice to a C style out array with proper VkResult return value.
The caller can use this function to handle the output array in Vulkan with slice.
If p_out is NULL, write the length to p_out. If p_out is not NULL, p_count describes
the length of the output array. This function will clone the slice to the output array, and
rewrite the p_count to indicate how many elements are written to the out array. If the length
of the slice is larger than the out array, VK_INCOMPLETE will be returned. For all other
cases, VK_SUCCESS is returned.
§Safety
p_count must be a valid pointer to U. If p_count doesn’t reference 0, and p_out is not
null, p_out must be a valid pointer to *p_count number of T’s.
§Examples
Obtain the length with a NULL p_out.
use ash::vk;
use std::ptr::NonNull;
use vulkan_layer::fill_vk_out_array;
let mut count = 0;
let out_array = &[0, 1, 2, 3];
assert_eq!(
unsafe {
fill_vk_out_array(
out_array,
NonNull::new(&mut count as *mut _).unwrap(),
std::ptr::null_mut(),
)
},
vk::Result::SUCCESS
);
assert_eq!(count as usize, out_array.len());Short output array results in a VK_INCOMPLETE.
use ash::vk;
use std::ptr::NonNull;
use vulkan_layer::fill_vk_out_array;
let mut out_array = [0; 2];
let mut count = out_array.len() as u32;
let out_slice = &[3, 1, 44];
assert_eq!(
unsafe {
fill_vk_out_array(
out_slice,
NonNull::new(&mut count as *mut _).unwrap(),
out_array.as_mut_ptr(),
)
},
vk::Result::INCOMPLETE
);
assert_eq!(count as usize, out_array.len());
assert_eq!(out_array, out_slice[0..out_array.len()]);Longer output array will only be partly overwritten.
use ash::vk;
use std::ptr::NonNull;
use vulkan_layer::fill_vk_out_array;
let mut out_array = [42; 3];
let mut count = out_array.len() as u32;
let out_slice = &[3, 1];
assert_eq!(
unsafe {
fill_vk_out_array(
out_slice,
NonNull::new(&mut count as *mut _).unwrap(),
out_array.as_mut_ptr(),
)
},
vk::Result::SUCCESS
);
assert_eq!(count as usize, out_slice.len());
assert_eq!(out_array, [3, 1, 42]);