Shaders: a skip around a loop stays only where lanes reach the scalars (#1914) #1952

Manually merged
github merged 1 commit from github-bot/gh-1952 into main 2026-11-30 14:15:52 +00:00 AGit
Owner

@⁠joeypercia on GitHub · 2026-11-29 04:02 UTC · original
joeypercia:shaders-skip-loops-without-lane-reads → main · +97 −28 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC

Fixes #1914

What it changes

#888 (90eb835, "retain empty-EXEC guards around a reachable loop") made without_skips's stalls keep an empty-EXEC skip around every reachable cycle without a proven exit, and also whenever its search ran out of its 20,000-state budget. That covers the case #888 was for, a scalar loop whose exit depends on an inactive lane's old value brought in by v_readfirstlane, which can run as far as the watchdog. But it also takes the "without skips" forms away from every program with an ordinary loop behind a skip, and those are the forms that lower wave64 programs on 32-lane hosts. @⁠matla00 bisected the swimming and boat buoyancy break to this commit and showed that reverting it alone fixes them (#1914).

This keeps #888's protection where it applies and drops it where it can't:

  • A chain of decided branches that comes back to a state it was in still keeps its skip, as before #888. That's the case of water_shading:CS_TransmissionVolumetrics_Tiled's dark tiles, now run with #888's better step, which also decides s_cbranch_vccz / vccnz and treats any v_cmp under empty EXEC as an empty mask.
  • #888's search for any cycle (the budget counting as a cycle) runs only where the region brings a lane's value into the scalars (v_readfirstlane / v_readlane). Without such a transfer, a loop whose exit isn't decided ends as the program's scalars say, the same with lanes as without, so it can't be kept turning by stale lane data.

step's facts only grow compared with before #888: it decides more branches and never decides one differently. So every skip the pre-#888 check kept is still kept.

How it was tested

  • GPU and profile: offline translation (no game run) as a 32-lane host, plus the unit tests; RTX 4070 Ti, Windows 11 26200. I couldn't run the game here: the PC is short of resources for it right now.
  • Before / after, VICTORY_HOST_WAVE=32 VICTORY_WAVE_WHY=1 victory translate shaders.rpf on the title's pack (26,084 programs), main 568c5e5 against this branch:
    • "WAVE64-SKIP kept": 3,163 on main, 1,999 with this change;
    • programs translated / emitted: identical (26,084 translated; the same 7 compute programs not emitted on both: 5 "a descriptor read only as data", 2 "no wave32 lowering for this wave64 program");
    • with --list --jobs 1, 96 programs emit different DXIL. They include the water ones: water_compressed_simulation_rendertarget:CS_MinMax_* (3), RiverSimPacket:CS_HighDetailDeltas_SelectOutputPatches, water_micro_geom_renderer:CS_GenerateWaterPatches* (3), water_shading:* (6), and the water SSR / temporal-resolve passes. Also InstanceCulling (12), GpuParticleEmit (11), GpuParticleUpdate (6) and shadows.
  • New test a_scalar_counted_loop_behind_a_skip_does_not_keep_it: a counted scalar loop (s_mov_b32 s6, 0 … s_cbranch_scc0) behind a skip loses its skip in both modes. It fails on main (the skip is kept) and passes here. #888's an_empty_wave_keeps_its_skip_around_a_loop_that_can_reach_the_watchdog passes unchanged (its three cases: the vccz loop as a decided cycle, the v_readfirstlane loop through the lane-read search, and the vccnz loop that exits).
  • For shader changes, the wave sizes tested: 32 lanes (the forms this changes are only used on 32-lane hosts); no 64-lane host here.
  • cargo test passed for the crates it touches: yes, cargo test --locked -p victory-shader: 396 passed, 0 failed, 8 ignored.

Not tested: in the game. @⁠matla00, if you can, a swim and a boat on this branch would confirm it.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: none change stalls. #1504 touches ir.rs (VGPR numbering only). I claimed #1914 before opening this.

Written with Claude Code (Claude Opus 5.5): it found the change in #888, wrote the fix, the test and this description, and ran the tests and translations above.

**@⁠joeypercia** on GitHub · 2026-11-29 04:02 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1952) `joeypercia:shaders-skip-loops-without-lane-reads` → `main` · +97 −28 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC Fixes #1914 ## What it changes #888 (`90eb835`, "retain empty-EXEC guards around a reachable loop") made `without_skips`'s `stalls` keep an empty-EXEC skip around **every** reachable cycle without a proven exit, and also whenever its search ran out of its 20,000-state budget. That covers the case #888 was for, a scalar loop whose exit depends on an inactive lane's old value brought in by `v_readfirstlane`, which can run as far as the watchdog. But it also takes the "without skips" forms away from every program with an ordinary loop behind a skip, and those are the forms that lower wave64 programs on 32-lane hosts. @⁠matla00 bisected the swimming and boat buoyancy break to this commit and showed that reverting it alone fixes them (#1914). This keeps #888's protection where it applies and drops it where it can't: - **A chain of decided branches that comes back to a state it was in still keeps its skip**, as before #888. That's the case of `water_shading:CS_TransmissionVolumetrics_Tiled`'s dark tiles, now run with #888's better `step`, which also decides `s_cbranch_vccz` / `vccnz` and treats any `v_cmp` under empty EXEC as an empty mask. - **#888's search for any cycle (the budget counting as a cycle) runs only where the region brings a lane's value into the scalars** (`v_readfirstlane` / `v_readlane`). Without such a transfer, a loop whose exit isn't decided ends as the program's scalars say, the same with lanes as without, so it can't be kept turning by stale lane data. `step`'s facts only grow compared with before #888: it decides more branches and never decides one differently. So every skip the pre-#888 check kept is still kept. ## How it was tested - GPU and profile: offline translation (no game run) as a 32-lane host, plus the unit tests; RTX 4070 Ti, Windows 11 26200. I couldn't run the game here: the PC is short of resources for it right now. - Before / after, `VICTORY_HOST_WAVE=32 VICTORY_WAVE_WHY=1 victory translate shaders.rpf` on the title's pack (26,084 programs), `main` `568c5e5` against this branch: - "WAVE64-SKIP kept": **3,163 on `main`, 1,999 with this change**; - programs translated / emitted: identical (26,084 translated; the same 7 compute programs not emitted on both: 5 "a descriptor read only as data", 2 "no wave32 lowering for this wave64 program"); - with `--list --jobs 1`, 96 programs emit different DXIL. They include the water ones: `water_compressed_simulation_rendertarget:CS_MinMax_*` (3), `RiverSimPacket:CS_HighDetailDeltas_SelectOutputPatches`, `water_micro_geom_renderer:CS_GenerateWaterPatches*` (3), `water_shading:*` (6), and the water SSR / temporal-resolve passes. Also `InstanceCulling` (12), `GpuParticleEmit` (11), `GpuParticleUpdate` (6) and shadows. - New test `a_scalar_counted_loop_behind_a_skip_does_not_keep_it`: a counted scalar loop (`s_mov_b32 s6, 0` … `s_cbranch_scc0`) behind a skip loses its skip in both modes. It **fails on `main`** (the skip is kept) and passes here. #888's `an_empty_wave_keeps_its_skip_around_a_loop_that_can_reach_the_watchdog` passes unchanged (its three cases: the `vccz` loop as a decided cycle, the `v_readfirstlane` loop through the lane-read search, and the `vccnz` loop that exits). - For shader changes, the wave sizes tested: 32 lanes (the forms this changes are only used on 32-lane hosts); no 64-lane host here. - `cargo test` passed for the crates it touches: yes, `cargo test --locked -p victory-shader`: 396 passed, 0 failed, 8 ignored. **Not tested:** in the game. @⁠matla00, if you can, a swim and a boat on this branch would confirm it. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: none change `stalls`. #1504 touches `ir.rs` (VGPR numbering only). I claimed #1914 before opening this. Written with Claude Code (Claude Opus 5.5): it found the change in #888, wrote the fix, the test and this description, and ran the tests and translations above.
#888 kept an empty-EXEC skip around every reachable loop without a proven
exit, and also whenever its search ran out of budget. That covered the
loop that reads an inactive lane's old value (v_readfirstlane) and can run
as far as the watchdog, but it also left out the 32-lane forms of every
program with an ordinary loop behind a skip: since #888 the player cannot
swim and boats sink near the player (#1914, bisected and reverted there).

A loop whose way out is not decided ends as the program's scalars say,
the same with lanes as without, unless the region brings a lane's value
into the scalars. So a chain of decided branches that comes back still
keeps its skip, as before #888 (the water tiles of
CS_TransmissionVolumetrics_Tiled), and #888's search for any cycle runs
only in a region with v_readfirstlane / v_readlane.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 04:05:40 +00:00
Author
Owner

@⁠Nosheboo on GitHub · 2026-11-29 04:14 UTC · original · reviewed

Note

🤖 Muse Spark responding on behalf of Nosheboo

This approach holds up against an independent check. I ran this PR's head (7347259) and a value-tracking variant of stalls (scalar dword values through mask algebra, comparisons, and induction counters) over the same 18 target shaders — spill-built wave64 programs from shaders.rpf and the FidelityFX upscaler DLL, without_skips in both modes, keep/remove per s_cbranch_execz site:

  • FidelityFX upscaler (3 programs): all skips removed under both. Unblocked either way.
  • The known stall skips stay kept under both: Tiled 0x29f0, LocalLights 0x4958, FrameStatistics 0x1e30/0x1ec8, and the Submerged sets are identical except this PR additionally keeps 0x1dc.
  • Where they differ, this PR keeps a few more ordinary-loop guards the value tracking proves exiting: MinMax 0x0/0x1a4/0x1bc, SortRayTiles 0x120/0x390, TAA-dual 0x0, SSR 0x338, cascade 0xfa8, particles 0x0/0x214. That is perf follow-up material, not a correctness gap — these match what the pre-90eb835 check kept.
  • One reverse case: ptx Trail 0xc0 is removed here but kept by the value-tracking variant, which could not prove that loop exits. If Trail still misbehaves, that site is worth a look either way.

Verified fact: the keep sets agree on every previously identified stall. Judgment: the lane-read gate is the smaller, safer change versus value tracking, and it already restores the 32-lane forms. Same caveat as the PR body — no game run here, offline translation only.

**@⁠Nosheboo** on GitHub · 2026-11-29 04:14 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1952#pullrequestreview-6101364674) · **reviewed** > [!NOTE] > 🤖 **Muse Spark responding on behalf of Nosheboo** This approach holds up against an independent check. I ran this PR's head (`7347259`) and a value-tracking variant of `stalls` (scalar dword values through mask algebra, comparisons, and induction counters) over the same 18 target shaders — spill-built wave64 programs from `shaders.rpf` and the FidelityFX upscaler DLL, `without_skips` in both modes, keep/remove per `s_cbranch_execz` site: - FidelityFX upscaler (3 programs): all skips removed under both. Unblocked either way. - The known stall skips stay kept under both: Tiled `0x29f0`, LocalLights `0x4958`, FrameStatistics `0x1e30`/`0x1ec8`, and the Submerged sets are identical except this PR additionally keeps `0x1dc`. - Where they differ, this PR keeps a few more ordinary-loop guards the value tracking proves exiting: MinMax `0x0`/`0x1a4`/`0x1bc`, SortRayTiles `0x120`/`0x390`, TAA-dual `0x0`, SSR `0x338`, cascade `0xfa8`, particles `0x0`/`0x214`. That is perf follow-up material, not a correctness gap — these match what the pre-`90eb835` check kept. - One reverse case: ptx Trail `0xc0` is removed here but kept by the value-tracking variant, which could not prove that loop exits. If Trail still misbehaves, that site is worth a look either way. Verified fact: the keep sets agree on every previously identified stall. Judgment: the lane-read gate is the smaller, safer change versus value tracking, and it already restores the 32-lane forms. Same caveat as the PR body — no game run here, offline translation only.
Author
Owner

@⁠Robotniq on GitHub · 2026-11-29 08:50 UTC · original

Tested in play on a 32-lane card: RTX 3070 Ti 8 GB, driver 621.40, Series S profile, DLSS Quality, ray tracing off; 568c5e5 + this PR.

  • In a 5-minute run on the first boat mission, "no wave32 lowering for this wave64 program" went from 4 programs to 2: 34992f2b65a789a5 and 71883e40620a567a come back, 7168dd781ca7efb9 and 6b82bc7d22016cb5 stay refused. Median frame rate 25.7 -> 25.1, VRAM peak about the same (6.50 -> 6.43 GB).
  • Swimming and boats (#1914), checked in play: the player swims normally, and boats near the player float, on the first boat mission and in the swamp camp.
  • One side effect: with the reflection pre-pass and one of the two temporal resolves back, but 7168dd781ca7efb9 still dropped, glass, glasses, mirrors and bottles come out in glittering colours. Leaving 34992f2b65a789a5 and 71883e40620a567a out again (VICTORY_SKIP_PIPELINES) removes it, and the water fix stays. On 32-lane hosts it may be worth keeping those two out until the third translates as well.

Measured with AI assistance (Claude Code); the runs were made on my machine.

**@⁠Robotniq** on GitHub · 2026-11-29 08:50 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1952#issuecomment-7253361788) Tested in play on a 32-lane card: RTX 3070 Ti 8 GB, driver 621.40, Series S profile, DLSS Quality, ray tracing off; 568c5e5 + this PR. - In a 5-minute run on the first boat mission, "no wave32 lowering for this wave64 program" went from 4 programs to 2: `34992f2b65a789a5` and `71883e40620a567a` come back, `7168dd781ca7efb9` and `6b82bc7d22016cb5` stay refused. Median frame rate 25.7 -> 25.1, VRAM peak about the same (6.50 -> 6.43 GB). - Swimming and boats (#1914), checked in play: the player swims normally, and boats near the player float, on the first boat mission and in the swamp camp. - One side effect: with the reflection pre-pass and one of the two temporal resolves back, but `7168dd781ca7efb9` still dropped, glass, glasses, mirrors and bottles come out in glittering colours. Leaving `34992f2b65a789a5` and `71883e40620a567a` out again (`VICTORY_SKIP_PIPELINES`) removes it, and the water fix stays. On 32-lane hosts it may be worth keeping those two out until the third translates as well. Measured with AI assistance (Claude Code); the runs were made on my machine.
Author
Owner

@⁠MrEjecutor on GitHub · 2026-11-29 16:59 UTC · original

As asked on #888: offline translate --list on this branch (7347259), VICTORY_HOST_WAVE=32, VICTORY_EARLY_DEPTH=1, against main 568c5e5 and main plus the retry from #888. Same files and switches for all three builds.

main 568c5e5 + retry #1952 7347259
programs listed 25,787 25,787 25,787
emitted 25,776 25,779 25,779
"no wave32 lowering" 3 3 3
"a lane mask exchanged where not every lane runs" 3 0 0
  • 477b52e73ddeb6f2, 8b437ab61d8008fe, 17af85f170e66f30: emitted on this branch. On main they fail at 0x218.
  • 5dc3b25986622949 and 6f225b641c5b0708: emitted, with the same short hashes (~d6a72e5f, ~848b30db) on all three builds.
  • These three are the only programs whose result differs between main and this branch. This branch and main plus the retry give the same result for every one of the 25,787 programs.

So the retry PR is not needed for these three.

Not tested: in play (swimming, boats); emitted bytes compared beyond the short hashes the list prints; other cards (RTX 5060 Ti here).

AI-assisted (Claude Code): the builds, the runs and this text. No game files attached.

**@⁠MrEjecutor** on GitHub · 2026-11-29 16:59 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1952#issuecomment-7259331745) As asked on #888: offline `translate --list` on this branch (`7347259`), `VICTORY_HOST_WAVE=32`, `VICTORY_EARLY_DEPTH=1`, against main `568c5e5` and main plus the retry from #888. Same files and switches for all three builds. | | main `568c5e5` | + retry | #1952 `7347259` | |---|---|---|---| | programs listed | 25,787 | 25,787 | 25,787 | | emitted | 25,776 | 25,779 | 25,779 | | "no wave32 lowering" | 3 | 3 | 3 | | "a lane mask exchanged where not every lane runs" | 3 | 0 | 0 | - `477b52e73ddeb6f2`, `8b437ab61d8008fe`, `17af85f170e66f30`: emitted on this branch. On main they fail at `0x218`. - `5dc3b25986622949` and `6f225b641c5b0708`: emitted, with the same short hashes (`~d6a72e5f`, `~848b30db`) on all three builds. - These three are the only programs whose result differs between main and this branch. This branch and main plus the retry give the same result for every one of the 25,787 programs. So the retry PR is not needed for these three. **Not tested:** in play (swimming, boats); emitted bytes compared beyond the short hashes the list prints; other cards (RTX 5060 Ti here). AI-assisted (Claude Code): the builds, the runs and this text. No game files attached.
Author
Owner

@⁠dyshay on GitHub · 2026-11-29 17:49 UTC · original

Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch janus-prs). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with --profile diag --features diagnostics, and the CPU tests of the touched crates pass. Runs on an RTX 4090 are queued (Series S with ray tracing, and Series X, DLSS Quality). Frame times will follow here.

**@⁠dyshay** on GitHub · 2026-11-29 17:49 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1952#issuecomment-7259986846) Merged into our fork's integration branch for testing ([dyshay/VIctory-NVIDIA](https://github.com/dyshay/VIctory-NVIDIA/tree/janus-prs), branch `janus-prs`). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with `--profile diag --features diagnostics`, and the CPU tests of the touched crates pass. Runs on an RTX 4090 are queued (Series S with ray tracing, and Series X, DLSS Quality). Frame times will follow here.
github manually merged commit 26894fb0e0 into main 2026-11-30 14:15:52 +00:00
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!1952
No description provided.