diff --git a/.gitignore b/.gitignore index ac9edc3..1be7f5e 100644 --- a/.gitignore +++ b/.gitignore @@ -76,3 +76,9 @@ *.swp Thumbs.db .DS_Store + +# NVIDIA's own files (Get-NVIDIA-DLSS.cmd fetches them from NVIDIA; never part of this repository) +/nvidia-sdk/ +# What the F1 menu saved +/victory-settings.txt +/victory-settings.*.txt diff --git a/Get-NVIDIA-DLSS.cmd b/Get-NVIDIA-DLSS.cmd new file mode 100644 index 0000000..757ff62 --- /dev/null +++ b/Get-NVIDIA-DLSS.cmd @@ -0,0 +1,8 @@ +@echo off +rem Downloads the NVIDIA files that DLSS and DLSS frame generation need (about 70 MB) from NVIDIA's own +rem GitHub and puts them where the launcher looks for them (nvidia-sdk\ in this folder). Run it once. +rem They are NVIDIA's files under NVIDIA's licences, which are saved beside them; this repository does +rem not contain them. Without them the game still runs, with its own upscaling and no frame generation. +powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\get-nvidia-sdks.ps1" %* +echo. +pause \ No newline at end of file diff --git a/README.md b/README.md index 72926e7..0ec0628 100644 --- a/README.md +++ b/README.md @@ -1,187 +1,181 @@ -# foxhound +# VIctory on NVIDIA -A fork of [VIctory](https://github.com/Marvisak/VIctory), a compatibility layer that runs an Xbox Series title -natively on Windows from files **you** supply. foxhound is tuned for **NVIDIA RTX** GPUs: DLSS Super Resolution and -DLSS Frame Generation in place of the title's own upscaling, the Series X profile at a native 2560x1440, and fewer -stalls at scene cuts. +> **Before you play** +> +> - **You must install DLSS yourself:** run `Get-NVIDIA-DLSS.cmd` once (it is +> in this folder; a double click does it), or have your AI assistant run it +> for you. It downloads NVIDIA's DLSS and frame generation files, about 70 MB, +> from NVIDIA's own GitHub; they are not part of this repository. Without +> them the game still runs, with its own upscaling and no frame generation. +> - **F1 in the game brings up the settings menu** (arrow keys pick and +> change, Enter does it). +> +> The steps are under [How to run it](#how-to-run-it). -> **This repository contains no game files, code or assets.** You need your own legally obtained copy of the -> title. foxhound is not affiliated with or endorsed by the title's developer or publisher, nor by NVIDIA. -> See [docs/asset-policy.md](docs/asset-policy.md). +A fork of [VIctory](https://github.com/Marvisak/VIctory), a compatibility layer +that runs an Xbox Series title natively on Windows from files **you** supply, +tuned for **NVIDIA RTX** cards. + +> **This repository contains no game files, code or assets.** You need your +> own legally obtained copy of the title. It is not affiliated with or endorsed +> by the title's developer or publisher, nor by NVIDIA. See +> [docs/asset-policy.md](docs/asset-policy.md). + +## New on 2026-11-26: foxhound is the base + +On 2026-11-26 this fork moved onto +[readmet3xt-lab/foxhound](https://github.com/readmet3xt-lab/foxhound) +(`02fc18a`, GPL-3.0-or-later). On the same PC it ran the same rooms at close to +twice the frame rate of what this fork had, at a higher resolution, so its +tree is now this one's, with its history kept, and this fork's own additions +are on top. What foxhound is and how it got there is in its own README, kept as +[docs/README-foxhound.md](docs/README-foxhound.md); its measurements are in +[docs/findings.md](docs/findings.md). + +What foxhound brings: + +- the Series X profile at a native 2560x1440; +- DLSS Super Resolution and DLSS Frame Generation through NVIDIA Streamline, + loaded when the game runs (nothing of NVIDIA's is needed to build); +- an estimate of indirect light and of reflections in place of the title's ray + tracing, and fewer stalls at scene cuts. + +What this fork adds on top: + +- **The F1 settings menu**, in every build: DLSS mode and model, frame + generation, frame rate cap, console profile, picture size, the light + estimates and the main speed switches. Changes are saved to + `victory-settings.txt` and apply at the next start; "SAVE AND RESTART NOW" + does that for you. Lines marked LIVE change at once. +- **Frame generation from 2x to 6x**, switched and changed from the menu + while playing, without a restart (`VICTORY_FRAMEGEN_X`; foxhound's is 2x, set + at the start). No more is asked than the card and driver generate. +- **No frame rate cap by default.** The title asks for 30 frames a second; + the menu's FRAME RATE CAP sets 120, 60 or the title's own 30 instead. +- **The frame rate at the top left of the picture**: the frames rendered a + second, and with frame generation the frames shown (`FPS: 28.4 FG: 170.4`). + The window's title says both too. +- **`Get-NVIDIA-DLSS.cmd`**: fetches only the eight NVIDIA files that are + loaded, about 70 MB, out of NVIDIA's 263 MB Streamline release. +- The launcher builds the layer by itself the first time. ## Where it stands -Tested on one PC: Windows 11, Ryzen 7 7800X3D, 32 GB RAM, **RTX 4070 SUPER 12 GB**, NVMe SSD; the Xbox Series -build **v1.0.2.1** of the title, Series X profile, 2560x1440 output, DLSS Quality. Frame times are the layer's -own count, in the opening scenes unless noted. +Tested on one PC: Windows 11, Ryzen 7 9800X3D, 64 GB RAM, **GeForce RTX 5070 +12 GB**; the title's Xbox Series build v1.0.2.1, Series X profile, 2560x1440 +output, DLSS Quality. Frame rates are the layer's own count, in the opening +rooms. -| | Frame time | +| | | |---|---| -| Opening, gameplay | 34-37 ms (27-30 fps); our CPU work per frame sets it | -| Opening, cutscenes | median 36-38 ms, 95th percentile 49-58 ms, no second over 100 ms | -| Open water (first boat ride) | about 47 ms (21 fps); the GPU sets it there | -| With `-FrameGen` | every frame the title renders is shown twice (2x presented) | -| Memory | about 8 GB of VRAM; 32 GB of RAM is enough, 64 GB is more comfortable | +| Opening rooms | mostly 26-30 frames a second rendered (33-38 ms a frame) | +| Frame generation | 2x to 6x on top of that: in NVIDIA's own check, exactly 2, 4 and 6 frames shown for each one rendered | +| Device losses, crashes | none in the measured runs | +| Before this base (Series S, 720p to 1080p by DLSS) | 15-17 frames a second in the same rooms | + +foxhound's own measurements, on an RTX 4070 SUPER, are in its README. What is known to be wrong: -- **No ray tracing.** The title traces its indirect light, reflections and lamp shadows in its own compute - shaders. They are off (`VICTORY_BVH_BUILDER=1` turns them on: about 3 fps and a broken picture today). An - estimate stands in for indirect light and for reflections of opaque surfaces: rooms are lit, but reflections - are blurry, and in cutscenes they can still show the sky's bright colour. -- **Left out:** the heat-haze / in-scattering pass (it smears blocks of pixels, also on water) and the decal - heap's defragmentation (5.6 ms of GPU a frame). `VICTORY_LEAVE_OUT` names them. -- **Hitches:** some single frames of 70-190 ms in cutscenes while the title streams. -- **Frame rate:** the title runs at 30 fps. `-Fps 60` lets frames start every 1/60 s, but the layer itself costs - about 33 ms a frame today, so it stays near 30. 60 fps is the goal. -- **The first run of every new build stutters** while the driver compiles pipelines (see *Warming up* below). +- **No ray tracing.** The title's own is off (`VICTORY_BVH_BUILDER=1`, or the + menu's RAY TRACING, turns it on: slow and with a broken picture on this + base). An estimate stands in for indirect light and reflections. +- **Frame generation needs room in the card's memory.** The layer fills the + card with textures up to its budget; with frame generation on from the start + the launcher holds a fifth of the budget back (a little less while it is only + ready), so a few more textures can come late. Switched on from the menu on a + full 12 GB card it can still say that memory is past the budget; it then + runs, perhaps unevenly. +- **Frames are only generated while the game's window has the focus**, and + about a second passes after a change before they come. +- **The first run of every new build stutters** while the driver compiles + pipelines (foxhound's README, *Warming up*, says how to make them ahead). +- "SAVE AND RESTART NOW" can leave the old game's process behind without a + window; it goes when the PC restarts. +- What foxhound lists as wrong (the heat-haze pass left out, hitches in + cutscenes) applies here too. -## What you need +## How to run it -- Windows 10 or 11 (x64), a CPU with AVX2, 32 GB of RAM or more, an SSD. -- An NVIDIA GeForce RTX GPU with a recent driver for DLSS (RTX 40 or later for Frame Generation, with - hardware-accelerated GPU scheduling on). Any Direct3D 12 GPU with shader model 6.6 and mesh shaders runs the - layer without DLSS. -- **Your own dump** of the title's Xbox Series build v1.0.2.1 (the folder with `game_scarlett_master.exe`). - Other builds may start, but the image patches (1440p output, FidelityFX path, frame rate) check every byte - they change and leave a differing build alone. -- [Rust](https://rustup.rs) (the toolchain is pinned in `rust-toolchain.toml`; rustup fetches it), and the - **Visual Studio Build Tools** with "Desktop development with C++" (MSVC and a Windows SDK). -- For DLSS: NVIDIA's **Streamline SDK** (below). You download it yourself; nothing of NVIDIA's is in this - repository. - -## Build +You need Windows 10 or 11 (x64), a CPU with AVX2, 32 GB of RAM or more, an +SSD, an NVIDIA GeForce RTX card with a recent driver (RTX 40 or later for frame +generation, with hardware-accelerated GPU scheduling on; more than 2x needs an +RTX 50), [Rust](https://rustup.rs) (the toolchain is pinned), the Visual Studio +Build Tools with "Desktop development with C++", and **your own dump** of the +title's Xbox Series build v1.0.2.1 (the folder with +`game_scarlett_master.exe`). ```powershell -git clone https://github.com/readmet3xt-lab/foxhound -cd foxhound -cargo build --release --locked -p victory +git clone https://github.com/trustno1-coder/VIctory-NVIDIA +cd VIctory-NVIDIA +copy victory.example.toml victory.toml # then set game_dir to your dump's folder, outside this one +.\Get-NVIDIA-DLSS.cmd # once: NVIDIA's DLSS and frame generation files, about 70 MB +scripts\play-nvidia.ps1 -Exe 'D:\Games\MyDump\game_scarlett_master.exe' ``` -The diagnostics build (frame timelines, captures, GPU timing) is optional: -`cargo build --locked --profile diag -p victory --features diagnostics`. +The first start builds the layer (a few minutes). `Get-NVIDIA-DLSS.cmd` gets +NVIDIA's files from +[NVIDIA-RTX/Streamline](https://github.com/NVIDIA-RTX/Streamline) into +`nvidia-sdk\` (git-ignored). They are NVIDIA's, under NVIDIA's licences, which +are saved beside them; this repository does not carry them and may not. Nothing +is downloaded unless you run that file; `VICTORY_STREAMLINE_DIR` names another +folder if you have the Streamline SDK already. -## Set up - -1. **Point it at your copy.** Copy `victory.example.toml` to `victory.toml` (git-ignored) and set `game_dir` to - your dump's folder. Keep your files **outside** this repository; the tools refuse otherwise. - - ```toml - [paths] - game_dir = 'D:\Games\MyDump' - ``` - -2. **DLSS (optional, recommended on RTX).** Download the Streamline SDK release from - (tested: `streamline-sdk-v2.14.16.zip`; it comes under - NVIDIA's RTX SDK license, which you accept yourself), unpack it **outside** the repository, and point foxhound - at its `bin\x64` folder: - - ```powershell - [Environment]::SetEnvironmentVariable('VICTORY_STREAMLINE_DIR', 'D:\sdk\streamline-sdk-v2.14.16\bin\x64', 'User') - ``` - - Check it without the title: `target\release\victory.exe upscaler-check --device` (and `--present` for Frame - Generation). Details: [docs/dlss.md](docs/dlss.md). Without Streamline the launcher runs without DLSS. - -3. **Translate the shaders ahead** (a few minutes, once per new build of foxhound): - - ```powershell - $env:VICTORY_HOST_WAVE = '32' # NVIDIA runs 32-lane waves; leave it out on AMD - target\release\victory.exe shaders - ``` - -## Run - -```powershell -.\scripts\play-foxhound.ps1 -Exe 'D:\Games\MyDump\game_scarlett_master.exe' -``` +`scripts\play-nvidia.ps1` is `scripts\play-foxhound.ps1` under the name this +fork has always had; its options: | Option | What | |---|---| -| *(none)* | Series X profile, 2560x1440, DLSS Quality (if Streamline is set up), all fixes on | +| *(none)* | Series X profile, 2560x1440, DLSS Quality, no frame rate cap, frame generation ready but off | +| `-FrameGen`, `-FrameGenX 4` | frame generation on from the start, 2 to 6 frames shown for each one rendered | | `-Dlss off` / `dlaa` / `balanced` / `performance` | the title's own upscaling, or another DLSS mode | -| `-FrameGen` | DLSS Frame Generation (about +1.4 GB of VRAM) | +| `-Fps 60` | a frame rate cap (30 is the title's own) | | `-SeriesS` | the Series S profile: 1280x720 inside, faster, softer | | `-Res 1080to1440` / `4k` | scene at 1080p upscaled by the title / the stock 3840x2160 output | -| `-Build diag` | the diagnostics build | +| `-NoFrameGenReady` | frame generation only with `-FrameGen` (it is otherwise made ready at every start, so the menu can switch it) | +| `-Build diag` | the diagnostics build (slower; captures, timelines, the F3 numbers panel) | | `-More @{VICTORY_X='1'}` | add or override any switch | -Full screen: start the game, then run `.\scripts\fullscreen.ps1` in another window (borderless, the size of the -monitor the game is on). - -Logs go to `%LOCALAPPDATA%\victory\logs`, saves to `%LOCALAPPDATA%\victory\data`. Close the game window to quit. - -### Warming up (once per build or driver) - -The first run of a build compiles pipelines while playing and stutters. Runs write down every pipeline the title -makes (`VICTORY_PIPELINE_BOOK=1`, set by the launcher); afterwards make them all ahead: - -```powershell -$env:VICTORY_HOST_WAVE = '32' -target\release\victory.exe warm -``` - -The NVIDIA driver keeps its compiled pipelines **per program path**: a build run from another folder starts cold. - -## Switches worth knowing - -Every `VICTORY_...` switch is described in a comment where the code reads it. The launcher's full set is in -`scripts/play-foxhound.ps1`; these are the ones foxhound added or changed: - -| Switch | Launcher | What | -|---|---|---| -| `VICTORY_DLSS`, `VICTORY_DLSS_MODE` | `quality` | DLSS Super Resolution through the title's FidelityFX dispatch | -| `VICTORY_FRAMEGEN` | off (`-FrameGen`) | DLSS Frame Generation, with the picture before the HUD tagged | -| `VICTORY_NATIVE_1440P` | on | Series X renders and outputs 2560x1440 (image patched) | -| `VICTORY_SOFT_VIEWS` | `copies` | the title's tiled-heap page mappings kept without Windows views: no freezes at scene cuts | -| `VICTORY_WC_NO_BACK`, `_MIN_KB` | `1`, `1024` | shader writes into big write-combined copies are not copied back | -| `VICTORY_AMBIENT`, `VICTORY_AMBIENT_SPECULAR` | `0.8`, `1` | estimates of indirect light and of reflections (no ray tracing) | -| `VICTORY_EARLY_DEPTH` | on | pixel programs keep the console's early depth test | -| `VICTORY_PRELUDE_UPLOADS`, `VICTORY_SHOW_NEW_LATER`, `VICTORY_TABLED_REREAD` | on | texture upload order and slot changes (flicker, device losses) | -| `VICTORY_SYNC_IN_PLACE`, `VICTORY_SPANS_QUICK`, `VICTORY_HEAP_SYNC_AT_SUBMIT` | on | cheaper descriptor-heap bookkeeping | -| `VICTORY_PORT_CONSTANTS` | off | the title's constants heap read in place: less CPU, but on a 12 GB card the GPU then waits (slower overall) | -| `VICTORY_FRAME_INTERVAL_MS` | off | experimental: the title's own 30 fps setting patched to a higher rate | -| `VICTORY_BVH_BUILDER` | off | the title's ray tracing (slow, broken) | +What the F1 menu saved (`victory-settings.txt`) goes over these at every start; +delete that file to go back to them. Full screen: start the game, then run +`.\scripts\fullscreen.ps1` in another window. Logs go to +`%LOCALAPPDATA%\victory\logs`, saves to `%LOCALAPPDATA%\victory\data`. ## How it works, and the findings +- [docs/README-foxhound.md](docs/README-foxhound.md): foxhound's own README + (set-up by hand, warming up, its switches). - [docs/architecture.md](docs/architecture.md): the layer's parts. - [docs/findings.md](docs/findings.md): measurements behind the choices. - [docs/dlss.md](docs/dlss.md): DLSS and Frame Generation. -- [docs/fork-ray-tracing.md](docs/fork-ray-tracing.md): the title's ray tracing and the light estimate. -- [docs/replay.md](docs/replay.md): recording a frame and replaying it. -- [docs/asset-policy.md](docs/asset-policy.md): what may and may not be in this repository. - -## Contributing - -Issues and pull requests are welcome. Never attach or commit anything from the game: files, dumps, shader dumps -or extracted data. Describe faults technically. `cargo xtask policy` (also the pre-commit hook in `.githooks/`) -checks the asset policy. +- [docs/fork-ray-tracing.md](docs/fork-ray-tracing.md): the title's ray tracing + and the light estimate. +- [docs/asset-policy.md](docs/asset-policy.md): what may and may not be in this + repository. ## Credits -A tree of other people's work with more on top; the history is kept, and commits taken from elsewhere name the -commit and its author. +A tree of other people's work with a little on top; the history is kept. -- **[VIctory](https://github.com/Marvisak/VIctory)** by Marvisak and its contributors: the loader, the runtime - services, the Direct3D 12 back end and the shader recompiler. -- **[fxceless/victory-fork](https://github.com/fxceless/victory-fork)** and the people whose pull requests it carries. -- **[avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX)**: the submission line, write - guards, relay and much of the speed work this fork starts from. -- **[codec-d/cool_fox](https://github.com/codec-d/cool_fox)**: the base this fork was taken from. -- **[DexNom/VIctory](https://github.com/DexNom/VIctory)**: native 1440p output, the FidelityFX path on Series X, - ray tracing fixes. -- **[Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD)**: the light estimate, renderer - ports (constants heap in place, heap records), texture upload order, the frame rate switch; ported commits name - their source. -- **[FQY55kai/ZJOU-VICTORY](https://github.com/FQY55kai/ZJOU-VICTORY)**, **[myokex/victory-amd](https://github.com/myokex/victory-amd)** - (with Spexivus, joroyt and tightfall), Joshua Odom, **Geckomacabre** and **cxy0072019-sketch**. -- **[XCL](https://github.com/ivall/xcl)** (GPL-2.0-only) was read for how the same title behaves under another - layer; no code of it is here. -- NVIDIA Streamline, DLSS and Reflex are NVIDIA's; they are loaded at run time from a folder you supply. -- Much of this fork's code was written with [Claude Code](https://claude.com/claude-code). +- **[foxhound](https://github.com/readmet3xt-lab/foxhound)** by + readmet3xt-lab: the base of this fork since 2026-11-26, and through it: +- **[VIctory](https://github.com/Marvisak/VIctory)** by Marvisak and its + contributors: the loader, the runtime services, the Direct3D 12 back end and + the shader recompiler. +- **[fxceless/victory-fork](https://github.com/fxceless/victory-fork)**, + **[avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX)**, + **[codec-d/cool_fox](https://github.com/codec-d/cool_fox)**, + **[DexNom/VIctory](https://github.com/DexNom/VIctory)**, + **[Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD)** + and the others foxhound's README names. +- Everyone who sent pull requests to this fork before the move; that work is + in the history, on the branch that was `main` until then. +- NVIDIA Streamline, DLSS and Reflex are NVIDIA's; they are loaded at run time + from a folder you supply. +- Much of this fork's code was written with + [Claude Code](https://claude.com/claude-code). ## License -GPL-3.0-or-later, as VIctory. See [LICENSE](LICENSE); the one file that is not covered is named in -[docs/asset-policy.md](docs/asset-policy.md). +GPL-3.0-or-later, as VIctory and foxhound. See [LICENSE](LICENSE); the one file +that is not covered is named in [docs/asset-policy.md](docs/asset-policy.md). diff --git a/crates/victory-gpu/src/host.rs b/crates/victory-gpu/src/host.rs index 2427053..c1cb889 100644 --- a/crates/victory-gpu/src/host.rs +++ b/crates/victory-gpu/src/host.rs @@ -3838,6 +3838,8 @@ pub(crate) mod aside; pub(crate) mod awake; mod card_steps; pub(crate) mod indirects; +mod font; +mod menu; #[cfg(feature = "diagnostics")] mod panel; mod place; @@ -9233,10 +9235,16 @@ struct Presenter { composer: Option, #[cfg(feature = "diagnostics")] panel: panel::Panel, + /// The F1 settings menu. + menu: menu::Menu, } /// The frame rate, shown in the window's caption every second and logged /// every few seconds. +/// The frame rate the meter last counted, in tenths of a frame a second (0: none yet): for the +/// line at the top of the picture (`menu.rs`). +pub(crate) static METER_FPS_TENTHS: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0); + struct Meter { since: std::time::Instant, frames: u32, @@ -9287,6 +9295,7 @@ impl Meter { let frames = f64::from(self.frames); let fps = frames / elapsed.as_secs_f64(); let ms = elapsed.as_secs_f64() * 1000.0 / frames; + METER_FPS_TENTHS.store((fps * 10.0).round() as u32, Ordering::Relaxed); let draws = (drawn - self.drawn) as f64 / frames; (self.since, self.frames, self.drawn) = (std::time::Instant::now(), 0, drawn); // Of a frame, ms preparing submissions and ms waiting for the GPU. @@ -9692,7 +9701,11 @@ impl Meter { self.caption = Some(buffer); } let Some(caption) = &self.caption else { return }; - let text = format!(" | VIctory {fps:.0} fps {ms:.1} ms/frame {draws:.0} draws/frame"); + // With frame generation showing more frames than are rendered, both rates. + let text = match crate::streamline::shown_per_frame() { + 1 => format!(" | VIctory {fps:.0} fps {ms:.1} ms/frame {draws:.0} draws/frame"), + per => format!(" | VIctory {fps:.0} fps (frame gen {:.0} fps) {ms:.1} ms/frame {draws:.0} draws/frame", fps * f64::from(per)), + }; let mut text: Vec = caption.iter().copied().chain(text.encode_utf16()).collect(); text.push(0); // Setting the text waits for the window's thread (a title thread, @@ -9960,6 +9973,7 @@ impl Host { }; #[cfg(feature = "diagnostics")] p.panel.draw(self, copy, &back, (width, height), format); + p.menu.draw(self, copy, &back, (width, height), format); #[cfg(not(feature = "diagnostics"))] let _ = frame; if composed { @@ -10021,6 +10035,7 @@ impl Host { showing.next("the frame meter"); #[cfg(feature = "diagnostics")] p.panel.frame(p.meter.line_due()); + p.menu.frame(); p.meter.frame(p.hwnd); showing.end(); #[cfg(feature = "diagnostics")] @@ -10109,6 +10124,7 @@ impl Host { composer: None, #[cfg(feature = "diagnostics")] panel: panel::Panel::new(), + menu: menu::Menu::new(), }) } } diff --git a/crates/victory-gpu/src/host/font.rs b/crates/victory-gpu/src/host/font.rs new file mode 100644 index 0000000..84dce4c --- /dev/null +++ b/crates/victory-gpu/src/host/font.rs @@ -0,0 +1,79 @@ +//! The dot letters the stats panel (`panel.rs`, diagnostics builds) and the settings menu +//! (`menu.rs`, every build) are written with, and the pixels they are painted in. + +use windows::Win32::Graphics::Dxgi::Common::*; + +/// Seven rows of five dots, the leftmost the highest bit. +#[rustfmt::skip] +pub(super) const fn glyph(c: u8) -> [u8; 7] { + match c { + b'0' => [0b01110, 0b10001, 0b10011, 0b10101, 0b11001, 0b10001, 0b01110], + b'1' => [0b00100, 0b01100, 0b00100, 0b00100, 0b00100, 0b00100, 0b01110], + b'2' => [0b01110, 0b10001, 0b00001, 0b00110, 0b01000, 0b10000, 0b11111], + b'3' => [0b11110, 0b00001, 0b00001, 0b01110, 0b00001, 0b00001, 0b11110], + b'4' => [0b00010, 0b00110, 0b01010, 0b10010, 0b11111, 0b00010, 0b00010], + b'5' => [0b11111, 0b10000, 0b11110, 0b00001, 0b00001, 0b10001, 0b01110], + b'6' => [0b00110, 0b01000, 0b10000, 0b11110, 0b10001, 0b10001, 0b01110], + b'7' => [0b11111, 0b00001, 0b00010, 0b00010, 0b00100, 0b00100, 0b00100], + b'8' => [0b01110, 0b10001, 0b10001, 0b01110, 0b10001, 0b10001, 0b01110], + b'9' => [0b01110, 0b10001, 0b10001, 0b01111, 0b00001, 0b00010, 0b01100], + b'A' => [0b00100, 0b01010, 0b10001, 0b10001, 0b11111, 0b10001, 0b10001], + b'B' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10001, 0b10001, 0b11110], + b'C' => [0b01111, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b01111], + b'D' => [0b11110, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b11110], + b'E' => [0b11111, 0b10000, 0b10000, 0b11110, 0b10000, 0b10000, 0b11111], + b'F' => [0b11111, 0b10000, 0b10000, 0b11110, 0b10000, 0b10000, 0b10000], + b'G' => [0b01111, 0b10000, 0b10000, 0b10011, 0b10001, 0b10001, 0b01111], + b'H' => [0b10001, 0b10001, 0b10001, 0b11111, 0b10001, 0b10001, 0b10001], + b'I' => [0b01110, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b01110], + b'J' => [0b00111, 0b00010, 0b00010, 0b00010, 0b00010, 0b10010, 0b01100], + b'K' => [0b10001, 0b10010, 0b10100, 0b11000, 0b10100, 0b10010, 0b10001], + b'L' => [0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b11111], + b'M' => [0b10001, 0b11011, 0b10101, 0b10101, 0b10001, 0b10001, 0b10001], + b'N' => [0b10001, 0b11001, 0b11001, 0b10101, 0b10011, 0b10011, 0b10001], + b'O' => [0b01110, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01110], + b'P' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10000, 0b10000, 0b10000], + b'Q' => [0b01110, 0b10001, 0b10001, 0b10001, 0b10101, 0b10010, 0b01101], + b'R' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10100, 0b10010, 0b10001], + b'S' => [0b01111, 0b10000, 0b10000, 0b01110, 0b00001, 0b00001, 0b11110], + b'T' => [0b11111, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100], + b'U' => [0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01110], + b'V' => [0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01010, 0b00100], + b'W' => [0b10001, 0b10001, 0b10001, 0b10101, 0b10101, 0b11011, 0b10001], + b'X' => [0b10001, 0b10001, 0b01010, 0b00100, 0b01010, 0b10001, 0b10001], + b'Y' => [0b10001, 0b10001, 0b01010, 0b00100, 0b00100, 0b00100, 0b00100], + b'Z' => [0b11111, 0b00001, 0b00010, 0b00100, 0b01000, 0b10000, 0b11111], + b'.' => [0, 0, 0, 0, 0, 0b01100, 0b01100], + b'/' => [0b00001, 0b00010, 0b00010, 0b00100, 0b01000, 0b01000, 0b10000], + b'-' => [0, 0, 0, 0b11111, 0, 0, 0], + // For the settings menu (menu.rs). + b'>' => [0b01000, 0b00100, 0b00010, 0b00001, 0b00010, 0b00100, 0b01000], + b'<' => [0b00010, 0b00100, 0b01000, 0b10000, 0b01000, 0b00100, 0b00010], + b'*' => [0, 0b00100, 0b10101, 0b01110, 0b10101, 0b00100, 0], + b':' => [0, 0b01100, 0b01100, 0, 0b01100, 0b01100, 0], + b'_' => [0, 0, 0, 0, 0, 0, 0b11111], + b'=' => [0, 0, 0b11111, 0, 0b11111, 0, 0], + b'(' => [0b00010, 0b00100, 0b01000, 0b01000, 0b01000, 0b00100, 0b00010], + b')' => [0b01000, 0b00100, 0b00010, 0b00010, 0b00010, 0b00100, 0b01000], + b'+' => [0, 0b00100, 0b00100, 0b11111, 0b00100, 0b00100, 0], + b',' => [0, 0, 0, 0, 0b01100, 0b00100, 0b01000], + b'!' => [0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0, 0b00100], + b'?' => [0b01110, 0b10001, 0b00001, 0b00010, 0b00100, 0, 0b00100], + b' ' => [0; 7], + _ => [0b11111, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b11111], + } +} + +/// The bytes of a black and a white pixel of a swap chain's format. +pub(super) fn colours(format: DXGI_FORMAT) -> Option<[&'static [u8]; 2]> { + Some(match format { + DXGI_FORMAT_R8G8B8A8_UNORM | DXGI_FORMAT_B8G8R8A8_UNORM => [&[0, 0, 0, 0xFF], &[0xFF; 4]], + DXGI_FORMAT_R10G10B10A2_UNORM => [&[0, 0, 0, 0xC0], &[0xFF; 4]], + // Halves of 0 and 1. + DXGI_FORMAT_R16G16B16A16_FLOAT => [ + &[0, 0, 0, 0, 0, 0, 0, 0x3C], + &[0, 0x3C, 0, 0x3C, 0, 0x3C, 0, 0x3C], + ], + _ => return None, + }) +} diff --git a/crates/victory-gpu/src/host/menu.rs b/crates/victory-gpu/src/host/menu.rs new file mode 100644 index 0000000..859b9e3 --- /dev/null +++ b/crates/victory-gpu/src/host/menu.rs @@ -0,0 +1,565 @@ +//! The F1 settings menu. F1 shows and hides it while our window has the +//! focus; Up/Down pick a setting, Left/Right change it, Enter runs the line +//! picked (save, save and restart, reset, close), Esc closes. While it is +//! shown the title sees no keyboard (`crate::SETTINGS_MENU_OPEN`, read by the +//! input module); a pad still works. +//! +//! The settings are read once at start, so a change is saved to the file +//! `VICTORY_MENU_FILE` names (`scripts\play-foxhound.ps1` sets it to +//! `victory-settings.txt` in the repository's folder and applies it at every +//! start) and takes effect at the next start; "SAVE AND RESTART" starts the +//! launcher again (`VICTORY_MENU_PLAY`, with `VICTORY_MENU_ARGS`) and ends +//! this run. The `VICTORY_MENU_...` settings are the launcher's own choices +//! (DLSS mode, frame generation, frame rate, console, picture size), which it +//! turns into the layer's switches; the others are the switches themselves. +//! +//! In every build (the stats panel is in diagnostics builds only). Drawn as +//! that panel is: white text on a black box, copied onto the swap chain's +//! buffer, in the middle of the picture. + +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::{Mutex, OnceLock}; +use std::time::Duration; + +use windows::Win32::Graphics::Direct3D12::*; +use windows::Win32::Graphics::Dxgi::Common::*; +use windows_sys::Win32::UI::Input::KeyboardAndMouse::{ + GetAsyncKeyState, VK_DOWN, VK_ESCAPE, VK_F1, VK_LEFT, VK_RETURN, VK_RIGHT, VK_UP, +}; +use windows_sys::Win32::UI::WindowsAndMessaging::{GetForegroundWindow, GetWindowThreadProcessId}; + +use super::font::{colours, glyph}; +use super::{Host, HostList, transition}; + +const GLYPH: (u32, u32) = (5, 7); +const CELL: (u32, u32) = (6, 9); +const COLUMNS: u32 = 60; +/// Lines of the box: a title, a help line, a blank, the settings shown, a +/// blank and a note. +const ROWS: usize = 20; +const LINES: u32 = ROWS as u32 + 5; +const RIM: u32 = 4; +const UPLOADS: usize = 4; + +/// A setting: the variable, its name in the menu, the values it takes +/// (`""`: not set, the build's own default), and whether a change applies at once. +struct Item { + var: &'static str, + label: &'static str, + values: &'static [(&'static str, &'static str)], + live: bool, +} + +const ON_UNSET: &[(&str, &str)] = &[("1", "ON"), ("", "OFF")]; +const UNSET_ON: &[(&str, &str)] = &[("", "OFF"), ("1", "ON")]; +const STAGES: &[(&str, &str)] = &[("2", "2"), ("1", "1"), ("0", "0 OFF")]; + +/// The first value of each is what the launcher starts with. +#[rustfmt::skip] +const ITEMS: &[Item] = &[ + // The launcher's own choices. + Item { var: "VICTORY_MENU_DLSS", label: "DLSS", values: &[("quality", "QUALITY"), ("balanced", "BALANCED"), ("performance", "PERFORMANCE"), ("dlaa", "DLAA (NATIVE)"), ("off", "OFF")], live: false }, + Item { var: "VICTORY_MENU_FRAMEGEN", label: "FRAME GENERATION", values: &[("0", "OFF"), ("2", "2X"), ("3", "3X"), ("4", "4X"), ("5", "5X"), ("6", "6X (MOST)")], live: false }, + Item { var: "VICTORY_MENU_FPS", label: "FRAME RATE CAP", values: &[("1000", "NONE"), ("120", "120"), ("60", "60"), ("30", "30 (THE GAME)")], live: false }, + Item { var: "VICTORY_FPS_LINE", label: "FPS AT THE TOP", values: &[("1", "ON"), ("0", "OFF")], live: true }, + Item { var: "VICTORY_MENU_CONSOLE", label: "CONSOLE", values: &[("series-x", "SERIES X"), ("series-s", "SERIES S (FASTER)")], live: false }, + Item { var: "VICTORY_MENU_RES", label: "SERIES X PICTURE", values: &[("1440", "2560X1440"), ("1080to1440", "1080P TO 1440P"), ("4k", "3840X2160")], live: false }, + // The layer's switches. + Item { var: "VICTORY_DLSS_PRESET", label: "DLSS MODEL", values: &[("", "DEFAULT"), ("k", "K"), ("j", "J"), ("m", "M"), ("l", "L")], live: false }, + Item { var: "VICTORY_AMBIENT", label: "LIGHT ESTIMATE", values: &[("0.8", "0.8"), ("1", "1"), ("0.5", "0.5"), ("", "OFF")], live: false }, + Item { var: "VICTORY_AMBIENT_SPECULAR", label: "REFLECTION ESTIMATE", values: ON_UNSET, live: false }, + Item { var: "VICTORY_AMBIENT_AIR", label: "FOG CAP", values: &[("1.5", "1.5"), ("1", "1"), ("2", "2"), ("", "NONE")], live: false }, + Item { var: "VICTORY_BVH_BUILDER", label: "RAY TRACING (SLOW, BROKEN)", values: UNSET_ON, live: false }, + Item { var: "VICTORY_LEAVE_OUT", label: "HEAT HAZE AND DECAL DEFRAG", values: &[("02384a60fda6f2d0,731a39171b568298", "LEFT OUT"), ("", "RUN (SLOWER, SMEARS)")], live: false }, + Item { var: "VICTORY_EARLY_DEPTH", label: "EARLY DEPTH TEST", values: ON_UNSET, live: false }, + Item { var: "VICTORY_WC_NO_BACK", label: "SKIP BIG COPY-BACKS", values: ON_UNSET, live: false }, + Item { var: "VICTORY_SOFT_VIEWS", label: "SOFT VIEWS (NO CUT FREEZES)", values: &[("copies", "ON"), ("", "OFF")], live: false }, + Item { var: "VICTORY_TEXTURE_NO_WAIT", label: "TEXTURE NO WAIT", values: ON_UNSET, live: false }, + Item { var: "VICTORY_RELAY", label: "RELAY (SPEED, TRIANGLES)", values: STAGES, live: false }, + Item { var: "VICTORY_CARD_STEPS", label: "CARD STEPS", values: STAGES, live: false }, + Item { var: "VICTORY_INDIRECT_BATCH", label: "INDIRECT BATCH", values: STAGES, live: false }, + Item { var: "VICTORY_CARD_BUFFERS_MIN_KB", label: "CARD COMPARES FROM (KB)", values: &[("64", "64"), ("1024", "1024")], live: false }, + Item { var: "VICTORY_PORT_CONSTANTS", label: "CONSTANTS HEAP IN PLACE", values: UNSET_ON, live: false }, +]; +/// The lines after the settings. +const ACTIONS: [&str; 4] = ["SAVE AND RESTART NOW", "SAVE FOR NEXT START", "RESET ALL TO PLAY DEFAULTS", "CLOSE"]; + +fn get(var: &str) -> String { + std::env::var(var).unwrap_or_default() +} + +/// Whether a change of `item` shows at once. Frame generation does when this run started with +/// it ready (the launcher asks for that whenever Streamline is there). +fn live(item: &Item) -> bool { + item.live || (item.var == "VICTORY_MENU_FRAMEGEN" && crate::streamline::framegen_live()) +} + +/// Whether the frame-rate line is shown at the top while the menu is closed +/// (`VICTORY_FPS_LINE=0`: not; the menu changes it). +fn fps_line_on() -> &'static AtomicBool { + static ON: OnceLock = OnceLock::new(); + ON.get_or_init(|| AtomicBool::new(std::env::var_os("VICTORY_FPS_LINE").is_none_or(|v| v != "0"))) +} + +/// That line: the frames rendered a second and, while frame generation shows more, those shown. +fn fps_line() -> Option { + if !fps_line_on().load(Ordering::Relaxed) { + return None; + } + // The stats panel has that corner (diagnostics builds, F3). + #[cfg(feature = "diagnostics")] + if super::panel::shown().load(Ordering::Relaxed) { + return None; + } + let fps = f64::from(super::METER_FPS_TENTHS.load(Ordering::Relaxed)) / 10.0; + if fps <= 0.0 { + return None; + } + Some(match crate::streamline::shown_per_frame() { + 1 => format!("FPS: {fps:.1}"), + per => format!("FPS: {fps:.1} FG: {:.1}", fps * f64::from(per)), + }) +} + +/// The index of `value` among the item's values (an unknown value: shown as +/// itself, at the end). +fn index_of(item: &Item, value: &str) -> Option { + item.values.iter().position(|(v, _)| *v == value) +} + +/// Keys pressed, gathered on a thread of their own every 10 ms: a frame +/// lasts 50 ms and more, and a short press would fall between two frames. +fn keys() -> &'static Mutex> { + static KEYS: OnceLock>> = OnceLock::new(); + KEYS.get_or_init(|| { + let _ = std::thread::Builder::new().name("settings menu keys".into()).spawn(|| { + const WATCHED: [u16; 7] = [VK_F1, VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT, VK_RETURN, VK_ESCAPE]; + let mut was = [false; WATCHED.len()]; + loop { + std::thread::sleep(Duration::from_millis(10)); + let mut process = 0; + // SAFETY: plain queries; room for the answer. + unsafe { GetWindowThreadProcessId(GetForegroundWindow(), &mut process) }; + let ours = process == std::process::id(); + for (i, &vk) in WATCHED.iter().enumerate() { + // SAFETY: a plain query. + let down = ours && unsafe { GetAsyncKeyState(i32::from(vk)) } < 0; + if down && !was[i] { + keys().lock().unwrap_or_else(|e| e.into_inner()).push(vk); + } + was[i] = down; + } + } + }); + Mutex::new(Vec::new()) + }) +} + +/// The box's size in pixels. +const fn size(scale: u32) -> (u32, u32) { + ((COLUMNS * CELL.0 + 2 * RIM) * scale, (LINES * CELL.1 + 2 * RIM) * scale) +} + +fn lit(lines: &[String], x: u32, y: u32) -> bool { + let (Some(x), Some(y)) = (x.checked_sub(RIM), y.checked_sub(RIM)) else { + return false; + }; + if x % CELL.0 >= GLYPH.0 || y % CELL.1 >= GLYPH.1 || x / CELL.0 >= COLUMNS { + return false; + } + let Some(&c) = lines.get((y / CELL.1) as usize).and_then(|l| l.as_bytes().get((x / CELL.0) as usize)) else { + return false; + }; + (glyph(c.to_ascii_uppercase())[(y % CELL.1) as usize] >> (GLYPH.0 - 1 - x % CELL.0)) & 1 != 0 +} + +fn painted(lines: &[String], scale: u32, colours: [&[u8]; 2], pitch: usize) -> Vec { + let (width, height) = size(scale); + let bytes = colours[0].len(); + let mut out = vec![0; pitch * height as usize]; + for y in 0..height / scale { + let top = pitch * (y * scale) as usize; + for x in 0..width / scale { + let colour = colours[usize::from(lit(lines, x, y))]; + for i in 0..scale { + let at = top + (x * scale + i) as usize * bytes; + out[at..at + bytes].copy_from_slice(colour); + } + } + for i in 1..scale as usize { + out.copy_within(top..top + pitch, top + i * pitch); + } + } + out +} + +struct Buffers { + format: DXGI_FORMAT, + scale: u32, + pitch: u32, + uploads: Vec<(ID3D12Resource, *mut u8)>, + card: ID3D12Resource, + turn: usize, + fresh: bool, + /// The card's buffer was copied into before (it is in the copy-source state; + /// at first it is in the common state, promoted by the first copy). + used: bool, +} + +// SAFETY: free-threaded resources, and memory only written under the presenter's lock. +unsafe impl Send for Buffers {} + +impl Buffers { + fn new(host: &Host, format: DXGI_FORMAT, scale: u32) -> Option { + let (width, height) = size(scale); + let pitch = (width * colours(format)?[0].len() as u32).next_multiple_of(256); + let bytes = u64::from(pitch) * u64::from(height); + let uploads = (0..UPLOADS).map(|_| host.upload_buffer(bytes)).collect::>>()?; + let heap = D3D12_HEAP_PROPERTIES { Type: D3D12_HEAP_TYPE_DEFAULT, ..Default::default() }; + let desc = D3D12_RESOURCE_DESC { + Dimension: D3D12_RESOURCE_DIMENSION_BUFFER, + Width: bytes, + Height: 1, + DepthOrArraySize: 1, + MipLevels: 1, + SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 }, + Layout: D3D12_TEXTURE_LAYOUT_ROW_MAJOR, + ..Default::default() + }; + let mut card: Option = None; + // SAFETY: plain creation of a buffer. + unsafe { + host.device + .CreateCommittedResource(&heap, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_COMMON, None, &mut card) + .ok()?; + } + Some(Buffers { format, scale, pitch, uploads, card: card?, turn: 0, fresh: false, used: false }) + } + + fn write(&mut self, lines: &[String]) { + let Some(colours) = colours(self.format) else { return }; + let picture = painted(lines, self.scale, colours, self.pitch as usize); + self.turn = (self.turn + 1) % UPLOADS; + // SAFETY: a mapped upload buffer of the picture's size, which the card read frames ago. + unsafe { std::ptr::copy_nonoverlapping(picture.as_ptr(), self.uploads[self.turn].1, picture.len()) }; + self.fresh = true; + } +} + +/// The menu of a presenter. +pub(super) struct Menu { + /// The values chosen, by item (as at start until changed). + values: Vec, + /// The values at start. + started: Vec, + /// The line picked: an item, or an action after them. + at: usize, + note: String, + changed: bool, + /// What the buffer holds: the frame-rate line, or (none) the menu's lines. + painted: Option, + buffers: Option, + failed: bool, +} + +impl Menu { + pub(super) fn new() -> Menu { + // Start the key thread now: F1 must be seen while the menu is closed. + let _ = keys(); + // `VICTORY_MENU_OPEN=1`: shown from the start (to look at it in a run nobody presses keys in). + if std::env::var_os("VICTORY_MENU_OPEN").is_some_and(|v| v == "1") { + crate::SETTINGS_MENU_OPEN.store(true, Ordering::Relaxed); + } + let values: Vec = ITEMS.iter().map(|i| get(i.var)).collect(); + Menu { started: values.clone(), values, at: 0, note: String::new(), changed: true, painted: None, buffers: None, failed: false } + } + + fn open() -> bool { + crate::SETTINGS_MENU_OPEN.load(Ordering::Relaxed) + } + + fn lines(&self) -> Vec { + let total = ITEMS.len() + ACTIONS.len(); + let first = self.at.saturating_sub(ROWS / 2).min(total.saturating_sub(ROWS)); + let mut out = vec![ + "SETTINGS F1 OR ESC CLOSES".to_owned(), + "UP/DOWN PICK LEFT/RIGHT CHANGE ENTER DOES IT".to_owned(), + String::new(), + ]; + for row in first..(first + ROWS).min(total) { + let cursor = if row == self.at { '>' } else { ' ' }; + let line = if let Some(item) = ITEMS.get(row) { + let value = &self.values[row]; + let shown = index_of(item, value).map_or(value.to_ascii_uppercase(), |i| item.values[i].1.to_owned()); + let mark = if *value != self.started[row] { if live(item) { " *LIVE" } else { " *" } } else if live(item) { " LIVE" } else { "" }; + format!("{cursor} {:<27} < {shown} >{mark}", item.label) + } else { + format!("{cursor} {}", ACTIONS[row - ITEMS.len()]) + }; + out.push(line.chars().take(COLUMNS as usize).collect()); + } + while out.len() < 3 + ROWS { + out.push(String::new()); + } + out.push(String::new()); + out.push(if self.note.is_empty() { "* = CHANGED: APPLIES AT THE NEXT START UNLESS LIVE".to_owned() } else { self.note.clone() }); + out + } + + /// Changes item `i` by `step` (+1 / -1) through its values. + fn change(&mut self, i: usize, step: isize) { + let item = &ITEMS[i]; + let n = item.values.len() as isize; + let now = index_of(item, &self.values[i]).map_or(-1, |x| x as isize); + let next = if now < 0 { if step > 0 { 0 } else { n - 1 } } else { (now + step).rem_euclid(n) }; + self.values[i] = item.values[next as usize].0.to_owned(); + if live(item) { + self.apply_live(i); + } + self.note.clear(); + } + + /// A setting the build reads at each use: changed in this run's environment at once. + fn apply_live(&self, i: usize) { + let (var, value) = (ITEMS[i].var, &self.values[i]); + // SAFETY: the variables changed here are read by this build with + // std::env::var at each use; Windows' environment block is locked by + // the process heap's routines, and std holds its own lock. + unsafe { + if value.is_empty() { + std::env::remove_var(var); + } else { + std::env::set_var(var, value); + } + } + match var { + // Off (0) or the frames shown for each one rendered, from the next present on. + "VICTORY_MENU_FRAMEGEN" => crate::streamline::set_framegen(value.parse().unwrap_or(0)), + "VICTORY_FPS_LINE" => fps_line_on().store(value != "0", Ordering::Relaxed), + _ => {} + } + } + + /// Writes the changed values over those in the settings file. + fn save(&mut self) -> bool { + let Some(path) = std::env::var_os("VICTORY_MENU_FILE") else { + self.note = "NO SETTINGS FILE: START WITH PLAY-FOXHOUND.PS1".to_owned(); + return false; + }; + let mut kept: Vec<(String, String)> = std::fs::read_to_string(&path) + .unwrap_or_default() + .lines() + .filter_map(|l| l.split_once('=').map(|(k, v)| (k.trim().to_owned(), v.trim().to_owned()))) + .filter(|(k, _)| k.starts_with("VICTORY_")) + .collect(); + for (i, item) in ITEMS.iter().enumerate() { + if self.values[i] == self.started[i] { + continue; + } + kept.retain(|(k, _)| k != item.var); + kept.push((item.var.to_owned(), self.values[i].clone())); + } + let mut text = String::from("# Saved by the F1 menu; scripts\\play-foxhound.ps1 applies these over its own settings (an empty value: unset).\r\n"); + for (k, v) in &kept { + text.push_str(&format!("{k}={v}\r\n")); + } + match std::fs::write(&path, text) { + Ok(()) => { + tracing::info!(path = %std::path::Path::new(&path).display(), "settings menu: saved"); + self.started = self.values.clone(); + self.note = "SAVED. APPLIES AT THE NEXT START".to_owned(); + true + } + Err(e) => { + tracing::warn!(error = %e, "settings menu: not saved"); + self.note = "COULD NOT SAVE THE SETTINGS FILE".to_owned(); + false + } + } + } + + /// Starts the launcher again in a new console, a few seconds on, and ends this run. + fn restart(&mut self) { + use std::os::windows::process::CommandExt; + let Some(play) = std::env::var_os("VICTORY_MENU_PLAY") else { + self.note = "SAVED. START THE LAUNCHER AGAIN YOURSELF".to_owned(); + return; + }; + let play = play.to_string_lossy().replace('\'', "''"); + let args = get("VICTORY_MENU_ARGS"); + let command = format!("Start-Sleep 3; & '{play}' {args}"); + const CREATE_NEW_CONSOLE: u32 = 0x10; + match std::process::Command::new("powershell.exe") + .args(["-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", &command]) + .creation_flags(CREATE_NEW_CONSOLE) + .spawn() + { + Ok(_) => { + tracing::info!(command, "settings menu: restarting"); + // Ended at once: std::process::exit runs the DLLs' unloading, which with + // Streamline loaded did not come back (a windowless leftover process). + // SAFETY: this process, with nothing of its own left to save. + unsafe { + use windows_sys::Win32::System::Threading::{GetCurrentProcess, TerminateProcess}; + TerminateProcess(GetCurrentProcess(), 0); + } + std::process::exit(0); + } + Err(e) => { + tracing::warn!(error = %e, "settings menu: restart failed"); + self.note = "SAVED, BUT THE RESTART FAILED".to_owned(); + } + } + } + + /// Removes the settings file: the launcher's own settings at the next start. + fn reset(&mut self) { + if let Some(path) = std::env::var_os("VICTORY_MENU_FILE") { + let _ = std::fs::remove_file(path); + } + self.note = "RESET. PLAY DEFAULTS AT THE NEXT START".to_owned(); + } + + /// A frame was presented: the keys pressed since the last one. + pub(super) fn frame(&mut self) { + let pressed = std::mem::take(&mut *keys().lock().unwrap_or_else(|e| e.into_inner())); + if pressed.is_empty() { + return; + } + let total = ITEMS.len() + ACTIONS.len(); + for vk in pressed { + let open = Self::open(); + if vk == VK_F1 || (open && vk == VK_ESCAPE) { + crate::SETTINGS_MENU_OPEN.store(!open && vk == VK_F1, Ordering::Relaxed); + self.note.clear(); + self.changed = true; + continue; + } + if !open { + continue; + } + match vk { + VK_UP => self.at = (self.at + total - 1) % total, + VK_DOWN => self.at = (self.at + 1) % total, + VK_LEFT if self.at < ITEMS.len() => self.change(self.at, -1), + VK_RIGHT if self.at < ITEMS.len() => self.change(self.at, 1), + VK_RETURN if self.at < ITEMS.len() => self.change(self.at, 1), + VK_RETURN => match self.at - ITEMS.len() { + 0 => { + if self.save() { + self.restart(); + } + } + 1 => { + self.save(); + } + 2 => self.reset(), + _ => crate::SETTINGS_MENU_OPEN.store(false, Ordering::Relaxed), + }, + _ => {} + } + self.changed = true; + } + } + + /// Records the copy of the box onto `back` (in the copy-destination state). + pub(super) fn draw(&mut self, host: &Host, list: &HostList, back: &ID3D12Resource, (width, height): (u32, u32), format: DXGI_FORMAT) { + if self.failed { + return; + } + // Closed: the frame-rate line in the top left corner, if it is wanted and there is a rate. + let open = Self::open(); + let line = if open { None } else { fps_line() }; + if !open && line.is_none() { + return; + } + // Our own copies are not part of a recorded frame (the recorder is in diagnostics builds). + #[cfg(feature = "diagnostics")] + let _ours = crate::replay::record::unrecorded(); + let scale = (height / 540).max(1); + if self.buffers.as_ref().is_none_or(|b| (b.format, b.scale) != (format, scale)) { + std::mem::forget(self.buffers.take()); + self.buffers = Buffers::new(host, format, scale); + self.failed = self.buffers.is_none(); + self.changed = true; + } + if self.painted != line { + self.painted = line.clone(); + self.changed = true; + } + let lines = if self.changed { Some(line.as_ref().map_or_else(|| self.lines(), |l| vec![l.clone()])) } else { None }; + let Some(buffers) = &mut self.buffers else { return }; + if let Some(lines) = lines { + self.changed = false; + buffers.write(&lines); + } + // The whole box in the middle, or of it the first line's part in the corner. + let (w, h) = match &line { + Some(l) => ((l.len() as u32 * CELL.0 + 2 * RIM) * scale, (CELL.1 + 2 * RIM) * scale), + None => size(scale), + }; + let (w, h) = (w.min(width), h.min(height)); + let (x, y) = if line.is_some() { (0, 0) } else { ((width - w) / 2, (height - h) / 2) }; + let list = &list.list; + // SAFETY: an open list and live resources; the box lies within both. + unsafe { + if std::mem::take(&mut buffers.fresh) { + if std::mem::replace(&mut buffers.used, true) { + list.ResourceBarrier(&[transition(&buffers.card, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COPY_DEST)]); + } + list.CopyResource(&buffers.card, &buffers.uploads[buffers.turn].0); + list.ResourceBarrier(&[transition(&buffers.card, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE)]); + } + let from = D3D12_TEXTURE_COPY_LOCATION { + pResource: std::mem::transmute_copy(&buffers.card), + Type: D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT, + Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { + PlacedFootprint: D3D12_PLACED_SUBRESOURCE_FOOTPRINT { + Offset: 0, + Footprint: D3D12_SUBRESOURCE_FOOTPRINT { Format: format, Width: size(scale).0, Height: size(scale).1, Depth: 1, RowPitch: buffers.pitch }, + }, + }, + }; + let to = D3D12_TEXTURE_COPY_LOCATION { + pResource: std::mem::transmute_copy(back), + Type: D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, + Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { SubresourceIndex: 0 }, + }; + let part = D3D12_BOX { left: 0, top: 0, front: 0, right: w, bottom: h, back: 1 }; + list.CopyTextureRegion(&to, x, y, 0, &from, Some(&part)); + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn every_line_fits_and_every_character_has_a_picture() { + let mut menu = Menu { values: ITEMS.iter().map(|_| String::new()).collect(), started: Vec::new(), at: 0, note: String::new(), changed: false, painted: None, buffers: None, failed: false }; + menu.started = menu.values.clone(); + for at in 0..ITEMS.len() + ACTIONS.len() { + menu.at = at; + for line in menu.lines() { + assert!(line.len() <= COLUMNS as usize, "{line}"); + for c in line.bytes() { + assert_ne!(glyph(c.to_ascii_uppercase()), glyph(b'#'), "{line}: {}", c as char); + } + } + } + } + + #[test] + fn values_cycle_both_ways() { + let mut menu = Menu { values: ITEMS.iter().map(|i| i.values[0].0.to_owned()).collect(), started: Vec::new(), at: 0, note: String::new(), changed: false, painted: None, buffers: None, failed: false }; + menu.started = menu.values.clone(); + let n = ITEMS[0].values.len(); + for _ in 0..n { + menu.change(0, 1); + } + assert_eq!(menu.values[0], ITEMS[0].values[0].0); + menu.change(0, -1); + assert_eq!(menu.values[0], ITEMS[0].values[n - 1].0); + } +} diff --git a/crates/victory-gpu/src/host/panel.rs b/crates/victory-gpu/src/host/panel.rs index a3d2f9b..bcdb8aa 100644 --- a/crates/victory-gpu/src/host/panel.rs +++ b/crates/victory-gpu/src/host/panel.rs @@ -17,6 +17,7 @@ use windows::Win32::Graphics::Dxgi::Common::*; use windows_sys::Win32::UI::Input::KeyboardAndMouse::{GetAsyncKeyState, VK_F3}; use windows_sys::Win32::UI::WindowsAndMessaging::{GetForegroundWindow, GetWindowThreadProcessId}; +use super::font::{colours, glyph}; use super::{Host, HostList, transition}; /// How often the numbers change. @@ -40,7 +41,7 @@ fn asked() -> bool { } /// Whether it is shown now. -fn shown() -> &'static AtomicBool { +pub(super) fn shown() -> &'static AtomicBool { static SHOWN: OnceLock = OnceLock::new(); SHOWN.get_or_init(|| AtomicBool::new(asked())) } @@ -59,54 +60,6 @@ fn pressed() -> bool { process == std::process::id() } -/// Seven rows of five dots, the leftmost the highest bit. -#[rustfmt::skip] -const fn glyph(c: u8) -> [u8; 7] { - match c { - b'0' => [0b01110, 0b10001, 0b10011, 0b10101, 0b11001, 0b10001, 0b01110], - b'1' => [0b00100, 0b01100, 0b00100, 0b00100, 0b00100, 0b00100, 0b01110], - b'2' => [0b01110, 0b10001, 0b00001, 0b00110, 0b01000, 0b10000, 0b11111], - b'3' => [0b11110, 0b00001, 0b00001, 0b01110, 0b00001, 0b00001, 0b11110], - b'4' => [0b00010, 0b00110, 0b01010, 0b10010, 0b11111, 0b00010, 0b00010], - b'5' => [0b11111, 0b10000, 0b11110, 0b00001, 0b00001, 0b10001, 0b01110], - b'6' => [0b00110, 0b01000, 0b10000, 0b11110, 0b10001, 0b10001, 0b01110], - b'7' => [0b11111, 0b00001, 0b00010, 0b00010, 0b00100, 0b00100, 0b00100], - b'8' => [0b01110, 0b10001, 0b10001, 0b01110, 0b10001, 0b10001, 0b01110], - b'9' => [0b01110, 0b10001, 0b10001, 0b01111, 0b00001, 0b00010, 0b01100], - b'A' => [0b00100, 0b01010, 0b10001, 0b10001, 0b11111, 0b10001, 0b10001], - b'B' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10001, 0b10001, 0b11110], - b'C' => [0b01111, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b01111], - b'D' => [0b11110, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b11110], - b'E' => [0b11111, 0b10000, 0b10000, 0b11110, 0b10000, 0b10000, 0b11111], - b'F' => [0b11111, 0b10000, 0b10000, 0b11110, 0b10000, 0b10000, 0b10000], - b'G' => [0b01111, 0b10000, 0b10000, 0b10011, 0b10001, 0b10001, 0b01111], - b'H' => [0b10001, 0b10001, 0b10001, 0b11111, 0b10001, 0b10001, 0b10001], - b'I' => [0b01110, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b01110], - b'J' => [0b00111, 0b00010, 0b00010, 0b00010, 0b00010, 0b10010, 0b01100], - b'K' => [0b10001, 0b10010, 0b10100, 0b11000, 0b10100, 0b10010, 0b10001], - b'L' => [0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b11111], - b'M' => [0b10001, 0b11011, 0b10101, 0b10101, 0b10001, 0b10001, 0b10001], - b'N' => [0b10001, 0b11001, 0b11001, 0b10101, 0b10011, 0b10011, 0b10001], - b'O' => [0b01110, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01110], - b'P' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10000, 0b10000, 0b10000], - b'Q' => [0b01110, 0b10001, 0b10001, 0b10001, 0b10101, 0b10010, 0b01101], - b'R' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10100, 0b10010, 0b10001], - b'S' => [0b01111, 0b10000, 0b10000, 0b01110, 0b00001, 0b00001, 0b11110], - b'T' => [0b11111, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100], - b'U' => [0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01110], - b'V' => [0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01010, 0b00100], - b'W' => [0b10001, 0b10001, 0b10001, 0b10101, 0b10101, 0b11011, 0b10001], - b'X' => [0b10001, 0b10001, 0b01010, 0b00100, 0b01010, 0b10001, 0b10001], - b'Y' => [0b10001, 0b10001, 0b01010, 0b00100, 0b00100, 0b00100, 0b00100], - b'Z' => [0b11111, 0b00001, 0b00010, 0b00100, 0b01000, 0b10000, 0b11111], - b'.' => [0, 0, 0, 0, 0, 0b01100, 0b01100], - b'/' => [0b00001, 0b00010, 0b00010, 0b00100, 0b01000, 0b01000, 0b10000], - b'-' => [0, 0, 0, 0b11111, 0, 0, 0], - b' ' => [0; 7], - _ => [0b11111, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b11111], - } -} - /// The box's size in pixels, a dot being `scale` of them each way. const fn size(scale: u32) -> (u32, u32) { ((COLUMNS * CELL.0 + 2 * RIM) * scale, (LINES * CELL.1 + 2 * RIM) * scale) @@ -132,20 +85,6 @@ fn lit(lines: &[String], x: u32, y: u32) -> bool { (glyph(c.to_ascii_uppercase())[(y % CELL.1) as usize] >> (GLYPH.0 - 1 - x % CELL.0)) & 1 != 0 } -/// The bytes of a black and a white pixel of a swap chain's format. -fn colours(format: DXGI_FORMAT) -> Option<[&'static [u8]; 2]> { - Some(match format { - DXGI_FORMAT_R8G8B8A8_UNORM | DXGI_FORMAT_B8G8R8A8_UNORM => [&[0, 0, 0, 0xFF], &[0xFF; 4]], - DXGI_FORMAT_R10G10B10A2_UNORM => [&[0, 0, 0, 0xC0], &[0xFF; 4]], - // Halves of 0 and 1. - DXGI_FORMAT_R16G16B16A16_FLOAT => [ - &[0, 0, 0, 0, 0, 0, 0, 0x3C], - &[0, 0x3C, 0, 0x3C, 0, 0x3C, 0, 0x3C], - ], - _ => return None, - }) -} - /// The box as rows of `pitch` bytes. fn painted(lines: &[String], scale: u32, colours: [&[u8]; 2], pitch: usize) -> Vec { let (width, height) = size(scale); diff --git a/crates/victory-gpu/src/lib.rs b/crates/victory-gpu/src/lib.rs index ae08b6e..f1cc6be 100644 --- a/crates/victory-gpu/src/lib.rs +++ b/crates/victory-gpu/src/lib.rs @@ -43,6 +43,9 @@ mod book; mod heap_marks; #[cfg(windows)] mod host; +/// The F1 settings menu is shown (`host/menu.rs`): the title gets no keyboard meanwhile +/// (read by the input module). +pub static SETTINGS_MENU_OPEN: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); #[cfg(windows)] mod indirect; #[cfg(windows)] diff --git a/crates/victory-gpu/src/streamline.rs b/crates/victory-gpu/src/streamline.rs index 6b18c5f..5b7a2fc 100644 --- a/crates/victory-gpu/src/streamline.rs +++ b/crates/victory-gpu/src/streamline.rs @@ -259,8 +259,10 @@ struct Calls { optimal: Vec<([u32; 2], u32, Option<[u32; 2]>)>, /// The mode, sizes and preset the last options named. last: Option<(u32, [u32; 2], [u32; 2])>, - /// Frame generation: on, and the frame whose simulation began. + /// Frame generation: on, the frames for each rendered one last asked of it (0 off), and + /// the frame whose simulation began. framegen_on: bool, + framegen_times: u32, simulating: Option, } @@ -268,6 +270,7 @@ static CALLS: Mutex = Mutex::new(Calls { optimal: Vec::new(), last: None, framegen_on: false, + framegen_times: 0, simulating: None, }); @@ -1450,8 +1453,42 @@ pub(crate) fn present_begins(frame: u64, planes: Planes<'_>) -> Option` (a check with nobody at the keys): the amount is asked + // anew every that many presents, in turn 2, 4, off and 6, as the settings menu would. + static CYCLE: std::sync::OnceLock = std::sync::OnceLock::new(); + let every = *CYCLE.get_or_init(|| std::env::var("VICTORY_FRAMEGEN_CYCLE").ok().and_then(|v| v.trim().parse().ok()).unwrap_or(0)); + if every > 0 { + static PRESENTS: AtomicU32 = AtomicU32::new(0); + let n = PRESENTS.fetch_add(1, Relaxed); + if n % every == 0 { + set_framegen([2, 4, 0, 6][(n / every % 4) as usize]); + } + } + let wanted = framegen_wanted(); + let on = on && wanted != 0; + let times = if on { wanted } else { 0 }; + if on != calls.framegen_on || times != calls.framegen_times { let mut options = abi::DlssgOptions::new(if on { abi::DLSSG_ON } else { abi::DLSSG_OFF }); + // `VICTORY_FRAMEGEN_X=2..6`: frames shown for each one rendered (2 unless set), no more + // than this card and driver generate (the state says how many: 5 on an RTX 50). + let mut generated = wanted.max(2) - 1; + if on + && generated > 1 + && let Some(get_state) = functions.dlssg_get_state + { + let mut state = abi::DlssgState::default(); + // SAFETY: a structure to fill, no options. + let code = unsafe { get_state(&viewport, &mut state, std::ptr::null()) }; + let most = if code == 0 { state.num_frames_to_generate_max.max(1) } else { 1 }; + if generated > most { + tracing::warn!(asked = generated + 1, given = most + 1, "DLSS Frame Generation: more frames asked than this card generates"); + generated = most; + } + } + options.num_frames_to_generate = generated; + FG_TIMES.store(generated + 1, Relaxed); options.flags = abi::DLSSG_RETAIN_RESOURCES_WHEN_OFF; options.num_back_buffers = 2; options.color_width = planes.size[0]; @@ -1459,9 +1496,20 @@ pub(crate) fn present_begins(frame: u64, planes: Planes<'_>) -> Option u32 { + static TIMES: std::sync::OnceLock = std::sync::OnceLock::new(); + *TIMES.get_or_init(|| { + std::env::var("VICTORY_FRAMEGEN_X").ok().and_then(|v| v.trim().parse::().ok()).map_or(2, |n| if n == 0 { 0 } else { n.clamp(2, 6) }) + }) +} + +/// Frames shown for each one rendered, as last given to frame generation. +static FG_TIMES: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(2); + +/// What is asked of frame generation now: 0 off, 2..6 frames shown for each one rendered; +/// `u32::MAX`: not asked yet (then [`framegen_times`], the start's). +static FG_WANTED: AtomicU32 = AtomicU32::new(u32::MAX); +/// Frames frame generation showed for the last frame presented (1 while it is off). +static FG_PER: AtomicU32 = AtomicU32::new(1); + +fn framegen_wanted() -> u32 { + match FG_WANTED.load(Relaxed) { + u32::MAX => framegen_times(), + n => n, + } +} + +/// Whether frame generation can be switched and changed while the title runs: it was planned +/// at the start, so our swap chain is Streamline's proxy (the F1 menu asks). +pub(crate) fn framegen_live() -> bool { + FG_READY.load(Acquire) && SWAP_CHAIN_PROXIED.load(Acquire) +} + +/// Asks frame generation off (0) or for `times` frames shown for each one rendered (2..6), +/// from the next present on. +pub(crate) fn set_framegen(times: u32) { + FG_WANTED.store(if times == 0 { 0 } else { times.clamp(2, 6) }, Relaxed); + tracing::info!(times, "DLSS Frame Generation: asked from the settings menu"); +} + +/// For the frame-rate texts: frames shown for each one rendered (1 without frame generation). +pub(crate) fn shown_per_frame() -> u32 { + FG_PER.load(Relaxed).max(1) +} + /// After our swap chain's Present: the frame's last marker, the next /// frame's first, and what frame generation reports. pub(crate) fn present_ends(presenting: Option) { @@ -1553,6 +1644,7 @@ pub(crate) fn present_ends(presenting: Option) { let code = unsafe { get_state(&viewport, &mut state, std::ptr::null()) }; spent(T_STATE, asked); if code == 0 { + FG_PER.store(state.num_frames_actually_presented.max(1), Relaxed); FG_SHOWN.fetch_add(u64::from(state.num_frames_actually_presented), Relaxed); FG_SHOWN_ALL.fetch_add(u64::from(state.num_frames_actually_presented), Relaxed); let before = FG_STATUS.swap(state.status, Relaxed); @@ -1581,6 +1673,8 @@ pub(crate) fn resizing() { // SAFETY: filled options. unsafe { set_options(&viewport, &options) }; calls.framegen_on = false; + calls.framegen_times = 0; + FG_PER.store(1, Relaxed); } } diff --git a/crates/victory-hle/src/modules/gameinput.rs b/crates/victory-hle/src/modules/gameinput.rs index 9cf1666..0e24b17 100644 --- a/crates/victory-hle/src/modules/gameinput.rs +++ b/crates/victory-hle/src/modules/gameinput.rs @@ -1208,6 +1208,10 @@ mod host { } fn keys(&mut self) -> Vec { + // The F1 settings menu takes the keyboard while it is shown. + if victory_gpu::SETTINGS_MENU_OPEN.load(std::sync::atomic::Ordering::Relaxed) { + return Vec::new(); + } let mut down = scripted(); if focused() { // Left/right modifier keys only, as devices report them; no diff --git a/docs/README-foxhound.md b/docs/README-foxhound.md new file mode 100644 index 0000000..72926e7 --- /dev/null +++ b/docs/README-foxhound.md @@ -0,0 +1,187 @@ +# foxhound + +A fork of [VIctory](https://github.com/Marvisak/VIctory), a compatibility layer that runs an Xbox Series title +natively on Windows from files **you** supply. foxhound is tuned for **NVIDIA RTX** GPUs: DLSS Super Resolution and +DLSS Frame Generation in place of the title's own upscaling, the Series X profile at a native 2560x1440, and fewer +stalls at scene cuts. + +> **This repository contains no game files, code or assets.** You need your own legally obtained copy of the +> title. foxhound is not affiliated with or endorsed by the title's developer or publisher, nor by NVIDIA. +> See [docs/asset-policy.md](docs/asset-policy.md). + +## Where it stands + +Tested on one PC: Windows 11, Ryzen 7 7800X3D, 32 GB RAM, **RTX 4070 SUPER 12 GB**, NVMe SSD; the Xbox Series +build **v1.0.2.1** of the title, Series X profile, 2560x1440 output, DLSS Quality. Frame times are the layer's +own count, in the opening scenes unless noted. + +| | Frame time | +|---|---| +| Opening, gameplay | 34-37 ms (27-30 fps); our CPU work per frame sets it | +| Opening, cutscenes | median 36-38 ms, 95th percentile 49-58 ms, no second over 100 ms | +| Open water (first boat ride) | about 47 ms (21 fps); the GPU sets it there | +| With `-FrameGen` | every frame the title renders is shown twice (2x presented) | +| Memory | about 8 GB of VRAM; 32 GB of RAM is enough, 64 GB is more comfortable | + +What is known to be wrong: + +- **No ray tracing.** The title traces its indirect light, reflections and lamp shadows in its own compute + shaders. They are off (`VICTORY_BVH_BUILDER=1` turns them on: about 3 fps and a broken picture today). An + estimate stands in for indirect light and for reflections of opaque surfaces: rooms are lit, but reflections + are blurry, and in cutscenes they can still show the sky's bright colour. +- **Left out:** the heat-haze / in-scattering pass (it smears blocks of pixels, also on water) and the decal + heap's defragmentation (5.6 ms of GPU a frame). `VICTORY_LEAVE_OUT` names them. +- **Hitches:** some single frames of 70-190 ms in cutscenes while the title streams. +- **Frame rate:** the title runs at 30 fps. `-Fps 60` lets frames start every 1/60 s, but the layer itself costs + about 33 ms a frame today, so it stays near 30. 60 fps is the goal. +- **The first run of every new build stutters** while the driver compiles pipelines (see *Warming up* below). + +## What you need + +- Windows 10 or 11 (x64), a CPU with AVX2, 32 GB of RAM or more, an SSD. +- An NVIDIA GeForce RTX GPU with a recent driver for DLSS (RTX 40 or later for Frame Generation, with + hardware-accelerated GPU scheduling on). Any Direct3D 12 GPU with shader model 6.6 and mesh shaders runs the + layer without DLSS. +- **Your own dump** of the title's Xbox Series build v1.0.2.1 (the folder with `game_scarlett_master.exe`). + Other builds may start, but the image patches (1440p output, FidelityFX path, frame rate) check every byte + they change and leave a differing build alone. +- [Rust](https://rustup.rs) (the toolchain is pinned in `rust-toolchain.toml`; rustup fetches it), and the + **Visual Studio Build Tools** with "Desktop development with C++" (MSVC and a Windows SDK). +- For DLSS: NVIDIA's **Streamline SDK** (below). You download it yourself; nothing of NVIDIA's is in this + repository. + +## Build + +```powershell +git clone https://github.com/readmet3xt-lab/foxhound +cd foxhound +cargo build --release --locked -p victory +``` + +The diagnostics build (frame timelines, captures, GPU timing) is optional: +`cargo build --locked --profile diag -p victory --features diagnostics`. + +## Set up + +1. **Point it at your copy.** Copy `victory.example.toml` to `victory.toml` (git-ignored) and set `game_dir` to + your dump's folder. Keep your files **outside** this repository; the tools refuse otherwise. + + ```toml + [paths] + game_dir = 'D:\Games\MyDump' + ``` + +2. **DLSS (optional, recommended on RTX).** Download the Streamline SDK release from + (tested: `streamline-sdk-v2.14.16.zip`; it comes under + NVIDIA's RTX SDK license, which you accept yourself), unpack it **outside** the repository, and point foxhound + at its `bin\x64` folder: + + ```powershell + [Environment]::SetEnvironmentVariable('VICTORY_STREAMLINE_DIR', 'D:\sdk\streamline-sdk-v2.14.16\bin\x64', 'User') + ``` + + Check it without the title: `target\release\victory.exe upscaler-check --device` (and `--present` for Frame + Generation). Details: [docs/dlss.md](docs/dlss.md). Without Streamline the launcher runs without DLSS. + +3. **Translate the shaders ahead** (a few minutes, once per new build of foxhound): + + ```powershell + $env:VICTORY_HOST_WAVE = '32' # NVIDIA runs 32-lane waves; leave it out on AMD + target\release\victory.exe shaders + ``` + +## Run + +```powershell +.\scripts\play-foxhound.ps1 -Exe 'D:\Games\MyDump\game_scarlett_master.exe' +``` + +| Option | What | +|---|---| +| *(none)* | Series X profile, 2560x1440, DLSS Quality (if Streamline is set up), all fixes on | +| `-Dlss off` / `dlaa` / `balanced` / `performance` | the title's own upscaling, or another DLSS mode | +| `-FrameGen` | DLSS Frame Generation (about +1.4 GB of VRAM) | +| `-SeriesS` | the Series S profile: 1280x720 inside, faster, softer | +| `-Res 1080to1440` / `4k` | scene at 1080p upscaled by the title / the stock 3840x2160 output | +| `-Build diag` | the diagnostics build | +| `-More @{VICTORY_X='1'}` | add or override any switch | + +Full screen: start the game, then run `.\scripts\fullscreen.ps1` in another window (borderless, the size of the +monitor the game is on). + +Logs go to `%LOCALAPPDATA%\victory\logs`, saves to `%LOCALAPPDATA%\victory\data`. Close the game window to quit. + +### Warming up (once per build or driver) + +The first run of a build compiles pipelines while playing and stutters. Runs write down every pipeline the title +makes (`VICTORY_PIPELINE_BOOK=1`, set by the launcher); afterwards make them all ahead: + +```powershell +$env:VICTORY_HOST_WAVE = '32' +target\release\victory.exe warm +``` + +The NVIDIA driver keeps its compiled pipelines **per program path**: a build run from another folder starts cold. + +## Switches worth knowing + +Every `VICTORY_...` switch is described in a comment where the code reads it. The launcher's full set is in +`scripts/play-foxhound.ps1`; these are the ones foxhound added or changed: + +| Switch | Launcher | What | +|---|---|---| +| `VICTORY_DLSS`, `VICTORY_DLSS_MODE` | `quality` | DLSS Super Resolution through the title's FidelityFX dispatch | +| `VICTORY_FRAMEGEN` | off (`-FrameGen`) | DLSS Frame Generation, with the picture before the HUD tagged | +| `VICTORY_NATIVE_1440P` | on | Series X renders and outputs 2560x1440 (image patched) | +| `VICTORY_SOFT_VIEWS` | `copies` | the title's tiled-heap page mappings kept without Windows views: no freezes at scene cuts | +| `VICTORY_WC_NO_BACK`, `_MIN_KB` | `1`, `1024` | shader writes into big write-combined copies are not copied back | +| `VICTORY_AMBIENT`, `VICTORY_AMBIENT_SPECULAR` | `0.8`, `1` | estimates of indirect light and of reflections (no ray tracing) | +| `VICTORY_EARLY_DEPTH` | on | pixel programs keep the console's early depth test | +| `VICTORY_PRELUDE_UPLOADS`, `VICTORY_SHOW_NEW_LATER`, `VICTORY_TABLED_REREAD` | on | texture upload order and slot changes (flicker, device losses) | +| `VICTORY_SYNC_IN_PLACE`, `VICTORY_SPANS_QUICK`, `VICTORY_HEAP_SYNC_AT_SUBMIT` | on | cheaper descriptor-heap bookkeeping | +| `VICTORY_PORT_CONSTANTS` | off | the title's constants heap read in place: less CPU, but on a 12 GB card the GPU then waits (slower overall) | +| `VICTORY_FRAME_INTERVAL_MS` | off | experimental: the title's own 30 fps setting patched to a higher rate | +| `VICTORY_BVH_BUILDER` | off | the title's ray tracing (slow, broken) | + +## How it works, and the findings + +- [docs/architecture.md](docs/architecture.md): the layer's parts. +- [docs/findings.md](docs/findings.md): measurements behind the choices. +- [docs/dlss.md](docs/dlss.md): DLSS and Frame Generation. +- [docs/fork-ray-tracing.md](docs/fork-ray-tracing.md): the title's ray tracing and the light estimate. +- [docs/replay.md](docs/replay.md): recording a frame and replaying it. +- [docs/asset-policy.md](docs/asset-policy.md): what may and may not be in this repository. + +## Contributing + +Issues and pull requests are welcome. Never attach or commit anything from the game: files, dumps, shader dumps +or extracted data. Describe faults technically. `cargo xtask policy` (also the pre-commit hook in `.githooks/`) +checks the asset policy. + +## Credits + +A tree of other people's work with more on top; the history is kept, and commits taken from elsewhere name the +commit and its author. + +- **[VIctory](https://github.com/Marvisak/VIctory)** by Marvisak and its contributors: the loader, the runtime + services, the Direct3D 12 back end and the shader recompiler. +- **[fxceless/victory-fork](https://github.com/fxceless/victory-fork)** and the people whose pull requests it carries. +- **[avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX)**: the submission line, write + guards, relay and much of the speed work this fork starts from. +- **[codec-d/cool_fox](https://github.com/codec-d/cool_fox)**: the base this fork was taken from. +- **[DexNom/VIctory](https://github.com/DexNom/VIctory)**: native 1440p output, the FidelityFX path on Series X, + ray tracing fixes. +- **[Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD)**: the light estimate, renderer + ports (constants heap in place, heap records), texture upload order, the frame rate switch; ported commits name + their source. +- **[FQY55kai/ZJOU-VICTORY](https://github.com/FQY55kai/ZJOU-VICTORY)**, **[myokex/victory-amd](https://github.com/myokex/victory-amd)** + (with Spexivus, joroyt and tightfall), Joshua Odom, **Geckomacabre** and **cxy0072019-sketch**. +- **[XCL](https://github.com/ivall/xcl)** (GPL-2.0-only) was read for how the same title behaves under another + layer; no code of it is here. +- NVIDIA Streamline, DLSS and Reflex are NVIDIA's; they are loaded at run time from a folder you supply. +- Much of this fork's code was written with [Claude Code](https://claude.com/claude-code). + +## License + +GPL-3.0-or-later, as VIctory. See [LICENSE](LICENSE); the one file that is not covered is named in +[docs/asset-policy.md](docs/asset-policy.md). diff --git a/scripts/get-nvidia-sdks.ps1 b/scripts/get-nvidia-sdks.ps1 new file mode 100644 index 0000000..72a60bc --- /dev/null +++ b/scripts/get-nvidia-sdks.ps1 @@ -0,0 +1,136 @@ +# Fetches the NVIDIA files DLSS and DLSS frame generation need (about 70 MB) from NVIDIA's own GitHub into +# nvidia-sdk\Streamline\bin\x64 here (git-ignored), where scripts\play-foxhound.ps1 looks for them. They are +# NVIDIA's, under NVIDIA's licences (saved beside them: read them); this repository does not and may not carry +# them, so each person gets them from NVIDIA directly. Get-NVIDIA-DLSS.cmd in the repository's folder runs this. +# Nothing of NVIDIA's is needed to build the layer: the files are loaded when the game runs. +param( + [string]$StreamlineTag = 'v2.14.16' +) +$ProgressPreference = 'SilentlyContinue' # Invoke-WebRequest's progress bar makes it many times slower +[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 +$root = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path +$sdk = Join-Path $root 'nvidia-sdk' +$sl = Join-Path $sdk 'Streamline' +$bin = Join-Path $sl 'bin\x64' +# What is loaded when the game runs: Streamline's interposer and plugins, DLSS and the frame generation model. +$dlls = 'sl.interposer.dll', 'sl.common.dll', 'sl.dlss.dll', 'sl.dlss_g.dll', 'sl.reflex.dll', 'sl.pcl.dll', 'nvngx_dlss.dll', 'nvngx_dlssg.dll' + +# One file from a URL, with curl's progress line where Windows has curl (it has since Windows 10 1803). +function Get-File([string]$Url, [string]$To) { + New-Item -ItemType Directory -Force (Split-Path $To) | Out-Null + $part = "$To.part" + if (Get-Command curl.exe -ErrorAction SilentlyContinue) { + & curl.exe --location --fail --silent --show-error --progress-bar --output $part $Url + if ($LASTEXITCODE -ne 0) { Remove-Item $part -ErrorAction SilentlyContinue; throw "could not get $Url" } + } else { + Invoke-WebRequest -Uri $Url -OutFile $part -UseBasicParsing -ErrorAction Stop + } + Move-Item $part $To -Force +} + +# Bytes first..last of a URL. +function Get-Range([string]$Url, [long]$First, [long]$Last) { + $q = [Net.HttpWebRequest]::Create($Url) + $q.UserAgent = 'get-nvidia-sdks' + $q.AddRange($First, $Last) + $r = $q.GetResponse() + try { + if ([int]$r.StatusCode -ne 206) { throw 'the server does not give parts of the file' } + $m = New-Object IO.MemoryStream + $r.GetResponseStream().CopyTo($m) + , $m.ToArray() + } finally { $r.Close() } +} + +# Takes the named files out of a zip on a server without downloading the whole zip: its directory is at +# its end, and each file in it can be asked for by its place. $Want: a regex on the paths in the zip. +# Each goes into $Into under the part of its path after the SDK's top folder. +function Get-FromZip([string]$Url, [string]$Want, [string]$Into) { + # Where the file really is (the download address redirects), and how long it is. + $h = [Net.HttpWebRequest]::Create($Url); $h.Method = 'HEAD'; $h.UserAgent = 'get-nvidia-sdks' + $r = $h.GetResponse(); $real = $r.ResponseUri.AbsoluteUri; $length = $r.ContentLength; $r.Close() + $tailLen = [Math]::Min($length, 2MB) + $tail = Get-Range $real ($length - $tailLen) ($length - 1) + $end = -1 + for ($i = $tail.Length - 22; $i -ge 0; $i--) { + if ($tail[$i] -eq 0x50 -and $tail[$i + 1] -eq 0x4b -and $tail[$i + 2] -eq 5 -and $tail[$i + 3] -eq 6) { $end = $i; break } + } + if ($end -lt 0) { throw 'no zip directory found' } + $dirSize = [BitConverter]::ToUInt32($tail, $end + 12) + $dirAt = [BitConverter]::ToUInt32($tail, $end + 16) + if ($dirAt -eq [uint32]::MaxValue) { throw 'a zip64 archive' } + $dir = if ($dirAt -ge $length - $tailLen) { + $from = [int]($dirAt - ($length - $tailLen)); , $tail[$from..($from + $dirSize - 1)] + } else { Get-Range $real $dirAt ($dirAt + $dirSize - 1) } + $got = 0 + $at = 0 + while ($at + 46 -le $dir.Length -and [BitConverter]::ToUInt32($dir, $at) -eq 0x02014b50) { + $method = [BitConverter]::ToUInt16($dir, $at + 10) + $packed = [BitConverter]::ToUInt32($dir, $at + 20) + $size = [BitConverter]::ToUInt32($dir, $at + 24) + $nameLen = [BitConverter]::ToUInt16($dir, $at + 28) + $extraLen = [BitConverter]::ToUInt16($dir, $at + 30) + $noteLen = [BitConverter]::ToUInt16($dir, $at + 32) + $headerAt = [BitConverter]::ToUInt32($dir, $at + 42) + $name = [Text.Encoding]::UTF8.GetString($dir, $at + 46, $nameLen) + $at += 46 + $nameLen + $extraLen + $noteLen + if ($name -notmatch $Want) { continue } + # The file's own header (its extra field may be longer than the directory's), then its bytes. + $piece = Get-Range $real $headerAt ($headerAt + 30 + $nameLen + 2048 + $packed - 1) + if ([BitConverter]::ToUInt32($piece, 0) -ne 0x04034b50) { throw "no file header for $name" } + $dataAt = 30 + [BitConverter]::ToUInt16($piece, 26) + [BitConverter]::ToUInt16($piece, 28) + if ($dataAt + $packed -gt $piece.Length) { throw "the header of $name is longer than expected" } + $out = [IO.MemoryStream]::new() + if ($method -eq 0) { $out.Write($piece, $dataAt, [int]$packed) } + elseif ($method -eq 8) { + $in = [IO.MemoryStream]::new($piece, $dataAt, [int]$packed) + $z = [IO.Compression.DeflateStream]::new($in, [IO.Compression.CompressionMode]::Decompress) + $z.CopyTo($out); $z.Close() + } else { throw "$name is packed in a way this script does not know ($method)" } + if ($out.Length -ne $size) { throw "$name came out $($out.Length) bytes long, not $size" } + $rel = ($name -replace '^.*?(?=(bin/x64/|license\.txt$))', '') -replace '/', '\' + $to = Join-Path $Into $rel + New-Item -ItemType Directory -Force (Split-Path $to) | Out-Null + [IO.File]::WriteAllBytes($to, $out.ToArray()) + Write-Host (" {0} {1:N1} MB" -f $rel, ($size / 1MB)) + $got++ + } + $got +} + +Write-Host "NVIDIA Streamline $StreamlineTag with DLSS and frame generation, from github.com/NVIDIA-RTX/Streamline (about 70 MB):" +$missing = @($dlls | Where-Object { -not (Test-Path (Join-Path $bin $_)) }) +if (-not $missing) { + Write-Host " all there already: $bin" +} else { + $url = "https://github.com/NVIDIA-RTX/Streamline/releases/download/$StreamlineTag/streamline-sdk-$StreamlineTag.zip" + $names = ($dlls | ForEach-Object { [regex]::Escape($_) }) -join '|' + $want = "(^|/)bin/x64/($names|[^/]*license[^/]*\.txt)$|^([^/]+/)?license\.txt$" + try { [void](Get-FromZip $url $want $sl) } + catch { Write-Host " Taking the files out of the archive in place did not work ($($_.Exception.Message))." } + if (@($dlls | Where-Object { -not (Test-Path (Join-Path $bin $_)) })) { + # The whole archive then (263 MB). + Write-Host ' Getting the whole archive instead (263 MB) ...' + $zip = Join-Path $sdk "streamline-sdk-$StreamlineTag.zip" + Get-File $url $zip + $into = Join-Path $sdk 'streamline-unpacked' + Expand-Archive -Path $zip -DestinationPath $into -Force -ErrorAction Stop + $found = Get-ChildItem $into -Recurse -Filter 'sl.interposer.dll' | + Where-Object { $_.FullName -match '\\bin\\x64\\sl\.interposer\.dll$' -and $_.FullName -notmatch '\\development\\' } | + Select-Object -First 1 + if (-not $found) { throw 'The Streamline archive has no bin\x64\sl.interposer.dll.' } + $top = Split-Path (Split-Path (Split-Path $found.FullName)) + New-Item -ItemType Directory -Force $bin | Out-Null + Get-ChildItem (Join-Path $top 'bin\x64') -File | + Where-Object { $dlls -contains $_.Name -or $_.Name -match 'license.*\.txt$' } | + Copy-Item -Destination $bin -Force + Copy-Item (Join-Path $top 'license.txt') $sl -Force -ErrorAction SilentlyContinue + Remove-Item $into -Recurse -Force -ErrorAction SilentlyContinue + Remove-Item $zip -Force + } +} +$still = @($dlls | Where-Object { -not (Test-Path (Join-Path $bin $_)) }) +if ($still) { throw "Not there after all: $($still -join ', ')" } +Write-Host " licences: $(Join-Path $sl 'license.txt') (Streamline) and the *.license.txt files in $bin (DLSS, Reflex)" +Write-Host '' +Write-Host 'Done. scripts\play-foxhound.ps1 uses them from its next start.' \ No newline at end of file diff --git a/scripts/play-foxhound.ps1 b/scripts/play-foxhound.ps1 index 4af8d5d..a93fe45 100644 --- a/scripts/play-foxhound.ps1 +++ b/scripts/play-foxhound.ps1 @@ -8,6 +8,10 @@ # .\scripts\play-foxhound.ps1 -Exe ... -Build diag diagnostics build (slower; captures, timelines) # .\scripts\play-foxhound.ps1 -Exe ... -More @{VICTORY_AMBIENT_SPECULAR='0'} add or override switches # +# In the game, F1 opens a settings menu (arrow keys pick and change, Enter does it). What it saves goes to +# victory-settings.txt in the repository's folder and is applied here at every start, over the options above; +# delete that file to go back to them. +# # Build first (README). Run from a normal window, not as administrator. Each run writes a log to # %LOCALAPPDATA%\victory\logs. Every VICTORY_... switch is described in a comment where the code reads it. param( @@ -21,11 +25,38 @@ param( [ValidateSet('off', 'dlaa', 'quality', 'balanced', 'performance')][string]$Dlss = 'quality', # DLSS Frame Generation (RTX 40 or later, hardware-accelerated GPU scheduling on); needs DLSS. [switch]$FrameGen, - # Frames begin every 1/Fps s whatever the title asks (it asks 1/30); the frame time is the layer's limit. - [ValidateRange(1, 1000)][int]$Fps = 0, + # Frames shown for each one rendered with -FrameGen: 2 to 6 (more than 2 needs an RTX 50; the layer asks the + # driver how many this card does and gives no more). + [ValidateRange(2, 6)][int]$FrameGenX = 2, + # Frame generation is made ready at every start with Streamline, on or off, so that the F1 menu switches it + # and changes its amount while playing. -NoFrameGenReady: only with -FrameGen, as before. + [switch]$NoFrameGenReady, + # Frames begin every 1/Fps s whatever the title asks (it asks 1/30). 1000, the default: no cap, a frame + # begins as soon as the last is done. 30: the title's own rate. + [ValidateRange(1, 1000)][int]$Fps = 1000, [hashtable]$More = @{} ) $repo = Split-Path $PSScriptRoot -Parent +# What the F1 menu saved: its own choices (VICTORY_MENU_...) stand in for this script's options, and its +# switches go over the settings below. An empty value unsets a switch. +$menuFile = Join-Path $repo 'victory-settings.txt' +$menu = [ordered]@{} +if (Test-Path -LiteralPath $menuFile) { + foreach ($line in Get-Content -LiteralPath $menuFile) { + if ($line -match '^\s*(VICTORY_[A-Z0-9_]+)\s*=(.*)$') { $menu[$Matches[1]] = $Matches[2].Trim() } + } +} +$fpsWanted = $Fps +if ($menu.Contains('VICTORY_MENU_CONSOLE')) { $SeriesS = $menu['VICTORY_MENU_CONSOLE'] -eq 'series-s' } +if ($menu['VICTORY_MENU_RES'] -in '1440', '1080to1440', '4k') { $Res = $menu['VICTORY_MENU_RES'] } +if ($menu['VICTORY_MENU_DLSS'] -in 'off', 'dlaa', 'quality', 'balanced', 'performance') { $Dlss = $menu['VICTORY_MENU_DLSS'] } +$timesWanted = $FrameGenX +if ($menu.Contains('VICTORY_MENU_FRAMEGEN')) { + # 0: off; 2 to 6: that many frames shown for each one rendered (1, from an older file: 2). + $FrameGen = $menu['VICTORY_MENU_FRAMEGEN'] -match '^[1-6]$' + if ($menu['VICTORY_MENU_FRAMEGEN'] -match '^[2-6]$') { $timesWanted = [int]$menu['VICTORY_MENU_FRAMEGEN'] } +} +if ($menu['VICTORY_MENU_FPS'] -match '^\d+$' -and [int]$menu['VICTORY_MENU_FPS'] -ge 1 -and [int]$menu['VICTORY_MENU_FPS'] -le 1000) { $fpsWanted = [int]$menu['VICTORY_MENU_FPS'] } $settings = @{ # Submission and copy machinery VICTORY_THIN = '1'; VICTORY_JOIN_PARTS = '8'; VICTORY_RELAY = '2'; VICTORY_RELAY_COPY = '1'; VICTORY_WIDE_BACK = '1' @@ -58,20 +89,51 @@ if (-not $SeriesS) { elseif ($Res -eq '1080to1440') { $settings.VICTORY_RENDER_1080P = '1' } } if ($Dlss -ne 'off') { - $sl = if ($env:VICTORY_STREAMLINE_DIR) { $env:VICTORY_STREAMLINE_DIR } else { 'C:\dev\sdk\streamline-sdk-v2.14.16\bin\x64' } + # NVIDIA's files: where VICTORY_STREAMLINE_DIR says, else where Get-NVIDIA-DLSS.cmd puts them. + $sl = if ($env:VICTORY_STREAMLINE_DIR) { $env:VICTORY_STREAMLINE_DIR } else { Join-Path $repo 'nvidia-sdk\Streamline\bin\x64' } if (Test-Path (Join-Path $sl 'sl.interposer.dll')) { $settings.VICTORY_DLSS = '1'; $settings.VICTORY_DLSS_MODE = $Dlss; $settings.VICTORY_STREAMLINE_DIR = $sl - if ($FrameGen) { $settings.VICTORY_FRAMEGEN = '1' } + if ($FrameGen) { $settings.VICTORY_FRAMEGEN = '1'; $settings.VICTORY_FRAMEGEN_X = [string]$timesWanted } + elseif (-not $NoFrameGenReady) { $settings.VICTORY_FRAMEGEN = '1'; $settings.VICTORY_FRAMEGEN_X = '0' } # ready, off + # Frame generation takes 1.5 to 2 GB of the card's memory, which the layer otherwise fills with textures up + # to nine tenths of its budget (on a 12 GB card it then ran out: no generated frames). On from the start, it + # is left a fifth of the budget; ready but off, a little less is held back. + if ($settings.VICTORY_FRAMEGEN -eq '1') { $settings.VICTORY_TEXTURE_ROOM_PERCENT = if ($FrameGen) { '80' } else { '86' } } } else { - Write-Host "No NVIDIA Streamline in $sl (set VICTORY_STREAMLINE_DIR, see README): running without DLSS." + Write-Host "No NVIDIA files in ${sl}: running without DLSS and frame generation. Get-NVIDIA-DLSS.cmd in the" + Write-Host "repository folder fetches them from NVIDIA once (about 70 MB); VICTORY_STREAMLINE_DIR names another folder." } } -if ($Fps -gt 0) { $settings.VICTORY_FRAME_INTERVAL_US = [string][int][math]::Round(1000000 / $Fps) } +if ($fpsWanted -gt 0) { $settings.VICTORY_FRAME_INTERVAL_US = [string][int][math]::Round(1000000 / $fpsWanted) } +foreach ($k in $menu.Keys) { + if ($k -like 'VICTORY_MENU_*') { continue } + if ($menu[$k]) { $settings[$k] = $menu[$k] } else { $settings.Remove($k) } +} foreach ($k in $More.Keys) { $settings[$k] = $More[$k] } $console = if ($SeriesS) { 'series-s' } else { 'series-x' } +# For the menu: what it shows as the current choices, where it saves, and how it starts the game again +# (-More is not carried over a restart from the menu). +$settings.VICTORY_MENU_CONSOLE = $console +$settings.VICTORY_MENU_RES = $Res +$settings.VICTORY_MENU_DLSS = if ($settings.VICTORY_DLSS -eq '1') { $Dlss } else { 'off' } +$settings.VICTORY_MENU_FRAMEGEN = if ($settings.VICTORY_FRAMEGEN -eq '1') { [string]$settings.VICTORY_FRAMEGEN_X } else { '0' } +$settings.VICTORY_MENU_FPS = [string]$fpsWanted +$settings.VICTORY_MENU_FILE = $menuFile +$settings.VICTORY_MENU_PLAY = $MyInvocation.MyCommand.Path +$settings.VICTORY_MENU_ARGS = "-Exe '$($Exe -replace "'", "''")' -Build $Build$(if ($NoFrameGenReady) { ' -NoFrameGenReady' })" $victory = Join-Path $repo "target\$Build\victory.exe" -if (-not (Test-Path $victory)) { Write-Host "No $victory. Build it first (README)."; return } +if (-not (Test-Path $victory)) { + # Not built yet: built here, once. + if (-not (Get-Command cargo -ErrorAction SilentlyContinue)) { Write-Host "No $victory, and no cargo to build it with: install Rust (README), then start this again."; return } + Write-Host 'Building the layer (a few minutes the first time) ...' + Push-Location $repo + try { + if ($Build -eq 'diag') { cargo build --locked --profile diag -p victory --features diagnostics } + else { cargo build --release --locked -p victory } + } finally { Pop-Location } + if (-not (Test-Path $victory)) { Write-Host "The build did not make $victory."; return } +} if (-not (Test-Path -LiteralPath $Exe)) { Write-Host "No $Exe."; return } # Switches left over in this window are cleared; path settings stay (victory.toml gives them otherwise). $paths = 'VICTORY_CONFIG', 'VICTORY_GAME_DIR', 'VICTORY_CACHE_DIR', 'VICTORY_DATA_DIR', 'VICTORY_STREAMLINE_DIR' diff --git a/scripts/play-nvidia.ps1 b/scripts/play-nvidia.ps1 new file mode 100644 index 0000000..b7bd28d --- /dev/null +++ b/scripts/play-nvidia.ps1 @@ -0,0 +1,4 @@ +# The launcher under the name this fork has always had: everything goes on to play-foxhound.ps1 (its options +# are described at its top). +# scripts\play-nvidia.ps1 -Exe +& "$PSScriptRoot\play-foxhound.ps1" @args \ No newline at end of file