pub struct Allocator { /* private fields */ }
Expand description
Thread-safe device memory allocator
See top-level crate documentation for more detail and examples.
Implementations§
Source§impl Allocator
impl Allocator
Sourcepub fn builder(
device: Device,
physical_device: PhysicalDevice,
) -> AllocatorBuilder
pub fn builder( device: Device, physical_device: PhysicalDevice, ) -> AllocatorBuilder
Creates a builder for creating an Allocator.
Simple usage:
let allocator = Allocator::builder(device, physical_device).build();
Sourcepub fn find_memory_type_index(
&self,
memory_type_bits: u32,
reqs: &AllocatorMemoryRequirements,
) -> Result<u32, Error>
pub fn find_memory_type_index( &self, memory_type_bits: u32, reqs: &AllocatorMemoryRequirements, ) -> Result<u32, Error>
This algorithm tries to find a memory type that:
- Is allowed by memoryTypeBits.
- Contains all the flags from pMemoryRequirements->requiredFlags.
- Matches intended usage.
- Has as many flags from pMemoryRequirements->preferredFlags as possible.
Returns Error::FeatureNotPresent
if not found. Receiving such result
from this function or any other allocating function probably means that your
device doesn’t support any memory type with requested features for the specific
type of resource you want to use it for. Please check parameters of your
resource, like image layout (OPTIMAL versus LINEAR) or mip level count.
Sourcepub fn free(&self, mem_range: &MappedMemoryRange)
pub fn free(&self, mem_range: &MappedMemoryRange)
Frees memory previously allocated using allocate
or allocate_for_buffer
or allocate_for_image
.
Sourcepub fn allocate(
&self,
vulkan_reqs: &MemoryRequirements,
other_reqs: &AllocatorMemoryRequirements,
) -> Result<MappedMemoryRange, Error>
pub fn allocate( &self, vulkan_reqs: &MemoryRequirements, other_reqs: &AllocatorMemoryRequirements, ) -> Result<MappedMemoryRange, Error>
General purpose memory allocation.
Memory allocated with this function should be freed using free
.
It is recommended to use allocate_for_buffer
, allocate_for_image
,
create_buffer
, create_image
instead whenever possible.
Sourcepub fn allocate_for_image(
&self,
image: Image,
reqs: &AllocatorMemoryRequirements,
) -> Result<MappedMemoryRange, Error>
pub fn allocate_for_image( &self, image: Image, reqs: &AllocatorMemoryRequirements, ) -> Result<MappedMemoryRange, Error>
Memory allocated with this function should be freed using free
.
Sourcepub fn allocate_for_buffer(
&self,
buffer: Buffer,
reqs: &AllocatorMemoryRequirements,
) -> Result<MappedMemoryRange, Error>
pub fn allocate_for_buffer( &self, buffer: Buffer, reqs: &AllocatorMemoryRequirements, ) -> Result<MappedMemoryRange, Error>
Memory allocated with this function should be freed using free
.
Sourcepub fn create_buffer(
&self,
create_info: &BufferCreateInfo,
reqs: &AllocatorMemoryRequirements,
) -> Result<(Buffer, MappedMemoryRange), Error>
pub fn create_buffer( &self, create_info: &BufferCreateInfo, reqs: &AllocatorMemoryRequirements, ) -> Result<(Buffer, MappedMemoryRange), Error>
This function automatically:
- Creates a buffer.
- Allocates appropriate memory for it.
- Binds the buffer with the memory.
Make sure to call free_buffer
when finished with the returned buffer. Do not use free
.
Sourcepub fn free_buffer(&self, buffer: Buffer)
pub fn free_buffer(&self, buffer: Buffer)
Frees internal resources and memory for a buffer created by create_buffer
.
Sourcepub fn create_image(
&self,
create_info: &ImageCreateInfo,
reqs: &AllocatorMemoryRequirements,
) -> Result<(Image, MappedMemoryRange), Error>
pub fn create_image( &self, create_info: &ImageCreateInfo, reqs: &AllocatorMemoryRequirements, ) -> Result<(Image, MappedMemoryRange), Error>
This function automatically:
- Creates an image.
- Allocates appropriate memory for it.
- Binds the image with the memory.
Make sure to call free_image
when finished with the returned image. Do not use free
.
Sourcepub fn free_image(&self, image: Image)
pub fn free_image(&self, image: Image)
Frees internal resources and memory for an image created by create_image
.
Sourcepub fn map_memory(range: &MappedMemoryRange) -> Result<MappedMemory, Error>
pub fn map_memory(range: &MappedMemoryRange) -> Result<MappedMemory, Error>
Feel free to use DeviceMemory::map
on your own if you want, but
just for convenience and to make sure correct offset and size is always
specified, usage of map_memory
is recommended.