diff --git a/ash-examples/src/bin/texture.rs b/ash-examples/src/bin/texture.rs index 298446c..b512a22 100644 --- a/ash-examples/src/bin/texture.rs +++ b/ash-examples/src/bin/texture.rs @@ -768,7 +768,6 @@ fn main() { device.cmd_end_render_pass(draw_command_buffer); }, ); - //let mut present_info_err = mem::zeroed(); let present_info = vk::PresentInfoKHR { wait_semaphore_count: 1, p_wait_semaphores: &base.rendering_complete_semaphore, diff --git a/ash-examples/src/bin/triangle.rs b/ash-examples/src/bin/triangle.rs index 621b57b..ee0bcc5 100644 --- a/ash-examples/src/bin/triangle.rs +++ b/ash-examples/src/bin/triangle.rs @@ -423,7 +423,6 @@ fn main() { device.cmd_end_render_pass(draw_command_buffer); }, ); - //let mut present_info_err = mem::zeroed(); let wait_semaphors = [base.rendering_complete_semaphore]; let swapchains = [base.swapchain]; let image_indices = [present_index]; diff --git a/ash/src/device.rs b/ash/src/device.rs index d64a760..6775b38 100644 --- a/ash/src/device.rs +++ b/ash/src/device.rs @@ -70,14 +70,14 @@ impl Device { create_info: &vk::PrivateDataSlotCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut private_data_slot = mem::zeroed(); + let mut private_data_slot = mem::MaybeUninit::uninit(); (self.device_fn_1_3.create_private_data_slot)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut private_data_slot, + private_data_slot.as_mut_ptr(), ) - .result_with_success(private_data_slot) + .assume_init_on_success(private_data_slot) } /// @@ -119,15 +119,15 @@ impl Device { object: T, private_data_slot: vk::PrivateDataSlot, ) -> u64 { - let mut data = mem::zeroed(); + let mut data = mem::MaybeUninit::uninit(); (self.device_fn_1_3.get_private_data)( self.handle, T::TYPE, object.as_raw(), private_data_slot, - &mut data, + data.as_mut_ptr(), ); - data + data.assume_init() } /// @@ -511,16 +511,16 @@ impl Device { &self, memory_requirements: &vk::DeviceImageMemoryRequirements<'_>, ) -> usize { - let mut count = 0; + let mut count = mem::MaybeUninit::uninit(); (self .device_fn_1_3 .get_device_image_sparse_memory_requirements)( self.handle, memory_requirements, - &mut count, + count.as_mut_ptr(), ptr::null_mut(), ); - count as usize + count.assume_init() as usize } /// @@ -606,14 +606,14 @@ impl Device { create_info: &vk::RenderPassCreateInfo2<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut renderpass = mem::zeroed(); + let mut renderpass = mem::MaybeUninit::uninit(); (self.device_fn_1_2.create_render_pass2)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut renderpass, + renderpass.as_mut_ptr(), ) - .result_with_success(renderpass) + .assume_init_on_success(renderpass) } /// @@ -670,9 +670,13 @@ impl Device { /// #[inline] pub unsafe fn get_semaphore_counter_value(&self, semaphore: vk::Semaphore) -> VkResult { - let mut value = 0; - (self.device_fn_1_2.get_semaphore_counter_value)(self.handle(), semaphore, &mut value) - .result_with_success(value) + let mut value = mem::MaybeUninit::uninit(); + (self.device_fn_1_2.get_semaphore_counter_value)( + self.handle(), + semaphore, + value.as_mut_ptr(), + ) + .assume_init_on_success(value) } /// @@ -765,15 +769,15 @@ impl Device { local_device_index: u32, remote_device_index: u32, ) -> vk::PeerMemoryFeatureFlags { - let mut peer_memory_features = mem::zeroed(); + let mut peer_memory_features = mem::MaybeUninit::uninit(); (self.device_fn_1_1.get_device_group_peer_memory_features)( self.handle(), heap_index, local_device_index, remote_device_index, - &mut peer_memory_features, + peer_memory_features.as_mut_ptr(), ); - peer_memory_features + peer_memory_features.assume_init() } /// @@ -831,14 +835,14 @@ impl Device { &self, info: &vk::ImageSparseMemoryRequirementsInfo2<'_>, ) -> usize { - let mut count = 0; + let mut count = mem::MaybeUninit::uninit(); (self.device_fn_1_1.get_image_sparse_memory_requirements2)( self.handle(), info, - &mut count, + count.as_mut_ptr(), ptr::null_mut(), ); - count as usize + count.assume_init() as usize } /// @@ -874,9 +878,9 @@ impl Device { /// #[inline] pub unsafe fn get_device_queue2(&self, queue_info: &vk::DeviceQueueInfo2<'_>) -> vk::Queue { - let mut queue = mem::zeroed(); - (self.device_fn_1_1.get_device_queue2)(self.handle(), queue_info, &mut queue); - queue + let mut queue = mem::MaybeUninit::uninit(); + (self.device_fn_1_1.get_device_queue2)(self.handle(), queue_info, queue.as_mut_ptr()); + queue.assume_init() } /// @@ -886,14 +890,14 @@ impl Device { create_info: &vk::SamplerYcbcrConversionCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut ycbcr_conversion = mem::zeroed(); + let mut ycbcr_conversion = mem::MaybeUninit::uninit(); (self.device_fn_1_1.create_sampler_ycbcr_conversion)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut ycbcr_conversion, + ycbcr_conversion.as_mut_ptr(), ) - .result_with_success(ycbcr_conversion) + .assume_init_on_success(ycbcr_conversion) } /// @@ -917,14 +921,14 @@ impl Device { create_info: &vk::DescriptorUpdateTemplateCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut descriptor_update_template = mem::zeroed(); + let mut descriptor_update_template = mem::MaybeUninit::uninit(); (self.device_fn_1_1.create_descriptor_update_template)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut descriptor_update_template, + descriptor_update_template.as_mut_ptr(), ) - .result_with_success(descriptor_update_template) + .assume_init_on_success(descriptor_update_template) } /// @@ -1030,14 +1034,14 @@ impl Device { create_info: &vk::EventCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut event = mem::zeroed(); + let mut event = mem::MaybeUninit::uninit(); (self.device_fn_1_0.create_event)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut event, + event.as_mut_ptr(), ) - .result_with_success(event) + .assume_init_on_success(event) } /// Returns [`true`] if the event was set, and [`false`] if the event was reset, otherwise it will @@ -1363,14 +1367,14 @@ impl Device { create_info: &vk::SamplerCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut sampler = mem::zeroed(); + let mut sampler = mem::MaybeUninit::uninit(); (self.device_fn_1_0.create_sampler)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut sampler, + sampler.as_mut_ptr(), ) - .result_with_success(sampler) + .assume_init_on_success(sampler) } /// @@ -1542,10 +1546,7 @@ impl Device { allocate_info, desc_set.as_mut_ptr(), ) - .result()?; - - desc_set.set_len(allocate_info.descriptor_set_count as usize); - Ok(desc_set) + .set_vec_len_on_success(desc_set, allocate_info.descriptor_set_count as usize) } /// @@ -1555,14 +1556,14 @@ impl Device { create_info: &vk::DescriptorSetLayoutCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut layout = mem::zeroed(); + let mut layout = mem::MaybeUninit::uninit(); (self.device_fn_1_0.create_descriptor_set_layout)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut layout, + layout.as_mut_ptr(), ) - .result_with_success(layout) + .assume_init_on_success(layout) } /// @@ -1578,14 +1579,14 @@ impl Device { create_info: &vk::DescriptorPoolCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut pool = mem::zeroed(); + let mut pool = mem::MaybeUninit::uninit(); (self.device_fn_1_0.create_descriptor_pool)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut pool, + pool.as_mut_ptr(), ) - .result_with_success(pool) + .assume_init_on_success(pool) } /// @@ -2123,14 +2124,14 @@ impl Device { create_info: &vk::SemaphoreCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut semaphore = mem::zeroed(); + let mut semaphore = mem::MaybeUninit::uninit(); (self.device_fn_1_0.create_semaphore)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut semaphore, + semaphore.as_mut_ptr(), ) - .result_with_success(semaphore) + .assume_init_on_success(semaphore) } /// @@ -2188,14 +2189,14 @@ impl Device { create_info: &vk::BufferCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut buffer = mem::zeroed(); + let mut buffer = mem::MaybeUninit::uninit(); (self.device_fn_1_0.create_buffer)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut buffer, + buffer.as_mut_ptr(), ) - .result_with_success(buffer) + .assume_init_on_success(buffer) } /// @@ -2205,14 +2206,14 @@ impl Device { create_info: &vk::PipelineLayoutCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut pipeline_layout = mem::zeroed(); + let mut pipeline_layout = mem::MaybeUninit::uninit(); (self.device_fn_1_0.create_pipeline_layout)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut pipeline_layout, + pipeline_layout.as_mut_ptr(), ) - .result_with_success(pipeline_layout) + .assume_init_on_success(pipeline_layout) } /// @@ -2222,14 +2223,14 @@ impl Device { create_info: &vk::PipelineCacheCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut pipeline_cache = mem::zeroed(); + let mut pipeline_cache = mem::MaybeUninit::uninit(); (self.device_fn_1_0.create_pipeline_cache)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut pipeline_cache, + pipeline_cache.as_mut_ptr(), ) - .result_with_success(pipeline_cache) + .assume_init_on_success(pipeline_cache) } /// @@ -2273,9 +2274,16 @@ impl Device { size: vk::DeviceSize, flags: vk::MemoryMapFlags, ) -> VkResult<*mut c_void> { - let mut data: *mut c_void = ptr::null_mut(); - (self.device_fn_1_0.map_memory)(self.handle(), memory, offset, size, flags, &mut data) - .result_with_success(data) + let mut data = mem::MaybeUninit::uninit(); + (self.device_fn_1_0.map_memory)( + self.handle(), + memory, + offset, + size, + flags, + data.as_mut_ptr(), + ) + .assume_init_on_success(data) } /// @@ -2319,27 +2327,27 @@ impl Device { create_info: &vk::FramebufferCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut framebuffer = mem::zeroed(); + let mut framebuffer = mem::MaybeUninit::uninit(); (self.device_fn_1_0.create_framebuffer)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut framebuffer, + framebuffer.as_mut_ptr(), ) - .result_with_success(framebuffer) + .assume_init_on_success(framebuffer) } /// #[inline] pub unsafe fn get_device_queue(&self, queue_family_index: u32, queue_index: u32) -> vk::Queue { - let mut queue = mem::zeroed(); + let mut queue = mem::MaybeUninit::uninit(); (self.device_fn_1_0.get_device_queue)( self.handle(), queue_family_index, queue_index, - &mut queue, + queue.as_mut_ptr(), ); - queue + queue.assume_init() } /// @@ -2375,14 +2383,14 @@ impl Device { create_info: &vk::RenderPassCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut renderpass = mem::zeroed(); + let mut renderpass = mem::MaybeUninit::uninit(); (self.device_fn_1_0.create_render_pass)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut renderpass, + renderpass.as_mut_ptr(), ) - .result_with_success(renderpass) + .assume_init_on_success(renderpass) } /// @@ -2472,14 +2480,14 @@ impl Device { create_info: &vk::BufferViewCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut buffer_view = mem::zeroed(); + let mut buffer_view = mem::MaybeUninit::uninit(); (self.device_fn_1_0.create_buffer_view)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut buffer_view, + buffer_view.as_mut_ptr(), ) - .result_with_success(buffer_view) + .assume_init_on_success(buffer_view) } /// @@ -2503,14 +2511,14 @@ impl Device { create_info: &vk::ImageViewCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut image_view = mem::zeroed(); + let mut image_view = mem::MaybeUninit::uninit(); (self.device_fn_1_0.create_image_view)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut image_view, + image_view.as_mut_ptr(), ) - .result_with_success(image_view) + .assume_init_on_success(image_view) } /// @@ -2525,9 +2533,7 @@ impl Device { allocate_info, buffers.as_mut_ptr(), ) - .result()?; - buffers.set_len(allocate_info.command_buffer_count as usize); - Ok(buffers) + .set_vec_len_on_success(buffers, allocate_info.command_buffer_count as usize) } /// @@ -2537,14 +2543,14 @@ impl Device { create_info: &vk::CommandPoolCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut pool = mem::zeroed(); + let mut pool = mem::MaybeUninit::uninit(); (self.device_fn_1_0.create_command_pool)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut pool, + pool.as_mut_ptr(), ) - .result_with_success(pool) + .assume_init_on_success(pool) } /// @@ -2554,14 +2560,14 @@ impl Device { create_info: &vk::QueryPoolCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut pool = mem::zeroed(); + let mut pool = mem::MaybeUninit::uninit(); (self.device_fn_1_0.create_query_pool)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut pool, + pool.as_mut_ptr(), ) - .result_with_success(pool) + .assume_init_on_success(pool) } /// @@ -2571,14 +2577,14 @@ impl Device { create_info: &vk::ImageCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut image = mem::zeroed(); + let mut image = mem::MaybeUninit::uninit(); (self.device_fn_1_0.create_image)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut image, + image.as_mut_ptr(), ) - .result_with_success(image) + .assume_init_on_success(image) } /// @@ -2588,22 +2594,26 @@ impl Device { image: vk::Image, subresource: vk::ImageSubresource, ) -> vk::SubresourceLayout { - let mut layout = mem::zeroed(); + let mut layout = mem::MaybeUninit::uninit(); (self.device_fn_1_0.get_image_subresource_layout)( self.handle(), image, &subresource, - &mut layout, + layout.as_mut_ptr(), ); - layout + layout.assume_init() } /// #[inline] pub unsafe fn get_image_memory_requirements(&self, image: vk::Image) -> vk::MemoryRequirements { - let mut mem_req = mem::zeroed(); - (self.device_fn_1_0.get_image_memory_requirements)(self.handle(), image, &mut mem_req); - mem_req + let mut mem_req = mem::MaybeUninit::uninit(); + (self.device_fn_1_0.get_image_memory_requirements)( + self.handle(), + image, + mem_req.as_mut_ptr(), + ); + mem_req.assume_init() } /// @@ -2612,9 +2622,13 @@ impl Device { &self, buffer: vk::Buffer, ) -> vk::MemoryRequirements { - let mut mem_req = mem::zeroed(); - (self.device_fn_1_0.get_buffer_memory_requirements)(self.handle(), buffer, &mut mem_req); - mem_req + let mut mem_req = mem::MaybeUninit::uninit(); + (self.device_fn_1_0.get_buffer_memory_requirements)( + self.handle(), + buffer, + mem_req.as_mut_ptr(), + ); + mem_req.assume_init() } /// @@ -2624,14 +2638,14 @@ impl Device { allocate_info: &vk::MemoryAllocateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut memory = mem::zeroed(); + let mut memory = mem::MaybeUninit::uninit(); (self.device_fn_1_0.allocate_memory)( self.handle(), allocate_info, allocation_callbacks.as_raw_ptr(), - &mut memory, + memory.as_mut_ptr(), ) - .result_with_success(memory) + .assume_init_on_success(memory) } /// @@ -2641,14 +2655,14 @@ impl Device { create_info: &vk::ShaderModuleCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut shader = mem::zeroed(); + let mut shader = mem::MaybeUninit::uninit(); (self.device_fn_1_0.create_shader_module)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut shader, + shader.as_mut_ptr(), ) - .result_with_success(shader) + .assume_init_on_success(shader) } /// @@ -2658,14 +2672,14 @@ impl Device { create_info: &vk::FenceCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut fence = mem::zeroed(); + let mut fence = mem::MaybeUninit::uninit(); (self.device_fn_1_0.create_fence)( self.handle(), create_info, allocation_callbacks.as_raw_ptr(), - &mut fence, + fence.as_mut_ptr(), ) - .result_with_success(fence) + .assume_init_on_success(fence) } /// @@ -2694,25 +2708,25 @@ impl Device { /// #[inline] pub unsafe fn get_render_area_granularity(&self, render_pass: vk::RenderPass) -> vk::Extent2D { - let mut granularity = mem::zeroed(); + let mut granularity = mem::MaybeUninit::uninit(); (self.device_fn_1_0.get_render_area_granularity)( self.handle(), render_pass, - &mut granularity, + granularity.as_mut_ptr(), ); - granularity + granularity.assume_init() } /// #[inline] pub unsafe fn get_device_memory_commitment(&self, memory: vk::DeviceMemory) -> vk::DeviceSize { - let mut committed_memory_in_bytes = 0; + let mut committed_memory_in_bytes = mem::MaybeUninit::uninit(); (self.device_fn_1_0.get_device_memory_commitment)( self.handle(), memory, - &mut committed_memory_in_bytes, + committed_memory_in_bytes.as_mut_ptr(), ); - committed_memory_in_bytes + committed_memory_in_bytes.assume_init() } /// diff --git a/ash/src/entry.rs b/ash/src/entry.rs index 0562061..a87cafc 100644 --- a/ash/src/entry.rs +++ b/ash/src/entry.rs @@ -219,7 +219,6 @@ impl Entry { /// ``` #[inline] pub unsafe fn try_enumerate_instance_version(&self) -> VkResult> { - let mut api_version = 0; let enumerate_instance_version: Option = { let name = CStr::from_bytes_with_nul_unchecked(b"vkEnumerateInstanceVersion\0"); mem::transmute((self.static_fn.get_instance_proc_addr)( @@ -228,7 +227,10 @@ impl Entry { )) }; if let Some(enumerate_instance_version) = enumerate_instance_version { - (enumerate_instance_version)(&mut api_version).result_with_success(Some(api_version)) + let mut api_version = mem::MaybeUninit::uninit(); + (enumerate_instance_version)(api_version.as_mut_ptr()) + .assume_init_on_success(api_version) + .map(Some) } else { Ok(None) } @@ -251,13 +253,13 @@ impl Entry { create_info: &vk::InstanceCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut instance = mem::zeroed(); - (self.entry_fn_1_0.create_instance)( + let mut instance = mem::MaybeUninit::uninit(); + let instance = (self.entry_fn_1_0.create_instance)( create_info, allocation_callbacks.as_raw_ptr(), - &mut instance, + instance.as_mut_ptr(), ) - .result()?; + .assume_init_on_success(instance)?; Ok(Instance::load(&self.static_fn, instance)) } @@ -308,9 +310,9 @@ impl Entry { /// Please use [`try_enumerate_instance_version()`][Self::try_enumerate_instance_version()] instead. #[inline] pub unsafe fn enumerate_instance_version(&self) -> VkResult { - let mut api_version = 0; - (self.entry_fn_1_1.enumerate_instance_version)(&mut api_version) - .result_with_success(api_version) + let mut api_version = mem::MaybeUninit::uninit(); + (self.entry_fn_1_1.enumerate_instance_version)(api_version.as_mut_ptr()) + .assume_init_on_success(api_version) } } diff --git a/ash/src/extensions/amdx/shader_enqueue.rs b/ash/src/extensions/amdx/shader_enqueue.rs index 054aac1..d034a11 100644 --- a/ash/src/extensions/amdx/shader_enqueue.rs +++ b/ash/src/extensions/amdx/shader_enqueue.rs @@ -29,7 +29,7 @@ impl ShaderEnqueue { create_infos: &[vk::ExecutionGraphPipelineCreateInfoAMDX<'_>], allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult> { - let mut pipelines = vec![mem::zeroed(); create_infos.len()]; + let mut pipelines = Vec::with_capacity(create_infos.len()); (self.fp.create_execution_graph_pipelines_amdx)( self.handle, pipeline_cache, @@ -38,7 +38,7 @@ impl ShaderEnqueue { allocation_callbacks.as_raw_ptr(), pipelines.as_mut_ptr(), ) - .result_with_success(pipelines) + .set_vec_len_on_success(pipelines, create_infos.len()) } /// @@ -63,14 +63,14 @@ impl ShaderEnqueue { execution_graph: vk::Pipeline, node_info: &vk::PipelineShaderStageNodeCreateInfoAMDX<'_>, ) -> VkResult { - let mut node_index = 0; + let mut node_index = mem::MaybeUninit::uninit(); (self.fp.get_execution_graph_pipeline_node_index_amdx)( self.handle, execution_graph, node_info, - &mut node_index, + node_index.as_mut_ptr(), ) - .result_with_success(node_index) + .assume_init_on_success(node_index) } /// diff --git a/ash/src/extensions/android/external_memory_android_hardware_buffer.rs b/ash/src/extensions/android/external_memory_android_hardware_buffer.rs index be18bec..fec7ec6 100644 --- a/ash/src/extensions/android/external_memory_android_hardware_buffer.rs +++ b/ash/src/extensions/android/external_memory_android_hardware_buffer.rs @@ -37,9 +37,9 @@ impl ExternalMemoryAndroidHardwareBuffer { &self, info: &vk::MemoryGetAndroidHardwareBufferInfoANDROID<'_>, ) -> VkResult<*mut vk::AHardwareBuffer> { - let mut buffer = std::ptr::null_mut(); - (self.fp.get_memory_android_hardware_buffer_android)(self.handle, info, &mut buffer) - .result_with_success(buffer) + let mut buffer = mem::MaybeUninit::uninit(); + (self.fp.get_memory_android_hardware_buffer_android)(self.handle, info, buffer.as_mut_ptr()) + .assume_init_on_success(buffer) } pub const NAME: &'static CStr = vk::AndroidExternalMemoryAndroidHardwareBufferFn::NAME; diff --git a/ash/src/extensions/ext/calibrated_timestamps.rs b/ash/src/extensions/ext/calibrated_timestamps.rs index d2d527f..b5880c1 100644 --- a/ash/src/extensions/ext/calibrated_timestamps.rs +++ b/ash/src/extensions/ext/calibrated_timestamps.rs @@ -43,16 +43,18 @@ impl CalibratedTimestamps { device: vk::Device, info: &[vk::CalibratedTimestampInfoEXT<'_>], ) -> VkResult<(Vec, u64)> { - let mut timestamps = vec![0u64; info.len()]; - let mut max_deviation = 0u64; - (self.fp.get_calibrated_timestamps_ext)( + let mut timestamps = Vec::with_capacity(info.len()); + let mut max_deviation = mem::MaybeUninit::uninit(); + let max_deviation = (self.fp.get_calibrated_timestamps_ext)( device, info.len() as u32, info.as_ptr(), timestamps.as_mut_ptr(), - &mut max_deviation, + max_deviation.as_mut_ptr(), ) - .result_with_success((timestamps, max_deviation)) + .assume_init_on_success(max_deviation)?; + timestamps.set_len(info.len()); + Ok((timestamps, max_deviation)) } pub const NAME: &'static CStr = vk::ExtCalibratedTimestampsFn::NAME; diff --git a/ash/src/extensions/ext/debug_report.rs b/ash/src/extensions/ext/debug_report.rs index 0443894..6951002 100755 --- a/ash/src/extensions/ext/debug_report.rs +++ b/ash/src/extensions/ext/debug_report.rs @@ -41,14 +41,14 @@ impl DebugReport { create_info: &vk::DebugReportCallbackCreateInfoEXT<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut debug_cb = mem::zeroed(); + let mut debug_cb = mem::MaybeUninit::uninit(); (self.fp.create_debug_report_callback_ext)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut debug_cb, + debug_cb.as_mut_ptr(), ) - .result_with_success(debug_cb) + .assume_init_on_success(debug_cb) } pub const NAME: &'static CStr = vk::ExtDebugReportFn::NAME; diff --git a/ash/src/extensions/ext/debug_utils.rs b/ash/src/extensions/ext/debug_utils.rs index 5ba5dd2..7dad5c2 100755 --- a/ash/src/extensions/ext/debug_utils.rs +++ b/ash/src/extensions/ext/debug_utils.rs @@ -98,14 +98,14 @@ impl DebugUtils { create_info: &vk::DebugUtilsMessengerCreateInfoEXT<'_>, allocator: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut messenger = mem::zeroed(); + let mut messenger = mem::MaybeUninit::uninit(); (self.fp.create_debug_utils_messenger_ext)( self.handle, create_info, allocator.as_raw_ptr(), - &mut messenger, + messenger.as_mut_ptr(), ) - .result_with_success(messenger) + .assume_init_on_success(messenger) } /// diff --git a/ash/src/extensions/ext/descriptor_buffer.rs b/ash/src/extensions/ext/descriptor_buffer.rs index 341537d..d7cf6d0 100644 --- a/ash/src/extensions/ext/descriptor_buffer.rs +++ b/ash/src/extensions/ext/descriptor_buffer.rs @@ -26,9 +26,9 @@ impl DescriptorBuffer { &self, layout: vk::DescriptorSetLayout, ) -> vk::DeviceSize { - let mut count = 0; - (self.fp.get_descriptor_set_layout_size_ext)(self.handle, layout, &mut count); - count + let mut count = mem::MaybeUninit::uninit(); + (self.fp.get_descriptor_set_layout_size_ext)(self.handle, layout, count.as_mut_ptr()); + count.assume_init() } /// @@ -38,14 +38,14 @@ impl DescriptorBuffer { layout: vk::DescriptorSetLayout, binding: u32, ) -> vk::DeviceSize { - let mut offset = 0; + let mut offset = mem::MaybeUninit::uninit(); (self.fp.get_descriptor_set_layout_binding_offset_ext)( self.handle, layout, binding, - &mut offset, + offset.as_mut_ptr(), ); - offset + offset.assume_init() } /// diff --git a/ash/src/extensions/ext/full_screen_exclusive.rs b/ash/src/extensions/ext/full_screen_exclusive.rs index 8d3a7dc..5c9d10c 100644 --- a/ash/src/extensions/ext/full_screen_exclusive.rs +++ b/ash/src/extensions/ext/full_screen_exclusive.rs @@ -60,13 +60,13 @@ impl FullScreenExclusive { &self, surface_info: &vk::PhysicalDeviceSurfaceInfo2KHR<'_>, ) -> VkResult { - let mut present_modes = mem::zeroed(); + let mut present_modes = mem::MaybeUninit::uninit(); (self.fp.get_device_group_surface_present_modes2_ext)( self.handle, surface_info, - &mut present_modes, + present_modes.as_mut_ptr(), ) - .result_with_success(present_modes) + .assume_init_on_success(present_modes) } pub const NAME: &'static CStr = vk::ExtFullScreenExclusiveFn::NAME; diff --git a/ash/src/extensions/ext/headless_surface.rs b/ash/src/extensions/ext/headless_surface.rs index 1b0f249..a0cd490 100644 --- a/ash/src/extensions/ext/headless_surface.rs +++ b/ash/src/extensions/ext/headless_surface.rs @@ -28,14 +28,14 @@ impl HeadlessSurface { create_info: &vk::HeadlessSurfaceCreateInfoEXT<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut surface = mem::zeroed(); + let mut surface = mem::MaybeUninit::uninit(); (self.fp.create_headless_surface_ext)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut surface, + surface.as_mut_ptr(), ) - .result_with_success(surface) + .assume_init_on_success(surface) } pub const NAME: &'static CStr = vk::ExtHeadlessSurfaceFn::NAME; diff --git a/ash/src/extensions/ext/metal_surface.rs b/ash/src/extensions/ext/metal_surface.rs index ca971fe..0c069d2 100644 --- a/ash/src/extensions/ext/metal_surface.rs +++ b/ash/src/extensions/ext/metal_surface.rs @@ -27,14 +27,14 @@ impl MetalSurface { create_info: &vk::MetalSurfaceCreateInfoEXT<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut surface = mem::zeroed(); + let mut surface = mem::MaybeUninit::uninit(); (self.fp.create_metal_surface_ext)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut surface, + surface.as_mut_ptr(), ) - .result_with_success(surface) + .assume_init_on_success(surface) } pub const NAME: &'static CStr = vk::ExtMetalSurfaceFn::NAME; diff --git a/ash/src/extensions/ext/private_data.rs b/ash/src/extensions/ext/private_data.rs index 44d467f..8e54ec7 100644 --- a/ash/src/extensions/ext/private_data.rs +++ b/ash/src/extensions/ext/private_data.rs @@ -28,14 +28,14 @@ impl PrivateData { create_info: &vk::PrivateDataSlotCreateInfoEXT<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut private_data_slot = mem::zeroed(); + let mut private_data_slot = mem::MaybeUninit::uninit(); (self.fp.create_private_data_slot_ext)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut private_data_slot, + private_data_slot.as_mut_ptr(), ) - .result_with_success(private_data_slot) + .assume_init_on_success(private_data_slot) } /// @@ -77,15 +77,15 @@ impl PrivateData { object: T, private_data_slot: vk::PrivateDataSlotEXT, ) -> u64 { - let mut data = mem::zeroed(); + let mut data = mem::MaybeUninit::uninit(); (self.fp.get_private_data_ext)( self.handle, T::TYPE, object.as_raw(), private_data_slot, - &mut data, + data.as_mut_ptr(), ); - data + data.assume_init() } pub const NAME: &'static CStr = vk::ExtPrivateDataFn::NAME; diff --git a/ash/src/extensions/ext/shader_object.rs b/ash/src/extensions/ext/shader_object.rs index 358ade4..baaad72 100644 --- a/ash/src/extensions/ext/shader_object.rs +++ b/ash/src/extensions/ext/shader_object.rs @@ -37,9 +37,7 @@ impl ShaderObject { allocator.as_raw_ptr(), shaders.as_mut_ptr(), ) - .result()?; - shaders.set_len(create_infos.len()); - Ok(shaders) + .set_vec_len_on_success(shaders, create_infos.len()) } /// diff --git a/ash/src/extensions/google/display_timing.rs b/ash/src/extensions/google/display_timing.rs index 6b912cf..1ea45fb 100644 --- a/ash/src/extensions/google/display_timing.rs +++ b/ash/src/extensions/google/display_timing.rs @@ -37,9 +37,9 @@ impl DisplayTiming { &self, swapchain: vk::SwapchainKHR, ) -> VkResult { - let mut properties = mem::zeroed(); - (self.fp.get_refresh_cycle_duration_google)(self.handle, swapchain, &mut properties) - .result_with_success(properties) + let mut properties = mem::MaybeUninit::uninit(); + (self.fp.get_refresh_cycle_duration_google)(self.handle, swapchain, properties.as_mut_ptr()) + .assume_init_on_success(properties) } pub const NAME: &'static CStr = vk::GoogleDisplayTimingFn::NAME; diff --git a/ash/src/extensions/khr/acceleration_structure.rs b/ash/src/extensions/khr/acceleration_structure.rs index 0a52e99..043ab20 100644 --- a/ash/src/extensions/khr/acceleration_structure.rs +++ b/ash/src/extensions/khr/acceleration_structure.rs @@ -28,14 +28,14 @@ impl AccelerationStructure { create_info: &vk::AccelerationStructureCreateInfoKHR<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut accel_struct = mem::zeroed(); + let mut accel_struct = mem::MaybeUninit::uninit(); (self.fp.create_acceleration_structure_khr)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut accel_struct, + accel_struct.as_mut_ptr(), ) - .result_with_success(accel_struct) + .assume_init_on_success(accel_struct) } /// @@ -259,15 +259,13 @@ impl AccelerationStructure { &self, version: &vk::AccelerationStructureVersionInfoKHR<'_>, ) -> vk::AccelerationStructureCompatibilityKHR { - let mut compatibility = mem::zeroed(); - + let mut compatibility = mem::MaybeUninit::uninit(); (self.fp.get_device_acceleration_structure_compatibility_khr)( self.handle, version, - &mut compatibility, + compatibility.as_mut_ptr(), ); - - compatibility + compatibility.assume_init() } /// diff --git a/ash/src/extensions/khr/android_surface.rs b/ash/src/extensions/khr/android_surface.rs index f870bfa..d405273 100755 --- a/ash/src/extensions/khr/android_surface.rs +++ b/ash/src/extensions/khr/android_surface.rs @@ -27,14 +27,14 @@ impl AndroidSurface { create_info: &vk::AndroidSurfaceCreateInfoKHR<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut surface = mem::zeroed(); + let mut surface = mem::MaybeUninit::uninit(); (self.fp.create_android_surface_khr)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut surface, + surface.as_mut_ptr(), ) - .result_with_success(surface) + .assume_init_on_success(surface) } pub const NAME: &'static CStr = vk::KhrAndroidSurfaceFn::NAME; diff --git a/ash/src/extensions/khr/create_render_pass2.rs b/ash/src/extensions/khr/create_render_pass2.rs index 5062e4d..55db387 100644 --- a/ash/src/extensions/khr/create_render_pass2.rs +++ b/ash/src/extensions/khr/create_render_pass2.rs @@ -27,14 +27,14 @@ impl CreateRenderPass2 { create_info: &vk::RenderPassCreateInfo2<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut renderpass = mem::zeroed(); + let mut renderpass = mem::MaybeUninit::uninit(); (self.fp.create_render_pass2_khr)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut renderpass, + renderpass.as_mut_ptr(), ) - .result_with_success(renderpass) + .assume_init_on_success(renderpass) } /// diff --git a/ash/src/extensions/khr/deferred_host_operations.rs b/ash/src/extensions/khr/deferred_host_operations.rs index 61cbcf4..bf62488 100644 --- a/ash/src/extensions/khr/deferred_host_operations.rs +++ b/ash/src/extensions/khr/deferred_host_operations.rs @@ -26,13 +26,13 @@ impl DeferredHostOperations { &self, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut operation = mem::zeroed(); + let mut operation = mem::MaybeUninit::uninit(); (self.fp.create_deferred_operation_khr)( self.handle, allocation_callbacks.as_raw_ptr(), - &mut operation, + operation.as_mut_ptr(), ) - .result_with_success(operation) + .assume_init_on_success(operation) } /// diff --git a/ash/src/extensions/khr/device_group.rs b/ash/src/extensions/khr/device_group.rs index df86dd1..d030e51 100644 --- a/ash/src/extensions/khr/device_group.rs +++ b/ash/src/extensions/khr/device_group.rs @@ -30,15 +30,15 @@ impl DeviceGroup { local_device_index: u32, remote_device_index: u32, ) -> vk::PeerMemoryFeatureFlags { - let mut peer_memory_features = mem::zeroed(); + let mut peer_memory_features = mem::MaybeUninit::uninit(); (self.fp.get_device_group_peer_memory_features_khr)( self.handle, heap_index, local_device_index, remote_device_index, - &mut peer_memory_features, + peer_memory_features.as_mut_ptr(), ); - peer_memory_features + peer_memory_features.assume_init() } /// @@ -99,9 +99,13 @@ impl DeviceGroup { &self, surface: vk::SurfaceKHR, ) -> VkResult { - let mut modes = mem::zeroed(); - (self.fp.get_device_group_surface_present_modes_khr)(self.handle, surface, &mut modes) - .result_with_success(modes) + let mut modes = mem::MaybeUninit::uninit(); + (self.fp.get_device_group_surface_present_modes_khr)( + self.handle, + surface, + modes.as_mut_ptr(), + ) + .assume_init_on_success(modes) } /// Requires [`VK_KHR_surface`] to be enabled. @@ -143,11 +147,12 @@ impl DeviceGroup { &self, acquire_info: &vk::AcquireNextImageInfoKHR<'_>, ) -> VkResult<(u32, bool)> { - let mut index = 0; - let err_code = (self.fp.acquire_next_image2_khr)(self.handle, acquire_info, &mut index); + let mut index = mem::MaybeUninit::uninit(); + let err_code = + (self.fp.acquire_next_image2_khr)(self.handle, acquire_info, index.as_mut_ptr()); match err_code { - vk::Result::SUCCESS => Ok((index, false)), - vk::Result::SUBOPTIMAL_KHR => Ok((index, true)), + vk::Result::SUCCESS => Ok((index.assume_init(), false)), + vk::Result::SUBOPTIMAL_KHR => Ok((index.assume_init(), true)), _ => Err(err_code), } } diff --git a/ash/src/extensions/khr/device_group_creation.rs b/ash/src/extensions/khr/device_group_creation.rs index 6832765..3b5c9bd 100644 --- a/ash/src/extensions/khr/device_group_creation.rs +++ b/ash/src/extensions/khr/device_group_creation.rs @@ -24,13 +24,14 @@ impl DeviceGroupCreation { /// Retrieve the number of elements to pass to [`enumerate_physical_device_groups()`][Self::enumerate_physical_device_groups()] #[inline] pub unsafe fn enumerate_physical_device_groups_len(&self) -> VkResult { - let mut group_count = 0; + let mut group_count = mem::MaybeUninit::uninit(); (self.fp.enumerate_physical_device_groups_khr)( self.handle, - &mut group_count, + group_count.as_mut_ptr(), ptr::null_mut(), ) - .result_with_success(group_count as usize) + .assume_init_on_success(group_count) + .map(|c| c as usize) } /// diff --git a/ash/src/extensions/khr/display.rs b/ash/src/extensions/khr/display.rs index f393f49..8025d5a 100755 --- a/ash/src/extensions/khr/display.rs +++ b/ash/src/extensions/khr/display.rs @@ -80,7 +80,7 @@ impl Display { create_info: &vk::DisplayModeCreateInfoKHR<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut display_mode = mem::MaybeUninit::zeroed(); + let mut display_mode = mem::MaybeUninit::uninit(); (self.fp.create_display_mode_khr)( physical_device, display, @@ -99,7 +99,7 @@ impl Display { mode: vk::DisplayModeKHR, plane_index: u32, ) -> VkResult { - let mut display_plane_capabilities = mem::MaybeUninit::zeroed(); + let mut display_plane_capabilities = mem::MaybeUninit::uninit(); (self.fp.get_display_plane_capabilities_khr)( physical_device, mode, @@ -116,7 +116,7 @@ impl Display { create_info: &vk::DisplaySurfaceCreateInfoKHR<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut surface = mem::MaybeUninit::zeroed(); + let mut surface = mem::MaybeUninit::uninit(); (self.fp.create_display_plane_surface_khr)( self.handle, create_info, diff --git a/ash/src/extensions/khr/display_swapchain.rs b/ash/src/extensions/khr/display_swapchain.rs index cdc89c0..ff7cac4 100755 --- a/ash/src/extensions/khr/display_swapchain.rs +++ b/ash/src/extensions/khr/display_swapchain.rs @@ -35,9 +35,7 @@ impl DisplaySwapchain { allocation_callbacks.as_raw_ptr(), swapchains.as_mut_ptr(), ) - .result()?; - swapchains.set_len(create_infos.len()); - Ok(swapchains) + .set_vec_len_on_success(swapchains, create_infos.len()) } pub const NAME: &'static CStr = vk::KhrDisplaySwapchainFn::NAME; diff --git a/ash/src/extensions/khr/external_fence_fd.rs b/ash/src/extensions/khr/external_fence_fd.rs index ff703e9..4e387b4 100644 --- a/ash/src/extensions/khr/external_fence_fd.rs +++ b/ash/src/extensions/khr/external_fence_fd.rs @@ -31,8 +31,9 @@ impl ExternalFenceFd { /// #[inline] pub unsafe fn get_fence_fd(&self, get_info: &vk::FenceGetFdInfoKHR<'_>) -> VkResult { - let mut fd = -1; - (self.fp.get_fence_fd_khr)(self.handle, get_info, &mut fd).result_with_success(fd) + let mut fd = mem::MaybeUninit::uninit(); + (self.fp.get_fence_fd_khr)(self.handle, get_info, fd.as_mut_ptr()) + .assume_init_on_success(fd) } pub const NAME: &'static CStr = vk::KhrExternalFenceFdFn::NAME; diff --git a/ash/src/extensions/khr/external_fence_win32.rs b/ash/src/extensions/khr/external_fence_win32.rs index ec3c722..92ce2ca 100644 --- a/ash/src/extensions/khr/external_fence_win32.rs +++ b/ash/src/extensions/khr/external_fence_win32.rs @@ -3,7 +3,6 @@ use crate::vk; use crate::{Device, Instance}; use std::ffi::CStr; use std::mem; -use std::mem::MaybeUninit; /// #[derive(Clone)] @@ -36,7 +35,7 @@ impl ExternalFenceWin32 { &self, get_info: &vk::FenceGetWin32HandleInfoKHR<'_>, ) -> VkResult { - let mut handle = MaybeUninit::uninit(); + let mut handle = mem::MaybeUninit::uninit(); (self.fp.get_fence_win32_handle_khr)(self.handle, get_info, handle.as_mut_ptr()) .assume_init_on_success(handle) } diff --git a/ash/src/extensions/khr/external_memory_fd.rs b/ash/src/extensions/khr/external_memory_fd.rs index 7e28036..9e26042 100644 --- a/ash/src/extensions/khr/external_memory_fd.rs +++ b/ash/src/extensions/khr/external_memory_fd.rs @@ -23,8 +23,9 @@ impl ExternalMemoryFd { /// #[inline] pub unsafe fn get_memory_fd(&self, get_fd_info: &vk::MemoryGetFdInfoKHR<'_>) -> VkResult { - let mut fd = -1; - (self.fp.get_memory_fd_khr)(self.handle, get_fd_info, &mut fd).result_with_success(fd) + let mut fd = mem::MaybeUninit::uninit(); + (self.fp.get_memory_fd_khr)(self.handle, get_fd_info, fd.as_mut_ptr()) + .assume_init_on_success(fd) } /// diff --git a/ash/src/extensions/khr/external_memory_win32.rs b/ash/src/extensions/khr/external_memory_win32.rs index 7ac2039..3887109 100644 --- a/ash/src/extensions/khr/external_memory_win32.rs +++ b/ash/src/extensions/khr/external_memory_win32.rs @@ -3,7 +3,6 @@ use crate::vk; use crate::{Device, Instance}; use std::ffi::CStr; use std::mem; -use std::mem::MaybeUninit; /// #[derive(Clone)] @@ -27,7 +26,7 @@ impl ExternalMemoryWin32 { &self, create_info: &vk::MemoryGetWin32HandleInfoKHR<'_>, ) -> VkResult { - let mut handle = MaybeUninit::uninit(); + let mut handle = mem::MaybeUninit::uninit(); (self.fp.get_memory_win32_handle_khr)(self.handle, create_info, handle.as_mut_ptr()) .assume_init_on_success(handle) } diff --git a/ash/src/extensions/khr/external_semaphore_fd.rs b/ash/src/extensions/khr/external_semaphore_fd.rs index 5c8383f..09d8bba 100644 --- a/ash/src/extensions/khr/external_semaphore_fd.rs +++ b/ash/src/extensions/khr/external_semaphore_fd.rs @@ -34,8 +34,9 @@ impl ExternalSemaphoreFd { &self, get_info: &vk::SemaphoreGetFdInfoKHR<'_>, ) -> VkResult { - let mut fd = -1; - (self.fp.get_semaphore_fd_khr)(self.handle, get_info, &mut fd).result_with_success(fd) + let mut fd = mem::MaybeUninit::uninit(); + (self.fp.get_semaphore_fd_khr)(self.handle, get_info, fd.as_mut_ptr()) + .assume_init_on_success(fd) } pub const NAME: &'static CStr = vk::KhrExternalSemaphoreFdFn::NAME; diff --git a/ash/src/extensions/khr/external_semaphore_win32.rs b/ash/src/extensions/khr/external_semaphore_win32.rs index 6b0714c..0c69bcb 100644 --- a/ash/src/extensions/khr/external_semaphore_win32.rs +++ b/ash/src/extensions/khr/external_semaphore_win32.rs @@ -3,7 +3,6 @@ use crate::vk; use crate::{Device, Instance}; use std::ffi::CStr; use std::mem; -use std::mem::MaybeUninit; /// #[derive(Clone)] @@ -36,7 +35,7 @@ impl ExternalSemaphoreWin32 { &self, get_info: &vk::SemaphoreGetWin32HandleInfoKHR<'_>, ) -> VkResult { - let mut handle = MaybeUninit::uninit(); + let mut handle = mem::MaybeUninit::uninit(); (self.fp.get_semaphore_win32_handle_khr)(self.handle, get_info, handle.as_mut_ptr()) .assume_init_on_success(handle) } diff --git a/ash/src/extensions/khr/get_memory_requirements2.rs b/ash/src/extensions/khr/get_memory_requirements2.rs index 4fd7f84..a29ebd7 100644 --- a/ash/src/extensions/khr/get_memory_requirements2.rs +++ b/ash/src/extensions/khr/get_memory_requirements2.rs @@ -45,14 +45,14 @@ impl GetMemoryRequirements2 { &self, info: &vk::ImageSparseMemoryRequirementsInfo2KHR<'_>, ) -> usize { - let mut count = 0; + let mut count = mem::MaybeUninit::uninit(); (self.fp.get_image_sparse_memory_requirements2_khr)( self.handle, info, - &mut count, + count.as_mut_ptr(), ptr::null_mut(), ); - count as usize + count.assume_init() as usize } /// diff --git a/ash/src/extensions/khr/get_physical_device_properties2.rs b/ash/src/extensions/khr/get_physical_device_properties2.rs index 16fe4e6..1bb507c 100644 --- a/ash/src/extensions/khr/get_physical_device_properties2.rs +++ b/ash/src/extensions/khr/get_physical_device_properties2.rs @@ -85,13 +85,13 @@ impl GetPhysicalDeviceProperties2 { &self, physical_device: vk::PhysicalDevice, ) -> usize { - let mut count = 0; + let mut count = mem::MaybeUninit::uninit(); (self.fp.get_physical_device_queue_family_properties2_khr)( physical_device, - &mut count, + count.as_mut_ptr(), ptr::null_mut(), ); - count as usize + count.assume_init() as usize } /// @@ -120,16 +120,16 @@ impl GetPhysicalDeviceProperties2 { physical_device: vk::PhysicalDevice, format_info: &vk::PhysicalDeviceSparseImageFormatInfo2KHR<'_>, ) -> usize { - let mut count = 0; + let mut count = mem::MaybeUninit::uninit(); (self .fp .get_physical_device_sparse_image_format_properties2_khr)( physical_device, format_info, - &mut count, + count.as_mut_ptr(), ptr::null_mut(), ); - count as usize + count.assume_init() as usize } /// diff --git a/ash/src/extensions/khr/get_surface_capabilities2.rs b/ash/src/extensions/khr/get_surface_capabilities2.rs index 878c337..23762b3 100644 --- a/ash/src/extensions/khr/get_surface_capabilities2.rs +++ b/ash/src/extensions/khr/get_surface_capabilities2.rs @@ -41,14 +41,14 @@ impl GetSurfaceCapabilities2 { physical_device: vk::PhysicalDevice, surface_info: &vk::PhysicalDeviceSurfaceInfo2KHR<'_>, ) -> VkResult { - let mut count = 0; + let mut count = mem::MaybeUninit::uninit(); let err_code = (self.fp.get_physical_device_surface_formats2_khr)( physical_device, surface_info, - &mut count, + count.as_mut_ptr(), std::ptr::null_mut(), ); - err_code.result_with_success(count as usize) + err_code.assume_init_on_success(count).map(|c| c as usize) } /// diff --git a/ash/src/extensions/khr/maintenance4.rs b/ash/src/extensions/khr/maintenance4.rs index aaf5f57..db7a075 100644 --- a/ash/src/extensions/khr/maintenance4.rs +++ b/ash/src/extensions/khr/maintenance4.rs @@ -45,14 +45,14 @@ impl Maintenance4 { &self, memory_requirements: &vk::DeviceImageMemoryRequirementsKHR<'_>, ) -> usize { - let mut count = 0; + let mut count = mem::MaybeUninit::uninit(); (self.fp.get_device_image_sparse_memory_requirements_khr)( self.handle, memory_requirements, - &mut count, + count.as_mut_ptr(), std::ptr::null_mut(), ); - count as usize + count.assume_init() as usize } /// diff --git a/ash/src/extensions/khr/maintenance5.rs b/ash/src/extensions/khr/maintenance5.rs index 3ed8787..f54a99a 100644 --- a/ash/src/extensions/khr/maintenance5.rs +++ b/ash/src/extensions/khr/maintenance5.rs @@ -40,13 +40,13 @@ impl Maintenance5 { &self, rendering_area_info: &vk::RenderingAreaInfoKHR<'_>, ) -> vk::Extent2D { - let mut granularity = mem::zeroed(); + let mut granularity = mem::MaybeUninit::uninit(); (self.fp.get_rendering_area_granularity_khr)( self.handle, rendering_area_info, - &mut granularity, + granularity.as_mut_ptr(), ); - granularity + granularity.assume_init() } /// diff --git a/ash/src/extensions/khr/performance_query.rs b/ash/src/extensions/khr/performance_query.rs index dc47019..868378b 100644 --- a/ash/src/extensions/khr/performance_query.rs +++ b/ash/src/extensions/khr/performance_query.rs @@ -28,17 +28,18 @@ impl PerformanceQuery { physical_device: vk::PhysicalDevice, queue_family_index: u32, ) -> VkResult { - let mut count = 0; + let mut count = mem::MaybeUninit::uninit(); (self .fp .enumerate_physical_device_queue_family_performance_query_counters_khr)( physical_device, queue_family_index, - &mut count, + count.as_mut_ptr(), ptr::null_mut(), ptr::null_mut(), ) - .result_with_success(count as usize) + .assume_init_on_success(count) + .map(|c| c as usize) } /// @@ -77,15 +78,15 @@ impl PerformanceQuery { physical_device: vk::PhysicalDevice, performance_query_create_info: &vk::QueryPoolPerformanceCreateInfoKHR<'_>, ) -> u32 { - let mut num_passes = 0; + let mut num_passes = mem::MaybeUninit::uninit(); (self .fp .get_physical_device_queue_family_performance_query_passes_khr)( physical_device, performance_query_create_info, - &mut num_passes, + num_passes.as_mut_ptr(), ); - num_passes + num_passes.assume_init() } /// diff --git a/ash/src/extensions/khr/ray_tracing_pipeline.rs b/ash/src/extensions/khr/ray_tracing_pipeline.rs index ed397cd..e29cde4 100644 --- a/ash/src/extensions/khr/ray_tracing_pipeline.rs +++ b/ash/src/extensions/khr/ray_tracing_pipeline.rs @@ -54,7 +54,7 @@ impl RayTracingPipeline { create_info: &[vk::RayTracingPipelineCreateInfoKHR<'_>], allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult> { - let mut pipelines = vec![mem::zeroed(); create_info.len()]; + let mut pipelines = Vec::with_capacity(create_info.len()); (self.fp.create_ray_tracing_pipelines_khr)( self.handle, deferred_operation, @@ -64,7 +64,7 @@ impl RayTracingPipeline { allocation_callbacks.as_raw_ptr(), pipelines.as_mut_ptr(), ) - .result_with_success(pipelines) + .set_vec_len_on_success(pipelines, create_info.len()) } /// @@ -85,9 +85,7 @@ impl RayTracingPipeline { data_size, data.as_mut_ptr().cast(), ) - .result()?; - data.set_len(data_size); - Ok(data) + .set_vec_len_on_success(data, data_size) } /// @@ -110,9 +108,7 @@ impl RayTracingPipeline { data_size, data.as_mut_ptr().cast(), ) - .result()?; - data.set_len(data_size); - Ok(data) + .set_vec_len_on_success(data, data_size) } /// diff --git a/ash/src/extensions/khr/sampler_ycbcr_conversion.rs b/ash/src/extensions/khr/sampler_ycbcr_conversion.rs index 56876e1..ade7fd5 100644 --- a/ash/src/extensions/khr/sampler_ycbcr_conversion.rs +++ b/ash/src/extensions/khr/sampler_ycbcr_conversion.rs @@ -28,14 +28,14 @@ impl SamplerYcbcrConversion { create_info: &vk::SamplerYcbcrConversionCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut ycbcr_conversion = mem::zeroed(); + let mut ycbcr_conversion = mem::MaybeUninit::uninit(); (self.fp.create_sampler_ycbcr_conversion_khr)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut ycbcr_conversion, + ycbcr_conversion.as_mut_ptr(), ) - .result_with_success(ycbcr_conversion) + .assume_init_on_success(ycbcr_conversion) } /// diff --git a/ash/src/extensions/khr/surface.rs b/ash/src/extensions/khr/surface.rs index 1ba4756..5245884 100755 --- a/ash/src/extensions/khr/surface.rs +++ b/ash/src/extensions/khr/surface.rs @@ -28,14 +28,15 @@ impl Surface { queue_family_index: u32, surface: vk::SurfaceKHR, ) -> VkResult { - let mut b = 0; + let mut b = mem::MaybeUninit::uninit(); (self.fp.get_physical_device_surface_support_khr)( physical_device, queue_family_index, surface, - &mut b, + b.as_mut_ptr(), ) - .result_with_success(b > 0) + .result()?; + Ok(b.assume_init() > 0) } /// @@ -62,13 +63,13 @@ impl Surface { physical_device: vk::PhysicalDevice, surface: vk::SurfaceKHR, ) -> VkResult { - let mut surface_capabilities = mem::zeroed(); + let mut surface_capabilities = mem::MaybeUninit::uninit(); (self.fp.get_physical_device_surface_capabilities_khr)( physical_device, surface, - &mut surface_capabilities, + surface_capabilities.as_mut_ptr(), ) - .result_with_success(surface_capabilities) + .assume_init_on_success(surface_capabilities) } /// diff --git a/ash/src/extensions/khr/swapchain.rs b/ash/src/extensions/khr/swapchain.rs index 03b9702..cfc10ac 100755 --- a/ash/src/extensions/khr/swapchain.rs +++ b/ash/src/extensions/khr/swapchain.rs @@ -29,14 +29,14 @@ impl Swapchain { create_info: &vk::SwapchainCreateInfoKHR<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut swapchain = mem::zeroed(); + let mut swapchain = mem::MaybeUninit::uninit(); (self.fp.create_swapchain_khr)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut swapchain, + swapchain.as_mut_ptr(), ) - .result_with_success(swapchain) + .assume_init_on_success(swapchain) } /// @@ -71,18 +71,18 @@ impl Swapchain { semaphore: vk::Semaphore, fence: vk::Fence, ) -> VkResult<(u32, bool)> { - let mut index = 0; + let mut index = mem::MaybeUninit::uninit(); let err_code = (self.fp.acquire_next_image_khr)( self.handle, swapchain, timeout, semaphore, fence, - &mut index, + index.as_mut_ptr(), ); match err_code { - vk::Result::SUCCESS => Ok((index, false)), - vk::Result::SUBOPTIMAL_KHR => Ok((index, true)), + vk::Result::SUCCESS => Ok((index.assume_init(), false)), + vk::Result::SUBOPTIMAL_KHR => Ok((index.assume_init(), true)), _ => Err(err_code), } } @@ -139,9 +139,13 @@ impl Swapchain { &self, surface: vk::SurfaceKHR, ) -> VkResult { - let mut modes = mem::zeroed(); - (self.fp.get_device_group_surface_present_modes_khr)(self.handle, surface, &mut modes) - .result_with_success(modes) + let mut modes = mem::MaybeUninit::uninit(); + (self.fp.get_device_group_surface_present_modes_khr)( + self.handle, + surface, + modes.as_mut_ptr(), + ) + .assume_init_on_success(modes) } /// Only available since [Vulkan 1.1]. @@ -185,11 +189,12 @@ impl Swapchain { &self, acquire_info: &vk::AcquireNextImageInfoKHR<'_>, ) -> VkResult<(u32, bool)> { - let mut index = 0; - let err_code = (self.fp.acquire_next_image2_khr)(self.handle, acquire_info, &mut index); + let mut index = mem::MaybeUninit::uninit(); + let err_code = + (self.fp.acquire_next_image2_khr)(self.handle, acquire_info, index.as_mut_ptr()); match err_code { - vk::Result::SUCCESS => Ok((index, false)), - vk::Result::SUBOPTIMAL_KHR => Ok((index, true)), + vk::Result::SUCCESS => Ok((index.assume_init(), false)), + vk::Result::SUBOPTIMAL_KHR => Ok((index.assume_init(), true)), _ => Err(err_code), } } diff --git a/ash/src/extensions/khr/timeline_semaphore.rs b/ash/src/extensions/khr/timeline_semaphore.rs index 2cb96a3..afd5f86 100644 --- a/ash/src/extensions/khr/timeline_semaphore.rs +++ b/ash/src/extensions/khr/timeline_semaphore.rs @@ -22,9 +22,9 @@ impl TimelineSemaphore { /// #[inline] pub unsafe fn get_semaphore_counter_value(&self, semaphore: vk::Semaphore) -> VkResult { - let mut value = 0; - (self.fp.get_semaphore_counter_value_khr)(self.handle, semaphore, &mut value) - .result_with_success(value) + let mut value = mem::MaybeUninit::uninit(); + (self.fp.get_semaphore_counter_value_khr)(self.handle, semaphore, value.as_mut_ptr()) + .assume_init_on_success(value) } /// diff --git a/ash/src/extensions/khr/wayland_surface.rs b/ash/src/extensions/khr/wayland_surface.rs index 1dd4a37..d7f382d 100755 --- a/ash/src/extensions/khr/wayland_surface.rs +++ b/ash/src/extensions/khr/wayland_surface.rs @@ -27,14 +27,14 @@ impl WaylandSurface { create_info: &vk::WaylandSurfaceCreateInfoKHR<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut surface = mem::zeroed(); + let mut surface = mem::MaybeUninit::uninit(); (self.fp.create_wayland_surface_khr)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut surface, + surface.as_mut_ptr(), ) - .result_with_success(surface) + .assume_init_on_success(surface) } /// diff --git a/ash/src/extensions/khr/win32_surface.rs b/ash/src/extensions/khr/win32_surface.rs index 98b8125..e72752d 100755 --- a/ash/src/extensions/khr/win32_surface.rs +++ b/ash/src/extensions/khr/win32_surface.rs @@ -27,14 +27,14 @@ impl Win32Surface { create_info: &vk::Win32SurfaceCreateInfoKHR<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut surface = mem::zeroed(); + let mut surface = mem::MaybeUninit::uninit(); (self.fp.create_win32_surface_khr)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut surface, + surface.as_mut_ptr(), ) - .result_with_success(surface) + .assume_init_on_success(surface) } /// diff --git a/ash/src/extensions/khr/xcb_surface.rs b/ash/src/extensions/khr/xcb_surface.rs index d9f79c3..70a400e 100755 --- a/ash/src/extensions/khr/xcb_surface.rs +++ b/ash/src/extensions/khr/xcb_surface.rs @@ -27,14 +27,14 @@ impl XcbSurface { create_info: &vk::XcbSurfaceCreateInfoKHR<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut surface = mem::zeroed(); + let mut surface = mem::MaybeUninit::uninit(); (self.fp.create_xcb_surface_khr)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut surface, + surface.as_mut_ptr(), ) - .result_with_success(surface) + .assume_init_on_success(surface) } /// diff --git a/ash/src/extensions/khr/xlib_surface.rs b/ash/src/extensions/khr/xlib_surface.rs index db4f87a..a0cf782 100755 --- a/ash/src/extensions/khr/xlib_surface.rs +++ b/ash/src/extensions/khr/xlib_surface.rs @@ -27,14 +27,14 @@ impl XlibSurface { create_info: &vk::XlibSurfaceCreateInfoKHR<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut surface = mem::zeroed(); + let mut surface = mem::MaybeUninit::uninit(); (self.fp.create_xlib_surface_khr)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut surface, + surface.as_mut_ptr(), ) - .result_with_success(surface) + .assume_init_on_success(surface) } /// diff --git a/ash/src/extensions/mvk/ios_surface.rs b/ash/src/extensions/mvk/ios_surface.rs index 005ee88..cf33f1b 100755 --- a/ash/src/extensions/mvk/ios_surface.rs +++ b/ash/src/extensions/mvk/ios_surface.rs @@ -27,14 +27,14 @@ impl IOSSurface { create_info: &vk::IOSSurfaceCreateInfoMVK<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut surface = mem::zeroed(); + let mut surface = mem::MaybeUninit::uninit(); (self.fp.create_ios_surface_mvk)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut surface, + surface.as_mut_ptr(), ) - .result_with_success(surface) + .assume_init_on_success(surface) } pub const NAME: &'static CStr = vk::MvkIosSurfaceFn::NAME; diff --git a/ash/src/extensions/mvk/macos_surface.rs b/ash/src/extensions/mvk/macos_surface.rs index 5d2feef..9d68d49 100755 --- a/ash/src/extensions/mvk/macos_surface.rs +++ b/ash/src/extensions/mvk/macos_surface.rs @@ -27,14 +27,14 @@ impl MacOSSurface { create_info: &vk::MacOSSurfaceCreateInfoMVK<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut surface = mem::zeroed(); + let mut surface = mem::MaybeUninit::uninit(); (self.fp.create_mac_os_surface_mvk)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut surface, + surface.as_mut_ptr(), ) - .result_with_success(surface) + .assume_init_on_success(surface) } pub const NAME: &'static CStr = vk::MvkMacosSurfaceFn::NAME; diff --git a/ash/src/extensions/nn/vi_surface.rs b/ash/src/extensions/nn/vi_surface.rs index 07fec12..3b6c296 100644 --- a/ash/src/extensions/nn/vi_surface.rs +++ b/ash/src/extensions/nn/vi_surface.rs @@ -27,14 +27,14 @@ impl ViSurface { create_info: &vk::ViSurfaceCreateInfoNN<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut surface = mem::zeroed(); + let mut surface = mem::MaybeUninit::uninit(); (self.fp.create_vi_surface_nn)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut surface, + surface.as_mut_ptr(), ) - .result_with_success(surface) + .assume_init_on_success(surface) } pub const NAME: &'static CStr = vk::NnViSurfaceFn::NAME; diff --git a/ash/src/extensions/nv/coverage_reduction_mode.rs b/ash/src/extensions/nv/coverage_reduction_mode.rs index 972849d..94c7892 100644 --- a/ash/src/extensions/nv/coverage_reduction_mode.rs +++ b/ash/src/extensions/nv/coverage_reduction_mode.rs @@ -24,15 +24,16 @@ impl CoverageReductionMode { &self, physical_device: vk::PhysicalDevice, ) -> VkResult { - let mut count = 0; + let mut count = mem::MaybeUninit::uninit(); (self .fp .get_physical_device_supported_framebuffer_mixed_samples_combinations_nv)( physical_device, - &mut count, + count.as_mut_ptr(), std::ptr::null_mut(), ) - .result_with_success(count as usize) + .assume_init_on_success(count) + .map(|c| c as usize) } /// diff --git a/ash/src/extensions/nv/device_diagnostic_checkpoints.rs b/ash/src/extensions/nv/device_diagnostic_checkpoints.rs index d665c2c..03c8011 100644 --- a/ash/src/extensions/nv/device_diagnostic_checkpoints.rs +++ b/ash/src/extensions/nv/device_diagnostic_checkpoints.rs @@ -31,9 +31,9 @@ impl DeviceDiagnosticCheckpoints { /// Retrieve the number of elements to pass to [`get_queue_checkpoint_data()`][Self::get_queue_checkpoint_data()] #[inline] pub unsafe fn get_queue_checkpoint_data_len(&self, queue: vk::Queue) -> usize { - let mut count = 0; - (self.fp.get_queue_checkpoint_data_nv)(queue, &mut count, std::ptr::null_mut()); - count as usize + let mut count = mem::MaybeUninit::uninit(); + (self.fp.get_queue_checkpoint_data_nv)(queue, count.as_mut_ptr(), std::ptr::null_mut()); + count.assume_init() as usize } /// diff --git a/ash/src/extensions/nv/ray_tracing.rs b/ash/src/extensions/nv/ray_tracing.rs index 75d7187..d09a709 100755 --- a/ash/src/extensions/nv/ray_tracing.rs +++ b/ash/src/extensions/nv/ray_tracing.rs @@ -27,14 +27,14 @@ impl RayTracing { create_info: &vk::AccelerationStructureCreateInfoNV<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut accel_struct = mem::zeroed(); + let mut accel_struct = mem::MaybeUninit::uninit(); (self.fp.create_acceleration_structure_nv)( self.handle, create_info, allocation_callbacks.as_raw_ptr(), - &mut accel_struct, + accel_struct.as_mut_ptr(), ) - .result_with_success(accel_struct) + .assume_init_on_success(accel_struct) } /// @@ -166,7 +166,7 @@ impl RayTracing { create_info: &[vk::RayTracingPipelineCreateInfoNV<'_>], allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult> { - let mut pipelines = vec![mem::zeroed(); create_info.len()]; + let mut pipelines = Vec::with_capacity(create_info.len()); (self.fp.create_ray_tracing_pipelines_nv)( self.handle, pipeline_cache, @@ -175,7 +175,7 @@ impl RayTracing { allocation_callbacks.as_raw_ptr(), pipelines.as_mut_ptr(), ) - .result_with_success(pipelines) + .set_vec_len_on_success(pipelines, create_info.len()) } /// @@ -204,15 +204,14 @@ impl RayTracing { &self, accel_struct: vk::AccelerationStructureNV, ) -> VkResult { - let mut handle: u64 = 0; - let handle_ptr: *mut u64 = &mut handle; + let mut handle = mem::MaybeUninit::::uninit(); (self.fp.get_acceleration_structure_handle_nv)( self.handle, accel_struct, - std::mem::size_of::(), - handle_ptr.cast(), + std::mem::size_of_val(&handle), + handle.as_mut_ptr().cast(), ) - .result_with_success(handle) + .assume_init_on_success(handle) } /// diff --git a/ash/src/instance.rs b/ash/src/instance.rs index 97576fe..8987224 100644 --- a/ash/src/instance.rs +++ b/ash/src/instance.rs @@ -67,13 +67,14 @@ impl Instance { &self, physical_device: vk::PhysicalDevice, ) -> VkResult { - let mut count = 0; + let mut count = mem::MaybeUninit::uninit(); (self.instance_fn_1_3.get_physical_device_tool_properties)( physical_device, - &mut count, + count.as_mut_ptr(), ptr::null_mut(), ) - .result_with_success(count as usize) + .assume_init_on_success(count) + .map(|c| c as usize) } /// @@ -108,13 +109,14 @@ impl Instance { /// Retrieve the number of elements to pass to [`enumerate_physical_device_groups()`][Self::enumerate_physical_device_groups()] #[inline] pub unsafe fn enumerate_physical_device_groups_len(&self) -> VkResult { - let mut group_count = 0; + let mut group_count = mem::MaybeUninit::uninit(); (self.instance_fn_1_1.enumerate_physical_device_groups)( self.handle(), - &mut group_count, + group_count.as_mut_ptr(), ptr::null_mut(), ) - .result_with_success(group_count as usize) + .assume_init_on_success(group_count) + .map(|c| c as usize) } /// @@ -192,15 +194,15 @@ impl Instance { &self, physical_device: vk::PhysicalDevice, ) -> usize { - let mut queue_count = 0; + let mut queue_count = mem::MaybeUninit::uninit(); (self .instance_fn_1_1 .get_physical_device_queue_family_properties2)( physical_device, - &mut queue_count, + queue_count.as_mut_ptr(), ptr::null_mut(), ); - queue_count as usize + queue_count.assume_init() as usize } /// @@ -241,16 +243,16 @@ impl Instance { physical_device: vk::PhysicalDevice, format_info: &vk::PhysicalDeviceSparseImageFormatInfo2<'_>, ) -> usize { - let mut format_count = 0; + let mut format_count = mem::MaybeUninit::uninit(); (self .instance_fn_1_1 .get_physical_device_sparse_image_format_properties2)( physical_device, format_info, - &mut format_count, + format_count.as_mut_ptr(), ptr::null_mut(), ); - format_count as usize + format_count.assume_init() as usize } /// @@ -356,14 +358,14 @@ impl Instance { create_info: &vk::DeviceCreateInfo<'_>, allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, ) -> VkResult { - let mut device = mem::zeroed(); - (self.instance_fn_1_0.create_device)( + let mut device = mem::MaybeUninit::uninit(); + let device = (self.instance_fn_1_0.create_device)( physical_device, create_info, allocation_callbacks.as_raw_ptr(), - &mut device, + device.as_mut_ptr(), ) - .result()?; + .assume_init_on_success(device)?; Ok(Device::load(&self.instance_fn_1_0, device)) } @@ -393,13 +395,13 @@ impl Instance { physical_device: vk::PhysicalDevice, format: vk::Format, ) -> vk::FormatProperties { - let mut format_prop = mem::zeroed(); + let mut format_prop = mem::MaybeUninit::uninit(); (self.instance_fn_1_0.get_physical_device_format_properties)( physical_device, format, - &mut format_prop, + format_prop.as_mut_ptr(), ); - format_prop + format_prop.assume_init() } /// @@ -413,7 +415,7 @@ impl Instance { usage: vk::ImageUsageFlags, flags: vk::ImageCreateFlags, ) -> VkResult { - let mut image_format_prop = mem::zeroed(); + let mut image_format_prop = mem::MaybeUninit::uninit(); (self .instance_fn_1_0 .get_physical_device_image_format_properties)( @@ -423,9 +425,9 @@ impl Instance { tiling, usage, flags, - &mut image_format_prop, + image_format_prop.as_mut_ptr(), ) - .result_with_success(image_format_prop) + .assume_init_on_success(image_format_prop) } /// @@ -434,12 +436,12 @@ impl Instance { &self, physical_device: vk::PhysicalDevice, ) -> vk::PhysicalDeviceMemoryProperties { - let mut memory_prop = mem::zeroed(); + let mut memory_prop = mem::MaybeUninit::uninit(); (self.instance_fn_1_0.get_physical_device_memory_properties)( physical_device, - &mut memory_prop, + memory_prop.as_mut_ptr(), ); - memory_prop + memory_prop.assume_init() } /// @@ -448,9 +450,9 @@ impl Instance { &self, physical_device: vk::PhysicalDevice, ) -> vk::PhysicalDeviceProperties { - let mut prop = mem::zeroed(); - (self.instance_fn_1_0.get_physical_device_properties)(physical_device, &mut prop); - prop + let mut prop = mem::MaybeUninit::uninit(); + (self.instance_fn_1_0.get_physical_device_properties)(physical_device, prop.as_mut_ptr()); + prop.assume_init() } /// @@ -477,9 +479,9 @@ impl Instance { &self, physical_device: vk::PhysicalDevice, ) -> vk::PhysicalDeviceFeatures { - let mut prop = mem::zeroed(); - (self.instance_fn_1_0.get_physical_device_features)(physical_device, &mut prop); - prop + let mut prop = mem::MaybeUninit::uninit(); + (self.instance_fn_1_0.get_physical_device_features)(physical_device, prop.as_mut_ptr()); + prop.assume_init() } /// diff --git a/ash/src/prelude.rs b/ash/src/prelude.rs index 8f79494..d73e53d 100644 --- a/ash/src/prelude.rs +++ b/ash/src/prelude.rs @@ -24,6 +24,14 @@ impl vk::Result { pub unsafe fn assume_init_on_success(self, v: mem::MaybeUninit) -> VkResult { self.result().map(move |()| v.assume_init()) } + + #[inline] + pub unsafe fn set_vec_len_on_success(self, mut v: Vec, len: usize) -> VkResult> { + self.result().map(move |()| { + v.set_len(len); + v + }) + } } /// Repeatedly calls `f` until it does not return [`vk::Result::INCOMPLETE`] anymore, ensuring all @@ -48,9 +56,10 @@ where let err_code = f(&mut count, data.as_mut_ptr()); if err_code != vk::Result::INCOMPLETE { - err_code.result()?; - data.set_len(count.try_into().expect("`N` failed to convert to `usize`")); - break Ok(data); + break err_code.set_vec_len_on_success( + data, + count.try_into().expect("`N` failed to convert to `usize`"), + ); } } } @@ -85,8 +94,10 @@ where let err_code = f(&mut count, data.as_mut_ptr()); if err_code != vk::Result::INCOMPLETE { - data.set_len(count.try_into().expect("`N` failed to convert to `usize`")); - break err_code.result_with_success(data); + break err_code.set_vec_len_on_success( + data, + count.try_into().expect("`N` failed to convert to `usize`"), + ); } } }