Skip to main content

euv_core/render/fallback/
enum.rs

1use super::*;
2
3/// Explicit outcome of a frame submission attempt separating idle skip, successful submit, and retryable failure.
4#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
5pub enum FrameSubmitOutcome {
6    /// No scene or surface damage required presentation on this tick.
7    #[default]
8    SkippedNoDamage,
9    /// Complete frame was successfully submitted to the active surface generation.
10    Submitted,
11    /// Presentation submission failed; the complete pending frame is retained for automatic retry on the same surface generation.
12    SubmitFailed,
13}
14
15/// Reason a runtime fallback switched execution to the full CPU reference backend.
16#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
17pub enum FallbackCpuReason {
18    /// Physical GPU device or pipeline initialization failed.
19    #[default]
20    GpuInitFailed,
21    /// GPU device or context was lost beyond bounded recovery attempts.
22    DeviceLost,
23    /// Critical GPU resource allocation failed after cache trimming.
24    CriticalAllocationFailed,
25    /// A cross-layer visual effect lacks an equivalent GPU path and cannot be safely isolated to one layer.
26    UnisolatableEffectPath,
27}
28
29/// Runtime event evaluated by `FallbackPolicyEngine` to pick a strictly non-degrading response.
30#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
31pub enum FallbackTrigger {
32    /// Host or allocator memory pressure notification.
33    MemoryPressure(MemoryPressure),
34    /// Single-frame budget overrun or cache pressure spike.
35    TransientFrameOverrun,
36    /// Sustained frame budget overrun across consecutive active frames.
37    SustainedFrameOverrun,
38    /// Active GPU backend lacks an equivalent shader path for an effect layer.
39    MissingGpuEffectPath {
40        /// Whether the effect can be isolated to a single layer with exact backdrop/blend semantics.
41        isolatable: bool,
42    },
43    /// GPU backend initialization failed.
44    GpuInitFailed,
45    /// GPU device was lost at runtime.
46    DeviceLost,
47    /// Required frame resource allocation failed.
48    AllocationFailed,
49}
50
51/// Strictly non-degrading 4-step fallback ladder state tracked by `FallbackPolicyEngine`.
52#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
53pub enum FallbackLadderStep {
54    /// Normal full-cadence GPU direct-draw execution with full prefetch and cache retention.
55    #[default]
56    Normal,
57    /// Tier 1: Speculative route prefetch cancelled and cold/offscreen caches trimmed.
58    Tier1CacheAndPrefetchTrim,
59    /// Tier 2: Presentation cadence stepped down along display-compatible tiers with hysteresis.
60    Tier2CadenceStepDown,
61    /// Tier 3: Isolated missing GPU effect layer rasterized through CPU reference with exact fidelity.
62    Tier3IsolatedCpuEffect,
63    /// Tier 4: Full-frame CPU software reference backend active after GPU init/device-loss or unisolatable effect.
64    Tier4FullCpuReference,
65}
66
67/// Strictly non-degrading action produced by `FallbackPolicyEngine` (never modifies shadows, blur, AA, clipping, or resolution).
68#[derive(Clone, Copy, Debug, Default, PartialEq)]
69pub enum FallbackAction {
70    /// Continue normal execution with no policy change.
71    #[default]
72    None,
73    /// Cancel speculative route prefetch and shrink cold/invisible cache retention while keeping all visible content identical.
74    TrimPrefetchAndColdCache {
75        /// Retained fraction of default cold cache budgets in `(0.0..=1.0]`.
76        retain_ratio: f32,
77    },
78    /// Adjust presentation cadence along display-compatible tiers with hysteresis and minimum dwell time.
79    AdjustPresentCadence {
80        /// Target presentation cadence in Hertz.
81        target_hz: f32,
82    },
83    /// Render one isolated effect layer through the full CPU reference rasterizer and composite into the GPU frame.
84    RouteLayerToCpuReference,
85    /// Switch the entire frame to the full CPU reference backend while preserving route, scroll, focus, and gesture state.
86    SwitchToCpuReference {
87        /// Structured cause for moving to CPU reference rendering.
88        reason: FallbackCpuReason,
89    },
90}
91
92/// Unified backend-agnostic resource classification shared by CPU reference and GPU direct-draw backends.
93#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
94pub enum RenderResourceKind {
95    /// Color or alpha texture image resource.
96    #[default]
97    Texture,
98    /// Vertex, index, or instanced quad GPU buffer.
99    Buffer,
100    /// Persistent cached scroll tile texture layer.
101    TileLayer,
102    /// Packed glyph coverage texture atlas.
103    GlyphAtlas,
104    /// Reusable per-frame upload staging buffer slot.
105    StagingSlot,
106}