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

Open
ANDREANIADS wants to merge 3 commits from upstream-pr/345 into a-publier
ANDREANIADS commented 2026-11-26 21:22:16 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by ANDREANIADS on 2026-11-26T21:22:16Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:5517307540 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/345). Originally posted by [ANDREANIADS](https://github.com/ANDREANIADS) on 2026-11-26T21:22:16Z. --- 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.
ANDREANIADS commented 2026-11-26 21:27:35 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by ANDREANIADS on 2026-11-26T21:27:35Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7203747165 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/345#issuecomment-7203747165). Originally posted by [ANDREANIADS](https://github.com/ANDREANIADS) on 2026-11-26T21:27:35Z. --- 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.
Aniseto commented 2026-11-26 22:01:36 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by Aniseto on 2026-11-26T22:01:36Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7204284814 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/345#issuecomment-7204284814). Originally posted by [Aniseto](https://github.com/Aniseto) on 2026-11-26T22:01:36Z. --- 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.
MamaLeVrai commented 2026-11-26 22:22:55 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by MamaLeVrai on 2026-11-26T22:22:55Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7204625815 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/345#issuecomment-7204625815). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-26T22:22:55Z. --- 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 commented 2026-11-26 22:51:49 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by MamaLeVrai on 2026-11-26T22:51:49Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7205049877 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/345#issuecomment-7205049877). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-26T22:51:49Z. --- 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 commented 2026-11-27 00:12:23 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by MamaLeVrai on 2026-11-27T00:12:23Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7206263493 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/345#issuecomment-7206263493). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-27T00:12:23Z. --- 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.
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/345:upstream-pr/345'
git switch 'upstream-pr/345'

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 'a-publier'
git merge --no-ff 'upstream-pr/345'
git switch 'upstream-pr/345'
git rebase 'a-publier'
git switch 'a-publier'
git merge --ff-only 'upstream-pr/345'
git switch 'upstream-pr/345'
git rebase 'a-publier'
git switch 'a-publier'
git merge --no-ff 'upstream-pr/345'
git switch 'a-publier'
git merge --squash 'upstream-pr/345'
git switch 'a-publier'
git merge --ff-only 'upstream-pr/345'
git switch 'a-publier'
git merge 'upstream-pr/345'
git push origin 'a-publier'
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
Belobug/VIctory-Belobug-AMD!345
No description provided.