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/// Queued dirty-rectangle sub-region upload for R8/RGBA8 glyph atlases and resident GPU image textures.
82#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
83pub struct GpuTextureUploadRect {
84    /// Target texture pixel storage format (`R8Unorm` or `Rgba8Unorm`).
85    #[get(type(copy))]
86    pub(crate) format: GpuAtlasPixelFormat,
87    /// Texture slot index (`0` = R8 glyph atlas, `1` = RGBA8 color glyph atlas, `2+` = image textures).
88    #[get(type(copy))]
89    pub(crate) texture_slot: u8,
90    /// Left pixel coordinate of the dirty region inside the target texture.
91    #[get(type(copy))]
92    pub(crate) x: u32,
93    /// Top pixel coordinate of the dirty region inside the target texture.
94    #[get(type(copy))]
95    pub(crate) y: u32,
96    /// Dirty region width in pixels.
97    #[get(type(copy))]
98    pub(crate) width: u32,
99    /// Dirty region height in pixels.
100    #[get(type(copy))]
101    pub(crate) height: u32,
102    /// Monotonic GPU fence associated with this dirty-rect upload.
103    #[get(type(copy))]
104    pub(crate) fence_id: u64,
105}
106
107/// Evicted GPU texture or buffer awaiting GPU fence completion before final memory reclamation.
108#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
109pub struct DeferredGpuReclaim {
110    /// Evicted unified resource handle awaiting retirement.
111    #[get(type(copy))]
112    pub(crate) handle: RenderResourceHandle,
113    /// GPU fence identifier that must complete before releasing backing memory.
114    #[get(type(copy))]
115    pub(crate) retire_fence_id: u64,
116    /// Reclaimable byte footprint held until `retire_fence_id` completes.
117    #[get(type(copy))]
118    pub(crate) byte_size: usize,
119}
120
121/// Bounded cross-frame GPU staging ring, persistent scroll tile cache, and fence-deferred reclamation tracker.
122#[derive(Clone, Data, Debug)]
123pub struct GpuResourceRing {
124    /// Maximum bounded number of staging slots in the ring.
125    #[get(type(copy))]
126    pub(crate) max_slots: usize,
127    /// Maximum aggregate byte ceiling across all staging slots.
128    #[get(type(copy))]
129    pub(crate) max_total_bytes: usize,
130    /// Bounded staging slots reused across frames once their fence completes.
131    pub(crate) slots: Vec<GpuStagingSlot>,
132    /// Next monotonic GPU fence identifier to issue.
133    #[get(type(copy))]
134    pub(crate) next_fence_id: u64,
135    /// Highest GPU fence identifier confirmed complete by the graphics queue.
136    #[get(type(copy))]
137    pub(crate) completed_fence_id: u64,
138    /// Monotonic resource handle counter.
139    #[get(type(copy))]
140    pub(crate) next_handle_id: u64,
141    /// Round-robin probe cursor into `slots`.
142    #[get(type(copy))]
143    pub(crate) cursor: usize,
144    /// Cumulative number of staging buffer allocations or grows.
145    #[get(type(copy))]
146    pub(crate) total_allocations: u64,
147    /// Cumulative number of zero-allocation staging slot reuses.
148    #[get(type(copy))]
149    pub(crate) total_reuses: u64,
150    /// Cumulative number of optional prefetch uploads dropped because the ring was full.
151    #[get(type(copy))]
152    pub(crate) dropped_prefetch_uploads: u64,
153    /// Cumulative number of required frame uploads deferred because all slots were in flight.
154    #[get(type(copy))]
155    pub(crate) deferred_frame_uploads: u64,
156    /// Configured resident VRAM budget in bytes for persistent scroll tiles.
157    #[get(type(copy))]
158    pub(crate) tile_budget_bytes: usize,
159    /// Current resident VRAM bytes occupied by live scroll tile textures.
160    #[get(type(copy))]
161    pub(crate) tile_resident_bytes: usize,
162    /// Monotonic logical LRU clock for persistent scroll tile eviction.
163    #[get(type(copy))]
164    pub(crate) tile_clock: u64,
165    /// Cumulative scroll tile cache hits.
166    #[get(type(copy))]
167    pub(crate) tile_hits: u64,
168    /// Cumulative scroll tile cache misses.
169    #[get(type(copy))]
170    pub(crate) tile_misses: u64,
171    /// Cumulative cold scroll tiles evicted under budget.
172    #[get(type(copy))]
173    pub(crate) tile_evictions: u64,
174    /// Active persistent scroll tile texture entries.
175    pub(crate) tiles: Vec<GpuScrollTileEntry>,
176    /// Evicted GPU handles waiting for in-flight fences to complete before final reclamation.
177    pub(crate) pending_reclaim: Vec<DeferredGpuReclaim>,
178    /// Total bytes currently waiting in `pending_reclaim`.
179    #[get(type(copy))]
180    pub(crate) pending_reclaim_bytes: usize,
181    /// Cumulative count of deferred GPU resources reclaimed after fence completion.
182    #[get(type(copy))]
183    pub(crate) reclaimed_count: u64,
184    /// Pending dirty-rectangle sub-region uploads for R8/RGBA8 glyph atlases and GPU image textures.
185    pub(crate) pending_texture_uploads: Vec<GpuTextureUploadRect>,
186    /// Cumulative dirty-rectangle texture upload bytes queued through this ring.
187    #[get(type(copy))]
188    pub(crate) total_texture_upload_bytes: u64,
189}