Trait gpu_alloc::MemoryDevice [−][src]
pub trait MemoryDevice<M> {
unsafe fn allocate_memory(
&self,
size: u64,
memory_type: u32,
flags: AllocationFlags
) -> Result<M, OutOfMemory>;
unsafe fn deallocate_memory(&self, memory: M);
unsafe fn map_memory(
&self,
memory: &mut M,
offset: u64,
size: u64
) -> Result<NonNull<u8>, DeviceMapError>;
unsafe fn unmap_memory(&self, memory: &mut M);
unsafe fn invalidate_memory_ranges(
&self,
ranges: &[MappedMemoryRange<'_, M>]
) -> Result<(), OutOfMemory>;
unsafe fn flush_memory_ranges(
&self,
ranges: &[MappedMemoryRange<'_, M>]
) -> Result<(), OutOfMemory>;
}
Expand description
Abstract device that can be used to allocate memory objects.
Required methods
unsafe fn allocate_memory(
&self,
size: u64,
memory_type: u32,
flags: AllocationFlags
) -> Result<M, OutOfMemory>
unsafe fn allocate_memory(
&self,
size: u64,
memory_type: u32,
flags: AllocationFlags
) -> Result<M, OutOfMemory>
Allocates new memory object from device. This function may be expensive and even limit maximum number of memory objects allocated. Which is the reason for sub-allocation this crate provides.
Safety
memory_type
must be valid index for memory type associated with this device.
Retreiving this information is implementation specific.
flags
must be supported by the device.
unsafe fn deallocate_memory(&self, memory: M)
unsafe fn deallocate_memory(&self, memory: M)
Deallocate memory object.
Safety
Memory object must have been allocated from this device.
All clones of specified memory handle must be dropped before calling this function.
unsafe fn map_memory(
&self,
memory: &mut M,
offset: u64,
size: u64
) -> Result<NonNull<u8>, DeviceMapError>
unsafe fn map_memory(
&self,
memory: &mut M,
offset: u64,
size: u64
) -> Result<NonNull<u8>, DeviceMapError>
Map region of device memory to host memory space.
Safety
- Memory object must have been allocated from this device.
- Memory object must not be already mapped.
- Memory must be allocated from type with
HOST_VISIBLE
property. offset + size
must not overflow.offset + size
must not be larger than memory object size specified when memory object was allocated from this device.
unsafe fn unmap_memory(&self, memory: &mut M)
unsafe fn unmap_memory(&self, memory: &mut M)
Unmap previously mapped memory region.
Safety
- Memory object must have been allocated from this device.
- Memory object must be mapped
unsafe fn invalidate_memory_ranges(
&self,
ranges: &[MappedMemoryRange<'_, M>]
) -> Result<(), OutOfMemory>
unsafe fn invalidate_memory_ranges(
&self,
ranges: &[MappedMemoryRange<'_, M>]
) -> Result<(), OutOfMemory>
Invalidates ranges of memory mapped regions.
Safety
- Memory objects must have been allocated from this device.
offset
andsize
in each element ofranges
must specify subregion of currently mapped memory region- if
memory
in some element ofranges
does not containHOST_COHERENT
property thenoffset
andsize
of that element must be multiple ofnon_coherent_atom_size
.
unsafe fn flush_memory_ranges(
&self,
ranges: &[MappedMemoryRange<'_, M>]
) -> Result<(), OutOfMemory>
unsafe fn flush_memory_ranges(
&self,
ranges: &[MappedMemoryRange<'_, M>]
) -> Result<(), OutOfMemory>
Flushes ranges of memory mapped regions.
Safety
- Memory objects must have been allocated from this device.
offset
andsize
in each element ofranges
must specify subregion of currently mapped memory region- if
memory
in some element ofranges
does not containHOST_COHERENT
property thenoffset
andsize
of that element must be multiple ofnon_coherent_atom_size
.