Struct vulkan_malloc::Allocator
[−]
[src]
pub struct Allocator { /* fields omitted */ }
Thread-safe device memory allocator
See top-level crate documentation for more detail and examples.
Methods
impl Allocator
[src]
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();
fn find_memory_type_index(
&self,
memory_type_bits: u32,
reqs: &AllocatorMemoryRequirements
) -> Result<u32, Error>
&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.
fn free(&self, mem_range: &MappedMemoryRange)
Frees memory previously allocated using allocate
or allocate_for_buffer
or allocate_for_image
.
fn allocate(
&self,
vulkan_reqs: &MemoryRequirements,
other_reqs: &AllocatorMemoryRequirements
) -> Result<MappedMemoryRange, Error>
&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.
fn allocate_for_image(
&self,
image: Image,
reqs: &AllocatorMemoryRequirements
) -> Result<MappedMemoryRange, Error>
&self,
image: Image,
reqs: &AllocatorMemoryRequirements
) -> Result<MappedMemoryRange, Error>
Memory allocated with this function should be freed using free
.
fn allocate_for_buffer(
&self,
buffer: Buffer,
reqs: &AllocatorMemoryRequirements
) -> Result<MappedMemoryRange, Error>
&self,
buffer: Buffer,
reqs: &AllocatorMemoryRequirements
) -> Result<MappedMemoryRange, Error>
Memory allocated with this function should be freed using free
.
fn create_buffer(
&self,
create_info: &BufferCreateInfo,
reqs: &AllocatorMemoryRequirements
) -> Result<(Buffer, MappedMemoryRange), Error>
&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
.
fn free_buffer(&self, buffer: Buffer)
Frees internal resources and memory for a buffer created by create_buffer
.
fn create_image(
&self,
create_info: &ImageCreateInfo,
reqs: &AllocatorMemoryRequirements
) -> Result<(Image, MappedMemoryRange), Error>
&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
.
fn free_image(&self, image: Image)
Frees internal resources and memory for an image created by create_image
.
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.