Convert mem::zeroed() / 0 to MaybeUninit::uninit() (#798)

* 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).

* Use uninit `Vec`s with late `set_len()` call instead of zero-initialization

* Use `uninit()` instead of `-1` for file descriptors

* Introduce `set_vec_len_on_success()` helper for `Vec::with_capacity()`
This commit is contained in:
Marijn Suijten 2023-12-01 22:25:45 +01:00 committed by GitHub
parent 02c7a83592
commit 4e99de1cbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 380 additions and 348 deletions

View file

@ -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,

View file

@ -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];

View file

@ -70,14 +70,14 @@ impl Device {
create_info: &vk::PrivateDataSlotCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::PrivateDataSlot> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDestroyPrivateDataSlot.html>
@ -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()
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdPipelineBarrier2.html>
@ -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
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetDeviceImageSparseMemoryRequirements.html>
@ -606,14 +606,14 @@ impl Device {
create_info: &vk::RenderPassCreateInfo2<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::RenderPass> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdBeginRenderPass2.html>
@ -670,9 +670,13 @@ impl Device {
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetSemaphoreCounterValue.html>
#[inline]
pub unsafe fn get_semaphore_counter_value(&self, semaphore: vk::Semaphore) -> VkResult<u64> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkWaitSemaphores.html>
@ -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()
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdSetDeviceMask.html>
@ -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
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetImageSparseMemoryRequirements2.html>
@ -874,9 +878,9 @@ impl Device {
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetDeviceQueue2.html>
#[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()
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCreateSamplerYcbcrConversion.html>
@ -886,14 +890,14 @@ impl Device {
create_info: &vk::SamplerYcbcrConversionCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::SamplerYcbcrConversion> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDestroySamplerYcbcrConversion.html>
@ -917,14 +921,14 @@ impl Device {
create_info: &vk::DescriptorUpdateTemplateCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::DescriptorUpdateTemplate> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDestroyDescriptorUpdateTemplate.html>
@ -1030,14 +1034,14 @@ impl Device {
create_info: &vk::EventCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::Event> {
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<vk::Sampler> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdBlitImage.html>
@ -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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCreateDescriptorSetLayout.html>
@ -1555,14 +1556,14 @@ impl Device {
create_info: &vk::DescriptorSetLayoutCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::DescriptorSetLayout> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDeviceWaitIdle.html>
@ -1578,14 +1579,14 @@ impl Device {
create_info: &vk::DescriptorPoolCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::DescriptorPool> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkResetDescriptorPool.html>
@ -2123,14 +2124,14 @@ impl Device {
create_info: &vk::SemaphoreCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::Semaphore> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCreateGraphicsPipelines.html>
@ -2188,14 +2189,14 @@ impl Device {
create_info: &vk::BufferCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::Buffer> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCreatePipelineLayout.html>
@ -2205,14 +2206,14 @@ impl Device {
create_info: &vk::PipelineLayoutCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::PipelineLayout> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCreatePipelineCache.html>
@ -2222,14 +2223,14 @@ impl Device {
create_info: &vk::PipelineCacheCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::PipelineCache> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPipelineCacheData.html>
@ -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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkUnmapMemory.html>
@ -2319,27 +2327,27 @@ impl Device {
create_info: &vk::FramebufferCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::Framebuffer> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetDeviceQueue.html>
#[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()
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdPipelineBarrier.html>
@ -2375,14 +2383,14 @@ impl Device {
create_info: &vk::RenderPassCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::RenderPass> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkBeginCommandBuffer.html>
@ -2472,14 +2480,14 @@ impl Device {
create_info: &vk::BufferViewCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::BufferView> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDestroyBufferView.html>
@ -2503,14 +2511,14 @@ impl Device {
create_info: &vk::ImageViewCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::ImageView> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkAllocateCommandBuffers.html>
@ -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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCreateCommandPool.html>
@ -2537,14 +2543,14 @@ impl Device {
create_info: &vk::CommandPoolCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::CommandPool> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCreateQueryPool.html>
@ -2554,14 +2560,14 @@ impl Device {
create_info: &vk::QueryPoolCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::QueryPool> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCreateImage.html>
@ -2571,14 +2577,14 @@ impl Device {
create_info: &vk::ImageCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::Image> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetImageSubresourceLayout.html>
@ -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()
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetImageMemoryRequirements.html>
#[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()
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetBufferMemoryRequirements.html>
@ -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()
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkAllocateMemory.html>
@ -2624,14 +2638,14 @@ impl Device {
allocate_info: &vk::MemoryAllocateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::DeviceMemory> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCreateShaderModule.html>
@ -2641,14 +2655,14 @@ impl Device {
create_info: &vk::ShaderModuleCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::ShaderModule> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCreateFence.html>
@ -2658,14 +2672,14 @@ impl Device {
create_info: &vk::FenceCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::Fence> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkBindBufferMemory.html>
@ -2694,25 +2708,25 @@ impl Device {
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetRenderAreaGranularity.html>
#[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()
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetDeviceMemoryCommitment.html>
#[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()
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetImageSparseMemoryRequirements.html>

View file

@ -219,7 +219,6 @@ impl Entry {
/// ```
#[inline]
pub unsafe fn try_enumerate_instance_version(&self) -> VkResult<Option<u32>> {
let mut api_version = 0;
let enumerate_instance_version: Option<vk::PFN_vkEnumerateInstanceVersion> = {
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<Instance> {
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<u32> {
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)
}
}

View file

@ -29,7 +29,7 @@ impl ShaderEnqueue {
create_infos: &[vk::ExecutionGraphPipelineCreateInfoAMDX<'_>],
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<Vec<vk::Pipeline>> {
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())
}
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetExecutionGraphPipelineScratchSizeAMDX.html>
@ -63,14 +63,14 @@ impl ShaderEnqueue {
execution_graph: vk::Pipeline,
node_info: &vk::PipelineShaderStageNodeCreateInfoAMDX<'_>,
) -> VkResult<u32> {
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)
}
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdInitializeGraphScratchMemoryAMDX.html>

View file

@ -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;

View file

@ -43,16 +43,18 @@ impl CalibratedTimestamps {
device: vk::Device,
info: &[vk::CalibratedTimestampInfoEXT<'_>],
) -> VkResult<(Vec<u64>, 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;

View file

@ -41,14 +41,14 @@ impl DebugReport {
create_info: &vk::DebugReportCallbackCreateInfoEXT<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::DebugReportCallbackEXT> {
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;

View file

@ -98,14 +98,14 @@ impl DebugUtils {
create_info: &vk::DebugUtilsMessengerCreateInfoEXT<'_>,
allocator: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::DebugUtilsMessengerEXT> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDestroyDebugUtilsMessengerEXT.html>

View file

@ -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()
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetDescriptorSetLayoutBindingOffsetEXT.html>
@ -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()
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetDescriptorEXT.html>

View file

@ -60,13 +60,13 @@ impl FullScreenExclusive {
&self,
surface_info: &vk::PhysicalDeviceSurfaceInfo2KHR<'_>,
) -> VkResult<vk::DeviceGroupPresentModeFlagsKHR> {
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;

View file

@ -28,14 +28,14 @@ impl HeadlessSurface {
create_info: &vk::HeadlessSurfaceCreateInfoEXT<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::SurfaceKHR> {
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;

View file

@ -27,14 +27,14 @@ impl MetalSurface {
create_info: &vk::MetalSurfaceCreateInfoEXT<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::SurfaceKHR> {
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;

View file

@ -28,14 +28,14 @@ impl PrivateData {
create_info: &vk::PrivateDataSlotCreateInfoEXT<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::PrivateDataSlotEXT> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDestroyPrivateDataSlotEXT.html>
@ -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;

View file

@ -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())
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDestroyShaderEXT.html>

View file

@ -37,9 +37,9 @@ impl DisplayTiming {
&self,
swapchain: vk::SwapchainKHR,
) -> VkResult<vk::RefreshCycleDurationGOOGLE> {
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;

View file

@ -28,14 +28,14 @@ impl AccelerationStructure {
create_info: &vk::AccelerationStructureCreateInfoKHR<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::AccelerationStructureKHR> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDestroyAccelerationStructureKHR.html>
@ -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()
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetAccelerationStructureBuildSizesKHR.html>

View file

@ -27,14 +27,14 @@ impl AndroidSurface {
create_info: &vk::AndroidSurfaceCreateInfoKHR<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::SurfaceKHR> {
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;

View file

@ -27,14 +27,14 @@ impl CreateRenderPass2 {
create_info: &vk::RenderPassCreateInfo2<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::RenderPass> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdBeginRenderPass2.html>

View file

@ -26,13 +26,13 @@ impl DeferredHostOperations {
&self,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::DeferredOperationKHR> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDeferredOperationJoinKHR.html>

View file

@ -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()
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdSetDeviceMaskKHR.html>
@ -99,9 +99,13 @@ impl DeviceGroup {
&self,
surface: vk::SurfaceKHR,
) -> VkResult<vk::DeviceGroupPresentModeFlagsKHR> {
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),
}
}

View file

@ -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<usize> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkEnumeratePhysicalDeviceGroupsKHR.html>

View file

@ -80,7 +80,7 @@ impl Display {
create_info: &vk::DisplayModeCreateInfoKHR<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::DisplayModeKHR> {
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<vk::DisplayPlaneCapabilitiesKHR> {
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<vk::SurfaceKHR> {
let mut surface = mem::MaybeUninit::zeroed();
let mut surface = mem::MaybeUninit::uninit();
(self.fp.create_display_plane_surface_khr)(
self.handle,
create_info,

View file

@ -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;

View file

@ -31,8 +31,9 @@ impl ExternalFenceFd {
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetFenceFdKHR.html>
#[inline]
pub unsafe fn get_fence_fd(&self, get_info: &vk::FenceGetFdInfoKHR<'_>) -> VkResult<i32> {
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;

View file

@ -3,7 +3,6 @@ use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
use std::mem::MaybeUninit;
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_fence_win32.html>
#[derive(Clone)]
@ -36,7 +35,7 @@ impl ExternalFenceWin32 {
&self,
get_info: &vk::FenceGetWin32HandleInfoKHR<'_>,
) -> VkResult<vk::HANDLE> {
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)
}

View file

@ -23,8 +23,9 @@ impl ExternalMemoryFd {
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetMemoryFdKHR.html>
#[inline]
pub unsafe fn get_memory_fd(&self, get_fd_info: &vk::MemoryGetFdInfoKHR<'_>) -> VkResult<i32> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetMemoryFdPropertiesKHR.html>

View file

@ -3,7 +3,6 @@ use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
use std::mem::MaybeUninit;
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_memory_win32.html>
#[derive(Clone)]
@ -27,7 +26,7 @@ impl ExternalMemoryWin32 {
&self,
create_info: &vk::MemoryGetWin32HandleInfoKHR<'_>,
) -> VkResult<vk::HANDLE> {
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)
}

View file

@ -34,8 +34,9 @@ impl ExternalSemaphoreFd {
&self,
get_info: &vk::SemaphoreGetFdInfoKHR<'_>,
) -> VkResult<i32> {
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;

View file

@ -3,7 +3,6 @@ use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
use std::mem::MaybeUninit;
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_semaphore_win32.html>
#[derive(Clone)]
@ -36,7 +35,7 @@ impl ExternalSemaphoreWin32 {
&self,
get_info: &vk::SemaphoreGetWin32HandleInfoKHR<'_>,
) -> VkResult<vk::HANDLE> {
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)
}

View file

@ -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
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetImageSparseMemoryRequirements2KHR.html>

View file

@ -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
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceQueueFamilyProperties2KHR.html>
@ -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
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceSparseImageFormatProperties2KHR.html>

View file

@ -41,14 +41,14 @@ impl GetSurfaceCapabilities2 {
physical_device: vk::PhysicalDevice,
surface_info: &vk::PhysicalDeviceSurfaceInfo2KHR<'_>,
) -> VkResult<usize> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceSurfaceFormats2KHR.html>

View file

@ -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
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetDeviceImageSparseMemoryRequirementsKHR.html>

View file

@ -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()
}
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetDeviceImageSubresourceLayoutKHR.html>

View file

@ -28,17 +28,18 @@ impl PerformanceQuery {
physical_device: vk::PhysicalDevice,
queue_family_index: u32,
) -> VkResult<usize> {
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)
}
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR.html>
@ -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()
}
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkAcquireProfilingLockKHR.html>

View file

@ -54,7 +54,7 @@ impl RayTracingPipeline {
create_info: &[vk::RayTracingPipelineCreateInfoKHR<'_>],
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<Vec<vk::Pipeline>> {
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())
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetRayTracingShaderGroupHandlesKHR.html>
@ -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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetRayTracingCaptureReplayShaderGroupHandlesKHR.html>
@ -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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdTraceRaysIndirectKHR.html>

View file

@ -28,14 +28,14 @@ impl SamplerYcbcrConversion {
create_info: &vk::SamplerYcbcrConversionCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::SamplerYcbcrConversion> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDestroySamplerYcbcrConversion.html>

View file

@ -28,14 +28,15 @@ impl Surface {
queue_family_index: u32,
surface: vk::SurfaceKHR,
) -> VkResult<bool> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceSurfacePresentModesKHR.html>
@ -62,13 +63,13 @@ impl Surface {
physical_device: vk::PhysicalDevice,
surface: vk::SurfaceKHR,
) -> VkResult<vk::SurfaceCapabilitiesKHR> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceSurfaceFormatsKHR.html>

View file

@ -29,14 +29,14 @@ impl Swapchain {
create_info: &vk::SwapchainCreateInfoKHR<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::SwapchainKHR> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDestroySwapchainKHR.html>
@ -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<vk::DeviceGroupPresentModeFlagsKHR> {
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),
}
}

View file

@ -22,9 +22,9 @@ impl TimelineSemaphore {
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetSemaphoreCounterValue.html>
#[inline]
pub unsafe fn get_semaphore_counter_value(&self, semaphore: vk::Semaphore) -> VkResult<u64> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkWaitSemaphores.html>

View file

@ -27,14 +27,14 @@ impl WaylandSurface {
create_info: &vk::WaylandSurfaceCreateInfoKHR<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::SurfaceKHR> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceWaylandPresentationSupportKHR.html>

View file

@ -27,14 +27,14 @@ impl Win32Surface {
create_info: &vk::Win32SurfaceCreateInfoKHR<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::SurfaceKHR> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceWin32PresentationSupportKHR.html>

View file

@ -27,14 +27,14 @@ impl XcbSurface {
create_info: &vk::XcbSurfaceCreateInfoKHR<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::SurfaceKHR> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceXcbPresentationSupportKHR.html>

View file

@ -27,14 +27,14 @@ impl XlibSurface {
create_info: &vk::XlibSurfaceCreateInfoKHR<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::SurfaceKHR> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceXlibPresentationSupportKHR.html>

View file

@ -27,14 +27,14 @@ impl IOSSurface {
create_info: &vk::IOSSurfaceCreateInfoMVK<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::SurfaceKHR> {
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;

View file

@ -27,14 +27,14 @@ impl MacOSSurface {
create_info: &vk::MacOSSurfaceCreateInfoMVK<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::SurfaceKHR> {
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;

View file

@ -27,14 +27,14 @@ impl ViSurface {
create_info: &vk::ViSurfaceCreateInfoNN<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::SurfaceKHR> {
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;

View file

@ -24,15 +24,16 @@ impl CoverageReductionMode {
&self,
physical_device: vk::PhysicalDevice,
) -> VkResult<usize> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceSupportedFramebufferMixedSamplesCombinationsNV.html>

View file

@ -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
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetQueueCheckpointDataNV.html>

View file

@ -27,14 +27,14 @@ impl RayTracing {
create_info: &vk::AccelerationStructureCreateInfoNV<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::AccelerationStructureNV> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDestroyAccelerationStructureNV.html>
@ -166,7 +166,7 @@ impl RayTracing {
create_info: &[vk::RayTracingPipelineCreateInfoNV<'_>],
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<Vec<vk::Pipeline>> {
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())
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetRayTracingShaderGroupHandlesNV.html>
@ -204,15 +204,14 @@ impl RayTracing {
&self,
accel_struct: vk::AccelerationStructureNV,
) -> VkResult<u64> {
let mut handle: u64 = 0;
let handle_ptr: *mut u64 = &mut handle;
let mut handle = mem::MaybeUninit::<u64>::uninit();
(self.fp.get_acceleration_structure_handle_nv)(
self.handle,
accel_struct,
std::mem::size_of::<u64>(),
handle_ptr.cast(),
std::mem::size_of_val(&handle),
handle.as_mut_ptr().cast(),
)
.result_with_success(handle)
.assume_init_on_success(handle)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdWriteAccelerationStructuresPropertiesNV.html>

View file

@ -67,13 +67,14 @@ impl Instance {
&self,
physical_device: vk::PhysicalDevice,
) -> VkResult<usize> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceToolProperties.html>
@ -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<usize> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkEnumeratePhysicalDeviceGroups.html>
@ -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
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceQueueFamilyProperties2.html>
@ -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
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceSparseImageFormatProperties2.html>
@ -356,14 +358,14 @@ impl Instance {
create_info: &vk::DeviceCreateInfo<'_>,
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<Device> {
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()
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceImageFormatProperties.html>
@ -413,7 +415,7 @@ impl Instance {
usage: vk::ImageUsageFlags,
flags: vk::ImageCreateFlags,
) -> VkResult<vk::ImageFormatProperties> {
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)
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceMemoryProperties.html>
@ -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()
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceProperties.html>
@ -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()
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceQueueFamilyProperties.html>
@ -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()
}
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkEnumeratePhysicalDevices.html>

View file

@ -24,6 +24,14 @@ impl vk::Result {
pub unsafe fn assume_init_on_success<T>(self, v: mem::MaybeUninit<T>) -> VkResult<T> {
self.result().map(move |()| v.assume_init())
}
#[inline]
pub unsafe fn set_vec_len_on_success<T>(self, mut v: Vec<T>, len: usize) -> VkResult<Vec<T>> {
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`"),
);
}
}
}