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

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

@⁠justrealyme on GitHub · 2026-11-25 01:40 UTC · original
justrealyme:wave-alike-first-lane → main · +289 −44 · 2 files · 2 commits · open

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

**@⁠justrealyme** on GitHub · 2026-11-25 01:40 UTC · [original](https://github.com/fxceless/victory-fork/pull/497) `justrealyme:wave-alike-first-lane` → `main` · +289 −44 · 2 files · 2 commits · open ## 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)
On a GPU with 32-lane waves a console wave64 program runs as two host
waves, and a v_readfirstlane where not every lane runs was refused (the
two halves cannot meet there to give each other their first lane). Three
programs of the ray-tracing structure builder stopped that way, so the
builder (all or none) could not run on NVIDIA at all (issue #4).

They read the first lane of a value every lane of the console wave holds
alike, inside a loop whose conditions are alike in the console wave too:
a prefix over wave totals, `if (id >> 6 != 0)` and lanes leaving at their
wave's own index. Then each host wave can take its own first lane.

lane_uniform now proves that: it runs to a fixed point; an instruction
under a condition whose atoms are compares of alike values (or uniform)
counts, over an old value that is alike too (waves the condition leaves
out keep that); LDS reads at an alike address count; phis count where
every predecessor is reached by whole console waves (past branches on
alike conditions only); and the thread id's x shifted right by 6 or more
is alike where console waves are runs of 64 ids along x. The result is
only used for v_readfirstlane in the two-host-wave form.

Checked: a GPU test of the same shape (256 threads, four console waves)
fails on the old analysis with the builder's refusal and passes with
this one on an RTX 5070 Ti (driver 621.40), every thread getting the
console's sum. Over the title's whole shader pack and the builder DLL
(VICTORY_HOST_WAVE=32), the only programs whose translation changes are
these three (now emitted and validated: compute 2,718 -> 2,721 of 2,734)
and one other builder program, whose first-lane read of `id >> 6` now
skips an exchange that gave the same value. victory-shader tests: 211
passed. In a world run with VICTORY_BVH_BUILDER=1 the builder now runs
(all 53 programs have host pipelines); the title still crashes within
seconds of it, with or without VICTORY_BVH_QUARANTINE, so it stays off by
default.

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

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

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.

**@⁠ryotdev** on GitHub · 2026-11-25 05:32 UTC · [original](https://github.com/fxceless/victory-fork/pull/497#issuecomment-7153870889) 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.
Author
Owner

@⁠justrealyme on GitHub · 2026-11-25 07:51 UTC · original

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

**@⁠justrealyme** on GitHub · 2026-11-25 07:51 UTC · [original](https://github.com/fxceless/victory-fork/pull/497#issuecomment-7156333704) 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).
Author
Owner

@⁠Dathinel on GitHub · 2026-11-25 22:27 UTC · original

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.

**@⁠Dathinel** on GitHub · 2026-11-25 22:27 UTC · [original](https://github.com/fxceless/victory-fork/pull/497#issuecomment-7176382198) 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 has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/wave64_tests.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/497/head:github-bot/gh-497'
git switch 'github-bot/gh-497'

Merge

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