diff --git a/d3d12/crates/leonida-gpu/src/console.rs b/d3d12/crates/leonida-gpu/src/console.rs index ab7252c576..6031f8b12e 100644 --- a/d3d12/crates/leonida-gpu/src/console.rs +++ b/d3d12/crates/leonida-gpu/src/console.rs @@ -17,9 +17,33 @@ impl Console { /// advanced configuration; Series S has one range, counted as standard /// (7,776 MiB, the published console-mode figure). // shortcut: later system updates gave Series S titles more (amount not - // published here); the title sizes nothing from this figure - // (it goes by the device type), so update it if a title does. - pub const fn title_memory(self) -> (usize, usize) { + // published here). + /// + /// `LEONIDA_TITLE_MEMORY_SCALE=` (1 unless set, 1 to 2.5) tells the + /// title it has that many times as much, both ranges, in whole 2 MiB + /// pages (`title_memory_scale`). Keep it within what the PC has: at 2.5 + /// a Series X title is told 34 GB in all and 25 GB of video memory. + /// Nothing refuses or saturates on account of it: the value is clamped + /// to 1-2.5 before the title is told, the figure is only what it is told + /// (the runtime checks neither the PC's memory nor the card's against + /// it), and what the title then commits beyond what the PC has fails as + /// any commit over Windows' limit does. + /// + /// The title seems to size its own pools from the limit it reads at the start + /// (`XMemGetWorkingSetStatistics`, the adapter's description). At + /// 3840x2160 with `-RayTracing` and DLSS on Series X those pools no + /// longer hold a frame: it maps its pages one at a time, about 2,900 + /// changes of mapping a frame (the "changes of mapping per frame" line), + /// 5.6 s of kernel time a frame for the process, the card 2 % busy, 0.1 + /// to 0.2 fps. With 2 the same run reads 2.0 changes a frame and 10.5 + /// fps; the same output without ray tracing is unchanged (41.2 against + /// 41.4 fps, two runs each, by turns). RTX 5090 32 GB, 64 GB of RAM. + pub fn title_memory(self) -> (usize, usize) { + scaled(self.console_memory(), title_memory_scale()) + } + + /// The console's own figures, unscaled. + const fn console_memory(self) -> (usize, usize) { match self { Console::SeriesX => (10 * GIB, 7 * GIB / 2), Console::SeriesS => (0, 7_776 << 20), @@ -34,6 +58,24 @@ impl Console { } } +/// `LEONIDA_TITLE_MEMORY_SCALE`, read once ([`Console::title_memory`]). +fn title_memory_scale() -> f64 { + static SCALE: std::sync::OnceLock = std::sync::OnceLock::new(); + *SCALE.get_or_init(|| parse_scale(std::env::var("LEONIDA_TITLE_MEMORY_SCALE").ok().as_deref())) +} + +/// 1 for nothing or what is not a number; otherwise between 1 and 2.5. +fn parse_scale(asked: Option<&str>) -> f64 { + asked.and_then(|v| v.trim().parse::().ok()).filter(|v| v.is_finite()).map_or(1.0, |v| v.clamp(1.0, 2.5)) +} + +/// Both ranges times `scale`, each down to whole 2 MiB pages. +fn scaled((gpu_optimal, standard): (usize, usize), scale: f64) -> (usize, usize) { + const PAGE: usize = 2 << 20; + let grow = |n: usize| ((n as f64 * scale) as usize) / PAGE * PAGE; + (grow(gpu_optimal), grow(standard)) +} + static SERIES_S: AtomicBool = AtomicBool::new(false); /// Set before the title starts. @@ -48,3 +90,30 @@ pub fn current() -> Console { Console::SeriesX } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn the_scale_is_one_unless_asked_and_stays_in_bounds() { + assert_eq!(parse_scale(None), 1.0); + assert_eq!(parse_scale(Some("")), 1.0); + assert_eq!(parse_scale(Some("two")), 1.0); + assert_eq!(parse_scale(Some("NaN")), 1.0); + assert_eq!(parse_scale(Some(" 2 ")), 2.0); + assert_eq!(parse_scale(Some("0.5")), 1.0); + assert_eq!(parse_scale(Some("9")), 2.5); + } + + #[test] + fn scaled_memory_is_whole_pages_and_one_leaves_it_as_it_is() { + for console in [Console::SeriesX, Console::SeriesS] { + assert_eq!(scaled(console.console_memory(), 1.0), console.console_memory()); + } + assert_eq!(scaled(Console::SeriesX.console_memory(), 2.0), (20 * GIB, 7 * GIB)); + let (a, b) = scaled(Console::SeriesS.console_memory(), 1.3); + assert_eq!((a % (2 << 20), b % (2 << 20)), (0, 0)); + assert!(b > Console::SeriesS.console_memory().1); + } +} diff --git a/d3d12/docs/switches.md b/d3d12/docs/switches.md index 941c3b866e..8006df725e 100644 --- a/d3d12/docs/switches.md +++ b/d3d12/docs/switches.md @@ -6,7 +6,7 @@ It says which names exist and what the code's own comments say of them. It is ** settings and says nothing of what a switch gains: for that read [findings.md](findings.md) first, and [how to measure frame rates](../../docs/measuring_fps.md) before trying one. -673 names; 633 have a sentence of a comment below, the others no comment or only a bare list. +674 names; 634 have a sentence of a comment below, the others no comment or only a bare list. - **Kind**: how the code reads it, where that can be told. "see the code" is a number, a path, a list or a switch read some other way; its default is not given here. @@ -87,6 +87,7 @@ and [how to measure frame rates](../../docs/measuring_fps.md) before trying one. | `LEONIDA_SKIP_CPU_CHECK` | see the code | | | | `leonida/run.rs` | | | `LEONIDA_TELEPORT` | see the code | | | | `leonida/player.rs` +1 | Nothing leaves the machine; nothing of the title is stored here. - `LEONIDA_TELEPORT=<delay s>,<x>,<y>,<z>[,<hold ms>]` teleports once, that many seconds after start (the menu's Teleport page and `leonida.teleport` do th... | | `LEONIDA_TELEPORT_LIFT` | see the code | | | | `leonida/player.rs` | ...port page and `leonida.teleport` do the same on demand). - `LEONIDA_TELEPORT_LIFT=<metres>` is added to the target's z (a few metres above the ground, so a position slightly under it does not trap the player). - `LEONIDA... | +| `LEONIDA_TITLE_MEMORY_SCALE` | see the code | | | | `leonida-gpu/console.rs` | `LEONIDA_TITLE_MEMORY_SCALE=<x>` (1 unless set, 1 to 2.5) tells the title it has that many times as much, both ranges, in whole 2 MiB pages (`title_memory_scale`). | | `LEONIDA_TRANSLATE_ONLY` | see the code | | | | `leonida/translate.rs` | `LEONIDA_TRANSLATE_ONLY=<hash prefix>,...` translates those containers alone. | | `LEONIDA_UPSCALE` | see the code | | yes | | `leonida/run.rs` +6 | `LEONIDA_UPSCALE=stretch\|dlss`: the upscale dispatch is ours (`leonida_hle::modules::ffx`: DLSS, or a plain stretch) instead of the title's own FidelityFX passes, which are slow translated on 32-lane hosts; the rest of t... | | `LEONIDA_VICE_CITY` | see the code | | | | `leonida/player.rs` | ... a position slightly under it does not trap the player). - `LEONIDA_VICE_CITY=<x>,<y>,<z>` (or the file `vice.txt` beside the paths) is the place the menu's "To Vice City" item goes to.... |