euv_core/render/config/impl.rs
1use super::*;
2
3/// Default rendering configuration (`Auto` hardware-first, `VSync`, `AnalyticalSdf`, uncapped FPS, `max_frames_in_flight = 1`).
4impl Default for RenderConfig {
5 /// Creates the recommended cross-platform `RenderConfig`.
6 ///
7 /// # Returns
8 ///
9 /// - `Self` - Default `RenderConfig`.
10 fn default() -> Self {
11 Self {
12 mode: RenderMode::Auto,
13 preferred_backend: None,
14 present_mode: PresentMode::VSync,
15 antialiasing: AntialiasingMode::AnalyticalSdf,
16 color_space: ColorSpace::Srgb,
17 dirty_rect_optimization: true,
18 tile_size: DEFAULT_TILE_SIZE,
19 max_fps: DEFAULT_MAX_FPS,
20 max_frames_in_flight: DEFAULT_MAX_FRAMES_IN_FLIGHT,
21 hdr: false,
22 direct_gpu_present: false,
23 }
24 }
25}
26
27/// Fluent builder helpers for `RenderConfig`.
28impl RenderConfig {
29 /// Creates a software-rendering configuration.
30 ///
31 /// # Returns
32 ///
33 /// - `Self` - Software-mode `RenderConfig`.
34 #[must_use]
35 pub fn software() -> Self {
36 let mut cfg: Self = Self::default();
37 cfg.set_mode(RenderMode::Software);
38 cfg.set_preferred_backend(Some(GraphicsBackend::SoftwareCpu));
39 cfg.set_direct_gpu_present(false);
40 cfg
41 }
42
43 /// Creates an explicit deterministic CPU software reference configuration for headless and visual-parity tests.
44 ///
45 /// # Returns
46 ///
47 /// - `Self` - Deterministic CPU reference `RenderConfig`.
48 #[must_use]
49 pub fn software_reference() -> Self {
50 Self::software()
51 }
52
53 /// Creates a hardware GPU rendering configuration.
54 ///
55 /// # Returns
56 ///
57 /// - `Self` - Hardware-mode `RenderConfig`.
58 #[must_use]
59 pub fn hardware() -> Self {
60 let mut cfg: Self = Self::default();
61 cfg.set_mode(RenderMode::Hardware);
62 cfg
63 }
64
65 /// Creates a hardware GPU direct-draw configuration skipping steady-state CPU RGBA mirror generation.
66 ///
67 /// # Returns
68 ///
69 /// - `Self` - Direct-draw hardware-mode `RenderConfig`.
70 #[must_use]
71 pub fn hardware_direct() -> Self {
72 let mut cfg: Self = Self::hardware();
73 cfg.set_direct_gpu_present(true);
74 cfg
75 }
76
77 /// Configures whether `Hardware` mode renders directly to the GPU without steady-state CPU RGBA readback.
78 ///
79 /// # Arguments
80 ///
81 /// - `Self` - Base render configuration.
82 /// - `bool` - `true` to enable direct GPU presentation with zero steady-state CPU RGBA mirroring.
83 ///
84 /// # Returns
85 ///
86 /// - `Self` - Updated render configuration.
87 #[must_use]
88 pub fn with_direct_gpu_present(mut self, enabled: bool) -> Self {
89 self.set_direct_gpu_present(enabled);
90 self
91 }
92
93 /// Configures an optional explicit frame-rate cap (`None` = uncapped hardware VSync).
94 ///
95 /// # Arguments
96 ///
97 /// - `Self` - Base render configuration.
98 /// - `Option<u32>` - Optional explicit FPS cap, or `None` for uncapped native refresh.
99 ///
100 /// # Returns
101 ///
102 /// - `Self` - Updated render configuration.
103 #[must_use]
104 pub fn with_max_fps(mut self, max_fps: Option<u32>) -> Self {
105 self.set_max_fps(max_fps.unwrap_or(DEFAULT_MAX_FPS));
106 self
107 }
108
109 /// Returns the configured optional frame-rate cap (`None` when uncapped).
110 ///
111 /// # Arguments
112 ///
113 /// - `&Self` - Render config.
114 ///
115 /// # Returns
116 ///
117 /// - `Option<u32>` - Explicit FPS cap, or `None` when uncapped.
118 #[must_use]
119 pub fn max_fps_limit(&self) -> Option<u32> {
120 let raw: u32 = self.get_max_fps();
121 if raw == 0 { None } else { Some(raw) }
122 }
123
124 /// Configures the bounded in-flight frame queue depth clamped to `1..=MAX_ALLOWED_FRAMES_IN_FLIGHT`.
125 ///
126 /// # Arguments
127 ///
128 /// - `Self` - Base render configuration.
129 /// - `u32` - Desired maximum frames in flight.
130 ///
131 /// # Returns
132 ///
133 /// - `Self` - Updated render configuration.
134 #[must_use]
135 pub fn with_max_frames_in_flight(mut self, max_frames_in_flight: u32) -> Self {
136 self.set_max_frames_in_flight(max_frames_in_flight.clamp(1, MAX_ALLOWED_FRAMES_IN_FLIGHT));
137 self
138 }
139
140 /// Creates a hybrid CPU-tile + GPU-compositor rendering configuration.
141 ///
142 /// # Returns
143 ///
144 /// - `Self` - Hybrid-mode `RenderConfig`.
145 #[must_use]
146 pub fn hybrid() -> Self {
147 let mut cfg: Self = Self::default();
148 cfg.set_mode(RenderMode::Hybrid);
149 cfg
150 }
151
152 /// Returns the optional preferred graphics backend.
153 ///
154 /// # Arguments
155 ///
156 /// - `&Self` - Render config.
157 ///
158 /// # Returns
159 ///
160 /// - `Option<GraphicsBackend>` - Explicit backend preference if set.
161 #[must_use]
162 pub fn preferred_backend_value(&self) -> Option<GraphicsBackend> {
163 let Self {
164 preferred_backend, ..
165 } = *self;
166 preferred_backend
167 }
168}
169
170/// Present-outcome projection helpers for `FrameStats`.
171impl FrameStats {
172 /// Returns the unified `PresentOutcome` corresponding to this frame's submission and pipelining state.
173 ///
174 /// # Arguments
175 ///
176 /// - `&Self` - Frame statistics reference.
177 ///
178 /// # Returns
179 ///
180 /// - `PresentOutcome` - Detailed presentation outcome for this frame tick.
181 #[must_use]
182 pub fn present_outcome(&self) -> PresentOutcome {
183 let submit: FrameSubmitOutcome = self.get_submit_outcome();
184 if self.get_wait_in_flight() && submit == FrameSubmitOutcome::SkippedNoDamage {
185 PresentOutcome::WaitInFlight
186 } else {
187 PresentOutcome::from_submit_outcome(submit)
188 }
189 }
190
191 /// Updates both `submit_outcome` and `wait_in_flight` consistently from `outcome`.
192 ///
193 /// # Arguments
194 ///
195 /// - `&Self` - Mutable frame statistics.
196 /// - `PresentOutcome` - Observed presentation outcome.
197 pub fn record_present_outcome(&mut self, outcome: PresentOutcome) {
198 self.set_wait_in_flight(outcome == PresentOutcome::WaitInFlight);
199 self.set_submit_outcome(outcome.to_submit_outcome());
200 }
201}