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/// 32-byte Dual-Kawase blur uniform block shared across Metal, HLSL D3D11, and WGSL shaders.
46#[repr(C)]
47#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
48pub struct GpuBlurUniforms {
49 /// Reciprocal source texture dimensions `[1.0 / width, 1.0 / height]`.
50 #[get(type(copy))]
51 pub(crate) texel_size: [f32; 2],
52 /// Dual-Kawase tap radius in source texels.
53 #[get(type(copy))]
54 pub(crate) blur_offset: f32,
55 /// Pass mode (`0` = downsample, `1` = upsample, `2` = opaque 1:1 copy).
56 #[get(type(copy))]
57 pub(crate) pass_mode: u32,
58 /// Clamped normalized active clip bounds `[min_u, min_v, max_u, max_v]` preventing kernel bleed across clips.
59 #[get(type(copy))]
60 pub(crate) clip_uv: [f32; 4],
61}
62
63/// Effect-dependency Dual-Kawase / separable Gaussian `BackdropBlur` pass descriptor executed on GPU.
64#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
65pub struct GpuBackdropBlurPass {
66 /// Destination blur card bounds in physical pixels.
67 #[get(type(copy))]
68 pub(crate) bounds: Rect,
69 /// Inflated input sampling halo (`bounds.inflate(blur_radius)`) tracking exact effect dependencies.
70 #[get(type(copy))]
71 pub(crate) input_bounds: Rect,
72 /// Active physical scissor clip rectangle.
73 #[get(type(copy))]
74 pub(crate) clip_rect: Rect,
75 /// Per-corner physical clip radii `[tl, tr, br, bl]`.
76 #[get(type(copy))]
77 pub(crate) radii: [f32; 4],
78 /// Full configured blur radius in physical pixels (never degraded).
79 #[get(type(copy))]
80 pub(crate) blur_radius: f32,
81 /// Owning retained layer identifier.
82 #[get(type(copy))]
83 pub(crate) layer_id: u8,
84}
85
86/// Tightly packed GPU instance payload uploaded directly to Metal, Vulkan, D3D12, WebGPU, or WebGL2 buffers.
87#[repr(C)]
88#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
89pub struct GpuQuadInstance {
90 /// Destination bounds `[x, y, width, height]` in physical pixels.
91 #[get(type(copy))]
92 pub(crate) rect: [f32; 4],
93 /// Clip bounds `[x0, y0, x1, y1]` in physical pixels.
94 #[get(type(copy))]
95 pub(crate) clip: [f32; 4],
96 /// Primary normalized RGBA color.
97 #[get(type(copy))]
98 pub(crate) color: [f32; 4],
99 /// Secondary color (border color or gradient end color).
100 #[get(type(copy))]
101 pub(crate) secondary_color: [f32; 4],
102 /// Corner radii `[tl, tr, br, bl]` in physical pixels.
103 #[get(type(copy))]
104 pub(crate) radii: [f32; 4],
105 /// Border width or blur radius in physical pixels.
106 #[get(type(copy))]
107 pub(crate) stroke_or_blur: f32,
108 /// Gradient angle in radians.
109 #[get(type(copy))]
110 pub(crate) angle_rad: f32,
111 /// Encoded `GpuPrimitiveKind` discriminant.
112 #[get(type(copy))]
113 pub(crate) kind: u32,
114 /// Padding for 16-byte GPU std140/std430 alignment.
115 #[get(type(copy))]
116 pub(crate) reserved: u32,
117}
118
119/// Coalesced instanced GPU draw batch submitted as a single hardware draw call.
120#[derive(Clone, Data, Debug, Default, PartialEq)]
121pub struct GpuBatch {
122 /// Active scissor rectangle in physical pixels.
123 #[get(type(copy))]
124 pub(crate) scissor: Rect,
125 /// Instanced legacy 96-byte quad stream belonging to this batch.
126 pub(crate) instances: Vec<GpuQuadInstance>,
127 /// Unified 64-byte `GpuPrimitiveInstance` stream uploaded directly to GPU instance buffers.
128 pub(crate) primitives: Vec<GpuPrimitiveInstance>,
129 /// Retained scroll-layer offset `[scroll_x, scroll_y]` bound as vertex uniform for this batch.
130 #[get(type(copy))]
131 pub(crate) scroll_offset: [f32; 2],
132 /// Bound texture array/slot identifier for this batch (`0` = default R8/RGBA8 glyph atlases).
133 #[get(type(copy))]
134 pub(crate) texture_slot: u8,
135 /// Owning retained layer identifier (`0` = root layer).
136 #[get(type(copy))]
137 pub(crate) layer_id: u8,
138}
139
140/// Recording GPU driver used on headless targets and as a hardware-contract validator.
141#[derive(Clone, Data, Debug, Default)]
142pub struct RecordingGpuDriver {
143 /// Emulated or bound graphics backend tag.
144 #[get(type(copy))]
145 pub(crate) backend_kind: GraphicsBackend,
146 /// Total draw batches submitted across frames.
147 #[get(type(copy))]
148 pub(crate) total_draw_calls: usize,
149 /// Total GPU quad instances submitted in the most recent frame.
150 #[get(type(copy))]
151 pub(crate) last_instance_count: usize,
152 /// Last clear color submitted.
153 #[get(type(copy))]
154 pub(crate) last_clear: Color,
155}
156
157/// Per-batch coalescing metadata tracking whether all queued instances are unclipped within `bounds`.
158#[derive(Clone, Copy, Debug, Default)]
159pub(crate) struct GpuBatchCoalesceState {
160 /// True only while every instance in the active tail batch lies strictly inside its safe unclipped region.
161 pub(crate) all_unclipped: bool,
162 /// True when the active tail batch contains a backdrop-sampling primitive requiring strict scissor isolation.
163 pub(crate) has_backdrop_blur: bool,
164 /// Conservative physical bounding box covering all instances in the active tail batch.
165 pub(crate) bounds: Rect,
166 /// Active retained-layer scroll offset propagated into batch uniforms.
167 pub(crate) scroll_offset: [f32; 2],
168 /// Active retained-layer identifier encoded in `GpuPrimitiveInstance::kind_flags`.
169 pub(crate) layer_id: u8,
170}
171
172/// Active physical clip scope pairing the scissor rectangle with its corner-free interior safe rectangle and encoded per-corner rounded-clip mask.
173#[derive(Clone, Copy, Debug, Default)]
174pub(crate) struct GpuClipEntry {
175 /// Intersected physical scissor rectangle.
176 pub(crate) scissor: Rect,
177 /// Conservative interior safe rectangle strictly clear of any active rounded-clip corners.
178 pub(crate) safe_inner: Rect,
179 /// Packed 10-bit rounded-clip descriptor (`bits[0..4] = TL/TR/BR/BL active mask`, `bits[4..10] = physical radius * 2`).
180 pub(crate) rounded_clip_bits: u16,
181}
182
183/// Hardware GPU renderer compiling `DisplayList` streams into order-preserving coalesced instanced `GpuBatch` calls.
184#[derive(Data, Debug, Default)]
185pub struct HardwareRenderer {
186 /// Active physical OS GPU driver handling shader compilation and batch submission.
187 pub(crate) driver: NativeGpuDriver,
188 /// Reusable batch scratch buffer avoiding per-frame allocations.
189 #[get(pub(crate))]
190 #[get_mut(pub(crate))]
191 #[set(pub(crate))]
192 pub(crate) batches: Vec<GpuBatch>,
193 /// Count of active `GpuBatch` slots populated for the latest frame so inner `Vec` capacities persist across frames.
194 #[get(type(copy))]
195 #[get_mut(skip)]
196 #[set(pub(crate))]
197 pub(crate) active_batches: usize,
198 /// Persistent physical clip-rectangle and safe-inner stack reused across frames without heap reallocation.
199 #[get(skip)]
200 #[get_mut(skip)]
201 #[set(skip)]
202 pub(crate) clip_stack: Vec<GpuClipEntry>,
203 /// Number of draw batches submitted in the most recent frame.
204 #[get(type(copy))]
205 #[get_mut(skip)]
206 #[set(skip)]
207 pub(crate) last_submitted_batches: usize,
208 /// Number of adjacent cross-clip batch splits eliminated via order-preserving coalescing in the latest frame.
209 #[get(type(copy))]
210 #[get_mut(skip)]
211 #[set(skip)]
212 pub(crate) last_coalesced_merges: usize,
213 /// Number of completely off-clip instances culled prior to GPU upload in the latest frame.
214 #[get(type(copy))]
215 #[get_mut(skip)]
216 #[set(skip)]
217 pub(crate) last_culled_instances: usize,
218 /// Number of 64-byte `GpuPrimitiveInstance` records uploaded in the latest frame.
219 #[get(type(copy))]
220 #[get_mut(skip)]
221 #[set(skip)]
222 pub(crate) last_uploaded_instances: usize,
223 /// Total instance payload bytes uploaded in the latest frame (`last_uploaded_instances * GPU_PRIMITIVE_INSTANCE_BYTES`).
224 #[get(type(copy))]
225 #[get_mut(skip)]
226 #[set(skip)]
227 pub(crate) last_uploaded_bytes: usize,
228 /// Optional software readback mirror used for deterministic pixel-parity testing.
229 pub(crate) readback: SoftwareRenderer,
230 /// Whether readback mirroring is enabled.
231 #[get(type(copy))]
232 pub(crate) enable_readback: bool,
233 /// Bounded GPU staging buffer ring, persistent scroll tile cache, and fence-deferred reclamation manager.
234 pub(crate) resource_ring: GpuResourceRing,
235 /// Cumulative count of frames rendered directly on the GPU path with zero CPU RGBA mirror generation.
236 #[get(type(copy))]
237 #[get_mut(skip)]
238 #[set(skip)]
239 pub(crate) direct_gpu_frames: u64,
240 /// Cumulative count of frames that also executed the CPU software readback mirror.
241 #[get(type(copy))]
242 #[get_mut(skip)]
243 #[set(skip)]
244 pub(crate) cpu_readback_frames: u64,
245 /// CPU RGBA framebuffer bytes generated on the most recent frame (`0` in direct GPU mode).
246 #[get(type(copy))]
247 #[get_mut(skip)]
248 #[set(skip)]
249 pub(crate) last_cpu_rgba_upload_bytes: usize,
250 /// True when the most recently compiled frame contained an effect requiring full CPU reference fallback.
251 #[get(type(copy))]
252 #[get_mut(skip)]
253 #[set(skip)]
254 pub(crate) has_unsupported_effect: bool,
255 /// Monotonic GPU submission fence identifier assigned to the latest rendered frame.
256 #[get(type(copy))]
257 #[get_mut(skip)]
258 #[set(skip)]
259 pub(crate) last_fence_id: u64,
260 /// Active GPU effect-dependency `BackdropBlur` pass queue populated for the latest frame.
261 pub(crate) blur_passes: Vec<GpuBackdropBlurPass>,
262 /// Active retained-layer scroll offset `[scroll_x, scroll_y]` propagated to GPU layer uniforms.
263 #[get(type(copy))]
264 pub(crate) active_scroll_offset: [f32; 2],
265 /// Active retained layer identifier (`0` = root).
266 #[get(type(copy))]
267 pub(crate) active_layer_id: u8,
268 /// Packed 64-byte `GpuPrimitiveInstance` byte payload uploaded in the latest frame.
269 #[get(type(copy))]
270 #[get_mut(skip)]
271 #[set(skip)]
272 pub(crate) last_uploaded_primitive_bytes: usize,
273 /// Persistent incremental R8 glyph atlas synchronized via dirty sub-rect uploads to GPU texture slot 0.
274 pub(crate) gpu_glyph_atlas: IncrementalGpuGlyphAtlas,
275 /// Persistent incremental RGBA8 image atlas synchronized via dirty sub-rect uploads to GPU texture slot 2.
276 pub(crate) gpu_image_atlas: IncrementalGpuImageAtlas,
277 /// When `true` (enabled in direct GPU mode), expands `DrawCommand::TextRun` into per-glyph UV-mapped `PrimKind::GlyphAlpha8` quads.
278 #[get(type(copy))]
279 pub(crate) per_glyph_atlas: bool,
280}