Trait vulkano::memory::allocator::MemoryAllocator
source · 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§
sourcefn find_memory_type_index(
&self,
memory_type_bits: u32,
filter: MemoryTypeFilter
) -> Option<u32>
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.
sourcefn allocate_from_type(
&self,
memory_type_index: u32,
create_info: SuballocationCreateInfo
) -> Result<MemoryAlloc, AllocationCreationError>
fn allocate_from_type( &self, memory_type_index: u32, create_info: SuballocationCreateInfo ) -> Result<MemoryAlloc, AllocationCreationError>
Allocates memory from a specific memory type.
sourcefn allocate(
&self,
requirements: MemoryRequirements,
allocation_type: AllocationType,
create_info: AllocationCreateInfo,
dedicated_allocation: Option<DedicatedAllocation<'_>>
) -> Result<MemoryAlloc, AllocationCreationError>
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
orRawImage::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 alignmentDeviceAlignment::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, andNonLinear
for optimal images. You can not bind memory allocated with theLinear
type to optimal images or bind memory allocated with theNonLinear
type to buffers and linear images. You should never use theUnknown
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 thekhr_dedicated_allocation
extension is not enabled on the device.