Skip to main content

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    /// True when the active tail batch contains a backdrop-sampling primitive requiring strict scissor isolation.
69    pub(crate) has_backdrop_blur: bool,
70    /// Conservative physical bounding box covering all instances in the active tail batch.
71    pub(crate) bounds: Rect,
72}
73
74/// Active physical clip scope pairing the scissor rectangle with its corner-free interior safe rectangle.
75#[derive(Clone, Copy, Debug, Default)]
76pub(crate) struct GpuClipEntry {
77    /// Intersected physical scissor rectangle.
78    pub(crate) scissor: Rect,
79    /// Conservative interior safe rectangle strictly clear of any active rounded-clip corners.
80    pub(crate) safe_inner: Rect,
81}
82
83/// Hardware GPU renderer compiling `DisplayList` streams into order-preserving coalesced instanced `GpuBatch` calls.
84#[derive(Data, Debug, Default)]
85pub struct HardwareRenderer {
86    /// Active physical OS GPU driver handling shader compilation and batch submission.
87    pub(crate) driver: NativeGpuDriver,
88    /// Reusable batch scratch buffer avoiding per-frame allocations.
89    #[get(pub(crate))]
90    #[get_mut(pub(crate))]
91    #[set(pub(crate))]
92    pub(crate) batches: Vec<GpuBatch>,
93    /// Count of active `GpuBatch` slots populated for the latest frame so inner `Vec` capacities persist across frames.
94    #[get(type(copy))]
95    #[get_mut(skip)]
96    #[set(pub(crate))]
97    pub(crate) active_batches: usize,
98    /// Persistent physical clip-rectangle and safe-inner stack reused across frames without heap reallocation.
99    #[get(skip)]
100    #[get_mut(skip)]
101    #[set(skip)]
102    pub(crate) clip_stack: Vec<GpuClipEntry>,
103    /// Number of draw batches submitted in the most recent frame.
104    #[get(type(copy))]
105    #[get_mut(skip)]
106    #[set(skip)]
107    pub(crate) last_submitted_batches: usize,
108    /// Number of adjacent cross-clip batch splits eliminated via order-preserving coalescing in the latest frame.
109    #[get(type(copy))]
110    #[get_mut(skip)]
111    #[set(skip)]
112    pub(crate) last_coalesced_merges: usize,
113    /// Number of completely off-clip instances culled prior to GPU upload in the latest frame.
114    #[get(type(copy))]
115    #[get_mut(skip)]
116    #[set(skip)]
117    pub(crate) last_culled_instances: usize,
118    /// Number of `GpuQuadInstance` records uploaded in the latest frame.
119    #[get(type(copy))]
120    #[get_mut(skip)]
121    #[set(skip)]
122    pub(crate) last_uploaded_instances: usize,
123    /// Total instance payload bytes uploaded in the latest frame (`last_uploaded_instances * GPU_QUAD_INSTANCE_BYTES`).
124    #[get(type(copy))]
125    #[get_mut(skip)]
126    #[set(skip)]
127    pub(crate) last_uploaded_bytes: usize,
128    /// Optional software readback mirror used for deterministic pixel-parity testing.
129    pub(crate) readback: SoftwareRenderer,
130    /// Whether readback mirroring is enabled.
131    #[get(type(copy))]
132    pub(crate) enable_readback: bool,
133    /// Bounded GPU staging buffer ring, persistent scroll tile cache, and fence-deferred reclamation manager.
134    pub(crate) resource_ring: GpuResourceRing,
135    /// Cumulative count of frames rendered directly on the GPU path with zero CPU RGBA mirror generation.
136    #[get(type(copy))]
137    #[get_mut(skip)]
138    #[set(skip)]
139    pub(crate) direct_gpu_frames: u64,
140    /// Cumulative count of frames that also executed the CPU software readback mirror.
141    #[get(type(copy))]
142    #[get_mut(skip)]
143    #[set(skip)]
144    pub(crate) cpu_readback_frames: u64,
145    /// CPU RGBA framebuffer bytes generated on the most recent frame (`0` in direct GPU mode).
146    #[get(type(copy))]
147    #[get_mut(skip)]
148    #[set(skip)]
149    pub(crate) last_cpu_rgba_upload_bytes: usize,
150    /// True when the most recently compiled frame contained an effect requiring full CPU reference fallback.
151    #[get(type(copy))]
152    #[get_mut(skip)]
153    #[set(skip)]
154    pub(crate) has_unsupported_effect: bool,
155    /// Monotonic GPU submission fence identifier assigned to the latest rendered frame.
156    #[get(type(copy))]
157    #[get_mut(skip)]
158    #[set(skip)]
159    pub(crate) last_fence_id: u64,
160}