euv_core/render/fallback/struct.rs
1use super::*;
2
3/// Generation-tagged backend-agnostic resource handle shared between CPU reference and GPU direct-draw backends.
4#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
5pub struct RenderResourceHandle {
6 /// Monotonic resource identifier within the owning renderer.
7 #[get(type(copy))]
8 pub(crate) id: u64,
9 /// Reuse generation counter rejecting stale handles after reclamation.
10 #[get(type(copy))]
11 pub(crate) generation: u32,
12 /// Semantic kind of GPU/CPU render resource.
13 #[get(type(copy))]
14 pub(crate) kind: RenderResourceKind,
15 /// Tracked byte footprint of this resource.
16 #[get(type(copy))]
17 pub(crate) byte_size: usize,
18 /// Last GPU fence identifier referencing this handle (`0` when idle).
19 #[get(type(copy))]
20 pub(crate) fence_id: u64,
21}
22
23/// Immutable visual fidelity contract proving fallback never degrades shadows, blur, AA, clipping, color space, or resolution.
24#[derive(Clone, Copy, Debug, Getter, New, PartialEq)]
25pub struct RenderSemanticsContract {
26 /// Active framebuffer color space shared by CPU and GPU backends.
27 #[get(type(copy))]
28 pub(crate) color_space: ColorSpace,
29 /// Active anti-aliasing quality mode.
30 #[get(type(copy))]
31 pub(crate) antialiasing: AntialiasingMode,
32 /// Whether premultiplied linear-light alpha blending is enforced.
33 #[get(type(copy))]
34 pub(crate) premultiplied_alpha: bool,
35 /// Whether full box-shadow evaluation is enabled (must remain invariant across fallback).
36 #[get(type(copy))]
37 pub(crate) shadows_enabled: bool,
38 /// Whether full backdrop-blur evaluation is enabled (must remain invariant across fallback).
39 #[get(type(copy))]
40 pub(crate) backdrop_blur_enabled: bool,
41 /// Whether exact rounded and axis-aligned clipping is enabled (must remain invariant across fallback).
42 #[get(type(copy))]
43 pub(crate) clipping_enabled: bool,
44 /// Active physical resolution scale factor (must remain invariant across fallback).
45 #[get(type(copy))]
46 pub(crate) resolution_scale: f32,
47}
48
49/// Tunable hysteresis, dwell-time, and bounded recovery policy settings for `FallbackPolicyEngine`.
50#[derive(Clone, Copy, Data, Debug, PartialEq)]
51pub struct FallbackPolicyConfig {
52 /// Minimum dwell time in milliseconds before another cadence transition is permitted.
53 #[get(type(copy))]
54 pub(crate) min_dwell_ms: u64,
55 /// Number of consecutive over-budget frames required to step cadence down.
56 #[get(type(copy))]
57 pub(crate) overrun_streak_threshold: u32,
58 /// Number of consecutive under-budget frames required to step cadence back up.
59 #[get(type(copy))]
60 pub(crate) recovery_streak_threshold: u32,
61 /// Fraction of the next higher cadence tier's frame budget that must be met to recover upward.
62 #[get(type(copy))]
63 pub(crate) recovery_budget_ratio: f32,
64 /// Maximum bounded GPU recovery attempts before permanently switching to CPU reference rendering.
65 #[get(type(copy))]
66 pub(crate) max_gpu_recovery_attempts: u32,
67 /// Whether cadence stepping is permitted by platform and app policy.
68 #[get(type(copy))]
69 pub(crate) allow_cadence_step_down: bool,
70}
71
72/// Non-degrading runtime fallback controller governing cache trimming, hysteresis cadence stepping, and CPU reference fallback.
73#[derive(Clone, Copy, Data, Debug, PartialEq)]
74pub struct FallbackPolicyEngine {
75 /// Active policy thresholds and recovery limits.
76 #[get(type(copy))]
77 pub(crate) config: FallbackPolicyConfig,
78 /// Native display refresh rate in Hertz.
79 #[get(type(copy))]
80 pub(crate) display_refresh_hz: f32,
81 /// Currently selected presentation cadence in Hertz.
82 #[get(type(copy))]
83 pub(crate) active_cadence_hz: f32,
84 /// Monotonic timestamp in milliseconds of the previous cadence transition.
85 #[get(type(copy))]
86 pub(crate) last_cadence_change_ms: u64,
87 /// Whether a cadence transition has already occurred at least once.
88 #[get(type(copy))]
89 pub(crate) has_cadence_changed: bool,
90 /// Consecutive over-budget rendered frame counter.
91 #[get(type(copy))]
92 pub(crate) overrun_streak: u32,
93 /// Consecutive comfortably under-budget rendered frame counter.
94 #[get(type(copy))]
95 pub(crate) under_budget_streak: u32,
96 /// Whether speculative offscreen route prefetching is currently permitted.
97 #[get(type(copy))]
98 pub(crate) prefetch_enabled: bool,
99 /// Current cold-cache retention multiplier in `[0.25, 1.0]`.
100 #[get(type(copy))]
101 pub(crate) cache_retain_ratio: f32,
102 /// Number of GPU device recovery attempts consumed so far.
103 #[get(type(copy))]
104 pub(crate) gpu_recovery_attempts: u32,
105 /// Whether runtime policy has switched rendering to the full CPU reference backend.
106 #[get(type(copy))]
107 pub(crate) cpu_reference_forced: bool,
108 /// Most recent fallback action emitted by this engine.
109 #[get(type(copy))]
110 pub(crate) last_action: FallbackAction,
111 /// Current step along the 4-step non-degrading fallback ladder.
112 #[get(type(copy))]
113 pub(crate) active_ladder_step: FallbackLadderStep,
114 /// Total number of presentation cadence adjustments performed.
115 #[get(type(copy))]
116 pub(crate) total_cadence_steps: u64,
117 /// Total number of cache/prefetch trim actions triggered.
118 #[get(type(copy))]
119 pub(crate) total_cache_trims: u64,
120 /// Total number of full CPU reference backend fallbacks triggered.
121 #[get(type(copy))]
122 pub(crate) total_cpu_fallbacks: u64,
123 /// Baseline visual fidelity contract verified across every fallback decision.
124 #[get(type(copy))]
125 pub(crate) semantics_baseline: RenderSemanticsContract,
126}
127
128/// Surface generation and submission-outcome tracker retaining full pending frames across transient presentation failures.
129#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, PartialEq)]
130pub struct SurfacePresentState {
131 /// Active monotonic OS surface generation (`0` before initial surface binding).
132 #[get(type(copy))]
133 pub(crate) surface_generation: u64,
134 /// Outcome recorded by the most recent frame tick.
135 #[get(type(copy))]
136 pub(crate) last_outcome: FrameSubmitOutcome,
137 /// Detailed present outcome recorded by the most recent frame tick.
138 #[get(type(copy))]
139 pub(crate) last_present_outcome: PresentOutcome,
140 /// Surface generation on which a failed submission must be automatically retried.
141 #[get(type(copy))]
142 pub(crate) pending_retry_generation: u64,
143 /// True when a complete frame is queued for automatic retry after `SubmitFailed`.
144 #[get(type(copy))]
145 pub(crate) has_pending_retry: bool,
146 /// Consecutive retry count for the current failed submission.
147 #[get(type(copy))]
148 pub(crate) retry_attempts: u32,
149 /// Cumulative count of `FrameSubmitOutcome::Submitted` frames.
150 #[get(type(copy))]
151 pub(crate) total_submitted: u64,
152 /// Cumulative count of `FrameSubmitOutcome::SkippedNoDamage` ticks.
153 #[get(type(copy))]
154 pub(crate) total_skipped: u64,
155 /// Cumulative count of `PresentOutcome::WaitInFlight` backpressure ticks.
156 #[get(type(copy))]
157 pub(crate) total_wait_in_flight: u64,
158 /// Cumulative count of `FrameSubmitOutcome::SubmitFailed` presentations.
159 #[get(type(copy))]
160 pub(crate) total_failed: u64,
161 /// Most recent monotonic present timestamp in nanoseconds (`0` when unavailable).
162 #[get(type(copy))]
163 pub(crate) last_present_timestamp_ns: u64,
164 /// True when `last_present_timestamp_ns` holds a real presentation sample.
165 #[get(type(copy))]
166 pub(crate) has_present_timestamp: bool,
167}