Assert that Vulkan array-getters return the same length (#534)
Originally introduced in [#489] this inserts the array-length equality check everywhere else: in the supposedly invalid and inexistant event where Vulkan suddenly returns less items (`count` has been modified) than were originally queried through respective `_len()` functions (or more likely: a slice of invalid length passed by the user) and some elements at the end of the slice are left uninitialized, panic. Wherever there is valid concern or possibility for this to happen - or to circumvent assertions and panics altogether - mutable references to mutable slices should be passed allowing the length to be promptly updated. [#489]: https://github.com/MaikKlein/ash/pull/489#discussion_r753020089
This commit is contained in:
parent
fdaafe760a
commit
570b554894
|
@ -328,6 +328,7 @@ impl Device {
|
||||||
&mut count,
|
&mut count,
|
||||||
out.as_mut_ptr(),
|
out.as_mut_ptr(),
|
||||||
);
|
);
|
||||||
|
assert_eq!(count as usize, out.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkTrimCommandPool.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkTrimCommandPool.html>"]
|
||||||
|
|
|
@ -70,6 +70,7 @@ impl GetMemoryRequirements2 {
|
||||||
&mut count,
|
&mut count,
|
||||||
out.as_mut_ptr(),
|
out.as_mut_ptr(),
|
||||||
);
|
);
|
||||||
|
assert_eq!(count as usize, out.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name() -> &'static CStr {
|
pub fn name() -> &'static CStr {
|
||||||
|
|
|
@ -107,6 +107,7 @@ impl GetPhysicalDeviceProperties2 {
|
||||||
&mut count,
|
&mut count,
|
||||||
out.as_mut_ptr(),
|
out.as_mut_ptr(),
|
||||||
);
|
);
|
||||||
|
assert_eq!(count as usize, out.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieve the number of elements to pass to [`Self::get_physical_device_sparse_image_format_properties2()`]
|
/// Retrieve the number of elements to pass to [`Self::get_physical_device_sparse_image_format_properties2()`]
|
||||||
|
@ -144,6 +145,7 @@ impl GetPhysicalDeviceProperties2 {
|
||||||
&mut count,
|
&mut count,
|
||||||
out.as_mut_ptr(),
|
out.as_mut_ptr(),
|
||||||
);
|
);
|
||||||
|
assert_eq!(count as usize, out.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name() -> &'static CStr {
|
pub fn name() -> &'static CStr {
|
||||||
|
|
|
@ -66,7 +66,7 @@ impl GetSurfaceCapabilities2 {
|
||||||
&mut count,
|
&mut count,
|
||||||
out.as_mut_ptr(),
|
out.as_mut_ptr(),
|
||||||
);
|
);
|
||||||
assert_eq!(count, out.len() as u32);
|
assert_eq!(count as usize, out.len());
|
||||||
err_code.result()
|
err_code.result()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ impl Maintenance4 {
|
||||||
&mut count,
|
&mut count,
|
||||||
out.as_mut_ptr(),
|
out.as_mut_ptr(),
|
||||||
);
|
);
|
||||||
assert_eq!(count, out.len() as u32);
|
assert_eq!(count as usize, out.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name() -> &'static CStr {
|
pub fn name() -> &'static CStr {
|
||||||
|
|
|
@ -67,10 +67,12 @@ impl Instance {
|
||||||
&self,
|
&self,
|
||||||
out: &mut [vk::PhysicalDeviceGroupProperties],
|
out: &mut [vk::PhysicalDeviceGroupProperties],
|
||||||
) -> VkResult<()> {
|
) -> VkResult<()> {
|
||||||
let mut group_count = out.len() as u32;
|
let mut count = out.len() as u32;
|
||||||
self.instance_fn_1_1
|
self.instance_fn_1_1
|
||||||
.enumerate_physical_device_groups(self.handle(), &mut group_count, out.as_mut_ptr())
|
.enumerate_physical_device_groups(self.handle(), &mut count, out.as_mut_ptr())
|
||||||
.result()
|
.result()?;
|
||||||
|
assert_eq!(count as usize, out.len());
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceFeatures2.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceFeatures2.html>"]
|
||||||
|
@ -144,13 +146,14 @@ impl Instance {
|
||||||
physical_device: vk::PhysicalDevice,
|
physical_device: vk::PhysicalDevice,
|
||||||
out: &mut [vk::QueueFamilyProperties2],
|
out: &mut [vk::QueueFamilyProperties2],
|
||||||
) {
|
) {
|
||||||
let mut queue_count = out.len() as u32;
|
let mut count = out.len() as u32;
|
||||||
self.instance_fn_1_1
|
self.instance_fn_1_1
|
||||||
.get_physical_device_queue_family_properties2(
|
.get_physical_device_queue_family_properties2(
|
||||||
physical_device,
|
physical_device,
|
||||||
&mut queue_count,
|
&mut count,
|
||||||
out.as_mut_ptr(),
|
out.as_mut_ptr(),
|
||||||
);
|
);
|
||||||
|
assert_eq!(count as usize, out.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceMemoryProperties2.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceMemoryProperties2.html>"]
|
||||||
|
@ -190,14 +193,15 @@ impl Instance {
|
||||||
format_info: &vk::PhysicalDeviceSparseImageFormatInfo2,
|
format_info: &vk::PhysicalDeviceSparseImageFormatInfo2,
|
||||||
out: &mut [vk::SparseImageFormatProperties2],
|
out: &mut [vk::SparseImageFormatProperties2],
|
||||||
) {
|
) {
|
||||||
let mut format_count = out.len() as u32;
|
let mut count = out.len() as u32;
|
||||||
self.instance_fn_1_1
|
self.instance_fn_1_1
|
||||||
.get_physical_device_sparse_image_format_properties2(
|
.get_physical_device_sparse_image_format_properties2(
|
||||||
physical_device,
|
physical_device,
|
||||||
format_info,
|
format_info,
|
||||||
&mut format_count,
|
&mut count,
|
||||||
out.as_mut_ptr(),
|
out.as_mut_ptr(),
|
||||||
);
|
);
|
||||||
|
assert_eq!(count as usize, out.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceExternalBufferProperties.html>"]
|
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceExternalBufferProperties.html>"]
|
||||||
|
|
Loading…
Reference in a new issue