Struct vulkano::memory::DeviceMemory
source · pub struct DeviceMemory { /* private fields */ }
Expand description
Represents memory that has been allocated from the device.
The destructor of DeviceMemory
automatically frees the memory.
Examples
use vulkano::memory::{DeviceMemory, MemoryAllocateInfo};
let memory_type_index = 0;
// Allocates 1KB of memory.
let memory = DeviceMemory::allocate(
device.clone(),
MemoryAllocateInfo {
allocation_size: 1024,
memory_type_index,
..Default::default()
},
)
.unwrap();
Implementations
sourceimpl DeviceMemory
impl DeviceMemory
sourcepub fn allocate(
device: Arc<Device>,
allocate_info: MemoryAllocateInfo<'_>
) -> Result<Self, DeviceMemoryError>
pub fn allocate(
device: Arc<Device>,
allocate_info: MemoryAllocateInfo<'_>
) -> Result<Self, DeviceMemoryError>
Allocates a block of memory from the device.
Some platforms may have a limit on the maximum size of a single allocation. For example, certain systems may fail to create allocations with a size greater than or equal to 4GB.
Panics
- Panics if
allocate_info.allocation_size
is 0. - Panics if
allocate_info.dedicated_allocation
isSome
and the contained buffer or image does not belong todevice
.
sourcepub unsafe fn from_handle(
device: Arc<Device>,
handle: DeviceMemory,
allocate_info: MemoryAllocateInfo<'_>
) -> Self
pub unsafe fn from_handle(
device: Arc<Device>,
handle: DeviceMemory,
allocate_info: MemoryAllocateInfo<'_>
) -> Self
Creates a new DeviceMemory
from a raw object handle.
Safety
handle
must be a valid Vulkan object handle created fromdevice
.allocate_info
must match the info used to create the object.
sourcepub unsafe fn import(
device: Arc<Device>,
allocate_info: MemoryAllocateInfo<'_>,
import_info: MemoryImportInfo
) -> Result<Self, DeviceMemoryError>
pub unsafe fn import(
device: Arc<Device>,
allocate_info: MemoryAllocateInfo<'_>,
import_info: MemoryImportInfo
) -> Result<Self, DeviceMemoryError>
Imports a block of memory from an external source.
Safety
- See the documentation of the variants of
MemoryImportInfo
.
Panics
- Panics if
allocate_info.allocation_size
is 0. - Panics if
allocate_info.dedicated_allocation
isSome
and the contained buffer or image does not belong todevice
.
sourcepub fn memory_type_index(&self) -> u32
pub fn memory_type_index(&self) -> u32
Returns the index of the memory type that this memory was allocated from.
sourcepub fn allocation_size(&self) -> DeviceSize
pub fn allocation_size(&self) -> DeviceSize
Returns the size in bytes of the memory allocation.
sourcepub fn is_dedicated(&self) -> bool
pub fn is_dedicated(&self) -> bool
Returns true
if the memory is a dedicated to a resource.
sourcepub fn export_handle_types(&self) -> ExternalMemoryHandleTypes
pub fn export_handle_types(&self) -> ExternalMemoryHandleTypes
Returns the handle types that can be exported from the memory allocation.
sourcepub fn imported_handle_type(&self) -> Option<ExternalMemoryHandleType>
pub fn imported_handle_type(&self) -> Option<ExternalMemoryHandleType>
Returns the handle type that the memory allocation was imported from, if any.
sourcepub fn flags(&self) -> MemoryAllocateFlags
pub fn flags(&self) -> MemoryAllocateFlags
Returns the flags the memory was allocated with.
sourcepub fn commitment(&self) -> Result<DeviceSize, DeviceMemoryError>
pub fn commitment(&self) -> Result<DeviceSize, DeviceMemoryError>
Retrieves the amount of lazily-allocated memory that is currently commited to this memory object.
The device may change this value at any time, and the returned value may be already out-of-date.
self
must have been allocated from a memory type that has the
lazily_allocated
flag set.
sourcepub fn export_fd(
&self,
handle_type: ExternalMemoryHandleType
) -> Result<File, DeviceMemoryError>
pub fn export_fd(
&self,
handle_type: ExternalMemoryHandleType
) -> Result<File, DeviceMemoryError>
Exports the device memory into a Unix file descriptor. The caller owns the returned File
.
Panics
- Panics if the user requests an invalid handle type for this device memory object.