Preserve both words of a wave64 branch mask when EXEC is empty #345

Open
github-bot wants to merge 3 commits from github-bot/gh-345 into a-publier AGit
Owner

@⁠ANDREANIADS on GitHub · 2026-11-26 21:22 UTC · original
ANDREANIADS:fix-wave64-branch-mask-join → a-publier · +178 −3 · 4 files · 3 commits · open

On a-publier@cd8dfc06, the new compute shader fails during translation at byte offset 0x38 with “a lane mask holding lanes elsewhere read as data”. The shader updates a saved mask inside a divergent branch, then reads its low and high words after the join. This case came out of the NVIDIA investigation in #259.

Compiler change

With no active lanes, the vector comparison clears both words of VCC. OR-ing those zeros into the saved mask leaves both words intact. The new check in without_skips proves this identity for each incoming SSA value before removing the skip. It applies to a single compare/OR block over ordinary SGPR pairs. Negative tests cover a different incoming operand and observable changes to SCC or VCC.

Before and after on hardware

Tested with a GeForce RTX 3070 (8 GiB), NVIDIA driver 621.40, Windows 11 build 26300.9974, native wave32, WARP off. The original revision stopped before dispatch. With this patch, all 64 lanes returned the expected pair in each of four dispatches, for 512 matching 32-bit reads.

Branch threshold Low word High word
0 ffffffff 007fffff
32 0000001f 007fffff
48 0000001f 007f0000
64 0000001f 00000000

The IR and wave64 suites passed 33 tests. Three hardware paths in pre-existing tests reported “not run” on this adapter. The non-emitter library suite passed 121 tests, with 11 tests in common across those runs. The new hardware test ran all four cases.

To reproduce the individual regression on a machine with the project toolchain and a compatible physical adapter:

cargo test --locked --release -p victory-shader --lib a_branch_mask_preserves_both_words_on_the_host -- --nocapture --test-threads=1

Local validation used an isolated release build with rustc 1.98.0 MSVC (the repository pins 1.98.1). The offline cache supplied thiserror/thiserror-impl 2.0.19, unicode-ident 1.0.24, syn 3.0.3 and zlib-rs 0.6.3. Windows bindings matched the project. These measurements cover the synthetic shader. Game FPS, VRAM use and ray tracing still require a game run.

Implemented and tested with Codex.

**@⁠ANDREANIADS** on GitHub · 2026-11-26 21:22 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/345) `ANDREANIADS:fix-wave64-branch-mask-join` → `a-publier` · +178 −3 · 4 files · 3 commits · open On `a-publier@cd8dfc06`, the new compute shader fails during translation at byte offset `0x38` with “a lane mask holding lanes elsewhere read as data”. The shader updates a saved mask inside a divergent branch, then reads its low and high words after the join. This case came out of the NVIDIA investigation in #259. ### Compiler change With no active lanes, the vector comparison clears both words of VCC. OR-ing those zeros into the saved mask leaves both words intact. The new check in `without_skips` proves this identity for each incoming SSA value before removing the skip. It applies to a single compare/OR block over ordinary SGPR pairs. Negative tests cover a different incoming operand and observable changes to SCC or VCC. ### Before and after on hardware Tested with a GeForce RTX 3070 (8 GiB), NVIDIA driver 621.40, Windows 11 build 26300.9974, native wave32, WARP off. The original revision stopped before dispatch. With this patch, all 64 lanes returned the expected pair in each of four dispatches, for 512 matching 32-bit reads. | Branch threshold | Low word | High word | | ---: | --- | --- | | 0 | `ffffffff` | `007fffff` | | 32 | `0000001f` | `007fffff` | | 48 | `0000001f` | `007f0000` | | 64 | `0000001f` | `00000000` | The IR and wave64 suites passed 33 tests. Three hardware paths in pre-existing tests reported “not run” on this adapter. The non-emitter library suite passed 121 tests, with 11 tests in common across those runs. The new hardware test ran all four cases. To reproduce the individual regression on a machine with the project toolchain and a compatible physical adapter: ```powershell cargo test --locked --release -p victory-shader --lib a_branch_mask_preserves_both_words_on_the_host -- --nocapture --test-threads=1 ``` Local validation used an isolated release build with rustc 1.98.0 MSVC (the repository pins 1.98.1). The offline cache supplied thiserror/thiserror-impl 2.0.19, unicode-ident 1.0.24, syn 3.0.3 and zlib-rs 0.6.3. Windows bindings matched the project. These measurements cover the synthetic shader. Game FPS, VRAM use and ray tracing still require a game run. Implemented and tested with Codex.
Recognize a two-instruction VOPC / s_or_b64 block whose output equals its incoming mask when EXEC is empty. Match both SSA words and retain the original branch whenever another observable scalar would change. Add positive and negative IR cases.

Co-authored-by: Codex <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:58:01 +00:00
Author
Owner

@⁠ANDREANIADS on GitHub · 2026-11-26 21:27 UTC · original

I also ran the four existing emit::intersect_tests:: cases against both the base compiler (cd8dfc06) and this PR (3dac8db9) on the same RTX 3070. Both runs passed 4/4 with no skips. The fixtures compare the emitted shader’s 32-bit and 64-bit ray/node intersection outputs against the Rust reference, using both a host buffer and emulated title memory. Each fixture ran on the hardware adapter and separately on WARP as a control.

The physical-adapter run selected VICTORY_D3D12_ADAPTER=RTX 3070 with VICTORY_WARP=0. To repeat, use the emit::intersect_tests:: test filter with --nocapture --test-threads=1. This adds a regression check for the underlying intersection math. In-game lighting, device removal and frame time were outside this test.

**@⁠ANDREANIADS** on GitHub · 2026-11-26 21:27 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/345#issuecomment-7203747165) I also ran the four existing `emit::intersect_tests::` cases against both the base compiler (`cd8dfc06`) and this PR (`3dac8db9`) on the same RTX 3070. Both runs passed 4/4 with no skips. The fixtures compare the emitted shader’s 32-bit and 64-bit ray/node intersection outputs against the Rust reference, using both a host buffer and emulated title memory. Each fixture ran on the hardware adapter and separately on WARP as a control. The physical-adapter run selected `VICTORY_D3D12_ADAPTER=RTX 3070` with `VICTORY_WARP=0`. To repeat, use the `emit::intersect_tests::` test filter with `--nocapture --test-threads=1`. This adds a regression check for the underlying intersection math. In-game lighting, device removal and frame time were outside this test.
Author
Owner

@⁠Aniseto on GitHub · 2026-11-26 22:01 UTC · original

Ran the BVH intersection fixture at 3dac8db on an NVIDIA Blackwell desktop part:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, Rust 1.98.1 (pinned by rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5 (shared env), debug build; VICTORY_D3D12_ADAPTER=NVIDIA.

cargo test -p victory-shader --lib emit::intersect_tests -- --test-threads=1
8 passed; 0 failed; 0 ignored; 0 measured; 300 filtered out      (exit 0)

All eight emit::intersect_tests pass on the real adapter, including the native wave32 cases. The thread has a report on an RTX 3070 (driver 621.40) and a base-vs-head comparison by another user; this adds a desktop RTX 5070 Ti with driver 32.0.16.2124. The new compiler check itself is exercised by the translated fixtures, not by an injected empty-EXEC runtime case beyond what these tests cover.

Not tested: a retail title, a paired smoke run, the full workspace suite, release profile, AMD and Intel GPUs, native wave64 hosts, Wine, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

**@⁠Aniseto** on GitHub · 2026-11-26 22:01 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/345#issuecomment-7204284814) Ran the BVH intersection fixture at `3dac8db` on an NVIDIA Blackwell desktop part: Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, Rust 1.98.1 (pinned by `rust-toolchain.toml`), MSVC 14.44.35207, DXC 1.9.2609.5 (shared env), debug build; `VICTORY_D3D12_ADAPTER=NVIDIA`. ``` cargo test -p victory-shader --lib emit::intersect_tests -- --test-threads=1 8 passed; 0 failed; 0 ignored; 0 measured; 300 filtered out (exit 0) ``` All eight `emit::intersect_tests` pass on the real adapter, including the native wave32 cases. The thread has a report on an RTX 3070 (driver 621.40) and a base-vs-head comparison by another user; this adds a desktop RTX 5070 Ti with driver 32.0.16.2124. The new compiler check itself is exercised by the translated fixtures, not by an injected empty-EXEC runtime case beyond what these tests cover. Not tested: a retail title, a paired smoke run, the full workspace suite, release profile, AMD and Intel GPUs, native wave64 hosts, Wine, game data. AI-assisted (OpenCode), model: **DeepSeek V4.1 Flash Free** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-26 22:22 UTC · original

On an RDNA 2 card the new test fails at translation. The patch's case is still refused when the host wave is 64 lanes.

Host: RX 6950 XT 16 GB, driver 32.0.21045.29003 (wave lanes 32 to 64), Windows 11 build 26300, Rust 1.98.1, release, at 3dac8db:

emit::wave64_tests::a_branch_mask_preserves_both_words_on_the_host ... FAILED
panicked at crates\victory-shader\src\emit\wave64_tests.rs:1415:25:
translation: Unsupported { offset: 56, what: "a lane mask holding lanes elsewhere read as data" }

It is the same refusal you describe for cd8dfc06. The test translates with TEST_HOST_WAVE set to host.translation_caps()'s wave, and here that is presumably 64, where on the RTX 3070 it is 32. So the 64-lane lowering does not reach the identity without_skips now proves, or refuses earlier. The rest of cargo test --release -p victory-shader --lib passes on this card: 303 passed, 1 failed (this one), 4 ignored.

If the PR only means to cover 32-lane hosts, the test could take wave == 32 as its condition. Otherwise the 64-lane path needs the same handling.

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

**@⁠MamaLeVrai** on GitHub · 2026-11-26 22:22 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/345#issuecomment-7204625815) On an RDNA 2 card the new test fails at translation. The patch's case is still refused when the host wave is 64 lanes. Host: RX 6950 XT 16 GB, driver 32.0.21045.29003 (wave lanes 32 to 64), Windows 11 build 26300, Rust 1.98.1, release, at `3dac8db`: ``` emit::wave64_tests::a_branch_mask_preserves_both_words_on_the_host ... FAILED panicked at crates\victory-shader\src\emit\wave64_tests.rs:1415:25: translation: Unsupported { offset: 56, what: "a lane mask holding lanes elsewhere read as data" } ``` It is the same refusal you describe for `cd8dfc06`. The test translates with `TEST_HOST_WAVE` set to `host.translation_caps()`'s wave, and here that is presumably 64, where on the RTX 3070 it is 32. So the 64-lane lowering does not reach the identity `without_skips` now proves, or refuses earlier. The rest of `cargo test --release -p victory-shader --lib` passes on this card: 303 passed, 1 failed (this one), 4 ignored. If the PR only means to cover 32-lane hosts, the test could take `wave == 32` as its condition. Otherwise the 64-lane path needs the same handling. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-26 22:51 UTC · original

A follow-up on why it stays refused on a 64-lane host. I traced it on the RX 6950 XT but have no fix:

  • In emit(), every retry (the forms without early-outs or skips, including ir::without_skips(p, true) with your mask_or_on_empty) sits behind lower::host_max_wave() == 32. On RDNA, translation_caps() gives 64, so none of them runs.
  • I tried running both without_skips forms on 64-lane hosts too, for a MASK_ELSEWHERE refusal of a wave64 compute program. The deep form exists for this test's program (without_skips(p, true) is Some, without_skips(p, false) is None) and structures fine. Its emission is still refused at offset 56 with the same MASK_ELSEWHERE.
  • The reason is in Lowering::mask_dword: a mask made outside the active set is accepted only when whole, which needs self.exchange.is_some(), that is two host waves exchanging. On a host that runs the console wave whole there is no exchange, and all_lanes cannot tell which blocks every lane runs (it answers true for every block without exchange data). So the 64-lane path would need its own "this block runs every lane" information before mask_dword can accept such a mask.

So the PR as it stands helps 32-lane hosts only. The new test could check for wave == 32 (or skip when rdna is true) until the 64-lane lowering learns the same thing.

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

**@⁠MamaLeVrai** on GitHub · 2026-11-26 22:51 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/345#issuecomment-7205049877) A follow-up on why it stays refused on a 64-lane host. I traced it on the RX 6950 XT but have no fix: - In `emit()`, every retry (the forms without early-outs or skips, including `ir::without_skips(p, true)` with your `mask_or_on_empty`) sits behind `lower::host_max_wave() == 32`. On RDNA, `translation_caps()` gives 64, so none of them runs. - I tried running both `without_skips` forms on 64-lane hosts too, for a `MASK_ELSEWHERE` refusal of a wave64 compute program. The deep form exists for this test's program (`without_skips(p, true)` is `Some`, `without_skips(p, false)` is `None`) and structures fine. Its emission is still refused at offset 56 with the same `MASK_ELSEWHERE`. - The reason is in `Lowering::mask_dword`: a mask made outside the active set is accepted only when `whole`, which needs `self.exchange.is_some()`, that is two host waves exchanging. On a host that runs the console wave whole there is no exchange, and `all_lanes` cannot tell which blocks every lane runs (it answers `true` for every block without exchange data). So the 64-lane path would need its own "this block runs every lane" information before `mask_dword` can accept such a mask. So the PR as it stands helps 32-lane hosts only. The new test could check for `wave == 32` (or skip when `rdna` is true) until the 64-lane lowering learns the same thing. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-27 00:12 UTC · original

Following up on my diagnosis above, here is a fix for 64-lane hosts, as one commit on top of 3dac8db: github.com/MamaLeVrai/VIctory-Belobug-AMD@29e7a59 (branch MamaLeVrai:mask-whole-wave). It is for you to take into this PR if you want it.

  • emit/lower.rs: Lower gets whole_wave: Option<Vec<bool>>, which says per block whether every lane runs it (all_lane_blocks). It is set only for a console wave64 compute program that runs as one 64-lane host wave: wave_size == Some(64), no exchange, host not 32-lane. mask_dword accepts a mask made in such a block, as it already does for the exchange case. So it takes the ballot instead of refusing with MASK_ELSEWHERE.
  • emit/mod.rs: on hosts with 64-lane waves, a wave64 compute program refused with MASK_ELSEWHERE is tried again as without_skips(p, false), then without_skips(p, true), which reaches your mask_or_on_empty identity. Both forms are exact and add no barrier.

On the RX 6950 XT (RDNA 2, 64-lane host), a_branch_mask_preserves_both_words_on_the_host:

  • at 3dac8db: translation: Unsupported { offset: 56, what: "a lane mask holding lanes elsewhere read as data" };
  • with 29e7a59: passes. It translates through without skips, scalars followed with wave 64, and both words are right in all 64 lanes for thresholds 0, 32, 48 and 64.

Full cargo test --release -p victory-shader --lib, twice: 304 passed, 0 failed, 4 ignored.

Caveats: programs that used to fall back to with_mask_ops_on_numbers on 64-lane hosts may now take the ballot. They only do so in blocks every lane runs, the same rule the 32-lane exchange path uses. I have not checked this against the title's shaders. Not run on a 32-lane host either, but that path does not change: the new field is never set there.

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

**@⁠MamaLeVrai** on GitHub · 2026-11-27 00:12 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/345#issuecomment-7206263493) Following up on my diagnosis above, here is a fix for 64-lane hosts, as one commit on top of `3dac8db`: https://github.com/MamaLeVrai/VIctory-Belobug-AMD/commit/29e7a59 (branch `MamaLeVrai:mask-whole-wave`). It is for you to take into this PR if you want it. - **`emit/lower.rs`:** `Lower` gets `whole_wave: Option<Vec<bool>>`, which says per block whether every lane runs it (`all_lane_blocks`). It is set only for a console wave64 compute program that runs as one 64-lane host wave: `wave_size == Some(64)`, no `exchange`, host not 32-lane. `mask_dword` accepts a mask made in such a block, as it already does for the exchange case. So it takes the ballot instead of refusing with `MASK_ELSEWHERE`. - **`emit/mod.rs`:** on hosts with 64-lane waves, a wave64 compute program refused with `MASK_ELSEWHERE` is tried again as `without_skips(p, false)`, then `without_skips(p, true)`, which reaches your `mask_or_on_empty` identity. Both forms are exact and add no barrier. On the RX 6950 XT (RDNA 2, 64-lane host), `a_branch_mask_preserves_both_words_on_the_host`: - at `3dac8db`: `translation: Unsupported { offset: 56, what: "a lane mask holding lanes elsewhere read as data" }`; - with `29e7a59`: passes. It translates through `without skips, scalars followed` with wave 64, and both words are right in all 64 lanes for thresholds 0, 32, 48 and 64. Full `cargo test --release -p victory-shader --lib`, twice: 304 passed, 0 failed, 4 ignored. Caveats: programs that used to fall back to `with_mask_ops_on_numbers` on 64-lane hosts may now take the ballot. They only do so in blocks every lane runs, the same rule the 32-lane exchange path uses. I have not checked this against the title's shaders. Not run on a 32-lane host either, but that path does not change: the new field is never set there. AI-assisted (Claude Code); no game data.
A console wave64 compute program in one 64-lane host wave (WaveSize(64), no
exchange) now knows per IR block whether every lane runs it
(all_lane_blocks), and mask_dword takes the ballot of a mask holding lanes
outside EXEC there, as two exchanging 32-lane host waves already did. emit()
retries such a refusal (MASK_ELSEWHERE) on 64-lane hosts with the
without_skips forms, exact and without barriers.

a_branch_mask_preserves_both_words_on_the_host now translates and passes on
an RX 6950 XT (wave64, all four thresholds).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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/345/head:github-bot/gh-345'
git switch 'github-bot/gh-345'

Merge

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