Skip to main content

euv_core/render/ring/
struct.rs

1use super::*;
2
3/// One bounded staging buffer slot tracked by fence completion inside `GpuResourceRing`.
4#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, PartialEq)]
5pub struct GpuStagingSlot {
6    /// Zero-based ring slot index.
7    #[get(type(copy))]
8    pub(crate) slot_index: usize,
9    /// Unified resource handle backing this staging buffer slot.
10    #[get(type(copy))]
11    pub(crate) handle: RenderResourceHandle,
12    /// Allocated byte capacity of this slot.
13    #[get(type(copy))]
14    pub(crate) capacity_bytes: usize,
15    /// Payload bytes occupied by the latest submission in this slot.
16    #[get(type(copy))]
17    pub(crate) used_bytes: usize,
18    /// Fence identifier guarding reuse until `completed_fence_id >= fence_id`.
19    #[get(type(copy))]
20    pub(crate) fence_id: u64,
21    /// True while the GPU still holds a reference to this slot's buffer contents.
22    #[get(type(copy))]
23    pub(crate) in_flight: bool,
24    /// Cumulative number of submissions served by reusing this slot without reallocating.
25    #[get(type(copy))]
26    pub(crate) reuse_count: u64,
27}
28
29/// Content-and-scale-addressed lookup key for a persistent GPU scroll tile texture.
30#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
31pub struct GpuScrollTileKey {
32    /// Scene node arena index owning the scroll layer.
33    #[get(type(copy))]
34    pub(crate) layer_node_index: u32,
35    /// Scene node generation preventing reuse across recycled node slots.
36    #[get(type(copy))]
37    pub(crate) layer_node_gen: u32,
38    /// Horizontal tile coordinate in tile grid space.
39    #[get(type(copy))]
40    pub(crate) tile_x: i32,
41    /// Vertical tile coordinate in tile grid space.
42    #[get(type(copy))]
43    pub(crate) tile_y: i32,
44    /// IEEE-754 bit pattern of active DPI scale factor.
45    #[get(type(copy))]
46    pub(crate) dpr_bits: u32,
47    /// Deterministic hash of tile content, styles, and font revision.
48    #[get(type(copy))]
49    pub(crate) content_hash: u64,
50}
51
52/// Cached persistent GPU scroll tile texture tracked by LRU age and in-flight GPU fence.
53#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, PartialEq)]
54pub struct GpuScrollTileEntry {
55    /// Lookup key binding this tile to a layer generation, grid cell, DPI, and content hash.
56    #[get(type(copy))]
57    pub(crate) key: GpuScrollTileKey,
58    /// Unified GPU texture handle for this cached tile.
59    #[get(type(copy))]
60    pub(crate) handle: RenderResourceHandle,
61    /// Physical tile width in pixels.
62    #[get(type(copy))]
63    pub(crate) width: u32,
64    /// Physical tile height in pixels.
65    #[get(type(copy))]
66    pub(crate) height: u32,
67    /// Resident GPU memory footprint in bytes (`width * height * 4`).
68    #[get(type(copy))]
69    pub(crate) byte_size: usize,
70    /// Monotonic LRU access tick updated whenever this tile is sampled.
71    #[get(type(copy))]
72    pub(crate) last_used_tick: u64,
73    /// Highest GPU fence referencing this tile texture.
74    #[get(type(copy))]
75    pub(crate) last_fence_id: u64,
76    /// True when this tile is visible in the active viewport (protected from cold eviction).
77    #[get(type(copy))]
78    pub(crate) visible_this_frame: bool,
79}
80
81/// Evicted GPU texture or buffer awaiting GPU fence completion before final memory reclamation.
82#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
83pub struct DeferredGpuReclaim {
84    /// Evicted unified resource handle awaiting retirement.
85    #[get(type(copy))]
86    pub(crate) handle: RenderResourceHandle,
87    /// GPU fence identifier that must complete before releasing backing memory.
88    #[get(type(copy))]
89    pub(crate) retire_fence_id: u64,
90    /// Reclaimable byte footprint held until `retire_fence_id` completes.
91    #[get(type(copy))]
92    pub(crate) byte_size: usize,
93}
94
95/// Bounded cross-frame GPU staging ring, persistent scroll tile cache, and fence-deferred reclamation tracker.
96#[derive(Clone, Data, Debug)]
97pub struct GpuResourceRing {
98    /// Maximum bounded number of staging slots in the ring.
99    #[get(type(copy))]
100    pub(crate) max_slots: usize,
101    /// Maximum aggregate byte ceiling across all staging slots.
102    #[get(type(copy))]
103    pub(crate) max_total_bytes: usize,
104    /// Bounded staging slots reused across frames once their fence completes.
105    pub(crate) slots: Vec<GpuStagingSlot>,
106    /// Next monotonic GPU fence identifier to issue.
107    #[get(type(copy))]
108    pub(crate) next_fence_id: u64,
109    /// Highest GPU fence identifier confirmed complete by the graphics queue.
110    #[get(type(copy))]
111    pub(crate) completed_fence_id: u64,
112    /// Monotonic resource handle counter.
113    #[get(type(copy))]
114    pub(crate) next_handle_id: u64,
115    /// Round-robin probe cursor into `slots`.
116    #[get(type(copy))]
117    pub(crate) cursor: usize,
118    /// Cumulative number of staging buffer allocations or grows.
119    #[get(type(copy))]
120    pub(crate) total_allocations: u64,
121    /// Cumulative number of zero-allocation staging slot reuses.
122    #[get(type(copy))]
123    pub(crate) total_reuses: u64,
124    /// Cumulative number of optional prefetch uploads dropped because the ring was full.
125    #[get(type(copy))]
126    pub(crate) dropped_prefetch_uploads: u64,
127    /// Cumulative number of required frame uploads deferred because all slots were in flight.
128    #[get(type(copy))]
129    pub(crate) deferred_frame_uploads: u64,
130    /// Configured resident VRAM budget in bytes for persistent scroll tiles.
131    #[get(type(copy))]
132    pub(crate) tile_budget_bytes: usize,
133    /// Current resident VRAM bytes occupied by live scroll tile textures.
134    #[get(type(copy))]
135    pub(crate) tile_resident_bytes: usize,
136    /// Monotonic logical LRU clock for persistent scroll tile eviction.
137    #[get(type(copy))]
138    pub(crate) tile_clock: u64,
139    /// Cumulative scroll tile cache hits.
140    #[get(type(copy))]
141    pub(crate) tile_hits: u64,
142    /// Cumulative scroll tile cache misses.
143    #[get(type(copy))]
144    pub(crate) tile_misses: u64,
145    /// Cumulative cold scroll tiles evicted under budget.
146    #[get(type(copy))]
147    pub(crate) tile_evictions: u64,
148    /// Active persistent scroll tile texture entries.
149    pub(crate) tiles: Vec<GpuScrollTileEntry>,
150    /// Evicted GPU handles waiting for in-flight fences to complete before final reclamation.
151    pub(crate) pending_reclaim: Vec<DeferredGpuReclaim>,
152    /// Total bytes currently waiting in `pending_reclaim`.
153    #[get(type(copy))]
154    pub(crate) pending_reclaim_bytes: usize,
155    /// Cumulative count of deferred GPU resources reclaimed after fence completion.
156    #[get(type(copy))]
157    pub(crate) reclaimed_count: u64,
158}