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

Open
JaumeMarRib wants to merge 1 commit from upstream-pr/196 into main
JaumeMarRib commented 2026-11-24 22:26:58 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by JaumeMarRib on 2026-11-24T22:26:58Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:issue:6592657673 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/196). Originally posted by [JaumeMarRib](https://github.com/JaumeMarRib) on 2026-11-24T22:26:58Z. --- ## 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)
Flyander commented 2026-11-24 23:09:08 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Flyander on 2026-11-24T22:45:03Z.

Review: COMMENTED


The issue #107 timing and the 7-minute RTX 5070 run make the impact clear. One coverage gap before this lands: wave_loop_exit() changes branch conditions based on loop membership and a wave vote, but this PR adds no isolated regression test for that decision.

Could you add a synthetic program with a lane-dependent s_cbranch_vccz loop exit and check the emitted/executed result on a 32-lane GPU? In particular, it would pin that any lane reaching the exit ends the console wave's loop, while a wave with no participating lanes preserves the existing behavior. The game run is valuable integration evidence; this would make the control-flow rule reproducible without the title.

<!-- greyfinch-sync:fxceless/victory-fork:review:6048576832 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/196#pullrequestreview-6048576832). Originally posted by [Flyander](https://github.com/Flyander) on 2026-11-24T22:45:03Z. **Review:** COMMENTED --- The issue #107 timing and the 7-minute RTX 5070 run make the impact clear. One coverage gap before this lands: `wave_loop_exit()` changes branch conditions based on loop membership and a wave vote, but this PR adds no isolated regression test for that decision. Could you add a synthetic program with a lane-dependent `s_cbranch_vccz` loop exit and check the emitted/executed result on a 32-lane GPU? In particular, it would pin that any lane reaching the exit ends the console wave's loop, while a wave with no participating lanes preserves the existing behavior. The game run is valuable integration evidence; this would make the control-flow rule reproducible without the title.
rocobalt1 commented 2026-11-25 00:10:04 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by rocobalt1 on 2026-11-24T23:13:57Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7147165250 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/196#issuecomment-7147165250). Originally posted by [rocobalt1](https://github.com/rocobalt1) on 2026-11-24T23:13:57Z. --- 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.
luisaugustz commented 2026-11-25 00:10:10 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by luisaugustz on 2026-11-24T23:50:20Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7147851402 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/196#issuecomment-7147851402). Originally posted by [luisaugustz](https://github.com/luisaugustz) on 2026-11-24T23:50:20Z. --- **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._
Lospro772 commented 2026-11-25 01:11:22 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Lospro772 on 2026-11-25T00:09:31Z.

Review: APPROVED


No description provided.

<!-- greyfinch-sync:fxceless/victory-fork:review:6049509436 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/196#pullrequestreview-6049509436). Originally posted by [Lospro772](https://github.com/Lospro772) on 2026-11-25T00:09:31Z. **Review:** APPROVED --- _No description provided._
luisaugustz commented 2026-11-25 01:11:58 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by luisaugustz on 2026-11-25T00:23:40Z.


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).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7148463300 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/196#issuecomment-7148463300). Originally posted by [luisaugustz](https://github.com/luisaugustz) on 2026-11-25T00:23:40Z. --- **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)._
ryotdev commented 2026-11-25 01:12:06 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by ryotdev on 2026-11-25T01:01:53Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7149134458 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/196#issuecomment-7149134458). Originally posted by [ryotdev](https://github.com/ryotdev) on 2026-11-25T01:01:53Z. --- 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.
JRamos1993 commented 2026-11-25 07:06:19 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by JRamos1993 on 2026-11-25T06:56:23Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7155316466 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/196#issuecomment-7155316466). Originally posted by [JRamos1993](https://github.com/JRamos1993) on 2026-11-25T06:56:23Z. --- **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.
MamaLeVrai commented 2026-11-25 11:10:41 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by MamaLeVrai on 2026-11-25T10:59:21Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7160438235 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/196#issuecomment-7160438235). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-25T10:59:21Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/196:upstream-pr/196'
git switch 'upstream-pr/196'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/196'
git switch 'upstream-pr/196'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/196'
git switch 'upstream-pr/196'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/196'
git switch 'main'
git merge --squash 'upstream-pr/196'
git switch 'main'
git merge --ff-only 'upstream-pr/196'
git switch 'main'
git merge 'upstream-pr/196'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
fxceless/victory-fork!196
No description provided.