Skip to main content

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/// Memoized glyph rasterization cache shared across frames with O(1) slot indexing, ASCII direct tables, bounded LRU budget, and hit/miss telemetry.
13#[derive(Clone, Data, Debug, Default)]
14pub struct GlyphAtlas {
15    /// Open-addressed power-of-two lookup table packing `(slot << 40) | packed_key` (`u64::MAX` when empty).
16    #[get(pub(crate))]
17    #[get_mut(pub(crate))]
18    #[set(pub(crate))]
19    pub(crate) glyph_index: Vec<u64>,
20    /// Contiguous flat arena of `(GlyphKey, RasterizedGlyph)` pairs indexed directly by `u32` slot.
21    #[get(pub(crate))]
22    #[get_mut(pub(crate))]
23    #[set(pub(crate))]
24    pub(crate) entries: Vec<(GlyphKey, RasterizedGlyph)>,
25    /// Per-entry monotonic access ticks aligned 1:1 with `entries` for bounded LRU eviction.
26    #[get(skip)]
27    #[get_mut(skip)]
28    #[set(skip)]
29    pub(crate) entry_last_used: Vec<u64>,
30    /// Compact per-style `[u32; 128]` ASCII lookup tables eliminating hash probes on ASCII text runs.
31    #[get(pub(crate))]
32    #[get_mut(pub(crate))]
33    #[set(pub(crate))]
34    pub(crate) ascii_tables: Vec<AsciiGlyphStyleTable>,
35    /// Most recently matched ASCII style signature for 1-branch hot-run table lookup.
36    #[get(skip)]
37    #[get_mut(skip)]
38    #[set(skip)]
39    pub(crate) last_ascii_style_sig: u32,
40    /// Table index inside `ascii_tables` corresponding to `last_ascii_style_sig`.
41    #[get(skip)]
42    #[get_mut(skip)]
43    #[set(skip)]
44    pub(crate) last_ascii_table_idx: usize,
45    /// Monotonic counter incremented when new glyphs are inserted or evicted for GPU texture sync.
46    #[get(type(copy))]
47    #[get_mut(pub(crate))]
48    #[set(pub(crate))]
49    pub(crate) revision: u64,
50    /// Configured resident memory budget in bytes (`0` selects `GLYPH_ATLAS_DEFAULT_BUDGET_BYTES`).
51    #[get(type(copy))]
52    #[get_mut(skip)]
53    #[set(pub(crate))]
54    pub(crate) budget_bytes: usize,
55    /// Current resident memory usage in bytes across all cached glyph bitmaps and metadata.
56    #[get(type(copy))]
57    #[get_mut(skip)]
58    #[set(skip)]
59    pub(crate) resident_bytes: usize,
60    /// Monotonic logical clock incremented on cache accesses for LRU ordering.
61    #[get(skip)]
62    #[get_mut(skip)]
63    #[set(skip)]
64    pub(crate) lru_clock: u64,
65    /// Cumulative number of cache hits served without rasterizing.
66    #[get(type(copy))]
67    #[get_mut(skip)]
68    #[set(skip)]
69    pub(crate) cache_hits: u64,
70    /// Cumulative number of cache misses requiring rasterization.
71    #[get(type(copy))]
72    #[get_mut(skip)]
73    #[set(skip)]
74    pub(crate) cache_misses: u64,
75    /// Cumulative number of cold glyphs evicted to stay within `budget_bytes`.
76    #[get(type(copy))]
77    #[get_mut(skip)]
78    #[set(skip)]
79    pub(crate) evictions: u64,
80    /// Guard pinning arena slot indices for the duration of a single frame's `prepare_frame_range`.
81    #[get(pub(crate), type(copy))]
82    #[get_mut(skip)]
83    #[set(pub(crate))]
84    pub(crate) slots_pinned: bool,
85    /// Active DPI scale IEEE-754 bits bound to currently rasterized atlas bitmaps (`0` before first bind).
86    #[get(type(copy))]
87    #[get_mut(skip)]
88    #[set(skip)]
89    pub(crate) active_dpi_scale_bits: u32,
90    /// Active anti-aliasing policy bound to currently rasterized atlas bitmaps.
91    #[get(type(copy))]
92    #[get_mut(skip)]
93    #[set(skip)]
94    pub(crate) active_aa_mode: AntialiasingMode,
95    /// Active font fallback chain revision bound to currently rasterized atlas bitmaps.
96    #[get(type(copy))]
97    #[get_mut(skip)]
98    #[set(skip)]
99    pub(crate) font_chain_revision: u64,
100    /// Current in-flight GPU submission fence tagged onto touched glyph entries.
101    #[get(type(copy))]
102    #[get_mut(skip)]
103    #[set(skip)]
104    pub(crate) active_fence_id: u64,
105    /// Highest GPU submission fence known to have completed on the device.
106    #[get(type(copy))]
107    #[get_mut(skip)]
108    #[set(skip)]
109    pub(crate) completed_fence_id: u64,
110    /// Per-entry last-referenced GPU fence identifier aligned 1:1 with `entries` for fence-deferred reclamation.
111    #[get(skip)]
112    #[get_mut(skip)]
113    #[set(skip)]
114    pub(crate) entry_fence_ids: Vec<u64>,
115    /// Evicted glyph bitmap allocations waiting for `(retire_fence_id, byte_size)` GPU fence completion.
116    #[get(skip)]
117    #[get_mut(skip)]
118    #[set(skip)]
119    pub(crate) pending_reclaim: Vec<(u64, usize)>,
120    /// Aggregate bytes currently awaiting GPU fence completion before final release.
121    #[get(type(copy))]
122    #[get_mut(skip)]
123    #[set(skip)]
124    pub(crate) pending_reclaim_bytes: usize,
125    /// Cumulative count of evicted glyph allocations reclaimed after GPU fence completion.
126    #[get(type(copy))]
127    #[get_mut(skip)]
128    #[set(skip)]
129    pub(crate) reclaimed_entries: u64,
130}