From a187fc04ee5d007ad1acfed390de5da7959be330 Mon Sep 17 00:00:00 2001 From: hsteinmueller Date: Sat, 1 Oct 2022 15:38:24 +0200 Subject: [PATCH 1/2] #1935 add from_handle to DeviceMemory --- vulkano/src/memory/device_memory.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/vulkano/src/memory/device_memory.rs b/vulkano/src/memory/device_memory.rs index ad5839d033..e0fd8166a3 100644 --- a/vulkano/src/memory/device_memory.rs +++ b/vulkano/src/memory/device_memory.rs @@ -75,6 +75,18 @@ impl DeviceMemory { Self::validate(&device, &mut allocate_info, None)?; let handle = unsafe { Self::create(&device, &allocate_info, None)? }; + unsafe { Ok(DeviceMemory::from_handle(handle, allocate_info, device)) } + } + + /// Creates a new `DeviceMemory` from an ash-handle + /// # Safety + /// The `handle` has to be a valid vulkan object handle and + /// the `allocate_info` must match the info used to create said object + pub unsafe fn from_handle( + handle: ash::vk::DeviceMemory, + allocate_info: MemoryAllocateInfo<'_>, + device: Arc, + ) -> DeviceMemory { let MemoryAllocateInfo { allocation_size, memory_type_index, @@ -83,14 +95,14 @@ impl DeviceMemory { _ne: _, } = allocate_info; - Ok(DeviceMemory { + DeviceMemory { handle, device, allocation_size, memory_type_index, export_handle_types, - }) + } } /// Imports a block of memory from an external source. From 280cd888b639076fc91e3698d01479610cf4c340 Mon Sep 17 00:00:00 2001 From: hsteinmueller Date: Sun, 2 Oct 2022 15:10:37 +0200 Subject: [PATCH 2/2] change parameter order and fix documentation --- vulkano/src/memory/device_memory.rs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/vulkano/src/memory/device_memory.rs b/vulkano/src/memory/device_memory.rs index e0fd8166a3..f9b30804ff 100644 --- a/vulkano/src/memory/device_memory.rs +++ b/vulkano/src/memory/device_memory.rs @@ -75,17 +75,34 @@ impl DeviceMemory { Self::validate(&device, &mut allocate_info, None)?; let handle = unsafe { Self::create(&device, &allocate_info, None)? }; - unsafe { Ok(DeviceMemory::from_handle(handle, allocate_info, device)) } + let MemoryAllocateInfo { + allocation_size, + memory_type_index, + dedicated_allocation: _, + export_handle_types, + _ne: _, + } = allocate_info; + + Ok(DeviceMemory { + handle, + device, + + allocation_size, + memory_type_index, + export_handle_types, + }) } - /// Creates a new `DeviceMemory` from an ash-handle + /// Creates a new `DeviceMemory` from a raw object handle. + /// /// # Safety - /// The `handle` has to be a valid vulkan object handle and - /// the `allocate_info` must match the info used to create said object + /// + /// - `handle` must be a valid Vulkan object handle created from `device`. + /// - `allocate_info` must match the info used to create the object. pub unsafe fn from_handle( + device: Arc, handle: ash::vk::DeviceMemory, allocate_info: MemoryAllocateInfo<'_>, - device: Arc, ) -> DeviceMemory { let MemoryAllocateInfo { allocation_size,