pub struct AssetManager { /* private fields */ }Expand description
Cancelable budgeted LRU asset cache wired directly to ResourceAccountant for leak attribution.
Implementations§
Source§impl AssetManager
Cancelable loading, deterministic LRU budget enforcement, and ResourceAccountant lifecycle tracking for AssetManager.
impl AssetManager
Cancelable loading, deterministic LRU budget enforcement, and ResourceAccountant lifecycle tracking for AssetManager.
Sourcepub fn with_budget(budget: AssetBudgetConfig) -> Self
pub fn with_budget(budget: AssetBudgetConfig) -> Self
Sourcepub fn is_handle_valid(&self, handle: AssetHandle) -> bool
pub fn is_handle_valid(&self, handle: AssetHandle) -> bool
Sourcepub fn begin_load<KeyType>(
&mut self,
key: KeyType,
owner: ResourceOwnerId,
storage: AssetStorageKind,
accountant: &mut ResourceAccountant,
) -> AssetHandle
pub fn begin_load<KeyType>( &mut self, key: KeyType, owner: ResourceOwnerId, storage: AssetStorageKind, accountant: &mut ResourceAccountant, ) -> AssetHandle
Starts a cancelable asset load request and registers its pending AsyncTask under owner in accountant.
§Arguments
KeyType- Logical asset key (URI, path, or hash).ResourceOwnerId- Single authoritative resource owner.AssetStorageKind- Target residency domain (Ram,Vram, orHybrid).&mut ResourceAccountant- Framework resource accountant tracking the pending task.
§Returns
AssetHandle- Generation-stamped handle for completing, canceling, or querying the asset.
Sourcepub fn cancel_load(
&mut self,
handle: AssetHandle,
accountant: &mut ResourceAccountant,
) -> bool
pub fn cancel_load( &mut self, handle: AssetHandle, accountant: &mut ResourceAccountant, ) -> bool
Sourcepub fn complete_load(
&mut self,
handle: AssetHandle,
payload: Vec<u8>,
vram_bytes: usize,
accountant: &mut ResourceAccountant,
) -> Result<(), AssetError>
pub fn complete_load( &mut self, handle: AssetHandle, payload: Vec<u8>, vram_bytes: usize, accountant: &mut ResourceAccountant, ) -> Result<(), AssetError>
Completes a pending asset load, enforcing RAM/VRAM budgets via deterministic LRU eviction and registering allocations in accountant.
§Arguments
AssetHandle- Pending load handle returned bybegin_load.Vec<u8>- Decoded CPU payload bytes (discarded forAssetStorageKind::Vram).usize- GPU VRAM byte footprint (ignored forAssetStorageKind::Ram).&mut ResourceAccountant- Resource accountant updated with released tasks, evictions, and live allocations.
§Returns
Result<(), AssetError>-Ok(())once resident, orInvalidHandle/ExceedsBudgeton failure.
Sourcepub fn insert_ready<KeyType>(
&mut self,
key: KeyType,
owner: ResourceOwnerId,
storage: AssetStorageKind,
payload: Vec<u8>,
vram_bytes: usize,
accountant: &mut ResourceAccountant,
) -> Result<AssetHandle, AssetError>
pub fn insert_ready<KeyType>( &mut self, key: KeyType, owner: ResourceOwnerId, storage: AssetStorageKind, payload: Vec<u8>, vram_bytes: usize, accountant: &mut ResourceAccountant, ) -> Result<AssetHandle, AssetError>
Synchronously inserts a ready asset under owner, enforcing budgets and registering with accountant.
§Arguments
KeyType- Logical asset key.ResourceOwnerId- Single authoritative resource owner.AssetStorageKind- Memory residency domain.Vec<u8>- Decoded CPU payload bytes.usize- GPU VRAM byte footprint.&mut ResourceAccountant- Resource accountant receiving lifecycle updates.
§Returns
Result<AssetHandle, AssetError>- Live generation-stamped handle or budget error.
Sourcepub fn get(&mut self, handle: AssetHandle) -> Option<&[u8]>
pub fn get(&mut self, handle: AssetHandle) -> Option<&[u8]>
Sourcepub fn get_by_key(&mut self, key: &str) -> Option<(AssetHandle, &[u8])>
pub fn get_by_key(&mut self, key: &str) -> Option<(AssetHandle, &[u8])>
Sourcepub fn set_pinned(&mut self, handle: AssetHandle, pinned: bool) -> bool
pub fn set_pinned(&mut self, handle: AssetHandle, pinned: bool) -> bool
Sourcepub fn release(
&mut self,
handle: AssetHandle,
accountant: &mut ResourceAccountant,
) -> bool
pub fn release( &mut self, handle: AssetHandle, accountant: &mut ResourceAccountant, ) -> bool
Sourcepub fn evict_to_budget(
&mut self,
target_ram_bytes: usize,
target_vram_bytes: usize,
accountant: &mut ResourceAccountant,
) -> usize
pub fn evict_to_budget( &mut self, target_ram_bytes: usize, target_vram_bytes: usize, accountant: &mut ResourceAccountant, ) -> usize
Evicts unpinned least-recently-used assets until RAM and VRAM usage fall within the requested target ceilings.
§Arguments
usize- Target maximum resident CPU RAM bytes.usize- Target maximum resident GPU VRAM bytes.&mut ResourceAccountant- Resource accountant receiving release calls for each evicted entry.
§Returns
usize- Number of assets evicted.
Sourcepub fn release_owner(
&mut self,
owner: ResourceOwnerId,
now_ms: u64,
retire_fence_id: u64,
accountant: &mut ResourceAccountant,
) -> usize
pub fn release_owner( &mut self, owner: ResourceOwnerId, now_ms: u64, retire_fence_id: u64, accountant: &mut ResourceAccountant, ) -> usize
Releases every asset owned by owner, deferring VRAM retirement when retire_fence_id is still in flight on the GPU.
§Arguments
ResourceOwnerId- Destroyed owner identifier.u64- Monotonic destruction timestamp in milliseconds.u64- GPU fence required before VRAM release (0for immediate release).&mut ResourceAccountant- Resource accountant recording owner destruction and releases.
§Returns
usize- Number of asset entries removed from the manager.
Sourcepub fn stats(&self) -> AssetManagerStats
pub fn stats(&self) -> AssetManagerStats
Captures a structured telemetry snapshot of current asset counts, memory footprints, and cache statistics.
§Returns
AssetManagerStats- Current asset manager telemetry snapshot.