Skip to main content

euv_core/runtime/streaming/residency/
struct.rs

1use super::*;
2
3/// Memory and per-frame time ceilings governing `AssetStreamCoordinator` decode and residency pools.
4#[derive(Clone, Copy, Data, Debug, Eq, Hash, New, PartialEq)]
5pub struct AssetStreamBudget {
6    /// Maximum resident decoded asset RAM footprint in bytes.
7    #[get(type(copy))]
8    pub(crate) ram_budget_bytes: usize,
9    /// Maximum resident GPU texture and mesh VRAM footprint in bytes.
10    #[get(type(copy))]
11    pub(crate) vram_budget_bytes: usize,
12    /// Maximum main-thread cooperative decode budget per frame in microseconds.
13    #[get(type(copy))]
14    pub(crate) max_decode_us_per_frame: u64,
15    /// Maximum GPU upload payload per frame in bytes.
16    #[get(type(copy))]
17    pub(crate) max_gpu_upload_bytes_per_frame: usize,
18    /// Maximum GPU upload CPU time per frame in microseconds.
19    #[get(type(copy))]
20    pub(crate) max_gpu_upload_us_per_frame: u64,
21}
22
23/// Descriptor specifying per-tier VRAM footprints and dimensions for a progressive mipmapped texture.
24#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
25pub struct TextureMipSpec {
26    /// Deterministic 64-bit asset key hash.
27    #[get(type(copy))]
28    pub(crate) key_hash: u64,
29    /// Target bindless GPU texture slot index.
30    #[get(type(copy))]
31    pub(crate) texture_slot: u32,
32    /// Resident VRAM footprints `[mip_tail_bytes, mid_mip_bytes, full_res_bytes]`.
33    #[get(type(copy))]
34    pub(crate) tier_vram_bytes: [usize; 3],
35    /// Full-resolution texture dimensions `[width, height]` in texels.
36    #[get(type(copy))]
37    pub(crate) dimensions: [u32; 2],
38    /// Total allocated mipmap levels.
39    #[get(type(copy))]
40    pub(crate) total_mip_levels: u8,
41    /// True when texels use sRGB color encoding.
42    #[get(type(copy))]
43    pub(crate) is_srgb: bool,
44}
45
46/// Internal O(1) 2-hand Clock-LRU residency slot wired to `ResourceAccountant`.
47#[derive(Clone, Debug)]
48pub(crate) struct ResidencySlot {
49    /// Deterministic 64-bit asset key hash.
50    pub(crate) key_hash: u64,
51    /// Semantic asset category.
52    pub(crate) kind: ResidencyAssetKind,
53    /// Target GPU bindless texture slot index (`0` for non-textures).
54    pub(crate) texture_slot: u32,
55    /// Active progressive texture residency tier.
56    pub(crate) tier: TextureResidencyTier,
57    /// VRAM byte footprint at `MipTail`.
58    pub(crate) mip_tail_vram_bytes: usize,
59    /// VRAM byte footprint at `MidMip`.
60    pub(crate) mid_mip_vram_bytes: usize,
61    /// VRAM byte footprint at `FullRes`.
62    pub(crate) full_res_vram_bytes: usize,
63    /// Current live RAM bytes charged to this slot.
64    pub(crate) ram_bytes: usize,
65    /// Current live VRAM bytes charged to this slot.
66    pub(crate) vram_bytes: usize,
67    /// `ResourceAccountant` handle for RAM `CacheAllocation` (`0` when none).
68    pub(crate) ram_account_handle: u64,
69    /// `ResourceAccountant` handle for VRAM `GpuTexture`/`GpuBuffer` (`0` when none).
70    pub(crate) vram_account_handle: u64,
71    /// 2-hand Clock-LRU hotness bit cleared by `scan_hand` and checked by `evict_hand`.
72    pub(crate) referenced: bool,
73    /// True when this asset is visible on screen (prevents blanking visible textures).
74    pub(crate) visible: bool,
75    /// True when pinned against automatic Clock-LRU demotion or eviction.
76    pub(crate) pinned: bool,
77    /// Texture full width in texels.
78    pub(crate) width: u32,
79    /// Texture full height in texels.
80    pub(crate) height: u32,
81    /// Total mipmap levels allocated.
82    pub(crate) total_mip_levels: u8,
83    /// True when texture texels are sRGB-encoded.
84    pub(crate) is_srgb: bool,
85    /// Compact `16x16`/`32x32` mip-tail RGBA8 buffer retained for instant non-blank demotion.
86    pub(crate) mip_tail_rgba8: Vec<u8>,
87    /// Decoded CPU RAM payload bytes (mesh/audio/font/raw).
88    pub(crate) ram_payload: Vec<u8>,
89}
90
91/// O(1) amortized 2-hand Clock-LRU progressive mipmap and RAM/VRAM residency pool wired directly to `ResourceAccountant`.
92#[derive(Clone, Debug)]
93pub struct ProgressiveResidencyPool {
94    /// Active RAM and VRAM byte ceiling configuration.
95    pub(crate) budget: AssetStreamBudget,
96    /// Single authoritative resource owner recorded inside `ResourceAccountant`.
97    pub(crate) owner: ResourceOwnerId,
98    /// Dense slot table scanned by the 2-hand Clock-LRU pointers.
99    pub(crate) slots: Vec<Option<ResidencySlot>>,
100    /// Reusable freed slot indices.
101    pub(crate) free_slots: Vec<usize>,
102    /// O(1) index mapping 64-bit asset key hashes to slot indices.
103    pub(crate) key_to_slot: HashMap<u64, usize>,
104    /// Hand 1 (cool/scan hand) clearing reference bits ahead of `evict_hand`.
105    pub(crate) scan_hand: usize,
106    /// Hand 2 (eviction/demotion hand) reclaiming cold entries in O(1) amortized time.
107    pub(crate) evict_hand: usize,
108    /// Exact aggregate resident RAM bytes.
109    pub(crate) ram_used_bytes: usize,
110    /// Exact aggregate resident VRAM bytes.
111    pub(crate) vram_used_bytes: usize,
112    /// Count of textures currently resident at `TextureResidencyTier::MipTail`.
113    pub(crate) textures_mip_tail: u32,
114    /// Count of textures currently resident at `TextureResidencyTier::MidMip`.
115    pub(crate) textures_mid_mip: u32,
116    /// Count of textures currently resident at `TextureResidencyTier::FullRes`.
117    pub(crate) textures_full_res: u32,
118    /// Count of currently off-screen demotable textures (`MidMip` or `FullRes`) enabling O(1) pass gating.
119    pub(crate) offscreen_demotable_textures: u32,
120    /// Cumulative texture demotions down to `MipTail`.
121    pub(crate) evictions_to_mip_tail: u64,
122    /// Cumulative full off-screen slot evictions.
123    pub(crate) full_evictions: u64,
124}