Skip to main content

Allocator

Struct Allocator 

Source
pub struct Allocator<'device> { /* private fields */ }
Expand description

Borrows one device; native memory is released only by explicit operations.

Each allocation has an allocator identity and generation. Dropping either the allocator or a token can leak native objects; it never calls Vulkan.

Implementations§

Source§

impl<'device> Allocator<'device>

Source

pub unsafe fn new( device: &'device Device, properties: PhysicalDeviceMemoryProperties, atom: u64, ) -> Result<Self, AllocError>

Construct from caller-supplied physical-device metadata.

Prefer Self::new_from_physical_device for queried properties and the local native-allocation count limit. Managed buffers require the device’s owned creation capabilities; raw imports without them support only the explicitly unsafe low-level allocation route.

§Safety

Properties and atom size must belong to this device’s physical device. Caller must enforce device allocation size/count limits and enabled features.

Source

pub unsafe fn new_from_physical_device( instance: &Instance, physical_device: PhysicalDevice, device: &'device Device, ) -> Result<Self, AllocError>

Query properties and limits for the selected physical device.

Requires owned instance/device creation metadata and a compatible parent snapshot. It does not discover a logical device’s physical-device identity. Queries the maximum allocation size when core 1.1 or enabled maintenance3 provides it. Legacy 1.0 leaves this limit unknown; see Self::max_allocation_size. The local count limit excludes allocations made by other allocators/raw calls.

§Safety

physical_device must belong to instance and be the physical device used to create device. All contexts must remain live; native ownership and host synchronization remain the caller’s responsibility. Unqueried size limits and resource valid usage must still be observed by the caller.

Source

pub fn live_count(&self) -> usize

Source

pub fn is_closed(&self) -> bool

Source

pub fn max_allocation_size(&self) -> Option<u64>

Queried native per-allocation size ceiling, or unknown on the caller-supplied metadata route and legacy 1.0 without admitted maintenance3 properties. A known ceiling is not a promise of available heap space or allocation success.

Source

pub fn close(&mut self) -> Result<(), AllocError>

Close only when all allocations have been explicitly released; repeat close succeeds.

Source

pub unsafe fn allocate( &mut self, request: &AllocRequest, ) -> Result<Allocation, AllocError>

Allocate separate native storage without a resource-specific allocation chain.

§Safety

Request must satisfy resource requirements and device size/count limits. No external, protected, device-address or required-dedication semantics are admitted.

Source

pub unsafe fn free( &mut self, allocation: &mut Allocation, ) -> Result<(), AllocError>

§Safety

Destroy every bound resource and complete all GPU/host accesses first.

Source

pub unsafe fn map( &mut self, allocation: &Allocation, ) -> Result<*mut c_void, AllocError>

Map the complete allocation; repeated maps are rejected.

§Safety

Synchronize host/GPU access; returned pointers cannot outlive the mapping.

Source

pub unsafe fn unmap( &mut self, allocation: &Allocation, ) -> Result<(), AllocError>

§Safety

No pointer into this mapping may be used after unmapping.

Source

pub unsafe fn flush( &self, allocation: &Allocation, offset: u64, size: u64, ) -> Result<(), AllocError>

§Safety

Mapping and accesses must satisfy Vulkan host/device synchronization rules.

Source

pub unsafe fn invalidate( &self, allocation: &Allocation, offset: u64, size: u64, ) -> Result<(), AllocError>

§Safety

Complete device writes before invalidating and do not race host accesses.

Source

pub unsafe fn create_buffer( &mut self, info: &BufferCreateInfo, required: MemoryPropertyFlags, preferred: MemoryPropertyFlags, ) -> Result<(Buffer, Allocation), AllocError>

Create, allocate and bind an ordinary buffer transactionally.

§Safety

Info must satisfy device limits/valid usage. Sparse, external, protected and device-address buffers and arbitrary pNext chains are not admitted.

Source

pub unsafe fn destroy_buffer( &mut self, buffer: Buffer, allocation: &mut Allocation, ) -> Result<(), AllocError>

Destroy a matching managed buffer before freeing its allocation.

§Safety

Complete every CPU/GPU use; do not separately destroy this buffer first.

Source

pub unsafe fn create_buffer_with_options( &mut self, info: &BufferCreateInfo, options: &AllocationCreateInfo, ) -> Result<(Buffer, Allocation), AllocError>

Create and bind an ordinary buffer using explicit separate/pooled policy.

§Safety

Same native valid-usage, completion and synchronization obligations as create_buffer.

Source

pub fn mapped_pointer( &self, allocation: &Allocation, ) -> Result<Option<*mut c_void>, AllocError>

Observe a current explicit or persistent mapping without acquiring a hold.

Source

pub fn statistics(&self) -> AllocatorStats

Auto Trait Implementations§

§

impl<'device> !Send for Allocator<'device>

§

impl<'device> !Sync for Allocator<'device>

§

impl<'device> Freeze for Allocator<'device>

§

impl<'device> RefUnwindSafe for Allocator<'device>

§

impl<'device> Unpin for Allocator<'device>

§

impl<'device> UnsafeUnpin for Allocator<'device>

§

impl<'device> UnwindSafe for Allocator<'device>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.