From 763c9b39f27c33243de9714157a56353d139a024 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Wed, 6 Sep 2023 12:31:56 +0200 Subject: [PATCH 1/4] Convert `mem::zeroed()` / `0` to `MaybeUninit::uninit()` As noted in #792 changes like this might help us more strictly identify and validate that the argument in question is only relevant as an output argument (i.e. structs with `sType` are read by the function call, even if the caller strictly expects return values there, so that it can fill in multiple structures in a `pNext` chain, and must hence be `Default`- initialized). --- ash-examples/src/bin/texture.rs | 1 - ash-examples/src/bin/triangle.rs | 1 - ash/src/device.rs | 229 ++++++++++-------- ash/src/entry.rs | 20 +- ash/src/extensions/amdx/shader_enqueue.rs | 6 +- ...external_memory_android_hardware_buffer.rs | 6 +- .../extensions/ext/calibrated_timestamps.rs | 7 +- ash/src/extensions/ext/debug_report.rs | 6 +- ash/src/extensions/ext/debug_utils.rs | 6 +- ash/src/extensions/ext/descriptor_buffer.rs | 12 +- .../extensions/ext/full_screen_exclusive.rs | 6 +- ash/src/extensions/ext/headless_surface.rs | 6 +- ash/src/extensions/ext/metal_surface.rs | 6 +- ash/src/extensions/ext/private_data.rs | 12 +- ash/src/extensions/google/display_timing.rs | 6 +- .../extensions/khr/acceleration_structure.rs | 14 +- ash/src/extensions/khr/android_surface.rs | 6 +- ash/src/extensions/khr/create_render_pass2.rs | 6 +- .../khr/deferred_host_operations.rs | 6 +- ash/src/extensions/khr/device_group.rs | 25 +- .../extensions/khr/device_group_creation.rs | 7 +- ash/src/extensions/khr/display.rs | 6 +- .../extensions/khr/external_fence_win32.rs | 3 +- .../extensions/khr/external_memory_win32.rs | 3 +- .../khr/external_semaphore_win32.rs | 3 +- .../khr/get_memory_requirements2.rs | 6 +- .../khr/get_physical_device_properties2.rs | 12 +- .../khr/get_surface_capabilities2.rs | 6 +- ash/src/extensions/khr/maintenance4.rs | 6 +- ash/src/extensions/khr/maintenance5.rs | 6 +- ash/src/extensions/khr/performance_query.rs | 13 +- .../khr/sampler_ycbcr_conversion.rs | 6 +- ash/src/extensions/khr/surface.rs | 13 +- ash/src/extensions/khr/swapchain.rs | 33 +-- ash/src/extensions/khr/timeline_semaphore.rs | 6 +- ash/src/extensions/khr/wayland_surface.rs | 6 +- ash/src/extensions/khr/win32_surface.rs | 6 +- ash/src/extensions/khr/xcb_surface.rs | 6 +- ash/src/extensions/khr/xlib_surface.rs | 6 +- ash/src/extensions/mvk/ios_surface.rs | 6 +- ash/src/extensions/mvk/macos_surface.rs | 6 +- ash/src/extensions/nn/vi_surface.rs | 6 +- .../extensions/nv/coverage_reduction_mode.rs | 7 +- .../nv/device_diagnostic_checkpoints.rs | 6 +- ash/src/extensions/nv/ray_tracing.rs | 15 +- ash/src/instance.rs | 64 ++--- 46 files changed, 340 insertions(+), 310 deletions(-) diff --git a/ash-examples/src/bin/texture.rs b/ash-examples/src/bin/texture.rs index 298446c4c..b512a22fc 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 621b57b2e..ee0bcc5be 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 d64a760e7..f9a3f58b1 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) } /// @@ -1555,14 +1559,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 +1582,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 +2127,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 +2192,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 +2209,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 +2226,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 +2277,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 +2330,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 +2386,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 +2483,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 +2514,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) } /// @@ -2537,14 +2548,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 +2565,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 +2582,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 +2599,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 +2627,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 +2643,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 +2660,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 +2677,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 +2713,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 05620618f..a87cafc91 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 054aac19c..c775f848d 100644 --- a/ash/src/extensions/amdx/shader_enqueue.rs +++ b/ash/src/extensions/amdx/shader_enqueue.rs @@ -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 be18becbe..fec7ec62f 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 d2d527f3f..ff2ebc59f 100644 --- a/ash/src/extensions/ext/calibrated_timestamps.rs +++ b/ash/src/extensions/ext/calibrated_timestamps.rs @@ -44,15 +44,16 @@ impl CalibratedTimestamps { info: &[vk::CalibratedTimestampInfoEXT<'_>], ) -> VkResult<(Vec, u64)> { let mut timestamps = vec![0u64; info.len()]; - let mut max_deviation = 0u64; + let mut max_deviation = mem::MaybeUninit::uninit(); (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) + .map(|max_deviation| (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 0443894bc..695100238 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 5ba5dd2d2..7dad5c2f5 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 341537de2..d7cf6d039 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 8d3a7dcb8..5c9d10cb5 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 1b0f249ed..a0cd4906c 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 ca971fec7..0c069d28d 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 44d467fb8..8e54ec796 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/google/display_timing.rs b/ash/src/extensions/google/display_timing.rs index 6b912cf0e..1ea45fbe2 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 0a52e9952..043ab2061 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 f870bfa5a..d40527373 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 5062e4dc0..55db38758 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 61cbcf494..bf62488c1 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 df86dd1ba..d030e519a 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 683276552..3b5c9bdc3 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 f393f498e..8025d5a93 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/external_fence_win32.rs b/ash/src/extensions/khr/external_fence_win32.rs index ec3c722b4..92ce2caec 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_win32.rs b/ash/src/extensions/khr/external_memory_win32.rs index 7ac2039de..388710905 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_win32.rs b/ash/src/extensions/khr/external_semaphore_win32.rs index 6b0714c55..0c69bcbaa 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 4fd7f84d3..a29ebd75c 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 16fe4e67e..1bb507c4e 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 878c33761..23762b32b 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 aaf5f5745..db7a07588 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 3ed878733..f54a99a19 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 dc47019b4..868378b8f 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/sampler_ycbcr_conversion.rs b/ash/src/extensions/khr/sampler_ycbcr_conversion.rs index 56876e142..ade7fd5b4 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 1ba4756eb..5245884ea 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 03b970230..cfc10acd8 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 2cb96a3d5..afd5f864f 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 1dd4a370d..d7f382d7d 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 98b81258b..e72752d1d 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 d9f79c335..70a400e91 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 db4f87ac9..a0cf78254 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 005ee88de..cf33f1b8f 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 5d2feefcb..9d68d49ba 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 07fec1259..3b6c29670 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 972849d1b..94c789211 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 d665c2c82..03c801119 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 75d718724..9a9305558 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) } /// @@ -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 97576fe0c..898722472 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() } /// From cf1f28223758dde960702f8abdc06679bb393a25 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Mon, 13 Nov 2023 14:45:02 +0100 Subject: [PATCH 2/4] Use uninit `Vec`s with late `set_len()` call instead of zero-initialization --- ash/src/extensions/amdx/shader_enqueue.rs | 6 ++++-- ash/src/extensions/ext/calibrated_timestamps.rs | 9 +++++---- ash/src/extensions/khr/ray_tracing_pipeline.rs | 6 ++++-- ash/src/extensions/nv/ray_tracing.rs | 6 ++++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ash/src/extensions/amdx/shader_enqueue.rs b/ash/src/extensions/amdx/shader_enqueue.rs index c775f848d..132b0d865 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,9 @@ impl ShaderEnqueue { allocation_callbacks.as_raw_ptr(), pipelines.as_mut_ptr(), ) - .result_with_success(pipelines) + .result()?; + pipelines.set_len(create_infos.len()); + Ok(pipelines) } /// diff --git a/ash/src/extensions/ext/calibrated_timestamps.rs b/ash/src/extensions/ext/calibrated_timestamps.rs index ff2ebc59f..b5880c13b 100644 --- a/ash/src/extensions/ext/calibrated_timestamps.rs +++ b/ash/src/extensions/ext/calibrated_timestamps.rs @@ -43,17 +43,18 @@ impl CalibratedTimestamps { device: vk::Device, info: &[vk::CalibratedTimestampInfoEXT<'_>], ) -> VkResult<(Vec, u64)> { - let mut timestamps = vec![0u64; info.len()]; + let mut timestamps = Vec::with_capacity(info.len()); let mut max_deviation = mem::MaybeUninit::uninit(); - (self.fp.get_calibrated_timestamps_ext)( + let max_deviation = (self.fp.get_calibrated_timestamps_ext)( device, info.len() as u32, info.as_ptr(), timestamps.as_mut_ptr(), max_deviation.as_mut_ptr(), ) - .assume_init_on_success(max_deviation) - .map(|max_deviation| (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/khr/ray_tracing_pipeline.rs b/ash/src/extensions/khr/ray_tracing_pipeline.rs index ed397cd7b..4d4a45e04 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,9 @@ impl RayTracingPipeline { allocation_callbacks.as_raw_ptr(), pipelines.as_mut_ptr(), ) - .result_with_success(pipelines) + .result()?; + pipelines.set_len(create_info.len()); + Ok(pipelines) } /// diff --git a/ash/src/extensions/nv/ray_tracing.rs b/ash/src/extensions/nv/ray_tracing.rs index 9a9305558..2cc5459e1 100755 --- a/ash/src/extensions/nv/ray_tracing.rs +++ b/ash/src/extensions/nv/ray_tracing.rs @@ -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,9 @@ impl RayTracing { allocation_callbacks.as_raw_ptr(), pipelines.as_mut_ptr(), ) - .result_with_success(pipelines) + .result()?; + pipelines.set_len(create_info.len()); + Ok(pipelines) } /// From 3ad7c0655bf23854efcae30f9529fef9221793ec Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Mon, 13 Nov 2023 14:46:32 +0100 Subject: [PATCH 3/4] Use `uninit()` instead of `-1` for file descriptors --- ash/src/extensions/khr/external_fence_fd.rs | 5 +++-- ash/src/extensions/khr/external_memory_fd.rs | 5 +++-- ash/src/extensions/khr/external_semaphore_fd.rs | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ash/src/extensions/khr/external_fence_fd.rs b/ash/src/extensions/khr/external_fence_fd.rs index ff703e973..4e387b428 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_memory_fd.rs b/ash/src/extensions/khr/external_memory_fd.rs index 7e280369b..9e260428c 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_semaphore_fd.rs b/ash/src/extensions/khr/external_semaphore_fd.rs index 5c8383f3f..09d8bbafa 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; From 0927ece7a11f26e4595c1a6ffd962f5f5354d7d9 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Sun, 19 Nov 2023 20:37:20 +0100 Subject: [PATCH 4/4] Introduce `set_vec_len_on_success()` helper for `Vec::with_capacity()` --- ash/src/device.rs | 9 ++------ ash/src/extensions/amdx/shader_enqueue.rs | 4 +--- ash/src/extensions/ext/shader_object.rs | 4 +--- ash/src/extensions/khr/display_swapchain.rs | 4 +--- .../extensions/khr/ray_tracing_pipeline.rs | 12 +++-------- ash/src/extensions/nv/ray_tracing.rs | 4 +--- ash/src/prelude.rs | 21 ++++++++++++++----- 7 files changed, 25 insertions(+), 33 deletions(-) diff --git a/ash/src/device.rs b/ash/src/device.rs index f9a3f58b1..6775b3894 100644 --- a/ash/src/device.rs +++ b/ash/src/device.rs @@ -1546,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) } /// @@ -2536,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) } /// diff --git a/ash/src/extensions/amdx/shader_enqueue.rs b/ash/src/extensions/amdx/shader_enqueue.rs index 132b0d865..d034a111c 100644 --- a/ash/src/extensions/amdx/shader_enqueue.rs +++ b/ash/src/extensions/amdx/shader_enqueue.rs @@ -38,9 +38,7 @@ impl ShaderEnqueue { allocation_callbacks.as_raw_ptr(), pipelines.as_mut_ptr(), ) - .result()?; - pipelines.set_len(create_infos.len()); - Ok(pipelines) + .set_vec_len_on_success(pipelines, create_infos.len()) } /// diff --git a/ash/src/extensions/ext/shader_object.rs b/ash/src/extensions/ext/shader_object.rs index 358ade481..baaad721a 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/khr/display_swapchain.rs b/ash/src/extensions/khr/display_swapchain.rs index cdc89c030..ff7cac4ac 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/ray_tracing_pipeline.rs b/ash/src/extensions/khr/ray_tracing_pipeline.rs index 4d4a45e04..e29cde482 100644 --- a/ash/src/extensions/khr/ray_tracing_pipeline.rs +++ b/ash/src/extensions/khr/ray_tracing_pipeline.rs @@ -64,9 +64,7 @@ impl RayTracingPipeline { allocation_callbacks.as_raw_ptr(), pipelines.as_mut_ptr(), ) - .result()?; - pipelines.set_len(create_info.len()); - Ok(pipelines) + .set_vec_len_on_success(pipelines, create_info.len()) } /// @@ -87,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) } /// @@ -112,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/nv/ray_tracing.rs b/ash/src/extensions/nv/ray_tracing.rs index 2cc5459e1..d09a70959 100755 --- a/ash/src/extensions/nv/ray_tracing.rs +++ b/ash/src/extensions/nv/ray_tracing.rs @@ -175,9 +175,7 @@ impl RayTracing { allocation_callbacks.as_raw_ptr(), pipelines.as_mut_ptr(), ) - .result()?; - pipelines.set_len(create_info.len()); - Ok(pipelines) + .set_vec_len_on_success(pipelines, create_info.len()) } /// diff --git a/ash/src/prelude.rs b/ash/src/prelude.rs index 8f79494c1..d73e53de0 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`"), + ); } } }