Skip to main content

euv_core/render/hybrid/
struct.rs

1use super::*;
2
3/// Result of partitioning a `DisplayList` into GPU-native primitives and sparse CPU-only effect regions.
4#[derive(Clone, Data, Debug, Default, PartialEq)]
5pub struct HybridCommandPartition {
6    /// Number of commands compiled directly into GPU-native instanced batches.
7    #[get(type(copy))]
8    pub(crate) gpu_native_count: usize,
9    /// Tight physical pixel bounds for sparse CPU-only effect regions requiring tile rasterization.
10    pub(crate) cpu_effect_regions: Vec<Rect>,
11    /// Total GPU-native primitive area covered in physical pixels.
12    #[get(type(copy))]
13    pub(crate) gpu_covered_pixels: usize,
14}
15
16/// Net-gain evaluation proving whether `Hybrid` beats both pure `GpuDirect` and pure `Software`.
17#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
18pub struct HybridNetGainEstimate {
19    /// Fraction of viewport pixels covered by sparse CPU-only effect regions in `[0.0, 1.0]`.
20    #[get(type(copy))]
21    pub(crate) cpu_effect_coverage_ratio: f64,
22    /// Estimated total frame duration for the hybrid path (`cpu_tile_ms + gpu_composite_ms`).
23    #[get(type(copy))]
24    pub(crate) hybrid_total_ms: f64,
25    /// Estimated net gain in milliseconds over `min(gpu_full_ms, cpu_full_ms)` (`<= 0.0` disqualifies `Hybrid`).
26    #[get(type(copy))]
27    pub(crate) net_gain_ms: f64,
28    /// True ONLY when `cpu_effect_regions` is sparse and `Hybrid` delivers strictly positive net gain over pure GPU and pure CPU.
29    #[get(type(copy))]
30    pub(crate) should_use_hybrid: bool,
31    /// Recommended rendering backend (`Hybrid`, `GpuDirect`, or `Software`).
32    #[get(type(copy))]
33    pub(crate) recommended_candidate: RenderBackendCandidate,
34}
35
36/// Sparse-effect hybrid renderer compiling GPU-native primitives directly and rasterizing ONLY tight CPU-only effect tiles onto real `NativeGpuDriver`.
37#[derive(Data, Debug, Default)]
38pub struct HybridRenderer {
39    /// On-demand CPU tile rasterizer invoked ONLY for sparse `cpu_effect_regions` (never unconditional full-frame rasterization).
40    pub(crate) software: SoftwareRenderer,
41    /// Real physical OS GPU driver executing GPU-native 64-byte primitive batches plus tight sparse-effect tile quads.
42    pub(crate) driver: NativeGpuDriver,
43    /// Persistent incremental R8 glyph atlas synchronized via dirty sub-rect uploads to GPU texture slot 0.
44    pub(crate) gpu_glyph_atlas: IncrementalGpuGlyphAtlas,
45    /// Sparse CPU-only effect regions isolated during the most recent frame.
46    pub(crate) last_cpu_effect_regions: Vec<Rect>,
47    /// Number of GPU-native draw commands compiled directly without CPU rasterization on the most recent frame.
48    #[get(type(copy))]
49    pub(crate) last_gpu_native_commands: usize,
50    /// Number of tight CPU effect tiles rasterized and uploaded on the most recent frame (`0` when no CPU-only effects exist).
51    #[get(type(copy))]
52    pub(crate) last_cpu_tile_count: usize,
53    /// Exact tight-tile RGBA8 bytes uploaded on the most recent frame (`0` when no CPU-only effects exist).
54    #[get(type(copy))]
55    pub(crate) last_cpu_upload_bytes: usize,
56    /// Total CPU pixels rasterized on the most recent frame (`0` when no CPU-only effects exist).
57    #[get(type(copy))]
58    pub(crate) last_cpu_rasterized_pixels: usize,
59    /// Compiled 64-byte `GpuBatch` list submitted to `driver` on the most recent frame.
60    pub(crate) last_batches: Vec<GpuBatch>,
61}