[][src]Trait gpu_alloc_types::MemoryDevice

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: &M,
        offset: u64,
        size: u64
    ) -> Result<NonNull<u8>, DeviceMapError>;
unsafe fn unmap_memory(&self, memory: &M);
unsafe fn invalidate_memory_ranges(
        &self,
        ranges: &[MappedMemoryRange<'_, M>]
    ) -> Result<(), OutOfMemory>;
unsafe fn flush_memory_ranges(
        &self,
        ranges: &[MappedMemoryRange<'_, M>]
    ) -> Result<(), OutOfMemory>; }

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>

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)

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: &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: &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>

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.

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.
Loading content...

Implementors

Loading content...