Struct ccthw_ash_allocator::MemoryAllocator
source · 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
impl MemoryAllocator
sourcepub unsafe fn new<T: ComposableAllocator + 'static>(
instance: &Instance,
device: Device,
physical_device: PhysicalDevice,
internal_allocator: T
) -> Self
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 propertiesdevice
- the logical device is used to create and destroy Vulkan resourcesphysical_device
- the backing physical device being controlled by the logical deviceinternal_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
sourcepub unsafe fn allocate_buffer(
&mut self,
buffer_create_info: &BufferCreateInfo,
memory_property_flags: MemoryPropertyFlags
) -> Result<(Buffer, Allocation), AllocatorError>
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 needsmemory_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
sourcepub unsafe fn allocate_image(
&mut self,
image_create_info: &ImageCreateInfo,
memory_property_flags: MemoryPropertyFlags
) -> Result<(Image, Allocation), AllocatorError>
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 needsmemory_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
sourcepub unsafe fn free_buffer(&mut self, buffer: Buffer, allocation: Allocation)
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
sourcepub unsafe fn free_image(&mut self, image: Image, allocation: Allocation)
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