euv_core/game/pacing/struct.rs
1use super::*;
2
3/// Result returned by `FramePacingController::evaluate` for a single scheduling trigger.
4#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
5pub struct PacingDecision {
6 /// Selected pacing action.
7 #[get(type(copy))]
8 pub(crate) action: PacingAction,
9 /// Monotonic simulation delta time in seconds (`0.0` for deferred, capped, or lifecycle-only frames).
10 #[get(type(copy))]
11 pub(crate) sim_dt_secs: f32,
12 /// Monotonic simulation delta time in integer nanoseconds (`0` for deferred, capped, or lifecycle-only frames).
13 #[get(type(copy))]
14 pub(crate) sim_dt_ns: u64,
15 /// Monotonic VSync timestamp in nanoseconds associated with this decision.
16 #[get(type(copy))]
17 pub(crate) timestamp_ns: u64,
18 /// Age of the oldest unpresented pending input event in milliseconds (`0.0` when none pending).
19 #[get(type(copy))]
20 pub(crate) input_age_ms: f32,
21 /// Whether the caller should submit a rendered frame for this trigger.
22 #[get(type(copy))]
23 pub(crate) should_render: bool,
24 /// Whether simulation clocks should advance on this trigger.
25 #[get(type(copy))]
26 pub(crate) should_step_sim: bool,
27}
28
29/// Telemetry counters summarizing VSync pacing health, double-gate avoidance, and spurious-step prevention.
30#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
31pub struct FramePacingStats {
32 /// Total VSync opportunities processed.
33 #[get(type(copy))]
34 pub(crate) vsync_signals: u64,
35 /// Total complete frames submitted.
36 #[get(type(copy))]
37 pub(crate) frames_submitted: u64,
38 /// Total input/safe-area/fullscreen events cleanly deferred instead of spuriously advancing simulation.
39 #[get(type(copy))]
40 pub(crate) deferred_non_vsync_events: u64,
41 /// Total VSyncs skipped solely due to an explicit user FPS cap below display refresh rate.
42 #[get(type(copy))]
43 pub(crate) user_cap_skips: u64,
44 /// Total VSyncs deferred due to bounded in-flight frame backpressure.
45 #[get(type(copy))]
46 pub(crate) in_flight_waits: u64,
47 /// Estimated missed VSync intervals where consecutive timestamps exceeded `1.5x` the nominal period.
48 #[get(type(copy))]
49 pub(crate) missed_vsync_intervals: u64,
50 /// Number of clock time-base rebases (resume or display refresh mode switches).
51 #[get(type(copy))]
52 pub(crate) timebase_rebases: u64,
53}
54
55/// Unified single-source frame pacing controller eliminating double-gating and preventing non-VSync events from advancing game time.
56#[derive(Clone, Copy, Data, Debug, PartialEq)]
57pub struct FramePacingController {
58 /// Active hardware display refresh rate in Hertz (e.g. `60.0`, `120.0`, `144.0`, `240.0`).
59 #[get(type(copy))]
60 pub(crate) display_hz: f32,
61 /// Whether the platform present/VSync loop already paces frames natively (disables redundant software sleep/skip gates).
62 #[get(type(copy))]
63 pub(crate) native_vsync_active: bool,
64 /// Optional explicit user FPS cap (`None` = run at full display refresh rate).
65 #[get(skip)]
66 pub(crate) user_fps_cap: Option<u32>,
67 /// Maximum allowed concurrent in-flight frames (`1..=4`).
68 #[get(type(copy))]
69 pub(crate) max_in_flight_frames: u32,
70 /// Currently submitted frames awaiting present/fence completion.
71 #[get(type(copy))]
72 pub(crate) in_flight_frames: u32,
73 /// Last VSync monotonic timestamp in nanoseconds (`0` before first VSync or after rebase).
74 #[get(type(copy))]
75 pub(crate) last_vsync_ns: u64,
76 /// Last VSync timestamp at which a frame was actually submitted (`StepAndRender`), tracked separately from `last_vsync_ns`.
77 #[get(type(copy))]
78 pub(crate) last_submitted_vsync_ns: u64,
79 /// Last presented frame monotonic timestamp in nanoseconds for explicit user cap pacing.
80 #[get(type(copy))]
81 pub(crate) last_present_ns: u64,
82 /// Fixed simulation step duration in nanoseconds used to clamp `sim_dt_ns <= 2 * fixed_step_ns`.
83 #[get(type(copy))]
84 pub(crate) fixed_step_ns: u64,
85 /// Monotonic timestamp of the earliest unpresented input event (`0` when no input is pending).
86 #[get(type(copy))]
87 pub(crate) oldest_pending_input_ns: u64,
88 /// Whether a non-VSync input event marked the viewport dirty for the next VSync.
89 #[get(type(copy))]
90 pub(crate) pending_input_dirty: bool,
91 /// Whether a safe-area or fullscreen transition marked layout dirty for the next VSync.
92 #[get(type(copy))]
93 pub(crate) pending_layout_dirty: bool,
94 /// Cumulative pacing telemetry counters.
95 #[get(type(copy))]
96 pub(crate) stats: FramePacingStats,
97}