euv_core/layout/soa/struct.rs
1use super::*;
2
3/// Flat 64-byte `#[repr(C)]` GPU compute layout input record aligned 1:1 with `FlatBfsTopology` BFS indices.
4#[repr(C)]
5#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
6pub struct GpuLayoutNodeInput {
7 /// BFS index of this node's parent (`GPU_LAYOUT_INDEX_NONE` for root).
8 #[get(type(copy))]
9 pub(crate) parent_bfs: u32,
10 /// BFS index of this node's first direct child (`GPU_LAYOUT_INDEX_NONE` when leaf).
11 #[get(type(copy))]
12 pub(crate) first_child: u32,
13 /// Count of contiguous direct children starting at `first_child`.
14 #[get(type(copy))]
15 pub(crate) child_count: u32,
16 /// Packed `LayoutStyle::flags` (`bits[0..20]`), width/height mode tags (`bits[20..24]`), and `GPU_LAYOUT_FLAG_*` (`bits[24..29]`).
17 #[get(type(copy))]
18 pub(crate) flags_kind: u32,
19 /// Preferred and minimum outer size values `[pref_w, pref_h, min_w, min_h]`.
20 #[get(type(copy))]
21 pub(crate) pref_min_size: [f32; 4],
22 /// Padding totals, main gap, and flex-grow or column-gap parameter `[pad_h, pad_v, gap_main, flex_grow_or_col_gap]`.
23 #[get(type(copy))]
24 pub(crate) pad_gap_flex: [f32; 4],
25 /// Grid columns, aspect ratio, and pre-measured intrinsic dimensions `[grid_cols_f32, aspect_ratio, intrinsic_w, intrinsic_h]`.
26 #[get(type(copy))]
27 pub(crate) extra_or_intrinsic: [f32; 4],
28}
29
30/// Flat 32-byte `#[repr(C)]` GPU compute layout output record storing resolved border-box and content-box geometry.
31#[repr(C)]
32#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
33pub struct GpuLayoutNodeOutput {
34 /// Resolved outer border-box rectangle `[x, y, width, height]` in logical coordinates.
35 #[get(type(copy))]
36 pub(crate) rect: [f32; 4],
37 /// Resolved inner content-box rectangle `[cx, cy, cw, ch]` in logical coordinates.
38 #[get(type(copy))]
39 pub(crate) content_rect: [f32; 4],
40}
41
42/// Flat 48-byte `#[repr(C)]` GPU visual style record consumed by compute primitive culling and indirect draw emission.
43#[repr(C)]
44#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
45pub struct GpuVisualStyleInput {
46 /// Packed premultiplied RGBA8 primary fill color.
47 #[get(type(copy))]
48 pub(crate) color_rgba: u32,
49 /// Packed premultiplied RGBA8 secondary border or gradient color.
50 #[get(type(copy))]
51 pub(crate) aux_color_rgba: u32,
52 /// Normalized `[u0, v0, u1, v1]` atlas UV coordinates in `[0..=65535]`.
53 #[get(type(copy))]
54 pub(crate) uv_rect: [u16; 4],
55 /// Packed Q12.4 fixed-point corner radii `[tl, tr, br, bl]` in `1/16` px units.
56 #[get(type(copy))]
57 pub(crate) radii_border: [u16; 4],
58 /// Encoded `GpuPrimitiveInstance::kind_flags` bitfield (`PrimKind`, clip mask, texture slot, layer).
59 #[get(type(copy))]
60 pub(crate) kind_flags: u32,
61 /// Packed IEEE-754 `f16x2` `(border_or_blur, angle_or_pad)` auxiliary parameter.
62 #[get(type(copy))]
63 pub(crate) extra_param: u32,
64 /// BFS index of nearest clipping ancestor (`GPU_LAYOUT_INDEX_NONE` when unclipped).
65 #[get(type(copy))]
66 pub(crate) clip_ancestor_bfs: u32,
67 /// Scroll-layer identifier bound to this node's transform/scroll uniform.
68 #[get(type(copy))]
69 pub(crate) scroll_layer_id: u32,
70 /// Fixed-point Q16 opacity multiplier (`0..=65535`).
71 #[get(type(copy))]
72 pub(crate) opacity_q16: u32,
73 /// Stacking order bias mirrored from `LayoutStyle::z_index`.
74 #[get(type(copy))]
75 pub(crate) z_order_bias: i32,
76}
77
78/// Contiguous dirty byte range queued for incremental GPU storage or instance buffer flushing.
79#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, Ord, PartialEq, PartialOrd)]
80pub struct DirtyBufferSpan {
81 /// Inclusive starting byte offset inside the target GPU buffer.
82 #[get(type(copy))]
83 pub(crate) byte_offset: usize,
84 /// Number of dirty bytes starting at `byte_offset`.
85 #[get(type(copy))]
86 pub(crate) byte_len: usize,
87}
88
89/// Reusable dirty-range coalescer and retained primitive diff buffer merging spans within `merge_gap_bytes`.
90#[derive(Clone, Data, Debug, PartialEq)]
91pub struct DirtySpanCoalescer {
92 /// Maximum inter-span byte gap bridged when coalescing (`DIRTY_SPAN_MERGE_GAP_BYTES` by default).
93 #[get(type(copy))]
94 pub(crate) merge_gap_bytes: usize,
95 /// Unsorted raw dirty spans collected since the last `clear()`.
96 pub(crate) pending: Vec<DirtyBufferSpan>,
97 /// Sorted, non-overlapping coalesced dirty spans ready for GPU upload.
98 pub(crate) coalesced: Vec<DirtyBufferSpan>,
99 /// Whether `pending` contains uncoalesced entries requiring a merge pass.
100 #[get(type(copy))]
101 pub(crate) needs_coalesce: bool,
102 /// Retained previous-frame primitive stream used to detect changed primitive slots.
103 #[get(skip)]
104 #[get_mut(skip)]
105 #[set(skip)]
106 pub(crate) retained_primitives: Vec<GpuPrimitiveInstance>,
107 /// Coalesced dirty bytes uploaded in the most recent primitive diff frame.
108 #[get(type(copy))]
109 pub(crate) last_dirty_bytes: usize,
110 /// Full-frame primitive byte size in the most recent primitive diff frame.
111 #[get(type(copy))]
112 pub(crate) last_full_bytes: usize,
113 /// Cumulative bytes saved across all frames by incremental dirty-span flushing.
114 #[get(type(copy))]
115 pub(crate) cumulative_bytes_saved: u64,
116}
117
118/// Level-contiguous Breadth-First Search (BFS) topology consumed identically by parallel CPU layout and GPU compute shaders.
119#[derive(Clone, Data, Debug, Default, PartialEq)]
120pub struct FlatBfsTopology {
121 /// `SceneTree::topology_revision` captured when this BFS layout was constructed.
122 #[get(type(copy))]
123 pub(crate) topology_revision: u64,
124 /// Arena slot index of the root node (`GPU_LAYOUT_INDEX_NONE` when empty).
125 #[get(type(copy))]
126 pub(crate) root_arena_index: u32,
127 /// Mapping from BFS node index `0..node_count` to `SceneTree` arena slot index.
128 pub(crate) bfs_to_arena: Vec<u32>,
129 /// Mapping from `SceneTree` arena slot index to BFS index (`GPU_LAYOUT_INDEX_NONE` when detached).
130 pub(crate) arena_to_bfs: Vec<u32>,
131 /// Parent BFS index for each BFS node (`GPU_LAYOUT_INDEX_NONE` at root).
132 pub(crate) parent_bfs: Vec<u32>,
133 /// Starting BFS index of each node's contiguous direct children slice (`GPU_LAYOUT_INDEX_NONE` when leaf).
134 pub(crate) child_first: Vec<u32>,
135 /// Number of direct children for each BFS node.
136 pub(crate) child_count: Vec<u32>,
137 /// Prefix offsets partitioning `bfs_to_arena` into tree depth levels (`level_offsets[d]..level_offsets[d + 1]`).
138 pub(crate) level_offsets: Vec<u32>,
139 /// Total node count inside each BFS node's subtree (including self) for work granularity and partitioning.
140 pub(crate) subtree_sizes: Vec<u32>,
141}
142
143/// Compact byte-range slice into `SceneLayoutSoa::text_bytes` enabling zero-allocation `Send + Sync` text reads.
144#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
145pub struct SoaTextSlice {
146 /// Starting byte offset inside `SceneLayoutSoa::text_bytes`.
147 #[get(type(copy))]
148 pub(crate) byte_start: u32,
149 /// UTF-8 byte length of the node's text payload (`0` for non-text nodes).
150 #[get(type(copy))]
151 pub(crate) byte_len: u32,
152 /// True when every byte in the slice is ASCII (`< 128`), enabling SIMD advance fast-paths.
153 #[get(type(copy))]
154 pub(crate) is_ascii: bool,
155}
156
157/// Dense `Send + Sync` Structure-of-Arrays (SoA) layout, text, visual, and GPU compute staging snapshot extracted from `SceneTree`.
158#[derive(Clone, Data, Debug, Default)]
159pub struct SceneLayoutSoa {
160 /// Last `SceneTree::revision` synchronized into this SoA snapshot.
161 #[get(type(copy))]
162 pub(crate) synced_revision: u64,
163 /// Last `SceneTree::topology_revision` synchronized into `topology`.
164 #[get(type(copy))]
165 pub(crate) synced_topology_revision: u64,
166 /// Last `SceneTree::serial_layout_epoch` synchronized into `layout_boxes` and `gpu_outputs`.
167 #[get(type(copy))]
168 pub(crate) synced_serial_epoch: u64,
169 /// Synchronization strategy executed during the most recent `sync_from_tree`.
170 #[get(type(copy))]
171 pub(crate) last_sync_mode: SoaSyncMode,
172 /// Level-ordered BFS topology mirroring the live tree structure.
173 pub(crate) topology: FlatBfsTopology,
174 /// Arena-indexed live `NodeId` handles parallel to `SceneTree::nodes`.
175 pub(crate) node_ids: Vec<NodeId>,
176 /// Arena-indexed `SoaNodeKindTag` values parallel to `SceneTree::nodes`.
177 pub(crate) node_kinds: Vec<SoaNodeKindTag>,
178 /// Arena-indexed `LayoutStyle` records parallel to `SceneTree::nodes`.
179 pub(crate) layout_styles: Vec<LayoutStyle>,
180 /// Arena-indexed `TextStyle` records parallel to `SceneTree::nodes`.
181 pub(crate) text_styles: Vec<TextStyle>,
182 /// Arena-indexed border widths in logical pixels parallel to `SceneTree::nodes`.
183 pub(crate) border_widths: Vec<f32>,
184 /// Arena-indexed 2D paint transforms parallel to `SceneTree::nodes`.
185 pub(crate) transforms: Vec<Transform2D>,
186 /// Arena-indexed `LayoutBox` geometry mirrored from and written back to `SceneTree`.
187 pub(crate) layout_boxes: Vec<LayoutBox>,
188 /// Arena-indexed dirty bitmasks mirrored from `SceneTree::meta`.
189 pub(crate) dirty_masks: Vec<u16>,
190 /// Arena-indexed monotonic mutation epochs mirrored from `SceneTree::node_mutation_epochs`.
191 pub(crate) synced_node_epochs: Vec<u32>,
192 /// Arena-indexed text slices referencing `text_bytes`.
193 pub(crate) text_slices: Vec<SoaTextSlice>,
194 /// Contiguous UTF-8 text byte slab shared read-only across parallel CPU layout workers.
195 pub(crate) text_bytes: Vec<u8>,
196 /// Arena-indexed intrinsic sizes for `NodeKind::Image` leaves.
197 pub(crate) image_sizes: Vec<Size>,
198 /// BFS-ordered 64-byte GPU compute layout input buffer ready for incremental upload.
199 pub(crate) gpu_inputs: Vec<GpuLayoutNodeInput>,
200 /// BFS-ordered 32-byte GPU compute layout output buffer mirroring computed node rects.
201 pub(crate) gpu_outputs: Vec<GpuLayoutNodeOutput>,
202 /// BFS-ordered 48-byte GPU visual style input buffer for indirect draw culling and emission.
203 pub(crate) gpu_visuals: Vec<GpuVisualStyleInput>,
204 /// Coalesced dirty byte spans covering modified ranges of `gpu_inputs`.
205 pub(crate) input_dirty_spans: DirtySpanCoalescer,
206 /// Coalesced dirty byte spans covering modified ranges of `gpu_visuals`.
207 pub(crate) visual_dirty_spans: DirtySpanCoalescer,
208}