euv_core/font/atlas/struct.rs
1use super::*;
2
3/// Fast 128-entry ASCII glyph slot lookup table bound to one quantized style signature.
4#[derive(Clone, Debug)]
5pub(crate) struct AsciiGlyphStyleTable {
6 /// Packed `(size_tenths | bold<<16 | monospace<<17 | italic<<18)` style signature.
7 pub(crate) style_sig: u32,
8 /// Direct slot indices into `GlyphAtlas::entries` for ASCII codepoints `0..128` (`u32::MAX` when uncached).
9 pub(crate) slots: [u32; 128],
10}
11
12/// Intermediate shelf placement record for one glyph prior to multi-page RGBA8 raster blitting.
13pub(crate) struct RawGlyphPageItem {
14 /// Index into `GlyphAtlas::entries`.
15 pub(crate) entry_idx: usize,
16 /// Horizontal pixel offset inside the target page.
17 pub(crate) x: u32,
18 /// Vertical pixel offset inside the target page.
19 pub(crate) y: u32,
20 /// Clamped glyph width in pixels.
21 pub(crate) width: u32,
22 /// Clamped glyph height in pixels.
23 pub(crate) height: u32,
24}
25
26/// Intermediate shelf-packed page bucket collected prior to LRU eviction and RGBA8 allocation.
27pub(crate) struct RawGlyphPageBucket {
28 /// Packed page width in pixels.
29 pub(crate) width: u32,
30 /// Packed page height in pixels.
31 pub(crate) height: u32,
32 /// Highest LRU access tick among glyphs assigned to this page.
33 pub(crate) last_used_tick: u64,
34 /// Glyph placements belonging to this page.
35 pub(crate) items: Vec<RawGlyphPageItem>,
36}
37
38/// Retained CPU glyph bitmap snapshot for one recent DPI scale enabling zero-thrash hysteresis across multi-monitor drags.
39#[derive(Clone, Debug)]
40pub(crate) struct DpiAtlasSnapshot {
41 /// IEEE-754 bits of the DPI scale factor bound to these rasterized bitmaps.
42 pub(crate) dpi_scale_bits: u32,
43 /// Anti-aliasing policy bound to these rasterized bitmaps.
44 pub(crate) aa_mode: AntialiasingMode,
45 /// Font fallback chain revision bound to these rasterized bitmaps.
46 pub(crate) font_chain_revision: u64,
47 /// Saved `(GlyphKey, RasterizedGlyph)` entries for exact-DPI instant restore.
48 pub(crate) entries: Vec<(GlyphKey, RasterizedGlyph)>,
49 /// Saved per-entry LRU timestamps aligned 1:1 with `entries`.
50 pub(crate) entry_last_used: Vec<u64>,
51 /// Total resident byte footprint of `entries`.
52 pub(crate) resident_bytes: usize,
53 /// Monotonic LRU clock value when this DPI snapshot was stashed.
54 pub(crate) stashed_tick: u64,
55}
56
57/// Multi-page atlas UV placement assigning a cached `GlyphKey` to one bounded texture page and pixel rectangle.
58#[derive(Clone, Copy, Debug, Default, Eq, Getter, New, PartialEq)]
59pub struct GlyphPagePlacement {
60 /// Zero-based index of the owning `GlyphAtlasPage`.
61 #[get(type(copy))]
62 pub(crate) page_index: u32,
63 /// Horizontal pixel offset inside the owning page texture.
64 #[get(type(copy))]
65 pub(crate) x: u32,
66 /// Vertical pixel offset inside the owning page texture.
67 #[get(type(copy))]
68 pub(crate) y: u32,
69 /// Packed glyph width in pixels.
70 #[get(type(copy))]
71 pub(crate) width: u32,
72 /// Packed glyph height in pixels.
73 #[get(type(copy))]
74 pub(crate) height: u32,
75}
76
77/// Single shelf-packed RGBA8 glyph texture page strictly bounded by `<= min(max_texture_dim, 2048)` per axis.
78#[derive(Clone, Debug, Default, Getter, New)]
79pub struct GlyphAtlasPage {
80 /// Zero-based sequential page identifier inside `PackedMultiPageGlyphAtlas`.
81 #[get(type(copy))]
82 pub(crate) page_index: u32,
83 /// Page texture width in physical pixels (`<= page_dim_limit`).
84 #[get(type(copy))]
85 pub(crate) width: u32,
86 /// Page texture height in physical pixels (`<= page_dim_limit`).
87 #[get(type(copy))]
88 pub(crate) height: u32,
89 /// Packed RGBA8 pixel data (white RGB with glyph alpha coverage).
90 pub(crate) pixels: Vec<u8>,
91 /// Number of glyph bitmaps packed onto this page.
92 #[get(type(copy))]
93 pub(crate) glyph_count: usize,
94 /// Highest LRU access tick among glyphs resident on this page for LRU page eviction.
95 #[get(type(copy))]
96 pub(crate) last_used_tick: u64,
97}
98
99/// Multi-page shelf-packed RGBA8 glyph texture atlas enforcing per-page GPU texture bounds and LRU page eviction.
100#[derive(Clone, Debug, Default, Getter, New)]
101pub struct PackedMultiPageGlyphAtlas {
102 /// Effective maximum per-page width and height in pixels enforced across all pages.
103 #[get(type(copy))]
104 pub(crate) page_dim_limit: u32,
105 /// Resident shelf-packed RGBA8 texture pages strictly within `page_dim_limit x page_dim_limit`.
106 pub(crate) pages: Vec<GlyphAtlasPage>,
107 /// Per-glyph page index and pixel UV rectangles for every retained glyph.
108 pub(crate) placements: HashMap<GlyphKey, GlyphPagePlacement>,
109 /// Source `GlyphAtlas` revision number captured at pack time.
110 #[get(type(copy))]
111 pub(crate) revision: u64,
112 /// Number of coldest pages evicted during packing to stay within the configured page cap.
113 #[get(type(copy))]
114 pub(crate) evicted_pages: u64,
115}
116
117/// Memoized glyph rasterization cache shared across frames with O(1) slot indexing, ASCII direct tables, bounded LRU budget, and hit/miss telemetry.
118#[derive(Clone, Data, Debug, Default)]
119pub struct GlyphAtlas {
120 /// Open-addressed power-of-two lookup table packing `(slot << 40) | packed_key` (`u64::MAX` when empty).
121 #[get(pub(crate))]
122 #[get_mut(pub(crate))]
123 #[set(pub(crate))]
124 pub(crate) glyph_index: Vec<u64>,
125 /// Contiguous flat arena of `(GlyphKey, RasterizedGlyph)` pairs indexed directly by `u32` slot.
126 #[get(pub(crate))]
127 #[get_mut(pub(crate))]
128 #[set(pub(crate))]
129 pub(crate) entries: Vec<(GlyphKey, RasterizedGlyph)>,
130 /// Per-entry monotonic access ticks aligned 1:1 with `entries` for bounded LRU eviction.
131 #[get(skip)]
132 #[get_mut(skip)]
133 #[set(skip)]
134 pub(crate) entry_last_used: Vec<u64>,
135 /// Compact per-style `[u32; 128]` ASCII lookup tables eliminating hash probes on ASCII text runs.
136 #[get(pub(crate))]
137 #[get_mut(pub(crate))]
138 #[set(pub(crate))]
139 pub(crate) ascii_tables: Vec<AsciiGlyphStyleTable>,
140 /// Most recently matched ASCII style signature for 1-branch hot-run table lookup.
141 #[get(skip)]
142 #[get_mut(skip)]
143 #[set(skip)]
144 pub(crate) last_ascii_style_sig: u32,
145 /// Table index inside `ascii_tables` corresponding to `last_ascii_style_sig`.
146 #[get(skip)]
147 #[get_mut(skip)]
148 #[set(skip)]
149 pub(crate) last_ascii_table_idx: usize,
150 /// Monotonic counter incremented when new glyphs are inserted or evicted for GPU texture sync.
151 #[get(type(copy))]
152 #[get_mut(pub(crate))]
153 #[set(pub(crate))]
154 pub(crate) revision: u64,
155 /// Configured resident memory budget in bytes (`0` selects `GLYPH_ATLAS_DEFAULT_BUDGET_BYTES`).
156 #[get(type(copy))]
157 #[get_mut(skip)]
158 #[set(pub(crate))]
159 pub(crate) budget_bytes: usize,
160 /// Current resident memory usage in bytes across all cached glyph bitmaps and metadata.
161 #[get(type(copy))]
162 #[get_mut(skip)]
163 #[set(skip)]
164 pub(crate) resident_bytes: usize,
165 /// Monotonic logical clock incremented on cache accesses for LRU ordering.
166 #[get(skip)]
167 #[get_mut(skip)]
168 #[set(skip)]
169 pub(crate) lru_clock: u64,
170 /// Cumulative number of cache hits served without rasterizing.
171 #[get(type(copy))]
172 #[get_mut(skip)]
173 #[set(skip)]
174 pub(crate) cache_hits: u64,
175 /// Cumulative number of cache misses requiring rasterization.
176 #[get(type(copy))]
177 #[get_mut(skip)]
178 #[set(skip)]
179 pub(crate) cache_misses: u64,
180 /// Cumulative number of cold glyphs evicted to stay within `budget_bytes`.
181 #[get(type(copy))]
182 #[get_mut(skip)]
183 #[set(skip)]
184 pub(crate) evictions: u64,
185 /// Guard pinning arena slot indices for the duration of a single frame's `prepare_frame_range`.
186 #[get(pub(crate), type(copy))]
187 #[get_mut(skip)]
188 #[set(pub(crate))]
189 pub(crate) slots_pinned: bool,
190 /// Active DPI scale IEEE-754 bits bound to currently rasterized atlas bitmaps (`0` before first bind).
191 #[get(type(copy))]
192 #[get_mut(skip)]
193 #[set(skip)]
194 pub(crate) active_dpi_scale_bits: u32,
195 /// Active anti-aliasing policy bound to currently rasterized atlas bitmaps.
196 #[get(type(copy))]
197 #[get_mut(skip)]
198 #[set(skip)]
199 pub(crate) active_aa_mode: AntialiasingMode,
200 /// Active font fallback chain revision bound to currently rasterized atlas bitmaps.
201 #[get(type(copy))]
202 #[get_mut(skip)]
203 #[set(skip)]
204 pub(crate) font_chain_revision: u64,
205 /// Current in-flight GPU submission fence tagged onto touched glyph entries.
206 #[get(type(copy))]
207 #[get_mut(skip)]
208 #[set(skip)]
209 pub(crate) active_fence_id: u64,
210 /// Highest GPU submission fence known to have completed on the device.
211 #[get(type(copy))]
212 #[get_mut(skip)]
213 #[set(skip)]
214 pub(crate) completed_fence_id: u64,
215 /// Per-entry last-referenced GPU fence identifier aligned 1:1 with `entries` for fence-deferred reclamation.
216 #[get(skip)]
217 #[get_mut(skip)]
218 #[set(skip)]
219 pub(crate) entry_fence_ids: Vec<u64>,
220 /// Evicted glyph bitmap allocations waiting for `(retire_fence_id, byte_size)` GPU fence completion.
221 #[get(skip)]
222 #[get_mut(skip)]
223 #[set(skip)]
224 pub(crate) pending_reclaim: Vec<(u64, usize)>,
225 /// Aggregate bytes currently awaiting GPU fence completion before final release.
226 #[get(type(copy))]
227 #[get_mut(skip)]
228 #[set(skip)]
229 pub(crate) pending_reclaim_bytes: usize,
230 /// Cumulative count of evicted glyph allocations reclaimed after GPU fence completion.
231 #[get(type(copy))]
232 #[get_mut(skip)]
233 #[set(skip)]
234 pub(crate) reclaimed_entries: u64,
235 /// Bounded 2-slot recent-DPI hysteresis snapshots preventing rasterization thrash across multi-DPI monitors.
236 #[get(skip)]
237 #[get_mut(skip)]
238 #[set(skip)]
239 pub(crate) recent_dpi_slots: Vec<DpiAtlasSnapshot>,
240 /// Cumulative number of exact-DPI restores served from `recent_dpi_slots` without OS re-rasterization.
241 #[get(type(copy))]
242 #[get_mut(skip)]
243 #[set(skip)]
244 pub(crate) dpi_hysteresis_restores: u64,
245}