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>
impl<'device> Allocator<'device>
Sourcepub unsafe fn new(
device: &'device Device,
properties: PhysicalDeviceMemoryProperties,
atom: u64,
) -> Result<Self, AllocError>
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.
Sourcepub unsafe fn new_from_physical_device(
instance: &Instance,
physical_device: PhysicalDevice,
device: &'device Device,
) -> Result<Self, AllocError>
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.
pub fn live_count(&self) -> usize
pub fn is_closed(&self) -> bool
Sourcepub fn max_allocation_size(&self) -> Option<u64>
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.
Sourcepub fn close(&mut self) -> Result<(), AllocError>
pub fn close(&mut self) -> Result<(), AllocError>
Close only when all allocations have been explicitly released; repeat close succeeds.
Sourcepub unsafe fn allocate(
&mut self,
request: &AllocRequest,
) -> Result<Allocation, AllocError>
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.
Sourcepub unsafe fn free(
&mut self,
allocation: &mut Allocation,
) -> Result<(), AllocError>
pub unsafe fn free( &mut self, allocation: &mut Allocation, ) -> Result<(), AllocError>
§Safety
Destroy every bound resource and complete all GPU/host accesses first.
Sourcepub unsafe fn map(
&mut self,
allocation: &Allocation,
) -> Result<*mut c_void, AllocError>
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.
Sourcepub unsafe fn unmap(
&mut self,
allocation: &Allocation,
) -> Result<(), AllocError>
pub unsafe fn unmap( &mut self, allocation: &Allocation, ) -> Result<(), AllocError>
§Safety
No pointer into this mapping may be used after unmapping.
Sourcepub unsafe fn flush(
&self,
allocation: &Allocation,
offset: u64,
size: u64,
) -> Result<(), AllocError>
pub unsafe fn flush( &self, allocation: &Allocation, offset: u64, size: u64, ) -> Result<(), AllocError>
§Safety
Mapping and accesses must satisfy Vulkan host/device synchronization rules.
Sourcepub unsafe fn invalidate(
&self,
allocation: &Allocation,
offset: u64,
size: u64,
) -> Result<(), AllocError>
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.
Sourcepub unsafe fn create_buffer(
&mut self,
info: &BufferCreateInfo,
required: MemoryPropertyFlags,
preferred: MemoryPropertyFlags,
) -> Result<(Buffer, Allocation), AllocError>
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.
Sourcepub unsafe fn destroy_buffer(
&mut self,
buffer: Buffer,
allocation: &mut Allocation,
) -> Result<(), AllocError>
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.
Sourcepub unsafe fn create_buffer_with_options(
&mut self,
info: &BufferCreateInfo,
options: &AllocationCreateInfo,
) -> Result<(Buffer, Allocation), AllocError>
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.
Sourcepub fn mapped_pointer(
&self,
allocation: &Allocation,
) -> Result<Option<*mut c_void>, AllocError>
pub fn mapped_pointer( &self, allocation: &Allocation, ) -> Result<Option<*mut c_void>, AllocError>
Observe a current explicit or persistent mapping without acquiring a hold.