Skip to main content

euv_core/render/adaptive/
enum.rs

1use super::*;
2
3/// Unified cross-platform rendering path candidate evaluated by `AdaptiveRenderRouter`.
4#[derive(
5    Clone, Copy, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
6)]
7#[serde(rename_all = "snake_case")]
8pub enum RenderBackendCandidate {
9    /// Direct GPU primitive rendering with zero steady-state CPU RGBA framebuffer mirroring.
10    GpuDirect,
11    /// GPU texture upload path presenting CPU-rasterized dirty rectangles or framebuffers.
12    GpuUpload,
13    /// Sparse CPU-local effect tiles composited alongside GPU-native primitives.
14    Hybrid,
15    /// Pure CPU analytical-SDF software rasterizer and surface blit.
16    #[default]
17    Software,
18    /// Terminal character-cell incremental diff / CLI batched pipe output (never GPU-routed).
19    Terminal,
20}
21
22/// Rollout policy governing whether adaptive routing only records shadow recommendations or performs live frame-boundary switches.
23#[derive(
24    Clone, Copy, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
25)]
26#[serde(rename_all = "snake_case")]
27pub enum AdaptiveSwitchMode {
28    /// Shadow mode (default): evaluates candidates and records recommendations + evidence without switching live.
29    #[default]
30    RecommendOnly,
31    /// Live mode: triggers seamless frame-boundary handoff once all quality, gain, dwell, and cooldown gates pass.
32    AutoSwitch,
33}
34
35/// Workload scene profile ensuring candidate comparisons always occur under matching rendering characteristics.
36#[derive(
37    Clone, Copy, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
38)]
39#[serde(rename_all = "snake_case")]
40pub enum SceneProfile {
41    /// Static or lightly updated UI surfaces.
42    #[default]
43    StaticUi,
44    /// High-refresh scrolling or retained layer translation.
45    SmoothScroll,
46    /// Complex page/route transition with warmups and portal overlays.
47    RouteTransition,
48    /// Rich media playback, vector charts, or markdown/code canvases.
49    RichMedia,
50    /// Interactive 2D game scene with HUD overlay.
51    Game2d,
52    /// Interactive 3D game scene with HUD overlay.
53    Game3d,
54    /// Scene containing sparse CPU-local effects (e.g., isolated backdrop blur) over GPU primitives.
55    SparseCpuEffect,
56    /// Terminal PTY cell grid or CLI pipe workload.
57    TerminalTui,
58}
59
60/// Explicit hardware, surface, driver, or thermal fault classification excluded from seamless-handoff success counts.
61#[derive(
62    Clone, Copy, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
63)]
64#[serde(rename_all = "snake_case")]
65pub enum FaultEventKind {
66    /// Active GPU device or graphics context was lost; triggers immediate failover skipping perf comparison.
67    #[default]
68    DeviceLost,
69    /// OS destroyed or invalidated the presentation surface.
70    SurfaceDestroyed,
71    /// Graphics driver was suspended or reset by the OS.
72    DriverSuspended,
73    /// OS or hardware thermal throttling reduced sustained clock/refresh headroom.
74    ThermalThrottled,
75}
76
77/// Specific invariant violated when a candidate fails the visual-equivalence or capability gate.
78#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
79pub enum VisualEquivalenceFailure {
80    /// Candidate is not supported on the host platform.
81    BackendUnsupported,
82    /// Candidate is a simulated profile lacking on-device GPU direct-present verification.
83    UnverifiedSimulatedGpu,
84    /// Font rasterization or shaping metrics are not equivalent.
85    FontMismatch,
86    /// Layout geometry or subpixel alignment is not equivalent.
87    LayoutMismatch,
88    /// Output color space or gamma blending is not equivalent.
89    ColorSpaceMismatch,
90    /// Anti-aliasing coverage quality is not equivalent.
91    AntialiasingMismatch,
92    /// Drop-shadow rendering is not equivalent.
93    ShadowMismatch,
94    /// Backdrop-blur quality or coverage is not equivalent.
95    BackdropBlurMismatch,
96    /// Visible tile coverage or clipping is not equivalent.
97    VisibleTileMismatch,
98    /// Media/image decoding or sampling quality is not equivalent.
99    MediaQualityMismatch,
100}
101
102/// Lifecycle stage of a frame-boundary backend handoff managed by `HandoffCoordinator`.
103#[derive(
104    Clone, Copy, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
105)]
106#[serde(rename_all = "snake_case")]
107pub enum HandoffStage {
108    /// No handoff in progress.
109    #[default]
110    Idle,
111    /// Candidate backend is warming up on the exact `scene_version` using per-frame budget slices while old backend presents.
112    WarmingUp,
113    /// Candidate warmup completed and awaits frame-boundary first-frame verification.
114    ReadyForBoundary,
115    /// Frame-boundary takeover occurred; old resources remain alive pending post-handoff present confirmation and sync fence.
116    AwaitingPresentConfirmation,
117    /// Post-handoff present confirmed and sync fence completed; old resources released cleanly.
118    Committed,
119    /// Handoff aborted cleanly due to failure, mismatch, staleness, deadline miss, timeout, or fault.
120    Aborted,
121}
122
123/// Explicit diagnostic reason why a frame-boundary handoff aborted and remained on the old backend.
124#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
125pub enum HandoffAbortReason {
126    /// Candidate backend failed initialization.
127    InitFailed,
128    /// Candidate failed to produce its first frame.
129    FirstFrameFailed,
130    /// Candidate first-frame dimensions diverged from current viewport dimensions.
131    DimensionMismatch,
132    /// Candidate first-frame DPI scale factor diverged from current scale factor.
133    ScaleFactorMismatch,
134    /// Candidate first-frame `scene_version` became stale before boundary commit.
135    StaleSceneVersion,
136    /// Candidate first frame exceeded the active frame deadline.
137    MissedDeadline,
138    /// Candidate warmup exceeded `max_warmup_timeout_ms`.
139    TimedOut,
140    /// Candidate failed the visual-equivalence gate before commit.
141    VisualEquivalenceFailed,
142    /// An external hardware, surface, driver, or thermal fault interrupted the handoff.
143    FaultInterrupted,
144}
145
146/// Runtime degradation trigger permitting a headroom-gated short candidate probe.
147#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
148pub enum ProbeTriggerReason {
149    /// Sustained consecutive frame deadline misses observed.
150    SustainedDeadlineMiss,
151    /// Observed input-to-present latency degraded beyond the configured ratio.
152    InputLatencyDegraded,
153}
154
155/// Outcome classification produced by each stage of `AdaptiveRenderRouter`.
156#[derive(
157    Clone, Copy, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
158)]
159#[serde(rename_all = "snake_case")]
160pub enum AdaptiveDecisionKind {
161    /// Retain the currently active backend without changes.
162    #[default]
163    KeepCurrent,
164    /// Startup selected a previously verified winner from `WinnerCache`.
165    UseCachedWinner,
166    /// Startup selected visually-equivalent `GpuDirect` as its first trial candidate.
167    StartupGpuDirect,
168    /// Startup candidate failed initialization or first frame; failed over immediately.
169    StartupFailover,
170    /// Shadow mode (`RecommendOnly`) logged a verified recommendation without live switching.
171    RecommendSwitch,
172    /// Live mode (`AutoSwitch`) authorized starting a seamless frame-boundary handoff.
173    BeginHandoff,
174    /// Seamless frame-boundary handoff committed cleanly on matching geometry and scene version.
175    CommitHandoff,
176    /// Handoff aborted cleanly; old backend continues presenting without interruption.
177    AbortHandoff,
178    /// Immediate fault failover (e.g., `DeviceLost`) retaining last valid frame when window valid.
179    FaultFailover,
180    /// Single-channel host locked permanently to its sole channel with probing disabled.
181    LockedSingleChannel,
182    /// Probe suppressed because system lacked idle time or explicit frame headroom.
183    ProbeSkippedNoHeadroom,
184    /// Short candidate probe authorized during idle or explicit frame headroom.
185    ProbeStarted,
186}