Realm

vk::mem::virtual_block · Structs · V1

5 public declarations with native signatures and source-owned contracts.

StRustExperimental

Stvk::mem::virtual_block::VirtualAllocation

Contract

Generation-checked identity in exactly one virtual block; no implicit free.

Stvk::mem::virtual_block::VirtualAllocationInfo

Contract

Placement snapshot; valid only while the matching allocation remains live.

Fields

user_data

Field
user_data: usize

Uninterpreted consumer metadata; no ownership or dereference is inferred.

offset

Field
offset: u64
No public source comment is attached to this declaration.

size

Field
size: u64
No public source comment is attached to this declaration.

Methods and associated items

set_user_data

Method
pub fn set_user_data(self, value: usize) -> Self

Set user_data and return the updated record.

set_offset

Method
pub fn set_offset(self, value: u64) -> Self

Set offset and return the updated record.

set_size

Method
pub fn set_size(self, value: u64) -> Self

Set size and return the updated record.

clone

Method
fn clone(&self) -> VirtualAllocationInfo
Returns a duplicate of the value. Read more

fmt

Method
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter. Read more

eq

Method
fn eq(&self, other: &VirtualAllocationInfo) -> bool
Tests for self and other values to be equal, and is used by ==.

Stvk::mem::virtual_block::VirtualBlock

Contract

Virtual TLSF or linear allocator; owns host metadata and no native objects.

Mutations require exclusive access. Drop releases host metadata only. Callback construction borrows its allocation/free record through Drop; raw callback user data remains the unsafe constructor caller’s responsibility. This is not a Vulkan memory block or a pool with GPU lifetime tracking.

Methods and associated items

is_empty

Method
pub fn is_empty(&self) -> bool

Observe checked virtual emptiness in constant time.

set_user_data

Method
pub fn set_user_data( &mut self, allocation: &VirtualAllocation, data: usize, ) -> Result<(), AllocError>

Set opaque per-allocation metadata, with no native pointer dereference or ownership.

detailed_statistics

Method
pub fn detailed_statistics(&self) -> VirtualBlockDetails

Calculate explicit virtual allocation/free-span extrema.

write_statistics_json

Method
pub fn write_statistics_json( &self, output: &mut impl Write, detailed: bool, ) -> Result<(), AllocError>

Stream virtual JSON diagnostics; no native memory is accessed.

new

Method
pub fn new(size: u64) -> Result<Self, AllocError>
No public source comment is attached to this declaration.

new_with_algorithm

Method
pub fn new_with_algorithm( size: u64, algorithm: AllocationAlgorithm, ) -> Result<Self, AllocError>

Create TLSF or linear host-only placement. No native storage is acquired.

use vk::{VirtualBlock, mem::{AllocationAlgorithm, PlacementStrategy}};
let mut block = VirtualBlock::new_with_algorithm(4096, AllocationAlgorithm::Linear)?;
let mut lower = block.allocate(64, 16, PlacementStrategy::Default)?;
let mut upper = block.allocate_upper(64, 16)?;
assert_eq!(block.allocation_info(&lower)?.offset, 0);
assert_eq!(block.allocation_info(&upper)?.offset, 4032);
block.free(&mut upper)?;
block.free(&mut lower)?;
Errors

Rejects a zero size or failed host metadata reservation.

new_with_callbacks

Method
pub unsafe fn new_with_callbacks( size: u64, algorithm: AllocationAlgorithm, callbacks: &'callbacks AllocationCallbacks, ) -> Result<Self, AllocError>

Create host-only placement whose metadata uses borrowed Vulkan allocation callbacks.

TLSF/linear buffers, growth and detailed-JSON scratch storage use only this allocation/free pair, with SystemAllocationScope::OBJECT. The block value stays inline; tokens need no reference-count allocation. Reallocation and driver internal-allocation notifications are not invoked. Drop releases host metadata only; no Vulkan device or native memory is involved. The callback record cannot expire while the block still owns storage:

ⓘ
let mut block;
{
    let callbacks = vk::AllocationCallbacks::new();
    // SAFETY: demonstration of record lifetime; null functions are rejected at runtime.
    block = unsafe {
        VirtualBlock::new_with_callbacks(1024, AllocationAlgorithm::Tlsf, &callbacks)
    }.unwrap();
}
block.clear();
Errors

Rejects zero size, a missing allocation/free function or failed host storage.

Safety

Callbacks must return uniquely owned memory of the requested size/alignment, or null on failure, and free only their own allocations. They must not unwind or reenter this block. Their code and user data must remain valid through block Drop and support calls from any thread, including concurrent independent blocks. Borrowing retains the callback record, not ownership of its raw user data.

allocate

Method
pub fn allocate( &mut self, size: u64, alignment: u64, strategy: PlacementStrategy, ) -> Result<VirtualAllocation, AllocError>

Allocate an aligned region. Linear placement ignores the TLSF search strategy.

allocate_upper

Method
pub fn allocate_upper( &mut self, size: u64, alignment: u64, ) -> Result<VirtualAllocation, AllocError>

Allocate downward in a linear block. Active ring mode rejects this request.

Errors

Rejects TLSF, invalid extents/alignment, exhausted space or host metadata.

free

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

Release a matching live identity. No native resource is destroyed or waited on.

allocation_info

Method
pub fn allocation_info( &self, allocation: &VirtualAllocation, ) -> Result<VirtualAllocationInfo, AllocError>

Validate identity/generation and return the current offset/size snapshot.

clear

Method
pub fn clear(&mut self)

Invalidate all tokens and restore the full range, retaining host capacity. Users of previously returned offsets must stop using them before reuse.

statistics

Method
pub fn statistics(&self) -> VirtualBlockStats

Calculate detailed free-span statistics; this is not a constant-time hot path.

Stvk::mem::virtual_block::VirtualBlockDetails

pub struct VirtualBlockDetails { pub statistics: VirtualBlockStats, pub allocation_size_min: Option<u64>, pub allocation_size_max: Option<u64>, pub free_range_size_min: Option<u64>, pub free_range_size_max: Option<u64>, }
Explicit virtual placement diagnostics; physical holes may not be immediately reusable by linear placement.

Contract

Explicit virtual placement diagnostics; physical holes may not be immediately reusable by linear placement.

Fields

statistics

Field
statistics: VirtualBlockStats
No public source comment is attached to this declaration.

allocation_size_min

Field
allocation_size_min: Option<u64>
No public source comment is attached to this declaration.

allocation_size_max

Field
allocation_size_max: Option<u64>
No public source comment is attached to this declaration.

free_range_size_min

Field
free_range_size_min: Option<u64>
No public source comment is attached to this declaration.

free_range_size_max

Field
free_range_size_max: Option<u64>
No public source comment is attached to this declaration.

Methods and associated items

set_statistics

Method
pub fn set_statistics(self, value: VirtualBlockStats) -> Self

Set statistics and return the updated record.

set_allocation_size_min

Method
pub fn set_allocation_size_min(self, value: Option<u64>) -> Self

Set allocation_size_min and return the updated record.

set_allocation_size_max

Method
pub fn set_allocation_size_max(self, value: Option<u64>) -> Self

Set allocation_size_max and return the updated record.

set_free_range_size_min

Method
pub fn set_free_range_size_min(self, value: Option<u64>) -> Self

Set free_range_size_min and return the updated record.

set_free_range_size_max

Method
pub fn set_free_range_size_max(self, value: Option<u64>) -> Self

Set free_range_size_max and return the updated record.

fmt

Method
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter. Read more

eq

Method
fn eq(&self, other: &VirtualBlockDetails) -> bool
Tests for self and other values to be equal, and is used by ==.

Stvk::mem::virtual_block::VirtualBlockStats

pub struct VirtualBlockStats { pub size: u64, pub allocation_count: usize, pub allocated_bytes: u64, pub free_bytes: u64, pub free_region_count: usize, pub largest_free_region: u64, }
Host metadata statistics. Alignment holes remain free, not reserved to a token. Linear free spans can include holes that placement cannot immediately reuse.

Contract

Host metadata statistics. Alignment holes remain free, not reserved to a token. Linear free spans can include holes that placement cannot immediately reuse.

Fields

size

Field
size: u64
No public source comment is attached to this declaration.

allocation_count

Field
allocation_count: usize
No public source comment is attached to this declaration.

allocated_bytes

Field
allocated_bytes: u64
No public source comment is attached to this declaration.

free_bytes

Field
free_bytes: u64
No public source comment is attached to this declaration.

free_region_count

Field
free_region_count: usize
No public source comment is attached to this declaration.

largest_free_region

Field
largest_free_region: u64
No public source comment is attached to this declaration.

Methods and associated items

set_size

Method
pub fn set_size(self, value: u64) -> Self

Set size and return the updated record.

set_allocation_count

Method
pub fn set_allocation_count(self, value: usize) -> Self

Set allocation_count and return the updated record.

set_allocated_bytes

Method
pub fn set_allocated_bytes(self, value: u64) -> Self

Set allocated_bytes and return the updated record.

set_free_bytes

Method
pub fn set_free_bytes(self, value: u64) -> Self

Set free_bytes and return the updated record.

set_free_region_count

Method
pub fn set_free_region_count(self, value: usize) -> Self

Set free_region_count and return the updated record.

fmt

Method
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter. Read more

eq

Method
fn eq(&self, other: &VirtualBlockStats) -> bool
Tests for self and other values to be equal, and is used by ==.