From 75ef5218c45b48a2b85899ddb2084c2dc34cec63 Mon Sep 17 00:00:00 2001 From: Harald Steinmueller Date: Sun, 2 Oct 2022 15:19:53 +0200 Subject: [PATCH] #1935 add from_handle to DeviceMemory (#2011) * #1935 add from_handle to DeviceMemory * change parameter order and fix documentation --- vulkano/src/memory/device_memory.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/vulkano/src/memory/device_memory.rs b/vulkano/src/memory/device_memory.rs index ad5839d033..f9b30804ff 100644 --- a/vulkano/src/memory/device_memory.rs +++ b/vulkano/src/memory/device_memory.rs @@ -93,6 +93,35 @@ impl DeviceMemory { }) } + /// Creates a new `DeviceMemory` from a raw object handle. + /// + /// # Safety + /// + /// - `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<'_>, + ) -> DeviceMemory { + let MemoryAllocateInfo { + allocation_size, + memory_type_index, + dedicated_allocation: _, + export_handle_types, + _ne: _, + } = allocate_info; + + DeviceMemory { + handle, + device, + + allocation_size, + memory_type_index, + export_handle_types, + } + } + /// Imports a block of memory from an external source. /// /// # Safety