pub unsafe trait MemoryAllocator: DeviceOwned {
    // Required methods
    fn find_memory_type_index(
        &self,
        memory_type_bits: u32,
        filter: MemoryTypeFilter
    ) -> Option<u32>;
    fn allocate_from_type(
        &self,
        memory_type_index: u32,
        create_info: SuballocationCreateInfo
    ) -> Result<MemoryAlloc, AllocationCreationError>;
    fn allocate(
        &self,
        requirements: MemoryRequirements,
        allocation_type: AllocationType,
        create_info: AllocationCreateInfo,
        dedicated_allocation: Option<DedicatedAllocation<'_>>
    ) -> Result<MemoryAlloc, AllocationCreationError>;
}
Expand description

General-purpose memory allocators which allocate from any memory type dynamically as needed.

Required Methods§

source

fn find_memory_type_index( &self, memory_type_bits: u32, filter: MemoryTypeFilter ) -> Option<u32>

Finds the most suitable memory type index in memory_type_bits using a filter. Returns None if the requirements are too strict and no memory type is able to satisfy them.

source

fn allocate_from_type( &self, memory_type_index: u32, create_info: SuballocationCreateInfo ) -> Result<MemoryAlloc, AllocationCreationError>

Allocates memory from a specific memory type.

source

fn allocate( &self, requirements: MemoryRequirements, allocation_type: AllocationType, create_info: AllocationCreateInfo, dedicated_allocation: Option<DedicatedAllocation<'_>> ) -> Result<MemoryAlloc, AllocationCreationError>

Allocates memory according to requirements.

Arguments
  • requirements - Requirements of the resource you want to allocate memory for.

    If you plan to bind this memory directly to a non-sparse resource, then this must correspond to the value returned by either RawBuffer::memory_requirements or RawImage::memory_requirements for the respective buffer or image.

    memory_type_bits must be below 2n where n is the number of available memory types.

    The default is a layout with size DeviceLayout::MAX_SIZE and alignment DeviceAlignment::MIN and the rest all zeroes, which must be overridden.

  • allocation_type - What type of resource this allocation will be used for.

    This should be Linear for buffers and linear images, and NonLinear for optimal images. You can not bind memory allocated with the Linear type to optimal images or bind memory allocated with the NonLinear type to buffers and linear images. You should never use the Unknown type unless you have to, as that can be less memory efficient.

  • dedicated_allocation - Allows a dedicated allocation to be created.

    You should always fill this field in if you are allocating memory for a non-sparse resource, otherwise the allocator won’t be able to create a dedicated allocation if one is recommended.

    This option is silently ignored (treated as None) if the device API version is below 1.1 and the khr_dedicated_allocation extension is not enabled on the device.

Implementations on Foreign Types§

source§

impl<S: Suballocator> MemoryAllocator for Arc<GenericMemoryAllocator<S>>

source§

fn find_memory_type_index( &self, memory_type_bits: u32, filter: MemoryTypeFilter ) -> Option<u32>

source§

fn allocate_from_type( &self, memory_type_index: u32, create_info: SuballocationCreateInfo ) -> Result<MemoryAlloc, AllocationCreationError>

source§

fn allocate( &self, requirements: MemoryRequirements, allocation_type: AllocationType, create_info: AllocationCreateInfo, dedicated_allocation: Option<DedicatedAllocation<'_>> ) -> Result<MemoryAlloc, AllocationCreationError>

Implementors§