euv-core 0.56.0

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Memory and per-frame time ceilings governing `AssetStreamCoordinator` decode and residency pools.
#[derive(Clone, Copy, Data, Debug, Eq, Hash, New, PartialEq)]
pub struct AssetStreamBudget {
    /// Maximum resident decoded asset RAM footprint in bytes.
    #[get(type(copy))]
    pub(crate) ram_budget_bytes: usize,
    /// Maximum resident GPU texture and mesh VRAM footprint in bytes.
    #[get(type(copy))]
    pub(crate) vram_budget_bytes: usize,
    /// Maximum main-thread cooperative decode budget per frame in microseconds.
    #[get(type(copy))]
    pub(crate) max_decode_us_per_frame: u64,
    /// Maximum GPU upload payload per frame in bytes.
    #[get(type(copy))]
    pub(crate) max_gpu_upload_bytes_per_frame: usize,
    /// Maximum GPU upload CPU time per frame in microseconds.
    #[get(type(copy))]
    pub(crate) max_gpu_upload_us_per_frame: u64,
}

/// Descriptor specifying per-tier VRAM footprints and dimensions for a progressive mipmapped texture.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
pub struct TextureMipSpec {
    /// Deterministic 64-bit asset key hash.
    #[get(type(copy))]
    pub(crate) key_hash: u64,
    /// Target bindless GPU texture slot index.
    #[get(type(copy))]
    pub(crate) texture_slot: u32,
    /// Resident VRAM footprints `[mip_tail_bytes, mid_mip_bytes, full_res_bytes]`.
    #[get(type(copy))]
    pub(crate) tier_vram_bytes: [usize; 3],
    /// Full-resolution texture dimensions `[width, height]` in texels.
    #[get(type(copy))]
    pub(crate) dimensions: [u32; 2],
    /// Total allocated mipmap levels.
    #[get(type(copy))]
    pub(crate) total_mip_levels: u8,
    /// True when texels use sRGB color encoding.
    #[get(type(copy))]
    pub(crate) is_srgb: bool,
}

/// Internal O(1) 2-hand Clock-LRU residency slot wired to `ResourceAccountant`.
#[derive(Clone, Debug)]
pub(crate) struct ResidencySlot {
    /// Deterministic 64-bit asset key hash.
    pub(crate) key_hash: u64,
    /// Semantic asset category.
    pub(crate) kind: ResidencyAssetKind,
    /// Target GPU bindless texture slot index (`0` for non-textures).
    pub(crate) texture_slot: u32,
    /// Active progressive texture residency tier.
    pub(crate) tier: TextureResidencyTier,
    /// VRAM byte footprint at `MipTail`.
    pub(crate) mip_tail_vram_bytes: usize,
    /// VRAM byte footprint at `MidMip`.
    pub(crate) mid_mip_vram_bytes: usize,
    /// VRAM byte footprint at `FullRes`.
    pub(crate) full_res_vram_bytes: usize,
    /// Current live RAM bytes charged to this slot.
    pub(crate) ram_bytes: usize,
    /// Current live VRAM bytes charged to this slot.
    pub(crate) vram_bytes: usize,
    /// `ResourceAccountant` handle for RAM `CacheAllocation` (`0` when none).
    pub(crate) ram_account_handle: u64,
    /// `ResourceAccountant` handle for VRAM `GpuTexture`/`GpuBuffer` (`0` when none).
    pub(crate) vram_account_handle: u64,
    /// 2-hand Clock-LRU hotness bit cleared by `scan_hand` and checked by `evict_hand`.
    pub(crate) referenced: bool,
    /// True when this asset is visible on screen (prevents blanking visible textures).
    pub(crate) visible: bool,
    /// True when pinned against automatic Clock-LRU demotion or eviction.
    pub(crate) pinned: bool,
    /// Texture full width in texels.
    pub(crate) width: u32,
    /// Texture full height in texels.
    pub(crate) height: u32,
    /// Total mipmap levels allocated.
    pub(crate) total_mip_levels: u8,
    /// True when texture texels are sRGB-encoded.
    pub(crate) is_srgb: bool,
    /// Compact `16x16`/`32x32` mip-tail RGBA8 buffer retained for instant non-blank demotion.
    pub(crate) mip_tail_rgba8: Vec<u8>,
    /// Decoded CPU RAM payload bytes (mesh/audio/font/raw).
    pub(crate) ram_payload: Vec<u8>,
}

/// O(1) amortized 2-hand Clock-LRU progressive mipmap and RAM/VRAM residency pool wired directly to `ResourceAccountant`.
#[derive(Clone, Debug)]
pub struct ProgressiveResidencyPool {
    /// Active RAM and VRAM byte ceiling configuration.
    pub(crate) budget: AssetStreamBudget,
    /// Single authoritative resource owner recorded inside `ResourceAccountant`.
    pub(crate) owner: ResourceOwnerId,
    /// Dense slot table scanned by the 2-hand Clock-LRU pointers.
    pub(crate) slots: Vec<Option<ResidencySlot>>,
    /// Reusable freed slot indices.
    pub(crate) free_slots: Vec<usize>,
    /// O(1) index mapping 64-bit asset key hashes to slot indices.
    pub(crate) key_to_slot: HashMap<u64, usize>,
    /// Hand 1 (cool/scan hand) clearing reference bits ahead of `evict_hand`.
    pub(crate) scan_hand: usize,
    /// Hand 2 (eviction/demotion hand) reclaiming cold entries in O(1) amortized time.
    pub(crate) evict_hand: usize,
    /// Exact aggregate resident RAM bytes.
    pub(crate) ram_used_bytes: usize,
    /// Exact aggregate resident VRAM bytes.
    pub(crate) vram_used_bytes: usize,
    /// Count of textures currently resident at `TextureResidencyTier::MipTail`.
    pub(crate) textures_mip_tail: u32,
    /// Count of textures currently resident at `TextureResidencyTier::MidMip`.
    pub(crate) textures_mid_mip: u32,
    /// Count of textures currently resident at `TextureResidencyTier::FullRes`.
    pub(crate) textures_full_res: u32,
    /// Count of currently off-screen demotable textures (`MidMip` or `FullRes`) enabling O(1) pass gating.
    pub(crate) offscreen_demotable_textures: u32,
    /// Cumulative texture demotions down to `MipTail`.
    pub(crate) evictions_to_mip_tail: u64,
    /// Cumulative full off-screen slot evictions.
    pub(crate) full_evictions: u64,
}