Skip to content

Commit

Permalink
vulkano-rs#1935 add from_handle to DeviceMemory
Browse files Browse the repository at this point in the history
  • Loading branch information
hsteinmueller committed Oct 1, 2022
1 parent 3a83767 commit a187fc0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions vulkano/src/memory/device_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Device>,
) -> DeviceMemory {
let MemoryAllocateInfo {
allocation_size,
memory_type_index,
Expand All @@ -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.
Expand Down

0 comments on commit a187fc0

Please sign in to comment.