euv_core/render/hardware/struct.rs
1use super::*;
2
3/// Unified 64-byte `#[repr(C)]` instanced GPU draw primitive consumed identically across WGSL, MSL, GLSL ES 3.0, and HLSL uber-shaders.
4#[repr(C)]
5#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
6pub struct GpuPrimitiveInstance {
7 /// Destination physical rectangle `[x, y, width, height]` (layer-local or post-scroll).
8 #[get(type(copy))]
9 pub(crate) rect: [f32; 4],
10 /// Exact scissor/clip bounds `[x0, y0, x1, y1]` in physical pixels.
11 #[get(type(copy))]
12 pub(crate) clip_rect: [f32; 4],
13 /// Packed premultiplied RGBA8 primary color (or linear gradient stop 0).
14 #[get(type(copy))]
15 pub(crate) color_rgba: u32,
16 /// Packed premultiplied RGBA8 secondary color (border color, gradient stop 1, shadow, or packed vertex anchor).
17 #[get(type(copy))]
18 pub(crate) aux_color_rgba: u32,
19 /// Normalized atlas/texture UV bounds `[u0, v0, u1, v1]` in `[0..=65535]` (or packed line/triangle vertex coordinates).
20 #[get(type(copy))]
21 pub(crate) uv_rect: [u16; 4],
22 /// Packed Q12.4 fixed-point corner radii `[r_tl, r_tr, r_br, r_bl]` (`1/16` px units) or shape parameters.
23 #[get(type(copy))]
24 pub(crate) radii_border: [u16; 4],
25 /// Bitfield: `bits[0..4] = PrimKind`, `bits[4..16] = clip_mask_id / sub_kind`, `bits[16..24] = tex_slot`, `bits[24..32] = layer_id`.
26 #[get(type(copy))]
27 pub(crate) kind_flags: u32,
28 /// Packed IEEE-754 `f16x2` `(stroke_or_blur, angle_or_pad)` or effect-table index.
29 #[get(type(copy))]
30 pub(crate) extra_param: u32,
31}
32
33/// Per-layer 16-byte uniform buffer uploading physical viewport dimensions and GPU scroll offset.
34#[repr(C)]
35#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
36pub struct GpuLayerUniform {
37 /// Physical viewport `[width, height]` in pixels.
38 #[get(type(copy))]
39 pub(crate) viewport_size: [f32; 2],
40 /// Retained scroll-layer translation `[scroll_x, scroll_y]` in physical pixels.
41 #[get(type(copy))]
42 pub(crate) scroll_offset: [f32; 2],
43}
44
45/// Effect-dependency Dual-Kawase / separable Gaussian `BackdropBlur` pass descriptor executed on GPU.
46#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
47pub struct GpuBackdropBlurPass {
48 /// Destination blur card bounds in physical pixels.
49 #[get(type(copy))]
50 pub(crate) bounds: Rect,
51 /// Inflated input sampling halo (`bounds.inflate(blur_radius)`) tracking exact effect dependencies.
52 #[get(type(copy))]
53 pub(crate) input_bounds: Rect,
54 /// Active physical scissor clip rectangle.
55 #[get(type(copy))]
56 pub(crate) clip_rect: Rect,
57 /// Per-corner physical clip radii `[tl, tr, br, bl]`.
58 #[get(type(copy))]
59 pub(crate) radii: [f32; 4],
60 /// Full configured blur radius in physical pixels (never degraded).
61 #[get(type(copy))]
62 pub(crate) blur_radius: f32,
63 /// Owning retained layer identifier.
64 #[get(type(copy))]
65 pub(crate) layer_id: u8,
66}
67
68/// Tightly packed GPU instance payload uploaded directly to Metal, Vulkan, D3D12, WebGPU, or WebGL2 buffers.
69#[repr(C)]
70#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
71pub struct GpuQuadInstance {
72 /// Destination bounds `[x, y, width, height]` in physical pixels.
73 #[get(type(copy))]
74 pub(crate) rect: [f32; 4],
75 /// Clip bounds `[x0, y0, x1, y1]` in physical pixels.
76 #[get(type(copy))]
77 pub(crate) clip: [f32; 4],
78 /// Primary normalized RGBA color.
79 #[get(type(copy))]
80 pub(crate) color: [f32; 4],
81 /// Secondary color (border color or gradient end color).
82 #[get(type(copy))]
83 pub(crate) secondary_color: [f32; 4],
84 /// Corner radii `[tl, tr, br, bl]` in physical pixels.
85 #[get(type(copy))]
86 pub(crate) radii: [f32; 4],
87 /// Border width or blur radius in physical pixels.
88 #[get(type(copy))]
89 pub(crate) stroke_or_blur: f32,
90 /// Gradient angle in radians.
91 #[get(type(copy))]
92 pub(crate) angle_rad: f32,
93 /// Encoded `GpuPrimitiveKind` discriminant.
94 #[get(type(copy))]
95 pub(crate) kind: u32,
96 /// Padding for 16-byte GPU std140/std430 alignment.
97 #[get(type(copy))]
98 pub(crate) reserved: u32,
99}
100
101/// Coalesced instanced GPU draw batch submitted as a single hardware draw call.
102#[derive(Clone, Data, Debug, Default, PartialEq)]
103pub struct GpuBatch {
104 /// Active scissor rectangle in physical pixels.
105 #[get(type(copy))]
106 pub(crate) scissor: Rect,
107 /// Instanced legacy 96-byte quad stream belonging to this batch.
108 pub(crate) instances: Vec<GpuQuadInstance>,
109 /// Unified 64-byte `GpuPrimitiveInstance` stream uploaded directly to GPU instance buffers.
110 pub(crate) primitives: Vec<GpuPrimitiveInstance>,
111 /// Retained scroll-layer offset `[scroll_x, scroll_y]` bound as vertex uniform for this batch.
112 #[get(type(copy))]
113 pub(crate) scroll_offset: [f32; 2],
114 /// Bound texture array/slot identifier for this batch (`0` = default R8/RGBA8 glyph atlases).
115 #[get(type(copy))]
116 pub(crate) texture_slot: u8,
117 /// Owning retained layer identifier (`0` = root layer).
118 #[get(type(copy))]
119 pub(crate) layer_id: u8,
120}
121
122/// Recording GPU driver used on headless targets and as a hardware-contract validator.
123#[derive(Clone, Data, Debug, Default)]
124pub struct RecordingGpuDriver {
125 /// Emulated or bound graphics backend tag.
126 #[get(type(copy))]
127 pub(crate) backend_kind: GraphicsBackend,
128 /// Total draw batches submitted across frames.
129 #[get(type(copy))]
130 pub(crate) total_draw_calls: usize,
131 /// Total GPU quad instances submitted in the most recent frame.
132 #[get(type(copy))]
133 pub(crate) last_instance_count: usize,
134 /// Last clear color submitted.
135 #[get(type(copy))]
136 pub(crate) last_clear: Color,
137}
138
139/// Per-batch coalescing metadata tracking whether all queued instances are unclipped within `bounds`.
140#[derive(Clone, Copy, Debug, Default)]
141pub(crate) struct GpuBatchCoalesceState {
142 /// True only while every instance in the active tail batch lies strictly inside its safe unclipped region.
143 pub(crate) all_unclipped: bool,
144 /// True when the active tail batch contains a backdrop-sampling primitive requiring strict scissor isolation.
145 pub(crate) has_backdrop_blur: bool,
146 /// Conservative physical bounding box covering all instances in the active tail batch.
147 pub(crate) bounds: Rect,
148 /// Active retained-layer scroll offset propagated into batch uniforms.
149 pub(crate) scroll_offset: [f32; 2],
150 /// Active retained-layer identifier encoded in `GpuPrimitiveInstance::kind_flags`.
151 pub(crate) layer_id: u8,
152}
153
154/// Active physical clip scope pairing the scissor rectangle with its corner-free interior safe rectangle and encoded per-corner rounded-clip mask.
155#[derive(Clone, Copy, Debug, Default)]
156pub(crate) struct GpuClipEntry {
157 /// Intersected physical scissor rectangle.
158 pub(crate) scissor: Rect,
159 /// Conservative interior safe rectangle strictly clear of any active rounded-clip corners.
160 pub(crate) safe_inner: Rect,
161 /// Packed 10-bit rounded-clip descriptor (`bits[0..4] = TL/TR/BR/BL active mask`, `bits[4..10] = physical radius * 2`).
162 pub(crate) rounded_clip_bits: u16,
163}
164
165/// Hardware GPU renderer compiling `DisplayList` streams into order-preserving coalesced instanced `GpuBatch` calls.
166#[derive(Data, Debug, Default)]
167pub struct HardwareRenderer {
168 /// Active physical OS GPU driver handling shader compilation and batch submission.
169 pub(crate) driver: NativeGpuDriver,
170 /// Reusable batch scratch buffer avoiding per-frame allocations.
171 #[get(pub(crate))]
172 #[get_mut(pub(crate))]
173 #[set(pub(crate))]
174 pub(crate) batches: Vec<GpuBatch>,
175 /// Count of active `GpuBatch` slots populated for the latest frame so inner `Vec` capacities persist across frames.
176 #[get(type(copy))]
177 #[get_mut(skip)]
178 #[set(pub(crate))]
179 pub(crate) active_batches: usize,
180 /// Persistent physical clip-rectangle and safe-inner stack reused across frames without heap reallocation.
181 #[get(skip)]
182 #[get_mut(skip)]
183 #[set(skip)]
184 pub(crate) clip_stack: Vec<GpuClipEntry>,
185 /// Number of draw batches submitted in the most recent frame.
186 #[get(type(copy))]
187 #[get_mut(skip)]
188 #[set(skip)]
189 pub(crate) last_submitted_batches: usize,
190 /// Number of adjacent cross-clip batch splits eliminated via order-preserving coalescing in the latest frame.
191 #[get(type(copy))]
192 #[get_mut(skip)]
193 #[set(skip)]
194 pub(crate) last_coalesced_merges: usize,
195 /// Number of completely off-clip instances culled prior to GPU upload in the latest frame.
196 #[get(type(copy))]
197 #[get_mut(skip)]
198 #[set(skip)]
199 pub(crate) last_culled_instances: usize,
200 /// Number of `GpuQuadInstance` records uploaded in the latest frame.
201 #[get(type(copy))]
202 #[get_mut(skip)]
203 #[set(skip)]
204 pub(crate) last_uploaded_instances: usize,
205 /// Total instance payload bytes uploaded in the latest frame (`last_uploaded_instances * GPU_QUAD_INSTANCE_BYTES`).
206 #[get(type(copy))]
207 #[get_mut(skip)]
208 #[set(skip)]
209 pub(crate) last_uploaded_bytes: usize,
210 /// Optional software readback mirror used for deterministic pixel-parity testing.
211 pub(crate) readback: SoftwareRenderer,
212 /// Whether readback mirroring is enabled.
213 #[get(type(copy))]
214 pub(crate) enable_readback: bool,
215 /// Bounded GPU staging buffer ring, persistent scroll tile cache, and fence-deferred reclamation manager.
216 pub(crate) resource_ring: GpuResourceRing,
217 /// Cumulative count of frames rendered directly on the GPU path with zero CPU RGBA mirror generation.
218 #[get(type(copy))]
219 #[get_mut(skip)]
220 #[set(skip)]
221 pub(crate) direct_gpu_frames: u64,
222 /// Cumulative count of frames that also executed the CPU software readback mirror.
223 #[get(type(copy))]
224 #[get_mut(skip)]
225 #[set(skip)]
226 pub(crate) cpu_readback_frames: u64,
227 /// CPU RGBA framebuffer bytes generated on the most recent frame (`0` in direct GPU mode).
228 #[get(type(copy))]
229 #[get_mut(skip)]
230 #[set(skip)]
231 pub(crate) last_cpu_rgba_upload_bytes: usize,
232 /// True when the most recently compiled frame contained an effect requiring full CPU reference fallback.
233 #[get(type(copy))]
234 #[get_mut(skip)]
235 #[set(skip)]
236 pub(crate) has_unsupported_effect: bool,
237 /// Monotonic GPU submission fence identifier assigned to the latest rendered frame.
238 #[get(type(copy))]
239 #[get_mut(skip)]
240 #[set(skip)]
241 pub(crate) last_fence_id: u64,
242 /// Active GPU effect-dependency `BackdropBlur` pass queue populated for the latest frame.
243 pub(crate) blur_passes: Vec<GpuBackdropBlurPass>,
244 /// Active retained-layer scroll offset `[scroll_x, scroll_y]` propagated to GPU layer uniforms.
245 #[get(type(copy))]
246 pub(crate) active_scroll_offset: [f32; 2],
247 /// Active retained layer identifier (`0` = root).
248 #[get(type(copy))]
249 pub(crate) active_layer_id: u8,
250 /// Packed 64-byte `GpuPrimitiveInstance` byte payload uploaded in the latest frame.
251 #[get(type(copy))]
252 #[get_mut(skip)]
253 #[set(skip)]
254 pub(crate) last_uploaded_primitive_bytes: usize,
255}