From 53161660efb95f80f6fc02ea9240f9dd5172de40 Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Thu, 23 Aug 2018 10:22:06 +0300 Subject: [PATCH 1/2] Fix instance getters to support extensions This commit allows the user to pass in a chain of structures to be filled in by the Vulkan driver. --- ash/src/instance.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/ash/src/instance.rs b/ash/src/instance.rs index 50c459a..8b3e6ff 100644 --- a/ash/src/instance.rs +++ b/ash/src/instance.rs @@ -108,16 +108,13 @@ pub trait InstanceV1_1: InstanceV1_0 { } } - fn get_physical_device_properties2( + unsafe fn get_physical_device_properties2( &self, physical_device: vk::PhysicalDevice, - ) -> vk::PhysicalDeviceProperties2 { - unsafe { - let mut prop = mem::uninitialized(); - self.fp_v1_1() - .get_physical_device_properties2(physical_device, &mut prop); - prop - } + prop: &mut vk::PhysicalDeviceProperties2, + ) { + self.fp_v1_1() + .get_physical_device_properties2(physical_device, prop); } fn get_physical_device_format_properties2( @@ -140,15 +137,15 @@ pub trait InstanceV1_1: InstanceV1_0 { &self, physical_device: vk::PhysicalDevice, format_info: &vk::PhysicalDeviceImageFormatInfo2, - ) -> VkResult { - let mut image_format_prop = mem::uninitialized(); + image_format_prop: &mut vk::ImageFormatProperties2 + ) -> VkResult<()> { let err_code = self.fp_v1_1().get_physical_device_image_format_properties2( physical_device, format_info, - &mut image_format_prop, + image_format_prop, ); if err_code == vk::Result::SUCCESS { - Ok(image_format_prop) + Ok(()) } else { Err(err_code) } From 0c26422215ec59f98ac3166549ca4d8b19ec062f Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Sat, 25 Aug 2018 11:53:15 +0300 Subject: [PATCH 2/2] Separate getters for vectors into two functions One is safe, used to determine how many structures will be returned. The other is unsafe, and takes in a mutable reference to an array of structure chains. --- ash/src/instance.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/ash/src/instance.rs b/ash/src/instance.rs index 8b3e6ff..51a378f 100644 --- a/ash/src/instance.rs +++ b/ash/src/instance.rs @@ -151,10 +151,10 @@ pub trait InstanceV1_1: InstanceV1_0 { } } - fn get_physical_device_queue_family_properties2( + fn get_physical_device_queue_family_properties2_len( &self, physical_device: vk::PhysicalDevice, - ) -> Vec { + ) -> usize { unsafe { let mut queue_count = 0; self.fp_v1_1().get_physical_device_queue_family_properties2( @@ -162,17 +162,23 @@ pub trait InstanceV1_1: InstanceV1_0 { &mut queue_count, ptr::null_mut(), ); - let mut queue_families_vec = Vec::with_capacity(queue_count as usize); - self.fp_v1_1().get_physical_device_queue_family_properties2( - physical_device, - &mut queue_count, - queue_families_vec.as_mut_ptr(), - ); - queue_families_vec.set_len(queue_count as usize); - queue_families_vec + queue_count as usize } } + unsafe fn get_physical_device_queue_family_properties2( + &self, + physical_device: vk::PhysicalDevice, + queue_family_props: &mut [vk::QueueFamilyProperties2] + ) { + let mut queue_count = queue_family_props.len() as u32; + self.fp_v1_1().get_physical_device_queue_family_properties2( + physical_device, + &mut queue_count, + queue_family_props.as_mut_ptr(), + ); + } + fn get_physical_device_memory_properties2( &self, physical_device: vk::PhysicalDevice,