Trait gpu_alloc::MemoryDevice

source ·
pub trait MemoryDevice<M> {
    // Required methods
    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§

source

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. Retrieving this information is implementation specific.

flags must be supported by the device.

source

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.

source

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.
source

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
source

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 and size in each element of ranges must specify subregion of currently mapped memory region
  • if memory in some element of ranges does not contain HOST_COHERENT property then offset and size of that element must be multiple of non_coherent_atom_size.
source

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 and size in each element of ranges must specify subregion of currently mapped memory region
  • if memory in some element of ranges does not contain HOST_COHERENT property then offset and size of that element must be multiple of non_coherent_atom_size.

Implementors§