euv_core/render/software/struct.rs
1use super::*;
2
3/// Single disjoint horizontal framebuffer strip dispatched to a persistent rasterization worker thread.
4#[cfg(not(target_arch = "wasm32"))]
5#[derive(Clone, Copy, Data, Debug, Default)]
6pub(crate) struct BandTaskSlice {
7 /// Raw mutable pixel buffer base address encoded as `usize` for `Send` transfer.
8 #[get(type(copy))]
9 pub(crate) pixels_ptr: usize,
10 /// Byte length of the disjoint horizontal pixel strip.
11 #[get(type(copy))]
12 pub(crate) pixels_len: usize,
13 /// Full framebuffer physical width in pixels.
14 #[get(type(copy))]
15 pub(crate) width: u32,
16 /// Inclusive top physical Y row of this strip.
17 #[get(type(copy))]
18 pub(crate) y_start: u32,
19 /// Number of physical rows inside this strip.
20 #[get(type(copy))]
21 pub(crate) height: u32,
22 /// Optional raw source pointer for parallel base-scene backdrop restore (`0` when unused).
23 #[get(type(copy))]
24 pub(crate) base_src_ptr: usize,
25 /// Horizontal byte offset within each row where backdrop restore starts.
26 #[get(type(copy))]
27 pub(crate) restore_x0_bytes: usize,
28 /// Horizontal byte length restored per row (`width * 4` for full-width contiguous restore).
29 #[get(type(copy))]
30 pub(crate) restore_row_bytes: usize,
31}
32
33/// Optional base-scene backdrop restore and fused full-viewport scrim LUT specification for band dispatch.
34#[derive(Clone, Copy, Debug, Default)]
35pub(crate) struct BandRestoreSpec<'a> {
36 /// Cached full-framebuffer RGBA8 base scene pixels, if restoring backdrop.
37 pub(crate) base_pixels: Option<&'a [u8]>,
38 /// Inclusive physical start X column to restore on each row.
39 pub(crate) x0: u32,
40 /// Exclusive physical end X column to restore on each row.
41 pub(crate) x1: u32,
42 /// Optional prebuilt 256-entry linear-light scrim LUT fused into backdrop restore.
43 pub(crate) scrim_luts: Option<&'a [[u8; 256]; 4]>,
44}
45
46/// Read-only auxiliary frame slices passed to band rasterizers (glyphs, caret rects, rounded clips, and cached corner masks).
47#[derive(Clone, Copy)]
48pub(crate) struct BandAuxSlices<'a> {
49 /// Pre-positioned glyph instances for the active frame.
50 pub(crate) positioned_glyphs: &'a [PositionedGlyph],
51 /// Pre-measured caret bounding rectangles for the active frame.
52 pub(crate) caret_rects: &'a [Rect],
53 /// Active rounded clip masks for the frame.
54 pub(crate) rounded_clips: &'a [RoundedClipMask],
55 /// Cached quadrant corner anti-aliasing masks.
56 pub(crate) corner_masks: &'a [CachedCornerMask],
57}
58
59/// Precomputed 1D horizontal edge pixel sample reused across every vertical interior scanline of a rounded rectangle.
60#[derive(Clone, Copy, Debug, Default)]
61pub(crate) struct EdgeBlendSample {
62 /// Physical X pixel coordinate inside the target scanline.
63 pub(crate) x: u32,
64 /// Direct RGBA8 bytes written verbatim when `is_opaque` is true.
65 pub(crate) rgba: [u8; 4],
66 /// Pre-multiplied linear red channel `SRGB_TO_LIN_LUT[r] * alpha`.
67 pub(crate) sr_a: f32,
68 /// Pre-multiplied linear green channel `SRGB_TO_LIN_LUT[g] * alpha`.
69 pub(crate) sg_a: f32,
70 /// Pre-multiplied linear blue channel `SRGB_TO_LIN_LUT[b] * alpha`.
71 pub(crate) sb_a: f32,
72 /// Complement opacity `1.0 - alpha`.
73 pub(crate) inv_a: f32,
74 /// Quantized source alpha in `0..=255` for destination alpha update.
75 pub(crate) sa_u32: u32,
76 /// True when the sample overwrites destination pixels without blending.
77 pub(crate) is_opaque: bool,
78}
79
80/// Precomputed per-row exterior, anti-aliased, and dirty horizontal spans inside a cached rounded-clip corner mask.
81#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
82pub(crate) struct CornerMaskRowSpan {
83 /// Inclusive start X (in mask-local `0..dim`) of the contiguous exterior (`cov == 0`) run.
84 pub(crate) ext_start: u16,
85 /// Exclusive end X of the contiguous exterior (`cov == 0`) run.
86 pub(crate) ext_end: u16,
87 /// Inclusive start X of the anti-aliased (`1..=15`) transition run.
88 pub(crate) aa_start: u16,
89 /// Exclusive end X of the anti-aliased (`1..=15`) transition run.
90 pub(crate) aa_end: u16,
91 /// Inclusive start X of all non-interior (`cov < 16`) pixels requiring save/restore.
92 pub(crate) dirty_start: u16,
93 /// Exclusive end X of all non-interior (`cov < 16`) pixels requiring save/restore.
94 pub(crate) dirty_end: u16,
95}
96
97/// Cached exact 4x4 RGSS coverage grid (`0..=16` hit counts) for one rounded-clip quadrant `(radius, quadrant, aa)`.
98#[derive(Clone, Debug)]
99pub(crate) struct CachedCornerMask {
100 /// Bit representation of the clamped physical corner radius `r.to_bits()`.
101 pub(crate) radius_bits: u32,
102 /// Quadrant index (`0 = TL`, `1 = TR`, `2 = BR`, `3 = BL`).
103 pub(crate) quadrant: u8,
104 /// Whether 4x4 RGSS anti-aliasing is enabled (`false` for `AntialiasingMode::None`).
105 pub(crate) aa_enabled: bool,
106 /// Side length of the square coverage grid in physical pixels (`ceil(r + 1)`).
107 pub(crate) dim: u16,
108 /// Row-major exact coverage hit counts in `0..=16` (`0` = outside, `16` = fully inside).
109 pub(crate) cov: Vec<u8>,
110 /// Per-row horizontal exterior/AA/dirty span bounds (`len == dim`).
111 pub(crate) row_spans: Vec<CornerMaskRowSpan>,
112}
113
114/// Persistent cache of precomputed rounded-clip corner coverage masks reused across cards and frames.
115#[derive(Clone, Debug, Default)]
116pub(crate) struct CornerMaskCache {
117 /// Contiguous arena of cached quadrant coverage masks indexed by `u32` ID.
118 pub(crate) entries: Vec<CachedCornerMask>,
119}
120
121/// Single saved horizontal row segment belonging to one cached rounded-clip corner.
122#[derive(Clone, Copy, Debug, Default)]
123pub(crate) struct SavedCornerRow {
124 /// Global physical Y row coordinate.
125 pub(crate) y: u32,
126 /// Inclusive global physical start X of the saved segment.
127 pub(crate) sx0: u32,
128 /// Exclusive global physical end X of the saved segment.
129 pub(crate) sx1: u32,
130 /// Byte offset into `BandCornerScratch::saved_bytes` where this row's RGBA bytes start.
131 pub(crate) byte_off: usize,
132 /// Index into `CornerMaskCache::entries` for this quadrant.
133 pub(crate) mask_id: u32,
134 /// Mask-local X origin in global physical coordinates.
135 pub(crate) origin_x: i32,
136 /// Mask-local Y origin in global physical coordinates.
137 pub(crate) origin_y: i32,
138}
139
140/// Per-thread reusable scratch buffers for rounded-clip corner save and restore in `render_band`.
141#[derive(Debug, Default)]
142pub(crate) struct BandCornerScratch {
143 /// Bulk RGBA8 byte buffer storing pre-command corner pixels via `extend_from_slice`.
144 pub(crate) saved_bytes: Vec<u8>,
145 /// Saved row descriptors for the single-mask cached fast path.
146 pub(crate) saved_rows: Vec<SavedCornerRow>,
147 /// Clipped corner box bounds for the multi-mask / fallback path.
148 pub(crate) corner_boxes: Vec<(u32, u32, u32, u32)>,
149}
150
151/// Active rounded-rectangle clip mask in physical pixels applied during software band rasterization.
152#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
153pub(crate) struct RoundedClipMask {
154 /// Physical clip rectangle bounds.
155 #[get(type(copy))]
156 pub(crate) rect: Rect,
157 /// Physical corner radii.
158 #[get(type(copy))]
159 pub(crate) radius: CornerRadius,
160 /// Cached quadrant mask IDs `[tl, tr, br, bl]` into `CornerMaskCache::entries` (`u32::MAX` = uncached/inactive).
161 #[get(type(copy))]
162 pub(crate) corner_mask_ids: [u32; 4],
163}
164
165/// Pre-positioned glyph instance resolved once per frame on the main thread for zero-lookup band blitting.
166#[derive(Clone, Copy, Data, Debug, Default, Eq, New, PartialEq)]
167pub(crate) struct PositionedGlyph {
168 /// Direct arena slot index into `GlyphAtlas::entries`.
169 #[get(type(copy))]
170 pub(crate) glyph_idx: u32,
171 /// Rounded physical X coordinate of the glyph's left edge.
172 #[get(type(copy))]
173 pub(crate) x: i32,
174 /// Rounded physical Y coordinate of the glyph's top edge.
175 #[get(type(copy))]
176 pub(crate) y: i32,
177 /// Cached glyph bitmap width in physical pixels for fast band culling.
178 #[get(type(copy))]
179 pub(crate) width: u16,
180 /// Cached glyph bitmap height in physical pixels for fast band culling.
181 #[get(type(copy))]
182 pub(crate) height: u16,
183}
184
185/// Shared read-only descriptor for separable sliding-window `BackdropBlur` passes executed serially or in parallel.
186#[derive(Clone, Copy, Debug, Default)]
187pub(crate) struct BlurPassDesc {
188 /// Raw mutable framebuffer RGBA8 pixel base pointer (`*mut u8 as usize`).
189 #[cfg(not(target_arch = "wasm32"))]
190 pub(crate) fb_ptr: usize,
191 /// Total framebuffer RGBA8 byte length.
192 #[cfg(not(target_arch = "wasm32"))]
193 pub(crate) fb_len: usize,
194 /// Full framebuffer physical width in pixels.
195 pub(crate) fb_w: u32,
196 /// Raw mutable persistent horizontal-pass scratch base pointer (`*mut [u8; 4] as usize`).
197 #[cfg(not(target_arch = "wasm32"))]
198 pub(crate) horiz_ptr: usize,
199 /// Element count (`sw * sh`) of the active slice inside `blur_horiz_scratch`.
200 #[cfg(not(target_arch = "wasm32"))]
201 pub(crate) horiz_len: usize,
202 /// Inclusive halo source start X in physical pixels.
203 pub(crate) sx0: u32,
204 /// Inclusive halo source start Y in physical pixels.
205 pub(crate) sy0: u32,
206 /// Halo source width in physical pixels (`sx1 - sx0`).
207 pub(crate) sw: u32,
208 /// Halo source height in physical pixels (`sy1 - sy0`).
209 pub(crate) sh: u32,
210 /// Inclusive destination blur start X in physical pixels.
211 pub(crate) x0: u32,
212 /// Inclusive destination blur start Y in physical pixels.
213 pub(crate) y0: u32,
214 /// Exclusive destination blur end X in physical pixels.
215 pub(crate) x1: u32,
216 /// Exclusive destination blur end Y in physical pixels.
217 pub(crate) y1: u32,
218 /// Clamped integer box-filter half-radius (`1..=24`).
219 pub(crate) rad: u32,
220 /// Exact fixed-point Q24 reciprocal `ceil(2^24 / (2*rad + 1))` matching integer division bit-for-bit.
221 pub(crate) inv_win_q24: u64,
222 /// Physical destination rectangle for rounded-corner clipping.
223 pub(crate) rect: Rect,
224 /// Physical corner radii for rounded-corner clipping.
225 pub(crate) radius: CornerRadius,
226 /// True when `radius.max_radius() > 0.25`.
227 pub(crate) has_radius: bool,
228 /// Number of rows processed per work-stealing strip in parallel blur passes.
229 #[cfg(not(target_arch = "wasm32"))]
230 pub(crate) strip_rows: u32,
231 /// Total number of parallel blur strips for the current pass.
232 #[cfg(not(target_arch = "wasm32"))]
233 pub(crate) strip_count: usize,
234}
235
236/// Shared 128-byte aligned frame dispatch state consumed lock-free by persistent band workers during a single job epoch.
237#[cfg(not(target_arch = "wasm32"))]
238#[repr(align(128))]
239#[derive(Debug)]
240pub(crate) struct BandJob {
241 /// Active job execution mode (`RasterBands`, `BlurHoriz`, or `BlurVert`).
242 pub(crate) kind: BandJobKind,
243 /// Base address of the caller-owned `BandTaskSlice` slice.
244 pub(crate) tasks_ptr: usize,
245 /// Number of horizontal strips in the frame job.
246 pub(crate) tasks_len: usize,
247 /// Base address of `DisplayList::commands`.
248 pub(crate) commands_ptr: usize,
249 /// Length of `DisplayList::commands`.
250 pub(crate) commands_len: usize,
251 /// Base address of the pre-processed `PreppedCommand` slice.
252 pub(crate) prepped_ptr: usize,
253 /// Length of the pre-processed `PreppedCommand` slice.
254 pub(crate) prepped_len: usize,
255 /// Base address of the per-frame pre-positioned `PositionedGlyph` slice.
256 pub(crate) glyphs_ptr: usize,
257 /// Length of the per-frame pre-positioned `PositionedGlyph` slice.
258 pub(crate) glyphs_len: usize,
259 /// Base address of the per-frame pre-computed `TextCaret` rectangle slice.
260 pub(crate) caret_rects_ptr: usize,
261 /// Length of the per-frame pre-computed `TextCaret` rectangle slice.
262 pub(crate) caret_rects_len: usize,
263 /// Base address of the per-frame active `RoundedClipMask` slice.
264 pub(crate) rounded_clips_ptr: usize,
265 /// Length of the per-frame active `RoundedClipMask` slice.
266 pub(crate) rounded_clips_len: usize,
267 /// Base address of the read-only cached quadrant corner masks slice.
268 pub(crate) corner_masks_ptr: usize,
269 /// Length of the read-only cached quadrant corner masks slice.
270 pub(crate) corner_masks_len: usize,
271 /// Base address of the shared read-only `GlyphAtlas`.
272 pub(crate) atlas_ptr: usize,
273 /// Optional raw pointer to a stack-pinned 4-channel RGBA blend LUT tuple fused into backdrop restore (`0` when unused).
274 pub(crate) scrim_luts_ptr: usize,
275 /// Active physical DPI scale factor.
276 pub(crate) scale: f32,
277 /// Active anti-aliasing policy.
278 pub(crate) aa: AntialiasingMode,
279 /// Descriptor used when `kind` is `BlurHoriz` or `BlurVert`.
280 pub(crate) blur_desc: BlurPassDesc,
281 /// Cache-line-isolated atomic work-stealing strip cursor shared by the caller and all worker threads.
282 pub(crate) next_idx: AlignedAtomicUsize,
283 /// Cache-line-isolated atomic accumulated shaded pixel count across all strips.
284 pub(crate) total_shaded: AlignedAtomicUsize,
285}
286
287/// Software rasterizer band dispatcher delegating lock-free work execution to the unified `EngineWorkerPool`.
288#[cfg(not(target_arch = "wasm32"))]
289#[derive(Debug)]
290pub(crate) struct BandWorkerPool {
291 /// Non-blocking guard owning reusable horizontal band task slices across frames.
292 pub(crate) dispatch_tasks: Mutex<Vec<BandTaskSlice>>,
293}
294
295/// Preprocessed draw-command metadata computed once on the main thread before parallel band rasterization.
296#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
297pub(crate) struct PreppedCommand {
298 /// Original index inside `DisplayList::commands`.
299 #[get(type(copy))]
300 pub(crate) cmd_index: usize,
301 /// Active intersected physical clip rectangle for this command.
302 #[get(type(copy))]
303 pub(crate) active_clip: Rect,
304 /// Inclusive top physical Y row affected by this command.
305 #[get(type(copy))]
306 pub(crate) y0: u32,
307 /// Exclusive bottom physical Y row affected by this command.
308 #[get(type(copy))]
309 pub(crate) y1: u32,
310 /// Optional opaque inner vertical-span cutout for a `BoxShadow` followed immediately by an opaque `FillRoundedRect`.
311 #[get(type(copy))]
312 pub(crate) opaque_cutout_h: Rect,
313 /// Optional opaque inner horizontal-span cutout for a `BoxShadow` followed immediately by an opaque `FillRoundedRect`.
314 #[get(type(copy))]
315 pub(crate) opaque_cutout_v: Rect,
316 /// Start index into the per-frame `PositionedGlyph` slice for `TextRun` commands (`0` when unused).
317 #[get(type(copy))]
318 pub(crate) glyph_run_start: u32,
319 /// Count of pre-positioned glyphs for `TextRun` commands (`0` when unused).
320 #[get(type(copy))]
321 pub(crate) glyph_run_len: u32,
322 /// Optional index into the per-frame pre-resolved `TextCaret` rectangle slice (`u32::MAX` when unused).
323 #[get(type(copy))]
324 pub(crate) caret_rect_idx: u32,
325 /// Start index into the per-frame `RoundedClipMask` slice (`0` when unused).
326 #[get(type(copy))]
327 pub(crate) rounded_clip_start: u32,
328 /// Count of active `RoundedClipMask` entries touching this command (`0` on fast path).
329 #[get(type(copy))]
330 pub(crate) rounded_clip_len: u16,
331 /// Relative index jump inside `prepped_scratch` when a `usize::MAX` clip-scope sentinel misses a band.
332 #[get(type(copy))]
333 pub(crate) skip_delta: u32,
334}
335
336/// Single open-addressed slot in `TextLayoutCache` mapping `(key_hash, width_key)` to an arena index.
337#[derive(Clone, Copy, Debug, Eq, PartialEq)]
338pub(crate) struct TextLayoutSlot {
339 /// Deterministic 64-bit FxHash of source text bytes and typography style.
340 pub(crate) key_hash: u64,
341 /// Quantized wrap width (`(max_w * 10.0).round() as u32`, or `u32::MAX` for unbounded lines).
342 pub(crate) width_key: u32,
343 /// Arena index into `TextLayoutCache::entries` (`u32::MAX` marks an empty slot).
344 pub(crate) entry_idx: u32,
345}
346
347/// Zero-clone, SipHash-free open-addressed cache of wrapped `TextLayoutResult` entries with bounded LRU eviction and telemetry.
348#[derive(Clone, Debug, Default)]
349pub(crate) struct TextLayoutCache {
350 /// Power-of-two linear-probing slot table (`entry_idx == u32::MAX` denotes an empty slot).
351 pub(crate) slots: Vec<TextLayoutSlot>,
352 /// Contiguous arena owning cached `TextLayoutResult` entries read lock-free across band workers.
353 pub(crate) entries: Vec<TextLayoutResult>,
354 /// Lookup keys `(key_hash, width_key)` aligned 1:1 with `entries` for slot table reconstruction after LRU eviction.
355 pub(crate) entry_keys: Vec<(u64, u32)>,
356 /// Monotonic access ticks aligned 1:1 with `entries` for bounded LRU eviction.
357 pub(crate) entry_last_used: Vec<u64>,
358 /// Tracked resident byte footprint per entry aligned 1:1 with `entries`.
359 pub(crate) entry_bytes: Vec<usize>,
360 /// Current total resident memory in bytes across all cached layouts.
361 pub(crate) resident_bytes: usize,
362 /// Optional custom memory budget in bytes (`0` selects `TEXT_LAYOUT_CACHE_BUDGET_BYTES`).
363 pub(crate) budget_bytes: usize,
364 /// Monotonic access clock incremented on every cache lookup.
365 pub(crate) lru_clock: u64,
366 /// Cumulative count of text layout cache hits.
367 pub(crate) cache_hits: u64,
368 /// Cumulative count of text layout cache misses.
369 pub(crate) cache_misses: u64,
370 /// Cumulative count of evicted cold text layouts.
371 pub(crate) evictions: u64,
372}
373
374/// Single open-addressed slot in `PositionedGlyphRunCache` keyed by `(text_style_hash, width_bits, phys_scale_milli)`.
375#[derive(Clone, Copy, Debug, Eq, PartialEq)]
376pub(crate) struct PositionedGlyphRunSlot {
377 /// Deterministic 64-bit FxHash of source text bytes and typography style.
378 pub(crate) key_hash: u64,
379 /// IEEE-754 bits of the logical text box width.
380 pub(crate) width_bits: u32,
381 /// Quantized physical scale factor `(scale * 1000.0).round() as u32`.
382 pub(crate) phys_scale_milli: u32,
383 /// Arena index into `PositionedGlyphRunCache::entries` (`u32::MAX` marks an empty slot).
384 pub(crate) entry_idx: u32,
385}
386
387/// Cached relative-offset glyph sequence range inside `PositionedGlyphRunCache::glyph_slab`.
388#[derive(Clone, Copy, Debug, Default)]
389pub(crate) struct CachedPositionedGlyphRun {
390 /// Start index inside `PositionedGlyphRunCache::glyph_slab`.
391 pub(crate) glyph_start: u32,
392 /// Number of relative `PositionedGlyph` entries owned by this run.
393 pub(crate) glyph_len: u32,
394 /// True when any glyph had a non-integer relative X offset before rounding (guards negative-origin tie parity).
395 pub(crate) has_fractional_x: bool,
396 /// Maximum `GlyphAtlas` slot index referenced by this run for O(1) validity checks.
397 pub(crate) max_glyph_slot: u32,
398}
399
400/// Bounded open-addressed flat-slab cache of `CachedPositionedGlyphRun` entries keyed by `(text_hash, width_bits, phys_scale_milli)`.
401#[derive(Clone, Debug, Default)]
402pub(crate) struct PositionedGlyphRunCache {
403 /// Power-of-two linear-probing slot table (`entry_idx == u32::MAX` marks an empty slot).
404 pub(crate) slots: Vec<PositionedGlyphRunSlot>,
405 /// Contiguous flat glyph slab eliminating per-entry `Vec<PositionedGlyph>` heap allocations.
406 pub(crate) glyph_slab: Vec<PositionedGlyph>,
407 /// Contiguous arena of cached relative-positioned glyph run descriptors.
408 pub(crate) entries: Vec<CachedPositionedGlyphRun>,
409 /// Lookup keys `(key_hash, width_bits, phys_scale_milli)` aligned 1:1 with `entries`.
410 pub(crate) entry_keys: Vec<(u64, u32, u32)>,
411 /// Monotonic LRU access ticks aligned 1:1 with `entries`.
412 pub(crate) entry_last_used: Vec<u64>,
413 /// Pre-allocated keep-flag vector reused during zero-allocation LRU compaction.
414 pub(crate) evict_keep: Vec<bool>,
415 /// Pre-allocated destination slab reused during zero-allocation LRU compaction.
416 pub(crate) evict_slab_scratch: Vec<PositionedGlyph>,
417 /// Consecutive misses without any cache hit (detects streaming virtual-list text churn).
418 pub(crate) miss_streak: u32,
419 /// Misses observed during the current frame for streaming-churn decay on static frames.
420 pub(crate) frame_misses: u32,
421 /// Monotonic access clock incremented on lookups.
422 pub(crate) lru_clock: u64,
423 /// `GlyphAtlas::evictions` watermark last observed when populating cached slot indices.
424 pub(crate) atlas_evictions: u64,
425 /// `GlyphAtlas::font_chain_revision` watermark last observed when populating cached slot indices.
426 pub(crate) font_chain_revision: u64,
427 /// Highest `GlyphAtlas` slot index referenced across all cached runs.
428 pub(crate) max_cached_slot: u32,
429 /// Cumulative positioned glyph run cache hits (reused without `GlyphAtlas` mutation).
430 pub(crate) cache_hits: u64,
431 /// Cumulative positioned glyph run cache misses.
432 pub(crate) cache_misses: u64,
433 /// Cumulative evicted cold positioned glyph runs.
434 pub(crate) evictions: u64,
435}
436
437/// High-performance CPU tile and analytical-SDF software rasterizer with zero GPU dependencies.
438#[derive(Clone, Data, Debug, Default)]
439pub struct SoftwareRenderer {
440 /// Lazily allocated RGBA8 framebuffer (`None` when GPU direct-draw is active with zero CPU FB bytes).
441 #[get(skip)]
442 #[get_mut(skip)]
443 #[set(skip)]
444 pub(crate) framebuffer: Option<Framebuffer>,
445 /// Shared glyph rasterization atlas.
446 pub(crate) glyph_atlas: GlyphAtlas,
447 /// Native or deterministic font rasterization provider.
448 #[set(skip)]
449 pub(crate) font_provider: NativeSystemFont,
450 /// Deterministic text measurer matching `LayoutEngine` metrics.
451 #[get(type(copy))]
452 pub(crate) measurer: DeterministicTextMeasurer,
453 /// Zero-clone open-addressed cache of wrapped `TextLayoutResult` entries eliminating per-frame cloning and SipHash.
454 #[get(pub(crate))]
455 #[get_mut(pub(crate))]
456 #[set(pub(crate))]
457 pub(crate) text_layout_cache: TextLayoutCache,
458 /// Relative-offset `PositionedGlyphRun` cache keyed by `(text_hash, width_bits, phys_scale_milli)` for zero-LRU-mutation scroll reuse.
459 #[get(pub(crate))]
460 #[get_mut(pub(crate))]
461 #[set(skip)]
462 pub(crate) positioned_glyph_run_cache: PositionedGlyphRunCache,
463 /// Persistent scratch buffer for Pass 1 of separable sliding-window `BackdropBlur` (zero steady-state per-frame allocs).
464 #[get(pub(crate))]
465 #[get_mut(pub(crate))]
466 #[set(skip)]
467 pub(crate) blur_horiz_scratch: Vec<[u8; 4]>,
468 /// Persistent keep-flag buffer reused by `cull_occluded_prepped_commands` across frames.
469 #[get(skip)]
470 #[get_mut(skip)]
471 #[set(skip)]
472 pub(crate) cull_keep_scratch: Vec<bool>,
473 /// Persistent compacted command buffer reused by `cull_occluded_prepped_commands` across frames.
474 #[get(skip)]
475 #[get_mut(skip)]
476 #[set(skip)]
477 pub(crate) cull_compacted_scratch: Vec<PreppedCommand>,
478 /// Persistent open-sentinel stack reused by `cull_occluded_prepped_commands` across frames.
479 #[get(skip)]
480 #[get_mut(skip)]
481 #[set(skip)]
482 pub(crate) cull_sentinels_scratch: Vec<(usize, usize)>,
483 /// Active physical clip-rectangle stack.
484 #[get(pub(crate))]
485 #[get_mut(pub(crate))]
486 #[set(pub(crate))]
487 pub(crate) clip_stack: Vec<Rect>,
488 /// Parallel stack of optional rounded-rectangle clip masks aligned 1:1 with `clip_stack`.
489 #[get(pub(crate))]
490 #[get_mut(pub(crate))]
491 #[set(pub(crate))]
492 pub(crate) rounded_clip_stack: Vec<Option<RoundedClipMask>>,
493 /// Active anti-aliasing policy.
494 #[get(type(copy))]
495 pub(crate) antialiasing: AntialiasingMode,
496 /// Tile edge length in physical pixels for damage tile accounting.
497 #[get(type(copy))]
498 pub(crate) tile_size: u32,
499 /// Cached physical width of the static base-scene snapshot behind active portals.
500 #[get(pub(crate), type(copy))]
501 #[set(pub(crate))]
502 pub(crate) base_cache_width: u32,
503 /// Cached physical height of the static base-scene snapshot behind active portals.
504 #[get(pub(crate), type(copy))]
505 #[set(pub(crate))]
506 pub(crate) base_cache_height: u32,
507 /// Full base-layer command hash for the cached static backdrop (`0` when invalid).
508 #[get(pub(crate), type(copy))]
509 #[set(pub(crate))]
510 pub(crate) base_cache_hash: u64,
511 /// Base-layer command hash observed on the immediately preceding frame to avoid copying active scroll frames.
512 #[get(pub(crate), type(copy))]
513 #[set(pub(crate))]
514 pub(crate) prev_base_hash: u64,
515 /// Saved RGBA8 pixels of the static base scene beneath active portals for fast overlay compositing.
516 #[get(pub(crate))]
517 #[get_mut(pub(crate))]
518 #[set(pub(crate))]
519 pub(crate) base_cache_pixels: Vec<u8>,
520 /// Reusable pre-processed draw command buffer cleared at frame start to avoid per-frame allocations.
521 #[get(pub(crate))]
522 #[get_mut(pub(crate))]
523 #[set(pub(crate))]
524 pub(crate) prepped_scratch: Vec<PreppedCommand>,
525 /// Reusable active rounded-clip mask buffer cleared at frame start to avoid per-frame allocations.
526 #[get(pub(crate))]
527 #[get_mut(pub(crate))]
528 #[set(pub(crate))]
529 pub(crate) rounded_clips_scratch: Vec<RoundedClipMask>,
530 /// Reusable flat buffer of pre-positioned glyphs emitted once per frame for zero-lookup band rasterization.
531 #[get(pub(crate))]
532 #[get_mut(pub(crate))]
533 #[set(pub(crate))]
534 pub(crate) positioned_glyphs_scratch: Vec<PositionedGlyph>,
535 /// Reusable line buffer for single-lookup `Center`/`Right` text alignment positioning.
536 #[get(pub(crate))]
537 #[get_mut(pub(crate))]
538 #[set(pub(crate))]
539 pub(crate) line_glyphs_scratch: Vec<(u32, f32, u16, u16)>,
540 /// Reusable buffer of pre-computed physical caret rectangles for `DrawCommand::TextCaret`.
541 #[get(pub(crate))]
542 #[get_mut(pub(crate))]
543 #[set(pub(crate))]
544 pub(crate) caret_rects_scratch: Vec<Rect>,
545 /// Persistent cache of precomputed rounded-clip corner coverage masks reused across cards and frames.
546 #[get(pub(crate))]
547 #[get_mut(pub(crate))]
548 #[set(pub(crate))]
549 pub(crate) corner_mask_cache: CornerMaskCache,
550 /// Physical union bounds of the foreground portal commands painted on the previous cached frame.
551 #[get(pub(crate), type(copy))]
552 #[set(pub(crate))]
553 pub(crate) prev_portal_bounds: Option<Rect>,
554 /// Full-viewport translucent scrim color active on the previous cached portal frame, if any.
555 #[get(pub(crate), type(copy))]
556 #[set(pub(crate))]
557 pub(crate) prev_portal_scrim: Option<Color>,
558 /// Physical union bounds of all prepped commands emitted during the latest `prepare_frame_range`.
559 #[get(pub(crate), type(copy))]
560 #[set(pub(crate))]
561 pub(crate) prepped_bounds: Option<Rect>,
562 /// Physical union bounds of `prepped_scratch[1..]` emitted during the latest `prepare_frame_range`.
563 #[get(pub(crate), type(copy))]
564 #[set(pub(crate))]
565 pub(crate) prepped_fg_bounds: Option<Rect>,
566 /// Reusable clip-scope stack `(clip_y0, clip_y1, optional_sentinel_idx)` for O(1) off-band subtree skipping.
567 #[get(pub(crate))]
568 #[get_mut(pub(crate))]
569 #[set(pub(crate))]
570 pub(crate) clip_scope_scratch: Vec<(u32, u32, Option<usize>)>,
571 /// Cached full-viewport translucent scrim color matching `cached_scrim_luts`.
572 #[get(skip)]
573 #[get_mut(skip)]
574 #[set(skip)]
575 pub(crate) cached_scrim_color: Option<Color>,
576 /// Cached 256-entry per-channel linear-light scrim LUT reused across frames with identical scrim color.
577 #[get(skip)]
578 #[get_mut(skip)]
579 #[set(skip)]
580 pub(crate) cached_scrim_luts: Option<Box<[[u8; 256]; 4]>>,
581 /// Cumulative number of rasterization passes executed serially on the calling thread.
582 #[get(type(copy))]
583 #[get_mut(skip)]
584 #[set(skip)]
585 pub(crate) serial_dispatches: u64,
586 /// Cumulative number of rasterization passes dispatched across `BandWorkerPool`.
587 #[get(type(copy))]
588 #[get_mut(skip)]
589 #[set(skip)]
590 pub(crate) parallel_dispatches: u64,
591 /// Cumulative number of fully occluded draw commands culled without reordering translucent layers.
592 #[get(type(copy))]
593 #[get_mut(skip)]
594 #[set(skip)]
595 pub(crate) culled_occluded_commands: u64,
596 /// Current adaptive pixel-area threshold separating serial execution from multi-threaded band dispatch.
597 #[get(type(copy))]
598 #[get_mut(skip)]
599 #[set(skip)]
600 pub(crate) adaptive_parallel_threshold_pixels: usize,
601 /// Optional explicit pixel-area override for parallel band dispatch (`0` selects adaptive auto-tuning).
602 #[get(type(copy))]
603 #[get_mut(skip)]
604 #[set(skip)]
605 pub(crate) adaptive_threshold_override: usize,
606 /// Most recently observed serial band rasterization duration in microseconds.
607 #[get(type(copy))]
608 #[get_mut(skip)]
609 #[set(skip)]
610 pub(crate) last_serial_us: u64,
611 /// Most recently observed parallel band rasterization duration in microseconds.
612 #[get(type(copy))]
613 #[get_mut(skip)]
614 #[set(skip)]
615 pub(crate) last_parallel_us: u64,
616 /// Total frames rendered by this `SoftwareRenderer` (Frame 1 runs serially before async worker pool warm-up).
617 #[get(type(copy))]
618 #[get_mut(skip)]
619 #[set(skip)]
620 pub(crate) rendered_frames: u64,
621 /// Gates `Instant::now()` microsecond timing instrumentation inside `execute_prepared_bands` (`false` by default).
622 #[get(type(copy))]
623 pub(crate) telemetry_enabled: bool,
624 /// Tracks whether active animation or scrolling keeps `BandWorkerPool` adaptive hybrid spin enabled (`false` = `0` spin).
625 #[get(type(copy))]
626 #[set(skip)]
627 pub(crate) high_frequency_active: bool,
628 /// Cached per-tile (`128x16`) FNV-1a framebuffer hashes for O(dirty_tiles) bit-exact `incremental_framebuffer_hash`.
629 #[get(skip)]
630 #[get_mut(skip)]
631 #[set(skip)]
632 pub(crate) hash_tiles: Vec<u64>,
633 /// Bitset marking `128x16` framebuffer tiles dirtied since the last `incremental_framebuffer_hash` computation.
634 #[get(skip)]
635 #[get_mut(skip)]
636 #[set(skip)]
637 pub(crate) hash_dirty_bits: Vec<u64>,
638 /// Framebuffer width in pixels matching `hash_tiles`.
639 #[get(skip)]
640 #[get_mut(skip)]
641 #[set(skip)]
642 pub(crate) hash_tiles_w: u32,
643 /// Framebuffer height in pixels matching `hash_tiles`.
644 #[get(skip)]
645 #[get_mut(skip)]
646 #[set(skip)]
647 pub(crate) hash_tiles_h: u32,
648 /// True once `hash_tiles` holds valid hashes for `(hash_tiles_w, hash_tiles_h)`.
649 #[get(skip)]
650 #[get_mut(skip)]
651 #[set(skip)]
652 pub(crate) hash_tiles_valid: bool,
653}
654
655/// Compact 16-byte hot per-column cache entry reused across every vertical shadow strip scanline.
656#[derive(Clone, Copy, Debug, Default)]
657pub(crate) struct ShadowStripHot {
658 /// Precomputed horizontal IGN phase term `(x as f32) * 0.067_110_56`.
659 pub(crate) ign_x: f32,
660 /// Last observed destination RGBA8 bytes packed as native-endian `u32`.
661 pub(crate) cached_dst: u32,
662 /// Cached quantized sRGB Q4 red output prior to IGN dither addition.
663 pub(crate) q4_r: i16,
664 /// Cached quantized sRGB Q4 green output prior to IGN dither addition.
665 pub(crate) q4_g: i16,
666 /// Cached quantized sRGB Q4 blue output prior to IGN dither addition.
667 pub(crate) q4_b: i16,
668 /// Cached composited output alpha byte.
669 pub(crate) out_a: u8,
670 /// Column blend state (`0` = inactive, `1` = uncached blend, `2` = cached blend, `3` = opaque).
671 pub(crate) state: u8,
672}
673
674/// Precomputed linear-light blend factors for a single shadow column or mirrored corner sample.
675#[derive(Clone, Copy, Debug, Default)]
676pub(crate) struct ShadowStripParams {
677 /// Premultiplied linear red channel `SRGB_TO_LIN_LUT[r] * alpha`.
678 pub(crate) sr_a: f32,
679 /// Premultiplied linear green channel `SRGB_TO_LIN_LUT[g] * alpha`.
680 pub(crate) sg_a: f32,
681 /// Premultiplied linear blue channel `SRGB_TO_LIN_LUT[b] * alpha`.
682 pub(crate) sb_a: f32,
683 /// Complement opacity `1.0 - alpha`.
684 pub(crate) inv_a: f32,
685 /// Quantized source alpha `(alpha * 255.0) as u32`.
686 pub(crate) sa_u32: u32,
687 /// Complement integer alpha `255 - sa_u32`.
688 pub(crate) inv_a_u32: u32,
689}
690
691/// Single-pixel destination cache shared across 2x/4x symmetrically mirrored shadow corner writes.
692#[derive(Clone, Copy, Debug, Default)]
693pub(crate) struct ShadowPixelCache {
694 /// Last observed destination RGBA8 bytes packed as native-endian `u32`.
695 pub(crate) dst_u32: u32,
696 /// Cached quantized sRGB Q4 red output prior to IGN dither addition.
697 pub(crate) q4_r: i32,
698 /// Cached quantized sRGB Q4 green output prior to IGN dither addition.
699 pub(crate) q4_g: i32,
700 /// Cached quantized sRGB Q4 blue output prior to IGN dither addition.
701 pub(crate) q4_b: i32,
702 /// Cached composited output alpha byte.
703 pub(crate) out_a: u8,
704 /// Whether `dst_u32` and `q4_*` have been populated for the current corner sample.
705 pub(crate) valid: bool,
706}
707
708/// Per-thread reusable 1D horizontal shadow falloff strip buffers eliminating per-shadow allocations.
709#[derive(Debug, Default)]
710pub(crate) struct BandShadowScratch {
711 /// Hot per-column cache entries for the left vertical shadow strip.
712 pub(crate) left_hot: Vec<ShadowStripHot>,
713 /// Cold linear blend parameters for the left vertical shadow strip.
714 pub(crate) left_params: Vec<ShadowStripParams>,
715 /// Hot per-column cache entries for the right vertical shadow strip.
716 pub(crate) right_hot: Vec<ShadowStripHot>,
717 /// Cold linear blend parameters for the right vertical shadow strip.
718 pub(crate) right_params: Vec<ShadowStripParams>,
719}
720
721/// Precomputed geometry and hoisted linear tint constants shared across rows of one `raster_shadow` invocation.
722#[derive(Clone, Copy, Debug)]
723pub(crate) struct ShadowRenderContext {
724 /// Shadow tint RGBA color passed to `blend_shadow_span_const_alpha`.
725 pub(crate) color: Color,
726 /// Shadow tint sRGB RGB bytes `[r, g, b]`.
727 pub(crate) color_rgb: [u8; 3],
728 /// Hoisted linear-light shadow tint `[sr, sg, sb]`.
729 pub(crate) lin_rgb: [f32; 3],
730 /// Caster horizontal center X in physical pixels.
731 pub(crate) cx: f32,
732 /// Caster vertical center Y in physical pixels.
733 pub(crate) cy: f32,
734 /// Caster half-width in physical pixels.
735 pub(crate) half_w: f32,
736 /// Caster half-height in physical pixels.
737 pub(crate) half_h: f32,
738 /// Normalized shadow tint alpha in `[0.0, 1.0]`.
739 pub(crate) base_alpha: f32,
740 /// Inverse Gaussian standard deviation `1.0 / sigma.max(0.5)`.
741 pub(crate) inv_sigma: f32,
742 /// Gaussian cutoff radius `3.0 * sigma`.
743 pub(crate) cutoff: f32,
744 /// Clamped uniform corner radius in physical pixels.
745 pub(crate) uniform_r: f32,
746 /// Conservative squared distance threshold `(cutoff + uniform_r + 1e-3)^2` for sqrt-free corner early reject.
747 pub(crate) cutoff_r_safe_sq: f32,
748 /// Clamped inclusive visible left X bound.
749 pub(crate) x0: u32,
750 /// Clamped exclusive visible right X bound.
751 pub(crate) x1: u32,
752 /// Exclusive end X of the left corner region (`sx0` when `has_mid_x`, else `split_x`).
753 pub(crate) lx1: u32,
754 /// Inclusive start X of the right corner region (`sx1` when `has_mid_x`, else `split_x`).
755 pub(crate) rx0: u32,
756 /// Horizontal mirror sum `(2 * cx).round() - 1` when `cx` is half-integer aligned.
757 pub(crate) mirror_x_sum: i32,
758 /// True when the shadow has a middle constant-alpha horizontal span (`sx0 < sx1`).
759 pub(crate) has_mid_x: bool,
760}