Struct Allocator

Source
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

Source

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();
Source

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.

Source

pub fn free(&self, mem_range: &MappedMemoryRange)

Frees memory previously allocated using allocate or allocate_for_buffer or allocate_for_image.

Source

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.

Source

pub fn allocate_for_image( &self, image: Image, reqs: &AllocatorMemoryRequirements, ) -> Result<MappedMemoryRange, Error>

Memory allocated with this function should be freed using free.

Source

pub fn allocate_for_buffer( &self, buffer: Buffer, reqs: &AllocatorMemoryRequirements, ) -> Result<MappedMemoryRange, Error>

Memory allocated with this function should be freed using free.

Source

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.

Source

pub fn free_buffer(&self, buffer: Buffer)

Frees internal resources and memory for a buffer created by create_buffer.

Source

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.

Source

pub fn free_image(&self, image: Image)

Frees internal resources and memory for an image created by create_image.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.