Shaders: a loop leaves with the host wave when a VCC test of a lane compare says so #196

Open
github-bot wants to merge 1 commit from github-bot/gh-196 into main AGit
Owner

@⁠JaumeMarRib on GitHub · 2026-11-24 22:26 UTC · original
JaumeMarRib:pr/loop-exit-wave-vote → main · +73 −0 · 1 files · 1 commits · open

Problem

The structurisation turns a branch on a wave-wide mask test into a branch on the lane's own bit. That is right where compiled code only skips work, or where the tested value is the same in every lane, but not for a loop exit on s_cbranch_vccz/vccnz of a compare that differs between lanes: the console leaves with the whole wave as soon as one lane meets the exit, while the per-lane rule keeps a lane whose own test never holds looping up to the iteration limit.

The title's clustered-light pixel shaders do exactly that: the outer loop walks light-mask words from the first lane's start and leaves when the word index equals some lane's end (v_cmp_eq_u32 vcc, s79, v56; s_cbranch_vccz). In a wave that mixes clusters, a lane whose end lies before the first lane's start never matches and runs the loop (and the light loop inside it) about 2^20 times. On an RTX 5070, single draws of one mesh group with these shaders took 100-130 ms in the first mission's intro (VICTORY_GPU_TIMING=1), and lists of them ended in DXGI_ERROR_DEVICE_HUNG.

Change

crates/victory-shader/src/emit/lower.rs, +73 lines: where one way of such a branch stays in a loop around the block (its header, or plain jumps to it) and the other leaves, the exit also holds when it holds in some lane of the host wave (WaveActiveAnyTrue), as the console's wave-wide test does. A lane still leaves on its own exit, so a wave of helper lanes only (which wave votes leave out) keeps the old rule. Other branches keep the lane rule, and branches in Structured::wide, which already carry the wave-wide answer, are left alone.

Verification

  • Offline, for a 32-lane host, the 999 pixel, mesh and compute programs dumped from a hang: every program that translated before still does; 21 pixel shaders change, among them the four the per-command timing named slowest.
  • RTX 5070 (Windows 11), opening cutscene into the first scene: before, a device hang every run; with this change, several 5-7 minute runs with DRED on and no hang or device removal (one with the D3D12 debug layer: 0 errors).
  • cargo clippy --workspace --all-targets --locked -- -D warnings clean; cargo test --workspace --locked passes.

🤖 Generated with Claude Code

**@⁠JaumeMarRib** on GitHub · 2026-11-24 22:26 UTC · [original](https://github.com/fxceless/victory-fork/pull/196) `JaumeMarRib:pr/loop-exit-wave-vote` → `main` · +73 −0 · 1 files · 1 commits · open ## Problem The structurisation turns a branch on a wave-wide mask test into a branch on the lane's own bit. That is right where compiled code only skips work, or where the tested value is the same in every lane, but not for a loop exit on `s_cbranch_vccz`/`vccnz` of a compare that differs between lanes: the console leaves with the whole wave as soon as one lane meets the exit, while the per-lane rule keeps a lane whose own test never holds looping up to the iteration limit. The title's clustered-light pixel shaders do exactly that: the outer loop walks light-mask words from the first lane's start and leaves when the word index equals some lane's end (`v_cmp_eq_u32 vcc, s79, v56; s_cbranch_vccz`). In a wave that mixes clusters, a lane whose end lies before the first lane's start never matches and runs the loop (and the light loop inside it) about 2^20 times. On an RTX 5070, single draws of one mesh group with these shaders took 100-130 ms in the first mission's intro (`VICTORY_GPU_TIMING=1`), and lists of them ended in `DXGI_ERROR_DEVICE_HUNG`. ## Change `crates/victory-shader/src/emit/lower.rs`, +73 lines: where one way of such a branch stays in a loop around the block (its header, or plain jumps to it) and the other leaves, the exit also holds when it holds in some lane of the host wave (`WaveActiveAnyTrue`), as the console's wave-wide test does. A lane still leaves on its own exit, so a wave of helper lanes only (which wave votes leave out) keeps the old rule. Other branches keep the lane rule, and branches in `Structured::wide`, which already carry the wave-wide answer, are left alone. ## Verification - Offline, for a 32-lane host, the 999 pixel, mesh and compute programs dumped from a hang: every program that translated before still does; 21 pixel shaders change, among them the four the per-command timing named slowest. - RTX 5070 (Windows 11), opening cutscene into the first scene: before, a device hang every run; with this change, several 5-7 minute runs with DRED on and no hang or device removal (one with the D3D12 debug layer: 0 errors). - `cargo clippy --workspace --all-targets --locked -- -D warnings` clean; `cargo test --workspace --locked` passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The structurisation turns a branch on a wave-wide mask test into a branch
on the lane's own bit: compiled code only skips work that lanes outside
the mask would not change, or tests a value the same in every lane. A
loop's exit on s_cbranch_vccz/vccnz of a compare that differs between
lanes is neither. The console leaves with the whole wave as soon as one
lane meets the exit; the lane's own bit keeps a lane whose own test never
holds looping, up to the iteration limit.

The title's clustered-light pixel shaders do that: the outer loop walks
light-mask words from the first lane's start and leaves when the word
index equals some lane's end (v_cmp_eq_u32 vcc, s79, v56;
s_cbranch_vccz). In a wave that mixes clusters, a lane whose end lies
before the first lane's start never matches and runs the loop, and the
light loop inside it, about 2^20 times. On an RTX 5070, whose waves group
pixels differently from the console's, single draws of one mesh group
with these shaders took 100-130 ms in the first mission's intro, and
lists of them ended in DXGI_ERROR_DEVICE_HUNG.

Where one way of such a branch stays in a loop around the block (its
header, or plain jumps to it) and the other leaves, the exit now also
holds when it holds in some lane of the host wave (waveAnyTrue), as the
console's wave-wide test does. A lane still leaves on its own exit, so a
wave of helper lanes only, which wave votes leave out, keeps the old rule.
Other branches keep the lane rule. A branch in Structured::wide already
has the console's wave-wide answer in its condition, so the vote is
skipped there.

Translated offline for a 32-lane host, the 999 pixel, mesh and compute
programs dumped from that run: 21 pixel shaders change, among them the
slow ones the per-command timing named; every program that translated
before still does. On the RTX 5070, 7-minute runs through the intro no
longer hang the device.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:38:00 +00:00
Author
Owner

@⁠rocobalt1 on GitHub · 2026-11-24 23:13 UTC · original

This is the fix for the trade-off I reported in #62: with it, a 4060 Ti at VICTORY_SHADER_LOOP_LIMIT=256 draws the room and the hair, which it could not do before.

Setup: RTX 4060 Ti 8 GB, driver 32.0.16.1656, Ryzen 9 5900X, Windows 11; 4e17478 + #32 #77 #81 #9 #40 #83 #38 #51 #234 #188 + this PR (48747d8), diag build, --console series-s, VICTORY_SHADER_LOOP_LIMIT=256, VICTORY_NO_WATCHDOG=1, fresh data dir. TdrDelay=60.

without this PR with it
ceiling of the cell block missing - its lights float against the sky drawn, with the lamps on it
cell wall missing drawn
hair at loop limit 256 correct correct
frame in the yard 312 - 460 ms (median 312) 213 - 433 ms (median 414 in 5 frames, one 12 057-draw frame at 3 537 ms)
shader refusals 4 4
device removal none none

So on this card the missing geometry was the loop exit, exactly as #62 suspected, and not a refused draw - the four refusals remain the same four (transpose vec/mat, shadow cascades alpha, shallow water reduce, water volumetrics).

Nothing else regressed that I can see: the hair stays correct at 256 in the same frame that gained the ceiling, which is the pairing that was impossible before.

No game data; counts only.

**@⁠rocobalt1** on GitHub · 2026-11-24 23:13 UTC · [original](https://github.com/fxceless/victory-fork/pull/196#issuecomment-7147165250) This is the fix for the trade-off I reported in #62: with it, a 4060 Ti at `VICTORY_SHADER_LOOP_LIMIT=256` draws the room *and* the hair, which it could not do before. **Setup:** RTX 4060 Ti 8 GB, driver 32.0.16.1656, Ryzen 9 5900X, Windows 11; `4e17478` + #32 #77 #81 #9 #40 #83 #38 #51 #234 #188 + **this PR** (`48747d8`), diag build, `--console series-s`, `VICTORY_SHADER_LOOP_LIMIT=256`, `VICTORY_NO_WATCHDOG=1`, fresh data dir. `TdrDelay=60`. | | without this PR | **with it** | |---|---|---| | ceiling of the cell block | **missing** - its lights float against the sky | **drawn**, with the lamps on it | | cell wall | **missing** | **drawn** | | hair at loop limit 256 | correct | correct | | frame in the yard | 312 - 460 ms (median 312) | 213 - 433 ms (median 414 in 5 frames, one 12 057-draw frame at 3 537 ms) | | shader refusals | 4 | 4 | | device removal | none | none | So on this card the missing geometry was the loop exit, exactly as #62 suspected, and not a refused draw - the four refusals remain the same four (transpose vec/mat, shadow cascades alpha, shallow water reduce, water volumetrics). Nothing else regressed that I can see: the hair stays correct at 256 in the same frame that gained the ceiling, which is the pairing that was impossible before. No game data; counts only.
Author
Owner

@⁠luisaugustz on GitHub · 2026-11-25 00:23 UTC · original

Correction to my RX 9070 XT comment above: please disregard its results. They were not measured with this PR.

My build of this PR failed on our base (578d459 + staging fix): the patch uses Structured::wide, which that base does not have. My run script ignored the failed compile and kept using the previous executable, an unrelated experiment of mine (exact-copy texture views, the one I reported as negative on #3). So the "with this PR" and "half-wave vote" rows, the blow-out, and the G-buffer remarks all describe that other build, not this PR. I have not tested this PR on an RX 9070 XT yet.

Sorry for the noise. If I get it building (it probably needs the change that adds Structured::wide), I'll post real numbers in a new comment.

AI-assisted (Claude Code).

**@⁠luisaugustz** on GitHub · 2026-11-25 00:23 UTC · [original](https://github.com/fxceless/victory-fork/pull/196#issuecomment-7148463300) **Correction to my RX 9070 XT comment above: please disregard its results. They were not measured with this PR.** My build of this PR failed on our base (`578d459` + staging fix): the patch uses `Structured::wide`, which that base does not have. My run script ignored the failed compile and kept using the previous executable, an unrelated experiment of mine (exact-copy texture views, the one I reported as negative on #3). So the "with this PR" and "half-wave vote" rows, the blow-out, and the G-buffer remarks all describe that other build, not this PR. I have not tested this PR on an RX 9070 XT yet. Sorry for the noise. If I get it building (it probably needs the change that adds `Structured::wide`), I'll post real numbers in a new comment. _AI-assisted (Claude Code)._
Author
Owner

@⁠luisaugustz on GitHub · 2026-11-24 23:50 UTC · original · edited 2026-11-25 00:23 UTC

RETRACTED: these results were not measured with this PR, see the correction below.

RX 9070 XT (RDNA 4): with this PR the cell's wall and the character textures reach the G-buffer, but the lit picture is blown out and torn; a per-console-wave vote does not change that

A data point from AMD, since the PR is verified on NVIDIA so far.

Setup: RX 9070 XT, Adrenalin 32.0.32029.2010, Ryzen 7 5800X, 32 GB, Windows 11; fork 578d459 + a staging-release fix + this PR's commit 365c3b2 (applied cleanly), diag build, Series X, VICTORY_SHADER_LOOP_LIMIT=256, VICTORY_CUT_WRITES=1, texture queue 1024 MB / 1000 ms with VICTORY_TEXTURE_BUDGET_MB=6144, DRED off, 41 AMD CS_RaytracingResolve skips + 2 others. Same prologue, 10 minutes each, cold shader cache for each new executable.

build final picture G-buffer albedo at the window view
control (no PR) clean, lit, ~3 fps once settled room wall black (not drawn), shirt black
with this PR blown out to white/orange, content torn into shifted blocks, 0.1 to 3 fps while loading room's white block wall drawn, orange shirt, complete textures
this PR, vote changed to the console wave's own half (waveActiveBallot dword by lane index for console wave32, waveAnyTrue for wave64) blown out the same way, no detail left not checked

One run each, so read the first two rows as a lead and not a proof; I know the cell shell is intermittent on other cards.

So on this card the PR does something real before lighting (the wall and the shirt colour exist in the albedo plane only with it), and something wrong in the lit output. My first guess was the vote's scope: if the host runs the console's 32-lane pixel shaders as wave64 (as PastiiJay found for the purple blocks), waveAnyTrue would span two console waves. Testing the vote over the console wave's own half did not change the picture, so that is not it.

What I have not done: find which of the 21 changed pixel shaders is responsible, or check whether a lane's early exit leaves a light sum that the following code treats as clustered-light output. If it would help, I can test the PR with only the four slowest programs changed, by hash, to see whether the blow-out follows a subset.

Counts and settings only; no game data.

AI-assisted (Claude Code): measured on this machine with a diag build.

**@⁠luisaugustz** on GitHub · 2026-11-24 23:50 UTC · [original](https://github.com/fxceless/victory-fork/pull/196#issuecomment-7147851402) · edited 2026-11-25 00:23 UTC **RETRACTED: these results were not measured with this PR, see the correction below.** **RX 9070 XT (RDNA 4): with this PR the cell's wall and the character textures reach the G-buffer, but the lit picture is blown out and torn; a per-console-wave vote does not change that** A data point from AMD, since the PR is verified on NVIDIA so far. **Setup:** RX 9070 XT, Adrenalin 32.0.32029.2010, Ryzen 7 5800X, 32 GB, Windows 11; fork `578d459` + a staging-release fix + this PR's commit `365c3b2` (applied cleanly), diag build, Series X, `VICTORY_SHADER_LOOP_LIMIT=256`, `VICTORY_CUT_WRITES=1`, texture queue 1024 MB / 1000 ms with `VICTORY_TEXTURE_BUDGET_MB=6144`, DRED off, 41 AMD `CS_RaytracingResolve` skips + 2 others. Same prologue, 10 minutes each, cold shader cache for each new executable. | build | final picture | G-buffer albedo at the window view | |---|---|---| | control (no PR) | clean, lit, ~3 fps once settled | room wall black (not drawn), shirt black | | with this PR | **blown out to white/orange, content torn into shifted blocks**, 0.1 to 3 fps while loading | **room's white block wall drawn, orange shirt, complete textures** | | this PR, vote changed to the console wave's own half (`waveActiveBallot` dword by lane index for console wave32, `waveAnyTrue` for wave64) | blown out the same way, no detail left | not checked | One run each, so read the first two rows as a lead and not a proof; I know the cell shell is intermittent on other cards. So on this card the PR does something real before lighting (the wall and the shirt colour exist in the albedo plane only with it), and something wrong in the lit output. My first guess was the vote's scope: if the host runs the console's 32-lane pixel shaders as wave64 (as PastiiJay found for the purple blocks), `waveAnyTrue` would span two console waves. Testing the vote over the console wave's own half did not change the picture, so that is not it. What I have not done: find which of the 21 changed pixel shaders is responsible, or check whether a lane's early exit leaves a light sum that the following code treats as clustered-light output. If it would help, I can test the PR with only the four slowest programs changed, by hash, to see whether the blow-out follows a subset. Counts and settings only; no game data. _AI-assisted (Claude Code): measured on this machine with a diag build._
Author
Owner

@⁠ryotdev on GitHub · 2026-11-25 01:01 UTC · original

I found a branch-direction case in wave_loop_exit on 365c3b2. When s_cbranch_vccnz is the back edge, the wave must keep looping while any lane still has work. The current lowering stops the entire host wave as soon as any lane is done.

I reproduced this with a hand-written wave32 compute shader on Windows D3D12 WARP. The 32 lanes alternate between end values 1 and 2. A shared counter increments, compares against each lane’s end, then branches back on VCCNZ while the counter is below an end. The PR writes 1 in all 32 lanes. The guest result is 2 in every lane. The complementary VCCZ loop exits at 1 as expected. Both cases finish in at most two iterations.

The fix and regression test use the structuriser’s existing wave_any and account for exit() inverting the predicate and swapping successors. Both cases pass on WARP after the fix. The portable shader suite passed 170 tests, with 2 ignored.

For workload context, the PR’s rule fired in 11 of 455 submitted pixel shaders across three local prison checkpoint frames. All 11 already used the correct polarity for their loop. None of the 20 shader stages from our 15 highest-ranked timed pipelines selected the rule, so I have no FPS measurement to attribute to this fix. AI-assisted.

**@⁠ryotdev** on GitHub · 2026-11-25 01:01 UTC · [original](https://github.com/fxceless/victory-fork/pull/196#issuecomment-7149134458) I found a branch-direction case in `wave_loop_exit` on `365c3b2`. When `s_cbranch_vccnz` is the back edge, the wave must keep looping while **any lane still has work**. The current lowering stops the entire host wave as soon as **any lane is done**. I reproduced this with a hand-written wave32 compute shader on Windows D3D12 WARP. The 32 lanes alternate between end values 1 and 2. A shared counter increments, compares against each lane’s end, then branches back on VCCNZ while the counter is below an end. The PR writes 1 in all 32 lanes. The guest result is 2 in every lane. The complementary VCCZ loop exits at 1 as expected. Both cases finish in at most two iterations. The [fix and regression test](https://github.com/ryotdev/victory-gta6/commit/178b1a7086c08a456533b0d9d7a09a4170e2d111) use the structuriser’s existing `wave_any` and account for `exit()` inverting the predicate and swapping successors. Both cases pass on WARP after the fix. The portable shader suite passed 170 tests, with 2 ignored. For workload context, the PR’s rule fired in 11 of 455 submitted pixel shaders across three local prison checkpoint frames. All 11 already used the correct polarity for their loop. None of the 20 shader stages from our 15 highest-ranked timed pipelines selected the rule, so I have no FPS measurement to attribute to this fix. AI-assisted.
Author
Owner

@⁠JRamos1993 on GitHub · 2026-11-25 06:56 UTC · original

Offline check on the retail shader pack: no program gained or lost, but 1271 programs' DXIL changes.

victory translate --validate --list over the title's full shader pack (26,084 programs) on an RTX 5090, main 310c6eb against this head merged onto it. I added a local DXIL hash on each validated line (two runs of one build hash the same):

  • Validated: 25,382 in both, none lost.
  • DXIL: 1271 of those programs emit different DXIL. So this changes the code of that many of the title's shaders, and they all still pass the validator.

I have not looked at what changes in them or checked it in game.

AI use: Claude Code with Claude Opus 5.5 ran the pack and wrote this. Nothing from the title is in it.

**@⁠JRamos1993** on GitHub · 2026-11-25 06:56 UTC · [original](https://github.com/fxceless/victory-fork/pull/196#issuecomment-7155316466) **Offline check on the retail shader pack: no program gained or lost, but 1271 programs' DXIL changes.** `victory translate --validate --list` over the title's full shader pack (26,084 programs) on an RTX 5090, `main` `310c6eb` against this head merged onto it. I added a local DXIL hash on each validated line (two runs of one build hash the same): - **Validated:** 25,382 in both, none lost. - **DXIL:** **1271** of those programs emit different DXIL. So this changes the code of that many of the title's shaders, and they all still pass the validator. I have not looked at what changes in them or checked it in game. AI use: Claude Code with Claude Opus 5.5 ran the pack and wrote this. Nothing from the title is in it.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-25 10:59 UTC · original

Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head 365c3b2 into main f85101b in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings fails with exactly the errors main itself has on this machine (placed_filler_twins, depth_written, a sort; PR #841 fixes them); with --all-features it fails with the same number of errors as main (4). This PR adds none and removes none. cargo test --workspace --locked: run 1: one failure, run 2: 555 passed, 0 failed, 11 ignored (main alone: 555 passed). The failure is indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields, which fails on main itself most runs here (PR #849 fixes its assertion; see issue #850). The title was not run, so this says nothing about in-game effect. No game data.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-25 10:59 UTC · [original](https://github.com/fxceless/victory-fork/pull/196#issuecomment-7160438235) Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head `365c3b2` into `main` `f85101b` in a throwaway tree (no conflict). `cargo clippy --workspace --all-targets --locked -- -D warnings` fails with exactly the errors `main` itself has on this machine (`placed_filler_twins`, `depth_written`, a sort; PR #841 fixes them); with `--all-features` it fails with the same number of errors as `main` (4). This PR adds none and removes none. `cargo test --workspace --locked`: run 1: one failure, run 2: 555 passed, 0 failed, 11 ignored (`main` alone: 555 passed). The failure is `indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields`, which fails on `main` itself most runs here (PR #849 fixes its assertion; see issue #850). The title was not run, so this says nothing about in-game effect. No game data. AI-assisted (Claude Code); no game data.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-196'
git switch 'github-bot/gh-196'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-196'
git switch 'github-bot/gh-196'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-196'
git switch 'main'
git merge --squash 'github-bot/gh-196'
git switch 'main'
git merge --ff-only 'github-bot/gh-196'
git switch 'main'
git merge 'github-bot/gh-196'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.