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.
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}
162
163/// Hardware GPU renderer compiling `DisplayList` streams into order-preserving coalesced instanced `GpuBatch` calls.
164#[derive(Data, Debug, Default)]
165pub struct HardwareRenderer {
166 /// Active physical OS GPU driver handling shader compilation and batch submission.
167 pub(crate) driver: NativeGpuDriver,
168 /// Reusable batch scratch buffer avoiding per-frame allocations.
169 #[get(pub(crate))]
170 #[get_mut(pub(crate))]
171 #[set(pub(crate))]
172 pub(crate) batches: Vec<GpuBatch>,
173 /// Count of active `GpuBatch` slots populated for the latest frame so inner `Vec` capacities persist across frames.
174 #[get(type(copy))]
175 #[get_mut(skip)]
176 #[set(pub(crate))]
177 pub(crate) active_batches: usize,
178 /// Persistent physical clip-rectangle and safe-inner stack reused across frames without heap reallocation.
179 #[get(skip)]
180 #[get_mut(skip)]
181 #[set(skip)]
182 pub(crate) clip_stack: Vec<GpuClipEntry>,
183 /// Number of draw batches submitted in the most recent frame.
184 #[get(type(copy))]
185 #[get_mut(skip)]
186 #[set(skip)]
187 pub(crate) last_submitted_batches: usize,
188 /// Number of adjacent cross-clip batch splits eliminated via order-preserving coalescing in the latest frame.
189 #[get(type(copy))]
190 #[get_mut(skip)]
191 #[set(skip)]
192 pub(crate) last_coalesced_merges: usize,
193 /// Number of completely off-clip instances culled prior to GPU upload in the latest frame.
194 #[get(type(copy))]
195 #[get_mut(skip)]
196 #[set(skip)]
197 pub(crate) last_culled_instances: usize,
198 /// Number of `GpuQuadInstance` records uploaded in the latest frame.
199 #[get(type(copy))]
200 #[get_mut(skip)]
201 #[set(skip)]
202 pub(crate) last_uploaded_instances: usize,
203 /// Total instance payload bytes uploaded in the latest frame (`last_uploaded_instances * GPU_QUAD_INSTANCE_BYTES`).
204 #[get(type(copy))]
205 #[get_mut(skip)]
206 #[set(skip)]
207 pub(crate) last_uploaded_bytes: usize,
208 /// Optional software readback mirror used for deterministic pixel-parity testing.
209 pub(crate) readback: SoftwareRenderer,
210 /// Whether readback mirroring is enabled.
211 #[get(type(copy))]
212 pub(crate) enable_readback: bool,
213 /// Bounded GPU staging buffer ring, persistent scroll tile cache, and fence-deferred reclamation manager.
214 pub(crate) resource_ring: GpuResourceRing,
215 /// Cumulative count of frames rendered directly on the GPU path with zero CPU RGBA mirror generation.
216 #[get(type(copy))]
217 #[get_mut(skip)]
218 #[set(skip)]
219 pub(crate) direct_gpu_frames: u64,
220 /// Cumulative count of frames that also executed the CPU software readback mirror.
221 #[get(type(copy))]
222 #[get_mut(skip)]
223 #[set(skip)]
224 pub(crate) cpu_readback_frames: u64,
225 /// CPU RGBA framebuffer bytes generated on the most recent frame (`0` in direct GPU mode).
226 #[get(type(copy))]
227 #[get_mut(skip)]
228 #[set(skip)]
229 pub(crate) last_cpu_rgba_upload_bytes: usize,
230 /// True when the most recently compiled frame contained an effect requiring full CPU reference fallback.
231 #[get(type(copy))]
232 #[get_mut(skip)]
233 #[set(skip)]
234 pub(crate) has_unsupported_effect: bool,
235 /// Monotonic GPU submission fence identifier assigned to the latest rendered frame.
236 #[get(type(copy))]
237 #[get_mut(skip)]
238 #[set(skip)]
239 pub(crate) last_fence_id: u64,
240 /// Active GPU effect-dependency `BackdropBlur` pass queue populated for the latest frame.
241 pub(crate) blur_passes: Vec<GpuBackdropBlurPass>,
242 /// Active retained-layer scroll offset `[scroll_x, scroll_y]` propagated to GPU layer uniforms.
243 #[get(type(copy))]
244 pub(crate) active_scroll_offset: [f32; 2],
245 /// Active retained layer identifier (`0` = root).
246 #[get(type(copy))]
247 pub(crate) active_layer_id: u8,
248 /// Packed 64-byte `GpuPrimitiveInstance` byte payload uploaded in the latest frame.
249 #[get(type(copy))]
250 #[get_mut(skip)]
251 #[set(skip)]
252 pub(crate) last_uploaded_primitive_bytes: usize,
253}