Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 307563d

Browse files
committedDec 27, 2021
Assert that Vulkan array-getters return the same length
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]: #489 (comment)
1 parent ab36e84 commit 307563d

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed
 

‎ash/src/device.rs

+1
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ impl Device {
328328
&mut count,
329329
out.as_mut_ptr(),
330330
);
331+
assert_eq!(count, out.len() as u32);
331332
}
332333

333334
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkTrimCommandPool.html>"]

‎ash/src/extensions/khr/get_memory_requirements2.rs

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ impl GetMemoryRequirements2 {
7070
&mut count,
7171
out.as_mut_ptr(),
7272
);
73+
assert_eq!(count, out.len() as u32);
7374
}
7475

7576
pub fn name() -> &'static CStr {

‎ash/src/extensions/khr/get_physical_device_properties2.rs

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ impl GetPhysicalDeviceProperties2 {
107107
&mut count,
108108
out.as_mut_ptr(),
109109
);
110+
assert_eq!(count, out.len() as u32);
110111
}
111112

112113
/// Retrieve the number of elements to pass to [`Self::get_physical_device_sparse_image_format_properties2()`]
@@ -144,6 +145,7 @@ impl GetPhysicalDeviceProperties2 {
144145
&mut count,
145146
out.as_mut_ptr(),
146147
);
148+
assert_eq!(count, out.len() as u32);
147149
}
148150

149151
pub fn name() -> &'static CStr {

‎ash/src/instance.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ impl Instance {
6767
&self,
6868
out: &mut [vk::PhysicalDeviceGroupProperties],
6969
) -> VkResult<()> {
70-
let mut group_count = out.len() as u32;
70+
let mut count = out.len() as u32;
7171
self.instance_fn_1_1
72-
.enumerate_physical_device_groups(self.handle(), &mut group_count, out.as_mut_ptr())
73-
.result()
72+
.enumerate_physical_device_groups(self.handle(), &mut count, out.as_mut_ptr())
73+
.result()?;
74+
assert_eq!(count, out.len() as u32);
75+
Ok(())
7476
}
7577

7678
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceFeatures2.html>"]
@@ -144,13 +146,14 @@ impl Instance {
144146
physical_device: vk::PhysicalDevice,
145147
out: &mut [vk::QueueFamilyProperties2],
146148
) {
147-
let mut queue_count = out.len() as u32;
149+
let mut count = out.len() as u32;
148150
self.instance_fn_1_1
149151
.get_physical_device_queue_family_properties2(
150152
physical_device,
151-
&mut queue_count,
153+
&mut count,
152154
out.as_mut_ptr(),
153155
);
156+
assert_eq!(count, out.len() as u32);
154157
}
155158

156159
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceMemoryProperties2.html>"]
@@ -190,14 +193,15 @@ impl Instance {
190193
format_info: &vk::PhysicalDeviceSparseImageFormatInfo2,
191194
out: &mut [vk::SparseImageFormatProperties2],
192195
) {
193-
let mut format_count = out.len() as u32;
196+
let mut count = out.len() as u32;
194197
self.instance_fn_1_1
195198
.get_physical_device_sparse_image_format_properties2(
196199
physical_device,
197200
format_info,
198-
&mut format_count,
201+
&mut count,
199202
out.as_mut_ptr(),
200203
);
204+
assert_eq!(count, out.len() as u32);
201205
}
202206

203207
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceExternalBufferProperties.html>"]

0 commit comments

Comments
 (0)