Shaders: first-lane reads of values alike in a console wave let the structure builder run on 32-lane GPUs #497

Open
justrealyme wants to merge 2 commits from upstream-pr/497 into main
justrealyme commented 2026-11-25 01:40:08 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by justrealyme on 2026-11-25T01:40:08Z.


What

On a GPU with 32-lane waves (NVIDIA), a console wave64 program runs as two host waves, and a v_readfirstlane where not every lane runs is refused: a first-lane read where not every lane runs. Three programs of the ray-tracing structure builder (XboxBvhBuilder.dll at 0x99160, 0x9a830, 0x9be80; compute 39321a95223001ed, 77360df21e12ea43, 9fc111d3be79364f) stop that way, and since the builder runs all or none (builder_runs), it can never run on a 32-lane GPU: the ray-tracing structure builder stays off: ... missing=3 of=53.

Their shape: a prefix over wave totals in a 512-thread group. Each wave scans its lanes, its last lane writes the total to LDS, a barrier, then under if (id >> 6 != 0) each wave loops over the totals before it, lanes leaving at their own wave's index, with v_readfirstlane of the running sum each iteration. The sum and the conditions are the same in every lane of a console wave, so each host wave can take its own first lane, but lane_uniform skipped guarded instructions, loop-carried phis and LDS reads, so it could not tell.

lane_uniform now runs to a fixed point and also counts:

  • an instruction under a condition whose atoms are compares of alike values (or uniform), over an old value that is alike too (a wave the condition leaves out keeps that);
  • an LDS read at an alike address;
  • a phi whose predecessors are all reached by whole console waves (past branches on alike conditions only; all itself is unchanged, since it also decides where group barriers go);
  • the thread id's x shifted right by 6 or more, where console waves are runs of 64 ids along x (x a multiple of 64, or a one-row group).

Its result is still only used for v_readfirstlane in the two-host-wave form.

Checked

  • New GPU test a_first_lane_read_of_a_wave_alike_sum_under_a_wave_alike_loop (wave64_tests.rs): the same shape in 256 threads (four console waves, with a read across the two host waves so they exchange). It fails on main with exactly this refusal, and passes with the change on an RTX 5070 Ti, driver 621.40: every thread gets the sum of the waves before its own.
  • VICTORY_HOST_WAVE=32 victory translate --validate over the title's shader pack, executable and builder DLL, before and after, comparing every emitted shader byte for byte: the only programs that change are these three (now emitted and validated; compute 2,718 to 2,721 of 2,734) and one other builder program (0x95220), whose only first-lane read is of id >> 6 and now skips an exchange that gave the same value. Nothing else changes.
  • cargo test -p victory-shader on this branch (on top of c96b4f2): 215 passed. Clippy (--all-features) clean.
  • In the world with VICTORY_BVH_BUILDER=1, the builder now runs: the ray-tracing structure builder runs: all of its programs have host pipelines pipelines=53. The title then crashes within about 15 s (access violations in title code), with and without VICTORY_BVH_QUARANTINE=1, so the builder stays off by default, and this does not make anything visible yet. It removes the blocker that kept the builder from being tried at all on NVIDIA.

AI-assisted (Claude Code). Built and run on my machine with my own copy; no game data in the change or here.

🤖 Generated with Claude Code

<!-- greyfinch-sync:fxceless/victory-fork:issue:6595158391 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/497). Originally posted by [justrealyme](https://github.com/justrealyme) on 2026-11-25T01:40:08Z. --- ## What On a GPU with 32-lane waves (NVIDIA), a console wave64 program runs as two host waves, and a `v_readfirstlane` where not every lane runs is refused: `a first-lane read where not every lane runs`. Three programs of the ray-tracing structure builder (`XboxBvhBuilder.dll` at `0x99160`, `0x9a830`, `0x9be80`; compute `39321a95223001ed`, `77360df21e12ea43`, `9fc111d3be79364f`) stop that way, and since the builder runs all or none (`builder_runs`), **it can never run on a 32-lane GPU**: `the ray-tracing structure builder stays off: ... missing=3 of=53`. Their shape: a prefix over wave totals in a 512-thread group. Each wave scans its lanes, its last lane writes the total to LDS, a barrier, then under `if (id >> 6 != 0)` each wave loops over the totals before it, lanes leaving at their own wave's index, with `v_readfirstlane` of the running sum each iteration. The sum and the conditions are the same in every lane of a console wave, so each host wave can take its own first lane, but `lane_uniform` skipped guarded instructions, loop-carried phis and LDS reads, so it could not tell. `lane_uniform` now runs to a fixed point and also counts: - an instruction under a condition whose atoms are compares of alike values (or uniform), over an old value that is alike too (a wave the condition leaves out keeps that); - an LDS read at an alike address; - a phi whose predecessors are all reached by whole console waves (past branches on alike conditions only; `all` itself is unchanged, since it also decides where group barriers go); - the thread id's x shifted right by 6 or more, where console waves are runs of 64 ids along x (x a multiple of 64, or a one-row group). Its result is still only used for `v_readfirstlane` in the two-host-wave form. ## Checked - New GPU test `a_first_lane_read_of_a_wave_alike_sum_under_a_wave_alike_loop` (`wave64_tests.rs`): the same shape in 256 threads (four console waves, with a read across the two host waves so they exchange). It fails on `main` with exactly this refusal, and passes with the change on an **RTX 5070 Ti, driver 621.40**: every thread gets the sum of the waves before its own. - `VICTORY_HOST_WAVE=32 victory translate --validate` over the title's shader pack, executable and builder DLL, before and after, comparing every emitted shader byte for byte: the only programs that change are these three (now emitted and validated; compute 2,718 to 2,721 of 2,734) and one other builder program (`0x95220`), whose only first-lane read is of `id >> 6` and now skips an exchange that gave the same value. Nothing else changes. - `cargo test -p victory-shader` on this branch (on top of `c96b4f2`): 215 passed. Clippy (`--all-features`) clean. - In the world with `VICTORY_BVH_BUILDER=1`, the builder now runs: `the ray-tracing structure builder runs: all of its programs have host pipelines pipelines=53`. **The title then crashes within about 15 s** (access violations in title code), with and without `VICTORY_BVH_QUARANTINE=1`, so the builder stays off by default, and this does not make anything visible yet. It removes the blocker that kept the builder from being tried at all on NVIDIA. AI-assisted (Claude Code). Built and run on my machine with my own copy; no game data in the change or here. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
ryotdev commented 2026-11-25 06:06:38 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by ryotdev on 2026-11-25T05:32:15Z.


I found a case where the new proof in lane_uniform classifies a varying thread ID as uniform. RDNA2's v_lshrrev_b32 uses the low five bits of the shift count. With inline 32, lanes 0 and 32 produce 0 and 32. Treating this as a shift past the wave width can let the two host halves choose different values for a first-lane read. The builder's shift by six still qualifies. AMD RDNA2 ISA, �12.7

I put a cherry-pickable fix and regression test directly on your head. The test decodes a hand-written shift for each inline integer 0�64 and checks the proof against all 64 lane IDs. It fails on the original head at shift 32. With the fix the shader library suite passed on Linux (172 passed, 2 ignored), and cargo xtask policy passed. This checks the translator proof; I didn't run a game or GPU for this correction.

AI-assisted review.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7153870889 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/497#issuecomment-7153870889). Originally posted by [ryotdev](https://github.com/ryotdev) on 2026-11-25T05:32:15Z. --- I found a case where the new proof in `lane_uniform` classifies a varying thread ID as uniform. RDNA2's `v_lshrrev_b32` uses the low five bits of the shift count. With inline 32, lanes 0 and 32 produce 0 and 32. Treating this as a shift past the wave width can let the two host halves choose different values for a first-lane read. The builder's shift by six still qualifies. [AMD RDNA2 ISA, �12.7](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) I put a [cherry-pickable fix and regression test](https://github.com/ryotdev/victory-gta6/commit/9e24afa06d4d332d432c92680c398b31f59f28d3) directly on your head. The test decodes a hand-written shift for each inline integer 0�64 and checks the proof against all 64 lane IDs. It fails on the original head at shift 32. With the fix the shader library suite passed on Linux (172 passed, 2 ignored), and `cargo xtask policy` passed. This checks the translator proof; I didn't run a game or GPU for this correction. AI-assisted review.
justrealyme commented 2026-11-25 08:09:04 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by justrealyme on 2026-11-25T07:51:40Z.


Thanks, you're right: the b32 shift takes only the low five bits of the count, so an inline 32 (or anything with the low bits under 6) isn't a shift past the wave. I fast-forwarded the branch to your commit 9e24afa as is.

Checked on an RTX 5070 Ti (driver 621.40, Windows 11): the shader library suite passes, 216 passed and 3 ignored, including your new test and the GPU test from the first commit. I've taken the same commit into my own fork too.

AI-assisted (Claude Code).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7156333704 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/497#issuecomment-7156333704). Originally posted by [justrealyme](https://github.com/justrealyme) on 2026-11-25T07:51:40Z. --- Thanks, you're right: the b32 shift takes only the low five bits of the count, so an inline 32 (or anything with the low bits under 6) isn't a shift past the wave. I fast-forwarded the branch to your commit 9e24afa as is. Checked on an RTX 5070 Ti (driver 621.40, Windows 11): the shader library suite passes, 216 passed and 3 ignored, including your new test and the GPU test from the first commit. I've taken the same commit into my own fork too. AI-assisted (Claude Code).
Dathinel commented 2026-11-25 23:09:56 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Dathinel on 2026-11-25T22:27:17Z.


Measured the synthetic prefix test on an RTX 3050 Laptop (32-lane hardware), including the 512-thread group size described for the builder. With the proof from 9e24afa on our local Series S branch, both DXIL variants validated, both compute PSOs were created, and every output matched the CPU prefix of (10 + wave index). At 256 threads: 256/256 matched, last wave 33. At 512 threads: 512/512 matched, last wave 91. On the same base without the proof the 256-thread fixture failed to lower at offset 144. This tests arithmetic and cross-half communication on synthetic input; it does not exercise a live acceleration structure. AI-assisted.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7176382198 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/497#issuecomment-7176382198). Originally posted by [Dathinel](https://github.com/Dathinel) on 2026-11-25T22:27:17Z. --- Measured the synthetic prefix test on an RTX 3050 Laptop (32-lane hardware), including the 512-thread group size described for the builder. With the proof from 9e24afa on our local Series S branch, both DXIL variants validated, both compute PSOs were created, and every output matched the CPU prefix of (10 + wave index). At 256 threads: 256/256 matched, last wave 33. At 512 threads: 512/512 matched, last wave 91. On the same base without the proof the 256-thread fixture failed to lower at offset 144. This tests arithmetic and cross-half communication on synthetic input; it does not exercise a live acceleration structure. AI-assisted.
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/497:upstream-pr/497'
git switch 'upstream-pr/497'

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/497'
git switch 'upstream-pr/497'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/497'
git switch 'upstream-pr/497'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/497'
git switch 'main'
git merge --squash 'upstream-pr/497'
git switch 'main'
git merge --ff-only 'upstream-pr/497'
git switch 'main'
git merge 'upstream-pr/497'
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!497
No description provided.