pub struct MemoryAllocator { /* private fields */ }
Expand description

The top-level interface for allocating GPU memory.

The memory allocator owns a composable allocator instance which actually does the work of memory allocation. This allows the behavior to be customized by composing allocators.

Implementations§

source§

impl MemoryAllocator

source

pub unsafe fn new<T: ComposableAllocator + 'static>( instance: &Instance, device: Device, physical_device: PhysicalDevice, internal_allocator: T ) -> Self

Create a new memory allocator.

Params
  • instance - the ash Instance is used te query the physical device’s memory properties
  • device - the logical device is used to create and destroy Vulkan resources
  • physical_device - the backing physical device being controlled by the logical device
  • internal_allocator - the actual ComposableAllocator implementation which is responsible for allocating memory
Safety

Unsafe because:

  • the logical device must not be destroyed while the MemoryAllocator is still in use
source

pub unsafe fn allocate_buffer( &mut self, buffer_create_info: &BufferCreateInfo, memory_property_flags: MemoryPropertyFlags ) -> Result<(Buffer, Allocation), AllocatorError>

Allocate a buffer and memory.

Params
  • buffer_create_info - used to create the Buffer and determine what memory it needs
  • memory_property_flags - used to pick the correct memory type for the buffer’s memory
Returns

A tuple of (vk::buffer, Allocation) which contains the raw vulkan buffer and the backing memory Allocation.

The buffer is already bound to the memory in the allocation so the buffer is ready to use immediately.

Safety

Unsafe because:

  • the buffer and memory must be freed before the device is destroyed
source

pub unsafe fn allocate_image( &mut self, image_create_info: &ImageCreateInfo, memory_property_flags: MemoryPropertyFlags ) -> Result<(Image, Allocation), AllocatorError>

Allocate an Image and memory.

Params
  • image_create_info - used to create the Buffer and determine what memory it needs
  • memory_property_flags - used to pick the correct memory type for the buffer’s memory
Returns

A tuple of (vk::Image, Allocation) which contains the raw Vulkan image and the backing memory Allocation.

The image is already bound to the memory in the allocation so the image is ready to use immediately.

Safety

Unsafe because:

  • the image and memory must be freed before the device is destroyed
source

pub unsafe fn free_buffer(&mut self, buffer: Buffer, allocation: Allocation)

Free a buffer and the associated allocated memory.

Safety

Unsafe because:

  • the application must synchronize access to the buffer and its memory
  • it is an error to free a buffer while ongoing GPU operations still reference it
  • it is an error to use the buffer handle after calling this method
source

pub unsafe fn free_image(&mut self, image: Image, allocation: Allocation)

Free an image and the associated allocated memory.

Safety

Unsafe because:

  • the application must synchronize access to the image and its memory
  • it is an error to free an image while ongoing GPU operations still reference it
  • it is an error to use the image handle after calling this method

Trait Implementations§

source§

impl Debug for MemoryAllocator

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for MemoryAllocator

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.