Compare commits
25
Commits
800dada337
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d62b86f4a | ||
|
|
ebd07c1dbb | ||
|
|
b78c91f127 | ||
|
|
e4f94bc86f | ||
|
|
9a97e0a537 | ||
|
|
21f8d46d02 | ||
|
|
a7c7819db4 | ||
|
|
f0114565e0 | ||
|
|
6a9d4732e9 | ||
|
|
604908e486 | ||
|
|
e4dbd89cd3 | ||
|
|
5d65b5d333 | ||
|
|
3f3e525d55 | ||
|
|
3a4ce453cd | ||
|
|
084321f432 | ||
|
|
de86068a05 | ||
|
|
5fff0f1fb7 | ||
|
|
8503191734 | ||
|
|
6f34121d31 | ||
|
|
84b4509fa3 | ||
|
|
c9067a7d3f | ||
|
|
63b902fe17 | ||
|
|
8fc22547c8 | ||
|
|
b4e1b08245 | ||
|
|
9b712a6ab2 |
No files matched your search
@@ -1,45 +0,0 @@
|
|||||||
@echo off
|
|
||||||
rem One-click GTA VI on VIctory-NVIDIA (DLSS + frame generation). ASCII only.
|
|
||||||
rem PLAY_FRAMEGEN.cmd menu
|
|
||||||
rem PLAY_FRAMEGEN.cmd 1..6 start that mode directly
|
|
||||||
rem PLAY_FRAMEGEN.cmd check only show paths and what is ready
|
|
||||||
setlocal
|
|
||||||
set "PS1=%~dp0scripts\play-gta6-framegen.ps1"
|
|
||||||
set "PSH=powershell"
|
|
||||||
where pwsh >nul 2>nul && set "PSH=pwsh"
|
|
||||||
if not exist "%PS1%" (
|
|
||||||
echo Not found: %PS1%
|
|
||||||
pause
|
|
||||||
exit /b 1
|
|
||||||
)
|
|
||||||
if /i "%~1"=="check" (
|
|
||||||
%PSH% -NoProfile -ExecutionPolicy Bypass -File "%PS1%" -Check
|
|
||||||
pause
|
|
||||||
exit /b 0
|
|
||||||
)
|
|
||||||
set "PICK=%~1"
|
|
||||||
if not "%PICK%"=="" goto :run
|
|
||||||
|
|
||||||
echo ================================================
|
|
||||||
echo GTA VI - VIctory-NVIDIA, DLSS + frame generation
|
|
||||||
echo (RTX 50: frame generation 4x automatically)
|
|
||||||
echo ================================================
|
|
||||||
echo 1. Series X 1440p + DLSS Quality + frame gen (recommended)
|
|
||||||
echo 2. Series X 1440p + DLSS Quality, no frame gen
|
|
||||||
echo 3. Series S + DLSS Quality + frame gen (faster, softer)
|
|
||||||
echo 4. Series X 1440p + DLSS Performance + frame gen
|
|
||||||
echo 5. EXTREME Series S: DLSS Performance + frame gen + big pools + High priority
|
|
||||||
echo 6. EXTREME Series X: 1440p DLSS Performance + frame gen + big pools + High priority
|
|
||||||
echo Q. Quit
|
|
||||||
echo.
|
|
||||||
choice /c 123456Q /n /m "Choose 1-6 or Q: "
|
|
||||||
if errorlevel 7 goto :end
|
|
||||||
if errorlevel 6 (set "PICK=6") else if errorlevel 5 (set "PICK=5") else if errorlevel 4 (set "PICK=4") else if errorlevel 3 (set "PICK=3") else if errorlevel 2 (set "PICK=2") else (set "PICK=1")
|
|
||||||
|
|
||||||
:run
|
|
||||||
echo.
|
|
||||||
%PSH% -NoProfile -ExecutionPolicy Bypass -File "%PS1%" -Mode %PICK%
|
|
||||||
|
|
||||||
:end
|
|
||||||
echo.
|
|
||||||
pause
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
@echo off
|
|
||||||
setlocal EnableExtensions DisableDelayedExpansion
|
|
||||||
if not "%~1"=="" if /i not "%~1"=="pareto-residency" (
|
|
||||||
echo Usage: Play-VIctory.cmd pareto-residency 1>&2
|
|
||||||
exit /b 2
|
|
||||||
)
|
|
||||||
if not defined VICTORY_GAME_DIR set "VICTORY_GAME_DIR=%~dp0..\GTA6.Xbox.v1.0.2.1"
|
|
||||||
if not exist "%VICTORY_GAME_DIR%\game_scarlett_master.exe" (
|
|
||||||
echo Set VICTORY_GAME_DIR to your own dump folder containing game_scarlett_master.exe. 1>&2
|
|
||||||
exit /b 2
|
|
||||||
)
|
|
||||||
set "runner=%~dp0victory-3d-rtx-pareto-residency.exe"
|
|
||||||
if not exist "%runner%" set "runner=%~dp0target\release\victory.exe"
|
|
||||||
if not exist "%runner%" (
|
|
||||||
echo Extract the Windows release or run cargo build --release --locked -p victory. 1>&2
|
|
||||||
exit /b 2
|
|
||||||
)
|
|
||||||
if not defined VICTORY_AMBIENT_AIR set "VICTORY_AMBIENT_AIR=1.5"
|
|
||||||
if not defined VICTORY_CACHE_DIR set "VICTORY_CACHE_DIR=%LOCALAPPDATA%\VIctory\cache-pareto"
|
|
||||||
if not defined VICTORY_TEXTURE_NO_WAIT set "VICTORY_TEXTURE_NO_WAIT=1"
|
|
||||||
if not defined VICTORY_RELAY set "VICTORY_RELAY=2"
|
|
||||||
if not defined VICTORY_WIDE_BACK set "VICTORY_WIDE_BACK=1"
|
|
||||||
if not defined VICTORY_CARD_REHASH_RUNS set "VICTORY_CARD_REHASH_RUNS=1"
|
|
||||||
if not defined VICTORY_JOIN_COPIES set "VICTORY_JOIN_COPIES=1"
|
|
||||||
if not defined VICTORY_INDIRECT_WINDOW set "VICTORY_INDIRECT_WINDOW=1"
|
|
||||||
if not defined VICTORY_RELAY_COPY set "VICTORY_RELAY_COPY=1"
|
|
||||||
if not defined VICTORY_CARD_STEPS set "VICTORY_CARD_STEPS=2"
|
|
||||||
if not defined VICTORY_INDIRECT_BATCH set "VICTORY_INDIRECT_BATCH=2"
|
|
||||||
if not defined VICTORY_MAP_THREADS set "VICTORY_MAP_THREADS=1"
|
|
||||||
if not defined VICTORY_CARD_AWAKE set "VICTORY_CARD_AWAKE=1"
|
|
||||||
if not defined VICTORY_SHOW_AFTER set "VICTORY_SHOW_AFTER=1"
|
|
||||||
if not defined VICTORY_AMBIENT set "VICTORY_AMBIENT=0.8"
|
|
||||||
if not defined VICTORY_THIN set "VICTORY_THIN=1"
|
|
||||||
if not defined VICTORY_JOIN_PARTS set "VICTORY_JOIN_PARTS=8"
|
|
||||||
if not defined VICTORY_UPLOAD_AHEAD set "VICTORY_UPLOAD_AHEAD=1"
|
|
||||||
if not defined VICTORY_LEVELS_ON_DEMAND set "VICTORY_LEVELS_ON_DEMAND=1"
|
|
||||||
if not defined VICTORY_CARD_BUFFERS_MIN_KB set "VICTORY_CARD_BUFFERS_MIN_KB=64"
|
|
||||||
if not defined VICTORY_LOG if not defined RUST_LOG set "VICTORY_LOG=warn"
|
|
||||||
"%runner%" run "%VICTORY_GAME_DIR%\game_scarlett_master.exe" --console series-s --execute
|
|
||||||
exit /b %errorlevel%
|
|
||||||
@@ -1,393 +1,223 @@
|
|||||||
# VIctory on NVIDIA
|
# VIctory — 6 GB VRAM / 16 GB RAM & NVIDIA RTX Edition
|
||||||
|
|
||||||
> **Reporting a problem?** Please attach **both** logs from the run that went
|
> ### Support Me a Coffee
|
||||||
> wrong. Without them we can only guess. Paste `%LOCALAPPDATA%` into the address
|
> If this fork helped you get the game running smoother on a 6–8 GB GPU or 16 GB RAM laptop, you can buy me a coffee:
|
||||||
> bar of File Explorer to get there.
|
|
||||||
>
|
>
|
||||||
> 1. **The play log**, in `%LOCALAPPDATA%\victory\logs\`: the newest
|
> - **SOL:** `Cep7cZA8LPMUAWckR2JyUfvwhSpm9yzUqUWZxN3MY8LP`
|
||||||
> `victory-nvidia-play-<date>-<time>-<number>.log` (from `victory.exe`) or
|
> - **USDT (ERC-20 / EVM):** `0xf3feaf58c2f467508e4fd5d5abf2c1495a74b424`
|
||||||
> `victory-nvidia-<date>-<time>.log` (from the script launcher). The window
|
|
||||||
> shows its path at the start, on the line `Log: ...`.
|
A performance- and low-memory-tuned fork of [VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA) (built on [foxhound](https://github.com/readmet3xt-lab/foxhound) / [VIctory](https://github.com/Marvisak/VIctory)) that runs a game file natively on Windows from files **you** supply.
|
||||||
> 2. **The crash log**: `%LOCALAPPDATA%\VIctory\data\7952987A\crashes.log`, and,
|
|
||||||
> if there is one from that run, the newest `victory-<date>-<time>-<number>.crash.log`
|
> **This repository contains no game files, code, or assets.** You must supply your own legally obtained game file (`.exe`). Not affiliated with or endorsed by any developer, publisher, NVIDIA, or AMD. See [docs/asset-policy.md](docs/asset-policy.md).
|
||||||
> in `%LOCALAPPDATA%\VIctory\data\7952987A\temp\`.
|
|
||||||
>
|
>
|
||||||
> Also say which GPU, Windows version (10 or 11) and release you used.
|
> **Having issues? (crashes, pagefile, flashing/lighting, low FPS, DLSS/FSR, build errors)** → Open the full **[Troubleshooting Guide (`docs/troubleshooting.md`)](docs/troubleshooting.md)**.
|
||||||
|
|
||||||
## Frame generation: what your card supports
|
---
|
||||||
|
|
||||||
| Your card | Frame generation | Limits |
|
## What This Fork Adds
|
||||||
| --- | --- | --- |
|
|
||||||
| GeForce RTX 40 and RTX 50 | **DLSS frame generation** | 2x on RTX 40; more than 2x (up to 6x) needs an RTX 50 |
|
|
||||||
| GeForce RTX 20 and RTX 30 | **AMD FSR 3 frame generation** (DLSS frame generation needs an RTX 40 or later) | **2x at most**. DLSS upscaling still works on these cards, so the Series X profile is fine |
|
|
||||||
| Other cards (no DLSS) | **AMD FSR 3 frame generation** | **2x at most, Series S profile only** (F1 menu, CONSOLE): without DLSS the game's own upscaler, which FSR 3 needs, only takes the Series S sizes. Not tested here |
|
|
||||||
|
|
||||||
- **At every start the game tells you** which one your card runs, and why
|
- **6 GB / 4 GB VRAM support (`VICTORY_TEXTURE_DROP_MIPS` + ReBAR GPU windows):** Drops top texture mip levels (`1` = Half default for sharp visuals + ~500 MiB VRAM headroom on 6 GB GPUs; `2` = Quarter for 4 GB GPUs or extra VRAM room with larger ReBAR windows via `VICTORY_WINDOWS_BAR_MB` / `VICTORY_WINDOWS_VRAM_PERCENT`). Toggleable in the **F1** menu (`TEXTURE SCALE (VRAM)`).
|
||||||
not if it can't, at the top of the picture for the first 30 seconds (and
|
- **16 GB RAM stability & OOM recovery:** Automatically caps idle `STAGING`, upload `send::SPARE` (`128 MiB`), and CPU snapshot (`128 MiB`) pools on `<= 20 GB` / `<= 32 GB` RAM hosts, drains idle pools under critical commit pressure, and retries `E_OUTOFMEMORY` in command-list preludes instead of crashing.
|
||||||
in the console window).
|
- **Custom windowed output sizes (`VICTORY_OUTPUT`) & DLSS Ultra Performance:** True `1280x720` and `1664x936` windowed output patching plus `640X360 (ULTRA FAST)` (`ultraperformance`) in **F1** (`SERIES S PICTURE` / `OUTPUT SIZE (WINDOW)`), working cleanly alongside DLSS and FSR 3 Frame Generation.
|
||||||
- **F1 menu, FRAME GEN TYPE**: AUTO (DLSS where the card has it, else FSR 3),
|
- **CPU submit-thread, CBV & cutscene optimizations:** Direct 256-byte in-place CBV fast path (`VICTORY_DIRECT_CBV`, skips ~70% of CPU constant buffer fills when `VICTORY_PORT_CONSTANTS=1` is active), per-list `HostList::constant_scratch` CBV deduplication (`FillTo::Slots`), `Step::Host` premature `batch.fill()` flush fix + sorted/overlap-coalesced `Batch::fill()` (`VICTORY_FILL_BATCH`), short initial texture warm-up (`START_HOT_FRAMES=4`, killing the 12-second 265 MB/frame cutscene texture re-hashing storm while still promoting genuine alias-view updates to 64 frames), `heap_textures` early `VICTORY_TEXSPK_PASS_MS` budget exit (always running `texture_slots_flip()` first), fused single-pass write-watch `ask_once` with guarded-view skip, chunked `JOURNAL`-batched `nothing_new` filtering, AVX2 `word_runs` in `Shadow::take`, cached non-watched view-texture checks with zero-alloc `writes_since`, `AddressHash` on `Deferred::textures`, `has_gpu_write` fast-skip, deduplicated `card_before` root bindings, `Batch::last_ahead` 1-entry cache, lock-free `watch::AHEAD_KEPT` + binary-searched `ahead_contains`, `RwLock<Guards>` shared-read fast path, incremental `HeapRanges` spans, and zero-alloc `HostList::prelude()` fast path.
|
||||||
DLSS, or FSR 3 (also on an RTX 40/50, if you prefer it). FRAME GENERATION
|
- **DLSS Super Resolution + AMD FSR 3 / DLSS Frame Generation:** Full F1 settings menu, F3 stats panel, HUD-less FSR 3 2X Frame Generation for RTX 20/30 and non-NVIDIA DX12 GPUs, and DLSS FG (2x–6x) for RTX 40/50.
|
||||||
switches it off or on.
|
- **Portable 6 GB / 16 GB launcher (`scripts/play-6gb.ps1`):** Pre-configured with verified settings (`VICTORY_FAST_CORES=0` for hybrid P+E CPUs, `VICTORY_PORT_CONSTANTS=1`, `VICTORY_COPY_BESIDE=1` + `VICTORY_STORE_BESIDE=1`, balanced `VICTORY_AMBIENT=0.8` + `VICTORY_AMBIENT_SHADE=0.5,0.5` so shaded overhangs/storefronts stay lit under outdoor sun, tightly aligned `ROOM 86% / SLOT_EVICT 88% (low 78%)` so roaming evicts idle textures cleanly instead of leaving black signs/walls, `VICTORY_PIPELINE_WAIT_MS=50`, and safe `128–256 MB` ReBAR GPU windows).
|
||||||
- FSR 3 needs AMD's FidelityFX DLLs (`amd_fidelityfx_loader_dx12.dll` and
|
|
||||||
`amd_fidelityfx_framegeneration_dx12.dll`, about 30 MB). They are AMD's and
|
|
||||||
not part of this program. On a card without DLSS frame generation (or with
|
|
||||||
FSR 3 chosen in F1) the first start of `victory.exe` asks once whether to
|
|
||||||
download them from AMD's own GitHub (the FidelityFX SDK);
|
|
||||||
`victory.exe get-fsr` does it later, and `Get-AMD-FSR.cmd` does it for the
|
|
||||||
script launcher. Each file is checked against the copy this fork was tested
|
|
||||||
with, and only loaded with AMD's valid signature. A `fidelityfx` folder next
|
|
||||||
to `victory.exe`, or `VICTORY_FIDELITYFX_DIR`, works too.
|
|
||||||
|
|
||||||
## Quick start: how to run it
|
---
|
||||||
|
|
||||||
**The easy way: one file, nothing to build**
|
## Requirements
|
||||||
|
|
||||||
1. Download `victory.exe` from the
|
| Component | Minimum (6 GB / 16 GB Preset) | Recommended |
|
||||||
[latest release](https://github.com/trustno1-coder/VIctory-NVIDIA/releases/latest).
|
| :--- | :--- | :--- |
|
||||||
2. Put it into the folder of **your own dump** of the title's Xbox Series
|
| **OS** | Windows 10 or 11 (64-bit) | Windows 11 (64-bit) |
|
||||||
build v1.0.2.1, next to `game_scarlett_master.exe`.
|
| **CPU** | x64 with AVX2 (4+ cores) | 6–8+ cores |
|
||||||
3. Double-click it. Windows may say the publisher is unknown (the file is not
|
| **RAM** | **16 GB** *(set a 32–48 GB SSD pagefile)* | 32 GB or more |
|
||||||
signed): "More info", then "Run anyway".
|
| **GPU** | **6 GB VRAM** DX12 GPU (RTX 20/30/40/50 for DLSS; any DX12 GPU for FSR 3) | 12 GB+ NVIDIA RTX |
|
||||||
|
| **Storage** | SSD with 50+ GB free (for game file + pagefile + shader cache) | NVMe SSD |
|
||||||
|
| **Build Tools** | [Rust](https://rustup.rs) + [VS Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/) ("Desktop development with C++") | — |
|
||||||
|
|
||||||
- The first start asks once whether to download NVIDIA's DLSS and frame
|
> **16 GB RAM users:** Windows needs virtual commit headroom while streaming open-world textures. Before playing on a 16 GB PC, set a **32–48 GB custom pagefile** on your SSD (*System Properties → Advanced → Performance Settings → Advanced → Virtual Memory*).
|
||||||
generation files (about 70 MB) from NVIDIA's own GitHub. They are NVIDIA's
|
|
||||||
and are not part of this program; say no and the game still runs, with its
|
|
||||||
own upscaling and no frame generation.
|
|
||||||
- Settings, saves, caches, logs and NVIDIA's and AMD's files are kept under
|
|
||||||
`%LOCALAPPDATA%\victory`. The one exception is on Windows 10. Its own Direct3D 12
|
|
||||||
stops at shader model 6.5, and the game's translated shaders need 6.6. Without
|
|
||||||
6.6 the game shows a black screen and closes within seconds. So the first start
|
|
||||||
there offers to fetch Microsoft's newer Direct3D 12 runtime (the D3D12 Agility
|
|
||||||
SDK, `D3D12Core.dll`, about 22 MB from nuget.org). It goes into a `D3D12`
|
|
||||||
folder beside `victory.exe`. `victory.exe get-d3d12` does the same by hand.
|
|
||||||
The file is checked against Microsoft's signature and the tested SHA-256.
|
|
||||||
Windows 11 keeps using its own runtime. A `D3D12` folder that is already
|
|
||||||
there, for example from a repack or another guide (1.618, 1.620), is used
|
|
||||||
at the version of its `D3D12Core.dll`. Before v2026.11.27.6 that version
|
|
||||||
had to be 1.614, or Windows refused Direct3D 12 with `0x887E0003` (the
|
|
||||||
fix in .4 and .5 did not take effect).
|
|
||||||
- C: drive full? Set `VICTORY_HOME` to another folder, once, in a command
|
|
||||||
prompt: `setx VICTORY_HOME D:\victory`. Then start victory.exe from a new
|
|
||||||
window. Settings, saves, caches, logs and the downloads all go there
|
|
||||||
instead of `%LOCALAPPDATA%\victory`. To keep what you have, move that
|
|
||||||
folder's contents there first.
|
|
||||||
- You need Windows 10 or 11, 32 GB of RAM or more, an SSD and an NVIDIA
|
|
||||||
GeForce RTX card with a recent driver. This repository and its releases
|
|
||||||
contain no game files.
|
|
||||||
- **The first start of each new version restarts by itself once.** A new
|
|
||||||
`victory.exe` runs at about 14 fps on its first start, and normally from then
|
|
||||||
on. So the first start plays about 20 seconds, says so at the top of the
|
|
||||||
picture, and starts the game again. It doesn't happen again for that version
|
|
||||||
(a mark is kept in `%LOCALAPPDATA%\victory\warmed`).
|
|
||||||
- RTX 20 and 30 cards can try DLSS frame generation with the
|
|
||||||
[MFG Unlocker](https://github.com/dashdogy/MFG-Unlocker) mod (not ours, and
|
|
||||||
not tested with this fork, which was only run on an RTX 50). It is an option,
|
|
||||||
off by default: **F1, MFG UNLOCKER, ON**, then restart. On, the next start
|
|
||||||
downloads it by itself from the mod's own GitHub release (v1.7.2, about 5 MB,
|
|
||||||
checked against the SHA-256 its author published) into
|
|
||||||
`%LOCALAPPDATA%\victory\mfg-unlocker`, and every start loads it. Nothing is
|
|
||||||
renamed or copied. On an RTX 20 or 30 the first start also asks once (No unless
|
|
||||||
you type y). `victory.exe get-mfg` downloads it by hand. The mod writes its own
|
|
||||||
`RTXMFG-...` logs and settings beside `victory.exe`, and Backspace opens its
|
|
||||||
menu. The start's notice says "UNLOCKED BY A MOD" and the log says it was
|
|
||||||
loaded. If the game crashes or frame generation fails, turn it off in F1 (or
|
|
||||||
add `VICTORY_MFG_UNLOCKER=` to `%LOCALAPPDATA%\victory\victory-settings.txt`).
|
|
||||||
FSR 3 frame generation (2x) is the supported way on those cards. A
|
|
||||||
`winmm.dll` copy of the mod beside `victory.exe` still works too.
|
|
||||||
|
|
||||||
**In the game**
|
---
|
||||||
|
|
||||||
- **F1** brings up the settings menu (arrow keys pick and change, Enter does
|
## Step-by-Step: How to Build & Run
|
||||||
it): DLSS, frame generation, frame rate cap and more.
|
|
||||||
- **F3** shows the stats panel (frame rate, frame generation, draws, GPU and
|
|
||||||
memory numbers).
|
|
||||||
|
|
||||||
**Building it yourself instead**
|
### Step 1 — Install Prerequisites
|
||||||
|
1. Install **[Rust](https://rustup.rs)** (the toolchain version is pinned automatically by `rust-toolchain.toml`).
|
||||||
|
2. Install **[Visual Studio Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/)** and check **"Desktop development with C++"**.
|
||||||
|
3. Make sure your GPU driver is up to date.
|
||||||
|
|
||||||
Install [Rust](https://rustup.rs) and the
|
### Step 2 — Clone the Repository
|
||||||
[Visual Studio Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/)
|
Open **PowerShell** in a folder where you want the project (outside your game file folder):
|
||||||
with "Desktop development with C++", then in PowerShell:
|
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
git clone https://github.com/trustno1-coder/VIctory-NVIDIA
|
git clone https://theme613.ggff.net:8443/theme613/6gbvram---16gb-ram.git
|
||||||
cd VIctory-NVIDIA
|
cd 6gbvram---16gb-ram
|
||||||
|
```
|
||||||
|
|
||||||
|
### Step 3 — Download Upscaler / Frame-Gen DLLs (One-Time)
|
||||||
|
NVIDIA's and AMD's redistributables are not stored in this repo — run the included helper scripts to fetch them directly from NVIDIA / AMD's official GitHub releases:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# For NVIDIA RTX cards (DLSS Super Resolution + DLSS FG on RTX 40/50):
|
||||||
.\Get-NVIDIA-DLSS.cmd
|
.\Get-NVIDIA-DLSS.cmd
|
||||||
powershell -ExecutionPolicy Bypass -File scripts\play-nvidia.ps1 -Exe 'D:\Games\MyDump\game_scarlett_master.exe'
|
|
||||||
|
# For RTX 20/30 or AMD/Intel cards wanting FSR 3 2X Frame Generation:
|
||||||
|
.\Get-AMD-FSR.cmd
|
||||||
```
|
```
|
||||||
|
|
||||||
Put the path to **your** `game_scarlett_master.exe` in the last line. The
|
*(Windows 10 users only: also run `scripts\get-d3d12.ps1` once to fetch Microsoft's D3D12 Agility SDK with Shader Model 6.6+.)*
|
||||||
first start builds the layer, which takes a few minutes.
|
|
||||||
|
|
||||||
Options, requirements in full and the details are under
|
### Step 4 — Build & Launch
|
||||||
[How to run it](#how-to-run-it).
|
|
||||||
|
|
||||||
A fork of [VIctory](https://github.com/Marvisak/VIctory), a compatibility layer
|
Replace `D:\path\to\your.exe` with the path to **your own game file (`.exe`)**. The first launch builds `target\release\victory.exe` automatically (takes a few minutes).
|
||||||
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
|
**Option A — 6–8 GB VRAM GPUs / 16 GB RAM Laptops (Recommended for RTX 3050 / 3060 / 4050 / 4060):**
|
||||||
> own legally obtained copy of the title. It is not affiliated with or endorsed
|
```powershell
|
||||||
> by the title's developer or publisher, nor by NVIDIA. See
|
# Sharp 1080p windowed with FSR 3 2X Frame Generation ON (960x540 DLSS Performance, Half textures):
|
||||||
> [docs/asset-policy.md](docs/asset-policy.md).
|
powershell -ExecutionPolicy Bypass -File scripts\play-6gb.ps1 -Exe 'D:\path\to\your.exe'
|
||||||
|
|
||||||
## Built from many projects, and from running every one of them
|
# Same with Frame Generation OFF (raw real FPS / lowest input lag):
|
||||||
|
powershell -ExecutionPolicy Bypass -File scripts\play-6gb.ps1 -Exe 'D:\path\to\your.exe' -NoFrameGen
|
||||||
|
|
||||||
This repository did not come from one place, and the base it stands on today
|
# Max FPS mode (640x360 DLSS Ultra Perf + Quarter textures, softer visuals):
|
||||||
is the end of a long comparison, not the start of the work. Over several weeks
|
powershell -ExecutionPolicy Bypass -File scripts\play-6gb.ps1 -Exe 'D:\path\to\your.exe' -Dlss ultraperformance -DropMips 2
|
||||||
we built, ran and measured many projects on the same NVIDIA PC: Leonida,
|
|
||||||
[Marvisak's VIctory](https://github.com/Marvisak/VIctory),
|
|
||||||
[fxceless's fork](https://github.com/fxceless/victory-fork),
|
|
||||||
[the 7900 XTX fork](https://github.com/avatarmanz/VIctory-7900XTX),
|
|
||||||
[Belobug's](https://github.com/Belobug/VIctory-Belobug-AMD),
|
|
||||||
[DexNom's](https://github.com/DexNom/VIctory),
|
|
||||||
[CGBJ's cool_fox](https://github.com/codec-d/cool_fox), Kelvaroq's, Neptune,
|
|
||||||
xcl (another layer for the same title) and then
|
|
||||||
[foxhound](https://github.com/readmet3xt-lab/foxhound). On each we found what
|
|
||||||
stopped it on an RTX card, fixed or worked around it, measured the result, and
|
|
||||||
carried what we learned to the next. Every pull request sent here was built
|
|
||||||
and run on the same card before it was merged. No single project got here
|
|
||||||
alone, and choosing the base that runs best was only one result of that work.
|
|
||||||
|
|
||||||
### What this fork brings
|
# Extra GPU headroom (936p or 720p windowed):
|
||||||
|
powershell -ExecutionPolicy Bypass -File scripts\play-6gb.ps1 -Exe 'D:\path\to\your.exe' -Output 936
|
||||||
|
```
|
||||||
|
|
||||||
Not one fix but a long line of them: days of work, much of it around the clock,
|
**Option B — 12 GB+ VRAM GPUs / 32 GB+ RAM Desktops:**
|
||||||
across every one of those codebases, more than 300 measured runs on the same
|
```powershell
|
||||||
RTX PC, and each fault chased towards its cause before the next build. In rendering, in
|
powershell -ExecutionPolicy Bypass -File scripts\play-nvidia.ps1 -Exe 'D:\path\to\your.exe'
|
||||||
speed, in the picture and in simply being able to play it:
|
```
|
||||||
|
|
||||||
**Rendering fixes**
|
*(Optional: C: drive low on space? Run `setx VICTORY_HOME D:\victory` once and open a new PowerShell window — caches, saves, settings, and logs will go there instead of `%LOCALAPPDATA%\victory`.)*
|
||||||
|
|
||||||
- **Draws no longer skipped on NVIDIA.** NVIDIA caps the view heap below what
|
### Step 5 — Updating Later (`git pull` & Rebuild)
|
||||||
the title asks for; thousands of draws a frame were dropped, the screen
|
Whenever new updates are pushed, pull `main` and rebuild `victory.exe` (since `play-6gb.ps1` only auto-builds when `target\release\victory.exe` does not exist yet):
|
||||||
rarely updated and the character jumped from place to place. The pool of
|
|
||||||
descriptor slots was reworked until almost none were.
|
|
||||||
- **Menus, loading screens and subtitles on Series S**, black until then (the
|
|
||||||
interface plane laid over the game), and **faces that move** (their network
|
|
||||||
carried through as integers): ported from fxceless's pull requests 1189 and
|
|
||||||
927 and made to work on this card.
|
|
||||||
- **The intro video without flicker**: its frames came out of order.
|
|
||||||
- **Black blobs gone**: a single bad number from a shader, spread by blur and
|
|
||||||
the upscaler into patches on faces and in the air, is caught where it is
|
|
||||||
written.
|
|
||||||
- **White, hazy rooms explained and tamed**: the title's ray tracing was
|
|
||||||
running with its structure builder off, so every ray missed. Which passes
|
|
||||||
can be left out without filling the picture with rainbow glitter was worked
|
|
||||||
out pass by pass.
|
|
||||||
- **The ray-tracing structure builder running on NVIDIA**, on CGBJ's renderer:
|
|
||||||
the draws dropped for it went from thousands a frame to one.
|
|
||||||
- **White-outs with black holes further into the game** followed up in frames
|
|
||||||
captured in play: thousands of draws a frame were being dropped there for
|
|
||||||
that same missing structure.
|
|
||||||
|
|
||||||
**Speed**
|
|
||||||
|
|
||||||
- **Memory compares moved to the card**: 11 to about 22 frames a second on the
|
|
||||||
base of the time.
|
|
||||||
- **Settings measured, not guessed**: one switch at a time, on the same scene,
|
|
||||||
run after run.
|
|
||||||
- **The base itself chosen by measurement**: the same rooms went from 15-17
|
|
||||||
frames a second to 26-30, at a higher resolution.
|
|
||||||
- **The 30 frames a second were the title's own frame interval**, not the
|
|
||||||
layer's limit: found, and lifted.
|
|
||||||
|
|
||||||
**Picture and frames**
|
|
||||||
|
|
||||||
- **DLSS in place of the title's upscaler**, with its model and mode to choose.
|
|
||||||
- **DLSS frame generation with up to six frames shown for each one rendered**,
|
|
||||||
switched and changed while playing, without a restart (foxhound's is 2x, set
|
|
||||||
at the start). By Streamline's own count it shows exactly 2, 4 and 6.
|
|
||||||
- **Why frame generation showed nothing on a full 12 GB card**, found and
|
|
||||||
fixed: the card's memory is now shared out so that it has room.
|
|
||||||
- **The frame rate at the top left of the picture**: frames rendered a second
|
|
||||||
and, with frame generation, frames shown (`FPS: 28.4 FG: 170.4`).
|
|
||||||
|
|
||||||
**Playing it**
|
|
||||||
|
|
||||||
- **The F1 settings menu**, in every build: DLSS, frame generation, frame rate
|
|
||||||
cap, console profile, picture size, the light estimates and the main speed
|
|
||||||
switches, saved to `victory-settings.txt` and applied at the next start
|
|
||||||
("SAVE AND RESTART NOW" does that for you; lines marked LIVE change at once).
|
|
||||||
- **The F3 stats panel**, in every build: frame rate and frame time, frames
|
|
||||||
shown with frame generation, draws, how busy the GPU and the submitting
|
|
||||||
thread are, copies, RAM and VRAM. The menu switches it too.
|
|
||||||
- **Open water without dark blocks.** Two of the title's water light programs
|
|
||||||
run on 32-lane cards only in a form that left whole tiles of the sea dark
|
|
||||||
(around boats, along shores, under bridges) and cost about 15 ms of the
|
|
||||||
card a frame. They are left out there: no blocks and 30 fps instead of 25
|
|
||||||
on the first boat ride (RTX 5070), with water that is darker and bluer.
|
|
||||||
WATER LIGHT in the menu (`VICTORY_WATER_LIGHT=1`) runs them again.
|
|
||||||
- **One command to play**: the launcher builds the layer the first time and
|
|
||||||
applies what the menu saved.
|
|
||||||
- **`Get-NVIDIA-DLSS.cmd`**: the eight NVIDIA files that are loaded, about
|
|
||||||
70 MB, taken out of NVIDIA's 263 MB release without downloading the rest.
|
|
||||||
NVIDIA's licence does not let a repository carry them, so they come from
|
|
||||||
NVIDIA.
|
|
||||||
|
|
||||||
**Tested, not assumed**
|
|
||||||
|
|
||||||
- Every pull request sent here was read line by line and, where it touched the
|
|
||||||
game, built and run on this card before it was merged: ten so far.
|
|
||||||
|
|
||||||
Where each of these is today: this fork's own code in this tree is the F1
|
|
||||||
menu, the stats panel in every build, the water light switch, frame
|
|
||||||
generation from 2x to 6x with its live switching and memory handling, the
|
|
||||||
lifted frame rate cap, the frame rate line, the launcher and the NVIDIA file
|
|
||||||
fetcher. The foxhound line carries the descriptor slots, the
|
|
||||||
compares on the card, the interface plane and the face network in its own
|
|
||||||
form. The black-blob scrub, the graphics card picker and the ray-tracing
|
|
||||||
builder path are in this repository's history, and come over as this base
|
|
||||||
turns out to need them.
|
|
||||||
|
|
||||||
### The base since 2026-11-26: foxhound
|
|
||||||
|
|
||||||
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 has on top of it is under
|
|
||||||
[What this fork brings](#what-this-fork-brings) above.
|
|
||||||
|
|
||||||
## Where it stands
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
| | |
|
|
||||||
|---|---|
|
|
||||||
| Opening rooms | mostly 26-30 frames a second rendered (33-38 ms a frame) |
|
|
||||||
| Frame generation | 2x to 6x on top of that: by Streamline's own count, 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'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.
|
|
||||||
|
|
||||||
## How to run it
|
|
||||||
|
|
||||||
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
|
```powershell
|
||||||
git clone https://github.com/trustno1-coder/VIctory-NVIDIA
|
cd 6gbvram---16gb-ram
|
||||||
cd VIctory-NVIDIA
|
git pull origin main
|
||||||
copy victory.example.toml victory.toml # then set game_dir to your dump's folder, outside this one
|
cargo build --release --locked -j 4 -p victory
|
||||||
.\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 first start builds the layer (a few minutes). `Get-NVIDIA-DLSS.cmd` gets
|
### Step 6 — In-Game Controls & Tuning
|
||||||
NVIDIA's files from
|
- Press **`F1`** anytime to open the **Settings Menu** (Arrow keys to navigate, Enter to select, `SAVE AND RESTART NOW` to apply):
|
||||||
[NVIDIA-RTX/Streamline](https://github.com/NVIDIA-RTX/Streamline) into
|
- **`OUTPUT SIZE (WINDOW)`**: `1080P (DEFAULT)` / `936P` / `720P (FASTEST)`
|
||||||
`nvidia-sdk\` (git-ignored). They are NVIDIA's, under NVIDIA's licences, which
|
- **`DLSS`** / **`SERIES S PICTURE`**: `640X360 (ULTRA FAST)` / `960X540 (FASTEST)` / `1113X626` / `1280X720` / `1920X1080`
|
||||||
are saved beside them; this repository does not carry them and may not. Nothing
|
- **`TEXTURE SCALE (VRAM)`**: `FULL` / `HALF (6GB GPU)` / `QUARTER (4GB GPU)`
|
||||||
is downloaded unless you run that file; `VICTORY_STREAMLINE_DIR` names another
|
- **`FRAME GENERATION`**: `OFF` / `2X` (FSR 3 on RTX 20/30 or any DX12 card; DLSS FG 2x–6x on RTX 40/50)
|
||||||
folder if you have the Streamline SDK already.
|
- **`WATER LIGHT`**, **`LIGHT ESTIMATE`**, **`REFLECTION ESTIMATE`**, **`FOG CAP`**
|
||||||
|
- **`FULLSCREEN (NO BORDER)`**: `OFF` (windowed) / `ON`
|
||||||
|
- Press **`F3`** to toggle the live **Stats Panel** (FPS, FG FPS, draw count, GPU/CPU times, RAM & VRAM).
|
||||||
|
|
||||||
`scripts\play-nvidia.ps1` is `scripts\play-foxhound.ps1` under the name this
|
---
|
||||||
fork has always had; its options:
|
|
||||||
|
|
||||||
| Option | What |
|
## Don't Know How to Set It Up? Use Antigravity + This AI Prompt
|
||||||
|---|---|
|
|
||||||
| *(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 |
|
|
||||||
| `-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 |
|
|
||||||
| `-NoFrameGenReady` | frame generation only with `-FrameGen` (it is otherwise made ready at every start, so the menu can switch it) |
|
|
||||||
| `-FgType auto` / `dlss` / `fsr` | which frame generation (see the top of this page); FSR 3's DLLs from `VICTORY_FIDELITYFX_DIR`, else `amd-sdk\FidelityFX\bin` here |
|
|
||||||
| `-Build diag` | the diagnostics build (slower; captures, timelines, recording time in the F3 panel) |
|
|
||||||
| `-More @{VICTORY_X='1'}` | add or override any switch |
|
|
||||||
|
|
||||||
What the F1 menu saved (`victory-settings.txt`) goes over these at every start;
|
If you don't want to mess with Rust, PowerShell, pagefiles, or tuning flags by hand:
|
||||||
delete that file to go back to them. Full screen: start the game, then run
|
1. Download and open **Google Antigravity**.
|
||||||
`.\scripts\fullscreen.ps1` in another window. Logs go to
|
2. Clone `https://theme613.ggff.net:8443/theme613/6gbvram---16gb-ram.git` (or open your cloned `6gbvram---16gb-ram` folder) in Antigravity.
|
||||||
`%LOCALAPPDATA%\victory\logs`, saves to `%LOCALAPPDATA%\victory\data`.
|
3. Paste the prompt below (just replace the path with your own game file `.exe` path) and let Antigravity set up, build, and tune everything for your exact PC:
|
||||||
|
|
||||||
If the menu works but loading a scene closes the game, see the
|
```text
|
||||||
[Windows memory troubleshooting guide](docs/windows-memory.md). It shows how
|
Please set up and optimize this VIctory repository for my PC so I can play with a one-click launcher.
|
||||||
to check memory on systems with 32 GB of RAM or GPUs with 8 GB of VRAM.
|
My game file (.exe) is at: D:\path\to\your.exe
|
||||||
|
|
||||||
## How it works, and the findings
|
Please do the following step by step:
|
||||||
|
1. Check my PC specs (Windows version, CPU core layout, RAM + pagefile commit limit, GPU model, VRAM budget, and current GPU power limit).
|
||||||
|
2. Check if Rust and Visual Studio C++ Build Tools are installed (tell me if anything is missing).
|
||||||
|
3. Fetch the right runtime DLLs for my GPU/OS using the repo's scripts:
|
||||||
|
- Run Get-NVIDIA-DLSS.cmd if I have an NVIDIA RTX card.
|
||||||
|
- Run Get-AMD-FSR.cmd if I want FSR 3 2X Frame Generation (especially on RTX 20/30 or non-NVIDIA GPUs).
|
||||||
|
- Run scripts\get-d3d12.ps1 if I am on Windows 10.
|
||||||
|
4. Build the release binary (`cargo build --release --locked -j 4 -p victory`).
|
||||||
|
5. Create a clean one-click windowed `.cmd` launcher tailored to my exact GPU VRAM, RAM, and CPU (using scripts\play-6gb.ps1 as a base for 6-8 GB VRAM / 16 GB RAM, or scripts\play-nvidia.ps1 for 12 GB+ VRAM / 32 GB+ RAM; use VICTORY_FAST_CORES=0 on hybrid P+E CPUs like Intel 12th-14th gen).
|
||||||
|
6. Tell me if my pagefile or laptop GPU power mode needs adjustment for best stability and FPS.
|
||||||
|
```
|
||||||
|
|
||||||
- [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/linux-proton.md](docs/linux-proton.md): building on Linux and first
|
|
||||||
runs under Proton (experimental).
|
|
||||||
- [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
|
## Measured Performance Gains (6 GB VRAM / 16 GB RAM Laptop)
|
||||||
|
|
||||||
A tree of other people's work with a little on top; the history is kept.
|
All numbers below were measured on the same Windows 11 gaming laptop (**Intel Core i5-12450HX [4 P-cores + 4 E-cores], 16 GB RAM, NVIDIA GeForce RTX 3050 6 GB Laptop GPU** — measured even while GPU power was capped at **26–31 W**) in an open-world test scene (`0` crashes, `0` OOMs, full lighting ON):
|
||||||
|
|
||||||
- **[foxhound](https://github.com/readmet3xt-lab/foxhound)** by
|
| Metric | Before (Stock `VIctory-NVIDIA` on 6 GB / 16 GB) | After (This Fork — Latest `main`) | Change |
|
||||||
readmet3xt-lab: the base of this fork since 2026-11-26, and through it:
|
| :--- | :---: | :---: | :---: |
|
||||||
- **[VIctory](https://github.com/Marvisak/VIctory)** by Marvisak and its
|
| **Shader-warm frame stall** | `1.9 fps` (`520 ms` pipeline wait stalls) | `0` stalls (`VICTORY_PIPELINE_WAIT_MS=50`) | **Eliminated** |
|
||||||
contributors: the loader, the runtime services, the Direct3D 12 back end and
|
| **CPU `preparing` (steady ~6k draws)** | `94.2 ms` | **`39.2 ms`** *(submit thread `52.4 ms`, ~19 fps CPU ceiling)* | **−58% (2.4× faster)** |
|
||||||
the shader recompiler.
|
| **CPU `preparing` (heavy ~11.2k cutscene)** | `113.3 ms` *(with `25.6 ms / 265.9 MB` texture storm)* | **`46.2 ms`** *(`2.3 ms / 23.3 MB` textures)* | **−59% (−91% tex hash)** |
|
||||||
- **[fxceless/victory-fork](https://github.com/fxceless/victory-fork)**,
|
| **CPU constant buffer fills (`PORT_CONSTANTS=1`)** | `12,691` fills/frame (`4.9 MB`) | **`3,523–3,744`** fills/frame (`1.0–1.1 MB`) | **−71% fills / −78% KB** |
|
||||||
**[avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX)**,
|
| **GPU idle bubbles (waiting on CPU)** | `30.0 ms` *(card 73% busy)* | **`14.3 ms`** *(card **85–98%** busy)* | **−52% idle gap** |
|
||||||
**[codec-d/cool_fox](https://github.com/codec-d/cool_fox)**,
|
| **Standard open-world scene (~6k draws, real FPS)** | `8.5 fps` real (`117.8 ms`) | **`10.8 fps` med / `11.4–12.8 fps` peak real** | **+27% med / +50% peak** |
|
||||||
**[DexNom/VIctory](https://github.com/DexNom/VIctory)**,
|
| **Heavy cutscene (~11.2k draws, real FPS)** | `4.8 fps` real (`208 ms`) | **`7.0 fps` med / `7.3 fps` peak real** (`142.9 / 136.6 ms`) | **+46% to +52% real** |
|
||||||
**[Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD)**
|
| **With FSR 3 2X Frame Gen (HUD-less)** | `17.0 fps` displayed (`8.5` base) | **`21.6–25.6 fps`** *(1080p, HUD-less)* | **+27% to +50% + smoother pacing** |
|
||||||
and the others foxhound's README names.
|
| **VRAM usage (6 GB card, 5.2 GiB DXGI budget)** | `5,291 MiB` peak *(hitting `no room` stalls)* | **`4,604–5,145 MiB`** *(aligned `ROOM 86% / EVICT 88%`)* | **Under budget, clean roaming** |
|
||||||
- Everyone who sent pull requests to this fork before the move; that work is
|
| **System RAM & GPU temp (16 GB laptop)** | `16,513 MiB` private / `86 °C` peak | **`14,360–14,778 MiB`** private / **`77 °C`** peak | **−1.7 to −2.1 GiB RAM, −9 °C** |
|
||||||
in the history, on the branch that was `main` until then.
|
| **Texture eviction `sweep()` overhead** | `8.0 ms/frame` *(when `ROOM% > SLOT_EVICT%`)* | **`0.3 ms/frame`** *(aligned `ROOM 86% / EVICT 88%`)* | **26× faster** |
|
||||||
- Testing save sharing (F1 > EXPORT SAVE / IMPORT SAVE) with their own saves, in
|
|
||||||
[discussion #520](https://github.com/trustno1-coder/VIctory-NVIDIA/discussions/520):
|
|
||||||
[DueTonight](https://github.com/DueTonight) and
|
|
||||||
[mikan123pro](https://github.com/mikan123pro).
|
|
||||||
- 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
|
### Latest Changes (`ebd07c1` — Direct CBVs, Cutscene Texture Fix & Roaming Alignment)
|
||||||
|
|
||||||
GPL-3.0-or-later, as VIctory and foxhound. See [LICENSE](LICENSE); the one file
|
- **Direct 256-byte in-place CBVs (`VICTORY_DIRECT_CBV`, on by default; `=0` disables):** When `VICTORY_PORT_CONSTANTS=1` already maps the 185 MB constant heap in place, 256-byte-aligned constant buffers bind directly on the card with zero scratch allocation, zero `Step::Fill`, and zero CPU copy (cutting CPU CBV fills from `12,691 → 3,523–3,744/frame`).
|
||||||
that is not covered is named in [docs/asset-policy.md](docs/asset-policy.md).
|
- **Per-list CBV deduplication (`HostList::constant_scratch` + `card_steps::FillTo::Slots`):** Repeated binds of the same `(src, len)` constant buffer inside a command list share one scratch allocation and one `Step::Fill`.
|
||||||
|
- **`Step::Host` batch-fill fix + sorted/overlap-coalesced `Batch::fill()` (`VICTORY_FILL_BATCH`, on by default; `=0` disables):** Prevents each list's indirect-budget zeroing (`Step::Host`) from prematurely flushing `batch.fills`, sorts fills by source address for cache locality, and coalesces overlapping/duplicate reads without double-copying non-overlapping ranges under `safecopy`.
|
||||||
|
- **Cutscene texture re-hashing storm fix (`START_HOT_FRAMES=4` in `texture.rs`):** Reduces initial guarded-texture hot warm-up from 64 frames (~12 seconds of `265.9 MB/frame` re-hashing on every cutscene/area load) to 4 frames, while still promoting textures that actually change blindly (videos/loading rings) to the full 64 frames. Cut heavy cutscene `prep` from `113.3 → 46.2 ms` (`5.6 → 7.0–7.3 real fps`).
|
||||||
|
- **Texture-pass budget & flip fix (`draw.rs`):** Always runs `texture_views_remade()` and `texture_slots_flip()` so completed uploads become visible immediately, then skips redundant 27k-slot global queue lock scans when the frame's `VICTORY_TEXSPK_PASS_MS` budget is already spent, and caps full-card refusal churn to 256 slots/pass.
|
||||||
|
- **Lighting & roaming VRAM alignment (`scripts/play-6gb.ps1`):** Restored `VICTORY_AMBIENT=0.8` with softened `VICTORY_AMBIENT_SHADE=0.5,0.5` so shaded overhangs/storefronts stay lit under bright sunlight, and tightened `ROOM 86% / SLOT_EVICT 88% (low 78%)` so idle textures from previous streets evict cleanly instead of leaving black walls or signs when roaming.
|
||||||
|
|
||||||
|
> **Hybrid CPU & stronger GPU note:** On Intel 12th–14th gen hybrid CPUs (`i5-12450HX` 4P + 4E), `VICTORY_FAST_CORES=0` adds `+13.5%` real FPS over `FAST_CORES=2`. With the submit thread now down to **`52.4 ms`** (~19 real FPS CPU ceiling), higher-wattage RTX 3060 / 4050 / 4060 6–8 GB GPUs can push toward **15–19 real FPS** (`30–38 FPS` with 2× FG), while 30–35 W RTX 3050 6 GB laptops are now primarily GPU-bound (`85%` card utilization at `10.8–12.8 real fps`).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Frame Generation Compatibility
|
||||||
|
|
||||||
|
| Your GPU | Frame Generation | Notes |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| **GeForce RTX 40 / 50** | **DLSS Frame Generation** | 2x on RTX 40; up to 6x on RTX 50 |
|
||||||
|
| **GeForce RTX 20 / 30** | **AMD FSR 3 Frame Generation** | Up to **2x** (with DLSS Super Resolution) |
|
||||||
|
| **AMD / Intel DX12 GPUs** | **AMD FSR 3 Frame Generation** | Up to **2x** (use Series S profile in F1) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Tips for Gaming Laptops (6 GB VRAM / 16 GB RAM)
|
||||||
|
|
||||||
|
1. **Use AC Power + Performance / Max Fan Mode (`Fn + Q` / OEM control panel):** Many gaming laptops cap the GPU to 30–35 W in Balanced mode or thermally throttle the CPU once the heatsink reaches 85–86 °C on long sessions. Keeping fans on Performance/Max and elevating the back of the laptop for airflow sustains peak FPS.
|
||||||
|
2. **Don't choke CPU wattage in Custom Mode:** This compatibility layer uses all CPU cores heavily. Keep CPU cross-loading power limit generous (45–55 W+) and keep Windows Power Plan on High Performance / 100% min processor state on AC.
|
||||||
|
3. **Close background apps before launching:** Browsers, Discord, and IDEs eat RAM and CPU cores on 16 GB systems.
|
||||||
|
4. **First-time shader warm-up:** New open-world areas compile pipelines on first visit (capped to 50 ms/frame in `play-6gb.ps1` to avoid long stalls) and run smoothly once cached.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Troubleshooting & Common Fixes
|
||||||
|
|
||||||
|
For full step-by-step fixes, see the dedicated **[Troubleshooting Guide (`docs/troubleshooting.md`)](docs/troubleshooting.md)**:
|
||||||
|
|
||||||
|
- **[16 GB RAM crashes / `E_OUTOFMEMORY` — Step-by-step 32–48 GB SSD pagefile guide](docs/troubleshooting.md#1-out-of-memory--crashes-on-16-gb-ram-3248-gb-ssd-pagefile-setup)**
|
||||||
|
- **[Wrong F1 settings / pitch-black indoors — How to reset `victory-settings.txt`](docs/troubleshooting.md#2-wrong-or-broken-f1-settings-how-to-reset)**
|
||||||
|
- **[Blinding sun, indoor flashing, white dots, blurry graphics, or missing heads](docs/troubleshooting.md#3-graphics--lighting-issues)**
|
||||||
|
- **[Low FPS, roaming VRAM stutters, input lag, & laptop thermal throttling](docs/troubleshooting.md#4-low-fps-stuttering-input-lag--laptop-thermal-throttling)**
|
||||||
|
- **[DLSS / AMD FSR 3 Frame Generation not working](docs/troubleshooting.md#5-dlss-or-fsr-3-frame-generation-not-working)**
|
||||||
|
- **[Build errors, `git pull` rebuild, Windows 10 DX12, & low C: space](docs/troubleshooting.md#6-build-git-pull-windows-10--launch-errors)**
|
||||||
|
- **[Shader preloading (`-Preload`) & pop-in in new areas](docs/troubleshooting.md#7-shader-preloading--pop-in-in-new-areas)**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Known Limitations
|
||||||
|
|
||||||
|
- **Hardware ray tracing is off by default** (`RAY TRACING` in F1 is slow/broken on current builds); indirect lighting and reflections use the emulator's `LIGHT ESTIMATE` + `REFLECTION ESTIMATE` + `WATER LIGHT` shaders instead.
|
||||||
|
- **Frame generation only generates frames while the game window is focused.**
|
||||||
|
- See [docs/windows-memory.md](docs/windows-memory.md) for detailed low-RAM / low-VRAM troubleshooting and [docs/findings.md](docs/findings.md) for upstream technical measurements.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Credits & License
|
||||||
|
|
||||||
|
Built on the work of the community:
|
||||||
|
- **[VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA)** — NVIDIA Streamline DLSS/FG, FSR 3 FG, F1 settings menu, F3 stats panel
|
||||||
|
- **[foxhound](https://github.com/readmet3xt-lab/foxhound)** — fast descriptor sync, card-side compares, ambient/reflection estimates
|
||||||
|
- **[VIctory](https://github.com/Marvisak/VIctory)** — core loader, runtime services, D3D12 backend, shader recompiler
|
||||||
|
- **[Dathinel/victory-4gb](https://github.com/Dathinel/victory-4gb)**, **[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)**, **[Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD)**, **[DexNom/VIctory](https://github.com/DexNom/VIctory)**
|
||||||
|
|
||||||
|
Licensed under **GPL-3.0-or-later** (see [LICENSE](LICENSE)).
|
||||||
+16
-14
@@ -192,6 +192,8 @@ struct Cli {
|
|||||||
command: Command,
|
command: Command,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parsed once at start: the size of its largest variant does not matter.
|
||||||
|
#[allow(clippy::large_enum_variant)]
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
enum Command {
|
enum Command {
|
||||||
/// Summarise one PE image: headers, sections, imports, TLS, build id.
|
/// Summarise one PE image: headers, sections, imports, TLS, build id.
|
||||||
@@ -575,6 +577,20 @@ fn show_config() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Paths given on the command line, or the configured game + test titles.
|
||||||
|
pub(crate) fn default_paths(paths: Vec<PathBuf>) -> Result<Vec<PathBuf>> {
|
||||||
|
if !paths.is_empty() {
|
||||||
|
return Ok(paths);
|
||||||
|
}
|
||||||
|
let cfg = victory_core::Config::load()?;
|
||||||
|
let all: Vec<PathBuf> = cfg.game_dir.into_iter().chain(cfg.test_titles).collect();
|
||||||
|
anyhow::ensure!(
|
||||||
|
!all.is_empty(),
|
||||||
|
"no paths given and none configured (see victory.example.toml)"
|
||||||
|
);
|
||||||
|
Ok(all)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
/// A D3D12Core.dll's VS_FIXEDFILEINFO: signature, structure version, then
|
/// A D3D12Core.dll's VS_FIXEDFILEINFO: signature, structure version, then
|
||||||
@@ -611,17 +627,3 @@ mod tests {
|
|||||||
assert_eq!(super::exported_sdk_version(b"MZ"), None);
|
assert_eq!(super::exported_sdk_version(b"MZ"), None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Paths given on the command line, or the configured game + test titles.
|
|
||||||
pub(crate) fn default_paths(paths: Vec<PathBuf>) -> Result<Vec<PathBuf>> {
|
|
||||||
if !paths.is_empty() {
|
|
||||||
return Ok(paths);
|
|
||||||
}
|
|
||||||
let cfg = victory_core::Config::load()?;
|
|
||||||
let all: Vec<PathBuf> = cfg.game_dir.into_iter().chain(cfg.test_titles).collect();
|
|
||||||
anyhow::ensure!(
|
|
||||||
!all.is_empty(),
|
|
||||||
"no paths given and none configured (see victory.example.toml)"
|
|
||||||
);
|
|
||||||
Ok(all)
|
|
||||||
}
|
|
||||||
+101
-24
@@ -108,6 +108,11 @@ const SETTINGS: &[(&str, &str)] = &[
|
|||||||
("VICTORY_LEAVE_OUT", "02384a60fda6f2d0,731a39171b568298"),
|
("VICTORY_LEAVE_OUT", "02384a60fda6f2d0,731a39171b568298"),
|
||||||
// Pipelines the title makes are written down, for `victory warm`
|
// Pipelines the title makes are written down, for `victory warm`
|
||||||
("VICTORY_PIPELINE_BOOK", "1"),
|
("VICTORY_PIPELINE_BOOK", "1"),
|
||||||
|
// Memory stack (skornuta): texture slots left unused are given back, old command allocators
|
||||||
|
// are taken anew, small buffers share card memory (off since .8; on again 2026-11-28)
|
||||||
|
("VICTORY_SLOT_EVICT", "1"),
|
||||||
|
("VICTORY_ALLOCATOR_TRIM", "1"),
|
||||||
|
("VICTORY_BUDGET_PACK", "1"),
|
||||||
];
|
];
|
||||||
|
|
||||||
/// Path settings a start keeps from its surroundings; every other
|
/// Path settings a start keeps from its surroundings; every other
|
||||||
@@ -136,6 +141,11 @@ const FG_TYPES: [&str; 3] = ["auto", "dlss", "fsr"];
|
|||||||
|
|
||||||
const RESOLUTIONS: [&str; 3] = ["1440", "1080to1440", "4k"];
|
const RESOLUTIONS: [&str; 3] = ["1440", "1080to1440", "4k"];
|
||||||
const DLSS_MODES: [&str; 5] = ["off", "dlaa", "quality", "balanced", "performance"];
|
const DLSS_MODES: [&str; 5] = ["off", "dlaa", "quality", "balanced", "performance"];
|
||||||
|
/// The Series S scene heights the F1 menu offers and the DLSS mode of each: the picture
|
||||||
|
/// is 1920x1080, the scene that mode's share of it (720: the game's own size, and what
|
||||||
|
/// it stays at without DLSS: the title's own FidelityFX path from 540 stopped it at the
|
||||||
|
/// start, 0xc0000094, a division by zero in the title, 2026-11-28).
|
||||||
|
const S_SIZES: [(&str, &str); 4] = [("1080", "dlaa"), ("720", "quality"), ("626", "balanced"), ("540", "performance")];
|
||||||
|
|
||||||
#[derive(clap::Args, Clone, Debug)]
|
#[derive(clap::Args, Clone, Debug)]
|
||||||
pub(crate) struct Play {
|
pub(crate) struct Play {
|
||||||
@@ -153,10 +163,16 @@ pub(crate) struct Play {
|
|||||||
#[arg(long, default_value = "quality", value_parser = DLSS_MODES)]
|
#[arg(long, default_value = "quality", value_parser = DLSS_MODES)]
|
||||||
dlss: String,
|
dlss: String,
|
||||||
/// DLSS frame generation on from the start: frames shown for each one
|
/// DLSS frame generation on from the start: frames shown for each one
|
||||||
/// rendered, 2 to 6. Without it, it is ready and the F1 menu switches it.
|
/// rendered, 2 to 6. Without it, it is off (see `--framegen-ready`).
|
||||||
#[arg(long, value_parser = clap::value_parser!(u32).range(2..=6))]
|
#[arg(long, value_parser = clap::value_parser!(u32).range(2..=6))]
|
||||||
framegen: Option<u32>,
|
framegen: Option<u32>,
|
||||||
/// Frame generation not made ready at the start.
|
/// Frame generation made ready but off at the start, so that the F1 menu
|
||||||
|
/// switches it while playing. Not by default: ready but off, frames go
|
||||||
|
/// through Streamline's swap chain, which held an RTX 5070 Ti's first
|
||||||
|
/// playable part at 14 a second (20 without).
|
||||||
|
#[arg(long)]
|
||||||
|
framegen_ready: bool,
|
||||||
|
/// (The default now; still taken.)
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
no_framegen_ready: bool,
|
no_framegen_ready: bool,
|
||||||
/// Which frame generation: auto (DLSS frame generation where the card has
|
/// Which frame generation: auto (DLSS frame generation where the card has
|
||||||
@@ -275,7 +291,19 @@ fn settings(o: &Play, menu: &[(String, String)], streamline: Option<&Path>) -> (
|
|||||||
let saved = |k: &str| menu.iter().rev().find(|(n, _)| n == k).map(|(_, v)| v.as_str());
|
let saved = |k: &str| menu.iter().rev().find(|(n, _)| n == k).map(|(_, v)| v.as_str());
|
||||||
let series_s = saved("VICTORY_MENU_CONSOLE").map_or(o.series_s, |c| c == "series-s");
|
let series_s = saved("VICTORY_MENU_CONSOLE").map_or(o.series_s, |c| c == "series-s");
|
||||||
let res = saved("VICTORY_MENU_RES").filter(|r| RESOLUTIONS.contains(r)).unwrap_or(&o.res);
|
let res = saved("VICTORY_MENU_RES").filter(|r| RESOLUTIONS.contains(r)).unwrap_or(&o.res);
|
||||||
let dlss = saved("VICTORY_MENU_DLSS").filter(|d| DLSS_MODES.contains(d)).unwrap_or(&o.dlss);
|
let mut dlss = saved("VICTORY_MENU_DLSS").filter(|d| DLSS_MODES.contains(d)).unwrap_or(&o.dlss);
|
||||||
|
// Series S picture: the scene's size, which with DLSS on is its mode (the menu keeps the
|
||||||
|
// two matched); not saved yet, it is the DLSS mode's.
|
||||||
|
let s_res = saved("VICTORY_MENU_S_RES")
|
||||||
|
.and_then(|r| S_SIZES.iter().find(|(h, _)| *h == r))
|
||||||
|
.or_else(|| S_SIZES.iter().find(|(_, m)| *m == dlss))
|
||||||
|
.map_or("720", |(h, _)| *h);
|
||||||
|
if series_s
|
||||||
|
&& dlss != "off"
|
||||||
|
&& let Some((_, mode)) = S_SIZES.iter().find(|(h, _)| *h == s_res)
|
||||||
|
{
|
||||||
|
dlss = *mode;
|
||||||
|
}
|
||||||
// 0: off; 2 to 6: that many frames shown for each one rendered (1, from an older file: 2).
|
// 0: off; 2 to 6: that many frames shown for each one rendered (1, from an older file: 2).
|
||||||
let (mut framegen, mut times) = (o.framegen.is_some(), o.framegen.unwrap_or(2));
|
let (mut framegen, mut times) = (o.framegen.is_some(), o.framegen.unwrap_or(2));
|
||||||
if let Some(saved) = saved("VICTORY_MENU_FRAMEGEN") {
|
if let Some(saved) = saved("VICTORY_MENU_FRAMEGEN") {
|
||||||
@@ -310,7 +338,7 @@ fn settings(o: &Play, menu: &[(String, String)], streamline: Option<&Path>) -> (
|
|||||||
set("VICTORY_STREAMLINE_DIR", &dir.to_string_lossy());
|
set("VICTORY_STREAMLINE_DIR", &dir.to_string_lossy());
|
||||||
if framegen {
|
if framegen {
|
||||||
framegen_x = Some(times);
|
framegen_x = Some(times);
|
||||||
} else if !o.no_framegen_ready {
|
} else if o.framegen_ready && !o.no_framegen_ready {
|
||||||
framegen_x = Some(0); // ready, off
|
framegen_x = Some(0); // ready, off
|
||||||
}
|
}
|
||||||
if let Some(x) = framegen_x {
|
if let Some(x) = framegen_x {
|
||||||
@@ -328,7 +356,7 @@ fn settings(o: &Play, menu: &[(String, String)], streamline: Option<&Path>) -> (
|
|||||||
// Only with DLSS on: it never runs without DLSS's upscaling, and made ready without it (the
|
// Only with DLSS on: it never runs without DLSS's upscaling, and made ready without it (the
|
||||||
// title's FidelityFX then left with AMD's files) the title stopped during the boot screens
|
// title's FidelityFX then left with AMD's files) the title stopped during the boot screens
|
||||||
// (0x80000003 at +0x2219650, or exit code 3; #331, #459: --no-framegen-ready avoided it).
|
// (0x80000003 at +0x2219650, or exit code 3; #331, #459: --no-framegen-ready avoided it).
|
||||||
if dlss_on && fg_type != "dlss" && (framegen || !o.no_framegen_ready) {
|
if dlss_on && fg_type != "dlss" && (framegen || o.framegen_ready && !o.no_framegen_ready) {
|
||||||
set("VICTORY_FSR_FRAMEGEN", "1");
|
set("VICTORY_FSR_FRAMEGEN", "1");
|
||||||
if fg_type == "fsr" {
|
if fg_type == "fsr" {
|
||||||
s.remove("VICTORY_FRAMEGEN");
|
s.remove("VICTORY_FRAMEGEN");
|
||||||
@@ -356,6 +384,7 @@ fn settings(o: &Play, menu: &[(String, String)], streamline: Option<&Path>) -> (
|
|||||||
let mut set = |k: &str, v: &str| drop(s.insert(k.to_owned(), v.to_owned()));
|
let mut set = |k: &str, v: &str| drop(s.insert(k.to_owned(), v.to_owned()));
|
||||||
set("VICTORY_MENU_CONSOLE", if series_s { "series-s" } else { "series-x" });
|
set("VICTORY_MENU_CONSOLE", if series_s { "series-s" } else { "series-x" });
|
||||||
set("VICTORY_MENU_RES", res);
|
set("VICTORY_MENU_RES", res);
|
||||||
|
set("VICTORY_MENU_S_RES", if dlss_on { s_res } else { "720" });
|
||||||
set("VICTORY_MENU_DLSS", if dlss_on { dlss } else { "off" });
|
set("VICTORY_MENU_DLSS", if dlss_on { dlss } else { "off" });
|
||||||
set("VICTORY_MENU_FRAMEGEN", &framegen_x.unwrap_or(0).to_string());
|
set("VICTORY_MENU_FRAMEGEN", &framegen_x.unwrap_or(0).to_string());
|
||||||
set("VICTORY_MENU_FG_TYPE", fg_type);
|
set("VICTORY_MENU_FG_TYPE", fg_type);
|
||||||
@@ -730,20 +759,20 @@ fn check_shader_model() -> Result<()> {
|
|||||||
};
|
};
|
||||||
if yes {
|
if yes {
|
||||||
match fetch_d3d12(&to) {
|
match fetch_d3d12(&to) {
|
||||||
Ok(()) => match {
|
Ok(()) => {
|
||||||
// This process is yet to load Direct3D 12: it asks for the file now there.
|
// This process is yet to load Direct3D 12: it asks for the file now there.
|
||||||
crate::match_d3d12_core();
|
crate::match_d3d12_core();
|
||||||
shader_model()
|
match shader_model() {
|
||||||
} {
|
Some(now) if now >= needed => {
|
||||||
Some(now) if now >= needed => {
|
println!("Shader model {}.{} with Microsoft's runtime. Starting the game.", now.0, now.1);
|
||||||
println!("Shader model {}.{} with Microsoft's runtime. Starting the game.", now.0, now.1);
|
return Ok(());
|
||||||
return Ok(());
|
}
|
||||||
|
now => {
|
||||||
|
let now = now.unwrap_or(found);
|
||||||
|
println!("With Microsoft's runtime the GPU still runs shader model {}.{}.", now.0, now.1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
now => {
|
}
|
||||||
let now = now.unwrap_or(found);
|
|
||||||
println!("With Microsoft's runtime the GPU still runs shader model {}.{}.", now.0, now.1);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(e) => println!("{e:#}"),
|
Err(e) => println!("{e:#}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -862,7 +891,10 @@ pub(crate) fn prepare(o: &Play) -> Result<Ready> {
|
|||||||
// The first start of this victory.exe (no mark for its bytes yet): the game plays a little
|
// The first start of this victory.exe (no mark for its bytes yet): the game plays a little
|
||||||
// and starts again by itself (crates\victory-gpu\src\host\menu.rs, `warmup`), since a new
|
// and starts again by itself (crates\victory-gpu\src\host\menu.rs, `warmup`), since a new
|
||||||
// exe's first run stays at about 14 fps. `--set VICTORY_WARMUP_RESTART=0`: not done.
|
// exe's first run stays at about 14 fps. `--set VICTORY_WARMUP_RESTART=0`: not done.
|
||||||
|
// Only with DLSS Frame Generation ready or on: its swap chain (Streamline's) is what held
|
||||||
|
// a first run at 14 fps (#515, #574); without it a first run plays at full speed.
|
||||||
if !s.contains_key("VICTORY_WARMUP_RESTART")
|
if !s.contains_key("VICTORY_WARMUP_RESTART")
|
||||||
|
&& s.get("VICTORY_FRAMEGEN").is_some_and(|v| v == "1")
|
||||||
&& let Some(mark) = warmup_mark(&home, &program)
|
&& let Some(mark) = warmup_mark(&home, &program)
|
||||||
&& !mark.exists()
|
&& !mark.exists()
|
||||||
{
|
{
|
||||||
@@ -924,8 +956,8 @@ fn restart_args(o: &Play, exe: &Path) -> String {
|
|||||||
if let Some(x) = o.framegen {
|
if let Some(x) = o.framegen {
|
||||||
args.extend(["--framegen".to_owned(), x.to_string()]);
|
args.extend(["--framegen".to_owned(), x.to_string()]);
|
||||||
}
|
}
|
||||||
if o.no_framegen_ready {
|
if o.framegen_ready && !o.no_framegen_ready {
|
||||||
args.push("--no-framegen-ready".to_owned());
|
args.push("--framegen-ready".to_owned());
|
||||||
}
|
}
|
||||||
args.extend(["--fg-type".to_owned(), quoted(&o.fg_type), "--fps".to_owned(), o.fps.to_string()]);
|
args.extend(["--fg-type".to_owned(), quoted(&o.fg_type), "--fps".to_owned(), o.fps.to_string()]);
|
||||||
for more in &o.more {
|
for more in &o.more {
|
||||||
@@ -955,6 +987,7 @@ mod tests {
|
|||||||
res: "1440".to_owned(),
|
res: "1440".to_owned(),
|
||||||
dlss: "quality".to_owned(),
|
dlss: "quality".to_owned(),
|
||||||
framegen: None,
|
framegen: None,
|
||||||
|
framegen_ready: false,
|
||||||
no_framegen_ready: false,
|
no_framegen_ready: false,
|
||||||
fg_type: "auto".to_owned(),
|
fg_type: "auto".to_owned(),
|
||||||
fps: 1000,
|
fps: 1000,
|
||||||
@@ -971,7 +1004,7 @@ mod tests {
|
|||||||
#[command(flatten)]
|
#[command(flatten)]
|
||||||
play: Play,
|
play: Play,
|
||||||
}
|
}
|
||||||
let exe = Path::new(r"C:\Games\GTA VI's\game_scarlett_master.exe");
|
let exe = Path::new(r"C:\Games\My Title's\game_scarlett_master.exe");
|
||||||
let first = [
|
let first = [
|
||||||
"x", "--series-s", "--dlss", "performance", "--framegen", "2", "--fg-type", "dlss", "--set", "VICTORY_MFG_UNLOCKER=1", "--set",
|
"x", "--series-s", "--dlss", "performance", "--framegen", "2", "--fg-type", "dlss", "--set", "VICTORY_MFG_UNLOCKER=1", "--set",
|
||||||
"VICTORY_X=a b", "--preload",
|
"VICTORY_X=a b", "--preload",
|
||||||
@@ -980,7 +1013,7 @@ mod tests {
|
|||||||
let args = restart_args(&o, exe);
|
let args = restart_args(&o, exe);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
args,
|
args,
|
||||||
r"play 'C:\Games\GTA VI''s\game_scarlett_master.exe' --series-s --res '1440' --dlss 'performance' --framegen 2 --fg-type 'dlss' --fps 1000 --set 'VICTORY_MFG_UNLOCKER=1' --set 'VICTORY_X=a b'"
|
r"play 'C:\Games\My Title''s\game_scarlett_master.exe' --series-s --res '1440' --dlss 'performance' --framegen 2 --fg-type 'dlss' --fps 1000 --set 'VICTORY_MFG_UNLOCKER=1' --set 'VICTORY_X=a b'"
|
||||||
);
|
);
|
||||||
// Read back as PowerShell reads it: the same options again, and no preload.
|
// Read back as PowerShell reads it: the same options again, and no preload.
|
||||||
let mut words: Vec<String> = Vec::new();
|
let mut words: Vec<String> = Vec::new();
|
||||||
@@ -1004,7 +1037,7 @@ mod tests {
|
|||||||
let plain = Line::try_parse_from(["x"]).unwrap().play;
|
let plain = Line::try_parse_from(["x"]).unwrap().play;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
restart_args(&plain, exe),
|
restart_args(&plain, exe),
|
||||||
r"play 'C:\Games\GTA VI''s\game_scarlett_master.exe' --res '1440' --dlss 'quality' --fg-type 'auto' --fps 1000"
|
r"play 'C:\Games\My Title''s\game_scarlett_master.exe' --res '1440' --dlss 'quality' --fg-type 'auto' --fps 1000"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1020,7 +1053,14 @@ mod tests {
|
|||||||
assert_eq!(get("VICTORY_NATIVE_1440P"), Some("1"));
|
assert_eq!(get("VICTORY_NATIVE_1440P"), Some("1"));
|
||||||
assert_eq!((get("VICTORY_DLSS"), get("VICTORY_DLSS_MODE")), (Some("1"), Some("quality")));
|
assert_eq!((get("VICTORY_DLSS"), get("VICTORY_DLSS_MODE")), (Some("1"), Some("quality")));
|
||||||
assert_eq!(get("VICTORY_STREAMLINE_DIR"), Some(r"C:\nvidia"));
|
assert_eq!(get("VICTORY_STREAMLINE_DIR"), Some(r"C:\nvidia"));
|
||||||
// frame generation ready, off, with a little memory held back for it
|
// frame generation off and not made ready: no swap chain of Streamline's, no memory held back
|
||||||
|
assert!(!s.contains_key("VICTORY_FRAMEGEN") && !s.contains_key("VICTORY_FRAMEGEN_X"));
|
||||||
|
assert!(!s.contains_key("VICTORY_FSR_FRAMEGEN") && !s.contains_key("VICTORY_TEXTURE_ROOM_PERCENT"));
|
||||||
|
// ready, off, with a little memory held back for it, when asked
|
||||||
|
let mut o = options();
|
||||||
|
o.framegen_ready = true;
|
||||||
|
let (s, _) = settings(&o, &[], Some(dir));
|
||||||
|
let get = |k: &str| s.get(k).map(String::as_str);
|
||||||
assert_eq!((get("VICTORY_FRAMEGEN"), get("VICTORY_FRAMEGEN_X")), (Some("1"), Some("0")));
|
assert_eq!((get("VICTORY_FRAMEGEN"), get("VICTORY_FRAMEGEN_X")), (Some("1"), Some("0")));
|
||||||
assert_eq!(get("VICTORY_TEXTURE_ROOM_PERCENT"), Some("86"));
|
assert_eq!(get("VICTORY_TEXTURE_ROOM_PERCENT"), Some("86"));
|
||||||
assert_eq!(get("VICTORY_FRAME_INTERVAL_US"), Some("1000"));
|
assert_eq!(get("VICTORY_FRAME_INTERVAL_US"), Some("1000"));
|
||||||
@@ -1034,10 +1074,16 @@ mod tests {
|
|||||||
let get = |k: &str| s.get(k).map(String::as_str);
|
let get = |k: &str| s.get(k).map(String::as_str);
|
||||||
assert!(!s.contains_key("VICTORY_DLSS") && !s.contains_key("VICTORY_FRAMEGEN"));
|
assert!(!s.contains_key("VICTORY_DLSS") && !s.contains_key("VICTORY_FRAMEGEN"));
|
||||||
assert_eq!(get("VICTORY_MENU_DLSS"), Some("off"));
|
assert_eq!(get("VICTORY_MENU_DLSS"), Some("off"));
|
||||||
// nor FSR 3 frame generation: made ready without DLSS, the title's own FidelityFX
|
// nor FSR 3 frame generation, off and not made ready
|
||||||
// check stopped the game (#331, #459)
|
|
||||||
assert!(!s.contains_key("VICTORY_FSR_FRAMEGEN") && !s.contains_key("VICTORY_FRAMEGEN_X"));
|
assert!(!s.contains_key("VICTORY_FSR_FRAMEGEN") && !s.contains_key("VICTORY_FRAMEGEN_X"));
|
||||||
|
assert!(!s.contains_key("VICTORY_TEXTURE_ROOM_PERCENT"));
|
||||||
assert_eq!(get("VICTORY_MENU_FG_TYPE"), Some("auto"));
|
assert_eq!(get("VICTORY_MENU_FG_TYPE"), Some("auto"));
|
||||||
|
// nor when asked: made ready without DLSS, the title's own FidelityFX check stopped the
|
||||||
|
// game (#331, #459)
|
||||||
|
let mut o = options();
|
||||||
|
o.framegen_ready = true;
|
||||||
|
let (s, _) = settings(&o, &[], None);
|
||||||
|
assert!(!s.contains_key("VICTORY_FSR_FRAMEGEN") && !s.contains_key("VICTORY_FRAMEGEN_X"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -1077,6 +1123,37 @@ mod tests {
|
|||||||
assert_eq!(get("VICTORY_MENU_FRAMEGEN"), Some("6"));
|
assert_eq!(get("VICTORY_MENU_FRAMEGEN"), Some("6"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_series_s_picture_sets_the_scene() {
|
||||||
|
let get = |s: &BTreeMap<String, String>, k: &str| s.get(k).cloned();
|
||||||
|
let s_menu = |more: &str| parse_menu(&format!("VICTORY_MENU_CONSOLE=series-s\r\n{more}"));
|
||||||
|
// not saved yet: the DLSS mode's size, and the mode as it was
|
||||||
|
let (s, _) = settings(&options(), &s_menu("VICTORY_MENU_DLSS=balanced\r\n"), Some(Path::new("x")));
|
||||||
|
assert_eq!(get(&s, "VICTORY_MENU_S_RES").as_deref(), Some("626"));
|
||||||
|
assert_eq!(get(&s, "VICTORY_DLSS_MODE").as_deref(), Some("balanced"));
|
||||||
|
// 540 with DLSS: its performance mode, whatever the DLSS line held
|
||||||
|
let (s, _) = settings(&options(), &s_menu("VICTORY_MENU_DLSS=quality\r\nVICTORY_MENU_S_RES=540\r\n"), Some(Path::new("x")));
|
||||||
|
assert_eq!(get(&s, "VICTORY_DLSS_MODE").as_deref(), Some("performance"));
|
||||||
|
assert_eq!(get(&s, "VICTORY_MENU_DLSS").as_deref(), Some("performance"));
|
||||||
|
assert_eq!(get(&s, "VICTORY_FSR_PATH"), None);
|
||||||
|
// DLAA is 1080
|
||||||
|
let (s, _) = settings(&options(), &s_menu("VICTORY_MENU_DLSS=dlaa\r\n"), Some(Path::new("x")));
|
||||||
|
assert_eq!((get(&s, "VICTORY_DLSS_MODE").as_deref(), get(&s, "VICTORY_MENU_S_RES").as_deref()), (Some("dlaa"), Some("1080")));
|
||||||
|
// without DLSS (off, or no NVIDIA files): the game's 720, never the title's FidelityFX path
|
||||||
|
for (more, dir) in [("VICTORY_MENU_DLSS=off\r\nVICTORY_MENU_S_RES=540\r\n", Some(Path::new("x"))), ("VICTORY_MENU_S_RES=540\r\n", None)] {
|
||||||
|
let (s, _) = settings(&options(), &s_menu(more), dir);
|
||||||
|
assert_eq!((get(&s, "VICTORY_DLSS"), get(&s, "VICTORY_FSR_PATH"), get(&s, "VICTORY_DLSS_MODE")), (None, None, None));
|
||||||
|
assert_eq!(get(&s, "VICTORY_MENU_S_RES").as_deref(), Some("720"));
|
||||||
|
}
|
||||||
|
// 720 without DLSS: the game as it is
|
||||||
|
let (s, _) = settings(&options(), &s_menu("VICTORY_MENU_DLSS=off\r\nVICTORY_MENU_S_RES=720\r\n"), None);
|
||||||
|
assert_eq!((get(&s, "VICTORY_FSR_PATH"), get(&s, "VICTORY_DLSS_MODE")), (None, None));
|
||||||
|
// Series X: the Series S size changes nothing
|
||||||
|
let (s, series_s) = settings(&options(), &parse_menu("VICTORY_MENU_S_RES=540\r\n"), Some(Path::new("x")));
|
||||||
|
assert!(!series_s);
|
||||||
|
assert_eq!((get(&s, "VICTORY_DLSS_MODE").as_deref(), get(&s, "VICTORY_FSR_PATH")), (Some("quality"), None));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn options_and_set_are_applied() {
|
fn options_and_set_are_applied() {
|
||||||
let mut o = options();
|
let mut o = options();
|
||||||
|
|||||||
@@ -353,6 +353,13 @@ pub fn run(
|
|||||||
None => println!("frame rate: our clock {ms} ms; the title's own rate (30) left as it is"),
|
None => println!("frame rate: our clock {ms} ms; the title's own rate (30) left as it is"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Optional output size override (VICTORY_OUTPUT=1280x720, 1664x936, etc.).
|
||||||
|
#[cfg(windows)]
|
||||||
|
if execute {
|
||||||
|
let size = image.info().size_of_image as usize;
|
||||||
|
// SAFETY: the image stays mapped and nothing of it has run yet.
|
||||||
|
unsafe { victory_loader::resolution::apply_asked(image.base(), size) };
|
||||||
|
}
|
||||||
if !execute {
|
if !execute {
|
||||||
println!("not executing (pass --execute to start the title)");
|
println!("not executing (pass --execute to start the title)");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ pub fn run(jobs: Option<usize>, limit: Option<usize>, again: bool, used: bool, t
|
|||||||
state.0.push(ms);
|
state.0.push(ms);
|
||||||
state.1 += usize::from(!there);
|
state.1 += usize::from(!there);
|
||||||
let count = state.0.len();
|
let count = state.0.len();
|
||||||
if count % 1000 == 0 {
|
if count.is_multiple_of(1000) {
|
||||||
println!("{count} of {}, {:.0} s", all.len(), began.elapsed().as_secs_f64());
|
println!("{count} of {}, {:.0} s", all.len(), began.elapsed().as_secs_f64());
|
||||||
}
|
}
|
||||||
drop(state);
|
drop(state);
|
||||||
|
|||||||
@@ -1431,7 +1431,7 @@ mod tests {
|
|||||||
let needs: Vec<u64> = (0..9).map(|mip| l.bytes_from(mip)).collect();
|
let needs: Vec<u64> = (0..9).map(|mip| l.bytes_from(mip)).collect();
|
||||||
assert!(needs.windows(2).all(|w| w[0] >= w[1]), "{needs:?}");
|
assert!(needs.windows(2).all(|w| w[0] >= w[1]), "{needs:?}");
|
||||||
assert!(needs[3] * 4 < l.size, "{needs:?}");
|
assert!(needs[3] * 4 < l.size, "{needs:?}");
|
||||||
let tiled: Vec<u8> = (0..l.size).map(|i| (i * 7 >> 3) as u8).collect();
|
let tiled: Vec<u8> = (0..l.size).map(|i| ((i * 7) >> 3) as u8).collect();
|
||||||
for mip in 1..9 {
|
for mip in 1..9 {
|
||||||
let m = l.mips[mip as usize];
|
let m = l.mips[mip as usize];
|
||||||
let pitch = m.width as usize * 8;
|
let pitch = m.width as usize * 8;
|
||||||
|
|||||||
@@ -327,8 +327,15 @@ void clear_air(uint3 at : SV_DispatchThreadID) {
|
|||||||
float far = float(at.z) / float(d);
|
float far = float(at.z) / float(d);
|
||||||
float cap = air * lerp(dot(cells[CELLS].rgb, LUMA), dot(seen_there, LUMA), far);
|
float cap = air * lerp(dot(cells[CELLS].rgb, LUMA), dot(seen_there, LUMA), far);
|
||||||
float3 c = scattered[at];
|
float3 c = scattered[at];
|
||||||
|
uint3 bits = asuint(c);
|
||||||
|
bool3 bad = (bits & 0x7f800000u) == 0x7f800000u;
|
||||||
|
bool fixed_any = any(bad);
|
||||||
|
if (fixed_any) {
|
||||||
|
c = bad ? (bits == 0x7f800000u ? 64512.0 : 0.0) : c;
|
||||||
|
}
|
||||||
float has = dot(c, LUMA);
|
float has = dot(c, LUMA);
|
||||||
if (has > cap) scattered[at] = c * (cap / has);
|
if (has > cap) scattered[at] = c * (cap / has);
|
||||||
|
else if (fixed_any) scattered[at] = c;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -257,7 +257,11 @@ pub(crate) fn address(texture: &ID3D12Resource) -> Option<u64> {
|
|||||||
|
|
||||||
/// The address of a texture: the base its descriptor has.
|
/// The address of a texture: the base its descriptor has.
|
||||||
fn texture_address(texture: &ID3D12Resource, desc: &D3D12_RESOURCE_DESC) -> Option<u64> {
|
fn texture_address(texture: &ID3D12Resource, desc: &D3D12_RESOURCE_DESC) -> Option<u64> {
|
||||||
struct Slot(ID3D12DescriptorHeap, usize);
|
struct Slot {
|
||||||
|
/// Kept alive: `at` is in it.
|
||||||
|
_heap: ID3D12DescriptorHeap,
|
||||||
|
at: usize,
|
||||||
|
}
|
||||||
// SAFETY: a descriptor heap, used under the lock.
|
// SAFETY: a descriptor heap, used under the lock.
|
||||||
unsafe impl Send for Slot {}
|
unsafe impl Send for Slot {}
|
||||||
static SLOT: Mutex<Option<Slot>> = Mutex::new(None);
|
static SLOT: Mutex<Option<Slot>> = Mutex::new(None);
|
||||||
@@ -278,9 +282,9 @@ fn texture_address(texture: &ID3D12Resource, desc: &D3D12_RESOURCE_DESC) -> Opti
|
|||||||
.ok()?;
|
.ok()?;
|
||||||
// SAFETY: a live heap.
|
// SAFETY: a live heap.
|
||||||
let at = unsafe { heap.GetCPUDescriptorHandleForHeapStart().ptr };
|
let at = unsafe { heap.GetCPUDescriptorHandleForHeapStart().ptr };
|
||||||
*slot = Some(Slot(heap, at));
|
*slot = Some(Slot { _heap: heap, at });
|
||||||
}
|
}
|
||||||
let at = slot.as_ref()?.1;
|
let at = slot.as_ref()?.at;
|
||||||
let format = viewable(desc.Format.0)?;
|
let format = viewable(desc.Format.0)?;
|
||||||
let mut view = D3D12_SHADER_RESOURCE_VIEW_DESC {
|
let mut view = D3D12_SHADER_RESOURCE_VIEW_DESC {
|
||||||
Format: DXGI_FORMAT(format),
|
Format: DXGI_FORMAT(format),
|
||||||
|
|||||||
@@ -1236,7 +1236,7 @@ pub(crate) fn log(frames: f64) {
|
|||||||
);
|
);
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
"waits for the write trackers' locks per frame, all threads (number, time): {}",
|
"waits for the write trackers' locks per frame, all threads (number, time): {}",
|
||||||
crate::watch::lock_waits(frames as f64)
|
crate::watch::lock_waits(frames)
|
||||||
);
|
);
|
||||||
let [copies, blocks, opened, stores, unknown, full, stayed, copied_same, records] =
|
let [copies, blocks, opened, stores, unknown, full, stayed, copied_same, records] =
|
||||||
[0, 1, 2, 3, 4, 5, 6, 7, 8].map(|n| crate::titlewrite::DONE[n].load(std::sync::atomic::Ordering::Relaxed));
|
[0, 1, 2, 3, 4, 5, 6, 7, 8].map(|n| crate::titlewrite::DONE[n].load(std::sync::atomic::Ordering::Relaxed));
|
||||||
|
|||||||
@@ -1342,8 +1342,8 @@ impl Due {
|
|||||||
fn ordered(self, max: usize) -> (Vec<(u32, u64)>, Vec<Option<Checked>>) {
|
fn ordered(self, max: usize) -> (Vec<(u32, u64)>, Vec<Option<Checked>>) {
|
||||||
let Due { mut again, mut fresh } = self;
|
let Due { mut again, mut fresh } = self;
|
||||||
// By the number of the write, counted over the run.
|
// By the number of the write, counted over the run.
|
||||||
again.sort_unstable_by(|a, b| b.2.cmp(&a.2));
|
again.sort_unstable_by_key(|e| std::cmp::Reverse(e.2));
|
||||||
fresh.sort_unstable_by(|a, b| b.2.cmp(&a.2));
|
fresh.sort_unstable_by_key(|e| std::cmp::Reverse(e.2));
|
||||||
let mut order: Vec<(u32, u64)> = again.iter().map(|&(_, index, write, _)| (index, write)).collect();
|
let mut order: Vec<(u32, u64)> = again.iter().map(|&(_, index, write, _)| (index, write)).collect();
|
||||||
let mut known: Vec<Option<Checked>> = again.iter().map(|a| a.3).collect();
|
let mut known: Vec<Option<Checked>> = again.iter().map(|a| a.3).collect();
|
||||||
let (mut new, mut old) = (0, fresh.len());
|
let (mut new, mut old) = (0, fresh.len());
|
||||||
@@ -5159,20 +5159,30 @@ fn make_twinned(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The view `desc` of a texture, of a host copy of its levels from `base`
|
/// The view `desc` of a texture, of a host copy of its levels from `base`
|
||||||
/// on (`crate::resource::held_only`). What it shows of larger ones, if any,
|
/// on (`crate::resource::held_only` / `VICTORY_TEXTURE_DROP_MIPS`). What it
|
||||||
/// is left out.
|
/// shows of larger ones, if any, is left out.
|
||||||
fn from_base(desc: &mut D3D12_SHADER_RESOURCE_VIEW_DESC, base: u32) {
|
fn from_base(desc: &mut D3D12_SHADER_RESOURCE_VIEW_DESC, base: u32) {
|
||||||
if desc.ViewDimension != D3D12_SRV_DIMENSION_TEXTURE2D {
|
let shift = |first: &mut u32, levels: &mut u32, clamp: &mut f32| {
|
||||||
return;
|
let lost = base.saturating_sub(*first);
|
||||||
|
*first = first.saturating_sub(base);
|
||||||
|
if *levels != u32::MAX {
|
||||||
|
*levels = levels.saturating_sub(lost).max(1);
|
||||||
|
}
|
||||||
|
*clamp = (*clamp - base as f32).max(0.0);
|
||||||
|
};
|
||||||
|
match desc.ViewDimension {
|
||||||
|
D3D12_SRV_DIMENSION_TEXTURE2D => {
|
||||||
|
// SAFETY: the member its dimension says.
|
||||||
|
let t = unsafe { &mut desc.Anonymous.Texture2D };
|
||||||
|
shift(&mut t.MostDetailedMip, &mut t.MipLevels, &mut t.ResourceMinLODClamp);
|
||||||
|
}
|
||||||
|
D3D12_SRV_DIMENSION_TEXTURE2DARRAY => {
|
||||||
|
// SAFETY: the member its dimension says.
|
||||||
|
let t = unsafe { &mut desc.Anonymous.Texture2DArray };
|
||||||
|
shift(&mut t.MostDetailedMip, &mut t.MipLevels, &mut t.ResourceMinLODClamp);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
// SAFETY: the member its dimension says.
|
|
||||||
let t = unsafe { &mut desc.Anonymous.Texture2D };
|
|
||||||
let lost = base.saturating_sub(t.MostDetailedMip);
|
|
||||||
t.MostDetailedMip = t.MostDetailedMip.saturating_sub(base);
|
|
||||||
if t.MipLevels != u32::MAX {
|
|
||||||
t.MipLevels = t.MipLevels.saturating_sub(lost).max(1);
|
|
||||||
}
|
|
||||||
t.ResourceMinLODClamp = (t.ResourceMinLODClamp - base as f32).max(0.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Writes of a slot with another view of the placed texture it showed,
|
/// Writes of a slot with another view of the placed texture it showed,
|
||||||
|
|||||||
+218
-67
@@ -715,49 +715,162 @@ fn heap_spread() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The host copy and range the buffer view of each of a heap's slots reads
|
/// The host copy and range the buffer view of each of a heap's slots reads
|
||||||
/// ([`State::heap_buffers`]), by slot.
|
/// ([`State::heap_buffers`]), by slot, with incremental per-copy spans and
|
||||||
#[derive(Default)]
|
/// active-slot buckets partitioned by `slot % HEAP_ROUND`.
|
||||||
struct HeapRanges<T>(Vec<Option<(T, u64, u64)>>);
|
struct HeapRanges<T> {
|
||||||
|
slots: Vec<Option<(std::sync::Arc<T>, u64, u64)>>,
|
||||||
|
in_part: Vec<u64>,
|
||||||
|
by_part: [Vec<u32>; HEAP_ROUND as usize],
|
||||||
|
spans: crate::host::ByCopy<(std::sync::Arc<T>, u64, u64)>,
|
||||||
|
spans_dirty: bool,
|
||||||
|
views: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Default for HeapRanges<T> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
slots: Vec::new(),
|
||||||
|
in_part: Vec::new(),
|
||||||
|
by_part: std::array::from_fn(|_| Vec::new()),
|
||||||
|
spans: Default::default(),
|
||||||
|
spans_dirty: false,
|
||||||
|
views: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Descriptor-derived references belong to the heap that produced them.
|
/// Descriptor-derived references belong to the heap that produced them.
|
||||||
pub(crate) struct BufferSweep {
|
pub(crate) struct BufferSweep {
|
||||||
passes: u64,
|
passes: u64,
|
||||||
ranges: HeapRanges<std::sync::Arc<crate::shadow::Shadow>>,
|
ranges: HeapRanges<crate::shadow::Shadow>,
|
||||||
// Last refresh frame and covered interval for throttled, unwatched copies.
|
// Last refresh frame and covered interval for throttled, unwatched copies.
|
||||||
unwatched: std::collections::HashMap<u64, (u64, u64, u64)>,
|
unwatched: std::collections::HashMap<u64, (u64, u64, u64)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for BufferSweep {
|
impl Default for BufferSweep {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self { passes: 0, ranges: HeapRanges(Vec::new()), unwatched: Default::default() }
|
Self { passes: 0, ranges: HeapRanges::default(), unwatched: Default::default() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> HeapRanges<T> {
|
impl<T> HeapRanges<T> {
|
||||||
fn set(&mut self, slot: u32, range: Option<(T, u64, u64)>) {
|
fn clear(&mut self) {
|
||||||
let slot = slot as usize;
|
self.slots.clear();
|
||||||
if range.is_none() && slot >= self.0.len() {
|
self.in_part.clear();
|
||||||
return;
|
for part in &mut self.by_part {
|
||||||
|
part.clear();
|
||||||
}
|
}
|
||||||
if slot >= self.0.len() {
|
self.spans.clear();
|
||||||
self.0.resize_with(slot + 1, || None);
|
self.spans_dirty = false;
|
||||||
}
|
self.views = 0;
|
||||||
self.0[slot] = range;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Forgets the slots of one of `parts` parts
|
fn set(&mut self, slot: u32, range: Option<(std::sync::Arc<T>, u64, u64)>) {
|
||||||
/// (`HostHeap::buffer_slots_of`).
|
use std::sync::Arc;
|
||||||
fn forget_part(&mut self, part: u32, parts: u32) {
|
let idx = slot as usize;
|
||||||
self.0.iter_mut().skip(part as usize).step_by(parts as usize).for_each(|r| *r = None);
|
match (self.slots.get(idx).and_then(Option::as_ref), range.as_ref()) {
|
||||||
|
(None, None) => return,
|
||||||
|
(Some((os, of, ot)), Some((ns, nf, nt)))
|
||||||
|
if Arc::ptr_eq(os, ns) && *of == *nf && *ot == *nt =>
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
if idx >= self.slots.len() {
|
||||||
|
self.slots.resize_with(idx + 1, || None);
|
||||||
|
}
|
||||||
|
let old = std::mem::replace(&mut self.slots[idx], range);
|
||||||
|
if let Some((os, of, ot)) = old {
|
||||||
|
self.views -= 1;
|
||||||
|
if !self.spans_dirty {
|
||||||
|
let old_key = Arc::as_ptr(&os) as usize;
|
||||||
|
if let Some(&(_, min_from, max_to)) = self.spans.get(&old_key) {
|
||||||
|
let shrunk = match &self.slots[idx] {
|
||||||
|
Some((ns, nf, nt)) if Arc::ptr_eq(&os, ns) => {
|
||||||
|
(of <= min_from && *nf > of) || (ot >= max_to && *nt < ot)
|
||||||
|
}
|
||||||
|
_ => of <= min_from || ot >= max_to,
|
||||||
|
};
|
||||||
|
if shrunk {
|
||||||
|
self.spans_dirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some((ns, nf, nt)) = &self.slots[idx] {
|
||||||
|
self.views += 1;
|
||||||
|
let word = idx / 64;
|
||||||
|
let bit = 1u64 << (idx % 64);
|
||||||
|
if word >= self.in_part.len() {
|
||||||
|
self.in_part.resize(word + 1, 0);
|
||||||
|
}
|
||||||
|
if self.in_part[word] & bit == 0 {
|
||||||
|
self.in_part[word] |= bit;
|
||||||
|
self.by_part[idx % HEAP_ROUND as usize].push(slot);
|
||||||
|
}
|
||||||
|
if !self.spans_dirty {
|
||||||
|
let key = Arc::as_ptr(ns) as usize;
|
||||||
|
let span = self.spans.entry(key).or_insert_with(|| (ns.clone(), *nf, *nt));
|
||||||
|
span.1 = span.1.min(*nf);
|
||||||
|
span.2 = span.2.max(*nt);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ranges(&self) -> impl Iterator<Item = &(T, u64, u64)> {
|
/// Removes slots in `part` that are no longer live buffer slots without
|
||||||
self.0.iter().flatten()
|
/// churning slots that stay unchanged.
|
||||||
|
fn prune_part(&mut self, part: u32, mut is_live: impl FnMut(u32) -> bool) {
|
||||||
|
let part_idx = part as usize;
|
||||||
|
let mut list = std::mem::take(&mut self.by_part[part_idx]);
|
||||||
|
let mut i = 0;
|
||||||
|
while i < list.len() {
|
||||||
|
let slot = list[i];
|
||||||
|
let idx = slot as usize;
|
||||||
|
let occupied = self.slots.get(idx).is_some_and(Option::is_some);
|
||||||
|
if !occupied || !is_live(slot) {
|
||||||
|
if occupied {
|
||||||
|
self.set(slot, None);
|
||||||
|
}
|
||||||
|
let word = idx / 64;
|
||||||
|
if let Some(bits) = self.in_part.get_mut(word) {
|
||||||
|
*bits &= !(1u64 << (idx % 64));
|
||||||
|
}
|
||||||
|
list.swap_remove(i);
|
||||||
|
} else {
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.by_part[part_idx] = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn spans(&mut self) -> &crate::host::ByCopy<(std::sync::Arc<T>, u64, u64)> {
|
||||||
|
if self.spans_dirty {
|
||||||
|
self.spans.clear();
|
||||||
|
for part in &self.by_part {
|
||||||
|
for &slot in part {
|
||||||
|
if let Some((shadow, from, to)) = self.slots.get(slot as usize).and_then(Option::as_ref) {
|
||||||
|
let key = std::sync::Arc::as_ptr(shadow) as usize;
|
||||||
|
let span = self.spans.entry(key).or_insert_with(|| (shadow.clone(), *from, *to));
|
||||||
|
span.1 = span.1.min(*from);
|
||||||
|
span.2 = span.2.max(*to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.spans_dirty = false;
|
||||||
|
}
|
||||||
|
&self.spans
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
fn ranges(&self) -> impl Iterator<Item = &(std::sync::Arc<T>, u64, u64)> {
|
||||||
|
self.slots.iter().flatten()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod heap_range_tests {
|
mod heap_range_tests {
|
||||||
|
use std::sync::Arc;
|
||||||
use super::{HEAP_ROUND, HeapRanges};
|
use super::{HEAP_ROUND, HeapRanges};
|
||||||
|
|
||||||
/// Round by round every slot is looked at again once, whatever was
|
/// Round by round every slot is looked at again once, whatever was
|
||||||
@@ -765,25 +878,25 @@ mod heap_range_tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn every_slot_is_looked_at_again_in_a_round() {
|
fn every_slot_is_looked_at_again_in_a_round() {
|
||||||
const SLOTS: u32 = 1000;
|
const SLOTS: u32 = 1000;
|
||||||
let mut ranges = HeapRanges(Vec::new());
|
let copy = Arc::new(());
|
||||||
|
let mut ranges = HeapRanges::default();
|
||||||
ranges.set(7, None);
|
ranges.set(7, None);
|
||||||
assert_eq!(ranges.ranges().count(), 0);
|
assert_eq!(ranges.views, 0);
|
||||||
for slot in (0..SLOTS).step_by(3) {
|
for slot in (0..SLOTS).step_by(3) {
|
||||||
ranges.set(slot, Some(((), 0, 1)));
|
ranges.set(slot, Some((copy.clone(), 0, 1)));
|
||||||
}
|
}
|
||||||
let parts = HEAP_ROUND as u32;
|
let parts = HEAP_ROUND as u32;
|
||||||
for pass in 1..=HEAP_ROUND {
|
for pass in 1..=HEAP_ROUND {
|
||||||
let part = (pass % HEAP_ROUND) as u32;
|
let part = (pass % HEAP_ROUND) as u32;
|
||||||
ranges.forget_part(part, parts);
|
ranges.prune_part(part, |s| s % 3 == 0);
|
||||||
for slot in (0..SLOTS).step_by(3).filter(|slot| slot % parts == part) {
|
for slot in (0..SLOTS).step_by(3).filter(|slot| slot % parts == part) {
|
||||||
assert!(ranges.0[slot as usize].is_none(), "slot {slot} not forgotten");
|
ranges.set(slot, Some((copy.clone(), pass, pass + 1)));
|
||||||
ranges.set(slot, Some(((), pass, pass)));
|
|
||||||
}
|
}
|
||||||
assert_eq!(ranges.ranges().count(), SLOTS.div_ceil(3) as usize);
|
assert_eq!(ranges.views as usize, SLOTS.div_ceil(3) as usize);
|
||||||
}
|
}
|
||||||
assert!(ranges.ranges().all(|r| r.1 != 0), "a slot not looked at in a round");
|
assert!(ranges.ranges().all(|r| r.1 != 0), "a slot not looked at in a round");
|
||||||
ranges.set(3, None);
|
ranges.set(3, None);
|
||||||
assert_eq!(ranges.ranges().count(), SLOTS.div_ceil(3) as usize - 1);
|
assert_eq!(ranges.views as usize, SLOTS.div_ceil(3) as usize - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The spans of 4,400 copies from the ranges of 72,000 slots, as a pass
|
/// The spans of 4,400 copies from the ranges of 72,000 slots, as a pass
|
||||||
@@ -793,9 +906,8 @@ mod heap_range_tests {
|
|||||||
#[ignore]
|
#[ignore]
|
||||||
fn spans_of_a_pass() {
|
fn spans_of_a_pass() {
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
|
||||||
let copies: Vec<Arc<u64>> = (0..4400).map(Arc::new).collect();
|
let copies: Vec<Arc<u64>> = (0..4400).map(Arc::new).collect();
|
||||||
let (mut table, mut slots) = (HashMap::new(), HeapRanges(Vec::new()));
|
let (mut table, mut slots) = (HashMap::new(), HeapRanges::default());
|
||||||
for slot in 0..72_000u32 {
|
for slot in 0..72_000u32 {
|
||||||
let copy = &copies[slot as usize * 7919 % 4400];
|
let copy = &copies[slot as usize * 7919 % 4400];
|
||||||
table.insert(slot, (copy.clone(), u64::from(slot), u64::from(slot) + 64));
|
table.insert(slot, (copy.clone(), u64::from(slot), u64::from(slot) + 64));
|
||||||
@@ -1174,13 +1286,13 @@ fn heap_buffer_pass(heap: &crate::descriptor::Heap, host: &crate::descriptor::ho
|
|||||||
let changed = host.buffer_changes();
|
let changed = host.buffer_changes();
|
||||||
let all = *passes == 0 || (*passes % HEAP_ROUND == 0 && !heap_spread());
|
let all = *passes == 0 || (*passes % HEAP_ROUND == 0 && !heap_spread());
|
||||||
let slots = if all {
|
let slots = if all {
|
||||||
ranges.0.clear();
|
ranges.clear();
|
||||||
host.buffer_slots()
|
host.buffer_slots()
|
||||||
} else if heap_spread() {
|
} else if heap_spread() {
|
||||||
// The written ones, and this pass's part of the others.
|
// The written ones, and this pass's part of the others.
|
||||||
let (part, parts) = ((*passes % HEAP_ROUND) as u32, HEAP_ROUND as u32);
|
let (part, parts) = ((*passes % HEAP_ROUND) as u32, HEAP_ROUND as u32);
|
||||||
ranges.forget_part(part, parts);
|
|
||||||
let mut slots = host.buffer_slots_of(part, parts);
|
let mut slots = host.buffer_slots_of(part, parts);
|
||||||
|
ranges.prune_part(part, |s| slots.binary_search(&s).is_ok());
|
||||||
slots.extend(changed);
|
slots.extend(changed);
|
||||||
slots
|
slots
|
||||||
} else {
|
} else {
|
||||||
@@ -1256,16 +1368,10 @@ fn heap_buffer_pass(heap: &crate::descriptor::Heap, host: &crate::descriptor::ho
|
|||||||
}
|
}
|
||||||
#[cfg(feature = "diagnostics")]
|
#[cfg(feature = "diagnostics")]
|
||||||
let looked = std::time::Instant::now();
|
let looked = std::time::Instant::now();
|
||||||
// Per host copy, the span its picked views cover.
|
// Per host copy, the span its picked views cover (maintained incrementally).
|
||||||
let mut spans: crate::host::ByCopy<(std::sync::Arc<crate::shadow::Shadow>, u64, u64)> = Default::default();
|
let views = ranges.views;
|
||||||
let mut views = 0u32;
|
let spans = ranges.spans();
|
||||||
for (shadow, from, to) in ranges.ranges() {
|
let copies_len = spans.len();
|
||||||
views += 1;
|
|
||||||
let key = std::sync::Arc::as_ptr(shadow) as usize;
|
|
||||||
let span = spans.entry(key).or_insert_with(|| (shadow.clone(), *from, *to));
|
|
||||||
span.1 = span.1.min(*from);
|
|
||||||
span.2 = span.2.max(*to);
|
|
||||||
}
|
|
||||||
let bytes: u64 = spans.values().map(|s| s.2 - s.1).sum();
|
let bytes: u64 = spans.values().map(|s| s.2 - s.1).sum();
|
||||||
// Memory that is not write-watched is copied whole by every refresh.
|
// Memory that is not write-watched is copied whole by every refresh.
|
||||||
// It was once refreshed only every 120 frames (unmapped pages read
|
// It was once refreshed only every 120 frames (unmapped pages read
|
||||||
@@ -1279,21 +1385,27 @@ fn heap_buffer_pass(heap: &crate::descriptor::Heap, host: &crate::descriptor::ho
|
|||||||
std::env::var("VICTORY_UNWATCHED_FRAMES").ok().and_then(|v| v.parse().ok()).unwrap_or(1)
|
std::env::var("VICTORY_UNWATCHED_FRAMES").ok().and_then(|v| v.parse().ok()).unwrap_or(1)
|
||||||
});
|
});
|
||||||
let mut found = Vec::with_capacity(spans.len());
|
let mut found = Vec::with_capacity(spans.len());
|
||||||
let mut next_unwatched = std::collections::HashMap::new();
|
if every > 1 {
|
||||||
for (shadow, from, to) in spans.values() {
|
let mut next_unwatched = std::collections::HashMap::new();
|
||||||
if every > 1 && shadow.unwatched() {
|
for (shadow, from, to) in spans.values() {
|
||||||
let id = shadow.id();
|
if shadow.unwatched() {
|
||||||
if let Some(&(last, low, high)) = unwatched.get(&id)
|
let id = shadow.id();
|
||||||
&& frame >= last && frame - last < every && low <= *from && *to <= high
|
if let Some(&(last, low, high)) = unwatched.get(&id)
|
||||||
{
|
&& frame >= last && frame - last < every && low <= *from && *to <= high
|
||||||
next_unwatched.insert(id, (last, low, high));
|
{
|
||||||
continue;
|
next_unwatched.insert(id, (last, low, high));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
next_unwatched.insert(id, (frame, *from, *to));
|
||||||
}
|
}
|
||||||
next_unwatched.insert(id, (frame, *from, *to));
|
found.push((shadow.clone(), *from, (*to).min(*from + shadow.left(*from))));
|
||||||
|
}
|
||||||
|
*unwatched = next_unwatched;
|
||||||
|
} else {
|
||||||
|
for (shadow, from, to) in spans.values() {
|
||||||
|
found.push((shadow.clone(), *from, (*to).min(*from + shadow.left(*from))));
|
||||||
}
|
}
|
||||||
found.push((shadow.clone(), *from, (*to).min(*from + shadow.left(*from))));
|
|
||||||
}
|
}
|
||||||
*unwatched = next_unwatched;
|
|
||||||
drop(kept);
|
drop(kept);
|
||||||
#[cfg(feature = "diagnostics")]
|
#[cfg(feature = "diagnostics")]
|
||||||
let refreshed = std::time::Instant::now();
|
let refreshed = std::time::Instant::now();
|
||||||
@@ -1310,7 +1422,7 @@ fn heap_buffer_pass(heap: &crate::descriptor::Heap, host: &crate::descriptor::ho
|
|||||||
tracing::info!(
|
tracing::info!(
|
||||||
slots = slots.len(),
|
slots = slots.len(),
|
||||||
views,
|
views,
|
||||||
copies = spans.len(),
|
copies = copies_len,
|
||||||
mb = bytes >> 20,
|
mb = bytes >> 20,
|
||||||
ms = started.elapsed().as_millis(),
|
ms = started.elapsed().as_millis(),
|
||||||
"buffer views of the heap made ready for shaders that pick them by index"
|
"buffer views of the heap made ready for shaders that pick them by index"
|
||||||
@@ -1979,7 +2091,7 @@ impl State {
|
|||||||
} else {
|
} else {
|
||||||
crate::memory::Use::Reads
|
crate::memory::Use::Reads
|
||||||
};
|
};
|
||||||
let Some(ready) = self.memory_ready(list, &t, compute, use_) else {
|
let Some(ready) = self.memory_ready(list, t, compute, use_) else {
|
||||||
once!("a shader that reads title memory by address without a view heap to hold its views: the draw is dropped");
|
once!("a shader that reads title memory by address without a view heap to hold its views: the draw is dropped");
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
@@ -3075,6 +3187,25 @@ impl State {
|
|||||||
if FRAME.swap(frame, Ordering::Relaxed) != frame {
|
if FRAME.swap(frame, Ordering::Relaxed) != frame {
|
||||||
SPENT.store(0, Ordering::Relaxed);
|
SPENT.store(0, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
let baking = crate::texture::BAKING.get();
|
||||||
|
let required = PASS_BUDGET.get().is_some_and(|(_, _, bake)| bake);
|
||||||
|
let frame_pass = !required && !baking && sync.is_none();
|
||||||
|
// If an earlier pass in this same frame already exhausted the
|
||||||
|
// `VICTORY_TEXSPK_PASS_MS` budget, still flip any newly-completed
|
||||||
|
// texture uploads visible, then bail before taking the global
|
||||||
|
// texture-queue lock and scanning tens of thousands of slots for a
|
||||||
|
// loop that would immediately time out on iteration 0.
|
||||||
|
if frame_pass
|
||||||
|
&& let Some(cap) = texspk_pass_ms()
|
||||||
|
&& PASS_FRAME.load(Ordering::Relaxed) == frame
|
||||||
|
&& PASS_FRAME_NANOS.load(Ordering::Relaxed) >= cap.saturating_mul(1_000_000)
|
||||||
|
{
|
||||||
|
before(1, || {
|
||||||
|
host.texture_views_remade();
|
||||||
|
host.texture_slots_flip();
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// No more of them are made while the card has no room
|
// No more of them are made while the card has no room
|
||||||
// (`resource::room`): by what is alive now, not by what was ever
|
// (`resource::room`): by what is alive now, not by what was ever
|
||||||
// staged (4 GB in all, after which later textures stayed empty for
|
// staged (4 GB in all, after which later textures stayed empty for
|
||||||
@@ -3093,7 +3224,6 @@ impl State {
|
|||||||
once!("textures picked by index: the card has no room for more; they wait");
|
once!("textures picked by index: the card has no room for more; they wait");
|
||||||
}
|
}
|
||||||
let mut refused = 0;
|
let mut refused = 0;
|
||||||
let baking = crate::texture::BAKING.get();
|
|
||||||
before(0, || {
|
before(0, || {
|
||||||
// Room again: the slots held back while the card was full are
|
// Room again: the slots held back while the card was full are
|
||||||
// due now (`full_card_pass`).
|
// due now (`full_card_pass`).
|
||||||
@@ -3121,10 +3251,15 @@ impl State {
|
|||||||
if room {
|
if room {
|
||||||
before(0, || host.texture_slots_waiting(frame));
|
before(0, || host.texture_slots_waiting(frame));
|
||||||
}
|
}
|
||||||
let required = PASS_BUDGET.get().is_some_and(|(_, _, bake)| bake);
|
|
||||||
// (And what the queue knew of each, `known`: see `Tells`.)
|
// (And what the queue knew of each, `known`: see `Tells`.)
|
||||||
let (mut due, mut known, census) =
|
let due_cap = if baking {
|
||||||
before(2, || host.texture_slots_due_known(frame, if baking { 1 << 16 } else { 4096 }));
|
1 << 16
|
||||||
|
} else if !room && !required {
|
||||||
|
1024
|
||||||
|
} else {
|
||||||
|
4096
|
||||||
|
};
|
||||||
|
let (mut due, mut known, census) = before(2, || host.texture_slots_due_known(frame, due_cap));
|
||||||
// (Those that are due later after all that are due.)
|
// (Those that are due later after all that are due.)
|
||||||
let on_time = due.len();
|
let on_time = due.len();
|
||||||
if baking {
|
if baking {
|
||||||
@@ -3210,7 +3345,6 @@ impl State {
|
|||||||
// A frame's runs of the pass (its own and the early ones, not those
|
// A frame's runs of the pass (its own and the early ones, not those
|
||||||
// before a bake) within `VICTORY_TEXSPK_PASS_MS` together
|
// before a bake) within `VICTORY_TEXSPK_PASS_MS` together
|
||||||
// ([`texspk_pass_ms`]).
|
// ([`texspk_pass_ms`]).
|
||||||
let frame_pass = !required && !baking && sync.is_none();
|
|
||||||
let span = match texspk_pass_ms() {
|
let span = match texspk_pass_ms() {
|
||||||
Some(cap) if frame_pass => {
|
Some(cap) if frame_pass => {
|
||||||
if PASS_FRAME.swap(frame, Ordering::Relaxed) != frame {
|
if PASS_FRAME.swap(frame, Ordering::Relaxed) != frame {
|
||||||
@@ -3377,10 +3511,11 @@ impl State {
|
|||||||
outcome(slot_outcome::HELD);
|
outcome(slot_outcome::HELD);
|
||||||
if full_card_pass() {
|
if full_card_pass() {
|
||||||
// Held back for the frames of about four seconds
|
// Held back for the frames of about four seconds
|
||||||
// (`most`), or until the card has room; the pass
|
// (`most`), or until the card has room; cap refusals
|
||||||
// goes on, within a count that bounds one pass.
|
// per pass at 256 so full-card cutscenes do not thrash
|
||||||
|
// thousands of held-slot tells under the queue lock.
|
||||||
tells.tell(index, write, Told::Held(frame + most));
|
tells.tell(index, write, Told::Held(frame + most));
|
||||||
if refused > 1024 {
|
if refused > 256 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if refused > 256 {
|
} else if refused > 256 {
|
||||||
@@ -4410,7 +4545,7 @@ impl State {
|
|||||||
let draws: u32 = census.1.values().sum();
|
let draws: u32 = census.1.values().sum();
|
||||||
if draws > 0 {
|
if draws > 0 {
|
||||||
let mut rects: Vec<([i32; 4], u32)> = census.1.iter().map(|(r, n)| (*r, *n)).collect();
|
let mut rects: Vec<([i32; 4], u32)> = census.1.iter().map(|(r, n)| (*r, *n)).collect();
|
||||||
rects.sort_unstable_by(|a, b| b.1.cmp(&a.1));
|
rects.sort_unstable_by_key(|r| std::cmp::Reverse(r.1));
|
||||||
let scissors: Vec<String> = rects
|
let scissors: Vec<String> = rects
|
||||||
.iter()
|
.iter()
|
||||||
.take(5)
|
.take(5)
|
||||||
@@ -4708,12 +4843,28 @@ impl State {
|
|||||||
let used = group.entry(k);
|
let used = group.entry(k);
|
||||||
match crate::descriptor::view(table + u64::from(k) * 32) {
|
match crate::descriptor::view(table + u64::from(k) * 32) {
|
||||||
Some(View::Constant(address, size)) => {
|
Some(View::Constant(address, size)) => {
|
||||||
let Some((buffer, gpu, to)) = list.scratch_held(u64::from(size)) else {
|
// Direct 256-byte-aligned in-place CBV fast path: when
|
||||||
|
// `VICTORY_PORT_CONSTANTS=1` already has the constant heap
|
||||||
|
// in place on the card and `gpu` is 256-byte aligned, bind
|
||||||
|
// directly with zero scratch alloc, zero `Step::Fill`, and
|
||||||
|
// zero CPU copy (`VICTORY_DIRECT_CBV=0` disables).
|
||||||
|
static DIRECT_CBV: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||||
|
if *DIRECT_CBV.get_or_init(|| std::env::var_os("VICTORY_DIRECT_CBV").is_none_or(|v| v != "0"))
|
||||||
|
&& crate::port::on()
|
||||||
|
&& let Some(shadow) = crate::shadow::find(address, u64::from(size)).filter(|s| s.in_place())
|
||||||
|
{
|
||||||
|
let gpu = shadow.gpu(address);
|
||||||
|
let aligned = u64::from(size).next_multiple_of(256);
|
||||||
|
if gpu.is_multiple_of(256) && shadow.left(address) >= aligned {
|
||||||
|
host.constant_at(index, &shadow.buffer, gpu, size);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let slot = (std::ptr::from_ref(heap) as usize, index);
|
||||||
|
let Some((buffer, gpu)) = list.constant_scratch(address as *const u8, size, slot) else {
|
||||||
host.make_null(index);
|
host.make_null(index);
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
let slot = (std::ptr::from_ref(heap) as usize, index);
|
|
||||||
list.defer_constants(to, address as *const u8, size as usize, slot);
|
|
||||||
host.constant_at(index, &buffer, gpu, size);
|
host.constant_at(index, &buffer, gpu, size);
|
||||||
}
|
}
|
||||||
Some(view) => {
|
Some(view) => {
|
||||||
|
|||||||
+573
-154
File diff suppressed because it is too large.
Load diff
@@ -225,6 +225,8 @@ pub(super) enum FillTo {
|
|||||||
/// A descriptor slot that shows the fill's memory, and nothing else does
|
/// A descriptor slot that shows the fill's memory, and nothing else does
|
||||||
/// (title heap, slot): it is made to show our buffer instead.
|
/// (title heap, slot): it is made to show our buffer instead.
|
||||||
Slot(usize, u32),
|
Slot(usize, u32),
|
||||||
|
/// Multiple deduplicated descriptor slots sharing the same fill.
|
||||||
|
Slots(Vec<(usize, u32)>),
|
||||||
/// A buffer the card can write, filled from its beginning.
|
/// A buffer the card can write, filled from its beginning.
|
||||||
Buffer(ID3D12Resource),
|
Buffer(ID3D12Resource),
|
||||||
}
|
}
|
||||||
@@ -370,45 +372,66 @@ fn plan(does: &[Does], stage: u32, by_order: bool, behind: &mut Option<(usize, u
|
|||||||
let mut taken = vec![false; does.len()];
|
let mut taken = vec![false; does.len()];
|
||||||
let (mut read, mut written) = (Vec::new(), Vec::new());
|
let (mut read, mut written) = (Vec::new(), Vec::new());
|
||||||
let mut more = Vec::new();
|
let mut more = Vec::new();
|
||||||
|
let (mut has_copy, mut has_placed) = (false, false);
|
||||||
for (i, d) in does.iter().enumerate() {
|
for (i, d) in does.iter().enumerate() {
|
||||||
match *d {
|
match *d {
|
||||||
Does::Run => return Err("a step of ours runs"),
|
Does::Run => return Err("a step of ours runs"),
|
||||||
Does::Read { asked: true, .. } => return Err("a texture reads it"),
|
Does::Read { asked: true, .. } => return Err("a texture reads it"),
|
||||||
Does::Copy { asked: true, .. } | Does::Fill { asked: true, .. } => more.push(i),
|
Does::Copy { asked, .. } => {
|
||||||
|
has_copy = true;
|
||||||
|
if asked {
|
||||||
|
more.push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Does::Fill { asked: true, .. } => more.push(i),
|
||||||
|
Does::Placed { .. } => has_placed = true,
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let mut taken_count = 0usize;
|
||||||
while !more.is_empty() {
|
while !more.is_empty() {
|
||||||
// (Joined once for the round: one by one the 2,800 fills of a frame
|
// (Joined once for the round: one by one the 2,800 fills of a frame
|
||||||
// sorted the ranges each time, 16 ms of the submitting thread.)
|
// sorted the ranges each time, 16 ms of the submitting thread.)
|
||||||
let (mut reads, mut writes) = (Vec::new(), Vec::new());
|
let (mut reads, mut writes) = (Vec::new(), Vec::new());
|
||||||
for i in std::mem::take(&mut more) {
|
for i in std::mem::take(&mut more) {
|
||||||
takes(&does[i])?;
|
takes(&does[i])?;
|
||||||
taken[i] = true;
|
if !taken[i] {
|
||||||
|
taken[i] = true;
|
||||||
|
taken_count += 1;
|
||||||
|
}
|
||||||
if let Some((r, w)) = reads_writes(&does[i]) {
|
if let Some((r, w)) = reads_writes(&does[i]) {
|
||||||
if w.0 < w.1 && meet(r, w) {
|
if w.0 < w.1 && meet(r, w) {
|
||||||
return Err("a copy onto itself");
|
return Err("a copy onto itself");
|
||||||
}
|
}
|
||||||
reads.push(r);
|
if has_copy || has_placed {
|
||||||
writes.push(w);
|
reads.push(r);
|
||||||
|
}
|
||||||
|
if w.0 < w.1 {
|
||||||
|
writes.push(w);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
join_ranges(&mut read, reads);
|
if !reads.is_empty() {
|
||||||
if writes.iter().any(|w| w.0 < w.1) {
|
join_ranges(&mut read, reads);
|
||||||
|
}
|
||||||
|
if !writes.is_empty() {
|
||||||
join_ranges(&mut written, writes);
|
join_ranges(&mut written, writes);
|
||||||
}
|
}
|
||||||
if taken.iter().filter(|t| **t).count() > MOST {
|
if taken_count > MOST {
|
||||||
return Err("too many steps depend on it");
|
return Err("too many steps depend on it");
|
||||||
}
|
}
|
||||||
for (i, d) in does.iter().enumerate() {
|
if !written.is_empty() || (has_copy && !read.is_empty()) {
|
||||||
// A fill that cannot be taken is looked at below.
|
for (i, d) in does.iter().enumerate() {
|
||||||
if taken[i] || matches!(d, Does::Fill { to: false, .. }) {
|
// A fill that cannot be taken is looked at below.
|
||||||
continue;
|
if taken[i] || matches!(d, Does::Fill { to: false, .. }) {
|
||||||
}
|
continue;
|
||||||
if let Some((r, w)) = reads_writes(d)
|
}
|
||||||
&& (touched(&written, r) || touched(&written, w) || touched(&read, w))
|
if let Some((r, w)) = reads_writes(d)
|
||||||
{
|
&& (touched(&written, r)
|
||||||
more.push(i);
|
|| (w.0 < w.1 && (touched(&written, w) || touched(&read, w))))
|
||||||
|
{
|
||||||
|
more.push(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -638,6 +661,8 @@ enum To {
|
|||||||
Copy(Arc<Shadow>, usize),
|
Copy(Arc<Shadow>, usize),
|
||||||
/// A descriptor slot (title heap, slot).
|
/// A descriptor slot (title heap, slot).
|
||||||
Slot(usize, u32),
|
Slot(usize, u32),
|
||||||
|
/// Multiple deduplicated descriptor slots sharing one fill.
|
||||||
|
Slots(Vec<(usize, u32)>),
|
||||||
/// A buffer's beginning.
|
/// A buffer's beginning.
|
||||||
Buffer(ID3D12Resource),
|
Buffer(ID3D12Resource),
|
||||||
}
|
}
|
||||||
@@ -879,6 +904,7 @@ impl Host {
|
|||||||
}
|
}
|
||||||
_ => match fill_to(runs, steps[i]) {
|
_ => match fill_to(runs, steps[i]) {
|
||||||
Some(FillTo::Slot(heap, index)) => To::Slot(heap, index),
|
Some(FillTo::Slot(heap, index)) => To::Slot(heap, index),
|
||||||
|
Some(FillTo::Slots(slots)) => To::Slots(slots),
|
||||||
Some(FillTo::Buffer(buffer)) => To::Buffer(buffer),
|
Some(FillTo::Buffer(buffer)) => To::Buffer(buffer),
|
||||||
None => continue,
|
None => continue,
|
||||||
},
|
},
|
||||||
@@ -936,7 +962,7 @@ impl Host {
|
|||||||
match &op.to {
|
match &op.to {
|
||||||
To::Copy(to, dst) => writes.push((&to.buffer, to.offset(*dst as u64), op.at, len)),
|
To::Copy(to, dst) => writes.push((&to.buffer, to.offset(*dst as u64), op.at, len)),
|
||||||
To::Buffer(buffer) => writes.push((buffer, 0, op.at, len)),
|
To::Buffer(buffer) => writes.push((buffer, 0, op.at, len)),
|
||||||
To::Slot(..) => {}
|
To::Slot(..) | To::Slots(..) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
record(level == 0, &own.list.list, &own.between, &reads, &writes);
|
record(level == 0, &own.list.list, &own.between, &reads, &writes);
|
||||||
@@ -951,11 +977,19 @@ impl Host {
|
|||||||
let parts = if ops.len() < 256 { 1 } else { 8 };
|
let parts = if ops.len() < 256 { 1 } else { 8 };
|
||||||
crate::land::each_under(parts, &|part| {
|
crate::land::each_under(parts, &|part| {
|
||||||
for op in &ops {
|
for op in &ops {
|
||||||
if let To::Slot(heap, index) = &op.to
|
match &op.to {
|
||||||
&& *index as usize / 4 % parts == part
|
To::Slot(heap, index) if *index as usize / 4 % parts == part => {
|
||||||
{
|
// (A heap that is gone: nothing can read the slot.)
|
||||||
// (A heap that is gone: nothing can read the slot.)
|
crate::descriptor::constant_slot(*heap, *index, &own.between, gpu + op.at, op.len as u32);
|
||||||
crate::descriptor::constant_slot(*heap, *index, &own.between, gpu + op.at, op.len as u32);
|
}
|
||||||
|
To::Slots(slots) => {
|
||||||
|
for &(heap, index) in slots {
|
||||||
|
if index as usize / 4 % parts == part {
|
||||||
|
crate::descriptor::constant_slot(heap, index, &own.between, gpu + op.at, op.len as u32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1002,7 +1036,7 @@ fn noted(ops: &[Op]) {
|
|||||||
for op in ops {
|
for op in ops {
|
||||||
let (to, dst) = match &op.to {
|
let (to, dst) = match &op.to {
|
||||||
To::Copy(to, dst) => (to.span(), *dst),
|
To::Copy(to, dst) => (to.span(), *dst),
|
||||||
To::Slot(..) | To::Buffer(_) => ((0, 0), 0),
|
To::Slot(..) | To::Slots(..) | To::Buffer(_) => ((0, 0), 0),
|
||||||
};
|
};
|
||||||
let e = noted.entry((op.len, op.from.0.span(), to)).or_default();
|
let e = noted.entry((op.len, op.from.0.span(), to)).or_default();
|
||||||
*e = (e.0 + 1, op.from.1, dst);
|
*e = (e.0 + 1, op.from.1, dst);
|
||||||
|
|||||||
@@ -102,6 +102,34 @@ const ABOUT_NO_DLSS: [&str; 3] = [
|
|||||||
"DOWNLOADED FROM NVIDIA ON GITHUB AT THE NEXT START",
|
"DOWNLOADED FROM NVIDIA ON GITHUB AT THE NEXT START",
|
||||||
"(ABOUT 70 MB, ONCE). SAVE AND RESTART NOW DOES IT.",
|
"(ABOUT 70 MB, ONCE). SAVE AND RESTART NOW DOES IT.",
|
||||||
];
|
];
|
||||||
|
/// Frame generation that this run did not start with: it is made ready only at a start with it
|
||||||
|
/// on (a start with it ready but off held some PCs at 14 fps, #515, #574), so turning it on takes
|
||||||
|
/// a restart; a run started with it on changes it, or turns it off, live.
|
||||||
|
const ABOUT_FRAMEGEN_RESTART: [&str; 3] = [
|
||||||
|
"RESTART REQUIRED TO ENABLE FRAME GENERATION: THIS RUN",
|
||||||
|
"STARTED WITHOUT IT. SAVE AND RESTART NOW TURNS IT ON.",
|
||||||
|
"AFTER THAT IT CHANGES, OR TURNS OFF, LIVE.",
|
||||||
|
];
|
||||||
|
const FRAMEGEN: &str = "VICTORY_MENU_FRAMEGEN";
|
||||||
|
/// The console, and the picture row of each: only the one of the console picked is shown.
|
||||||
|
const CONSOLE: &str = "VICTORY_MENU_CONSOLE";
|
||||||
|
const X_RES: &str = "VICTORY_MENU_RES";
|
||||||
|
const S_RES: &str = "VICTORY_MENU_S_RES";
|
||||||
|
/// The Series S scene sizes and the DLSS mode of each (the picture is 1920x1080). Only DLSS
|
||||||
|
/// changes it: the title's own FidelityFX path from 540 stopped it at the start (0xc0000094,
|
||||||
|
/// a division by zero in the title, 2026-11-28), so with DLSS off the scene stays at 720.
|
||||||
|
const S_MODES: [(&str, &str); 5] = [
|
||||||
|
("1080", "dlaa"),
|
||||||
|
("720", "quality"),
|
||||||
|
("626", "balanced"),
|
||||||
|
("540", "performance"),
|
||||||
|
("360", "ultraperformance"),
|
||||||
|
];
|
||||||
|
const ABOUT_S_RES: [&str; 3] = [
|
||||||
|
"THE SIZE THE GAME RENDERS AT. THE PICTURE IS 1920X1080.",
|
||||||
|
"OTHER THAN 720 NEEDS DLSS: THIS SETS ITS MODE (1080 IS",
|
||||||
|
"DLAA, 720 QUALITY, 626 BALANCED, 540 PERFORMANCE).",
|
||||||
|
];
|
||||||
/// The note after the first Enter on it: the second one does it.
|
/// The note after the first Enter on it: the second one does it.
|
||||||
const CONFIRM_PRELOAD: &str = "ENTER AGAIN: SAVE, CLOSE THE GAME AND PRELOAD";
|
const CONFIRM_PRELOAD: &str = "ENTER AGAIN: SAVE, CLOSE THE GAME AND PRELOAD";
|
||||||
/// The last line of the box: where this build comes from.
|
/// The last line of the box: where this build comes from.
|
||||||
@@ -126,7 +154,7 @@ const STAGES: &[(&str, &str)] = &[("2", "2"), ("1", "1"), ("0", "0 OFF")];
|
|||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
const ITEMS: &[Item] = &[
|
const ITEMS: &[Item] = &[
|
||||||
// The launcher's own choices.
|
// 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_DLSS", label: "DLSS", values: &[("quality", "QUALITY"), ("balanced", "BALANCED"), ("performance", "PERFORMANCE"), ("ultraperformance", "ULTRA PERF"), ("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_FRAMEGEN", label: "FRAME GENERATION", values: &[("0", "OFF"), ("2", "2X"), ("3", "3X"), ("4", "4X"), ("5", "5X"), ("6", "6X (MOST)")], live: false },
|
||||||
// DLSS Frame Generation where it runs (RTX 40 and later), else AMD's FSR 3 (2X only).
|
// DLSS Frame Generation where it runs (RTX 40 and later), else AMD's FSR 3 (2X only).
|
||||||
Item { var: "VICTORY_MENU_FG_TYPE", label: "FRAME GEN TYPE", values: &[("auto", "AUTO"), ("dlss", "DLSS"), ("fsr", "FSR 3 (OLDER CARDS)")], live: false },
|
Item { var: "VICTORY_MENU_FG_TYPE", label: "FRAME GEN TYPE", values: &[("auto", "AUTO"), ("dlss", "DLSS"), ("fsr", "FSR 3 (OLDER CARDS)")], live: false },
|
||||||
@@ -139,7 +167,9 @@ const ITEMS: &[Item] = &[
|
|||||||
Item { var: "VICTORY_MOUSE_CAPTURE", label: "MOUSE CAPTURE", values: UNSET_ON, live: false },
|
Item { var: "VICTORY_MOUSE_CAPTURE", label: "MOUSE CAPTURE", values: UNSET_ON, live: false },
|
||||||
Item { var: "VICTORY_IME_ENGLISH", label: "ENGLISH KEYBOARD", values: UNSET_ON, live: false },
|
Item { var: "VICTORY_IME_ENGLISH", label: "ENGLISH KEYBOARD", values: UNSET_ON, live: false },
|
||||||
Item { var: "VICTORY_MENU_CONSOLE", label: "CONSOLE", values: &[("series-x", "SERIES X"), ("series-s", "SERIES S (FASTER)")], live: false },
|
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 },
|
Item { var: X_RES, label: "SERIES X PICTURE", values: &[("1440", "2560X1440"), ("1080to1440", "1080P TO 1440P"), ("4k", "3840X2160")], live: false },
|
||||||
|
// In place of SERIES X PICTURE when CONSOLE is Series S.
|
||||||
|
Item { var: S_RES, label: "SERIES S PICTURE", values: &[("1080", "1920X1080 (DLAA)"), ("720", "1280X720 (THE GAME)"), ("626", "1113X626"), ("540", "960X540 (FASTEST)"), ("360", "640X360 (ULTRA FAST)")], live: false },
|
||||||
// The layer's switches.
|
// 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_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", label: "LIGHT ESTIMATE", values: &[("0.8", "0.8"), ("1", "1"), ("0.5", "0.5"), ("", "OFF")], live: false },
|
||||||
@@ -149,6 +179,8 @@ const ITEMS: &[Item] = &[
|
|||||||
// On unless "0": a file saved by an earlier version holds an empty value (its OFF) or "1",
|
// On unless "0": a file saved by an earlier version holds an empty value (its OFF) or "1",
|
||||||
// and both start it on, so nobody keeps it off from before by accident (2026-11-27).
|
// and both start it on, so nobody keeps it off from before by accident (2026-11-27).
|
||||||
Item { var: "VICTORY_WATER_LIGHT", label: "WATER LIGHT", values: &[("", "ON"), ("0", "OFF")], live: false },
|
Item { var: "VICTORY_WATER_LIGHT", label: "WATER LIGHT", values: &[("", "ON"), ("0", "OFF")], live: false },
|
||||||
|
Item { var: "VICTORY_OUTPUT", label: "OUTPUT SIZE (WINDOW)", values: &[("", "1080P (DEFAULT)"), ("1664x936", "936P"), ("1280x720", "720P (FASTEST)")], live: false },
|
||||||
|
Item { var: "VICTORY_TEXTURE_DROP_MIPS", label: "TEXTURE SCALE (VRAM)", values: &[("", "FULL"), ("1", "HALF (6GB GPU)"), ("2", "QUARTER (4GB GPU)")], 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_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_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_WC_NO_BACK", label: "SKIP BIG COPY-BACKS", values: ON_UNSET, live: false },
|
||||||
@@ -474,18 +506,46 @@ impl Menu {
|
|||||||
crate::SETTINGS_MENU_OPEN.load(Ordering::Relaxed)
|
crate::SETTINGS_MENU_OPEN.load(Ordering::Relaxed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The value of the setting `var` as the menu holds it now.
|
||||||
|
fn value(&self, var: &str) -> &str {
|
||||||
|
ITEMS.iter().position(|i| i.var == var).map_or("", |i| self.values[i].as_str())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Row `row` is left out: the picture row of the console not picked.
|
||||||
|
fn hidden(&self, row: usize) -> bool {
|
||||||
|
let series_s = self.value(CONSOLE) == "series-s";
|
||||||
|
ITEMS.get(row).is_some_and(|i| if series_s { i.var == X_RES } else { i.var == S_RES })
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The rows shown, settings then actions.
|
||||||
|
fn rows(&self) -> Vec<usize> {
|
||||||
|
(0..ITEMS.len() + ACTIONS.len()).filter(|r| !self.hidden(*r)).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The row shown `step` (+1 / -1) from the one picked, round the ends.
|
||||||
|
fn step(&self, step: isize) -> usize {
|
||||||
|
let rows = self.rows();
|
||||||
|
let n = rows.len() as isize;
|
||||||
|
match rows.iter().position(|r| *r == self.at) {
|
||||||
|
Some(p) => rows[(p as isize + step).rem_euclid(n) as usize],
|
||||||
|
None => rows.iter().copied().find(|r| *r > self.at).unwrap_or(rows[0]),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn lines(&self) -> Vec<String> {
|
fn lines(&self) -> Vec<String> {
|
||||||
if self.picking {
|
if self.picking {
|
||||||
return self.pick_lines();
|
return self.pick_lines();
|
||||||
}
|
}
|
||||||
let total = ITEMS.len() + ACTIONS.len();
|
let rows = self.rows();
|
||||||
let first = self.at.saturating_sub(ROWS / 2).min(total.saturating_sub(ROWS));
|
let total = rows.len();
|
||||||
|
let at = rows.iter().position(|r| *r == self.at).unwrap_or(0);
|
||||||
|
let first = at.saturating_sub(ROWS / 2).min(total.saturating_sub(ROWS));
|
||||||
let mut out = vec![
|
let mut out = vec![
|
||||||
"SETTINGS F1 OR ESC CLOSES".to_owned(),
|
"SETTINGS F1 OR ESC CLOSES".to_owned(),
|
||||||
"UP/DOWN PICK LEFT/RIGHT CHANGE ENTER DOES IT".to_owned(),
|
"UP/DOWN PICK LEFT/RIGHT CHANGE ENTER DOES IT".to_owned(),
|
||||||
String::new(),
|
String::new(),
|
||||||
];
|
];
|
||||||
for row in first..(first + ROWS).min(total) {
|
for &row in &rows[first..(first + ROWS).min(total)] {
|
||||||
let cursor = if row == self.at { '>' } else { ' ' };
|
let cursor = if row == self.at { '>' } else { ' ' };
|
||||||
let line = if let Some(item) = ITEMS.get(row) {
|
let line = if let Some(item) = ITEMS.get(row) {
|
||||||
let value = &self.values[row];
|
let value = &self.values[row];
|
||||||
@@ -509,11 +569,17 @@ impl Menu {
|
|||||||
ABOUT_IMPORT
|
ABOUT_IMPORT
|
||||||
} else if ITEMS.get(self.at).is_some_and(|i| i.var == MFG) {
|
} else if ITEMS.get(self.at).is_some_and(|i| i.var == MFG) {
|
||||||
ABOUT_MFG
|
ABOUT_MFG
|
||||||
|
} else if ITEMS.get(self.at).is_some_and(|i| i.var == S_RES) {
|
||||||
|
ABOUT_S_RES
|
||||||
} else if ITEMS.get(self.at).is_some_and(|i| i.var == DLSS)
|
} else if ITEMS.get(self.at).is_some_and(|i| i.var == DLSS)
|
||||||
&& !matches!(self.values[self.at].as_str(), "" | "off")
|
&& !matches!(self.values[self.at].as_str(), "" | "off")
|
||||||
&& std::env::var_os("VICTORY_STREAMLINE_DIR").is_none()
|
&& std::env::var_os("VICTORY_STREAMLINE_DIR").is_none()
|
||||||
{
|
{
|
||||||
ABOUT_NO_DLSS
|
ABOUT_NO_DLSS
|
||||||
|
} else if ITEMS.get(self.at).is_some_and(|i| i.var == FRAMEGEN && !live(i))
|
||||||
|
&& !matches!(self.values[self.at].as_str(), "" | "0")
|
||||||
|
{
|
||||||
|
ABOUT_FRAMEGEN_RESTART
|
||||||
} else {
|
} else {
|
||||||
[""; 3]
|
[""; 3]
|
||||||
};
|
};
|
||||||
@@ -558,6 +624,31 @@ impl Menu {
|
|||||||
self.apply_live(i);
|
self.apply_live(i);
|
||||||
}
|
}
|
||||||
self.note.clear();
|
self.note.clear();
|
||||||
|
if item.var == FRAMEGEN && !live(item) && !matches!(self.values[i].as_str(), "" | "0") {
|
||||||
|
"RESTART REQUIRED TO ENABLE FRAME GENERATION".clone_into(&mut self.note);
|
||||||
|
}
|
||||||
|
self.match_series_s(item.var);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// On Series S the scene's size and DLSS's mode are one choice: a change of either
|
||||||
|
/// (`changed`) sets the other. DLSS off is the game's 720, and 720 picked leaves it off.
|
||||||
|
fn match_series_s(&mut self, changed: &str) {
|
||||||
|
let (Some(dlss), Some(res)) = (ITEMS.iter().position(|i| i.var == DLSS), ITEMS.iter().position(|i| i.var == S_RES)) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
if self.value(CONSOLE) != "series-s" {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let off = matches!(self.values[dlss].as_str(), "" | "off");
|
||||||
|
if changed == DLSS {
|
||||||
|
let size = S_MODES.iter().find(|(_, m)| *m == self.values[dlss]).map_or("720", |(s, _)| *s);
|
||||||
|
size.clone_into(&mut self.values[res]);
|
||||||
|
} else if changed == S_RES
|
||||||
|
&& !(off && self.values[res] == "720")
|
||||||
|
&& let Some((_, mode)) = S_MODES.iter().find(|(s, _)| *s == self.values[res])
|
||||||
|
{
|
||||||
|
(*mode).clone_into(&mut self.values[dlss]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A setting the build reads at each use: changed in this run's environment at once.
|
/// A setting the build reads at each use: changed in this run's environment at once.
|
||||||
@@ -788,7 +879,6 @@ impl Menu {
|
|||||||
if pressed.is_empty() {
|
if pressed.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let total = ITEMS.len() + ACTIONS.len();
|
|
||||||
for vk in pressed {
|
for vk in pressed {
|
||||||
let open = Self::open();
|
let open = Self::open();
|
||||||
// Esc in the list of saves goes back to the settings.
|
// Esc in the list of saves goes back to the settings.
|
||||||
@@ -830,8 +920,8 @@ impl Menu {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
match vk {
|
match vk {
|
||||||
VK_UP => self.at = (self.at + total - 1) % total,
|
VK_UP => self.at = self.step(-1),
|
||||||
VK_DOWN => self.at = (self.at + 1) % total,
|
VK_DOWN => self.at = self.step(1),
|
||||||
VK_LEFT if self.at < ITEMS.len() => self.change_and_save(self.at, -1),
|
VK_LEFT if self.at < ITEMS.len() => self.change_and_save(self.at, -1),
|
||||||
VK_RIGHT if self.at < ITEMS.len() => self.change_and_save(self.at, 1),
|
VK_RIGHT if self.at < ITEMS.len() => self.change_and_save(self.at, 1),
|
||||||
VK_RETURN if self.at < ITEMS.len() => self.change_and_save(self.at, 1),
|
VK_RETURN if self.at < ITEMS.len() => self.change_and_save(self.at, 1),
|
||||||
@@ -1013,6 +1103,8 @@ mod tests {
|
|||||||
assert_eq!(about, ABOUT_IMPORT);
|
assert_eq!(about, ABOUT_IMPORT);
|
||||||
} else if at < ITEMS.len() && ITEMS[at].var == MFG {
|
} else if at < ITEMS.len() && ITEMS[at].var == MFG {
|
||||||
assert_eq!(about, ABOUT_MFG);
|
assert_eq!(about, ABOUT_MFG);
|
||||||
|
} else if at < ITEMS.len() && ITEMS[at].var == S_RES {
|
||||||
|
assert_eq!(about, ABOUT_S_RES);
|
||||||
} else {
|
} else {
|
||||||
assert!(about.iter().all(String::is_empty), "{about:?}");
|
assert!(about.iter().all(String::is_empty), "{about:?}");
|
||||||
}
|
}
|
||||||
@@ -1041,6 +1133,67 @@ mod tests {
|
|||||||
let lines = menu.lines();
|
let lines = menu.lines();
|
||||||
assert!(lines[lines.len() - 5..lines.len() - 2].iter().all(String::is_empty));
|
assert!(lines[lines.len() - 5..lines.len() - 2].iter().all(String::is_empty));
|
||||||
assert_eq!(ITEMS.iter().filter(|i| i.var == MFG).count(), 1);
|
assert_eq!(ITEMS.iter().filter(|i| i.var == MFG).count(), 1);
|
||||||
|
// Frame generation turned on in a run started without it (no Streamline in tests): a
|
||||||
|
// restart is required, and the menu says so; OFF needs no word.
|
||||||
|
for line in ABOUT_FRAMEGEN_RESTART {
|
||||||
|
assert!(line.len() <= COLUMNS as usize && line.bytes().all(|c| glyph(c) != glyph(b'#')), "{line}");
|
||||||
|
}
|
||||||
|
let fg = ITEMS.iter().position(|i| i.var == FRAMEGEN).expect("in the menu");
|
||||||
|
menu.at = fg;
|
||||||
|
menu.values[fg] = "0".to_owned();
|
||||||
|
menu.change(fg, 1);
|
||||||
|
assert_eq!(menu.values[fg], "2");
|
||||||
|
assert_eq!(menu.note, "RESTART REQUIRED TO ENABLE FRAME GENERATION");
|
||||||
|
let lines = menu.lines();
|
||||||
|
assert_eq!(&lines[lines.len() - 5..lines.len() - 2], ABOUT_FRAMEGEN_RESTART);
|
||||||
|
menu.change(fg, -1);
|
||||||
|
assert!(menu.note.is_empty());
|
||||||
|
let lines = menu.lines();
|
||||||
|
assert!(lines[lines.len() - 5..lines.len() - 2].iter().all(String::is_empty));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_picture_line_is_the_consoles() {
|
||||||
|
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, imports: Vec::new(), import_at: 0, picking: false };
|
||||||
|
menu.started = menu.values.clone();
|
||||||
|
let at = |var: &str| ITEMS.iter().position(|i| i.var == var).expect("in the menu");
|
||||||
|
let (console, x, s, dlss) = (at(CONSOLE), at(X_RES), at(S_RES), at(DLSS));
|
||||||
|
let shown = |menu: &Menu, label: &str| menu.lines().iter().any(|l| l.contains(label));
|
||||||
|
"series-x".clone_into(&mut menu.values[console]);
|
||||||
|
assert!(shown(&menu, "SERIES X PICTURE") && !shown(&menu, "SERIES S PICTURE"));
|
||||||
|
// down from the console: the Series X line, never the hidden one
|
||||||
|
menu.at = console;
|
||||||
|
assert_eq!(menu.step(1), x);
|
||||||
|
assert!(!menu.rows().contains(&s));
|
||||||
|
"series-s".clone_into(&mut menu.values[console]);
|
||||||
|
assert!(shown(&menu, "SERIES S PICTURE") && !shown(&menu, "SERIES X PICTURE"));
|
||||||
|
assert_eq!(menu.step(1), s);
|
||||||
|
assert_eq!(menu.step(-1), console - 1);
|
||||||
|
// the size and DLSS's mode follow each other on Series S
|
||||||
|
"quality".clone_into(&mut menu.values[dlss]);
|
||||||
|
"720".clone_into(&mut menu.values[s]);
|
||||||
|
menu.change(s, 1);
|
||||||
|
assert_eq!((menu.values[s].as_str(), menu.values[dlss].as_str()), ("626", "balanced"));
|
||||||
|
menu.change(s, 1);
|
||||||
|
assert_eq!((menu.values[s].as_str(), menu.values[dlss].as_str()), ("540", "performance"));
|
||||||
|
menu.change(dlss, -2);
|
||||||
|
assert_eq!((menu.values[s].as_str(), menu.values[dlss].as_str()), ("720", "quality"));
|
||||||
|
// DLSS off is 720, and 720 leaves it off; another size turns DLSS on at its mode
|
||||||
|
menu.change(dlss, -1);
|
||||||
|
assert_eq!((menu.values[s].as_str(), menu.values[dlss].as_str()), ("720", "off"));
|
||||||
|
menu.change(s, -1);
|
||||||
|
assert_eq!((menu.values[s].as_str(), menu.values[dlss].as_str()), ("1080", "dlaa"));
|
||||||
|
"off".clone_into(&mut menu.values[dlss]);
|
||||||
|
"626".clone_into(&mut menu.values[s]);
|
||||||
|
menu.change(s, -1);
|
||||||
|
assert_eq!((menu.values[s].as_str(), menu.values[dlss].as_str()), ("720", "off"));
|
||||||
|
menu.change(s, 2);
|
||||||
|
assert_eq!((menu.values[s].as_str(), menu.values[dlss].as_str()), ("540", "performance"));
|
||||||
|
menu.at = s;
|
||||||
|
assert_eq!(&menu.lines()[menu.lines().len() - 5..menu.lines().len() - 2], ABOUT_S_RES);
|
||||||
|
for line in ABOUT_S_RES {
|
||||||
|
assert!(line.len() <= COLUMNS as usize && line.bytes().all(|b| glyph(b) != glyph(b'#') || b == b'#'), "{line}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ const SHORT: usize = 256;
|
|||||||
|
|
||||||
/// Whether a run of `len` bytes at offset `at` of a copy goes as pairs.
|
/// Whether a run of `len` bytes at offset `at` of a copy goes as pairs.
|
||||||
fn short(at: usize, len: usize) -> bool {
|
fn short(at: usize, len: usize) -> bool {
|
||||||
len <= SHORT && at % 4 == 0 && len % 4 == 0
|
len <= SHORT && at.is_multiple_of(4) && len.is_multiple_of(4)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether a run of `len` bytes at offset `at` of a copy in the card's memory
|
/// Whether a run of `len` bytes at offset `at` of a copy in the card's memory
|
||||||
@@ -119,8 +119,16 @@ unsafe impl Send for Memory {}
|
|||||||
static SPARE: Mutex<Vec<Memory>> = Mutex::new(Vec::new());
|
static SPARE: Mutex<Vec<Memory>> = Mutex::new(Vec::new());
|
||||||
|
|
||||||
/// At most this much is kept (of the card's memory, with [`on_card`]).
|
/// At most this much is kept (of the card's memory, with [`on_card`]).
|
||||||
|
/// On hosts with <= 32 GiB RAM, cap the idle upload pool at 256 MiB (instead
|
||||||
|
/// of 768 MiB) so streaming bursts have more commit headroom.
|
||||||
fn kept() -> u64 {
|
fn kept() -> u64 {
|
||||||
if on_card() { 256 << 20 } else { 768 << 20 }
|
if crate::residency::tight_host_ram() {
|
||||||
|
128 << 20
|
||||||
|
} else if on_card() || crate::residency::limited_host_ram() {
|
||||||
|
256 << 20
|
||||||
|
} else {
|
||||||
|
768 << 20
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the memory lies in the card's memory, written by the CPU through
|
/// Whether the memory lies in the card's memory, written by the CPU through
|
||||||
@@ -164,9 +172,35 @@ pub(super) fn give_back(memory: Memory) {
|
|||||||
let mut spare = SPARE.lock().unwrap_or_else(|e| e.into_inner());
|
let mut spare = SPARE.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
spare.push(memory);
|
spare.push(memory);
|
||||||
spare.sort_by_key(|m| std::cmp::Reverse(m.size));
|
spare.sort_by_key(|m| std::cmp::Reverse(m.size));
|
||||||
|
let mut freed = Vec::new();
|
||||||
while spare.iter().map(|m| m.size).sum::<u64>() > kept() {
|
while spare.iter().map(|m| m.size).sum::<u64>() > kept() {
|
||||||
spare.remove(0);
|
freed.push(spare.remove(0));
|
||||||
}
|
}
|
||||||
|
drop(spare);
|
||||||
|
drop(freed);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Drops excess idle submission upload buffers during critical host commit
|
||||||
|
/// pressure, keeping up to two small buffers (<= 32 MiB).
|
||||||
|
pub(super) fn trim_spare() {
|
||||||
|
let freed: Vec<Memory> = {
|
||||||
|
let mut spare = SPARE.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
if spare.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
spare.sort_by_key(|m| m.size);
|
||||||
|
let mut kept_bytes = 0u64;
|
||||||
|
let mut keep = 0usize;
|
||||||
|
for m in spare.iter().take(2) {
|
||||||
|
if kept_bytes + m.size > 32 << 20 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
kept_bytes += m.size;
|
||||||
|
keep += 1;
|
||||||
|
}
|
||||||
|
spare.split_off(keep)
|
||||||
|
};
|
||||||
|
drop(freed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Since the last frame-rate line: bytes copied, runs copied, words stored,
|
/// Since the last frame-rate line: bytes copied, runs copied, words stored,
|
||||||
@@ -187,7 +221,7 @@ pub(super) struct Own {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Runs whose pairs are one piece of work.
|
/// Runs whose pairs are one piece of work.
|
||||||
const RUNS_AT_A_TIME: usize = 4096;
|
const RUNS_AT_A_TIME: usize = 512;
|
||||||
|
|
||||||
/// Takes what `dirty` sends up out of the CPU sides.
|
/// Takes what `dirty` sends up out of the CPU sides.
|
||||||
pub(super) fn take(host: &Host, dirty: &[(std::sync::Arc<Shadow>, Vec<(usize, usize)>)]) -> Option<Own> {
|
pub(super) fn take(host: &Host, dirty: &[(std::sync::Arc<Shadow>, Vec<(usize, usize)>)]) -> Option<Own> {
|
||||||
@@ -195,42 +229,58 @@ pub(super) fn take(host: &Host, dirty: &[(std::sync::Arc<Shadow>, Vec<(usize, us
|
|||||||
pass(host)?;
|
pass(host)?;
|
||||||
// Runs of whole words of the copy: only those are pairs. (A byte beside
|
// Runs of whole words of the copy: only those are pairs. (A byte beside
|
||||||
// them in a word may be the card's.)
|
// them in a word may be the card's.)
|
||||||
let short = |&(a, b): &(usize, usize)| short(a, b - a);
|
let is_short = |&(a, b): &(usize, usize)| short(a, b - a);
|
||||||
let mut at = 0u64;
|
let mut at = 0u64;
|
||||||
let mut copies = Vec::with_capacity(dirty.len());
|
let mut copies = Vec::with_capacity(dirty.len());
|
||||||
for (_, ranges) in dirty {
|
let mut word_chunks: Vec<(usize, &[(usize, usize)], u64)> = Vec::new();
|
||||||
|
let mut run_bytes = 0u64;
|
||||||
|
let mut run_count = 0u64;
|
||||||
|
let mut total_words = 0u64;
|
||||||
|
for (shadow, ranges) in dirty {
|
||||||
let mut runs = Vec::new();
|
let mut runs = Vec::new();
|
||||||
for &(a, b) in ranges.iter().filter(|r| !short(r)) {
|
let mut words = 0usize;
|
||||||
runs.push((a, at, b - a));
|
let from = shadow.card_data() as usize;
|
||||||
at += ((b - a) as u64).next_multiple_of(16);
|
let chunk_start = word_chunks.len();
|
||||||
|
for chunk in ranges.chunks(RUNS_AT_A_TIME) {
|
||||||
|
let mut chunk_words = 0usize;
|
||||||
|
for &(a, b) in chunk {
|
||||||
|
let len = b - a;
|
||||||
|
if short(a, len) {
|
||||||
|
chunk_words += len / 4;
|
||||||
|
} else {
|
||||||
|
runs.push((a, at, len));
|
||||||
|
at += (len as u64).next_multiple_of(16);
|
||||||
|
run_bytes += len as u64;
|
||||||
|
run_count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if chunk_words > 0 {
|
||||||
|
word_chunks.push((from, chunk, words as u64));
|
||||||
|
words += chunk_words;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let words: usize = ranges.iter().filter(|r| short(r)).map(|r| (r.1 - r.0) / 4).sum();
|
let pairs_at = at;
|
||||||
copies.push(Copy { runs, pairs: (at, words as u32) });
|
for entry in &mut word_chunks[chunk_start..] {
|
||||||
|
entry.2 = pairs_at + entry.2 * 8;
|
||||||
|
}
|
||||||
|
copies.push(Copy { runs, pairs: (pairs_at, words as u32) });
|
||||||
|
total_words += words as u64;
|
||||||
at += (words as u64 * 8).next_multiple_of(16);
|
at += (words as u64 * 8).next_multiple_of(16);
|
||||||
}
|
}
|
||||||
if at == 0 {
|
if at == 0 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let memory = memory(host, at)?;
|
let memory = memory(host, at)?;
|
||||||
let mut moves: Vec<(usize, usize, usize)> = Vec::new();
|
let mut moves: Vec<(usize, usize, usize)> = Vec::with_capacity(run_count as usize);
|
||||||
let mut work: Vec<(usize, &[(usize, usize)], usize)> = Vec::new();
|
for ((shadow, _), copy) in dirty.iter().zip(&copies) {
|
||||||
for ((shadow, ranges), copy) in dirty.iter().zip(&copies) {
|
|
||||||
let from = shadow.card_data() as usize;
|
let from = shadow.card_data() as usize;
|
||||||
moves.extend(copy.runs.iter().map(|&(a, to, n)| (from + a, memory.data + to as usize, n)));
|
moves.extend(copy.runs.iter().map(|&(a, to, n)| (from + a, memory.data + to as usize, n)));
|
||||||
// (80,000 runs of some words a frame: in pieces of work.)
|
|
||||||
let mut to = memory.data + copy.pairs.0 as usize;
|
|
||||||
for ranges in ranges.chunks(RUNS_AT_A_TIME) {
|
|
||||||
let words: usize = ranges.iter().filter(|r| short(r)).map(|r| (r.1 - r.0) / 4).sum();
|
|
||||||
if words > 0 {
|
|
||||||
work.push((from, ranges, to));
|
|
||||||
to += words * 8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
let mem_data = memory.data;
|
||||||
let one = |i: usize| {
|
let one = |i: usize| {
|
||||||
let (from, ranges, to) = work[i];
|
let (from, ranges, rel_to) = word_chunks[i];
|
||||||
let mut to = to as *mut [u32; 2];
|
let mut to = (mem_data + rel_to as usize) as *mut [u32; 2];
|
||||||
for &(a, b) in ranges.iter().filter(|r| short(r)) {
|
for &(a, b) in ranges.iter().filter(|r| is_short(r)) {
|
||||||
for offset in (a..b).step_by(4) {
|
for offset in (a..b).step_by(4) {
|
||||||
// SAFETY: inside the copy's mapping (its CPU side, which
|
// SAFETY: inside the copy's mapping (its CPU side, which
|
||||||
// the thread that asked, and waits, alone writes in these
|
// the thread that asked, and waits, alone writes in these
|
||||||
@@ -244,15 +294,20 @@ pub(super) fn take(host: &Host, dirty: &[(std::sync::Arc<Shadow>, Vec<(usize, us
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
crate::land::each_under(work.len(), &one);
|
crate::land::each_under(work_len(&word_chunks), &one);
|
||||||
STATS[0].fetch_add(moves.iter().map(|m| m.2 as u64).sum(), Ordering::Relaxed);
|
STATS[0].fetch_add(run_bytes, Ordering::Relaxed);
|
||||||
STATS[1].fetch_add(moves.len() as u64, Ordering::Relaxed);
|
STATS[1].fetch_add(run_count, Ordering::Relaxed);
|
||||||
STATS[2].fetch_add(copies.iter().map(|c| u64::from(c.pairs.1)).sum(), Ordering::Relaxed);
|
STATS[2].fetch_add(total_words, Ordering::Relaxed);
|
||||||
crate::shadow::copy_all(moves);
|
crate::shadow::copy_all(moves);
|
||||||
STATS[3].fetch_add(began.elapsed().as_micros() as u64, Ordering::Relaxed);
|
STATS[3].fetch_add(began.elapsed().as_micros() as u64, Ordering::Relaxed);
|
||||||
Some(Own { memory, copies })
|
Some(Own { memory, copies })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn work_len<T>(chunks: &[T]) -> usize {
|
||||||
|
chunks.len()
|
||||||
|
}
|
||||||
|
|
||||||
impl Own {
|
impl Own {
|
||||||
/// Records the sends into `list`; the copies that `looked` says are in
|
/// Records the sends into `list`; the copies that `looked` says are in
|
||||||
/// `COPY_DEST`, the others in the common state. Those with a "before" are
|
/// `COPY_DEST`, the others in the common state. Those with a "before" are
|
||||||
@@ -283,7 +338,7 @@ impl Own {
|
|||||||
}
|
}
|
||||||
state = Some(write);
|
state = Some(write);
|
||||||
}
|
}
|
||||||
let hashed = shadow.card_sides().is_some_and(|(_, before, _)| before.is_some());
|
let hashed = shadow.has_card_before();
|
||||||
if let Some(was) = state
|
if let Some(was) = state
|
||||||
&& hashed
|
&& hashed
|
||||||
&& (!copy.runs.is_empty() || copy.pairs.1 > 0)
|
&& (!copy.runs.is_empty() || copy.pairs.1 > 0)
|
||||||
|
|||||||
@@ -305,8 +305,6 @@ fn rest() -> u32 {
|
|||||||
/// The clamp compiled from `source` (ours, or in the benchmark the one it
|
/// The clamp compiled from `source` (ours, or in the benchmark the one it
|
||||||
/// replaced).
|
/// replaced).
|
||||||
fn make_from(device: &ID3D12Device, source: &str) -> windows::core::Result<Clamp> {
|
fn make_from(device: &ID3D12Device, source: &str) -> windows::core::Result<Clamp> {
|
||||||
#[cfg(feature = "diagnostics")]
|
|
||||||
let batched = source == batch::SOURCE;
|
|
||||||
let source = &format!("#define WIDEST {}u\n#define REST {}\n{source}", widest(amd(device)), rest());
|
let source = &format!("#define WIDEST {}u\n#define REST {}\n{source}", widest(amd(device)), rest());
|
||||||
let mut code: Option<ID3DBlob> = None;
|
let mut code: Option<ID3DBlob> = None;
|
||||||
let mut errors: Option<ID3DBlob> = None;
|
let mut errors: Option<ID3DBlob> = None;
|
||||||
@@ -2697,7 +2695,10 @@ void main(uint3 g : SV_GroupID, uint i : SV_GroupIndex) {
|
|||||||
}
|
}
|
||||||
sig.unwrap()
|
sig.unwrap()
|
||||||
};
|
};
|
||||||
// Three records of 65,535 x 16 groups: about half the budget each.
|
// Two records of 65,535 x 16 groups (64 threads each, 2^26 - 2,048
|
||||||
|
// threads), then one of 32 groups (2,048 threads): together exactly
|
||||||
|
// the budget, so the small record after them does not fit whether
|
||||||
|
// or not a record that does not fit takes the rest (`rest`).
|
||||||
let Some((big, big_ptr)) = host.shared_buffer(3 * u64::from(STRIDE)) else {
|
let Some((big, big_ptr)) = host.shared_buffer(3 * u64::from(STRIDE)) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@@ -2710,7 +2711,7 @@ void main(uint3 g : SV_GroupID, uint i : SV_GroupIndex) {
|
|||||||
// SAFETY: mapped buffers of these sizes; nothing runs yet.
|
// SAFETY: mapped buffers of these sizes; nothing runs yet.
|
||||||
unsafe {
|
unsafe {
|
||||||
for i in 0..3 {
|
for i in 0..3 {
|
||||||
let words = [65535u32, 16, 1];
|
let words = if i < 2 { [65535u32, 16, 1] } else { [32, 1, 1] };
|
||||||
std::ptr::copy_nonoverlapping(
|
std::ptr::copy_nonoverlapping(
|
||||||
words.as_ptr().cast::<u8>(),
|
words.as_ptr().cast::<u8>(),
|
||||||
big_ptr.add(i * STRIDE as usize),
|
big_ptr.add(i * STRIDE as usize),
|
||||||
@@ -3193,7 +3194,20 @@ void main(uint3 group : SV_GroupID, uint3 thread : SV_DispatchThreadID) {
|
|||||||
};
|
};
|
||||||
assert_eq!(out.iter().filter(|&&v| v == 1 << 22).count(), filled, "{times} times {records}: {out:?}");
|
assert_eq!(out.iter().filter(|&&v| v == 1 << 22).count(), filled, "{times} times {records}: {out:?}");
|
||||||
assert!(out.iter().all(|&v| v == 0 || v == 1 << 22));
|
assert!(out.iter().all(|&v| v == 0 || v == 1 << 22));
|
||||||
assert_eq!(spent, BUDGET.min((1 << 26) * times * records as u32));
|
// Each record's job charges 2^26 for every execution, in order:
|
||||||
|
// one that does not fit takes the rest with `REST`, else nothing.
|
||||||
|
let rest = super::rest() != 0;
|
||||||
|
let expected = (0..records).fold(0u32, |at, _| {
|
||||||
|
let cost = (1u32 << 26) * times;
|
||||||
|
if BUDGET - at >= cost {
|
||||||
|
at + cost
|
||||||
|
} else if rest {
|
||||||
|
BUDGET
|
||||||
|
} else {
|
||||||
|
at
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert_eq!(spent, expected, "{times} times {records}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3530,7 +3544,6 @@ void work() {
|
|||||||
heap_pairs: [[Option<ID3D12DescriptorHeap>; 2]; 2],
|
heap_pairs: [[Option<ID3D12DescriptorHeap>; 2]; 2],
|
||||||
tables: [D3D12_GPU_DESCRIPTOR_HANDLE; 2],
|
tables: [D3D12_GPU_DESCRIPTOR_HANDLE; 2],
|
||||||
targets: [D3D12_CPU_DESCRIPTOR_HANDLE; 2],
|
targets: [D3D12_CPU_DESCRIPTOR_HANDLE; 2],
|
||||||
depth_written: D3D12_CPU_DESCRIPTOR_HANDLE,
|
|
||||||
depth_tested: D3D12_CPU_DESCRIPTOR_HANDLE,
|
depth_tested: D3D12_CPU_DESCRIPTOR_HANDLE,
|
||||||
stamps: ID3D12QueryHeap,
|
stamps: ID3D12QueryHeap,
|
||||||
back: ID3D12Resource,
|
back: ID3D12Resource,
|
||||||
@@ -3877,7 +3890,6 @@ void work() {
|
|||||||
heap_pairs,
|
heap_pairs,
|
||||||
tables,
|
tables,
|
||||||
targets,
|
targets,
|
||||||
depth_written,
|
|
||||||
depth_tested,
|
depth_tested,
|
||||||
stamps,
|
stamps,
|
||||||
back,
|
back,
|
||||||
|
|||||||
@@ -572,6 +572,7 @@ pub(crate) unsafe fn piece(
|
|||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// [`piece`]'s.
|
/// [`piece`]'s.
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
unsafe fn piece_at(
|
unsafe fn piece_at(
|
||||||
title: usize,
|
title: usize,
|
||||||
now: *const u8,
|
now: *const u8,
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ fn landings_beside_the_title_and_its_refreshes_lose_nothing() {
|
|||||||
while !stop.load(Ordering::Relaxed) {
|
while !stop.load(Ordering::Relaxed) {
|
||||||
// Its own dwords, in every other block (in the rest
|
// Its own dwords, in every other block (in the rest
|
||||||
// only landings change anything).
|
// only landings change anything).
|
||||||
for i in (w..LEN / 4).step_by(4 * 97).filter(|i| i * 4 / BLOCK % 2 == 0) {
|
for i in (w..LEN / 4).step_by(4 * 97).filter(|i| (i * 4 / BLOCK).is_multiple_of(2)) {
|
||||||
assert_eq!(dword(i).swap(value, Ordering::Relaxed), value - 1, "dword {i}: undone");
|
assert_eq!(dword(i).swap(value, Ordering::Relaxed), value - 1, "dword {i}: undone");
|
||||||
}
|
}
|
||||||
value += 1;
|
value += 1;
|
||||||
@@ -343,7 +343,7 @@ fn landings_beside_the_title_and_its_refreshes_lose_nothing() {
|
|||||||
stop.store(true, Ordering::Relaxed);
|
stop.store(true, Ordering::Relaxed);
|
||||||
for (w, writer) in writers.into_iter().enumerate() {
|
for (w, writer) in writers.into_iter().enumerate() {
|
||||||
let last = writer.join().expect("nothing undone");
|
let last = writer.join().expect("nothing undone");
|
||||||
for i in (w..LEN / 4).step_by(4 * 97).filter(|i| i * 4 / BLOCK % 2 == 0) {
|
for i in (w..LEN / 4).step_by(4 * 97).filter(|i| (i * 4 / BLOCK).is_multiple_of(2)) {
|
||||||
assert_eq!(dword(i).load(Ordering::Relaxed), last);
|
assert_eq!(dword(i).load(Ordering::Relaxed), last);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+101
-17
@@ -300,14 +300,18 @@ unsafe impl Send for Idle {}
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
static IDLE: std::sync::Mutex<(Vec<Idle>, u64)> = std::sync::Mutex::new((Vec::new(), 0));
|
static IDLE: std::sync::Mutex<(Vec<Idle>, u64)> = std::sync::Mutex::new((Vec::new(), 0));
|
||||||
|
|
||||||
/// The most host lists kept idle (128 were too few: flights land several at
|
/// The most host lists kept idle, and the most upload memory they may keep
|
||||||
/// a time, so lists were thrown away and others made in the same frame, with
|
/// between them. On hosts with <= 32 GiB RAM, cap at 96 idle lists / 64 MiB
|
||||||
/// their preludes and buffers, 12 % of the submitting thread in the opening,
|
/// instead of 512 / 256 MiB so command-allocator pools cannot push a 16 GB
|
||||||
/// profile cpu-1), and the most upload memory they may keep
|
/// host into `E_OUTOFMEMORY` during long open-world sessions.
|
||||||
/// between them (a list keeps scratch chunks over a reset only while lists
|
|
||||||
/// do not share them, `VICTORY_SCRATCH_POOL=0`).
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
const IDLE_MOST: (usize, u64) = (512, 256 << 20);
|
fn idle_most() -> (usize, u64) {
|
||||||
|
if crate::residency::limited_host_ram() {
|
||||||
|
(96, 64 << 20)
|
||||||
|
} else {
|
||||||
|
(512, 256 << 20)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Idle-list trim: memory stack by skornuta (skornuta/victory-memory-stack 57fb136, GPL-3.0),
|
// Idle-list trim: memory stack by skornuta (skornuta/victory-memory-stack 57fb136, GPL-3.0),
|
||||||
// patch 13 (and the idle trim of its base).
|
// patch 13 (and the idle trim of its base).
|
||||||
@@ -382,7 +386,8 @@ pub(crate) fn recycle(lists: Vec<Detached>, ran: &[usize]) {
|
|||||||
if !ran.contains(&i) {
|
if !ran.contains(&i) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if IDLE.lock().unwrap_or_else(|e| e.into_inner()).0.len() >= IDLE_MOST.0 {
|
let (max_lists, max_bytes) = idle_most();
|
||||||
|
if IDLE.lock().unwrap_or_else(|e| e.into_inner()).0.len() >= max_lists {
|
||||||
// Its submission has run: its prelude serves another list.
|
// Its submission has run: its prelude serves another list.
|
||||||
host.give_prelude();
|
host.give_prelude();
|
||||||
continue;
|
continue;
|
||||||
@@ -392,7 +397,7 @@ pub(crate) fn recycle(lists: Vec<Detached>, ran: &[usize]) {
|
|||||||
host.reset();
|
host.reset();
|
||||||
let bytes = host.scratch_kept();
|
let bytes = host.scratch_kept();
|
||||||
let mut idle = IDLE.lock().unwrap_or_else(|e| e.into_inner());
|
let mut idle = IDLE.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
if idle.0.len() < IDLE_MOST.0 && idle.1 + bytes <= IDLE_MOST.1 {
|
if idle.0.len() < max_lists && idle.1 + bytes <= max_bytes {
|
||||||
let now = crate::host::now_ms();
|
let now = crate::host::now_ms();
|
||||||
idle.0.push(Idle(host, bytes, now));
|
idle.0.push(Idle(host, bytes, now));
|
||||||
idle.1 += bytes;
|
idle.1 += bytes;
|
||||||
@@ -412,6 +417,24 @@ pub(crate) fn recycle(lists: Vec<Detached>, ran: &[usize]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Drops excess idle command lists/allocators during critical host commit
|
||||||
|
/// pressure, keeping a small working set (64 lists).
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub(crate) fn trim_idle() {
|
||||||
|
const PRESSURED_KEEP: usize = 64;
|
||||||
|
let freed: Vec<Idle> = {
|
||||||
|
let mut idle = IDLE.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
if idle.0.len() <= PRESSURED_KEEP {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let dropped = idle.0.split_off(PRESSURED_KEEP);
|
||||||
|
let dropped_bytes: u64 = dropped.iter().map(|Idle(_, b, _)| *b).sum();
|
||||||
|
idle.1 = idle.1.saturating_sub(dropped_bytes);
|
||||||
|
dropped
|
||||||
|
};
|
||||||
|
drop(freed);
|
||||||
|
}
|
||||||
|
|
||||||
/// A wait for a memory value recorded into list `this`, with waits cut
|
/// A wait for a memory value recorded into list `this`, with waits cut
|
||||||
/// into lists (`crate::queue::cuts`). On the console the queue runs the
|
/// into lists (`crate::queue::cuts`). On the console the queue runs the
|
||||||
/// list up to the wait, stands there until the value is in memory, and
|
/// list up to the wait, stands there until the value is in memory, and
|
||||||
@@ -1007,7 +1030,14 @@ extern "system" fn copy_buffer_region(
|
|||||||
/// other is not ([`crate::resource::target_format`]): their texels differ
|
/// other is not ([`crate::resource::target_format`]): their texels differ
|
||||||
/// in size, so the host cannot copy between them (logged once).
|
/// in size, so the host cannot copy between them (logged once).
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn unlike(dst: This, src: This) -> bool {
|
fn unlike(dst: This, src: This, mapped: bool) -> bool {
|
||||||
|
if !mapped && (crate::resource::dropped(src) > 0 || crate::resource::dropped(dst) > 0) {
|
||||||
|
static ONCE: std::sync::Once = std::sync::Once::new();
|
||||||
|
ONCE.call_once(|| {
|
||||||
|
tracing::warn!(?dst, ?src, "copy with a texture whose host copy leaves out levels skipped")
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
let unlike = crate::resource::stands_in(dst) != crate::resource::stands_in(src);
|
let unlike = crate::resource::stands_in(dst) != crate::resource::stands_in(src);
|
||||||
if unlike {
|
if unlike {
|
||||||
static ONCE: std::sync::Once = std::sync::Once::new();
|
static ONCE: std::sync::Once = std::sync::Once::new();
|
||||||
@@ -1033,7 +1063,8 @@ extern "system" fn copy_resource(this: This, dst: This, src: This) {
|
|||||||
crate::resource::host_resource(dst),
|
crate::resource::host_resource(dst),
|
||||||
crate::resource::host_resource(src),
|
crate::resource::host_resource(src),
|
||||||
) {
|
) {
|
||||||
if unlike(dst, src) {
|
let levelwise = crate::resource::dropped(dst) != crate::resource::dropped(src);
|
||||||
|
if unlike(dst, src, true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Two title textures over the same memory have one host
|
// Two title textures over the same memory have one host
|
||||||
@@ -1075,8 +1106,12 @@ extern "system" fn copy_resource(this: This, dst: This, src: This) {
|
|||||||
ensure_state(list, src, COPY_SOURCE);
|
ensure_state(list, src, COPY_SOURCE);
|
||||||
#[cfg(feature = "diagnostics")]
|
#[cfg(feature = "diagnostics")]
|
||||||
list.note_op(|| format!("copy resource {src:?} to {dst:?}"));
|
list.note_op(|| format!("copy resource {src:?} to {dst:?}"));
|
||||||
// SAFETY: an open list and live textures.
|
if levelwise {
|
||||||
unsafe { list.list.CopyResource(to, from) };
|
copy_levels(list, dst, to, src, from);
|
||||||
|
} else {
|
||||||
|
// SAFETY: an open list and live textures.
|
||||||
|
unsafe { list.list.CopyResource(to, from) };
|
||||||
|
}
|
||||||
} else if let (Some((to, a)), Some((from, b))) = (
|
} else if let (Some((to, a)), Some((from, b))) = (
|
||||||
crate::resource::buffer_bytes(dst),
|
crate::resource::buffer_bytes(dst),
|
||||||
crate::resource::buffer_bytes(src),
|
crate::resource::buffer_bytes(src),
|
||||||
@@ -1088,6 +1123,41 @@ extern "system" fn copy_resource(this: This, dst: This, src: This) {
|
|||||||
let _ = (this, dst, src);
|
let _ = (this, dst, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A whole-texture copy between host copies that leave out different
|
||||||
|
/// numbers of levels (`crate::resource::drop_levels`): each title level both
|
||||||
|
/// host copies have, at its own index in each.
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn copy_levels(
|
||||||
|
list: &crate::host::HostList,
|
||||||
|
dst: This,
|
||||||
|
to: &windows::Win32::Graphics::Direct3D12::ID3D12Resource,
|
||||||
|
src: This,
|
||||||
|
from: &windows::Win32::Graphics::Direct3D12::ID3D12Resource,
|
||||||
|
) {
|
||||||
|
use windows::Win32::Graphics::Direct3D12::{
|
||||||
|
D3D12_TEXTURE_COPY_LOCATION, D3D12_TEXTURE_COPY_LOCATION_0,
|
||||||
|
D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, ID3D12Resource,
|
||||||
|
};
|
||||||
|
let location = |texture: &ID3D12Resource, index: u32| D3D12_TEXTURE_COPY_LOCATION {
|
||||||
|
// SAFETY: a borrowed pointer the location never releases.
|
||||||
|
pResource: unsafe { std::mem::transmute_copy(texture) },
|
||||||
|
Type: D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
|
||||||
|
Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { SubresourceIndex: index },
|
||||||
|
};
|
||||||
|
let count = crate::resource::title_subresources(dst).min(crate::resource::title_subresources(src));
|
||||||
|
for index in 0..count {
|
||||||
|
let (Some(d), Some(s)) = (
|
||||||
|
crate::resource::host_subresource(dst, index),
|
||||||
|
crate::resource::host_subresource(src, index),
|
||||||
|
) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
// SAFETY: an open list and live textures; both subresources exist
|
||||||
|
// and have the title level's size.
|
||||||
|
unsafe { list.list.CopyTextureRegion(&location(to, d), 0, 0, 0, &location(from, s), None) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extern "system" fn copy_resource_x(this: This, dst: This, src: This, _flags: u32) {
|
extern "system" fn copy_resource_x(this: This, dst: This, src: This, _flags: u32) {
|
||||||
copy_resource(this, dst, src);
|
copy_resource(this, dst, src);
|
||||||
}
|
}
|
||||||
@@ -1161,9 +1231,16 @@ extern "system" fn copy_texture_region(
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
if unlike(dst.resource, src.resource) {
|
if unlike(dst.resource, src.resource, true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let mut dst = dst;
|
||||||
|
if dst.kind != FOOTPRINT && crate::resource::dropped(dst.resource) > 0 {
|
||||||
|
match crate::resource::host_subresource(dst.resource, dst.footprint.offset as u32) {
|
||||||
|
Some(index) => dst.footprint.offset = u64::from(index),
|
||||||
|
None => return,
|
||||||
|
}
|
||||||
|
}
|
||||||
let mut from = src;
|
let mut from = src;
|
||||||
// Both sides are the same subresource of one host texture (set below).
|
// Both sides are the same subresource of one host texture (set below).
|
||||||
let mut same = false;
|
let mut same = false;
|
||||||
@@ -1207,10 +1284,15 @@ extern "system" fn copy_texture_region(
|
|||||||
// title textures over one memory): not a copy the host allows.
|
// title textures over one memory): not a copy the host allows.
|
||||||
// The states and the copy are left out below; the rest is
|
// The states and the copy are left out below; the rest is
|
||||||
// noted as before.
|
// noted as before.
|
||||||
|
if crate::resource::dropped(src.resource) > 0 {
|
||||||
|
match crate::resource::host_subresource(src.resource, src.footprint.offset as u32) {
|
||||||
|
Some(index) => from.footprint.offset = u64::from(index),
|
||||||
|
None => return,
|
||||||
|
}
|
||||||
|
}
|
||||||
same = texture.as_raw() == to.as_raw()
|
same = texture.as_raw() == to.as_raw()
|
||||||
&& src.kind != FOOTPRINT
|
|
||||||
&& dst.kind != FOOTPRINT
|
&& dst.kind != FOOTPRINT
|
||||||
&& src.footprint.offset as u32 == dst.footprint.offset as u32;
|
&& from.footprint.offset == dst.footprint.offset;
|
||||||
list.twin_use(src.resource, false, false);
|
list.twin_use(src.resource, false, false);
|
||||||
if crate::texture::title_written(texture) {
|
if crate::texture::title_written(texture) {
|
||||||
crate::texture::upload(list, src.resource, texture);
|
crate::texture::upload(list, src.resource, texture);
|
||||||
@@ -1342,6 +1424,7 @@ fn read_back(
|
|||||||
// The title's buffer holds every row at its own pitch.
|
// The title's buffer holds every row at its own pitch.
|
||||||
let bytes = pitch * (rows - 1) + row;
|
let bytes = pitch * (rows - 1) + row;
|
||||||
let data = buffer_range(dst.resource, dst.footprint.offset, bytes).ok_or("a destination outside its buffer")?;
|
let data = buffer_range(dst.resource, dst.footprint.offset, bytes).ok_or("a destination outside its buffer")?;
|
||||||
|
let index = crate::resource::readback_subresource(src.resource, src.footprint.offset as u32)?;
|
||||||
let texture = crate::resource::host_resource(src.resource).ok_or("no host texture")?;
|
let texture = crate::resource::host_resource(src.resource).ok_or("no host texture")?;
|
||||||
let buffer = host.read_back_buffer(size).ok_or("no read-back buffer")?;
|
let buffer = host.read_back_buffer(size).ok_or("no read-back buffer")?;
|
||||||
// As a texture source of any copy: what shaders wrote to a depth twin
|
// As a texture source of any copy: what shaders wrote to a depth twin
|
||||||
@@ -1353,6 +1436,7 @@ fn read_back(
|
|||||||
ensure_state(list, src.resource, COPY_SOURCE);
|
ensure_state(list, src.resource, COPY_SOURCE);
|
||||||
let mut from = src;
|
let mut from = src;
|
||||||
from.resource = texture.as_raw().cast_const().cast();
|
from.resource = texture.as_raw().cast_const().cast();
|
||||||
|
from.footprint.offset = u64::from(index);
|
||||||
let mut to = dst;
|
let mut to = dst;
|
||||||
to.resource = buffer.as_raw().cast_const().cast();
|
to.resource = buffer.as_raw().cast_const().cast();
|
||||||
to.footprint = footprint;
|
to.footprint = footprint;
|
||||||
@@ -1412,7 +1496,7 @@ extern "system" fn resolve(
|
|||||||
use windows::core::Interface;
|
use windows::core::Interface;
|
||||||
const RESOLVE_DEST: u32 = 0x1000;
|
const RESOLVE_DEST: u32 = 0x1000;
|
||||||
const RESOLVE_SOURCE: u32 = 0x2000;
|
const RESOLVE_SOURCE: u32 = 0x2000;
|
||||||
if unlike(dst, src) {
|
if unlike(dst, src, false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Depth textures shaders also write: what they wrote, first.
|
// Depth textures shaders also write: what they wrote, first.
|
||||||
|
|||||||
@@ -970,7 +970,7 @@ mod tests {
|
|||||||
fn a_target_is_the_one_at_the_call() {
|
fn a_target_is_the_one_at_the_call() {
|
||||||
let mut slot = [0x5256_5476u64, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
|
let mut slot = [0x5256_5476u64, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
|
||||||
let kept = record(slot.as_ptr() as u64);
|
let kept = record(slot.as_ptr() as u64);
|
||||||
slot[1] = 99;
|
std::hint::black_box(&mut slot)[1] = 99;
|
||||||
assert_eq!(kept[1], 2);
|
assert_eq!(kept[1], 2);
|
||||||
assert_eq!(record(0), [0; RECORD]);
|
assert_eq!(record(0), [0; RECORD]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,9 @@ fn book() -> Option<&'static Mutex<Book>> {
|
|||||||
let mut keys = HashSet::new();
|
let mut keys = HashSet::new();
|
||||||
let mut shaders = HashSet::new();
|
let mut shaders = HashSet::new();
|
||||||
let ends = [
|
let ends = [
|
||||||
walk_shaders(&dir, |_, hash, _, _| drop(shaders.insert(hash))),
|
walk_shaders(&dir, |_, hash, _, _| {
|
||||||
|
shaders.insert(hash);
|
||||||
|
}),
|
||||||
walk_pipelines(&dir, |_, bytes| {
|
walk_pipelines(&dir, |_, bytes| {
|
||||||
keys.extend(bytes.first_chunk::<16>().copied());
|
keys.extend(bytes.first_chunk::<16>().copied());
|
||||||
}),
|
}),
|
||||||
@@ -234,7 +236,9 @@ pub fn keep_library() {
|
|||||||
/// there is one.
|
/// there is one.
|
||||||
pub fn make(dir: &Path, which: &[usize], mut each: impl FnMut(usize, Option<(f64, bool)>)) {
|
pub fn make(dir: &Path, which: &[usize], mut each: impl FnMut(usize, Option<(f64, bool)>)) {
|
||||||
let mut places = HashMap::new();
|
let mut places = HashMap::new();
|
||||||
walk_shaders(dir, |stage, hash, at, len| drop(places.insert(hash, (stage, at, len))));
|
walk_shaders(dir, |stage, hash, at, len| {
|
||||||
|
places.insert(hash, (stage, at, len));
|
||||||
|
});
|
||||||
let Ok(mut file) = std::fs::File::open(dir.join(SHADERS)) else { return };
|
let Ok(mut file) = std::fs::File::open(dir.join(SHADERS)) else { return };
|
||||||
let wanted: HashSet<usize> = which.iter().copied().collect();
|
let wanted: HashSet<usize> = which.iter().copied().collect();
|
||||||
let mut entries = HashMap::new();
|
let mut entries = HashMap::new();
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ fn leave_out() -> &'static [String] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The light in the water's volume, in tiles (`water_shading:CS_TransmissionVolumetrics_Tiled`
|
/// The light in the water's volume, in tiles (`water_shading:CS_TransmissionVolumetrics_Tiled`
|
||||||
/// and `_Tiled_LocalLights`, GTA VI 1.0.2.1): programs of one 64-lane wave a group, which a
|
/// and `_Tiled_LocalLights`, title build 1.0.2.1): programs of one 64-lane wave a group, which a
|
||||||
/// host of 32-lane waves gets in the wave-wide form only (`victory_shader::emit`, 4 and 7
|
/// host of 32-lane waves gets in the wave-wide form only (`victory_shader::emit`, 4 and 7
|
||||||
/// branches taken wave-wide). In that form they leave whole tiles of open water dark, around
|
/// branches taken wave-wide). In that form they leave whole tiles of open water dark, around
|
||||||
/// boats, along shores and under bridges, and take about 15 ms of the card a frame (RTX 5070,
|
/// boats, along shores and under bridges, and take about 15 ms of the card a frame (RTX 5070,
|
||||||
|
|||||||
@@ -52,12 +52,15 @@ pub(crate) fn room(memory: Option<[u64; 4]>) {
|
|||||||
pool.reclaim(tick, limit, true);
|
pool.reclaim(tick, limit, true);
|
||||||
}
|
}
|
||||||
if let Ok(mut pool) = STAGING.try_lock() {
|
if let Ok(mut pool) = STAGING.try_lock() {
|
||||||
|
let tight = crate::residency::tight_host_ram();
|
||||||
let staging_limit = if crate::residency::critical_commit() {
|
let staging_limit = if crate::residency::critical_commit() {
|
||||||
0
|
0
|
||||||
} else if pressure {
|
} else if pressure {
|
||||||
1
|
1
|
||||||
|
} else if tight {
|
||||||
|
2
|
||||||
} else {
|
} else {
|
||||||
limit
|
limit.min(STAGING_KEPT)
|
||||||
};
|
};
|
||||||
pool.reclaim(tick, staging_limit, true);
|
pool.reclaim(tick, staging_limit, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -326,7 +326,7 @@ mod tests {
|
|||||||
let low = |at: u64, len: u64| at.checked_add(len).is_some_and(|end| end <= LOW && len > 0);
|
let low = |at: u64, len: u64| at.checked_add(len).is_some_and(|end| end <= LOW && len > 0);
|
||||||
assert!(low(0x34e1_0000, 0xae0_0000));
|
assert!(low(0x34e1_0000, 0xae0_0000));
|
||||||
assert!(!low(0xffff_0000, 0x2_0000));
|
assert!(!low(0xffff_0000, 0x2_0000));
|
||||||
assert!(!low(0xe1c80_0000, 0x1000));
|
assert!(!low(0x000e_1c80_0000, 0x1000));
|
||||||
assert!(!low(u64::MAX, 2));
|
assert!(!low(u64::MAX, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1377,7 +1377,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn a_pair_of_timestamps_shows_the_load_it_is_given() {
|
fn a_pair_of_timestamps_shows_the_load_it_is_given() {
|
||||||
let (start, end) = (0xd0419_6698, 0xd0419_6690);
|
let (start, end) = (0x000d_0419_6698, 0x000d_0419_6690);
|
||||||
assert_eq!(as_loaded(5_000_000, end, 4_000_000) - as_loaded(5_000_000, start, 4_000_000), 4_000_000);
|
assert_eq!(as_loaded(5_000_000, end, 4_000_000) - as_loaded(5_000_000, start, 4_000_000), 4_000_000);
|
||||||
assert_eq!(as_loaded(5_000_000, start, 0), 5_000_000);
|
assert_eq!(as_loaded(5_000_000, start, 0), 5_000_000);
|
||||||
assert_eq!(as_loaded(5, start, 100), 1);
|
assert_eq!(as_loaded(5, start, 100), 1);
|
||||||
|
|||||||
@@ -3154,7 +3154,7 @@ impl Player {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for l in all {
|
for l in all {
|
||||||
self.worker.queue.ExecuteCommandLists(&[l.clone()]);
|
self.worker.queue.ExecuteCommandLists(std::slice::from_ref(l));
|
||||||
self.worker.idle()?;
|
self.worker.idle()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1212,7 +1212,7 @@ impl Player {
|
|||||||
word(if s.kind == slot::SRV { 4 } else { 2 }),
|
word(if s.kind == slot::SRV { 4 } else { 2 }),
|
||||||
word(if s.kind == slot::SRV { 6 } else { 4 }),
|
word(if s.kind == slot::SRV { 6 } else { 4 }),
|
||||||
word(if s.kind == slot::SRV { 7 } else { 5 }),
|
word(if s.kind == slot::SRV { 7 } else { 5 }),
|
||||||
word(if s.kind == slot::SRV { 8 } else { 8 }),
|
word(8),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -277,7 +277,7 @@ impl Player {
|
|||||||
.map(|i| (all[i * 3 + 2], i))
|
.map(|i| (all[i * 3 + 2], i))
|
||||||
.filter(|w| w.0 > 0)
|
.filter(|w| w.0 > 0)
|
||||||
.collect();
|
.collect();
|
||||||
worst.sort_by(|a, b| b.0.cmp(&a.0));
|
worst.sort_by_key(|w| std::cmp::Reverse(w.0));
|
||||||
for (n, i) in worst.into_iter().take(8) {
|
for (n, i) in worst.into_iter().take(8) {
|
||||||
let (id, at, len) = calls[i];
|
let (id, at, len) = calls[i];
|
||||||
out.push(format!(
|
out.push(format!(
|
||||||
|
|||||||
@@ -488,6 +488,7 @@ impl Player {
|
|||||||
|
|
||||||
/// The commands that copy the texels of `spots` to [`PROBE`] from `first`
|
/// The commands that copy the texels of `spots` to [`PROBE`] from `first`
|
||||||
/// on; `copied`: a copy to them went before.
|
/// on; `copied`: a copy to them went before.
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn take(
|
fn take(
|
||||||
&self,
|
&self,
|
||||||
spots: &[Spot],
|
spots: &[Spot],
|
||||||
|
|||||||
@@ -95,6 +95,14 @@ pub(crate) fn limited_host_ram() -> bool {
|
|||||||
*LIMITED.get_or_init(|| memory_status().is_some_and(|s| s.ullTotalPhys <= 32 * GIB))
|
*LIMITED.get_or_init(|| memory_status().is_some_and(|s| s.ullTotalPhys <= 32 * GIB))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// True on hosts with <= 20 GiB physical RAM (e.g. 16 GB laptops), where idle
|
||||||
|
/// pools (staging blocks, snapshot buffers, upload scratch, command allocators)
|
||||||
|
/// should stay lean to leave physical RAM free for Windows and avoid paging.
|
||||||
|
pub(crate) fn tight_host_ram() -> bool {
|
||||||
|
static TIGHT: OnceLock<bool> = OnceLock::new();
|
||||||
|
*TIGHT.get_or_init(|| memory_status().is_some_and(|s| s.ullTotalPhys <= 20 * GIB))
|
||||||
|
}
|
||||||
|
|
||||||
fn next_pressure(was: bool, physical: u64, commit: u64) -> bool {
|
fn next_pressure(was: bool, physical: u64, commit: u64) -> bool {
|
||||||
if was {
|
if was {
|
||||||
physical < 5 * GIB || commit < 6 * GIB
|
physical < 5 * GIB || commit < 6 * GIB
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ pub(crate) struct ResourceDesc {
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
impl ResourceDesc {
|
impl ResourceDesc {
|
||||||
/// The texture of this one's levels from `base` on.
|
/// The texture of this one's levels from `base` on.
|
||||||
fn from_level(&self, base: u32) -> ResourceDesc {
|
fn levels_from(&self, base: u32) -> ResourceDesc {
|
||||||
let mut d = *self;
|
let mut d = *self;
|
||||||
if base > 0 {
|
if base > 0 {
|
||||||
d.width = (d.width >> base).max(1);
|
d.width = (d.width >> base).max(1);
|
||||||
@@ -1351,12 +1351,128 @@ pub(crate) fn read_from(layout: &victory_formats::texture::Layout, first: u32) -
|
|||||||
if layout.bytes_from(first) < layout.size { first } else { 0 }
|
if layout.bytes_from(first) < layout.size { first } else { 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Configured `VICTORY_TEXTURE_DROP_MIPS` count (0..=4; 0 leaves out none).
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub(crate) fn drop_mips_configured() -> u32 {
|
||||||
|
static N: std::sync::OnceLock<u32> = std::sync::OnceLock::new();
|
||||||
|
*N.get_or_init(|| {
|
||||||
|
std::env::var("VICTORY_TEXTURE_DROP_MIPS")
|
||||||
|
.ok()
|
||||||
|
.and_then(|v| v.trim().parse::<u32>().ok())
|
||||||
|
.unwrap_or(0)
|
||||||
|
.min(4)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// How many of its largest levels the host copy of a texture described by
|
||||||
|
/// `desc` leaves out (`VICTORY_TEXTURE_DROP_MIPS=N`, at most 4; 0, the
|
||||||
|
/// default, leaves out none). Each level left out divides the texture's
|
||||||
|
/// bytes by about four, keeping 6 GB / 4 GB GPUs within VRAM budget with
|
||||||
|
/// frame generation active. Only 2D single-slice textures the title fills
|
||||||
|
/// ([`fills`]), at least 512 texels on their shorter side, whose sides
|
||||||
|
/// halve cleanly into whole 4-texel blocks.
|
||||||
|
///
|
||||||
|
/// `VICTORY_TEXTURE_KEEP_SIDE=<texels>`: no texture is taken below that
|
||||||
|
/// many texels on its longer side ([`levels_above`]).
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub(crate) fn drop_levels(desc: &ResourceDesc) -> u32 {
|
||||||
|
const TEXTURE_2D: u32 = 3;
|
||||||
|
let n = drop_mips_configured();
|
||||||
|
if n == 0
|
||||||
|
|| !fills(desc)
|
||||||
|
|| desc.dimension != TEXTURE_2D
|
||||||
|
|| desc.depth_or_array_size != 1
|
||||||
|
|| desc.sample_count > 1
|
||||||
|
|| desc.mip_levels < 5
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static KEEP: std::sync::OnceLock<u64> = std::sync::OnceLock::new();
|
||||||
|
let keep = *KEEP.get_or_init(|| {
|
||||||
|
std::env::var("VICTORY_TEXTURE_KEEP_SIDE")
|
||||||
|
.ok()
|
||||||
|
.and_then(|v| v.trim().parse::<u64>().ok())
|
||||||
|
.unwrap_or(0)
|
||||||
|
});
|
||||||
|
let (w, h) = (desc.width, u64::from(desc.height));
|
||||||
|
let n = levels_above(n.min(u32::from(desc.mip_levels).saturating_sub(1)), w.max(h), keep);
|
||||||
|
let whole = |side: u64| side % (4 << n) == 0;
|
||||||
|
if n == 0 || w.min(h) < 512 || !whole(w) || !whole(h) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
n
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Of `n` levels, how many a texture `longer` texels long can give up and
|
||||||
|
/// stay at least `keep` texels long (`keep` 0: all `n`).
|
||||||
|
fn levels_above(n: u32, longer: u64, keep: u64) -> u32 {
|
||||||
|
match keep {
|
||||||
|
0 => n,
|
||||||
|
keep => n.min((longer / keep).checked_ilog2().unwrap_or(0)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[test]
|
||||||
|
fn a_kept_side_bounds_the_levels_dropped() {
|
||||||
|
assert_eq!(levels_above(2, 4096, 0), 2);
|
||||||
|
assert_eq!(levels_above(2, 4096, 1024), 2);
|
||||||
|
assert_eq!(levels_above(2, 2048, 1024), 1);
|
||||||
|
assert_eq!(levels_above(2, 1024, 1024), 0);
|
||||||
|
assert_eq!(levels_above(2, 512, 1024), 0);
|
||||||
|
assert_eq!(levels_above(4, 8192, 1024), 3);
|
||||||
|
assert_eq!(levels_above(1, 3000, 1024), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Base mip level omitted by the host copy of `this` (0 for buffers and null).
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub(crate) fn dropped(this: This) -> u32 {
|
||||||
|
if this.is_null() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
made_copy(this).map_or_else(|| drop_levels(&resource(this).desc), |copy| copy.base)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The host copy's subresource for subresource `index` of title texture
|
||||||
|
/// `this`, whose host copy leaves out [`dropped`] levels: `None` for a
|
||||||
|
/// level it leaves out.
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub(crate) fn host_subresource(this: This, index: u32) -> Option<u32> {
|
||||||
|
let drop = dropped(this);
|
||||||
|
let mips = u32::from(resource(this).desc.mip_levels).max(1);
|
||||||
|
let (mip, slice) = (index % mips, index / mips);
|
||||||
|
(mip >= drop).then(|| mip - drop + slice * (mips - drop))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Subresources in the first plane of title texture `this`, as the title
|
||||||
|
/// numbers them (levels times slices).
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub(crate) fn title_subresources(this: This) -> u32 {
|
||||||
|
let desc = &resource(this).desc;
|
||||||
|
u32::from(desc.mip_levels).max(1) * u32::from(desc.depth_or_array_size).max(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Maps a readback before creating a host texture. Ordinary textures keep
|
||||||
|
/// their native subresource numbering. Shrunken textures support plane zero.
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub(crate) fn readback_subresource(this: This, index: u32) -> Result<u32, &'static str> {
|
||||||
|
if dropped(this) == 0 {
|
||||||
|
return Ok(index);
|
||||||
|
}
|
||||||
|
let desc = &resource(this).desc;
|
||||||
|
if index >= u32::from(desc.mip_levels) * u32::from(desc.depth_or_array_size) {
|
||||||
|
return Err("a read back outside the first plane of the host texture");
|
||||||
|
}
|
||||||
|
host_subresource(this, index).ok_or("a mip level omitted from the host texture")
|
||||||
|
}
|
||||||
|
|
||||||
/// The level a host copy begins at for views that start at `first`: one the
|
/// The level a host copy begins at for views that start at `first`: one the
|
||||||
/// host can have as a texture's level 0 ([`read_from`]; block-compressed
|
/// host can have as a texture's level 0 ([`read_from`]; block-compressed
|
||||||
/// formats in whole blocks).
|
/// formats in whole blocks), never below [`drop_levels`].
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn base_level(desc: &ResourceDesc, first: u32) -> u32 {
|
fn base_level(desc: &ResourceDesc, first: u32) -> u32 {
|
||||||
const TEXTURE_2D: u32 = 3;
|
const TEXTURE_2D: u32 = 3;
|
||||||
|
let first = first.max(drop_levels(desc));
|
||||||
if first == 0
|
if first == 0
|
||||||
|| !fills(desc)
|
|| !fills(desc)
|
||||||
|| desc.dimension != TEXTURE_2D
|
|| desc.dimension != TEXTURE_2D
|
||||||
@@ -1387,7 +1503,8 @@ fn base_level(desc: &ResourceDesc, first: u32) -> u32 {
|
|||||||
/// [`placed_bytes`]. Remembered: asked for every slot that is looked at.
|
/// [`placed_bytes`]. Remembered: asked for every slot that is looked at.
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub(crate) fn placed_bytes_from(desc: &[u32; 14], first: u32) -> Option<u64> {
|
pub(crate) fn placed_bytes_from(desc: &[u32; 14], first: u32) -> Option<u64> {
|
||||||
if first == 0 || !held_only() {
|
let drop_on = drop_mips_configured() > 0;
|
||||||
|
if !drop_on && (first == 0 || !held_only()) {
|
||||||
return placed_bytes(desc);
|
return placed_bytes(desc);
|
||||||
}
|
}
|
||||||
type Known = std::collections::HashMap<([u32; 14], u32), Option<u64>>;
|
type Known = std::collections::HashMap<([u32; 14], u32), Option<u64>>;
|
||||||
@@ -1399,11 +1516,16 @@ pub(crate) fn placed_bytes_from(desc: &[u32; 14], first: u32) -> Option<u64> {
|
|||||||
let whole = placed_bytes(desc)?;
|
let whole = placed_bytes(desc)?;
|
||||||
// SAFETY: 56 bytes in the description's layout.
|
// SAFETY: 56 bytes in the description's layout.
|
||||||
let d = unsafe { desc.as_ptr().cast::<ResourceDesc>().read_unaligned() };
|
let d = unsafe { desc.as_ptr().cast::<ResourceDesc>().read_unaligned() };
|
||||||
|
let floor = drop_levels(&d);
|
||||||
|
let effective = if held_only() { first.max(floor) } else { floor };
|
||||||
|
if effective == 0 {
|
||||||
|
return Some(whole);
|
||||||
|
}
|
||||||
let Some(t) = texture_layout(&d).filter(|t| t.planes.len() == 1) else {
|
let Some(t) = texture_layout(&d).filter(|t| t.planes.len() == 1) else {
|
||||||
return Some(whole);
|
return Some(whole);
|
||||||
};
|
};
|
||||||
let layout = &t.planes[0].layout;
|
let layout = &t.planes[0].layout;
|
||||||
Some(layout.bytes_from(read_from(layout, first)).min(whole))
|
Some(layout.bytes_from(read_from(layout, effective)).min(whole))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1752,20 +1874,26 @@ fn hosted(this: This, make: bool) -> Option<Made> {
|
|||||||
texture = reserved;
|
texture = reserved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// The levels views show ([`held_only`]), those of the slots shaders
|
// The levels views show ([`held_only`]) and any configured mip floor
|
||||||
// pick by index among them.
|
// (`VICTORY_TEXTURE_DROP_MIPS`), for non-aliased, non-tiled textures.
|
||||||
let mut base = 0;
|
let mut base = 0;
|
||||||
if shape_fits && r.host.placed.load(Relaxed) && held_only() && !is_aliased(this) {
|
if shape_fits && !is_aliased(this) && tiled.is_none() {
|
||||||
let wanted = r.host.wanted.load(Relaxed);
|
let mut first = drop_levels(&r.desc);
|
||||||
let viewed = crate::descriptor::host::first_viewed(r.data() as u64).unwrap_or(u32::MAX);
|
if r.host.placed.load(Relaxed) && held_only() {
|
||||||
let first = wanted.min(viewed);
|
let wanted = r.host.wanted.load(Relaxed);
|
||||||
if first != u32::MAX {
|
let viewed = crate::descriptor::host::first_viewed(r.data() as u64).unwrap_or(u32::MAX);
|
||||||
|
let held = wanted.min(viewed);
|
||||||
|
if held != u32::MAX {
|
||||||
|
first = first.max(held);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if first > 0 {
|
||||||
base = base_level(&r.desc, first);
|
base = base_level(&r.desc, first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let texture = match texture {
|
let texture = match texture {
|
||||||
Some(texture) => Some(texture),
|
Some(texture) => Some(texture),
|
||||||
None => host_texture(&r.desc.from_level(base), r.host.state, clear),
|
None => host_texture(&r.desc.levels_from(base), r.host.state, clear),
|
||||||
};
|
};
|
||||||
let Some(texture) = texture else {
|
let Some(texture) = texture else {
|
||||||
r.host.refused.store(true, Relaxed);
|
r.host.refused.store(true, Relaxed);
|
||||||
@@ -3076,7 +3204,7 @@ fn host_texture_as(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let Err(e) = &made {
|
if let Err(e) = &made {
|
||||||
crate::residency::allocation_error(&e);
|
crate::residency::allocation_error(e);
|
||||||
tracing::warn!(error = %e, desc = ?d, reserved, "no host texture");
|
tracing::warn!(error = %e, desc = ?d, reserved, "no host texture");
|
||||||
}
|
}
|
||||||
if !reserved
|
if !reserved
|
||||||
|
|||||||
@@ -41,18 +41,17 @@ pub(crate) struct Shadow {
|
|||||||
start: u64,
|
start: u64,
|
||||||
len: u64,
|
len: u64,
|
||||||
/// Per page of title memory from `start`'s on: the write-watch asking
|
/// Per page of title memory from `start`'s on: the write-watch asking
|
||||||
/// after which it was last copied (0: never).
|
/// after which it was last copied (0: never), paired under the same lock
|
||||||
copied: Mutex<Vec<u64>>,
|
/// with the two ranges taken whole (last and longest, with their asking).
|
||||||
/// Two ranges of title memory taken whole, the last one and the longest,
|
copied: Mutex<(Vec<u64>, [(usize, usize, u64); 2])>,
|
||||||
/// and the asking after which each was ([`Shadow::copy_stale`]). A page
|
|
||||||
/// a range holds in part cannot say so in `copied`. Locked inside
|
|
||||||
/// `copied`'s lock.
|
|
||||||
ranged: Mutex<[(usize, usize, u64); 2]>,
|
|
||||||
/// Whether the memory is write-watched: unknown, yes, no.
|
/// Whether the memory is write-watched: unknown, yes, no.
|
||||||
watched: AtomicU8,
|
watched: AtomicU8,
|
||||||
/// Ranges shaders of a submission not yet copied back may be writing:
|
/// Ranges shaders of a submission not yet copied back may be writing:
|
||||||
/// title memory there is older than the copy.
|
/// title memory there is older than the copy.
|
||||||
pending: Mutex<Vec<(usize, usize)>>,
|
pending: Mutex<Vec<(usize, usize)>>,
|
||||||
|
/// Lock-free mirror of `pending.len()` so refreshes and filters skip
|
||||||
|
/// locking `pending` when no shader writes are in flight for this copy.
|
||||||
|
pending_len: AtomicUsize,
|
||||||
/// With [`relay`]: how many submissions not yet copied back declared
|
/// With [`relay`]: how many submissions not yet copied back declared
|
||||||
/// each range of `pending` ([`Flights`]). Locked inside `pending`'s
|
/// each range of `pending` ([`Flights`]). Locked inside `pending`'s
|
||||||
/// lock.
|
/// lock.
|
||||||
@@ -118,7 +117,9 @@ struct Card {
|
|||||||
/// started, in the card's memory too: made when shader writes are
|
/// started, in the card's memory too: made when shader writes are
|
||||||
/// first declared for the copy, and compared with the card's side, on
|
/// first declared for the copy, and compared with the card's side, on
|
||||||
/// the card, after each submission that declares some.
|
/// the card, after each submission that declares some.
|
||||||
before: Mutex<Option<ID3D12Resource>>,
|
before: std::sync::OnceLock<ID3D12Resource>,
|
||||||
|
/// Serializes one-time creation of `before`.
|
||||||
|
before_init: Mutex<()>,
|
||||||
/// Offsets of the copy whose bytes changed on the CPU's side and have
|
/// Offsets of the copy whose bytes changed on the CPU's side and have
|
||||||
/// not gone to the card's side yet.
|
/// not gone to the card's side yet.
|
||||||
dirty: Mutex<Vec<(usize, usize)>>,
|
dirty: Mutex<Vec<(usize, usize)>>,
|
||||||
@@ -320,8 +321,8 @@ pub(crate) fn card_room_kept() -> u64 {
|
|||||||
card_limits().1.min(SEEN).saturating_sub(CARD_BYTES[0].load(Ordering::Relaxed) + CARD_REFUSED[1].load(Ordering::Relaxed))
|
card_limits().1.min(SEEN).saturating_sub(CARD_BYTES[0].load(Ordering::Relaxed) + CARD_REFUSED[1].load(Ordering::Relaxed))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The copies in the card's memory.
|
/// The copies in the card's memory, with their title address range `(start, end)`.
|
||||||
static CARDED: Mutex<Vec<std::sync::Weak<Shadow>>> = Mutex::new(Vec::new());
|
static CARDED: Mutex<Vec<(std::sync::Weak<Shadow>, usize, usize)>> = Mutex::new(Vec::new());
|
||||||
|
|
||||||
/// The copies in the card's memory whose `touched` was set since
|
/// The copies in the card's memory whose `touched` was set since
|
||||||
/// [`card_dirty`] last took them (a copy may be on it twice). Before, each
|
/// [`card_dirty`] last took them (a copy may be on it twice). Before, each
|
||||||
@@ -339,9 +340,13 @@ fn carded(shadow: &Arc<Shadow>) {
|
|||||||
};
|
};
|
||||||
let _ = card.me.set(Arc::downgrade(shadow));
|
let _ = card.me.set(Arc::downgrade(shadow));
|
||||||
let mut carded = CARDED.lock().unwrap_or_else(|e| e.into_inner());
|
let mut carded = CARDED.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
carded.push(Arc::downgrade(shadow));
|
carded.push((
|
||||||
|
Arc::downgrade(shadow),
|
||||||
|
shadow.start as usize,
|
||||||
|
(shadow.start + shadow.len) as usize,
|
||||||
|
));
|
||||||
if carded.len() >= 2 * KEPT.load(Ordering::Relaxed).max(1024) {
|
if carded.len() >= 2 * KEPT.load(Ordering::Relaxed).max(1024) {
|
||||||
carded.retain(|weak| weak.strong_count() > 0);
|
carded.retain(|(weak, _, _)| weak.strong_count() > 0);
|
||||||
KEPT.store(carded.len(), Ordering::Relaxed);
|
KEPT.store(carded.len(), Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -364,7 +369,7 @@ pub(crate) fn card_stats() -> [u64; 10] {
|
|||||||
for (i, stat) in CARD_STATS.iter().enumerate() {
|
for (i, stat) in CARD_STATS.iter().enumerate() {
|
||||||
out[i] = stat.swap(0, Ordering::Relaxed);
|
out[i] = stat.swap(0, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
out[7] = CARDED.lock().unwrap_or_else(|e| e.into_inner()).iter().filter(|w| w.strong_count() > 0).count() as u64;
|
out[7] = CARDED.lock().unwrap_or_else(|e| e.into_inner()).iter().filter(|(w, _, _)| w.strong_count() > 0).count() as u64;
|
||||||
out[8] = CARD_BYTES[0].load(Ordering::Relaxed)
|
out[8] = CARD_BYTES[0].load(Ordering::Relaxed)
|
||||||
+ WINDOW_CARD_BYTES.load(Ordering::Relaxed)
|
+ WINDOW_CARD_BYTES.load(Ordering::Relaxed)
|
||||||
+ WINDOW_MAPPED_BYTES.load(Ordering::Relaxed);
|
+ WINDOW_MAPPED_BYTES.load(Ordering::Relaxed);
|
||||||
@@ -555,6 +560,19 @@ fn window_mapped_most() -> u64 {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Maximum VRAM budget percentage up to which windows may be placed in card
|
||||||
|
/// memory (`VICTORY_WINDOWS_VRAM_PERCENT`, 50..=95; default 80).
|
||||||
|
fn window_vram_percent() -> u64 {
|
||||||
|
static PCT: std::sync::OnceLock<u64> = std::sync::OnceLock::new();
|
||||||
|
*PCT.get_or_init(|| {
|
||||||
|
std::env::var("VICTORY_WINDOWS_VRAM_PERCENT")
|
||||||
|
.ok()
|
||||||
|
.and_then(|v| v.trim().parse().ok())
|
||||||
|
.unwrap_or(80)
|
||||||
|
.clamp(50, 95)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Bytes alive of windows in card memory the CPU maps.
|
/// Bytes alive of windows in card memory the CPU maps.
|
||||||
static WINDOW_MAPPED_BYTES: AtomicU64 = AtomicU64::new(0);
|
static WINDOW_MAPPED_BYTES: AtomicU64 = AtomicU64::new(0);
|
||||||
|
|
||||||
@@ -567,7 +585,7 @@ fn window_mapped_for(size: u64) -> Option<(ID3D12Resource, *mut u8)> {
|
|||||||
}
|
}
|
||||||
let host = host()?;
|
let host = host()?;
|
||||||
if let Some([budget, used, ..]) = host.video_memory()
|
if let Some([budget, used, ..]) = host.video_memory()
|
||||||
&& used + size > budget / 10 * 8
|
&& used + size > budget * window_vram_percent() / 100
|
||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@@ -603,7 +621,7 @@ fn window_room_for(size: u64) -> Option<ID3D12Resource> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
if let Some([budget, used, ..]) = host.video_memory()
|
if let Some([budget, used, ..]) = host.video_memory()
|
||||||
&& used + size > budget / 10 * 8
|
&& used + size > budget * window_vram_percent() / 100
|
||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@@ -733,7 +751,7 @@ pub(crate) fn stale_pages(most: usize, say: &mut dyn FnMut(&Shadow, usize, usize
|
|||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
let written: std::collections::HashMap<usize, u64> = written.into_iter().collect();
|
let written: std::collections::HashMap<usize, u64> = written.into_iter().collect();
|
||||||
let copied = shadow.copied.lock().unwrap_or_else(|e| e.into_inner()).clone();
|
let copied = shadow.copied.lock().unwrap_or_else(|e| e.into_inner()).0.clone();
|
||||||
for (i, &at) in copied.iter().enumerate() {
|
for (i, &at) in copied.iter().enumerate() {
|
||||||
let page = start / PAGE + i;
|
let page = start / PAGE + i;
|
||||||
if at == 0 || written.get(&page).is_some_and(|&w| w > at) {
|
if at == 0 || written.get(&page).is_some_and(|&w| w > at) {
|
||||||
@@ -784,12 +802,24 @@ pub(crate) fn copy_all(copies: Vec<(usize, usize, usize)>) {
|
|||||||
/// CPU side held the same before or not. Left out is what shaders in the air
|
/// CPU side held the same before or not. Left out is what shaders in the air
|
||||||
/// may be writing (such a copy waits for them, or is done on the card).
|
/// may be writing (such a copy waits for them, or is done on the card).
|
||||||
pub(crate) fn send_copied(dst: usize, len: usize) {
|
pub(crate) fn send_copied(dst: usize, len: usize) {
|
||||||
for shadow in carded_copies() {
|
let dst_end = dst.saturating_add(len);
|
||||||
|
let hits: Vec<Arc<Shadow>> = CARDED
|
||||||
|
.lock()
|
||||||
|
.unwrap_or_else(|e| e.into_inner())
|
||||||
|
.iter()
|
||||||
|
.filter(|&&(_, start, end)| dst < end && start < dst_end)
|
||||||
|
.filter_map(|(w, _, _)| w.upgrade())
|
||||||
|
.collect();
|
||||||
|
for shadow in hits {
|
||||||
let (start, end) = (shadow.start as usize, (shadow.start + shadow.len) as usize);
|
let (start, end) = (shadow.start as usize, (shadow.start + shadow.len) as usize);
|
||||||
let (from, to) = (dst.max(start), (dst + len).min(end));
|
let (from, to) = (dst.max(start), dst_end.min(end));
|
||||||
if from >= to {
|
if from >= to {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if shadow.pending_len.load(Ordering::Acquire) == 0 {
|
||||||
|
shadow.copy(from, to);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let busy: Vec<(usize, usize)> =
|
let busy: Vec<(usize, usize)> =
|
||||||
shadow.pending.lock().unwrap_or_else(|e| e.into_inner()).iter().copied().filter(|&(a, b)| a < to && b > from).collect();
|
shadow.pending.lock().unwrap_or_else(|e| e.into_inner()).iter().copied().filter(|&(a, b)| a < to && b > from).collect();
|
||||||
for (a, b) in outside(from, to, busy) {
|
for (a, b) in outside(from, to, busy) {
|
||||||
@@ -800,7 +830,7 @@ pub(crate) fn send_copied(dst: usize, len: usize) {
|
|||||||
|
|
||||||
/// The copies in the card's memory (diagnostics: `crate::host::upcheck`).
|
/// The copies in the card's memory (diagnostics: `crate::host::upcheck`).
|
||||||
pub(crate) fn carded_copies() -> Vec<Arc<Shadow>> {
|
pub(crate) fn carded_copies() -> Vec<Arc<Shadow>> {
|
||||||
CARDED.lock().unwrap_or_else(|e| e.into_inner()).iter().filter_map(std::sync::Weak::upgrade).collect()
|
CARDED.lock().unwrap_or_else(|e| e.into_inner()).iter().filter_map(|(w, _, _)| w.upgrade()).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ranges in order, those that overlap or touch as one.
|
/// Ranges in order, those that overlap or touch as one.
|
||||||
@@ -1319,6 +1349,12 @@ mod relay_tests {
|
|||||||
/// Snapshot memory kept for reuse (already touched, so no page faults).
|
/// Snapshot memory kept for reuse (already touched, so no page faults).
|
||||||
static POOL: Mutex<Vec<Vec<u8>>> = Mutex::new(Vec::new());
|
static POOL: Mutex<Vec<Vec<u8>>> = Mutex::new(Vec::new());
|
||||||
|
|
||||||
|
/// Drops pooled CPU snapshot buffers during critical host commit pressure.
|
||||||
|
pub(crate) fn trim_snapshot_pool() {
|
||||||
|
let gone = std::mem::take(&mut *POOL.lock().unwrap_or_else(|e| e.into_inner()));
|
||||||
|
drop(gone);
|
||||||
|
}
|
||||||
|
|
||||||
/// An empty buffer with room for `n` bytes, from the pool if it has one
|
/// An empty buffer with room for `n` bytes, from the pool if it has one
|
||||||
/// of about that size: a small copy's snapshot took the 174 MB buffer kept
|
/// of about that size: a small copy's snapshot took the 174 MB buffer kept
|
||||||
/// for the big heap's, which then got another, until eight of them were
|
/// for the big heap's, which then got another, until eight of them were
|
||||||
@@ -1358,14 +1394,14 @@ fn snapshots_kept() -> usize {
|
|||||||
/// the largest, and of those the largest one and the next ones up to `KEPT`
|
/// the largest, and of those the largest one and the next ones up to `KEPT`
|
||||||
/// bytes in all.
|
/// bytes in all.
|
||||||
fn give_back(v: Vec<u8>) {
|
fn give_back(v: Vec<u8>) {
|
||||||
const KEPT: usize = 512 << 20;
|
let cap: usize = if crate::residency::tight_host_ram() { 128 << 20 } else { 512 << 20 };
|
||||||
let mut pool = POOL.lock().unwrap_or_else(|e| e.into_inner());
|
let mut pool = POOL.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
pool.push(v);
|
pool.push(v);
|
||||||
pool.sort_by_key(|v| std::cmp::Reverse(v.capacity()));
|
pool.sort_by_key(|v| std::cmp::Reverse(v.capacity()));
|
||||||
let (mut kept, mut total) = (0, 0usize);
|
let (mut kept, mut total) = (0, 0usize);
|
||||||
for v in pool.iter().take(snapshots_kept()) {
|
for v in pool.iter().take(snapshots_kept()) {
|
||||||
total = total.saturating_add(v.capacity());
|
total = total.saturating_add(v.capacity());
|
||||||
if kept > 0 && total > KEPT {
|
if kept > 0 && total > cap {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
kept += 1;
|
kept += 1;
|
||||||
@@ -2442,7 +2478,7 @@ fn wc_mapped_for(size: u64) -> Option<(ID3D12Resource, *mut u8)> {
|
|||||||
}
|
}
|
||||||
let host = host()?;
|
let host = host()?;
|
||||||
if let Some([budget, used, ..]) = host.video_memory()
|
if let Some([budget, used, ..]) = host.video_memory()
|
||||||
&& used + size > budget / 10 * 8
|
&& used + size > budget * window_vram_percent() / 100
|
||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@@ -2542,7 +2578,7 @@ fn dword_runs(at: usize, title: &[u8], merged: &[u8], gap: usize) -> Vec<(usize,
|
|||||||
/// 12 MB this way and finds 80,000 runs.
|
/// 12 MB this way and finds 80,000 runs.
|
||||||
fn word_runs(at: usize, title: &[u8], held: &[u8]) -> Vec<(usize, usize)> {
|
fn word_runs(at: usize, title: &[u8], held: &[u8]) -> Vec<(usize, usize)> {
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
if at % 4 == 0 && title.len() % 4 == 0 && title.len() == held.len() && std::arch::is_x86_feature_detected!("avx2") {
|
if at.is_multiple_of(4) && title.len().is_multiple_of(4) && title.len() == held.len() && std::arch::is_x86_feature_detected!("avx2") {
|
||||||
// SAFETY: the processor has AVX2, and the lengths are the same.
|
// SAFETY: the processor has AVX2, and the lengths are the same.
|
||||||
return unsafe { word_runs_avx2(title, held) };
|
return unsafe { word_runs_avx2(title, held) };
|
||||||
}
|
}
|
||||||
@@ -2931,7 +2967,7 @@ impl Drop for Shadow {
|
|||||||
} else {
|
} else {
|
||||||
CARD_BYTES[0].fetch_sub(card.size, Ordering::Relaxed);
|
CARD_BYTES[0].fetch_sub(card.size, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
if card.before.get_mut().unwrap_or_else(|e| e.into_inner()).is_some() {
|
if card.before.get().is_some() {
|
||||||
CARD_BYTES[1].fetch_sub(card_hash_bytes(card.size), Ordering::Relaxed);
|
CARD_BYTES[1].fetch_sub(card_hash_bytes(card.size), Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3205,7 +3241,7 @@ pub(crate) fn window_use() -> [u64; 8] {
|
|||||||
let loose = LOOSE.write().unwrap_or_else(|e| e.into_inner());
|
let loose = LOOSE.write().unwrap_or_else(|e| e.into_inner());
|
||||||
for s in loose.values() {
|
for s in loose.values() {
|
||||||
let copied = s.copied.lock().unwrap_or_else(|e| e.into_inner());
|
let copied = s.copied.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
let pages = copied.iter().filter(|&&at| at != 0).count() as u64;
|
let pages = copied.0.iter().filter(|&&at| at != 0).count() as u64;
|
||||||
out[0] += (pages * PAGE as u64).min(s.len);
|
out[0] += (pages * PAGE as u64).min(s.len);
|
||||||
if crate::host::references(&s.buffer) > 1 {
|
if crate::host::references(&s.buffer) > 1 {
|
||||||
out[1] += 1;
|
out[1] += 1;
|
||||||
@@ -3403,10 +3439,10 @@ impl Shadow {
|
|||||||
gpu,
|
gpu,
|
||||||
start,
|
start,
|
||||||
len,
|
len,
|
||||||
copied: Mutex::new(vec![0; pages as usize]),
|
copied: Mutex::new((vec![0; pages as usize], Default::default())),
|
||||||
ranged: Mutex::default(),
|
|
||||||
watched: AtomicU8::new(0),
|
watched: AtomicU8::new(0),
|
||||||
pending: Mutex::default(),
|
pending: Mutex::default(),
|
||||||
|
pending_len: AtomicUsize::new(0),
|
||||||
flights: Mutex::default(),
|
flights: Mutex::default(),
|
||||||
before: Mutex::default(),
|
before: Mutex::default(),
|
||||||
merging: RwLock::default(),
|
merging: RwLock::default(),
|
||||||
@@ -3519,6 +3555,7 @@ impl Shadow {
|
|||||||
// lists).
|
// lists).
|
||||||
if self.card.is_some() {
|
if self.card.is_some() {
|
||||||
pending.push(range);
|
pending.push(range);
|
||||||
|
self.pending_len.store(pending.len(), Ordering::Release);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// The parts no declared range holds yet: their bytes are taken now,
|
// The parts no declared range holds yet: their bytes are taken now,
|
||||||
@@ -3543,6 +3580,7 @@ impl Shadow {
|
|||||||
parts = rest;
|
parts = rest;
|
||||||
}
|
}
|
||||||
pending.push(range);
|
pending.push(range);
|
||||||
|
self.pending_len.store(pending.len(), Ordering::Release);
|
||||||
let taken: usize = parts.iter().map(|&(from, to)| to.saturating_sub(from)).sum();
|
let taken: usize = parts.iter().map(|&(from, to)| to.saturating_sub(from)).sum();
|
||||||
BACK_CLASS[usize::from(!self.window)].fetch_add(taken as u64, Ordering::Relaxed);
|
BACK_CLASS[usize::from(!self.window)].fetch_add(taken as u64, Ordering::Relaxed);
|
||||||
let total = self.len as usize;
|
let total = self.len as usize;
|
||||||
@@ -3832,6 +3870,7 @@ impl Shadow {
|
|||||||
} else {
|
} else {
|
||||||
pending.retain(|r| !ranges.contains(r));
|
pending.retain(|r| !ranges.contains(r));
|
||||||
}
|
}
|
||||||
|
self.pending_len.store(pending.len(), Ordering::Release);
|
||||||
if !pending.is_empty() || self.card.is_some() {
|
if !pending.is_empty() || self.card.is_some() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -3886,15 +3925,39 @@ impl Shadow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// [`Shadow::changed`] for multiple offset ranges under a single `kept` lock.
|
||||||
|
fn changed_runs(&self, runs: impl Iterator<Item = (usize, usize)>) {
|
||||||
|
if !keeps() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let mut runs = runs.filter(|r| r.0 < r.1).peekable();
|
||||||
|
if runs.peek().is_none() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let mut kept = self.kept.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
if kept.0.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (from, to) in runs {
|
||||||
|
for piece in self.pieces(from, to) {
|
||||||
|
kept.0[piece] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Whether shaders of a submission not yet copied back may be writing
|
/// Whether shaders of a submission not yet copied back may be writing
|
||||||
/// the copy.
|
/// the copy.
|
||||||
|
#[inline]
|
||||||
pub(crate) fn writes_pending(&self) -> bool {
|
pub(crate) fn writes_pending(&self) -> bool {
|
||||||
!self.pending.lock().unwrap_or_else(|e| e.into_inner()).is_empty()
|
self.pending_len.load(Ordering::Acquire) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether one of those submissions may be writing in title memory
|
/// Whether one of those submissions may be writing in title memory
|
||||||
/// `[from, to)`.
|
/// `[from, to)`.
|
||||||
pub(crate) fn writes_pending_in(&self, from: usize, to: usize) -> bool {
|
pub(crate) fn writes_pending_in(&self, from: usize, to: usize) -> bool {
|
||||||
|
if self.pending_len.load(Ordering::Acquire) == 0 {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
self.pending.lock().unwrap_or_else(|e| e.into_inner()).iter().any(|&(a, e)| a < to && e > from)
|
self.pending.lock().unwrap_or_else(|e| e.into_inner()).iter().any(|&(a, e)| a < to && e > from)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3912,7 +3975,7 @@ impl Shadow {
|
|||||||
pub(crate) fn stale_under_writes(&self, address: usize, len: usize) -> bool {
|
pub(crate) fn stale_under_writes(&self, address: usize, len: usize) -> bool {
|
||||||
let (start, end) = (self.start as usize, (self.start + self.len) as usize);
|
let (start, end) = (self.start as usize, (self.start + self.len) as usize);
|
||||||
let (from, to) = (address.max(start), (address + len).min(end));
|
let (from, to) = (address.max(start), (address + len).min(end));
|
||||||
if from >= to {
|
if from >= to || self.pending_len.load(Ordering::Acquire) == 0 {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let busy: Vec<(usize, usize)> = self
|
let busy: Vec<(usize, usize)> = self
|
||||||
@@ -3932,7 +3995,7 @@ impl Shadow {
|
|||||||
let base = start / PAGE;
|
let base = start / PAGE;
|
||||||
let copied = self.copied.lock().unwrap_or_else(|e| e.into_inner());
|
let copied = self.copied.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
busy.into_iter().any(|(a, e)| match crate::watch::asked(a, e) {
|
busy.into_iter().any(|(a, e)| match crate::watch::asked(a, e) {
|
||||||
Some((_, written)) => !stale_pages_in(base, &copied, a, e, &written).is_empty(),
|
Some((_, written)) => !stale_pages_in(base, &copied.0, a, e, &written).is_empty(),
|
||||||
None => true,
|
None => true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -3956,7 +4019,7 @@ impl Shadow {
|
|||||||
pub(crate) fn merge_under_writes(&self, address: usize, len: usize, runs_left: &mut usize) -> bool {
|
pub(crate) fn merge_under_writes(&self, address: usize, len: usize, runs_left: &mut usize) -> bool {
|
||||||
let (start, end) = (self.start as usize, (self.start + self.len) as usize);
|
let (start, end) = (self.start as usize, (self.start + self.len) as usize);
|
||||||
let (from, to) = (address.max(start), (address + len).min(end));
|
let (from, to) = (address.max(start), (address + len).min(end));
|
||||||
if from >= to {
|
if from >= to || self.pending_len.load(Ordering::Acquire) == 0 {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let busy: Vec<(usize, usize)> = self
|
let busy: Vec<(usize, usize)> = self
|
||||||
@@ -3993,7 +4056,7 @@ impl Shadow {
|
|||||||
};
|
};
|
||||||
let stale: Vec<usize> = {
|
let stale: Vec<usize> = {
|
||||||
let copied = self.copied.lock().unwrap_or_else(|e| e.into_inner());
|
let copied = self.copied.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
stale_pages_in(base, &copied, a, e, &written)
|
stale_pages_in(base, &copied.0, a, e, &written)
|
||||||
};
|
};
|
||||||
if stale.is_empty() {
|
if stale.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
@@ -4068,7 +4131,7 @@ impl Shadow {
|
|||||||
{
|
{
|
||||||
let mut copied = self.copied.lock().unwrap_or_else(|e| e.into_inner());
|
let mut copied = self.copied.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
for page in taken {
|
for page in taken {
|
||||||
if let Some(at) = copied.get_mut(page - base) {
|
if let Some(at) = copied.0.get_mut(page - base) {
|
||||||
*at = now;
|
*at = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4152,30 +4215,32 @@ impl Shadow {
|
|||||||
if from >= to {
|
if from >= to {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
let mut busy: Vec<(usize, usize)> = self
|
if self.pending_len.load(Ordering::Acquire) != 0 {
|
||||||
.pending
|
let mut busy: Vec<(usize, usize)> = self
|
||||||
.lock()
|
.pending
|
||||||
.unwrap_or_else(|e| e.into_inner())
|
.lock()
|
||||||
.iter()
|
.unwrap_or_else(|e| e.into_inner())
|
||||||
.copied()
|
.iter()
|
||||||
.filter(|&(a, e)| a < to && e > from)
|
.copied()
|
||||||
.collect();
|
.filter(|&(a, e)| a < to && e > from)
|
||||||
if !busy.is_empty() {
|
.collect();
|
||||||
// Around ranges shaders are writing: the gaps, each as below
|
if !busy.is_empty() {
|
||||||
// (in the world most submissions have such ranges; copying the
|
// Around ranges shaders are writing: the gaps, each as below
|
||||||
// gaps whole cost ~1 s per frame).
|
// (in the world most submissions have such ranges; copying the
|
||||||
busy.sort_unstable();
|
// gaps whole cost ~1 s per frame).
|
||||||
let (mut at, mut bytes) = (from, 0);
|
busy.sort_unstable();
|
||||||
for (a, e) in busy {
|
let (mut at, mut bytes) = (from, 0);
|
||||||
if a > at {
|
for (a, e) in busy {
|
||||||
bytes += self.update_free(at, a);
|
if a > at {
|
||||||
|
bytes += self.update_free(at, a);
|
||||||
|
}
|
||||||
|
at = at.max(e);
|
||||||
}
|
}
|
||||||
at = at.max(e);
|
if at < to {
|
||||||
|
bytes += self.update_free(at, to);
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
}
|
}
|
||||||
if at < to {
|
|
||||||
bytes += self.update_free(at, to);
|
|
||||||
}
|
|
||||||
return bytes;
|
|
||||||
}
|
}
|
||||||
self.update_free(from, to)
|
self.update_free(from, to)
|
||||||
}
|
}
|
||||||
@@ -4184,6 +4249,12 @@ impl Shadow {
|
|||||||
/// nothing, and knows it without asking anything
|
/// nothing, and knows it without asking anything
|
||||||
/// (`crate::watch::nothing_new`). `false` if it would have to ask.
|
/// (`crate::watch::nothing_new`). `false` if it would have to ask.
|
||||||
pub(crate) fn nothing_new(&self, address: usize, len: usize) -> bool {
|
pub(crate) fn nothing_new(&self, address: usize, len: usize) -> bool {
|
||||||
|
let j = crate::watch::read_journal();
|
||||||
|
self.nothing_new_in(&j, address, len)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// [`Shadow::nothing_new`] using an already-held write-watch journal read guard.
|
||||||
|
pub(crate) fn nothing_new_in(&self, j: &crate::watch::JournalGuard, address: usize, len: usize) -> bool {
|
||||||
if self.place.is_some() {
|
if self.place.is_some() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -4196,11 +4267,14 @@ impl Shadow {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Around ranges shaders are writing the refresh asks gap by gap.
|
// Around ranges shaders are writing the refresh asks gap by gap.
|
||||||
if self.pending.lock().unwrap_or_else(|e| e.into_inner()).iter().any(|&(a, e)| a < to && e > from) {
|
if self.pending_len.load(Ordering::Acquire) != 0
|
||||||
|
&& self.pending.lock().unwrap_or_else(|e| e.into_inner()).iter().any(|&(a, e)| a < to && e > from)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let copied = self.copied.lock().unwrap_or_else(|e| e.into_inner());
|
let copied = self.copied.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
let same = crate::watch::nothing_new(from, to, start / PAGE, &copied, self.ranged(from, to));
|
let ranged = Self::ranged_in(&copied.1, from, to);
|
||||||
|
let same = crate::watch::nothing_new_in(j, from, to, start / PAGE, &copied.0, ranged);
|
||||||
#[cfg(feature = "diagnostics")]
|
#[cfg(feature = "diagnostics")]
|
||||||
if same {
|
if same {
|
||||||
use crate::copystat::{C, add};
|
use crate::copystat::{C, add};
|
||||||
@@ -4211,20 +4285,24 @@ impl Shadow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The latest asking after which a range that holds `[from, to)` was
|
/// The latest asking after which a range that holds `[from, to)` was
|
||||||
/// taken whole (0: none is known). The caller holds `copied`'s lock.
|
/// taken whole (0: none is known).
|
||||||
fn ranged(&self, from: usize, to: usize) -> u64 {
|
#[inline]
|
||||||
let ranged = self.ranged.lock().unwrap_or_else(|e| e.into_inner());
|
fn ranged_in(ranged: &[(usize, usize, u64); 2], from: usize, to: usize) -> u64 {
|
||||||
ranged.iter().filter(|r| r.0 <= from && to <= r.1).map(|r| r.2).max().unwrap_or(0)
|
ranged.iter().filter(|r| r.0 <= from && to <= r.1).map(|r| r.2).max().unwrap_or(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [`Shadow::update`] of `[from, to)` (inside the buffer) where no
|
/// [`Shadow::update`] of `[from, to)` (inside the buffer) where no
|
||||||
/// shader writes.
|
/// shader writes.
|
||||||
fn update_free(&self, from: usize, to: usize) -> usize {
|
fn update_free(&self, from: usize, to: usize) -> usize {
|
||||||
if self.watched.load(Ordering::Relaxed) != NOT_WATCHED {
|
let prev = self.watched.load(Ordering::Relaxed);
|
||||||
|
if prev != NOT_WATCHED {
|
||||||
if let Some((now, written)) = crate::watch::writes(from, to, true) {
|
if let Some((now, written)) = crate::watch::writes(from, to, true) {
|
||||||
// (A range whose blocks rest after a write has no guard now.)
|
// (A range whose blocks rest after a write has no guard now.)
|
||||||
let guarded = crate::watch::guarded(from, to) || self.watched.load(Ordering::Relaxed) == GUARDED;
|
let guarded = prev == GUARDED || crate::watch::guarded(from, to);
|
||||||
self.watched.store(if guarded { GUARDED } else { 1 }, Ordering::Relaxed);
|
let next = if guarded { GUARDED } else { 1 };
|
||||||
|
if next != prev {
|
||||||
|
self.watched.store(next, Ordering::Relaxed);
|
||||||
|
}
|
||||||
let copied = self.copy_stale(from, to, now, &written);
|
let copied = self.copy_stale(from, to, now, &written);
|
||||||
self.refresh_check(from, to);
|
self.refresh_check(from, to);
|
||||||
#[cfg(feature = "diagnostics")]
|
#[cfg(feature = "diagnostics")]
|
||||||
@@ -4316,7 +4394,7 @@ impl Shadow {
|
|||||||
// of the heap's buffer views alone two ends for each of 4,400
|
// of the heap's buffer views alone two ends for each of 4,400
|
||||||
// copies, every frame. A range that was taken whole, and not written
|
// copies, every frame. A range that was taken whole, and not written
|
||||||
// since, is as it was.
|
// since, is as it was.
|
||||||
let ranged = if crate::watch::light() { self.ranged(from, to) } else { 0 };
|
let ranged = if crate::watch::light() { Self::ranged_in(&copied.1, from, to) } else { 0 };
|
||||||
let (mut runs, mut run) = (Vec::new(), None::<(usize, bool)>);
|
let (mut runs, mut run) = (Vec::new(), None::<(usize, bool)>);
|
||||||
// Pages taken before and written since: in the order of their runs.
|
// Pages taken before and written since: in the order of their runs.
|
||||||
let mut again_at: Vec<(usize, u64)> = Vec::new();
|
let mut again_at: Vec<(usize, u64)> = Vec::new();
|
||||||
@@ -4329,7 +4407,7 @@ impl Shadow {
|
|||||||
}
|
}
|
||||||
_ => 0,
|
_ => 0,
|
||||||
};
|
};
|
||||||
let at = &mut copied[page - base];
|
let at = &mut copied.0[page - base];
|
||||||
let taken = (*at).max(ranged);
|
let taken = (*at).max(ranged);
|
||||||
if taken == 0 || write > taken {
|
if taken == 0 || write > taken {
|
||||||
// A page only partly in the range is copied in part: it
|
// A page only partly in the range is copied in part: it
|
||||||
@@ -4358,11 +4436,17 @@ impl Shadow {
|
|||||||
if let Some((first, known)) = run {
|
if let Some((first, known)) = run {
|
||||||
runs.push(((first * PAGE).max(from), ((last + 1) * PAGE).min(to), known));
|
runs.push(((first * PAGE).max(from), ((last + 1) * PAGE).min(to), known));
|
||||||
}
|
}
|
||||||
let runs = by_parts(runs, &again_at, &crate::watch::parts_written(&again_at));
|
let bytes = if runs.is_empty() {
|
||||||
let bytes = self.take_all(runs);
|
0
|
||||||
|
} else if again_at.is_empty() {
|
||||||
|
self.take_all(runs)
|
||||||
|
} else {
|
||||||
|
let runs = by_parts(runs, &again_at, &crate::watch::parts_written(&again_at));
|
||||||
|
self.take_all(runs)
|
||||||
|
};
|
||||||
if crate::watch::light() {
|
if crate::watch::light() {
|
||||||
// All of the range is in the copy as of this asking.
|
// All of the range is in the copy as of this asking.
|
||||||
let mut ranged = self.ranged.lock().unwrap_or_else(|e| e.into_inner());
|
let ranged = &mut copied.1;
|
||||||
ranged[0] = (from, to, now);
|
ranged[0] = (from, to, now);
|
||||||
if to - from >= ranged[1].1 - ranged[1].0 {
|
if to - from >= ranged[1].1 - ranged[1].0 {
|
||||||
ranged[1] = (from, to, now);
|
ranged[1] = (from, to, now);
|
||||||
@@ -4495,8 +4579,9 @@ impl Shadow {
|
|||||||
}
|
}
|
||||||
return self.copy(from, to);
|
return self.copy(from, to);
|
||||||
};
|
};
|
||||||
let whole = !known && card.before.lock().unwrap_or_else(|e| e.into_inner()).is_none();
|
let whole = !known && card.before.get().is_none();
|
||||||
let start = self.start as usize;
|
let start = self.start as usize;
|
||||||
|
let (mut send0, mut send1, mut send2, mut send3) = (0u64, 0u64, 0u64, 0u64);
|
||||||
TITLE.with_borrow_mut(|title| {
|
TITLE.with_borrow_mut(|title| {
|
||||||
title.resize(PAGE, 0);
|
title.resize(PAGE, 0);
|
||||||
let mut at = from;
|
let mut at = from;
|
||||||
@@ -4511,24 +4596,37 @@ impl Shadow {
|
|||||||
// refresh lie apart.
|
// refresh lie apart.
|
||||||
let held = unsafe { std::slice::from_raw_parts_mut(self.data.add(at - start), n) };
|
let held = unsafe { std::slice::from_raw_parts_mut(self.data.add(at - start), n) };
|
||||||
let was = crate::host::upcheck::on().then(|| held.to_vec());
|
let was = crate::host::upcheck::on().then(|| held.to_vec());
|
||||||
let runs = if whole { vec![(0, n)] } else { dword_runs(at, held, title, 0) };
|
let runs = if whole { vec![(0, n)] } else { word_runs(at, held, title) };
|
||||||
|
let mut page_bytes = 0u64;
|
||||||
for &(a, len) in &runs {
|
for &(a, len) in &runs {
|
||||||
held[a..a + len].copy_from_slice(&title[a..a + len]);
|
held[a..a + len].copy_from_slice(&title[a..a + len]);
|
||||||
self.changed(at - start + a, at - start + a + len);
|
page_bytes += len as u64;
|
||||||
|
}
|
||||||
|
if !runs.is_empty() {
|
||||||
|
self.changed_runs(runs.iter().map(|&(a, len)| (at - start + a, at - start + a + len)));
|
||||||
|
self.card_changed_runs(runs.iter().map(|&(a, len)| (at - start + a, at - start + a + len)));
|
||||||
}
|
}
|
||||||
self.card_changed_runs(runs.iter().map(|&(a, len)| (at - start + a, at - start + a + len)));
|
|
||||||
if let Some(was) = was {
|
if let Some(was) = was {
|
||||||
crate::host::upcheck::note(self.id, at - start, &was, held);
|
crate::host::upcheck::note(self.id, at - start, &was, held);
|
||||||
}
|
}
|
||||||
SEND[0].fetch_add(n as u64, Ordering::Relaxed);
|
send0 += n as u64;
|
||||||
if runs.is_empty() {
|
if runs.is_empty() {
|
||||||
SEND[1].fetch_add(n as u64, Ordering::Relaxed);
|
send1 += n as u64;
|
||||||
|
} else {
|
||||||
|
send2 += page_bytes;
|
||||||
|
send3 += runs.len() as u64;
|
||||||
}
|
}
|
||||||
SEND[2].fetch_add(runs.iter().map(|r| r.1 as u64).sum(), Ordering::Relaxed);
|
|
||||||
SEND[3].fetch_add(runs.len() as u64, Ordering::Relaxed);
|
|
||||||
at += n;
|
at += n;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
SEND[0].fetch_add(send0, Ordering::Relaxed);
|
||||||
|
if send1 != 0 {
|
||||||
|
SEND[1].fetch_add(send1, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
if send2 != 0 {
|
||||||
|
SEND[2].fetch_add(send2, Ordering::Relaxed);
|
||||||
|
SEND[3].fetch_add(send3, Ordering::Relaxed);
|
||||||
|
}
|
||||||
to - from
|
to - from
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4653,11 +4751,17 @@ impl Shadow {
|
|||||||
self.card.as_ref().map_or_else(Vec::new, |c| c.dirty.lock().unwrap_or_else(|e| e.into_inner()).clone())
|
self.card.as_ref().map_or_else(Vec::new, |c| c.dirty.lock().unwrap_or_else(|e| e.into_inner()).clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether this copy is in the card's memory and has a "before" hash buffer.
|
||||||
|
#[inline]
|
||||||
|
pub(crate) fn has_card_before(&self) -> bool {
|
||||||
|
self.card.as_ref().is_some_and(|card| card.before.get().is_some())
|
||||||
|
}
|
||||||
|
|
||||||
/// Of a copy in the card's memory: the CPU's side (PC memory), the
|
/// Of a copy in the card's memory: the CPU's side (PC memory), the
|
||||||
/// card side's bytes from before if made yet, and their size.
|
/// card side's bytes from before if made yet, and their size.
|
||||||
pub(crate) fn card_sides(&self) -> Option<(&ID3D12Resource, Option<ID3D12Resource>, u64)> {
|
pub(crate) fn card_sides(&self) -> Option<(&ID3D12Resource, Option<ID3D12Resource>, u64)> {
|
||||||
let card = self.card.as_ref()?;
|
let card = self.card.as_ref()?;
|
||||||
let before = card.before.lock().unwrap_or_else(|e| e.into_inner()).clone();
|
let before = card.before.get().cloned();
|
||||||
Some((&card.staging, before, card.size))
|
Some((&card.staging, before, card.size))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4670,15 +4774,19 @@ impl Shadow {
|
|||||||
let Some(card) = &self.card else {
|
let Some(card) = &self.card else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
let mut before = card.before.lock().unwrap_or_else(|e| e.into_inner());
|
if card.before.get().is_some() {
|
||||||
if before.is_some() {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*before = make(card.size);
|
let _init = card.before_init.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
if before.is_some() {
|
if card.before.get().is_some() {
|
||||||
CARD_BYTES[1].fetch_add(card_hash_bytes(card.size), Ordering::Relaxed);
|
return false;
|
||||||
}
|
}
|
||||||
before.is_some()
|
let Some(made) = make(card.size) else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
let _ = card.before.set(made);
|
||||||
|
CARD_BYTES[1].fetch_add(card_hash_bytes(card.size), Ordering::Relaxed);
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The declared range `[address, end)` as the compare on the card
|
/// The declared range `[address, end)` as the compare on the card
|
||||||
@@ -4891,7 +4999,8 @@ impl Shadow {
|
|||||||
if card {
|
if card {
|
||||||
shadow.card = Some(Card {
|
shadow.card = Some(Card {
|
||||||
staging: none(),
|
staging: none(),
|
||||||
before: Mutex::default(),
|
before: std::sync::OnceLock::new(),
|
||||||
|
before_init: Mutex::default(),
|
||||||
dirty: Mutex::default(),
|
dirty: Mutex::default(),
|
||||||
sent: Mutex::default(),
|
sent: Mutex::default(),
|
||||||
touched: Default::default(),
|
touched: Default::default(),
|
||||||
@@ -5022,7 +5131,7 @@ impl Shadow {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
let mut copied = self.copied.lock().unwrap_or_else(|e| e.into_inner());
|
let mut copied = self.copied.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
let Some(at) = copied.get_mut(page) else {
|
let Some(at) = copied.0.get_mut(page) else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
let held = *at != 0 && *at >= before && crate::watch::block_published(block);
|
let held = *at != 0 && *at >= before && crate::watch::block_published(block);
|
||||||
@@ -5048,7 +5157,8 @@ mod land_tests {
|
|||||||
let mut shadow = Shadow::new(buffer.clone(), data, 0, title as u64, len as u64);
|
let mut shadow = Shadow::new(buffer.clone(), data, 0, title as u64, len as u64);
|
||||||
shadow.card = Some(Card {
|
shadow.card = Some(Card {
|
||||||
staging: buffer,
|
staging: buffer,
|
||||||
before: Mutex::default(),
|
before: std::sync::OnceLock::new(),
|
||||||
|
before_init: Mutex::default(),
|
||||||
dirty: Mutex::default(),
|
dirty: Mutex::default(),
|
||||||
sent: Mutex::default(),
|
sent: Mutex::default(),
|
||||||
touched: Default::default(),
|
touched: Default::default(),
|
||||||
@@ -5192,7 +5302,7 @@ mod land_tests {
|
|||||||
});
|
});
|
||||||
let mut now = vec![0u8; LEN];
|
let mut now = vec![0u8; LEN];
|
||||||
for round in 1..200u32 {
|
for round in 1..200u32 {
|
||||||
for block in (0..BLOCKS).filter(|b| (*b as u32 * 5 + round) % 3 != 0) {
|
for block in (0..BLOCKS).filter(|b| !(*b as u32 * 5 + round).is_multiple_of(3)) {
|
||||||
for i in (block * PIECE / 4 + 3..(block + 1) * PIECE / 4).step_by(4) {
|
for i in (block * PIECE / 4 + 3..(block + 1) * PIECE / 4).step_by(4) {
|
||||||
now[i * 4..i * 4 + 4].copy_from_slice(&(round << 20 | i as u32).to_le_bytes());
|
now[i * 4..i * 4 + 4].copy_from_slice(&(round << 20 | i as u32).to_le_bytes());
|
||||||
}
|
}
|
||||||
@@ -5493,7 +5603,8 @@ fn lookup(address: u64, len: u64, any: bool) -> Option<Arc<Shadow>> {
|
|||||||
);
|
);
|
||||||
let card = Card {
|
let card = Card {
|
||||||
staging: buffer,
|
staging: buffer,
|
||||||
before: Mutex::default(),
|
before: std::sync::OnceLock::new(),
|
||||||
|
before_init: Mutex::default(),
|
||||||
dirty: Mutex::default(),
|
dirty: Mutex::default(),
|
||||||
sent: Mutex::default(),
|
sent: Mutex::default(),
|
||||||
touched: Default::default(),
|
touched: Default::default(),
|
||||||
@@ -5722,7 +5833,8 @@ pub(crate) fn by_address(start: u64, len: u64) -> Option<Arc<Shadow>> {
|
|||||||
shadow.changes_only.store(true, Ordering::Relaxed);
|
shadow.changes_only.store(true, Ordering::Relaxed);
|
||||||
shadow.card = Some(Card {
|
shadow.card = Some(Card {
|
||||||
staging,
|
staging,
|
||||||
before: Mutex::default(),
|
before: std::sync::OnceLock::new(),
|
||||||
|
before_init: Mutex::default(),
|
||||||
dirty: Mutex::default(),
|
dirty: Mutex::default(),
|
||||||
sent: Mutex::default(),
|
sent: Mutex::default(),
|
||||||
touched: Default::default(),
|
touched: Default::default(),
|
||||||
@@ -5812,7 +5924,8 @@ fn loose(address: u64, end: u64, unsized_ask: bool, any: bool) -> Option<Arc<Sha
|
|||||||
crate::host::name(&on_card, || format!("title memory {start:#x}+{len:#x} on the card"));
|
crate::host::name(&on_card, || format!("title memory {start:#x}+{len:#x} on the card"));
|
||||||
let card = Card {
|
let card = Card {
|
||||||
staging: buffer,
|
staging: buffer,
|
||||||
before: Mutex::default(),
|
before: std::sync::OnceLock::new(),
|
||||||
|
before_init: Mutex::default(),
|
||||||
dirty: Mutex::default(),
|
dirty: Mutex::default(),
|
||||||
sent: Mutex::default(),
|
sent: Mutex::default(),
|
||||||
touched: Default::default(),
|
touched: Default::default(),
|
||||||
|
|||||||
@@ -1802,7 +1802,7 @@ pub(crate) fn present_begins(frame: u64, planes: Planes<'_>) -> Option<Presentin
|
|||||||
if every > 0 {
|
if every > 0 {
|
||||||
static PRESENTS: AtomicU32 = AtomicU32::new(0);
|
static PRESENTS: AtomicU32 = AtomicU32::new(0);
|
||||||
let n = PRESENTS.fetch_add(1, Relaxed);
|
let n = PRESENTS.fetch_add(1, Relaxed);
|
||||||
if n % every == 0 {
|
if n.is_multiple_of(every) {
|
||||||
set_framegen([2, 4, 0, 6][(n / every % 4) as usize]);
|
set_framegen([2, 4, 0, 6][(n / every % 4) as usize]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,12 +110,22 @@ struct Last {
|
|||||||
/// first checks, and after the hash found a change the guard had not
|
/// first checks, and after the hash found a change the guard had not
|
||||||
/// seen ([`hot_textures`]). 0: not checked under the guard yet.
|
/// seen ([`hot_textures`]). 0: not checked under the guard yet.
|
||||||
hot_until: u64,
|
hot_until: u64,
|
||||||
|
/// Cached negative result from write-watch (`writes(..., false)` returned
|
||||||
|
/// `None` or the range is already guarded view memory), avoiding a
|
||||||
|
/// guaranteed-failing `GetWriteWatch` syscall on every refresh.
|
||||||
|
not_watched: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Frames a guarded texture is hashed at every check from its first check,
|
/// Frames a guarded texture is hashed at every check after the hash found
|
||||||
/// and after the hash found a change the guard did not see.
|
/// a change the guard did not see.
|
||||||
const HOT_FRAMES: u64 = 64;
|
const HOT_FRAMES: u64 = 64;
|
||||||
|
|
||||||
|
/// Initial hot frames on a guarded texture's very first check: long enough
|
||||||
|
/// to catch ring-of-3 animated/video textures (which then promote to full
|
||||||
|
/// [`HOT_FRAMES`] via `found_blind`), without forcing hundreds of megabytes
|
||||||
|
/// of static cutscene/world textures to be re-hashed every frame for 64 frames.
|
||||||
|
const START_HOT_FRAMES: u64 = 4;
|
||||||
|
|
||||||
/// Whether a guarded texture whose memory the hash found changed although
|
/// Whether a guarded texture whose memory the hash found changed although
|
||||||
/// the guard saw no write is hashed at every check for a while
|
/// the guard saw no write is hashed at every check for a while
|
||||||
/// ([`HOT_FRAMES`]), not every eighth frame. A title that writes such a
|
/// ([`HOT_FRAMES`]), not every eighth frame. A title that writes such a
|
||||||
@@ -1449,20 +1459,26 @@ impl Staging {
|
|||||||
if alone && !exact && last.hash.is_some() {
|
if alone && !exact && last.hash.is_some() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if !alone && let Some((now, written)) = waited(1, || crate::watch::writes(start, start + size, false)) {
|
if !alone && !last.not_watched {
|
||||||
if !exact && last.asked != 0 && written.iter().all(|&(_, w)| w <= last.asked) {
|
if crate::watch::guarded(start, start + size) {
|
||||||
return 0;
|
last.not_watched = true;
|
||||||
|
} else if let Some((now, changed)) = waited(1, || crate::watch::writes_since(start, start + size, false, last.asked)) {
|
||||||
|
if !exact && !changed {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
last.asked = now;
|
||||||
|
// Read through the copy, which stands unmapped pages: memory of
|
||||||
|
// big pools is too slow to ask page by page.
|
||||||
|
with_read(size, |read| {
|
||||||
|
crate::host::copy_mapped(read.as_mut_ptr(), self.memory, size, false);
|
||||||
|
self.detile(read);
|
||||||
|
});
|
||||||
|
#[cfg(feature = "diagnostics")]
|
||||||
|
crate::copystat::add(crate::copystat::C::TexWatched, size as u64);
|
||||||
|
return size;
|
||||||
|
} else {
|
||||||
|
last.not_watched = true;
|
||||||
}
|
}
|
||||||
last.asked = now;
|
|
||||||
// Read through the copy, which stands unmapped pages: memory of
|
|
||||||
// big pools is too slow to ask page by page.
|
|
||||||
with_read(size, |read| {
|
|
||||||
crate::host::copy_mapped(read.as_mut_ptr(), self.memory, size, false);
|
|
||||||
self.detile(read);
|
|
||||||
});
|
|
||||||
#[cfg(feature = "diagnostics")]
|
|
||||||
crate::copystat::add(crate::copystat::C::TexWatched, size as u64);
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
// View memory has no write-watch, and a texture there was hashed
|
// View memory has no write-watch, and a texture there was hashed
|
||||||
// whole at every check: 229 MB and 51 ms a frame in a gameplay view
|
// whole at every check: 229 MB and 51 ms a frame in a gameplay view
|
||||||
@@ -1479,19 +1495,20 @@ impl Staging {
|
|||||||
let mut blind = false;
|
let mut blind = false;
|
||||||
if !alone
|
if !alone
|
||||||
&& *GUARD.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_GUARD").is_none_or(|v| v != "0"))
|
&& *GUARD.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_GUARD").is_none_or(|v| v != "0"))
|
||||||
&& let Some((now, written)) = waited(1, || crate::watch::writes(start, start + size, true))
|
&& let Some((now, changed)) = waited(1, || crate::watch::writes_since(start, start + size, true, last.asked))
|
||||||
{
|
{
|
||||||
const HASH_EVERY: u64 = 8;
|
const HASH_EVERY: u64 = 8;
|
||||||
let unwritten = last.asked != 0 && written.iter().all(|&(_, w)| w <= last.asked);
|
let unwritten = !changed;
|
||||||
last.asked = now;
|
last.asked = now;
|
||||||
let frame = crate::frame::current();
|
let frame = crate::frame::current();
|
||||||
let turn = frame
|
let turn = frame
|
||||||
.wrapping_add((start >> 16) as u64)
|
.wrapping_add((start >> 16) as u64)
|
||||||
.is_multiple_of(HASH_EVERY);
|
.is_multiple_of(HASH_EVERY);
|
||||||
// A texture starts hot: one written that way from its first
|
// A texture starts hot briefly: one written through an alias view
|
||||||
// frames on changes before the hash has ever caught it.
|
// from its first frames on changes within 1-3 frames and is then
|
||||||
|
// promoted to full `HOT_FRAMES` by `found_blind`.
|
||||||
if last.hot_until == 0 {
|
if last.hot_until == 0 {
|
||||||
last.hot_until = frame + HOT_FRAMES;
|
last.hot_until = frame + START_HOT_FRAMES;
|
||||||
}
|
}
|
||||||
let hot = hot_textures() && frame < last.hot_until;
|
let hot = hot_textures() && frame < last.hot_until;
|
||||||
if !exact && unwritten && !turn && !hot {
|
if !exact && unwritten && !turn && !hot {
|
||||||
@@ -2570,7 +2587,7 @@ mod allocation_costs {
|
|||||||
seen.push(digest(&bytes));
|
seen.push(digest(&bytes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let text: Vec<u8> = (0..400u32).map(|i| (i * 37 >> 2) as u8).collect();
|
let text: Vec<u8> = (0..400u32).map(|i| ((i * 37) >> 2) as u8).collect();
|
||||||
for at in 0..399 {
|
for at in 0..399 {
|
||||||
let mut bytes = text.clone();
|
let mut bytes = text.clone();
|
||||||
bytes.swap(at, at + 1);
|
bytes.swap(at, at + 1);
|
||||||
|
|||||||
@@ -604,7 +604,7 @@ mod tests {
|
|||||||
f.extend([0x9c, 0x41, 0x5a, 0x48, 0x8b, 0x4c, 0x24, 0x28]);
|
f.extend([0x9c, 0x41, 0x5a, 0x48, 0x8b, 0x4c, 0x24, 0x28]);
|
||||||
f.extend([0x4c, 0x89, 0x11, 0x48, 0x89, 0x51, 0x08, 0x48, 0x89, 0x41, 0x10, 0xc3]);
|
f.extend([0x4c, 0x89, 0x11, 0x48, 0x89, 0x51, 0x08, 0x48, 0x89, 0x41, 0x10, 0xc3]);
|
||||||
type F = unsafe extern "system" fn(*mut u64, u64, u64, u64, *mut [u64; 3]);
|
type F = unsafe extern "system" fn(*mut u64, u64, u64, u64, *mut [u64; 3]);
|
||||||
let (there, operand, compared) = (spread(1), spread(2), if seed % 3 == 0 { spread(1) } else { spread(3) });
|
let (there, operand, compared) = (spread(1), spread(2), if seed.is_multiple_of(3) { spread(1) } else { spread(3) });
|
||||||
let flags = 0x202 | (spread(4) & 0x8d5) as u32;
|
let flags = 0x202 | (spread(4) & 0x8d5) as u32;
|
||||||
let (mut memory, mut out) = (there, [0; 3]);
|
let (mut memory, mut out) = (there, [0; 3]);
|
||||||
// SAFETY: the code above, which keeps to the calling convention.
|
// SAFETY: the code above, which keeps to the calling convention.
|
||||||
|
|||||||
+251
-77
@@ -164,6 +164,14 @@ fn journal_mut() -> std::sync::RwLockWriteGuard<'static, Journal> {
|
|||||||
waited(2, || JOURNAL.write().unwrap_or_else(|e| e.into_inner()))
|
waited(2, || JOURNAL.write().unwrap_or_else(|e| e.into_inner()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Shared read guard over the write-watch journal so a batch of `nothing_new`
|
||||||
|
/// checks can acquire the lock once instead of per buffer.
|
||||||
|
pub(crate) struct JournalGuard(std::sync::RwLockReadGuard<'static, Journal>);
|
||||||
|
|
||||||
|
pub(crate) fn read_journal() -> JournalGuard {
|
||||||
|
JournalGuard(journal())
|
||||||
|
}
|
||||||
|
|
||||||
/// Since the last line: waits and nanoseconds of waiting, of all threads, for
|
/// Since the last line: waits and nanoseconds of waiting, of all threads, for
|
||||||
/// the ranges held ([`ASKING`]), the journal to read it, the journal to note
|
/// the ranges held ([`ASKING`]), the journal to read it, the journal to note
|
||||||
/// in it, and the guards (faults of the title's among them).
|
/// in it, and the guards (faults of the title's among them).
|
||||||
@@ -319,6 +327,42 @@ const AHEAD_GAP: usize = (8 << 20) / PAGE;
|
|||||||
/// The most one asking covers (its answer needs 8 bytes per 4 KiB page).
|
/// The most one asking covers (its answer needs 8 bytes per 4 KiB page).
|
||||||
const AHEAD_MAX: usize = (1 << 30) / PAGE;
|
const AHEAD_MAX: usize = (1 << 30) / PAGE;
|
||||||
|
|
||||||
|
/// Fast atomic mirror of `JOURNAL.kept`: true while a submission's `ask_once`
|
||||||
|
/// covers its ranges so per-flush `ask_ahead`/`ask_ahead_done` skip locking
|
||||||
|
/// `JOURNAL` and building range vectors.
|
||||||
|
static AHEAD_KEPT: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
||||||
|
|
||||||
|
/// Whether the submission's one-shot asking (`ask_once`) already covers
|
||||||
|
/// write-watch queries, so per-flush `ask_ahead` calls are no-ops.
|
||||||
|
#[inline]
|
||||||
|
pub(crate) fn kept_active() -> bool {
|
||||||
|
AHEAD_KEPT.load(std::sync::atomic::Ordering::Acquire)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sort_merge_ahead(ranges: &mut Vec<(usize, usize)>) {
|
||||||
|
if ranges.len() <= 1 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ranges.sort_unstable();
|
||||||
|
let mut write = 0usize;
|
||||||
|
for read in 1..ranges.len() {
|
||||||
|
let (a, b) = ranges[read];
|
||||||
|
if a <= ranges[write].1 {
|
||||||
|
ranges[write].1 = ranges[write].1.max(b);
|
||||||
|
} else {
|
||||||
|
write += 1;
|
||||||
|
ranges[write] = (a, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ranges.truncate(write + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn ahead_contains(ahead: &[(usize, usize)], first: usize, last: usize) -> bool {
|
||||||
|
let idx = ahead.partition_point(|&(a, _)| a <= first);
|
||||||
|
idx > 0 && ahead[idx - 1].1 >= last
|
||||||
|
}
|
||||||
|
|
||||||
/// Asks the kernel about many ranges `(start, end)` at once, before the
|
/// Asks the kernel about many ranges `(start, end)` at once, before the
|
||||||
/// [`writes`] of each: ranges close together are one asking, and `writes`
|
/// [`writes`] of each: ranges close together are one asking, and `writes`
|
||||||
/// then answers from the journal until [`ask_ahead_done`]. The world's
|
/// then answers from the journal until [`ask_ahead_done`]. The world's
|
||||||
@@ -326,20 +370,36 @@ const AHEAD_MAX: usize = (1 << 30) / PAGE;
|
|||||||
/// 456 ms, in run 14). Ranges that are not write-watched, or lie alone, are
|
/// 456 ms, in run 14). Ranges that are not write-watched, or lie alone, are
|
||||||
/// left to `writes`.
|
/// left to `writes`.
|
||||||
pub(crate) fn ask_ahead(ranges: &[(usize, usize)]) {
|
pub(crate) fn ask_ahead(ranges: &[(usize, usize)]) {
|
||||||
|
// The submission's one asking stands ([`ask_once`]): check before
|
||||||
|
// allocating, filtering, or sorting thousands of ranges.
|
||||||
|
if kept_active() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let skip_guarded = light();
|
||||||
let mut pieces: Vec<(usize, usize)> = ranges
|
let mut pieces: Vec<(usize, usize)> = ranges
|
||||||
.iter()
|
.iter()
|
||||||
// Not view memory known by its bits: the kernel would refuse the
|
// Not view memory known by its bits or guarded read-only: the kernel
|
||||||
// asking (and, asked together with others, theirs).
|
// would refuse the asking (and, asked together with others, theirs).
|
||||||
.filter(|r| r.0 < r.1 && !published(r.0, r.1))
|
.filter(|r| r.0 < r.1 && !published(r.0, r.1))
|
||||||
.map(|&(start, end)| (start / PAGE, end.div_ceil(PAGE)))
|
.map(|&(start, end)| (start / PAGE, end.div_ceil(PAGE)))
|
||||||
|
.filter(|&(first, last)| !(skip_guarded && PROTECTED.any(first, last)))
|
||||||
.collect();
|
.collect();
|
||||||
if pieces.len() < 2 {
|
if pieces.len() < 2 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pieces.sort_unstable();
|
pieces.sort_unstable();
|
||||||
// The submission's one asking stands ([`ask_once`]): what it does not
|
// Collapse duplicate or fully-contained page spans before asking.
|
||||||
// hold is left to `writes`.
|
let mut write = 0usize;
|
||||||
if journal().kept {
|
for read in 1..pieces.len() {
|
||||||
|
let (a, b) = pieces[read];
|
||||||
|
if a >= pieces[write].0 && b <= pieces[write].1 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
write += 1;
|
||||||
|
pieces[write] = (a, b);
|
||||||
|
}
|
||||||
|
pieces.truncate(write + 1);
|
||||||
|
if pieces.len() < 2 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let _all = Asking::hold_all();
|
let _all = Asking::hold_all();
|
||||||
@@ -356,9 +416,10 @@ pub(crate) fn ask_ahead(ranges: &[(usize, usize)]) {
|
|||||||
last = last.max(pieces[k].1);
|
last = last.max(pieces[k].1);
|
||||||
k += 1;
|
k += 1;
|
||||||
}
|
}
|
||||||
ask_run(&pieces[i..k], &mut asked, &mut written);
|
ask_run(&pieces[i..k], &mut asked, &mut written, false);
|
||||||
i = k;
|
i = k;
|
||||||
}
|
}
|
||||||
|
sort_merge_ahead(&mut asked);
|
||||||
note_hot(&written);
|
note_hot(&written);
|
||||||
let mut j = journal_mut();
|
let mut j = journal_mut();
|
||||||
j.ahead_asked = next_asking();
|
j.ahead_asked = next_asking();
|
||||||
@@ -476,7 +537,7 @@ fn ask_early(every: std::time::Duration) {
|
|||||||
idle = 0;
|
idle = 0;
|
||||||
}
|
}
|
||||||
round += 1;
|
round += 1;
|
||||||
if round % 64 == 0 {
|
if round.is_multiple_of(64) {
|
||||||
hot.retain(|_, n| {
|
hot.retain(|_, n| {
|
||||||
*n /= 2;
|
*n /= 2;
|
||||||
*n > 0
|
*n > 0
|
||||||
@@ -507,6 +568,9 @@ fn ask_early(every: std::time::Duration) {
|
|||||||
|
|
||||||
/// The submission's refreshes are done: `writes` asks the kernel again.
|
/// The submission's refreshes are done: `writes` asks the kernel again.
|
||||||
pub(crate) fn ask_ahead_done() {
|
pub(crate) fn ask_ahead_done() {
|
||||||
|
if kept_active() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let mut j = journal_mut();
|
let mut j = journal_mut();
|
||||||
if !j.kept {
|
if !j.kept {
|
||||||
j.ahead.clear();
|
j.ahead.clear();
|
||||||
@@ -538,61 +602,73 @@ pub(crate) fn once() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// With [`once`]: asks about `ranges` (everything a submission's lists
|
/// With [`once`]: asks about `ranges` (everything a submission's lists
|
||||||
/// refresh) as [`ask_ahead`] does, and lets that asking stand until
|
/// refresh) in a single pass (merged runs and isolated ranges together) and
|
||||||
/// [`ask_once_end`].
|
/// lets that asking stand until [`ask_once_end`].
|
||||||
pub(crate) fn ask_once(ranges: &[(usize, usize)]) {
|
pub(crate) fn ask_once(ranges: &[(usize, usize)]) {
|
||||||
if !once() {
|
if !once() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ask_once_end();
|
ask_once_end();
|
||||||
ask_ahead(ranges);
|
let skip_guarded = light();
|
||||||
ask_rest(ranges);
|
let mut pieces: Vec<(usize, usize)> = ranges
|
||||||
}
|
.iter()
|
||||||
|
.filter(|r| r.0 < r.1 && !published(r.0, r.1))
|
||||||
/// [`ask_once`] after its [`ask_ahead`]: what that left to `writes`, and the
|
.map(|&(start, end)| (start / PAGE, end.div_ceil(PAGE)))
|
||||||
/// asking stands.
|
.filter(|&(first, last)| !(skip_guarded && PROTECTED.any(first, last)))
|
||||||
fn ask_rest(ranges: &[(usize, usize)]) {
|
.collect();
|
||||||
let _all = Asking::hold_all();
|
if pieces.is_empty() {
|
||||||
let mut ahead = {
|
return;
|
||||||
let mut j = journal_mut();
|
}
|
||||||
std::mem::take(&mut j.ahead)
|
pieces.sort_unstable();
|
||||||
};
|
// Collapse exact duplicates and fully-contained page spans in O(N).
|
||||||
// `ask_ahead` leaves a range that lies alone to `writes`, which asks
|
let mut write = 0usize;
|
||||||
// once per flush: with one asking for the submission that was every
|
for read in 1..pieces.len() {
|
||||||
// such range asked again at each of its 70 flushes (run 76: 2,300
|
let (a, b) = pieces[read];
|
||||||
// askings a frame with the switch on, as without it). They are asked
|
if a >= pieces[write].0 && b <= pieces[write].1 {
|
||||||
// here, once; what is not write-watched stays with `writes`.
|
|
||||||
let mut written = Vec::new();
|
|
||||||
for &(start, end) in ranges {
|
|
||||||
if start >= end || published(start, end) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let (first, last) = (start / PAGE, end.div_ceil(PAGE));
|
write += 1;
|
||||||
if !ahead.iter().any(|&(a, b)| a <= first && last <= b)
|
pieces[write] = (a, b);
|
||||||
&& let Some(pages) = kernel_written(first, last)
|
|
||||||
{
|
|
||||||
written.extend(pages);
|
|
||||||
ahead.push((first, last));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
pieces.truncate(write + 1);
|
||||||
|
let _all = Asking::hold_all();
|
||||||
|
let (mut asked, mut written) = (Vec::new(), Vec::new());
|
||||||
|
let mut i = 0;
|
||||||
|
while i < pieces.len() {
|
||||||
|
let first = pieces[i].0;
|
||||||
|
let mut last = pieces[i].1;
|
||||||
|
let mut k = i + 1;
|
||||||
|
while k < pieces.len()
|
||||||
|
&& pieces[k].0 <= last + AHEAD_GAP
|
||||||
|
&& last.max(pieces[k].1) - first <= AHEAD_MAX
|
||||||
|
{
|
||||||
|
last = last.max(pieces[k].1);
|
||||||
|
k += 1;
|
||||||
|
}
|
||||||
|
ask_run(&pieces[i..k], &mut asked, &mut written, true);
|
||||||
|
i = k;
|
||||||
|
}
|
||||||
|
sort_merge_ahead(&mut asked);
|
||||||
note_hot(&written);
|
note_hot(&written);
|
||||||
let mut j = journal_mut();
|
let mut j = journal_mut();
|
||||||
// A number of its own, and the one this asking stands under: between
|
|
||||||
// the two parts another thread may have asked about a range of the
|
|
||||||
// second, copied it, and the title written it since. Under the first
|
|
||||||
// part's number that write was older than the copy, and never copied.
|
|
||||||
let now = next_asking();
|
let now = next_asking();
|
||||||
j.ahead_asked = now;
|
j.ahead_asked = now;
|
||||||
for (page, parts) in written {
|
for (page, parts) in written {
|
||||||
j.note(page, parts, now);
|
j.note(page, parts, now);
|
||||||
}
|
}
|
||||||
j.kept = !ahead.is_empty();
|
let kept = !asked.is_empty();
|
||||||
j.ahead = ahead;
|
j.kept = kept;
|
||||||
|
j.ahead = asked;
|
||||||
|
AHEAD_KEPT.store(kept, std::sync::atomic::Ordering::Release);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The submission's one asking stands no longer: its refreshes are done,
|
/// The submission's one asking stands no longer: its refreshes are done,
|
||||||
/// or title memory was written in a way the journal was not told.
|
/// or title memory was written in a way the journal was not told.
|
||||||
pub(crate) fn ask_once_end() {
|
pub(crate) fn ask_once_end() {
|
||||||
|
if !kept_active() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AHEAD_KEPT.store(false, std::sync::atomic::Ordering::Release);
|
||||||
let mut j = journal_mut();
|
let mut j = journal_mut();
|
||||||
if j.kept {
|
if j.kept {
|
||||||
j.kept = false;
|
j.kept = false;
|
||||||
@@ -634,10 +710,11 @@ fn elsewhere(at: usize, len: usize) -> Vec<(usize, Vec<usize>)> {
|
|||||||
|
|
||||||
/// One kernel asking for `pieces` (page ranges in order); by halves if it
|
/// One kernel asking for `pieces` (page ranges in order); by halves if it
|
||||||
/// fails, as a run across two reservations or into memory that is not
|
/// fails, as a run across two reservations or into memory that is not
|
||||||
/// write-watched does. A piece alone is left to [`writes`]. Adds what was
|
/// write-watched does. When `ask_single` is false, a piece alone is left to
|
||||||
/// asked to `asked` and the pages found written to `written`.
|
/// [`writes`]. Adds what was asked to `asked` and the pages found written to
|
||||||
fn ask_run(pieces: &[(usize, usize)], asked: &mut Vec<(usize, usize)>, written: &mut Vec<(usize, u16)>) {
|
/// `written`.
|
||||||
if pieces.len() < 2 {
|
fn ask_run(pieces: &[(usize, usize)], asked: &mut Vec<(usize, usize)>, written: &mut Vec<(usize, u16)>, ask_single: bool) {
|
||||||
|
if pieces.is_empty() || (!ask_single && pieces.len() < 2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let first = pieces[0].0;
|
let first = pieces[0].0;
|
||||||
@@ -647,9 +724,12 @@ fn ask_run(pieces: &[(usize, usize)], asked: &mut Vec<(usize, usize)>, written:
|
|||||||
asked.push((first, last));
|
asked.push((first, last));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if pieces.len() < 2 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let (a, b) = pieces.split_at(pieces.len() / 2);
|
let (a, b) = pieces.split_at(pieces.len() / 2);
|
||||||
ask_run(a, asked, written);
|
ask_run(a, asked, written, ask_single);
|
||||||
ask_run(b, asked, written);
|
ask_run(b, asked, written, ask_single);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// What [`writes`] would say of `[start, end)` from the journal alone, if
|
/// What [`writes`] would say of `[start, end)` from the journal alone, if
|
||||||
@@ -660,9 +740,7 @@ fn ask_run(pieces: &[(usize, usize)], asked: &mut Vec<(usize, usize)>, written:
|
|||||||
pub(crate) fn asked(start: usize, end: usize) -> Option<(u64, Vec<(usize, u64)>)> {
|
pub(crate) fn asked(start: usize, end: usize) -> Option<(u64, Vec<(usize, u64)>)> {
|
||||||
let (first, last) = (start / PAGE, end.div_ceil(PAGE));
|
let (first, last) = (start / PAGE, end.div_ceil(PAGE));
|
||||||
let j = journal();
|
let j = journal();
|
||||||
j.ahead
|
ahead_contains(&j.ahead, first, last)
|
||||||
.iter()
|
|
||||||
.any(|&(a, b)| a <= first && last <= b)
|
|
||||||
.then(|| (j.ahead_asked, j.written.range(first..last).map(|(&p, &w)| (p, w)).collect()))
|
.then(|| (j.ahead_asked, j.written.range(first..last).map(|(&p, &w)| (p, w)).collect()))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -679,9 +757,15 @@ pub(crate) fn writes(start: usize, end: usize, guarded: bool) -> Option<(u64, Ve
|
|||||||
materialize(start, end.saturating_sub(start));
|
materialize(start, end.saturating_sub(start));
|
||||||
}
|
}
|
||||||
let (first, last) = (start / PAGE, end.div_ceil(PAGE));
|
let (first, last) = (start / PAGE, end.div_ceil(PAGE));
|
||||||
let of = |j: &Journal| -> Vec<(usize, u64)> { j.written.range(first..last).map(|(&p, &w)| (p, w)).collect() };
|
let of = |j: &Journal| -> Vec<(usize, u64)> {
|
||||||
|
if first + 1 == last {
|
||||||
|
j.written.get(&first).map(|&w| vec![(first, w)]).unwrap_or_default()
|
||||||
|
} else {
|
||||||
|
j.written.range(first..last).map(|(&p, &w)| (p, w)).collect()
|
||||||
|
}
|
||||||
|
};
|
||||||
// Asked ahead with the submission's other ranges: the journal has it.
|
// Asked ahead with the submission's other ranges: the journal has it.
|
||||||
let ahead = |j: &Journal| j.ahead.iter().any(|&(a, b)| a <= first && last <= b).then(|| (j.ahead_asked, of(j)));
|
let ahead = |j: &Journal| ahead_contains(&j.ahead, first, last).then(|| (j.ahead_asked, of(j)));
|
||||||
if let Some(known) = ahead(&journal()) {
|
if let Some(known) = ahead(&journal()) {
|
||||||
return Some(known);
|
return Some(known);
|
||||||
}
|
}
|
||||||
@@ -750,29 +834,79 @@ pub(crate) fn writes(start: usize, end: usize, guarded: bool) -> Option<(u64, Ve
|
|||||||
Some(answer)
|
Some(answer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Like [`writes`], but returns `(asking, changed_since)` without allocating a
|
||||||
|
/// per-page vector on the hot fast paths (`ahead` or `published`).
|
||||||
|
pub(crate) fn writes_since(start: usize, end: usize, guarded: bool, since: u64) -> Option<(u64, bool)> {
|
||||||
|
if guarded && soft().is_none() {
|
||||||
|
materialize(start, end.saturating_sub(start));
|
||||||
|
}
|
||||||
|
let (first, last) = (start / PAGE, end.div_ceil(PAGE));
|
||||||
|
let newer = |j: &Journal| -> bool {
|
||||||
|
if since == 0 {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if first + 1 == last {
|
||||||
|
j.written.get(&first).is_some_and(|&w| w > since)
|
||||||
|
} else {
|
||||||
|
j.written.range(first..last).any(|(_, &w)| w > since)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
{
|
||||||
|
let j = journal();
|
||||||
|
if ahead_contains(&j.ahead, first, last) {
|
||||||
|
return Some((j.ahead_asked, newer(&j)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if guarded && published(start, end) {
|
||||||
|
#[cfg(feature = "diagnostics")]
|
||||||
|
{
|
||||||
|
tally(2, 1);
|
||||||
|
crate::faultbook::note(crate::faultbook::What::Known, first, last, 0);
|
||||||
|
}
|
||||||
|
let j = journal();
|
||||||
|
return Some((next_asking(), newer(&j)));
|
||||||
|
}
|
||||||
|
let (now, written) = writes(start, end, guarded)?;
|
||||||
|
let changed = since == 0 || written.iter().any(|&(_, w)| w > since);
|
||||||
|
Some((now, changed))
|
||||||
|
}
|
||||||
|
|
||||||
/// Whether nothing of `[start, end)` was written that a copy with the notes
|
/// Whether nothing of `[start, end)` was written that a copy with the notes
|
||||||
/// `copied` (the asking after which each page from page `base` on was taken)
|
/// `copied` (the asking after which each page from page `base` on was taken)
|
||||||
/// and `ranged` (the asking after which a range that holds this one was
|
/// and `ranged` (the asking after which a range that holds this one was
|
||||||
/// taken whole, or 0) does not hold, as [`writes`] would answer with nothing
|
/// taken whole, or 0) does not hold, as [`writes`] would answer with nothing
|
||||||
/// asked: the submission's asking covers the range, or its blocks are known
|
/// asked: the submission's asking covers the range, or its blocks are known
|
||||||
/// by their bits. `false` if something would have to be asked.
|
/// by their bits. `false` if something would have to be asked.
|
||||||
pub(crate) fn nothing_new(start: usize, end: usize, base: usize, copied: &[u64], ranged: u64) -> bool {
|
pub(crate) fn nothing_new_in(j: &JournalGuard, start: usize, end: usize, base: usize, copied: &[u64], ranged: u64) -> bool {
|
||||||
let (first, last) = (start / PAGE, end.div_ceil(PAGE));
|
let (first, last) = (start / PAGE, end.div_ceil(PAGE));
|
||||||
// The bits first, then the journal, as in `writes`.
|
let covered = {
|
||||||
let known = published(start, end);
|
#[cfg(feature = "diagnostics")]
|
||||||
#[cfg(feature = "diagnostics")]
|
{
|
||||||
if known {
|
let known = published(start, end);
|
||||||
crate::faultbook::note(crate::faultbook::What::Known, first, last, 1);
|
if known {
|
||||||
}
|
crate::faultbook::note(crate::faultbook::What::Known, first, last, 1);
|
||||||
let j = journal();
|
}
|
||||||
if !known && !j.ahead.iter().any(|&(a, b)| a <= first && last <= b) {
|
known || ahead_contains(&j.0.ahead, first, last)
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "diagnostics"))]
|
||||||
|
{
|
||||||
|
ahead_contains(&j.0.ahead, first, last) || published(start, end)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if !covered {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let Some(taken) = first.checked_sub(base).and_then(|from| copied.get(from..last - base)) else {
|
let Some(taken) = first.checked_sub(base).and_then(|from| copied.get(from..last - base)) else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
(ranged != 0 || taken.iter().all(|&at| at != 0))
|
if ranged == 0 && taken.iter().any(|&at| at == 0) {
|
||||||
&& j.written.range(first..last).all(|(&page, &write)| write <= taken[page - first].max(ranged))
|
return false;
|
||||||
|
}
|
||||||
|
if first + 1 == last {
|
||||||
|
j.0.written.get(&first).is_none_or(|&write| write <= taken[0].max(ranged))
|
||||||
|
} else {
|
||||||
|
j.0.written.range(first..last).all(|(&page, &write)| write <= taken[page - first].max(ranged))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tracked {
|
impl Tracked {
|
||||||
@@ -1466,7 +1600,7 @@ pub(crate) fn asks() -> [u64; 13] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The guards' lock, the wait for it counted.
|
/// The guards' lock, the wait for it counted.
|
||||||
fn guards_timed() -> std::sync::MutexGuard<'static, Guards> {
|
fn guards_timed() -> std::sync::RwLockWriteGuard<'static, Guards> {
|
||||||
#[cfg(feature = "diagnostics")]
|
#[cfg(feature = "diagnostics")]
|
||||||
let started = std::time::Instant::now();
|
let started = std::time::Instant::now();
|
||||||
let g = guards();
|
let g = guards();
|
||||||
@@ -1475,6 +1609,16 @@ fn guards_timed() -> std::sync::MutexGuard<'static, Guards> {
|
|||||||
g
|
g
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The guards' shared read lock, the wait for it counted.
|
||||||
|
fn guards_read_timed() -> std::sync::RwLockReadGuard<'static, Guards> {
|
||||||
|
#[cfg(feature = "diagnostics")]
|
||||||
|
let started = std::time::Instant::now();
|
||||||
|
let g = guards_read();
|
||||||
|
#[cfg(feature = "diagnostics")]
|
||||||
|
tally(7, started.elapsed().as_nanos() as u64);
|
||||||
|
g
|
||||||
|
}
|
||||||
|
|
||||||
/// A set of blocks, a bit each: a fault, or a look at a range of thousands of
|
/// A set of blocks, a bit each: a fault, or a look at a range of thousands of
|
||||||
/// blocks, is a few words of it and no walk through a tree of every guarded
|
/// blocks, is a few words of it and no walk through a tree of every guarded
|
||||||
/// block there is.
|
/// block there is.
|
||||||
@@ -1740,7 +1884,7 @@ impl Guards {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static GUARDS: Mutex<Guards> = Mutex::new(Guards {
|
static GUARDS: std::sync::RwLock<Guards> = std::sync::RwLock::new(Guards {
|
||||||
protected: Blocks::new(),
|
protected: Blocks::new(),
|
||||||
clean: Blocks::new(),
|
clean: Blocks::new(),
|
||||||
absent: Blocks::new(),
|
absent: Blocks::new(),
|
||||||
@@ -1754,17 +1898,29 @@ static GUARDS: Mutex<Guards> = Mutex::new(Guards {
|
|||||||
|
|
||||||
/// The guards' lock, with what faults opened without it settled first
|
/// The guards' lock, with what faults opened without it settled first
|
||||||
/// ([`settle`]).
|
/// ([`settle`]).
|
||||||
fn guards() -> std::sync::MutexGuard<'static, Guards> {
|
fn guards() -> std::sync::RwLockWriteGuard<'static, Guards> {
|
||||||
let mut g = match GUARDS.try_lock() {
|
let mut g = match GUARDS.try_write() {
|
||||||
Ok(g) => g,
|
Ok(g) => g,
|
||||||
// (Held by this, whoever panicked with it: not to be asked for again.)
|
// (Held by this, whoever panicked with it: not to be asked for again.)
|
||||||
Err(std::sync::TryLockError::Poisoned(e)) => e.into_inner(),
|
Err(std::sync::TryLockError::Poisoned(e)) => e.into_inner(),
|
||||||
Err(std::sync::TryLockError::WouldBlock) => waited(3, || GUARDS.lock().unwrap_or_else(|e| e.into_inner())),
|
Err(std::sync::TryLockError::WouldBlock) => waited(3, || GUARDS.write().unwrap_or_else(|e| e.into_inner())),
|
||||||
};
|
};
|
||||||
settle(&mut g);
|
settle(&mut g);
|
||||||
g
|
g
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Shared read lock on the guards, settling any unlocked faults first.
|
||||||
|
fn guards_read() -> std::sync::RwLockReadGuard<'static, Guards> {
|
||||||
|
if TO_SETTLE.load(std::sync::atomic::Ordering::SeqCst) != 0 {
|
||||||
|
drop(guards());
|
||||||
|
}
|
||||||
|
match GUARDS.try_read() {
|
||||||
|
Ok(g) => g,
|
||||||
|
Err(std::sync::TryLockError::Poisoned(e)) => e.into_inner(),
|
||||||
|
Err(std::sync::TryLockError::WouldBlock) => waited(3, || GUARDS.read().unwrap_or_else(|e| e.into_inner())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The 4 KiB pages of title memory that what shaders wrote was put into,
|
/// The 4 KiB pages of title memory that what shaders wrote was put into,
|
||||||
/// and the frame it last was: in pieces made when first needed and never let
|
/// and the frame it last was: in pieces made when first needed and never let
|
||||||
/// go. Some 20,000 pages a frame are noted by the relay and the landing
|
/// go. Some 20,000 pages a frame are noted by the relay and the landing
|
||||||
@@ -1958,7 +2114,7 @@ pub(crate) fn written_since_taken(at: usize, len: usize) -> bool {
|
|||||||
if len == 0 {
|
if len == 0 {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let g = guards();
|
let g = guards_read();
|
||||||
(at / BLOCK..=(at + len - 1) / BLOCK)
|
(at / BLOCK..=(at + len - 1) / BLOCK)
|
||||||
.all(|b| !g.clean.contains(b) && !g.absent.contains(b) && !g.protected.contains(b))
|
.all(|b| !g.clean.contains(b) && !g.absent.contains(b) && !g.protected.contains(b))
|
||||||
}
|
}
|
||||||
@@ -1978,7 +2134,7 @@ fn guard(start: usize, end: usize) -> Option<Vec<usize>> {
|
|||||||
let (first, last) = (start / BLOCK, end.div_ceil(BLOCK));
|
let (first, last) = (start / BLOCK, end.div_ceil(BLOCK));
|
||||||
let known = !*ASK.get_or_init(|| std::env::var_os("VICTORY_GUARD_ASK").is_some_and(|v| v == "1"))
|
let known = !*ASK.get_or_init(|| std::env::var_os("VICTORY_GUARD_ASK").is_some_and(|v| v == "1"))
|
||||||
&& (PROTECTED.any(first, first + 1) || {
|
&& (PROTECTED.any(first, first + 1) || {
|
||||||
let g = guards_timed();
|
let g = guards_read_timed();
|
||||||
g.protected.contains(first) || g.absent.contains(first)
|
g.protected.contains(first) || g.absent.contains(first)
|
||||||
});
|
});
|
||||||
if !known && !is_view(start, end) {
|
if !known && !is_view(start, end) {
|
||||||
@@ -1990,8 +2146,23 @@ fn guard(start: usize, end: usize) -> Option<Vec<usize>> {
|
|||||||
// other thread asks about it: `ASKING`); what the runtime tells meanwhile
|
// other thread asks about it: `ASKING`); what the runtime tells meanwhile
|
||||||
// takes the block out of the set, and it is looked at as any other.
|
// takes the block out of the set, and it is looked at as any other.
|
||||||
let unsure: Vec<usize> = {
|
let unsure: Vec<usize> = {
|
||||||
let g = guards_timed();
|
let g = guards_read_timed();
|
||||||
if g.clean.range(first..last).count() == last - first && !BESIDE.any(first, last) && !unsettled(first, last) {
|
// Fast path under shared read lock: every block in `first..last` is
|
||||||
|
// either clean (guarded, not BESIDE) or a known placeholder hole
|
||||||
|
// (`absent & held`), and none is OPENING/TOLD, so no VirtualQuery or
|
||||||
|
// write lock is needed.
|
||||||
|
let mut all_clean_or_held = true;
|
||||||
|
for word in first / 64..last.div_ceil(64) {
|
||||||
|
let mask = in_word(word * 64, first, last);
|
||||||
|
let ok = ((g.clean.word(word) & !BESIDE.word(word)) | (g.absent.word(word) & g.held.word(word)))
|
||||||
|
& !OPENING.word(word)
|
||||||
|
& !TOLD.word(word);
|
||||||
|
if (!ok & mask) != 0 {
|
||||||
|
all_clean_or_held = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if all_clean_or_held {
|
||||||
// Nothing written, mapped or new since the range was last taken.
|
// Nothing written, mapped or new since the range was last taken.
|
||||||
#[cfg(feature = "diagnostics")]
|
#[cfg(feature = "diagnostics")]
|
||||||
tally(3, 1);
|
tally(3, 1);
|
||||||
@@ -2538,12 +2709,15 @@ pub fn title_memory_written(at: usize, len: usize, pages: bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let mut g = guards();
|
let guarded = {
|
||||||
let guarded = g.protected.range(at / BLOCK..end.div_ceil(BLOCK)).count() as u64;
|
let g = guards_read();
|
||||||
|
g.protected.range(at / BLOCK..end.div_ceil(BLOCK)).count() as u64
|
||||||
|
};
|
||||||
if pages {
|
if pages {
|
||||||
WRITTEN[2].fetch_add(guarded, Relaxed);
|
WRITTEN[2].fetch_add(guarded, Relaxed);
|
||||||
}
|
}
|
||||||
if mode & 1 != 0 && guarded != 0 {
|
if mode & 1 != 0 && guarded != 0 {
|
||||||
|
let mut g = guards();
|
||||||
open(&mut g, at, end);
|
open(&mut g, at, end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2905,7 +3079,7 @@ fn allocation_end(at: usize, inside: usize) -> usize {
|
|||||||
|
|
||||||
/// Tells what keeps track of what title memory shows; the guards, with no
|
/// Tells what keeps track of what title memory shows; the guards, with no
|
||||||
/// block of the range known unmapped.
|
/// block of the range known unmapped.
|
||||||
fn title_memory_changed(at: usize, len: usize) -> std::sync::MutexGuard<'static, Guards> {
|
fn title_memory_changed(at: usize, len: usize) -> std::sync::RwLockWriteGuard<'static, Guards> {
|
||||||
// A placed texture there arrives, goes or changes with no descriptor
|
// A placed texture there arrives, goes or changes with no descriptor
|
||||||
// written.
|
// written.
|
||||||
crate::descriptor::host::remapped(at, len);
|
crate::descriptor::host::remapped(at, len);
|
||||||
@@ -3660,7 +3834,7 @@ mod tests {
|
|||||||
let (copied, _) = writes(p, p + 4 * PAGE, false).expect("watched");
|
let (copied, _) = writes(p, p + 4 * PAGE, false).expect("watched");
|
||||||
// SAFETY: committed pages of ours.
|
// SAFETY: committed pages of ours.
|
||||||
unsafe { ((p + PAGE) as *mut u8).write_volatile(1) };
|
unsafe { ((p + PAGE) as *mut u8).write_volatile(1) };
|
||||||
ask_rest(&ranges);
|
ask_once(&ranges);
|
||||||
let last = journal().written.get(&(p / PAGE + 1)).copied();
|
let last = journal().written.get(&(p / PAGE + 1)).copied();
|
||||||
ask_once_end();
|
ask_once_end();
|
||||||
assert!(last.is_some_and(|last| last > copied), "{last:?} is not after {copied}");
|
assert!(last.is_some_and(|last| last > copied), "{last:?} is not after {copied}");
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ pub(super) struct Convolver {
|
|||||||
impl Convolver {
|
impl Convolver {
|
||||||
/// `None` when the response is not in the layout described above.
|
/// `None` when the response is not in the layout described above.
|
||||||
pub(super) fn new(ir: &[f32]) -> Option<Self> {
|
pub(super) fn new(ir: &[f32]) -> Option<Self> {
|
||||||
if ir.is_empty() || ir.len() % N != 0 {
|
if ir.is_empty() || !ir.len().is_multiple_of(N) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let mut blocks = ir.len() / N;
|
let mut blocks = ir.len() / N;
|
||||||
|
|||||||
@@ -439,7 +439,7 @@ fn read_direct(file: &std::fs::File, out: &mut [u8], offset: u64) -> std::io::Re
|
|||||||
/// Read at a time.
|
/// Read at a time.
|
||||||
const MOST: usize = 1 << 20;
|
const MOST: usize = 1 << 20;
|
||||||
let sector = SECTOR as u64;
|
let sector = SECTOR as u64;
|
||||||
if offset % sector == 0 && out.len() % SECTOR == 0 && out.as_ptr() as usize % SECTOR == 0 {
|
if offset.is_multiple_of(sector) && out.len().is_multiple_of(SECTOR) && (out.as_ptr() as usize).is_multiple_of(SECTOR) {
|
||||||
return read_overlapped(file, out, offset);
|
return read_overlapped(file, out, offset);
|
||||||
}
|
}
|
||||||
thread_local! {
|
thread_local! {
|
||||||
@@ -2168,7 +2168,7 @@ mod tests {
|
|||||||
for round in 0..2 {
|
for round in 0..2 {
|
||||||
for mode in [Io::One, Io::Handles, Io::Overlapped, Io::Direct] {
|
for mode in [Io::One, Io::Handles, Io::Overlapped, Io::Direct] {
|
||||||
let file = Files::open_for_test(&path, mode);
|
let file = Files::open_for_test(&path, mode);
|
||||||
let at: Vec<u64> = (0..READS).map(|_| random() % (len - SIZE as u64) & !15).collect();
|
let at: Vec<u64> = (0..READS).map(|_| (random() % (len - SIZE as u64)) & !15).collect();
|
||||||
for pass in ["cold", "again"] {
|
for pass in ["cold", "again"] {
|
||||||
let next = std::sync::atomic::AtomicUsize::new(0);
|
let next = std::sync::atomic::AtomicUsize::new(0);
|
||||||
let busy = AtomicU64::new(0);
|
let busy = AtomicU64::new(0);
|
||||||
|
|||||||
@@ -3155,7 +3155,7 @@ mod tests {
|
|||||||
assert!(lazy(c));
|
assert!(lazy(c));
|
||||||
assert_eq!(map_pages(c, 3, std::ptr::null(), true), c);
|
assert_eq!(map_pages(c, 3, std::ptr::null(), true), c);
|
||||||
assert!(!lazy(c));
|
assert!(!lazy(c));
|
||||||
assert!(physical().views.get(&(c as usize)).is_none());
|
assert!(!physical().views.contains_key(&(c as usize)));
|
||||||
assert_eq!(host(c), MEM_RESERVE);
|
assert_eq!(host(c), MEM_RESERVE);
|
||||||
assert_eq!(map_pages(c, 3, pages.as_ptr(), false), c);
|
assert_eq!(map_pages(c, 3, pages.as_ptr(), false), c);
|
||||||
// SAFETY: mapped.
|
// SAFETY: mapped.
|
||||||
@@ -3166,7 +3166,7 @@ mod tests {
|
|||||||
assert_eq!(map_pages(d, 3, pages.as_ptr(), true), d);
|
assert_eq!(map_pages(d, 3, pages.as_ptr(), true), d);
|
||||||
assert_eq!(map_pages(at(d, 1), 1, std::ptr::null(), true), at(d, 1));
|
assert_eq!(map_pages(at(d, 1), 1, std::ptr::null(), true), at(d, 1));
|
||||||
assert!(lazy(d) && lazy(at(d, 2)));
|
assert!(lazy(d) && lazy(at(d, 2)));
|
||||||
assert!(physical().views.get(&(at(d, 1) as usize)).is_none());
|
assert!(!physical().views.contains_key(&(at(d, 1) as usize)));
|
||||||
assert!(materialize(at(d, 2) as usize, 1));
|
assert!(materialize(at(d, 2) as usize, 1));
|
||||||
assert!(!lazy(at(d, 2)) && lazy(d));
|
assert!(!lazy(at(d, 2)) && lazy(d));
|
||||||
// SAFETY: mapped now.
|
// SAFETY: mapped now.
|
||||||
@@ -3259,7 +3259,7 @@ mod tests {
|
|||||||
assert_eq!(read(heap, 1), ((true, 1), vec![2]));
|
assert_eq!(read(heap, 1), ((true, 1), vec![2]));
|
||||||
// Unmapped: gone, with no view of the host's ever there.
|
// Unmapped: gone, with no view of the host's ever there.
|
||||||
assert!(alias_as((heap + PAGE) as u64, 0, PAGE as u64, false, true));
|
assert!(alias_as((heap + PAGE) as u64, 0, PAGE as u64, false, true));
|
||||||
assert!(!lazy(heap + PAGE) && physical().views.get(&(heap + PAGE)).is_none());
|
assert!(!lazy(heap + PAGE) && !physical().views.contains_key(&(heap + PAGE)));
|
||||||
assert_eq!(soft_runs(heap, 4 * PAGE), [(heap, PAGE), (heap + 2 * PAGE, PAGE)]);
|
assert_eq!(soft_runs(heap, 4 * PAGE), [(heap, PAGE), (heap + 2 * PAGE, PAGE)]);
|
||||||
assert_eq!(read(heap + PAGE, 2 * PAGE).0, (false, PAGE));
|
assert_eq!(read(heap + PAGE, 2 * PAGE).0, (false, PAGE));
|
||||||
// The CPU touches one: the handler maps it with its page's bytes,
|
// The CPU touches one: the handler maps it with its page's bytes,
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ mod crash;
|
|||||||
pub mod frame_rate;
|
pub mod frame_rate;
|
||||||
pub mod prepare;
|
pub mod prepare;
|
||||||
pub(crate) mod publish;
|
pub(crate) mod publish;
|
||||||
|
pub mod resolution;
|
||||||
pub mod resolve;
|
pub mod resolve;
|
||||||
#[cfg(all(windows, feature = "diagnostics"))]
|
#[cfg(all(windows, feature = "diagnostics"))]
|
||||||
mod profile;
|
mod profile;
|
||||||
|
|||||||
@@ -0,0 +1,430 @@
|
|||||||
|
//! The title's output size and render scale (`VICTORY_OUTPUT`,
|
||||||
|
//! `VICTORY_RENDER_SCALE`, `VICTORY_FFX_SCALE`, `VICTORY_UPSCALER`; each off
|
||||||
|
//! without it): places
|
||||||
|
//! in the title's code changed at load, each compared byte for byte first
|
||||||
|
//! and left alone, said so, if it differs (another build of the title).
|
||||||
|
//!
|
||||||
|
//! What the title does (game_scarlett_master.exe 1.0.2.1, image offsets):
|
||||||
|
//!
|
||||||
|
//! - **Output size.** Its settings (`settings.xml` in its storage,
|
||||||
|
//! `video/resolutionFullscreen`, 3840x2160 as a Series X wrote it; read
|
||||||
|
//! into the live settings at +0x204/+0x208, the defaults' 1920x1080 at
|
||||||
|
//! +0x5b37a20 overwritten) are applied by +0x22434a0: from +0x224352b it
|
||||||
|
//! hands them to +0x2478130, the one writer of the screen size
|
||||||
|
//! (+0xa9438cc/+0xa9438d0), and when the height changes calls +0xd8c3a0.
|
||||||
|
//! The back buffers (+0x247ad10, by +0x501f4a0 and +0xcc2780) take that
|
||||||
|
//! size through the copy +0x5eb24f0 makes (+0x75e6fe0). The display mode
|
||||||
|
//! list it matches against is its own (+0x5a38910: 1280x720, 1664x936,
|
||||||
|
//! 1920x1080, 2560x1440, 3840x2160 at 60 Hz, table +0x615c0c0), not the
|
||||||
|
//! DXGI output's, which is why `VICTORY_DISPLAY_MODE` changes nothing.
|
||||||
|
//! Here that block becomes: write the size asked for into the settings
|
||||||
|
//! (+0x204/+0x208), then the title's own else-path (screen size set,
|
||||||
|
//! +0xd8c3a0 if the height changed). Everything that reads the settings
|
||||||
|
//! after it (the device parameters +0x1e0fb30, the render size +0x7b4e10)
|
||||||
|
//! sees the same size. The back buffers' pool (64 MB on Series X) is
|
||||||
|
//! checked to be used up but for 2 MB (+0x247af25, an `int3`); for another
|
||||||
|
//! size that check is jumped over.
|
||||||
|
//! - **Render scale.** The upscaler the title picks (+0x7e93f0: 6, its own,
|
||||||
|
//! except on Series S with a flag, 7, AMD FidelityFX) gives the render
|
||||||
|
//! size from the output size (+0x7e92f0 → the upscaler's +0x50 method):
|
||||||
|
//! its own (+0x7e9440) multiplies by a scale at +0x90 of it, set to 2/3 at
|
||||||
|
//! +0x28f1e78 (so 2560x1440 for 4K, 1280x720 for 1080p);
|
||||||
|
//! `VICTORY_RENDER_SCALE` replaces that constant (Series X; run res-4 at
|
||||||
|
//! 1.0). FidelityFX's (+0x28ef680, Series S) multiplies by 1.0 on Series X,
|
||||||
|
//! 2/3 on Series S; `VICTORY_FFX_SCALE` points its two loads at a constant
|
||||||
|
//! in its padding (as pull request #53 did). That one is not safe: at 0.5
|
||||||
|
//! on Series S (run res-6) FidelityFX's jitter phase count came back 0 and
|
||||||
|
//! the title divided by it (+0x28f03e8) 49 s in.
|
||||||
|
//! - **Upscaler.** `VICTORY_UPSCALER=<kind>` makes the picker return
|
||||||
|
//! `kind` (pull request #53): 6 the title's own, 7 FidelityFX.
|
||||||
|
|
||||||
|
use crate::frame_rate::Patched;
|
||||||
|
|
||||||
|
/// Sizes the title has a display mode for (its own list, +0x615c0c0).
|
||||||
|
pub const MODES: [(u32, u32); 5] = [(1280, 720), (1664, 936), (1920, 1080), (2560, 1440), (3840, 2160)];
|
||||||
|
|
||||||
|
/// `VICTORY_OUTPUT=<w>x<h>`: one of [`MODES`]. `None` if unset or not one
|
||||||
|
/// (said why).
|
||||||
|
pub fn asked_output() -> Option<(u32, u32)> {
|
||||||
|
let spec = std::env::var("VICTORY_OUTPUT").ok()?;
|
||||||
|
let size = parse_output(&spec);
|
||||||
|
if size.is_none() {
|
||||||
|
eprintln!("VIctory: VICTORY_OUTPUT={spec}: expected one of the title's modes: 1920x1080, 2560x1440, 1280x720, 1664x936, 3840x2160");
|
||||||
|
}
|
||||||
|
size
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_output(spec: &str) -> Option<(u32, u32)> {
|
||||||
|
let (w, h) = spec.trim().split_once(['x', 'X'])?;
|
||||||
|
let size = (w.trim().parse().ok()?, h.trim().parse().ok()?);
|
||||||
|
MODES.contains(&size).then_some(size)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `VICTORY_RENDER_SCALE=<s>`, 0.5 to 1.0 (0.5: half the output's width and
|
||||||
|
/// height): the title's own upscaler's scale (Series X; 2/3 without it).
|
||||||
|
/// Tested at 1.0 (run res-4); below 2/3 the title's largest render size
|
||||||
|
/// (+0x94, max(2/3, scale)) stays at 2/3. `None` if unset or out of range
|
||||||
|
/// (said why).
|
||||||
|
pub fn asked_render_scale() -> Option<f32> {
|
||||||
|
let spec = std::env::var("VICTORY_RENDER_SCALE").ok()?;
|
||||||
|
let scale = parse_render_scale(&spec);
|
||||||
|
if scale.is_none() {
|
||||||
|
eprintln!("VIctory: VICTORY_RENDER_SCALE={spec}: expected 0.5 to 1.0");
|
||||||
|
}
|
||||||
|
scale
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_render_scale(spec: &str) -> Option<f32> {
|
||||||
|
spec.trim().parse::<f32>().ok().filter(|s| (0.5..=1.0).contains(s))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `VICTORY_FFX_SCALE=<s>`, 0.5 to 1.0: FidelityFX's render scale (Series
|
||||||
|
/// S). Crashed at 0.5 (run res-6); see the module's notes.
|
||||||
|
pub fn asked_ffx_scale() -> Option<f32> {
|
||||||
|
let spec = std::env::var("VICTORY_FFX_SCALE").ok()?;
|
||||||
|
let scale = parse_render_scale(&spec);
|
||||||
|
if scale.is_none() {
|
||||||
|
eprintln!("VIctory: VICTORY_FFX_SCALE={spec}: expected 0.5 to 1.0");
|
||||||
|
}
|
||||||
|
scale
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `VICTORY_UPSCALER=<kind>`: 6 (the title's own) or 7 (FidelityFX).
|
||||||
|
pub fn asked_upscaler() -> Option<u32> {
|
||||||
|
let spec = std::env::var("VICTORY_UPSCALER").ok()?;
|
||||||
|
let kind = spec.trim().parse::<u32>().ok().filter(|k| matches!(k, 6 | 7));
|
||||||
|
if kind.is_none() {
|
||||||
|
eprintln!("VIctory: VICTORY_UPSCALER={spec}: expected 6 (the title's own) or 7 (FidelityFX)");
|
||||||
|
}
|
||||||
|
kind
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A place to change: its offset in the image and the bytes there
|
||||||
|
/// (compared first; the replacement is at most as long).
|
||||||
|
pub struct Site {
|
||||||
|
pub at: usize,
|
||||||
|
pub what: &'static str,
|
||||||
|
pub bytes: &'static [u8],
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The screen size setter, its screen height, and what +0x22434a0 calls when
|
||||||
|
/// the height changed.
|
||||||
|
pub const SET_SCREEN_SIZE: usize = 0x2478130;
|
||||||
|
pub const SCREEN_HEIGHT: usize = 0xa9438d0;
|
||||||
|
pub const HEIGHT_CHANGED: usize = 0xd8c3a0;
|
||||||
|
|
||||||
|
/// +0x22434a0 from +0x224352b to +0x2243568: the settings' size handed to
|
||||||
|
/// the screen size.
|
||||||
|
pub const OUTPUT: Site = Site {
|
||||||
|
at: 0x224352b,
|
||||||
|
what: "settings' output size applied",
|
||||||
|
bytes: &[
|
||||||
|
0x8b, 0x0d, 0x9b, 0x03, 0x70, 0x08, // mov ecx, [+0xa9438cc]
|
||||||
|
0x8b, 0x86, 0x04, 0x02, 0x00, 0x00, // mov eax, [rsi+204h]
|
||||||
|
0x39, 0xc1, 0x75, 0x0d, // cmp ecx, eax ; jne
|
||||||
|
0x8b, 0x96, 0x08, 0x02, 0x00, 0x00, // mov edx, [rsi+208h]
|
||||||
|
0xe8, 0xea, 0x4b, 0x23, 0x00, 0xeb, 0x20, // call +0x2478130 ; jmp +0x2243568
|
||||||
|
0x8b, 0xbe, 0x08, 0x02, 0x00, 0x00, // mov edi, [rsi+208h]
|
||||||
|
0x8b, 0x2d, 0x7c, 0x03, 0x70, 0x08, // mov ebp, [+0xa9438d0]
|
||||||
|
0x89, 0xc1, 0x89, 0xfa, // mov ecx, eax ; mov edx, edi
|
||||||
|
0xe8, 0xd3, 0x4b, 0x23, 0x00, // call +0x2478130
|
||||||
|
0x39, 0xfd, 0x74, 0x07, 0xb1, 0x01, // cmp ebp, edi ; je ; mov cl, 1
|
||||||
|
0xe8, 0x38, 0x8e, 0xb4, 0xfe, // call +0xd8c3a0
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
/// +0x247ad10, after the back buffers are made in their pool (64 MB on
|
||||||
|
/// Series X, 82 MB on Series S, from +0x247ad45): `int3` unless less than
|
||||||
|
/// 2 MB of the pool is left over. Sized for 3840x2160; at 1920x1080 49 MB
|
||||||
|
/// are left (run res-1 stopped here). With another output size the check
|
||||||
|
/// becomes a jump over the `int3`; the pool stays as large.
|
||||||
|
pub const POOL_CHECK: Site = Site {
|
||||||
|
at: 0x247af25,
|
||||||
|
what: "back buffer pool's left-over check",
|
||||||
|
bytes: &[0x48, 0x3d, 0xff, 0xff, 0x1f, 0x00, 0x76, 0x01, 0xcc], // cmp rax, 1FFFFFh ; jbe +1 ; int3
|
||||||
|
};
|
||||||
|
|
||||||
|
/// What goes at [`POOL_CHECK`]: `jmp +1` in place of `jbe +1`.
|
||||||
|
pub fn pool_check_code() -> Vec<u8> {
|
||||||
|
let mut c = POOL_CHECK.bytes[..8].to_vec();
|
||||||
|
c[6] = 0xeb;
|
||||||
|
c
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The title's own upscaler, its method +0x28f1e70: `mov dword [rcx+90h],
|
||||||
|
/// 2/3` (the scale +0x7e9440 renders at).
|
||||||
|
pub const OWN_SCALE: Site = Site {
|
||||||
|
at: 0x28f1e78,
|
||||||
|
what: "the title's own upscaler's render scale",
|
||||||
|
bytes: &[0xc7, 0x81, 0x90, 0x00, 0x00, 0x00, 0xab, 0xaa, 0x2a, 0x3f],
|
||||||
|
};
|
||||||
|
|
||||||
|
/// FidelityFX's render size method, +0x28ef680, and its padding: the scale
|
||||||
|
/// is 1.0 (+0x5fc6ed8) or, on Series S, 2/3 (+0x615d95c), loaded at +0x28
|
||||||
|
/// and +0x32.
|
||||||
|
pub const FFX_SCALE: Site = Site {
|
||||||
|
at: 0x28ef680,
|
||||||
|
what: "FidelityFX's render scale",
|
||||||
|
bytes: &[
|
||||||
|
0x41, 0x56, 0x56, 0x57, 0x53, 0x48, 0x83, 0xec, 0x28, 0x44, 0x89, 0xcb, 0x4c, 0x89, 0xc6, 0x48, 0x89, 0xd7, 0x49, 0x89,
|
||||||
|
0xce, 0xe8, 0xa6, 0x5a, 0x78, 0xfd, 0x0f, 0xb6, 0xc0, 0x41, 0x89, 0x86, 0x90, 0x00, 0x00, 0x00, 0x84, 0xc0, 0x75, 0x0a,
|
||||||
|
0xc5, 0xfa, 0x10, 0x05, 0x28, 0x78, 0x6d, 0x03, 0xeb, 0x08, 0xc5, 0xfa, 0x10, 0x05, 0xa2, 0xe2, 0x86, 0x03, 0xc5, 0xf2,
|
||||||
|
0x2a, 0x54, 0x24, 0x70, 0xc5, 0xf2, 0x2a, 0xcb, 0xc5, 0xfa, 0x59, 0xc9, 0xc5, 0xfa, 0x2c, 0xc1, 0x89, 0x07, 0xc5, 0xfa,
|
||||||
|
0x59, 0xc2, 0xc5, 0xfa, 0x2c, 0xc0, 0x89, 0x06, 0x48, 0x83, 0xc4, 0x28, 0x5b, 0x5f, 0x5e, 0x41, 0x5e, 0xc3, 0xcc, 0xcc,
|
||||||
|
0xcc, 0xcc, 0xcc, 0xcc,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
/// The upscaler picker, +0x7e93f0, to its first `ret`.
|
||||||
|
pub const PICKER: Site = Site {
|
||||||
|
at: 0x7e93f0,
|
||||||
|
what: "upscaler picker",
|
||||||
|
bytes: &[
|
||||||
|
0x48, 0x83, 0xec, 0x28, 0x80, 0x3d, 0x6d, 0xf0, 0x3a, 0x07, 0x00, 0x75, 0x09, 0x83, 0x3d, 0x68, 0xf0, 0x3a, 0x07, 0x00,
|
||||||
|
0x74, 0x28, 0xe8, 0x35, 0xbd, 0x88, 0xff, 0x8a, 0x0d, 0x5b, 0xf0, 0x3a, 0x07, 0x80, 0xe1, 0x40, 0x80, 0xf9, 0x01, 0xb9,
|
||||||
|
0x07, 0x00, 0x00, 0x00, 0x83, 0xd9, 0x00, 0x84, 0xc0, 0xb8, 0x06, 0x00, 0x00, 0x00, 0x0f, 0x45, 0xc1, 0x48, 0x83, 0xc4,
|
||||||
|
0x28, 0xc3,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
/// `rel32` from the end of an instruction at image offset `next` to `to`.
|
||||||
|
fn rel(to: usize, next: usize) -> [u8; 4] {
|
||||||
|
((to as i64 - next as i64) as i32).to_le_bytes()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What goes at [`OUTPUT`] for `width` x `height` (the same length).
|
||||||
|
pub fn output_code(width: u32, height: u32) -> Vec<u8> {
|
||||||
|
let at = OUTPUT.at;
|
||||||
|
let mut c = Vec::with_capacity(OUTPUT.bytes.len());
|
||||||
|
c.push(0xb8); // mov eax, width
|
||||||
|
c.extend(width.to_le_bytes());
|
||||||
|
c.extend([0x89, 0x86, 0x04, 0x02, 0x00, 0x00]); // mov [rsi+204h], eax
|
||||||
|
c.push(0xbf); // mov edi, height
|
||||||
|
c.extend(height.to_le_bytes());
|
||||||
|
c.extend([0x89, 0xbe, 0x08, 0x02, 0x00, 0x00]); // mov [rsi+208h], edi
|
||||||
|
c.extend([0x8b, 0x2d]); // mov ebp, [screen height]
|
||||||
|
c.extend(rel(SCREEN_HEIGHT, at + c.len() + 4));
|
||||||
|
c.extend([0x89, 0xc1, 0x89, 0xfa]); // mov ecx, eax ; mov edx, edi
|
||||||
|
c.push(0xe8); // call the setter
|
||||||
|
c.extend(rel(SET_SCREEN_SIZE, at + c.len() + 4));
|
||||||
|
let end = OUTPUT.bytes.len();
|
||||||
|
c.extend([0x39, 0xfd, 0x74, (end - (c.len() + 4)) as u8]); // cmp ebp, edi ; je end
|
||||||
|
c.extend([0xb1, 0x01, 0xe8]); // mov cl, 1 ; call
|
||||||
|
c.extend(rel(HEIGHT_CHANGED, at + c.len() + 4));
|
||||||
|
c.extend([0xeb, (end - (c.len() + 2)) as u8]); // jmp end
|
||||||
|
c.resize(end, 0xcc);
|
||||||
|
c
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What goes at [`OWN_SCALE`] for `scale`.
|
||||||
|
pub fn own_scale_code(scale: f32) -> Vec<u8> {
|
||||||
|
let mut c = OWN_SCALE.bytes[..6].to_vec();
|
||||||
|
c.extend(scale.to_le_bytes());
|
||||||
|
c
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What goes at [`FFX_SCALE`] for `scale`: both loads read `scale`, written
|
||||||
|
/// into the padding at +0x64.
|
||||||
|
pub fn ffx_scale_code(scale: f32) -> Vec<u8> {
|
||||||
|
const LOADS: [usize; 2] = [0x28, 0x32];
|
||||||
|
const SLOT: usize = 0x64;
|
||||||
|
let mut c = FFX_SCALE.bytes.to_vec();
|
||||||
|
c[SLOT..SLOT + 4].copy_from_slice(&scale.to_le_bytes());
|
||||||
|
for l in LOADS {
|
||||||
|
c[l + 4..l + 8].copy_from_slice(&((SLOT - (l + 8)) as i32).to_le_bytes());
|
||||||
|
}
|
||||||
|
c
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `mov eax, kind ; ret`.
|
||||||
|
pub fn picker_code(kind: u32) -> Vec<u8> {
|
||||||
|
let mut c = vec![0xb8];
|
||||||
|
c.extend(kind.to_le_bytes());
|
||||||
|
c.push(0xc3);
|
||||||
|
c
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Compares `site`'s bytes in the image of `size` bytes at `base`.
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
/// The image is mapped.
|
||||||
|
pub unsafe fn matches(base: usize, size: usize, site: &Site) -> Patched {
|
||||||
|
if site.at.checked_add(site.bytes.len()).is_none_or(|end| end > size) {
|
||||||
|
return Patched::Failed("outside the image");
|
||||||
|
}
|
||||||
|
// SAFETY: inside the mapped image (checked above).
|
||||||
|
let there = unsafe { std::slice::from_raw_parts((base + site.at) as *const u8, site.bytes.len()) };
|
||||||
|
if there == site.bytes { Patched::Done } else { Patched::Differs }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Writes `code` over `site` if its bytes are the expected ones.
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
/// The image stays mapped and no thread runs its code yet.
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub unsafe fn write(base: usize, size: usize, site: &Site, code: &[u8]) -> Patched {
|
||||||
|
use windows_sys::Win32::System::Diagnostics::Debug::FlushInstructionCache;
|
||||||
|
use windows_sys::Win32::System::Memory::{PAGE_EXECUTE_READWRITE, VirtualProtect};
|
||||||
|
use windows_sys::Win32::System::Threading::GetCurrentProcess;
|
||||||
|
if code.len() > site.bytes.len() {
|
||||||
|
return Patched::Failed("replacement longer than the bytes compared");
|
||||||
|
}
|
||||||
|
// SAFETY: the caller's promise.
|
||||||
|
let found = unsafe { matches(base, size, site) };
|
||||||
|
if found != Patched::Done {
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
let at = base + site.at;
|
||||||
|
let mut old = 0;
|
||||||
|
// SAFETY: inside the image (checked); made writable for this and put
|
||||||
|
// back; nothing runs it yet.
|
||||||
|
unsafe {
|
||||||
|
if VirtualProtect(at as *const _, code.len(), PAGE_EXECUTE_READWRITE, &mut old) == 0 {
|
||||||
|
return Patched::Failed("Windows would not make it writable");
|
||||||
|
}
|
||||||
|
std::ptr::copy_nonoverlapping(code.as_ptr(), at as *mut u8, code.len());
|
||||||
|
VirtualProtect(at as *const _, code.len(), old, &mut old);
|
||||||
|
FlushInstructionCache(GetCurrentProcess(), at as *const _, code.len());
|
||||||
|
}
|
||||||
|
Patched::Done
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Applies what the switches ask for; a line each in the log and on
|
||||||
|
/// standard output.
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
/// The image of `size` bytes at `base` stays mapped and no thread runs its
|
||||||
|
/// code yet.
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub unsafe fn apply_asked(base: usize, size: usize) {
|
||||||
|
let mut asked: Vec<(&Site, Vec<u8>, String)> = Vec::new();
|
||||||
|
if let Some((w, h)) = asked_output() {
|
||||||
|
asked.push((&OUTPUT, output_code(w, h), format!("{w}x{h}")));
|
||||||
|
if (w, h) != (3840, 2160) {
|
||||||
|
asked.push((&POOL_CHECK, pool_check_code(), format!("{w}x{h}")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(s) = asked_render_scale() {
|
||||||
|
asked.push((&OWN_SCALE, own_scale_code(s), format!("{s}")));
|
||||||
|
}
|
||||||
|
if let Some(s) = asked_ffx_scale() {
|
||||||
|
asked.push((&FFX_SCALE, ffx_scale_code(s), format!("{s}")));
|
||||||
|
}
|
||||||
|
if let Some(kind) = asked_upscaler() {
|
||||||
|
asked.push((&PICKER, picker_code(kind), format!("returns {kind}")));
|
||||||
|
}
|
||||||
|
for (site, code, value) in asked {
|
||||||
|
// SAFETY: the caller's promise.
|
||||||
|
let done = unsafe { write(base, size, site, &code) };
|
||||||
|
let offset = format!("{:#x}", site.at);
|
||||||
|
match done {
|
||||||
|
Patched::Done => tracing::info!(site = %offset, what = site.what, value, "resolution: patched"),
|
||||||
|
Patched::Differs => tracing::warn!(site = %offset, what = site.what, "resolution: not patched, the title's bytes there are not the ones expected (another build?)"),
|
||||||
|
Patched::Failed(why) => tracing::warn!(site = %offset, what = site.what, why, "resolution: not patched"),
|
||||||
|
}
|
||||||
|
println!("resolution: {} ({value}) at title+{offset}: {done:?}", site.what);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn switches_parse() {
|
||||||
|
assert_eq!(parse_output("1920x1080"), Some((1920, 1080)));
|
||||||
|
assert_eq!(parse_output(" 2560X1440 "), Some((2560, 1440)));
|
||||||
|
assert_eq!(parse_output("1600x900"), None);
|
||||||
|
assert_eq!(parse_output("1080p"), None);
|
||||||
|
assert_eq!(parse_render_scale("0.67"), Some(0.67));
|
||||||
|
assert_eq!(parse_render_scale("0.5"), Some(0.5));
|
||||||
|
assert_eq!(parse_render_scale("1"), Some(1.0));
|
||||||
|
assert_eq!(parse_render_scale("0.4"), None);
|
||||||
|
assert_eq!(parse_render_scale("1.5"), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The calls and loads in the bytes compared are the ones the
|
||||||
|
/// replacement keeps.
|
||||||
|
#[test]
|
||||||
|
fn the_output_block_is_the_titles() {
|
||||||
|
let b = OUTPUT.bytes;
|
||||||
|
assert_eq!(b.len(), 61);
|
||||||
|
let target = |op_end: usize| (OUTPUT.at + op_end) as i64 + i64::from(i32::from_le_bytes(b[op_end - 4..op_end].try_into().unwrap()));
|
||||||
|
assert_eq!(target(27), SET_SCREEN_SIZE as i64);
|
||||||
|
assert_eq!(target(50), SET_SCREEN_SIZE as i64);
|
||||||
|
assert_eq!(target(61), HEIGHT_CHANGED as i64);
|
||||||
|
assert_eq!(target(41), SCREEN_HEIGHT as i64);
|
||||||
|
assert_eq!(target(6), (SCREEN_HEIGHT - 4) as i64, "the width before it");
|
||||||
|
// jne to the else path at 29; jmp +0x20 and je +7 both land at the end.
|
||||||
|
assert_eq!((b[14], 16 + b[15] as usize), (0x75, 29));
|
||||||
|
assert_eq!((b[27], 29 + b[28] as usize), (0xeb, 61));
|
||||||
|
assert_eq!((b[52], 54 + b[53] as usize), (0x74, 61));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_output_code_keeps_the_titles_else_path() {
|
||||||
|
let c = output_code(1920, 1080);
|
||||||
|
assert_eq!(c.len(), OUTPUT.bytes.len());
|
||||||
|
assert_eq!(c[0], 0xb8);
|
||||||
|
assert_eq!(c[1..5], 1920u32.to_le_bytes());
|
||||||
|
assert_eq!(c[5..11], [0x89, 0x86, 0x04, 0x02, 0x00, 0x00]);
|
||||||
|
assert_eq!(c[12..16], 1080u32.to_le_bytes());
|
||||||
|
assert_eq!(c[16..22], [0x89, 0xbe, 0x08, 0x02, 0x00, 0x00]);
|
||||||
|
let target = |op_end: usize| (OUTPUT.at + op_end) as i64 + i64::from(i32::from_le_bytes(c[op_end - 4..op_end].try_into().unwrap()));
|
||||||
|
assert_eq!(c[22..24], [0x8b, 0x2d]);
|
||||||
|
assert_eq!(target(28), SCREEN_HEIGHT as i64);
|
||||||
|
assert_eq!(c[32], 0xe8);
|
||||||
|
assert_eq!(target(37), SET_SCREEN_SIZE as i64);
|
||||||
|
assert_eq!(c[37..40], [0x39, 0xfd, 0x74]);
|
||||||
|
assert_eq!(41 + c[40] as usize, 61, "je lands at the end");
|
||||||
|
assert_eq!(c[43], 0xe8);
|
||||||
|
assert_eq!(target(48), HEIGHT_CHANGED as i64);
|
||||||
|
assert_eq!(c[48], 0xeb);
|
||||||
|
assert_eq!(50 + c[49] as usize, 61, "jmp lands at the end");
|
||||||
|
assert!(c[50..].iter().all(|&x| x == 0xcc));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_scale_codes() {
|
||||||
|
let own = own_scale_code(0.5);
|
||||||
|
assert_eq!(own[..6], OWN_SCALE.bytes[..6]);
|
||||||
|
assert_eq!(own[6..], 0.5f32.to_le_bytes());
|
||||||
|
assert_eq!(OWN_SCALE.bytes[6..], (2.0f32 / 3.0).to_le_bytes());
|
||||||
|
let ffx = ffx_scale_code(0.75);
|
||||||
|
assert_eq!(ffx.len(), FFX_SCALE.bytes.len());
|
||||||
|
assert_eq!(ffx[0x64..0x68], 0.75f32.to_le_bytes());
|
||||||
|
for at in [0x28, 0x32] {
|
||||||
|
assert_eq!(ffx[at..at + 4], [0xc5, 0xfa, 0x10, 0x05], "vmovss xmm0, [rip+d]");
|
||||||
|
let disp = i32::from_le_bytes(ffx[at + 4..at + 8].try_into().unwrap());
|
||||||
|
assert_eq!(at as i32 + 8 + disp, 0x64);
|
||||||
|
}
|
||||||
|
// Only the two displacements and the padding change.
|
||||||
|
let changed: Vec<usize> = (0..ffx.len()).filter(|&i| ffx[i] != FFX_SCALE.bytes[i]).collect();
|
||||||
|
assert!(changed.iter().all(|&i| (0x2c..0x30).contains(&i) || (0x36..0x3a).contains(&i) || (0x64..0x68).contains(&i)));
|
||||||
|
assert_eq!(picker_code(7), [0xb8, 7, 0, 0, 0, 0xc3]);
|
||||||
|
assert_eq!(pool_check_code(), [0x48, 0x3d, 0xff, 0xff, 0x1f, 0x00, 0xeb, 0x01]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
#[test]
|
||||||
|
fn a_site_is_written_only_over_its_bytes() {
|
||||||
|
use windows_sys::Win32::System::Memory::{MEM_COMMIT, MEM_RELEASE, MEM_RESERVE, PAGE_EXECUTE_READ, VirtualAlloc, VirtualFree};
|
||||||
|
// SAFETY: fresh memory of our own, read-only to code as the image's is.
|
||||||
|
unsafe {
|
||||||
|
let place = VirtualAlloc(std::ptr::null(), 0x1000, MEM_COMMIT | MEM_RESERVE, 0x40) as *mut u8;
|
||||||
|
assert!(!place.is_null());
|
||||||
|
let site = Site { at: 0x100, what: "test", bytes: OWN_SCALE.bytes };
|
||||||
|
std::ptr::copy_nonoverlapping(site.bytes.as_ptr(), place.add(0x100), site.bytes.len());
|
||||||
|
let mut old = 0;
|
||||||
|
windows_sys::Win32::System::Memory::VirtualProtect(place.cast(), 0x1000, PAGE_EXECUTE_READ, &mut old);
|
||||||
|
assert_eq!(write(place as usize, 0x1000, &site, &own_scale_code(0.5)), Patched::Done);
|
||||||
|
assert_eq!(std::slice::from_raw_parts(place.add(0x106), 4), 0.5f32.to_le_bytes());
|
||||||
|
// Already changed: its bytes differ now, nothing is written again.
|
||||||
|
assert_eq!(write(place as usize, 0x1000, &site, &own_scale_code(0.75)), Patched::Differs);
|
||||||
|
assert_eq!(std::slice::from_raw_parts(place.add(0x106), 4), 0.5f32.to_le_bytes());
|
||||||
|
let far = Site { at: 0xffa, what: "test", bytes: OWN_SCALE.bytes };
|
||||||
|
assert!(matches!(write(place as usize, 0x1000, &far, &own_scale_code(0.5)), Patched::Failed(_)));
|
||||||
|
VirtualFree(place.cast(), 0, MEM_RELEASE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -346,7 +346,7 @@ mod tests {
|
|||||||
let list = format!("other.dll {:x}\nT.dll 0x{at:x}\nt.dll {at:x}\nt.dll 5\nt.dll\n", at);
|
let list = format!("other.dll {:x}\nT.dll 0x{at:x}\nt.dll {at:x}\nt.dll 5\nt.dll\n", at);
|
||||||
assert_eq!(apply("t.dll", second, 0x1000, &list), 1);
|
assert_eq!(apply("t.dll", second, 0x1000, &list), 1);
|
||||||
assert_eq!(std::ptr::read((second + at) as *const u8), 0xe9);
|
assert_eq!(std::ptr::read((second + at) as *const u8), 0xe9);
|
||||||
let (plain, changed): (F, F) = (std::mem::transmute(place), std::mem::transmute(second));
|
let (plain, changed) = (std::mem::transmute::<usize, F>(place), std::mem::transmute::<usize, F>(second));
|
||||||
for was in 0..=255u8 {
|
for was in 0..=255u8 {
|
||||||
let mut bytes = [[0u8; 0x40]; 2];
|
let mut bytes = [[0u8; 0x40]; 2];
|
||||||
bytes[0][0x31] = was;
|
bytes[0][0x31] = was;
|
||||||
@@ -422,7 +422,7 @@ mod tests {
|
|||||||
if size == 0 {
|
if size == 0 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let (plain, changed): (F, F) = (std::mem::transmute(place), std::mem::transmute(second));
|
let (plain, changed) = (std::mem::transmute::<usize, F>(place), std::mem::transmute::<usize, F>(second));
|
||||||
let data = VirtualAlloc(std::ptr::null(), 4096, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) as *mut u8;
|
let data = VirtualAlloc(std::ptr::null(), 4096, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) as *mut u8;
|
||||||
for seed in 0..200u64 {
|
for seed in 0..200u64 {
|
||||||
let value = seed.wrapping_mul(0x9e37_79b9_7f4a_7c15);
|
let value = seed.wrapping_mul(0x9e37_79b9_7f4a_7c15);
|
||||||
|
|||||||
@@ -511,7 +511,11 @@ fn translate_plain(container: &[u8]) -> Result<HostShader, ShaderError> {
|
|||||||
emit(&c, &native, &p, &st, &io, &res)
|
emit(&c, &native, &p, &st, &io, &res)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Emits a program whose earlier stages already ran.
|
/// Emits a program whose earlier stages already ran ([`emit_once`]). A wave64 compute program
|
||||||
|
/// that does not translate with the branches that close or leave its loops taken by each host
|
||||||
|
/// wave together ([`loops_wave`]) is tried once more without them, as before that step: the
|
||||||
|
/// underwater picture's program (`926c46bab3b86bd6`) translated before it and no longer did, so
|
||||||
|
/// its dispatch was dropped and diving showed a field of white flares (#539, #570).
|
||||||
pub fn emit(
|
pub fn emit(
|
||||||
c: &Container,
|
c: &Container,
|
||||||
native: &NativeProgram,
|
native: &NativeProgram,
|
||||||
@@ -519,6 +523,38 @@ pub fn emit(
|
|||||||
st: &structure::Structured,
|
st: &structure::Structured,
|
||||||
io: &io::Io,
|
io: &io::Io,
|
||||||
res: &resource::Resources,
|
res: &resource::Resources,
|
||||||
|
) -> Result<HostShader, ShaderError> {
|
||||||
|
let first = emit_once(c, native, p, st, io, res);
|
||||||
|
if !matches!(first, Err(ShaderError::Unsupported { .. })) || !loops_wave(native) {
|
||||||
|
return first;
|
||||||
|
}
|
||||||
|
LOOPS_OFF.with(|off| off.set(true));
|
||||||
|
let again = emit_once(c, native, p, st, io, res);
|
||||||
|
LOOPS_OFF.with(|off| off.set(false));
|
||||||
|
match again {
|
||||||
|
Ok(shader) => {
|
||||||
|
if std::env::var_os("VICTORY_WAVE_WHY").is_some() {
|
||||||
|
eprintln!("WAVE-LOOPS left out: the program translates without them");
|
||||||
|
}
|
||||||
|
Ok(shader)
|
||||||
|
}
|
||||||
|
Err(_) => first,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
thread_local! {
|
||||||
|
/// [`emit`]'s second try: [`loops_wave`] off.
|
||||||
|
static LOOPS_OFF: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One try of [`emit`].
|
||||||
|
fn emit_once(
|
||||||
|
c: &Container,
|
||||||
|
native: &NativeProgram,
|
||||||
|
p: &ir::Program,
|
||||||
|
st: &structure::Structured,
|
||||||
|
io: &io::Io,
|
||||||
|
res: &resource::Resources,
|
||||||
) -> Result<HostShader, ShaderError> {
|
) -> Result<HostShader, ShaderError> {
|
||||||
// (what an earlier program's lowering on this thread left behind)
|
// (what an earlier program's lowering on this thread left behind)
|
||||||
lower::take_needs();
|
lower::take_needs();
|
||||||
@@ -903,7 +939,7 @@ fn widen(
|
|||||||
/// - `2`: every compute program;
|
/// - `2`: every compute program;
|
||||||
/// - `0`: none, as before.
|
/// - `0`: none, as before.
|
||||||
fn loops_wave(native: &NativeProgram) -> bool {
|
fn loops_wave(native: &NativeProgram) -> bool {
|
||||||
if native.stage != HwStage::Cs {
|
if native.stage != HwStage::Cs || LOOPS_OFF.with(std::cell::Cell::get) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
match std::env::var("VICTORY_LOOPS_WAVE").ok().as_deref().map(str::trim) {
|
match std::env::var("VICTORY_LOOPS_WAVE").ok().as_deref().map(str::trim) {
|
||||||
|
|||||||
@@ -0,0 +1,190 @@
|
|||||||
|
# Troubleshooting Guide (6 GB VRAM / 16 GB RAM & Windows)
|
||||||
|
|
||||||
|
> Back to main setup guide: **[README.md](../README.md)** · Detailed memory notes: **[windows-memory.md](windows-memory.md)** · DLSS/FG details: **[dlss.md](dlss.md)**
|
||||||
|
|
||||||
|
## Quick Jump
|
||||||
|
|
||||||
|
- [1. Out of Memory / Crashes on 16 GB RAM (32–48 GB SSD Pagefile Setup)](#1-out-of-memory--crashes-on-16-gb-ram-3248-gb-ssd-pagefile-setup)
|
||||||
|
- [2. Wrong or Broken F1 Settings (How to Reset)](#2-wrong-or-broken-f1-settings-how-to-reset)
|
||||||
|
- [3. Graphics & Lighting Issues (Blinding Sun, Indoor Flashing, White Dots, Blurry Image, Missing Heads)](#3-graphics--lighting-issues)
|
||||||
|
- [4. Low FPS, Stuttering, Input Lag, & Laptop Thermal Throttling](#4-low-fps-stuttering-input-lag--laptop-thermal-throttling)
|
||||||
|
- [5. DLSS or FSR 3 Frame Generation Not Working](#5-dlss-or-fsr-3-frame-generation-not-working)
|
||||||
|
- [6. Build, Git Pull, Windows 10, & Launch Errors](#6-build-git-pull-windows-10--launch-errors)
|
||||||
|
- [7. Shader Preloading (`-Preload`) & Pop-In in New Areas](#7-shader-preloading--pop-in-in-new-areas)
|
||||||
|
- [8. Collecting Logs for Bug Reports](#8-collecting-logs-for-bug-reports)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Out of Memory / Crashes on 16 GB RAM (32–48 GB SSD Pagefile Setup)
|
||||||
|
|
||||||
|
Open-world texture and buffer streaming temporarily reserves more virtual commit than 16 GB of physical RAM. If Windows' pagefile is too small, the emulator will crash with `E_OUTOFMEMORY` or exit during loading.
|
||||||
|
|
||||||
|
### Step-by-Step: Set a 32–48 GB Custom SSD Pagefile
|
||||||
|
1. Press **`Win + R`**, type **`sysdm.cpl`**, and press **Enter**.
|
||||||
|
2. Open the **Advanced** tab → under **Performance**, click **Settings…**.
|
||||||
|
3. Open the **Advanced** tab → under **Virtual memory**, click **Change…**.
|
||||||
|
4. Uncheck **Automatically manage paging file size for all drives**.
|
||||||
|
5. Select your fastest **SSD** (C: or D: with at least 60 GB free).
|
||||||
|
6. Select **Custom size**:
|
||||||
|
- **Initial size (MB):** `32768` *(32 GB)*
|
||||||
|
- **Maximum size (MB):** `49152` *(48 GB)*
|
||||||
|
7. Click **Set** → **OK** → **OK** → **Restart your PC**.
|
||||||
|
|
||||||
|
### Verify It Worked
|
||||||
|
- Open **Task Manager** (`Ctrl + Shift + Esc`) → **Performance** → **Memory**.
|
||||||
|
- Check **Committed**: the right-hand limit should now show **48–64 GB** (16 GB RAM + 32–48 GB pagefile).
|
||||||
|
- Before launching, close heavy background apps (Chrome/Edge tabs, Discord, IDEs) to maximize free physical RAM.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Wrong or Broken F1 Settings (How to Reset)
|
||||||
|
|
||||||
|
Changes saved in the **F1** menu are written to `victory-settings.txt` and **override the launcher script on every future launch**. If you accidentally turned off lighting, broke resolution, or switched to blurry settings:
|
||||||
|
|
||||||
|
- **In-game (easiest):** Press **`F1`**, scroll to **`RESET ALL TO PLAY DEFAULTS`**, and press **Enter**. *(Do NOT press `SAVE AND RESTART NOW` if you want to discard bad changes.)*
|
||||||
|
- **Outside the game:** Delete the saved settings file and relaunch:
|
||||||
|
```powershell
|
||||||
|
Remove-Item "$env:LOCALAPPDATA\victory\victory-settings.txt" -ErrorAction SilentlyContinue
|
||||||
|
# If you set VICTORY_HOME (for example D:\victory):
|
||||||
|
Remove-Item "$env:VICTORY_HOME\victory-settings.txt" -ErrorAction SilentlyContinue
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Graphics & Lighting Issues
|
||||||
|
|
||||||
|
### Pitch-black character / dark rooms indoors with glowing eyes
|
||||||
|
- **Cause:** `LIGHT ESTIMATE` (`VICTORY_AMBIENT`) and/or `REFLECTION ESTIMATE` (`VICTORY_AMBIENT_SPECULAR`) was saved as OFF in `victory-settings.txt`.
|
||||||
|
- **Fix:** Reset F1 settings to defaults (see [Section 2](#2-wrong-or-broken-f1-settings-how-to-reset)). `play-6gb.ps1` uses `VICTORY_AMBIENT=0.65` and `VICTORY_AMBIENT_SPECULAR=1`.
|
||||||
|
|
||||||
|
### Sunlight looks blinding / overexposed
|
||||||
|
- **Cause:** `VICTORY_AMBIENT` set too high (`0.8`–`1.0`).
|
||||||
|
- **Fix:** Lower **`LIGHT ESTIMATE`** in F1 (or set `VICTORY_AMBIENT=0.65` / `0.55`).
|
||||||
|
|
||||||
|
### Indoor rooms flashing / strobing bright and dark
|
||||||
|
- **Cause:** `VICTORY_AMBIENT_ONCE=1` can oscillate frame-to-frame indoors where there is little direct light.
|
||||||
|
- **Fix:** Do **not** set `VICTORY_AMBIENT_ONCE=1`. Use the default `play-6gb.ps1` settings (`VICTORY_AMBIENT=0.65`, `VICTORY_AMBIENT_ONCE` unset).
|
||||||
|
|
||||||
|
### White dots / specular fireflies / violet tint
|
||||||
|
- **Cause:** Skipping screen-probe or reflection shaders via extra hashes in `VICTORY_LEAVE_OUT`.
|
||||||
|
- **Fix:** Only leave out the 2 safe passes (`VICTORY_LEAVE_OUT=02384a60fda6f2d0,731a39171b568298`), which is already default in `play-6gb.ps1`. If shiny surfaces still show bright speckles, toggle **`REFLECTION ESTIMATE`** in F1.
|
||||||
|
|
||||||
|
### Image looks very blurry or textures look muddy
|
||||||
|
- **Cause:** Running `640x360` DLSS Ultra Performance (`-Dlss ultraperformance`) and/or Quarter textures (`-DropMips 2`).
|
||||||
|
- **Fix:** Use the sharp 1080p default (`960x540` DLSS Performance + Half textures):
|
||||||
|
```powershell
|
||||||
|
powershell -ExecutionPolicy Bypass -File scripts\play-6gb.ps1 -Exe 'D:\path\to\your.exe' -Dlss performance -DropMips 1
|
||||||
|
```
|
||||||
|
You can also change **`SERIES S PICTURE`** (`960X540` / `1113X626` / `1280X720`) and **`TEXTURE SCALE (VRAM)`** (`HALF (6GB GPU)`) in F1.
|
||||||
|
|
||||||
|
### Missing character heads or disappearing geometry
|
||||||
|
- **Cause:** `VICTORY_THIN=1` (`THIN LISTS = 1` in F1) can drop geometry/heads on some builds and increases RAM usage on 16 GB PCs.
|
||||||
|
- **Fix:** Keep **`THIN LISTS`** set to **`0`** (`VICTORY_THIN=0`, default in `play-6gb.ps1`).
|
||||||
|
|
||||||
|
### Dark/blocky patches on water
|
||||||
|
- **Cause:** `WATER LIGHT` turned off, or outdated shader cache from an older build.
|
||||||
|
- **Fix:** Keep **`WATER LIGHT: ON`** in F1 (`VICTORY_WATER_LIGHT=1`).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Low FPS, Stuttering, Input Lag, & Laptop Thermal Throttling
|
||||||
|
|
||||||
|
### Laptop FPS starts fine (~10–12 real / 20–24 FG) then drops after 15–20 minutes
|
||||||
|
- **Cause:** Thermal throttling — once a gaming laptop heatsink saturates at **85–86 °C**, CPU turbo clocks drop by 30–40%, directly lowering FPS.
|
||||||
|
- **Fix:**
|
||||||
|
- Always play plugged into **AC power**.
|
||||||
|
- Switch your OEM control app (Lenovo Vantage / Armoury Crate / NitroSense / OMEN) to **Performance Mode** (`Fn + Q`) with **Max / Performance fan curve**.
|
||||||
|
- Elevate the back of the laptop 1–2 cm (or use a cooling pad) so bottom intake vents breathe freely.
|
||||||
|
|
||||||
|
### Low FPS on Intel 12th–14th Gen hybrid CPUs (P-cores + E-cores)
|
||||||
|
- **Cause:** Pinning worker threads exclusively to P-cores (`VICTORY_FAST_CORES=2`) starves the submission and recording threads on 4P+4E / 6P+4E CPUs.
|
||||||
|
- **Fix:** Keep **`VICTORY_FAST_CORES=0`** (already default in `play-6gb.ps1` — typically +13% to +16% real FPS on hybrid CPUs).
|
||||||
|
|
||||||
|
### Stuttering while roaming on 6 GB VRAM GPUs
|
||||||
|
- **Cause:** VRAM exceeding your DXGI local budget (~5.0–5.2 GB on 6 GB cards), causing Windows (WDDM) to spill textures over PCIe into system RAM.
|
||||||
|
- **Fix:**
|
||||||
|
- Press **`F3`** to watch the `VRAM X.X / Y.Y GB` readout — keep usage comfortably below the budget (`4.2–4.8 GB`).
|
||||||
|
- Keep `DropMips=1` with `WINDOWS_BAR_MB=128–256` (default in `play-6gb.ps1`), or drop to `-DropMips 2` (`QUARTER` in F1) on 4 GB cards.
|
||||||
|
- Ensure `VICTORY_SLOT_EVICT_PERCENT` (`92`) stays strictly higher than `VICTORY_TEXTURE_ROOM_PERCENT` (`82–85`) so eviction doesn't thrash every second.
|
||||||
|
|
||||||
|
### Sluggish controls / input lag with Frame Generation ON
|
||||||
|
- **Cause:** Frame Generation adds ~1 frame of presentation latency (noticeable when base real FPS is ~10 fps).
|
||||||
|
- **Fix:** Launch with **`-NoFrameGen`** or set **`FRAME GENERATION: OFF`** in F1 for lowest input latency:
|
||||||
|
```powershell
|
||||||
|
powershell -ExecutionPolicy Bypass -File scripts\play-6gb.ps1 -Exe 'D:\path\to\your.exe' -NoFrameGen
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. DLSS or FSR 3 Frame Generation Not Working
|
||||||
|
|
||||||
|
- **Missing DLLs:** Make sure you ran the one-time download scripts from inside the repository folder:
|
||||||
|
```powershell
|
||||||
|
.\Get-NVIDIA-DLSS.cmd
|
||||||
|
.\Get-AMD-FSR.cmd
|
||||||
|
```
|
||||||
|
- **Window not focused:** Both DLSS FG and FSR 3 FG only generate interpolated frames while the game window is the active focused window.
|
||||||
|
- **RTX 20 / 30 or AMD / Intel GPU:** Use **AMD FSR 3 (`-FgType fsr`, default in `play-6gb.ps1`)** for 2X Frame Generation. Native DLSS Frame Generation (`-FgType dlss`) requires **RTX 40 / 50** plus **Hardware-Accelerated GPU Scheduling (HAGS)** enabled in *Windows Settings → System → Display → Graphics → Default graphics settings*.
|
||||||
|
- **Do not enable `MFG UNLOCKER` on RTX 20/30:** Multi-Frame Generation unlocker only applies to RTX 40/50 DLSS FG.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. Build, Git Pull, Windows 10, & Launch Errors
|
||||||
|
|
||||||
|
### PowerShell says "running scripts is disabled on this system"
|
||||||
|
Always launch with `-ExecutionPolicy Bypass`:
|
||||||
|
```powershell
|
||||||
|
powershell -ExecutionPolicy Bypass -File scripts\play-6gb.ps1 -Exe 'D:\path\to\your.exe'
|
||||||
|
```
|
||||||
|
|
||||||
|
### `cargo build` fails with `linker 'link.exe' not found` or missing Windows SDK
|
||||||
|
1. Open **Visual Studio Installer** → **Modify** Visual Studio Build Tools.
|
||||||
|
2. Check **"Desktop development with C++"** (ensure **MSVC v143 build tools** and **Windows 10/11 SDK** are checked on the right).
|
||||||
|
3. Install, close PowerShell, open a **new** PowerShell window, and retry.
|
||||||
|
|
||||||
|
### Ran `git pull`, but nothing changed in-game
|
||||||
|
`scripts\play-6gb.ps1` only builds automatically when `target\release\victory.exe` does not exist yet. After pulling new code, always rebuild:
|
||||||
|
```powershell
|
||||||
|
git pull origin main
|
||||||
|
cargo build --release --locked -j 4 -p victory
|
||||||
|
```
|
||||||
|
|
||||||
|
### Windows 10 DX12 / Shader Model 6.6 error on startup
|
||||||
|
Run the Agility SDK helper script once and update your GPU driver:
|
||||||
|
```powershell
|
||||||
|
powershell -ExecutionPolicy Bypass -File scripts\get-d3d12.ps1
|
||||||
|
```
|
||||||
|
|
||||||
|
### C: drive running out of disk space (shader cache / saves)
|
||||||
|
Move caches, saves, settings, and logs to another drive (e.g. `D:\victory`) once, then open a new PowerShell window:
|
||||||
|
```powershell
|
||||||
|
setx VICTORY_HOME D:\victory
|
||||||
|
```
|
||||||
|
|
||||||
|
### "Game file (.exe) not found"
|
||||||
|
Wrap paths containing spaces in single quotes:
|
||||||
|
```powershell
|
||||||
|
powershell -ExecutionPolicy Bypass -File scripts\play-6gb.ps1 -Exe 'D:\My Folder\your.exe'
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. Shader Preloading (`-Preload`) & Pop-In in New Areas
|
||||||
|
|
||||||
|
- Every shader translated during gameplay is automatically cached on disk (`%LOCALAPPDATA%\victory\cache\shaders` or `$env:VICTORY_HOME\cache\shaders`), so areas you have already visited load cleanly on future runs.
|
||||||
|
- When entering **brand-new areas** for the first time, new shaders compile in the background (capped at 50 ms/frame by `VICTORY_PIPELINE_WAIT_MS=50` to avoid 500 ms freezes, which can briefly cause objects to pop in).
|
||||||
|
- To translate all shaders ahead of time once (~10–20 minutes on a laptop CPU, eliminates new-area pop-in; does not change steady FPS in already-cached areas):
|
||||||
|
```powershell
|
||||||
|
powershell -ExecutionPolicy Bypass -File scripts\play-6gb.ps1 -Exe 'D:\path\to\your.exe' -Preload
|
||||||
|
```
|
||||||
|
Or select **`PRELOAD SHADERS (RESTARTS THE GAME)`** in the F1 menu.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. Collecting Logs for Bug Reports
|
||||||
|
|
||||||
|
If you hit a crash, freeze, or graphical bug, capture a log with `-LogFile` and share the last ~100 lines along with your CPU, GPU, RAM, Windows version, and a screenshot of the **`F3`** stats panel:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
powershell -ExecutionPolicy Bypass -File scripts\play-6gb.ps1 -Exe 'D:\path\to\your.exe' -LogFile D:\victory.log
|
||||||
|
```
|
||||||
@@ -0,0 +1,265 @@
|
|||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Portable launcher tuned for 6-8 GB VRAM GPUs and 16 GB RAM PCs (windowed by default).
|
||||||
|
.EXAMPLE
|
||||||
|
powershell -ExecutionPolicy Bypass -File scripts\play-6gb.ps1 -Exe 'D:\path\to\your.exe'
|
||||||
|
.EXAMPLE
|
||||||
|
powershell -ExecutionPolicy Bypass -File scripts\play-6gb.ps1 -Exe 'D:\path\to\your.exe' -NoFrameGen
|
||||||
|
#>
|
||||||
|
param(
|
||||||
|
[string]$Exe = '',
|
||||||
|
[ValidateSet('1080', '936', '720')][string]$Output = '1080',
|
||||||
|
[ValidateSet('ultraperformance', 'performance', 'balanced', 'quality', 'dlaa', 'off')][string]$Dlss = 'performance',
|
||||||
|
[ValidateRange(0, 2)][int]$DropMips = 1,
|
||||||
|
[switch]$FrameGen,
|
||||||
|
[switch]$NoFrameGen,
|
||||||
|
[ValidateSet('fsr', 'dlss', 'auto')][string]$FgType = 'fsr',
|
||||||
|
[ValidateRange(2, 6)][int]$FrameGenX = 2,
|
||||||
|
[switch]$Preload,
|
||||||
|
[string]$LogFile = ''
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = 'Continue'
|
||||||
|
$repo = Split-Path -Parent $PSScriptRoot
|
||||||
|
$victory = Join-Path $repo 'target\release\victory.exe'
|
||||||
|
$homeDir = if ($env:VICTORY_HOME) { $env:VICTORY_HOME } else { Join-Path $env:LOCALAPPDATA 'victory' }
|
||||||
|
$cacheDir = Join-Path $homeDir 'cache'
|
||||||
|
$dataDir = Join-Path $homeDir 'data'
|
||||||
|
$menuFile = Join-Path $homeDir 'victory-settings.txt'
|
||||||
|
$slDir = if ($env:VICTORY_STREAMLINE_DIR) { $env:VICTORY_STREAMLINE_DIR } else { Join-Path $repo 'nvidia-sdk\Streamline\bin\x64' }
|
||||||
|
$fxDir = if ($env:VICTORY_FIDELITYFX_DIR) { $env:VICTORY_FIDELITYFX_DIR } else { Join-Path $repo 'amd-sdk\FidelityFX\bin' }
|
||||||
|
|
||||||
|
# Resolve game file (.exe) from -Exe, VICTORY_GAME_DIR, or victory.toml
|
||||||
|
if (-not $Exe -and $env:VICTORY_GAME_DIR -and (Test-Path -LiteralPath $env:VICTORY_GAME_DIR)) {
|
||||||
|
$cand = Get-ChildItem -LiteralPath $env:VICTORY_GAME_DIR -Filter '*.exe' -File -ErrorAction SilentlyContinue | Sort-Object Length -Descending | Select-Object -First 1
|
||||||
|
if ($cand) { $Exe = $cand.FullName }
|
||||||
|
}
|
||||||
|
if (-not $Exe) {
|
||||||
|
$toml = Join-Path $repo 'victory.toml'
|
||||||
|
if (Test-Path -LiteralPath $toml) {
|
||||||
|
$m = Select-String -Path $toml -Pattern '^\s*game_dir\s*=\s*"([^"]+)"' | Select-Object -First 1
|
||||||
|
if ($m -and (Test-Path -LiteralPath $m.Matches[0].Groups[1].Value)) {
|
||||||
|
$cand = Get-ChildItem -LiteralPath $m.Matches[0].Groups[1].Value -Filter '*.exe' -File -ErrorAction SilentlyContinue | Sort-Object Length -Descending | Select-Object -First 1
|
||||||
|
if ($cand) { $Exe = $cand.FullName }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (-not $Exe -or -not (Test-Path -LiteralPath $Exe)) {
|
||||||
|
Write-Host 'Game file (.exe) not found. Pass it with -Exe:'
|
||||||
|
Write-Host " powershell -ExecutionPolicy Bypass -File scripts\play-6gb.ps1 -Exe 'D:\path\to\your.exe'"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Build release binary automatically on first run
|
||||||
|
if (-not (Test-Path -LiteralPath $victory)) {
|
||||||
|
Write-Host 'Building release binary (first run only, takes a few minutes)...'
|
||||||
|
Push-Location $repo
|
||||||
|
try {
|
||||||
|
& cargo build --release --locked -j 4 -p victory
|
||||||
|
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||||
|
} finally {
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
New-Item -ItemType Directory -Force $cacheDir | Out-Null
|
||||||
|
New-Item -ItemType Directory -Force $dataDir | Out-Null
|
||||||
|
|
||||||
|
# Read saved F1 menu overrides
|
||||||
|
$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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$seriesS = $true
|
||||||
|
$res = '1080to1440'
|
||||||
|
$sRes = if ($Dlss -eq 'ultraperformance') { '360' } elseif ($Dlss -eq 'balanced') { '626' } elseif ($Dlss -eq 'quality') { '720' } elseif ($Dlss -eq 'dlaa') { '1080' } else { '540' }
|
||||||
|
$dlssMode = $Dlss
|
||||||
|
$fgOn = if ($NoFrameGen) { $false } else { $true }
|
||||||
|
$timesWanted = $FrameGenX
|
||||||
|
$fgKind = $FgType
|
||||||
|
$fpsWanted = 1000
|
||||||
|
|
||||||
|
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_S_RES'] -in '1080', '720', '626', '540', '360') { $sRes = $menu['VICTORY_MENU_S_RES'] }
|
||||||
|
if ($menu['VICTORY_MENU_DLSS'] -in 'off', 'dlaa', 'quality', 'balanced', 'performance', 'ultraperformance') { $dlssMode = $menu['VICTORY_MENU_DLSS'] }
|
||||||
|
if ($seriesS -and $dlssMode -ne 'off' -and $menu.Contains('VICTORY_MENU_S_RES')) {
|
||||||
|
$sMap = @{ '1080' = 'dlaa'; '720' = 'quality'; '626' = 'balanced'; '540' = 'performance'; '360' = 'ultraperformance' }
|
||||||
|
if ($sMap.ContainsKey($sRes)) { $dlssMode = $sMap[$sRes] }
|
||||||
|
}
|
||||||
|
if ($menu.Contains('VICTORY_MENU_FRAMEGEN')) {
|
||||||
|
$fgOn = $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_FG_TYPE'] -in 'auto', 'dlss', 'fsr') { $fgKind = $menu['VICTORY_MENU_FG_TYPE'] }
|
||||||
|
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 = [ordered]@{
|
||||||
|
VICTORY_CACHE_DIR = $cacheDir
|
||||||
|
VICTORY_DATA_DIR = $dataDir
|
||||||
|
VICTORY_LOG = 'info'
|
||||||
|
|
||||||
|
# CPU threading & submission (FAST_CORES=0 uses both P+E cores on hybrid CPUs)
|
||||||
|
VICTORY_THIN = '0'
|
||||||
|
VICTORY_ASYNC_SUBMIT = '1'
|
||||||
|
VICTORY_JOIN_PARTS = '8'
|
||||||
|
VICTORY_RELAY = '2'
|
||||||
|
VICTORY_RELAY_COPY = '1'
|
||||||
|
VICTORY_WIDE_BACK = '1'
|
||||||
|
VICTORY_CARD_REHASH_RUNS = '1'
|
||||||
|
VICTORY_JOIN_COPIES = '1'
|
||||||
|
VICTORY_CARD_STEPS = '2'
|
||||||
|
VICTORY_CARD_AWAKE = '1'
|
||||||
|
VICTORY_CARD_BUFFERS_MIN_KB = '64'
|
||||||
|
VICTORY_CARD_BUFFERS_MB = '1280'
|
||||||
|
VICTORY_CARD_ROOM_FOR_TARGETS_MB = '1024'
|
||||||
|
VICTORY_CARD_WINDOWS_MB = '0'
|
||||||
|
VICTORY_PORT_CONSTANTS = '1'
|
||||||
|
VICTORY_INDIRECT_WINDOW = '1'
|
||||||
|
VICTORY_INDIRECT_BATCH = '2'
|
||||||
|
VICTORY_UPLOAD_AHEAD = '1'
|
||||||
|
VICTORY_SHOW_AFTER = '1'
|
||||||
|
VICTORY_MAP_THREADS = '1'
|
||||||
|
VICTORY_FAST_CORES = '0'
|
||||||
|
VICTORY_INPLACE = '1'
|
||||||
|
VICTORY_INPLACE_MB = '512'
|
||||||
|
VICTORY_TEXSPK_PASS_MS = '8'
|
||||||
|
VICTORY_PASSES_HOT = '1'
|
||||||
|
VICTORY_HELPER_PRIORITY = '1'
|
||||||
|
VICTORY_WC_NO_BACK = '1'
|
||||||
|
VICTORY_WC_NO_BACK_MIN_KB = '1024'
|
||||||
|
VICTORY_SOFT_VIEWS = 'copies'
|
||||||
|
VICTORY_COPY_BESIDE = '1'
|
||||||
|
VICTORY_STORE_BESIDE = '1'
|
||||||
|
VICTORY_WINDOWS_VRAM_PERCENT = '80'
|
||||||
|
|
||||||
|
# Texture streaming + 6 GB VRAM mip scale
|
||||||
|
VICTORY_TEXTURE_POOL = '1'
|
||||||
|
VICTORY_RIPE_BLOCKS = '0'
|
||||||
|
VICTORY_TEXTURE_NO_WAIT = '1'
|
||||||
|
VICTORY_TEXTURE_CATCHUP = '0'
|
||||||
|
VICTORY_TEXTURE_STAGE_MS = '16'
|
||||||
|
VICTORY_LEVELS_ON_DEMAND = '0'
|
||||||
|
VICTORY_PRELUDE_UPLOADS = '1'
|
||||||
|
VICTORY_SHOW_NEW_LATER = '1'
|
||||||
|
VICTORY_POOL_SMALL = '0'
|
||||||
|
VICTORY_TABLED_REREAD = '1'
|
||||||
|
VICTORY_QUEUE_HOST_TEXTURES = '0'
|
||||||
|
VICTORY_TEXTURE_DROP_MIPS = [string]$DropMips
|
||||||
|
|
||||||
|
# Descriptor heap fast sync
|
||||||
|
VICTORY_HEAP_SYNC_FIRST = '1'
|
||||||
|
VICTORY_SYNC_IN_PLACE = '1'
|
||||||
|
VICTORY_SPANS_QUICK = '1'
|
||||||
|
VICTORY_SYNC_FINE = '1'
|
||||||
|
VICTORY_HEAP_SYNC_AT_SUBMIT = '1'
|
||||||
|
|
||||||
|
# Visuals (windowed by default; toggleable in F1 menu)
|
||||||
|
VICTORY_AMBIENT = '0.8'
|
||||||
|
VICTORY_AMBIENT_AIR = '1.5'
|
||||||
|
VICTORY_AMBIENT_SHADE = '0.5,0.5'
|
||||||
|
VICTORY_AMBIENT_SPECULAR = '1'
|
||||||
|
VICTORY_WATER_LIGHT = '1'
|
||||||
|
VICTORY_EARLY_DEPTH = '1'
|
||||||
|
VICTORY_LEAVE_OUT = '02384a60fda6f2d0,731a39171b568298'
|
||||||
|
|
||||||
|
# Pipeline caching + short wait cap to prevent 500 ms shader-compile freezes
|
||||||
|
VICTORY_PIPELINE_BOOK = '1'
|
||||||
|
VICTORY_PIPELINE_WAIT_MS = '50'
|
||||||
|
|
||||||
|
# Memory stack (SLOT_EVICT sits just above ROOM% so idle textures evict cleanly when roaming)
|
||||||
|
VICTORY_SLOT_EVICT = '1'
|
||||||
|
VICTORY_SLOT_EVICT_PERCENT = '88'
|
||||||
|
VICTORY_SLOT_EVICT_LOW_PERCENT = '78'
|
||||||
|
VICTORY_ALLOCATOR_TRIM = '1'
|
||||||
|
VICTORY_BUDGET_PACK = '1'
|
||||||
|
VICTORY_TEARING = '1'
|
||||||
|
VICTORY_FPS_LINE = '1'
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($Output -eq '936') { $settings['VICTORY_OUTPUT'] = '1664x936' }
|
||||||
|
elseif ($Output -eq '720') { $settings['VICTORY_OUTPUT'] = '1280x720' }
|
||||||
|
|
||||||
|
if (-not $seriesS) {
|
||||||
|
if ($res -eq '1440') { $settings['VICTORY_NATIVE_1440P'] = '1' }
|
||||||
|
elseif ($res -eq '1080to1440') { $settings['VICTORY_RENDER_1080P'] = '1' }
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($dlssMode -ne 'off' -and (Test-Path (Join-Path $slDir 'sl.interposer.dll'))) {
|
||||||
|
$settings['VICTORY_DLSS'] = '1'
|
||||||
|
$settings['VICTORY_DLSS_MODE'] = $dlssMode
|
||||||
|
$settings['VICTORY_STREAMLINE_DIR'] = $slDir
|
||||||
|
}
|
||||||
|
|
||||||
|
$barMb = if ($DropMips -ge 2) { '768' } elseif ($fgOn) { '128' } else { '256' }
|
||||||
|
$roomPct = if ($DropMips -ge 2) { if ($fgOn) { '75' } else { '78' } } else { '86' }
|
||||||
|
|
||||||
|
if ($dlssMode -ne 'off' -and $fgOn) {
|
||||||
|
if ($fgKind -ne 'dlss' -and (Test-Path (Join-Path $fxDir 'amd_fidelityfx_framegeneration_dx12.dll'))) {
|
||||||
|
$settings['VICTORY_FSR_FRAMEGEN'] = '1'
|
||||||
|
$settings['VICTORY_FIDELITYFX_DIR'] = $fxDir
|
||||||
|
$settings['VICTORY_FRAMEGEN_X'] = [string]$timesWanted
|
||||||
|
$settings['VICTORY_TEXTURE_ROOM_PERCENT'] = $roomPct
|
||||||
|
$settings['VICTORY_WINDOWS_BAR_MB'] = $barMb
|
||||||
|
} elseif ($fgKind -eq 'dlss') {
|
||||||
|
$settings['VICTORY_FRAMEGEN'] = '1'
|
||||||
|
$settings['VICTORY_FRAMEGEN_X'] = [string]$timesWanted
|
||||||
|
$settings['VICTORY_TEXTURE_ROOM_PERCENT'] = $roomPct
|
||||||
|
$settings['VICTORY_WINDOWS_BAR_MB'] = $barMb
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$settings['VICTORY_TEXTURE_ROOM_PERCENT'] = $roomPct
|
||||||
|
$settings['VICTORY_WINDOWS_BAR_MB'] = $barMb
|
||||||
|
}
|
||||||
|
|
||||||
|
$settings['VICTORY_FRAME_INTERVAL_US'] = [string][int][math]::Round(1000000 / $fpsWanted)
|
||||||
|
|
||||||
|
# Apply saved F1 menu overrides
|
||||||
|
foreach ($k in $menu.Keys) {
|
||||||
|
if ($k -like 'VICTORY_MENU_*') { continue }
|
||||||
|
if ($menu[$k]) { $settings[$k] = $menu[$k] } else { $settings.Remove($k) }
|
||||||
|
}
|
||||||
|
|
||||||
|
$console = if ($seriesS) { 'series-s' } else { 'series-x' }
|
||||||
|
$settings['VICTORY_MENU_CONSOLE'] = $console
|
||||||
|
$settings['VICTORY_MENU_RES'] = $res
|
||||||
|
$settings['VICTORY_MENU_S_RES'] = $sRes
|
||||||
|
$settings['VICTORY_MENU_DLSS'] = if ($settings.Contains('VICTORY_DLSS')) { $dlssMode } else { 'off' }
|
||||||
|
$settings['VICTORY_MENU_FRAMEGEN'] = if ($settings.Contains('VICTORY_FSR_FRAMEGEN') -or $settings.Contains('VICTORY_FRAMEGEN')) { [string]$timesWanted } else { '0' }
|
||||||
|
$settings['VICTORY_MENU_FG_TYPE'] = $fgKind
|
||||||
|
$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 "'", "''")'"
|
||||||
|
|
||||||
|
Get-ChildItem Env:VICTORY_* -ErrorAction SilentlyContinue | ForEach-Object { Remove-Item "Env:$($_.Name)" }
|
||||||
|
foreach ($k in $settings.Keys) { Set-Item "Env:$k" $settings[$k] }
|
||||||
|
|
||||||
|
Write-Host "Launching VIctory (6 GB VRAM / 16 GB RAM preset)..."
|
||||||
|
Write-Host " Window: $(if ($settings['VICTORY_OUTPUT']) { $settings['VICTORY_OUTPUT'] } else { '1920x1080' }) | Console: $console | DLSS: $($settings['VICTORY_MENU_DLSS']) | FG: $($settings['VICTORY_MENU_FRAMEGEN'])x ($fgKind) | DropMips: $($settings['VICTORY_TEXTURE_DROP_MIPS'])"
|
||||||
|
Write-Host " Home: $homeDir"
|
||||||
|
Write-Host " Tip: Press F1 for Settings Menu, F3 for Stats Panel."
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
Push-Location $repo
|
||||||
|
try {
|
||||||
|
if ($Preload) {
|
||||||
|
Write-Host "Preloading shaders into $cacheDir..."
|
||||||
|
& $victory preload ([IO.Path]::GetDirectoryName($Exe))
|
||||||
|
}
|
||||||
|
if ($LogFile) {
|
||||||
|
& $victory run $Exe --console $console --execute 2> $LogFile
|
||||||
|
} else {
|
||||||
|
& $victory run $Exe --console $console --execute
|
||||||
|
}
|
||||||
|
exit $LASTEXITCODE
|
||||||
|
} finally {
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||
@@ -29,7 +29,10 @@ param(
|
|||||||
# driver how many this card does and gives no more).
|
# driver how many this card does and gives no more).
|
||||||
[ValidateRange(2, 6)][int]$FrameGenX = 2,
|
[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
|
# 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.
|
# and changes its amount while playing. Only with -FrameGenReady now: ready but off, Streamline's swap chain
|
||||||
|
# held this PC's frames at 14 a second (20 without), so frame generation off is off unless asked.
|
||||||
|
[switch]$FrameGenReady,
|
||||||
|
# (The default now; still taken.)
|
||||||
[switch]$NoFrameGenReady,
|
[switch]$NoFrameGenReady,
|
||||||
# Which frame generation: auto (DLSS Frame Generation where it runs, else AMD's FSR 3), dlss, or fsr (FSR 3
|
# Which frame generation: auto (DLSS Frame Generation where it runs, else AMD's FSR 3), dlss, or fsr (FSR 3
|
||||||
# even on an RTX 40/50; 2X only). FSR 3 needs AMD's FidelityFX DLLs (VICTORY_FIDELITYFX_DIR, else
|
# even on an RTX 40/50; 2X only). FSR 3 needs AMD's FidelityFX DLLs (VICTORY_FIDELITYFX_DIR, else
|
||||||
@@ -94,6 +97,10 @@ $settings = @{
|
|||||||
VICTORY_LEAVE_OUT = '02384a60fda6f2d0,731a39171b568298'
|
VICTORY_LEAVE_OUT = '02384a60fda6f2d0,731a39171b568298'
|
||||||
# Pipelines the title makes are written down, so `victory warm` can make them ahead
|
# Pipelines the title makes are written down, so `victory warm` can make them ahead
|
||||||
VICTORY_PIPELINE_BOOK = '1'
|
VICTORY_PIPELINE_BOOK = '1'
|
||||||
|
# Memory stack (skornuta): unused texture slots given back, old allocators taken anew, small buffers packed
|
||||||
|
VICTORY_SLOT_EVICT = '1'
|
||||||
|
VICTORY_ALLOCATOR_TRIM = '1'
|
||||||
|
VICTORY_BUDGET_PACK = '1'
|
||||||
}
|
}
|
||||||
if (-not $SeriesS) {
|
if (-not $SeriesS) {
|
||||||
if ($Res -eq '1440') { $settings.VICTORY_NATIVE_1440P = '1' }
|
if ($Res -eq '1440') { $settings.VICTORY_NATIVE_1440P = '1' }
|
||||||
@@ -105,7 +112,7 @@ if ($Dlss -ne 'off') {
|
|||||||
if (Test-Path (Join-Path $sl 'sl.interposer.dll')) {
|
if (Test-Path (Join-Path $sl 'sl.interposer.dll')) {
|
||||||
$settings.VICTORY_DLSS = '1'; $settings.VICTORY_DLSS_MODE = $Dlss; $settings.VICTORY_STREAMLINE_DIR = $sl
|
$settings.VICTORY_DLSS = '1'; $settings.VICTORY_DLSS_MODE = $Dlss; $settings.VICTORY_STREAMLINE_DIR = $sl
|
||||||
if ($FrameGen) { $settings.VICTORY_FRAMEGEN = '1'; $settings.VICTORY_FRAMEGEN_X = [string]$timesWanted }
|
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
|
elseif ($FrameGenReady -and -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
|
# 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
|
# 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.
|
# is left a fifth of the budget; ready but off, a little less is held back.
|
||||||
@@ -117,7 +124,7 @@ if ($Dlss -ne 'off') {
|
|||||||
}
|
}
|
||||||
# AMD FSR 3 frame generation: made ready as DLSS Frame Generation is (on, or ready and off for the F1 menu).
|
# AMD FSR 3 frame generation: made ready as DLSS Frame Generation is (on, or ready and off for the F1 menu).
|
||||||
# auto: the layer uses it only where DLSS Frame Generation does not run; fsr: DLSS Frame Generation is not asked.
|
# auto: the layer uses it only where DLSS Frame Generation does not run; fsr: DLSS Frame Generation is not asked.
|
||||||
if ($FgType -ne 'dlss' -and ($FrameGen -or -not $NoFrameGenReady)) {
|
if ($FgType -ne 'dlss' -and ($FrameGen -or ($FrameGenReady -and -not $NoFrameGenReady))) {
|
||||||
$fx = if ($env:VICTORY_FIDELITYFX_DIR) { $env:VICTORY_FIDELITYFX_DIR } else { Join-Path $repo 'amd-sdk\FidelityFX\bin' }
|
$fx = if ($env:VICTORY_FIDELITYFX_DIR) { $env:VICTORY_FIDELITYFX_DIR } else { Join-Path $repo 'amd-sdk\FidelityFX\bin' }
|
||||||
# Asked whatever is here: the layer checks the files and the card, and the start's notice (on the picture for
|
# Asked whatever is here: the layer checks the files and the card, and the start's notice (on the picture for
|
||||||
# its first 30 s, and in this window) says what runs and why not. On Series X without DLSS it stays off: the
|
# its first 30 s, and in this window) says what runs and why not. On Series X without DLSS it stays off: the
|
||||||
@@ -148,7 +155,7 @@ $settings.VICTORY_MENU_FG_TYPE = $FgType
|
|||||||
$settings.VICTORY_MENU_FPS = [string]$fpsWanted
|
$settings.VICTORY_MENU_FPS = [string]$fpsWanted
|
||||||
$settings.VICTORY_MENU_FILE = $menuFile
|
$settings.VICTORY_MENU_FILE = $menuFile
|
||||||
$settings.VICTORY_MENU_PLAY = $MyInvocation.MyCommand.Path
|
$settings.VICTORY_MENU_PLAY = $MyInvocation.MyCommand.Path
|
||||||
$settings.VICTORY_MENU_ARGS = "-Exe '$($Exe -replace "'", "''")' -Build $Build$(if ($NoFrameGenReady) { ' -NoFrameGenReady' })"
|
$settings.VICTORY_MENU_ARGS = "-Exe '$($Exe -replace "'", "''")' -Build $Build$(if ($FrameGenReady -and -not $NoFrameGenReady) { ' -FrameGenReady' })"
|
||||||
|
|
||||||
$victory = Join-Path $repo "target\$Build\victory.exe"
|
$victory = Join-Path $repo "target\$Build\victory.exe"
|
||||||
if (-not (Test-Path $victory)) {
|
if (-not (Test-Path $victory)) {
|
||||||
|
|||||||
@@ -1,146 +0,0 @@
|
|||||||
# One-click GTA VI on trustno1-coder/VIctory-NVIDIA (foxhound base): DLSS Super Resolution + DLSS frame generation.
|
|
||||||
# PLAY_FRAMEGEN.cmd runs this. What it does, in order:
|
|
||||||
# 1. finds the game folder (game_dir.txt in the repository folder, else a search of every drive)
|
|
||||||
# 2. backs up the saves (%LOCALAPPDATA%\victory\data\7952987A) and checks every file by SHA-256
|
|
||||||
# 3. gets NVIDIA's DLSS files once (scripts\get-nvidia-sdks.ps1, from github.com/NVIDIA-RTX/Streamline)
|
|
||||||
# 4. starts scripts\play-foxhound.ps1, which builds the layer the first time (a few minutes)
|
|
||||||
# Modes: 1 Series X 1440p + DLSS Quality + frame generation 2x (default)
|
|
||||||
# 2 same without frame generation
|
|
||||||
# 3 Series S + DLSS Quality + frame generation 2x (faster, softer)
|
|
||||||
# 4 Series X 1440p + DLSS Performance + frame generation 2x
|
|
||||||
param(
|
|
||||||
[ValidateSet('1', '2', '3', '4', '5', '6')][string]$Mode = '1',
|
|
||||||
[string]$GameDir = '',
|
|
||||||
[switch]$Check,
|
|
||||||
[switch]$NoBackup
|
|
||||||
)
|
|
||||||
$ErrorActionPreference = 'Stop'
|
|
||||||
$repo = Split-Path $PSScriptRoot -Parent
|
|
||||||
|
|
||||||
# A game folder holds the executable and its data (a lone copy of the exe does not count).
|
|
||||||
function Test-GameDir([string]$d) {
|
|
||||||
if (-not $d -or -not (Test-Path (Join-Path $d 'game_scarlett_master.exe'))) { return $false }
|
|
||||||
return (Test-Path (Join-Path $d 'shaders.rpf')) -or (Test-Path (Join-Path $d 'MicrosoftGame.config'))
|
|
||||||
}
|
|
||||||
function Find-GameDir {
|
|
||||||
$txt = Join-Path $repo 'game_dir.txt'
|
|
||||||
if (Test-Path $txt) {
|
|
||||||
$d = (Get-Content $txt -Encoding UTF8 -TotalCount 1).Trim().Trim('"')
|
|
||||||
if (Test-GameDir $d) { return $d }
|
|
||||||
}
|
|
||||||
foreach ($drive in (Get-PSDrive -PSProvider FileSystem | Where-Object { $null -ne $_.Free })) {
|
|
||||||
$cands = @(Get-ChildItem $drive.Root -Directory -ErrorAction SilentlyContinue)
|
|
||||||
$cands += @($cands | ForEach-Object { Get-ChildItem $_.FullName -Directory -ErrorAction SilentlyContinue })
|
|
||||||
foreach ($c in $cands) { if (Test-GameDir $c.FullName) { return $c.FullName } }
|
|
||||||
}
|
|
||||||
return $null
|
|
||||||
}
|
|
||||||
|
|
||||||
if (-not $GameDir) { $GameDir = Find-GameDir }
|
|
||||||
if (-not (Test-GameDir $GameDir)) {
|
|
||||||
Write-Host 'Game folder not found. Put its full path on the first line of game_dir.txt in this folder.'
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
$gameExe = Join-Path $GameDir 'game_scarlett_master.exe'
|
|
||||||
|
|
||||||
switch ($Mode) {
|
|
||||||
'1' { $opts = @{ FrameGen = $true }; $what = 'Series X 2560x1440, DLSS Quality, frame generation 2x' }
|
|
||||||
'2' { $opts = @{}; $what = 'Series X 2560x1440, DLSS Quality, no frame generation' }
|
|
||||||
'3' { $opts = @{ SeriesS = $true; FrameGen = $true }; $what = 'Series S, DLSS Quality, frame generation 2x' }
|
|
||||||
'4' { $opts = @{ Dlss = 'performance'; FrameGen = $true }; $what = 'Series X 2560x1440, DLSS Performance, frame generation 2x' }
|
|
||||||
'5' { $opts = @{ SeriesS = $true; Dlss = 'performance'; FrameGen = $true; Fps = 1000 }; $what = 'EXTREME: Series S, DLSS Performance, frame generation 2x, no cap, big pools, High priority' }
|
|
||||||
'6' { $opts = @{ Dlss = 'performance'; FrameGen = $true; Fps = 1000 }; $what = 'EXTREME: Series X 2560x1440, DLSS Performance, frame generation 2x, no cap, big pools, High priority' }
|
|
||||||
}
|
|
||||||
$sl = Join-Path $repo 'nvidia-sdk\Streamline\bin\x64'
|
|
||||||
$victory = Join-Path $repo 'target\release\victory.exe'
|
|
||||||
$hags = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\GraphicsDrivers' -Name HwSchMode -ErrorAction SilentlyContinue).HwSchMode
|
|
||||||
$isWin11 = [Environment]::OSVersion.Version.Build -ge 22000
|
|
||||||
$hagsOff = ($hags -eq 1) -or ($null -eq $hags -and -not $isWin11)
|
|
||||||
$hagsText = if ($hags -eq 2) {
|
|
||||||
'on'
|
|
||||||
} elseif ($null -eq $hags -and $isWin11) {
|
|
||||||
'default (on in Windows 11)'
|
|
||||||
} else {
|
|
||||||
'off: frame generation needs it (Settings > Display > Graphics)'
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($Check) {
|
|
||||||
Write-Host "repo: $repo"
|
|
||||||
Write-Host "game: $gameExe"
|
|
||||||
Write-Host "mode: $Mode ($what)"
|
|
||||||
Write-Host "DLSS: $(if (Test-Path (Join-Path $sl 'sl.interposer.dll')) { 'present' } else { 'not yet (downloaded at first start)' })"
|
|
||||||
Write-Host "built: $(if (Test-Path $victory) { 'yes' } else { 'no (built at first start)' })"
|
|
||||||
Write-Host "HAGS: $hagsText"
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
if (Get-Process victory -ErrorAction SilentlyContinue) { Write-Host 'The game is already running. Close it first.'; exit 1 }
|
|
||||||
|
|
||||||
# 2. Saves backup, verified file by file.
|
|
||||||
if (-not $NoBackup) {
|
|
||||||
$src = Join-Path $env:LOCALAPPDATA 'victory\data\7952987A'
|
|
||||||
if (Test-Path $src) {
|
|
||||||
$root = if (Test-Path 'D:\') { 'D:\victory-save-backups' } else { Join-Path $env:USERPROFILE 'victory-save-backups' }
|
|
||||||
$dst = Join-Path $root ('7952987A-{0:yyyyMMdd-HHmmss}-before-nvidia' -f (Get-Date))
|
|
||||||
New-Item -ItemType Directory -Force $root | Out-Null
|
|
||||||
Copy-Item $src $dst -Recurse -Force
|
|
||||||
$files = @(Get-ChildItem $src -Recurse -File)
|
|
||||||
$bad = 0
|
|
||||||
foreach ($f in $files) {
|
|
||||||
$t = Join-Path $dst $f.FullName.Substring($src.Length)
|
|
||||||
try {
|
|
||||||
if (-not (Test-Path $t) -or (Get-FileHash $f.FullName).Hash -ne (Get-FileHash $t).Hash) { $bad++ }
|
|
||||||
} catch { $bad++ }
|
|
||||||
}
|
|
||||||
if ($bad) { Write-Host "Save backup check failed ($bad of $($files.Count) files). Not starting."; exit 1 }
|
|
||||||
Write-Host "Saves backed up and checked: $dst ($($files.Count) files)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# 3. NVIDIA's DLSS and frame generation files, once.
|
|
||||||
if (-not (Test-Path (Join-Path $sl 'sl.interposer.dll'))) {
|
|
||||||
Write-Host 'Getting NVIDIA DLSS files (about 70 MB, once) ...'
|
|
||||||
try { & (Join-Path $PSScriptRoot 'get-nvidia-sdks.ps1') }
|
|
||||||
catch { Write-Host "Could not get them ($($_.Exception.Message)): the game runs without DLSS and frame generation." }
|
|
||||||
}
|
|
||||||
if ($hagsOff) { Write-Host 'Hardware-accelerated GPU scheduling is off: frame generation will not work until it is on.' }
|
|
||||||
|
|
||||||
# 4. Start (play-foxhound.ps1 builds target\release\victory.exe the first time).
|
|
||||||
if (-not (Test-Path $victory)) { Write-Host 'First start: building the layer, a few minutes ...' }
|
|
||||||
Write-Host "Starting GTA VI: $what"
|
|
||||||
Write-Host 'In the game: F1 settings menu, F3 stats panel. Keep this window open while playing.'
|
|
||||||
$env:VICTORY_GAME_DIR = $GameDir
|
|
||||||
$ErrorActionPreference = 'Continue'
|
|
||||||
# foxhound reads these but play-foxhound.ps1 does not set them: AnyXboxX's worker pools for 16/24+ logical CPUs
|
|
||||||
# (measured on an RTX 4070 SUPER: heavy scenes +22-29 %) and Vice-Tay's placed order. GTA6_NO_TUNE=1: leave them out.
|
|
||||||
$cpus = [Environment]::ProcessorCount
|
|
||||||
$more = @{ VICTORY_PLACED_ORDER = '1' }
|
|
||||||
if ($cpus -ge 24) { $more.VICTORY_THIN_THREADS = '12'; $more.VICTORY_UNDER_THREADS = '8'; $more.VICTORY_LAND_THREADS = '8' }
|
|
||||||
elseif ($cpus -ge 16) { $more.VICTORY_THIN_THREADS = '12'; $more.VICTORY_UNDER_THREADS = '8'; $more.VICTORY_LAND_THREADS = '6' }
|
|
||||||
# Extreme: the landing pool sat full at 8 (x6.1-6.6 of 8 in AnyXboxX's heavy scenes), one more pipeline worker.
|
|
||||||
if (($Mode -in @('5', '6')) -and $cpus -ge 24) { $more.VICTORY_LAND_THREADS = '12'; $more.VICTORY_PIPELINE_WORKERS = '4' }
|
|
||||||
if ($env:GTA6_NO_TUNE -eq '1') { $more = @{}; Write-Host 'GTA6_NO_TUNE=1: foxhound defaults (no pool or placed-order tuning).' }
|
|
||||||
else { Write-Host ("Tuning for {0} logical CPUs: {1}" -f $cpus, (($more.GetEnumerator() | Sort-Object Name | ForEach-Object { "$($_.Name)=$($_.Value)" }) -join ' ')) }
|
|
||||||
$opts.More = $more
|
|
||||||
# RTX 50 cards do multi frame generation: 4x there (the layer asks the driver and gives no more than it does).
|
|
||||||
# GTA6_FRAMEGEN_X=2..6 overrides. RTX 40 stays at 2x.
|
|
||||||
$gpuName = (Get-CimInstance Win32_VideoController -ErrorAction SilentlyContinue | Where-Object { $_.Name -match 'NVIDIA' } | Select-Object -First 1).Name
|
|
||||||
if ($opts.FrameGen) {
|
|
||||||
if ($env:GTA6_FRAMEGEN_X -match '^[2-6]$') { $opts.FrameGenX = [int]$env:GTA6_FRAMEGEN_X }
|
|
||||||
elseif ($gpuName -match 'RTX\s*50\d\d') { $opts.FrameGenX = 4 }
|
|
||||||
$fgx = if ($opts.FrameGenX) { $opts.FrameGenX } else { 2 }
|
|
||||||
Write-Host ('GPU: {0}; frame generation {1}x' -f $gpuName, $fgx)
|
|
||||||
}
|
|
||||||
if ($Mode -in @('5', '6')) {
|
|
||||||
# Raise the game to High priority once it is up (the submitting thread is the limit).
|
|
||||||
$null = Start-Job -ArgumentList $repo -ScriptBlock {
|
|
||||||
param($r)
|
|
||||||
$end = (Get-Date).AddMinutes(15)
|
|
||||||
while ((Get-Date) -lt $end) {
|
|
||||||
$p = Get-Process victory -ErrorAction SilentlyContinue | Where-Object { $_.Path -like "$r*" }
|
|
||||||
if ($p) { $p | ForEach-Object { $_.PriorityClass = 'High' }; break }
|
|
||||||
Start-Sleep -Seconds 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Write-Host 'Extreme: the game process goes to High priority once it starts.'
|
|
||||||
}
|
|
||||||
& (Join-Path $PSScriptRoot 'play-foxhound.ps1') -Exe $gameExe -Build release @opts
|
|
||||||
Reference in new issue
Block a user