shader: prefer exact Wave32 before wave64 folding and cap eager fold at 255 host regs #2261

Open
github-bot wants to merge 2 commits from github-bot/gh-2261 into main AGit
Owner

@⁠qlfu on GitHub · 2026-11-29 11:09 UTC · original
qlfu:pr/wave64-fold-after-exact-and-vgpr-cap → main · +85 −2 · 3 files · 2 commits · open

**@⁠qlfu** on GitHub · 2026-11-29 11:09 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2261) `qlfu:pr/wave64-fold-after-exact-and-vgpr-cap` → `main` · +85 −2 · 3 files · 2 commits · open ## What it changes Fixes a severe GPU performance regression introduced when `folded()` (`8f0a0c24`) was placed at the very top of `emit_strict`'s Wave64 retry block in `crates/victory-shader/src/emit/mod.rs`: 1. **Try non-widened exact native Wave32 forms before folding** (`without early-outs`, `without skips`, `local waves (idiom)`, `without skips, scalars followed`), while keeping `folded()` **ahead of `widen()`** (`wave-wide branches`). Previously, placing `folded()` first hijacked **55 of 105** gameplay Wave64 compute shaders that already lowered cleanly and exactly to native Wave32 without doubling VGPRs (`CS_Prop_BatchCull`, `CS_Slod_BatchCull`, `CS_BatchCullMeshlets*`, `CS_HairTileClassify`, etc.). Keeping `folded()` ahead of `widen()` preserves bit-exact 64-lane semantics for all reflection/screen-probe shaders (`WIDE_SKIP_DEFAULT`, 20/20 verified folded, avoiding the window-reflection artifacts caused by `widen()`). 2. **Guard `safe_single_wave` with `!lower::wide_fallback_skipped()`** in `emit_strict` so reflection and screen-probe programs listed in `WIDE_SKIP_DEFAULT` (`sr_tracing:CS_RayPrePass_Opaque_SSR`, `sr_denoising:CS_TemporalResolve*`, screen probes) never enter `widen()` via `safe_single_wave` even when folding is disabled or skipped. 3. **Defer folding past `APPROXIMATE` when `2 * console_vgprs + TEMP_VGPRS > 255`** (`fold::fits_host_regs`, `console_vgprs > 126`). Folding doubles every VGPR; on 32-lane NVIDIA hosts (255 hardware registers/thread), folding 129-VGPR shaders (`ptfx_CS_lightAtlas_Sprite` `2561af9577c47289` and `ptfx_CS_lightAtlas_Trail` `c06aa62112ffba4c` → 260 host VGPRs, 88 KB code, 100 wave-wide EXEC branches) forces heavy local-memory register spilling to VRAM, turning a <0.5 ms pass into a **21 ms average / 70–105 ms peak GPU stall**. Over-255-register shaders are still tried with `folded()` as a last resort if no non-folded lowering succeeds, so **0 new refusals** are introduced (`636/636` gameplay compute shaders translate). 4. All shadow/hair/reflection shaders that rely on folding (`CS_GenerateShadowMasks*`, all 20 `WIDE_SKIP_DEFAULT` reflection & screen-probe shaders) continue to fold identically. ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): RTX 4070 Ti 12 GB + Ryzen 7 5700X, Series X 1440p, DLSS Balanced, FrameGen off (`-NoFrameGenReady`), Ray Tracing off (`VICTORY_PORT_CONSTANTS=1;VICTORY_WAIT_RESIDENT=textures`), clean 90s gameplay A/B on `origin/main` (`829188e9`). - Before (`origin/main` `829188e9`, `victory-nvidia-20261129-120600.log`): - FPS: median **16.80** | mean **16.58** | min **8.8** | p10 **9.3** - `cardmeter` GPU time (`120600.log`): median **40.8 ms**, p95 **105.6 ms**, max **122.7 ms** (`ptfx_CS_lightAtlas_Sprite` `2561af9577c47289` alone: 18.3–21.3 ms avg, ~80–105 ms peak), GPU busy ~94% - Folded gameplay compute shaders: **105** (of 636) - After (`pr/wave64-fold-after-exact-and-vgpr-cap`): - Shader audit: **636/636** gameplay compute shaders translate (**0 refused**), folded count **105 → 48** (55 clean exact Wave32 shaders + 2 >255-reg `ptfx_CS_lightAtlas` shaders rescued), **20/20 `WIDE_SKIP_DEFAULT`** reflection & screen-probe shaders verified folded (0 entering `widen`), **0/67** `sr_tracing`/`sr_denoising` shaders entering `widen`. - Clean 90s warm gameplay verification (`victory-nvidia-20261129-145029.log`, 0 WARNs / 0 ERRORs) eliminates the 80–105 ms `ptfx_CS_lightAtlas` GPU stall: `cardmeter` GPU time drops from **40.8 / 105.6 / 122.7 ms** (med / p95 / max) to **30.1 / 43.9 / 52.2 ms** (**-61.7 ms p95**, **-70.5 ms max**), with 0 reflection shaders entering `widen()`. - For shader changes, the wave sizes tested (32 and/or 64 lanes): 32-lane host (RTX 4070 Ti) lowering Wave64 compute shaders; new unit tests in `emit::folded_tests` cover `fits_host_regs` and `emit_strict` precedence for exact Wave32 vs folded (<=126 VGPRs) vs deferred (>126 VGPRs). - `cargo test` passed for the crates it touches: yes (`cargo test -p victory-shader --lib --locked`: **464 passed, 0 failed**; `emit::folded_tests`: **19 passed, 0 failed** after final revision; `cargo test -p victory-gpu --lib --locked shader_cache`: **11 passed, 0 failed**; `cargo clippy -p victory-shader --lib --tests --locked`: 0 new warnings). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #2220 (touches adaptive shadow pass Wave32 scalars, no overlap with `fold.rs` or `emit/mod.rs` retry ordering).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 11:12:06 +00:00
github-bot force-pushed github-bot/gh-2261 from 1acda587ce to a91133e024 2026-11-29 11:44:28 +00:00 Compare
Author
Owner

@⁠Aniseto on GitHub · 2026-11-29 12:35 UTC · original

Ran the folded-wave32 lowering tests at a91133e0 on an NVIDIA Blackwell desktop part.

System

  • GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, mesh shaders), driver 32.0.16.2140 (621.40)
  • CPU: Intel Core i5-12400F, 64 GB RAM
  • OS: Windows 11 Pro build 26200 x64
  • Toolchain: Rust 1.98.1 (48a229cea 2026-09-01, pinned by rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5
  • Build: debug

Results

  • VICTORY_D3D12_ADAPTER=NVIDIA cargo test -p victory-shader --lib emit::folded_tests --locked -- --test-threads=1: 19 passed, 0 failed, 0 ignored.

What this adds
All 19 emit::folded_tests pass here, covering the exact-Wave32-before-folding precedence, the 255-host-register cap and the WIDE_SKIP_DEFAULT ordering. The thread has no comments yet, so this is the first datapoint in it and the first from an RTX 5070 Ti. These are translation-level tests; I did not repeat the author's 90 s gameplay A/B and claim no FPS number.

Not tested
A retail title, FPS/GPU-time A/B, a paired smoke run, the whole workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - ran the commands above on this machine and wrote this report; no game data was used.

**@⁠Aniseto** on GitHub · 2026-11-29 12:35 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2261#issuecomment-7255920309) Ran the folded-wave32 lowering tests at `a91133e0` on an NVIDIA Blackwell desktop part. **System** - GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, mesh shaders), driver 32.0.16.2140 (621.40) - CPU: Intel Core i5-12400F, 64 GB RAM - OS: Windows 11 Pro build 26200 x64 - Toolchain: Rust 1.98.1 (48a229cea 2026-09-01, pinned by `rust-toolchain.toml`), MSVC 14.44.35207, DXC 1.9.2609.5 - Build: debug **Results** - `VICTORY_D3D12_ADAPTER=NVIDIA cargo test -p victory-shader --lib emit::folded_tests --locked -- --test-threads=1`: 19 passed, 0 failed, 0 ignored. **What this adds** All 19 `emit::folded_tests` pass here, covering the exact-Wave32-before-folding precedence, the 255-host-register cap and the `WIDE_SKIP_DEFAULT` ordering. The thread has no comments yet, so this is the first datapoint in it and the first from an RTX 5070 Ti. These are translation-level tests; I did not repeat the author's 90 s gameplay A/B and claim no FPS number. **Not tested** A retail title, FPS/GPU-time A/B, a paired smoke run, the whole workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data. AI-assisted (OpenCode), model: **DeepSeek V4.1 Flash Free** - ran the commands above on this machine and wrote this report; no game data was used.
Author
Owner

@⁠Aniseto on GitHub · 2026-11-29 15:54 UTC · original

Build attempt at 829188e9 on an NVIDIA Blackwell desktop part failed. This is a factual build report, not a review or a title run.

System

  • GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, mesh shaders), driver 32.0.16.2140 (621.40)
  • CPU: Intel Core i5-12400F, 64 GB RAM
  • OS: Windows 11 Pro build 26200 x64
  • Toolchain: Rust 1.98.1 (48a229cea 2026-09-01, pinned by rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5
  • Build: cargo build --locked --profile diag -p victory --features diagnostics, detached worktree at 829188e9

Results

  • exit 101, 9 compile errors in victory-gpu:
    • copystat.rs:1349-1352: cannot find function mb (4 errors)
    • host.rs:9127, 9169, 9180: a local timing binding shadows fn timing() (3 errors)
    • host.rs:9172: str has no Sized bound in runs[i].slowest(...) (2 errors)
  • No binary was produced. The same attempt was made twice, on 28/11 and 29/11, with the same result.

What this adds
This commit is the base named in the PR description for the before/after A/B. I am reporting only the measured build outcome on this host and toolchain. No source was changed and no game was run.

Not tested
A retail title, a paired smoke run, other drivers, AMD and Intel GPUs, other toolchains, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - ran the command above on this machine and wrote this report; no game data was used.

**@⁠Aniseto** on GitHub · 2026-11-29 15:54 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2261#issuecomment-7258468068) Build attempt at `829188e9` on an NVIDIA Blackwell desktop part failed. This is a factual build report, not a review or a title run. **System** - GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, mesh shaders), driver 32.0.16.2140 (621.40) - CPU: Intel Core i5-12400F, 64 GB RAM - OS: Windows 11 Pro build 26200 x64 - Toolchain: Rust 1.98.1 (48a229cea 2026-09-01, pinned by `rust-toolchain.toml`), MSVC 14.44.35207, DXC 1.9.2609.5 - Build: `cargo build --locked --profile diag -p victory --features diagnostics`, detached worktree at `829188e9` **Results** - exit 101, 9 compile errors in `victory-gpu`: - `copystat.rs:1349-1352`: `cannot find function mb` (4 errors) - `host.rs:9127`, `9169`, `9180`: a local `timing` binding shadows `fn timing()` (3 errors) - `host.rs:9172`: `str` has no `Sized` bound in `runs[i].slowest(...)` (2 errors) - No binary was produced. The same attempt was made twice, on 28/11 and 29/11, with the same result. **What this adds** This commit is the base named in the PR description for the before/after A/B. I am reporting only the measured build outcome on this host and toolchain. No source was changed and no game was run. **Not tested** A retail title, a paired smoke run, other drivers, AMD and Intel GPUs, other toolchains, game data. AI-assisted (OpenCode), model: **DeepSeek V4.1 Flash Free** - ran the command above on this machine and wrote this report; no game data was used.
Author
Owner

@⁠qlfu on GitHub · 2026-11-29 23:54 UTC · original

Rebased cleanly onto main (41adb551, v2026.11.29.05): keeps fits_host_regs(native.vgprs) (<= 255 host VGPRs) on pre-widen wave64 folding (emit/mod.rs) and !lower::wide_fallback_skipped() on safe_single_wave. Verified emit::folded_tests pass (0 failed).

**@⁠qlfu** on GitHub · 2026-11-29 23:54 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2261#issuecomment-7264821282) Rebased cleanly onto `main` (`41adb551`, `v2026.11.29.05`): keeps `fits_host_regs(native.vgprs)` (`<= 255` host VGPRs) on pre-widen wave64 folding (`emit/mod.rs`) and `!lower::wide_fallback_skipped()` on `safe_single_wave`. Verified `emit::folded_tests` pass (`0` failed).
github-bot force-pushed github-bot/gh-2261 from a91133e024 to 5821118cfd 2026-11-30 00:00:30 +00:00 Compare
Author
Owner

@⁠qlfu on GitHub · 2026-11-30 12:36 UTC · original · edited 2026-11-30 15:27 UTC

Updated pre-widen folded (before wave-wide) guard in crates/victory-shader/src/emit/mod.rs to also check !scene_kernel so curated wide_by_default compute kernels stay on the wave-wide path instead of being folded ahead of wide_by_default, and respected wide_fallback_skipped(). Verified with folded_tests and clean merge-tree against 41adb551.

**@⁠qlfu** on GitHub · 2026-11-30 12:36 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2261#issuecomment-7278681052) · edited 2026-11-30 15:27 UTC Updated pre-widen `folded (before wave-wide)` guard in `crates/victory-shader/src/emit/mod.rs` to also check `!scene_kernel` so curated `wide_by_default` compute kernels stay on the wave-wide path instead of being folded ahead of `wide_by_default`, and respected `wide_fallback_skipped()`. Verified with `folded_tests` and clean `merge-tree` against `41adb551`.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/folded_tests.rs
  • crates/victory-shader/src/fold.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2261/head:github-bot/gh-2261'
git switch 'github-bot/gh-2261'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2261'
git switch 'github-bot/gh-2261'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2261'
git switch 'github-bot/gh-2261'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2261'
git switch 'main'
git merge --squash 'github-bot/gh-2261'
git switch 'main'
git merge --ff-only 'github-bot/gh-2261'
git switch 'main'
git merge 'github-bot/gh-2261'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!2261
No description provided.