euv_core/render/hardware/struct.rs
1use super::*;
2
3/// Tightly packed GPU instance payload uploaded directly to Metal, Vulkan, D3D12, WebGPU, or WebGL2 buffers.
4#[repr(C)]
5#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
6pub struct GpuQuadInstance {
7 /// Destination bounds `[x, y, width, height]` in physical pixels.
8 #[get(type(copy))]
9 pub(crate) rect: [f32; 4],
10 /// Clip bounds `[x0, y0, x1, y1]` in physical pixels.
11 #[get(type(copy))]
12 pub(crate) clip: [f32; 4],
13 /// Primary normalized RGBA color.
14 #[get(type(copy))]
15 pub(crate) color: [f32; 4],
16 /// Secondary color (border color or gradient end color).
17 #[get(type(copy))]
18 pub(crate) secondary_color: [f32; 4],
19 /// Corner radii `[tl, tr, br, bl]` in physical pixels.
20 #[get(type(copy))]
21 pub(crate) radii: [f32; 4],
22 /// Border width or blur radius in physical pixels.
23 #[get(type(copy))]
24 pub(crate) stroke_or_blur: f32,
25 /// Gradient angle in radians.
26 #[get(type(copy))]
27 pub(crate) angle_rad: f32,
28 /// Encoded `GpuPrimitiveKind` discriminant.
29 #[get(type(copy))]
30 pub(crate) kind: u32,
31 /// Padding for 16-byte GPU std140/std430 alignment.
32 #[get(type(copy))]
33 pub(crate) reserved: u32,
34}
35
36/// Coalesced instanced GPU draw batch submitted as a single hardware draw call.
37#[derive(Clone, Data, Debug, Default, PartialEq)]
38pub struct GpuBatch {
39 /// Active scissor rectangle in physical pixels.
40 #[get(type(copy))]
41 pub(crate) scissor: Rect,
42 /// Instanced quad stream belonging to this batch.
43 pub(crate) instances: Vec<GpuQuadInstance>,
44}
45
46/// Recording GPU driver used on headless targets and as a hardware-contract validator.
47#[derive(Clone, Data, Debug, Default)]
48pub struct RecordingGpuDriver {
49 /// Emulated or bound graphics backend tag.
50 #[get(type(copy))]
51 pub(crate) backend_kind: GraphicsBackend,
52 /// Total draw batches submitted across frames.
53 #[get(type(copy))]
54 pub(crate) total_draw_calls: usize,
55 /// Total GPU quad instances submitted in the most recent frame.
56 #[get(type(copy))]
57 pub(crate) last_instance_count: usize,
58 /// Last clear color submitted.
59 #[get(type(copy))]
60 pub(crate) last_clear: Color,
61}
62
63/// Per-batch coalescing metadata tracking whether all queued instances are unclipped within `bounds`.
64#[derive(Clone, Copy, Debug, Default)]
65pub(crate) struct GpuBatchCoalesceState {
66 /// True only while every instance in the active tail batch lies strictly inside its safe unclipped region.
67 pub(crate) all_unclipped: bool,
68 /// Conservative physical bounding box covering all instances in the active tail batch.
69 pub(crate) bounds: Rect,
70}
71
72/// Active physical clip scope pairing the scissor rectangle with its corner-free interior safe rectangle.
73#[derive(Clone, Copy, Debug, Default)]
74pub(crate) struct GpuClipEntry {
75 /// Intersected physical scissor rectangle.
76 pub(crate) scissor: Rect,
77 /// Conservative interior safe rectangle strictly clear of any active rounded-clip corners.
78 pub(crate) safe_inner: Rect,
79}
80
81/// Hardware GPU renderer compiling `DisplayList` streams into order-preserving coalesced instanced `GpuBatch` calls.
82#[derive(Data, Debug, Default)]
83pub struct HardwareRenderer {
84 /// Active physical OS GPU driver handling shader compilation and batch submission.
85 pub(crate) driver: NativeGpuDriver,
86 /// Reusable batch scratch buffer avoiding per-frame allocations.
87 #[get(pub(crate))]
88 #[get_mut(pub(crate))]
89 #[set(pub(crate))]
90 pub(crate) batches: Vec<GpuBatch>,
91 /// Count of active `GpuBatch` slots populated for the latest frame so inner `Vec` capacities persist across frames.
92 #[get(type(copy))]
93 #[get_mut(skip)]
94 #[set(pub(crate))]
95 pub(crate) active_batches: usize,
96 /// Persistent physical clip-rectangle and safe-inner stack reused across frames without heap reallocation.
97 #[get(skip)]
98 #[get_mut(skip)]
99 #[set(skip)]
100 pub(crate) clip_stack: Vec<GpuClipEntry>,
101 /// Number of draw batches submitted in the most recent frame.
102 #[get(type(copy))]
103 #[get_mut(skip)]
104 #[set(skip)]
105 pub(crate) last_submitted_batches: usize,
106 /// Number of adjacent cross-clip batch splits eliminated via order-preserving coalescing in the latest frame.
107 #[get(type(copy))]
108 #[get_mut(skip)]
109 #[set(skip)]
110 pub(crate) last_coalesced_merges: usize,
111 /// Number of completely off-clip instances culled prior to GPU upload in the latest frame.
112 #[get(type(copy))]
113 #[get_mut(skip)]
114 #[set(skip)]
115 pub(crate) last_culled_instances: usize,
116 /// Number of `GpuQuadInstance` records uploaded in the latest frame.
117 #[get(type(copy))]
118 #[get_mut(skip)]
119 #[set(skip)]
120 pub(crate) last_uploaded_instances: usize,
121 /// Total instance payload bytes uploaded in the latest frame (`last_uploaded_instances * GPU_QUAD_INSTANCE_BYTES`).
122 #[get(type(copy))]
123 #[get_mut(skip)]
124 #[set(skip)]
125 pub(crate) last_uploaded_bytes: usize,
126 /// Optional software readback mirror used for deterministic pixel-parity testing.
127 pub(crate) readback: SoftwareRenderer,
128 /// Whether readback mirroring is enabled.
129 #[get(type(copy))]
130 pub(crate) enable_readback: bool,
131}