euv_core/game/engine3d/tsr/struct.rs
1use super::*;
2
3/// Per-frame camera and projection descriptor consumed by `TsrUpscaler::upscale_rgba`.
4#[derive(Clone, Copy, Data, Debug)]
5pub struct TsrFrameParams {
6 /// Internal rasterized source width in pixels.
7 #[get(type(copy))]
8 pub(crate) src_width: usize,
9 /// Internal rasterized source height in pixels.
10 #[get(type(copy))]
11 pub(crate) src_height: usize,
12 /// Target native display output width in pixels.
13 #[get(type(copy))]
14 pub(crate) dst_width: usize,
15 /// Target native display output height in pixels.
16 #[get(type(copy))]
17 pub(crate) dst_height: usize,
18 /// Current camera world position.
19 #[get(type(copy))]
20 pub(crate) camera_position: Vec3,
21 /// Current camera unit forward vector.
22 #[get(type(copy))]
23 pub(crate) camera_forward: Vec3,
24 /// Current camera right basis scaled by `half_w`.
25 #[get(type(copy))]
26 pub(crate) camera_right_scaled: Vec3,
27 /// Current camera up basis scaled by `half_h`.
28 #[get(type(copy))]
29 pub(crate) camera_up_scaled: Vec3,
30 /// Current frame view-projection matrix.
31 #[get(type(copy))]
32 pub(crate) view_projection: Mat4,
33 /// Halton(2, 3) subpixel jitter offset `(jx, jy)` applied to the internal render.
34 #[get(type(copy))]
35 pub(crate) jitter_offset: (f32, f32),
36 /// RCAS contrast-adaptive sharpening strength in `[0.0, 0.5]`.
37 #[get(type(copy))]
38 pub(crate) sharpness: f32,
39}
40
41/// UE5 Temporal Super Resolution (TSR) upscaler with analytical motion vectors, YCoCg 3x3 variance clipping, depth disocclusion rejection, and RCAS sharpening.
42#[derive(Clone, Data, Debug)]
43pub struct TsrUpscaler {
44 /// Cached history output width in pixels.
45 #[get(type(copy))]
46 pub(crate) history_width: usize,
47 /// Cached history output height in pixels.
48 #[get(type(copy))]
49 pub(crate) history_height: usize,
50 /// Whether `history_rgba` and `history_inv_w` contain valid previous-frame data.
51 #[get(type(copy))]
52 pub(crate) has_history: bool,
53 /// Previous frame view-projection matrix used for analytical 2D motion vector reprojection.
54 #[get(type(copy))]
55 pub(crate) prev_view_projection: Mat4,
56 /// Total frames successfully accumulated with valid temporal history.
57 #[get(type(copy))]
58 pub(crate) accumulated_frames: u64,
59 /// Persistent full-output-resolution RGBA8 temporal history buffer.
60 #[get(skip)]
61 #[get_mut(skip)]
62 #[set(skip)]
63 pub(crate) history_rgba: Vec<u8>,
64 /// Persistent double-buffered RGBA8 scratch swapped into `history_rgba` in O(1) without single-threaded memcpy.
65 #[get(skip)]
66 #[get_mut(skip)]
67 #[set(skip)]
68 pub(crate) next_history_rgba: Vec<u8>,
69 /// Persistent full-output-resolution reverse-Z `1/w` depth history for disocclusion rejection.
70 #[get(skip)]
71 #[get_mut(skip)]
72 #[set(skip)]
73 pub(crate) history_inv_w: Vec<f32>,
74 /// Persistent swap scratch buffer storing current reverse-Z depth at output resolution.
75 #[get(skip)]
76 #[get_mut(skip)]
77 #[set(skip)]
78 pub(crate) next_inv_w: Vec<f32>,
79}
80
81/// Real-time telemetry emitted by `AdaptiveFrameGovernor` for HUD and observability diagnostics.
82#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
83pub struct FramePacingTelemetry3D {
84 /// Active target frame budget in milliseconds (`1000.0 / target_hz`).
85 #[get(type(copy))]
86 pub(crate) budget_ms: f32,
87 /// Exponential moving average frame time in milliseconds.
88 #[get(type(copy))]
89 pub(crate) ema_frame_ms: f32,
90 /// Fast-attack slow-decay high-percentile frame time estimate in milliseconds.
91 #[get(type(copy))]
92 pub(crate) p99_est_ms: f32,
93 /// Ratio of `ema_frame_ms / budget_ms`.
94 #[get(type(copy))]
95 pub(crate) budget_utilization: f32,
96 /// Current TSR/DRS internal resolution scale applied by the governor.
97 #[get(type(copy))]
98 pub(crate) effective_resolution_scale: f32,
99 /// Current additive RT probe stride bias (`0..=3`) under heavy GPU/CPU load.
100 #[get(type(copy))]
101 pub(crate) effective_rt_stride_bias: usize,
102 /// Current Nanite LOD bias multiplier applied by the governor.
103 #[get(type(copy))]
104 pub(crate) effective_lod_bias: f32,
105 /// Normalized frame stability score in `[0.0, 1.0]` (`1.0` = rock-solid zero jitter).
106 #[get(type(copy))]
107 pub(crate) stability_score: f32,
108}
109
110/// Closed-loop damped PI + asymmetric hysteresis frame-budget governor stabilizing FPS across 60/120/144/240/360/480Hz targets.
111#[derive(Clone, Copy, Data, Debug, PartialEq)]
112pub struct AdaptiveFrameGovernor {
113 /// Target refresh cadence in Hertz (`30.0..=1000.0`).
114 #[get(type(copy))]
115 pub(crate) target_hz: f32,
116 /// Minimum permissible TSR/DRS internal scale (`0.40..=1.0`).
117 #[get(type(copy))]
118 pub(crate) min_scale: f32,
119 /// Maximum permissible TSR/DRS internal scale (`0.50..=1.25`).
120 #[get(type(copy))]
121 pub(crate) max_scale: f32,
122 /// Active quantized resolution scale.
123 #[get(type(copy))]
124 pub(crate) current_scale: f32,
125 /// Active additive coarse RT probe stride bias (`0..=3`).
126 #[get(type(copy))]
127 pub(crate) rt_stride_bias: usize,
128 /// Active Nanite LOD bias multiplier (`0.75..=1.80`).
129 #[get(type(copy))]
130 pub(crate) lod_bias: f32,
131 /// Exponential moving average frame duration in milliseconds.
132 #[get(type(copy))]
133 pub(crate) ema_frame_ms: f32,
134 /// Exponential moving average absolute frame-to-frame jitter in milliseconds.
135 #[get(type(copy))]
136 pub(crate) ema_jitter_ms: f32,
137 /// High-percentile envelope tracker (`p99` estimate) in milliseconds.
138 #[get(type(copy))]
139 pub(crate) p99_est_ms: f32,
140 /// Previous raw frame duration in milliseconds for frame-to-frame delta jitter.
141 #[get(type(copy))]
142 pub(crate) last_frame_ms: f32,
143 /// Consecutive frames comfortably below budget before allowing step-up.
144 #[get(type(copy))]
145 pub(crate) under_budget_streak: u32,
146 /// Consecutive frames exceeding budget triggering graduated fallback.
147 #[get(type(copy))]
148 pub(crate) over_budget_streak: u32,
149 /// Hysteresis frame count required before stepping resolution back up.
150 #[get(type(copy))]
151 pub(crate) hysteresis_frames: u32,
152 /// Total frames observed by this governor.
153 #[get(type(copy))]
154 pub(crate) total_frames: u64,
155}