Fix ds_bpermute_b32 lane selection on Wave32 hosts #1542

Merged
invismann merged 1 commit from upstream-pr/1542 into main 2026-11-29 08:16:55 +00:00
invismann commented 2026-11-28 21:25:43 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by invismann on 2026-11-28T21:25:43Z.


Supersedes #1019 and replaces the shader portion of #1532.

ds_bpermute_b32 gathers within the caller's 32-lane half and returns zero for inactive source lanes. Wrap the lane index within that half and check its activity before reading. This also lets independent Wave32 halves run the gather.

Includes the test-only module split from #1460 to bring emit/lower.rs within the asset-policy limit.

Validation

  • 39 targeted shader tests passed on Windows with an RTX 4090. One test remained ignored.
  • GPU readbacks checked wrapped indices and inactive sources in 64- and 128-thread groups. Restoring the old lowering made Wave32 translation fail.
  • cargo xtask policy passed for all 307 files.

Strict workspace Clippy stops at the unused colour variable and the manually checked division already present on upstream 77df871e.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5544721615 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1542). Originally posted by [invismann](https://github.com/invismann) on 2026-11-28T21:25:43Z. --- Supersedes #1019 and replaces the shader portion of #1532. `ds_bpermute_b32` gathers within the caller's 32-lane half and returns zero for inactive source lanes. Wrap the lane index within that half and check its activity before reading. This also lets independent Wave32 halves run the gather. Includes the test-only module split from #1460 to bring `emit/lower.rs` within the asset-policy limit. ## Validation - 39 targeted shader tests passed on Windows with an RTX 4090. One test remained ignored. - GPU readbacks checked wrapped indices and inactive sources in 64- and 128-thread groups. Restoring the old lowering made Wave32 translation fail. - `cargo xtask policy` passed for all 307 files. Strict workspace Clippy stops at the unused `colour` variable and the manually checked division already present on upstream `77df871e`.
upipibi commented 2026-11-28 22:23:29 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by upipibi on 2026-11-28T22:23:29Z.


Tested on Ampere: RTX 3070 (10de:2484), driver 616.56, native Windows 11 Pro 10.0.26100, rustc 1.98.1. Debug test profile. The system WARP is the one that ships with Windows. Wave sizes tested: 32 lanes only. This card reports WaveLaneCountMin/Max 32-32, so no 64-lane host ran.

  • Head 5ed4465ba, merged onto main d4b5d5170 (--no-ff, clean, no conflicts). The PR's base is 77df871e, 2 commits behind main. The merge changes the same three files by the same amounts as the PR: lower.rs +34/-814, lower/tests.rs +778, wave64_tests.rs +81. The head was still 5ed4465ba and main still d4b5d5170 when I finished.

What changes. Apart from the test split, the code change is three hunks in lower.rs:

  1. wave64_why_reasons gets a ds_permute arm.
  2. The wave64 to 32-lane split check drops ds_bpermute from its "crosses halves" list. A wave64 program with ds_bpermute_b32 is now split into two Wave32 halves on a 32-lane card instead of being refused.
  3. The ds_bpermute_b32 lowering. The source lane is wrapped within the caller's 32-lane half. Activity comes from a WaveActiveBallot of the guard (the half's ballot word on a 64-lane host wave), and an inactive source gives 0. The early Err("a lane permute across two host waves") is gone.

The split is a pure move. With the old inline mod tests { ... } taken out of lower.rs and de-indented by one level, it is byte-identical to the new lower/tests.rs. It is also byte-identical to #1460's lower/tests.rs.

The bug shows on the 3070 as a refusal, not as wrong values. On main's code, the PR's program does not lower for a 32-lane host (a lane permute across two host waves). The 64-lane lowering builds and validates, but the 3070 refuses its PSO. So on this card, main never runs the program at all. With the PR, the 3070 runs it at 32 lanes and every lane is right. A control that keeps the PR's split check but puts back main's ds_bpermute_b32 lowering is also right on the 3070 (see control B). So on a 32-lane card, the split check is what fixes this program. The new lane wrapping is what matters for a 64-lane host wave, which this card cannot run.

The tests

export CARGO_TARGET_DIR=<separate target dir>
cargo test -p victory-shader --lib --locked -- --nocapture --test-threads=1 backward_permute
VICTORY_WARP=1 cargo test ...   # same command

The filter matches the PR's new test, emit::wave64_tests::backward_permute_wraps_within_its_half_and_zeros_inactive_sources, and the existing emit::tests::a_backward_permute_reads_the_lane_its_address_names (which only lowers; it opens no device).

  • Default, 3 runs: 2 passed, 0 failed, 0 ignored each (0.64 to 0.78 s). Each run printed permute GPU readback passed for 64 threads at width 32 and ... for 128 threads at width 32.
  • VICTORY_WARP=1, 3 runs: 2 passed, 0 failed, 0 ignored each (0.03 s). The new test checks no dispatch here. It printed no readback line.

The new test is a real dispatch, not a CPU replay. It lowers the program for host widths 32 and 64, validates the DXIL, and dispatches only the widths that fall within the adapter's WaveLaneCountMin..=Max. It skips the others with a bare continue and prints nothing. On the 3070, only width 32 runs. Width 64 is lowered and validated, but never dispatched. With VICTORY_WARP=1, Host::new(false) opens WARP (4-4 lanes), so both widths skip and the test passes after lowering and validation only. The same thing happens on any runner without a 32- or 64-lane card. A runner with a 64-lane card would dispatch only width 64.

Adapters and wave sizes

A temporary dispatch test (below) prints GetDesc1 of the adapter behind device.GetAdapterLuid(), and the D3D12_OPTIONS1 wave lane counts, for Host::new(false) and Host::new(true):

run Host::new adapter vendor:device flags wave lanes
default false NVIDIA GeForce RTX 3070 10de:2484 0x0 32-32
default true Microsoft Basic Render Driver 1414:008c 0x2 (software) 4-4
VICTORY_WARP=1 false Microsoft Basic Render Driver 1414:008c 0x2 (software) 4-4

The PR's test uses Host::new(false): the 3070 in default runs, WARP with VICTORY_WARP=1.

A real dispatch on the 3070 (temporary test)

I appended a temporary test to wave64_tests.rs. It runs the PR test's program on both adapters, at 64 and 128 threads and host widths 32 and 64, for the same thresholds (0, 10, 31, 32, 53, 63, 101), 5 rounds each (35 dispatches per case). It counts wrong lanes instead of asserting. It also runs a second variant that puts s_cbranch_execz +2 over the permute, so inactive lanes can leave through a branch. I did not check whether that branch becomes a DXIL branch. I removed the test before the lib suites.

code 3070, width 32 3070, width 64 WARP
merge 4 cases (guard and branch, 64 and 128 threads) x 35 dispatches: 0 wrong lanes PSO refused (The parameter is incorrect.) PSO refused at both widths
control A (main's code) lowering refused: GFX10 code at 0x34: a lane permute across two host waves is not supported (0x38 for the branch variant) PSO refused lowering refused at 32, PSO refused at 64
control B (PR's split check, main's lowering) 4 cases x 35 dispatches: 0 wrong lanes PSO refused PSO refused at both widths

Three runs on the merge and three on each control printed identical lines.

Negative control A: main's code, PR's tests

I reverse-applied the PR's three non-test hunks of lower.rs. This keeps the test split and the PR's test. It builds, with the same single warning as main. These runs also include the temporary test (it matches the filter), so they show 3 tests.

  • Default, 3 runs: 2 passed, 1 failed, 0 ignored each. The PR's test fails. The other two passes are the lowering-only test and the temporary test.
  • VICTORY_WARP=1, 3 runs: 2 passed, 1 failed, 0 ignored each.

All six runs failed the same way, at wave64_tests.rs:187:

permute translation: Unsupported { offset: 52, what: "a lane permute across two host waves" }

That matches the description's "Restoring the old lowering made Wave32 translation fail". The failure is in lowering, before any device is used, so it is the same on WARP.

Negative control B: PR's split check, main's ds_bpermute_b32 lowering

I reverse-applied only the lowering hunk (hunk 3). It builds, with the same single warning.

  • Default, 3 runs: 3 passed, 0 failed, 0 ignored each (the PR's test, the lowering-only test and the temporary test). The PR's test printed both width 32 readback lines in each run.

So the PR's test does not catch a return to main's lowering on a 32-lane card. Main's lowering masks the source with wave() - 1. That is 31 on a 32-lane host wave, the same as the PR's wrap. On a 64-lane host wave it is 63, which would read the other half. That is my reading of the code. It was not run here.

cargo test -p victory-shader --lib --locked (default, once each)

  • PR merged onto d4b5d5170: 349 passed, 0 failed, 8 ignored (309 s).
  • Plain main d4b5d5170: 348 passed, 0 failed, 8 ignored (312 s).
  • The one extra pass is the new test. The moved tests keep their path, emit::lower::tests (17 in both runs). There were no failures.

The PR adds no compiler warnings. The one warning in both builds, unused colour, is main's (lower.rs:13896 on main, :13895 on the merge).

CI

gh pr checks 1542: only the label check (pass). I did not run clippy or cargo xtask policy. The PR has no comments or reviews yet.

Overlap

  • The PR says it supersedes #1019 and replaces the shader part of #1532. Both are closed.
  • #1460 (the same test-module split, by another author) is still open. Its lower/tests.rs is byte-identical to this PR's, and git merge-tree of the two heads is clean. Whichever lands second carries an empty split.
  • I ran git merge-tree of #1542 against the 23 other open PRs that change lower.rs or wave64_tests.rs. 15 are clean, among them #845, #1504 and #1460. #1450 (Wave32 lowering for known compute kernels, lds.rs and mod.rs only) is clean too.
  • #981 and #978 (whole-wave sections) merge cleanly with main but conflict with #1542. Each has one conflict region, at the old inline mod tests in lower.rs: they add tests there, and #1542 moves that module into lower/tests.rs. The conflict is mechanical (move their new tests into the new file). #1460 would cause the same conflict.
  • #894, #857, #849, #831, #822 and #809 already conflict with main. For #822 I compared conflict regions: two in lower.rs, at the same places with main and with #1542. #822 rewrites the split check and still lists ds_bpermute as crossing halves, so a rebase onto #1542 would have to drop it there too.
  • #845 (DPP and ds_swizzle inactive lanes, which we reported on) does not touch ds_bpermute_b32. The two merge cleanly. #1504 lists ds_permute/ds_bpermute as not covered by its paired form, and merges cleanly too.

Not tested

  • Native 64-lane hosts (this card has 32-lane waves only), so none of the width-64 code, and AMD or Intel cards.
  • A real dispatch on WARP (it refuses both pipelines).
  • ds_bpermute_b32 in a title shader (the checkerboard shadow masks named in the old comment), the game and any title capture.
  • Whether s_cbranch_execz in the temporary test's second variant became a real DXIL branch.
  • Groups other than 64 and 128 threads, and LDS in the same program.
  • Merging alongside #1460, #981 or #978.
  • VICTORY_SHADER_OPT, clippy, cargo xtask policy, the release build, and the rest of the workspace.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7246702339 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1542#issuecomment-7246702339). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-28T22:23:29Z. --- Tested on Ampere: RTX 3070 (`10de:2484`), driver 616.56, native Windows 11 Pro 10.0.26100, rustc 1.98.1. Debug test profile. The system WARP is the one that ships with Windows. Wave sizes tested: **32 lanes only**. This card reports `WaveLaneCountMin/Max` 32-32, so no 64-lane host ran. - Head `5ed4465ba`, merged onto main `d4b5d5170` (`--no-ff`, clean, no conflicts). The PR's base is `77df871e`, 2 commits behind main. The merge changes the same three files by the same amounts as the PR: `lower.rs` +34/-814, `lower/tests.rs` +778, `wave64_tests.rs` +81. The head was still `5ed4465ba` and main still `d4b5d5170` when I finished. **What changes.** Apart from the test split, the code change is three hunks in `lower.rs`: 1. `wave64_why_reasons` gets a `ds_permute` arm. 2. The wave64 to 32-lane split check drops `ds_bpermute` from its "crosses halves" list. A wave64 program with `ds_bpermute_b32` is now split into two Wave32 halves on a 32-lane card instead of being refused. 3. The `ds_bpermute_b32` lowering. The source lane is wrapped within the caller's 32-lane half. Activity comes from a `WaveActiveBallot` of the guard (the half's ballot word on a 64-lane host wave), and an inactive source gives 0. The early `Err("a lane permute across two host waves")` is gone. The split is a pure move. With the old inline `mod tests { ... }` taken out of `lower.rs` and de-indented by one level, it is byte-identical to the new `lower/tests.rs`. It is also byte-identical to #1460's `lower/tests.rs`. **The bug shows on the 3070 as a refusal, not as wrong values.** On main's code, the PR's program does not lower for a 32-lane host (`a lane permute across two host waves`). The 64-lane lowering builds and validates, but the 3070 refuses its PSO. So on this card, main never runs the program at all. With the PR, the 3070 runs it at 32 lanes and every lane is right. A control that keeps the PR's split check but puts back main's `ds_bpermute_b32` lowering is also right on the 3070 (see control B). So on a 32-lane card, the split check is what fixes this program. The new lane wrapping is what matters for a 64-lane host wave, which this card cannot run. **The tests** ``` export CARGO_TARGET_DIR=<separate target dir> cargo test -p victory-shader --lib --locked -- --nocapture --test-threads=1 backward_permute VICTORY_WARP=1 cargo test ... # same command ``` The filter matches the PR's new test, `emit::wave64_tests::backward_permute_wraps_within_its_half_and_zeros_inactive_sources`, and the existing `emit::tests::a_backward_permute_reads_the_lane_its_address_names` (which only lowers; it opens no device). - Default, 3 runs: 2 passed, 0 failed, 0 ignored each (0.64 to 0.78 s). Each run printed `permute GPU readback passed for 64 threads at width 32` and `... for 128 threads at width 32`. - `VICTORY_WARP=1`, 3 runs: 2 passed, 0 failed, 0 ignored each (0.03 s). **The new test checks no dispatch here.** It printed no readback line. The new test is a real dispatch, not a CPU replay. It lowers the program for host widths 32 and 64, validates the DXIL, and dispatches only the widths that fall within the adapter's `WaveLaneCountMin..=Max`. It skips the others with a bare `continue` and prints nothing. On the 3070, only width 32 runs. Width 64 is lowered and validated, but never dispatched. With `VICTORY_WARP=1`, `Host::new(false)` opens WARP (4-4 lanes), so both widths skip and the test passes after lowering and validation only. The same thing happens on any runner without a 32- or 64-lane card. A runner with a 64-lane card would dispatch only width 64. **Adapters and wave sizes** A temporary dispatch test (below) prints `GetDesc1` of the adapter behind `device.GetAdapterLuid()`, and the `D3D12_OPTIONS1` wave lane counts, for `Host::new(false)` and `Host::new(true)`: | run | `Host::new` | adapter | vendor:device | flags | wave lanes | |---|---|---|---|---|---| | default | `false` | NVIDIA GeForce RTX 3070 | `10de:2484` | `0x0` | 32-32 | | default | `true` | Microsoft Basic Render Driver | `1414:008c` | `0x2` (software) | 4-4 | | `VICTORY_WARP=1` | `false` | Microsoft Basic Render Driver | `1414:008c` | `0x2` (software) | 4-4 | The PR's test uses `Host::new(false)`: the 3070 in default runs, WARP with `VICTORY_WARP=1`. **A real dispatch on the 3070 (temporary test)** I appended a temporary test to `wave64_tests.rs`. It runs the PR test's program on both adapters, at 64 and 128 threads and host widths 32 and 64, for the same thresholds (0, 10, 31, 32, 53, 63, 101), 5 rounds each (35 dispatches per case). It counts wrong lanes instead of asserting. It also runs a second variant that puts `s_cbranch_execz +2` over the permute, so inactive lanes can leave through a branch. I did not check whether that branch becomes a DXIL branch. I removed the test before the lib suites. | code | 3070, width 32 | 3070, width 64 | WARP | |---|---|---|---| | merge | 4 cases (guard and branch, 64 and 128 threads) x 35 dispatches: **0 wrong lanes** | PSO refused (`The parameter is incorrect.`) | PSO refused at both widths | | control A (main's code) | **lowering refused**: `GFX10 code at 0x34: a lane permute across two host waves is not supported` (`0x38` for the branch variant) | PSO refused | lowering refused at 32, PSO refused at 64 | | control B (PR's split check, main's lowering) | 4 cases x 35 dispatches: **0 wrong lanes** | PSO refused | PSO refused at both widths | Three runs on the merge and three on each control printed identical lines. **Negative control A: main's code, PR's tests** I reverse-applied the PR's three non-test hunks of `lower.rs`. This keeps the test split and the PR's test. It builds, with the same single warning as main. These runs also include the temporary test (it matches the filter), so they show 3 tests. - Default, 3 runs: **2 passed, 1 failed, 0 ignored each.** The PR's test fails. The other two passes are the lowering-only test and the temporary test. - `VICTORY_WARP=1`, 3 runs: **2 passed, 1 failed, 0 ignored each.** All six runs failed the same way, at `wave64_tests.rs:187`: ``` permute translation: Unsupported { offset: 52, what: "a lane permute across two host waves" } ``` That matches the description's "Restoring the old lowering made Wave32 translation fail". The failure is in lowering, before any device is used, so it is the same on WARP. **Negative control B: PR's split check, main's `ds_bpermute_b32` lowering** I reverse-applied only the lowering hunk (hunk 3). It builds, with the same single warning. - Default, 3 runs: **3 passed, 0 failed, 0 ignored each** (the PR's test, the lowering-only test and the temporary test). The PR's test printed both `width 32` readback lines in each run. So the PR's test does not catch a return to main's lowering on a 32-lane card. Main's lowering masks the source with `wave() - 1`. That is 31 on a 32-lane host wave, the same as the PR's wrap. On a 64-lane host wave it is 63, which would read the other half. That is my reading of the code. It was not run here. **`cargo test -p victory-shader --lib --locked`** (default, once each) - PR merged onto `d4b5d5170`: 349 passed, 0 failed, 8 ignored (309 s). - Plain main `d4b5d5170`: 348 passed, 0 failed, 8 ignored (312 s). - The one extra pass is the new test. The moved tests keep their path, `emit::lower::tests` (17 in both runs). There were no failures. The PR adds no compiler warnings. The one warning in both builds, unused `colour`, is main's (`lower.rs:13896` on main, `:13895` on the merge). **CI** `gh pr checks 1542`: only the `label` check (pass). I did not run clippy or `cargo xtask policy`. The PR has no comments or reviews yet. **Overlap** - The PR says it supersedes #1019 and replaces the shader part of #1532. Both are closed. - **#1460** (the same test-module split, by another author) is still open. Its `lower/tests.rs` is byte-identical to this PR's, and `git merge-tree` of the two heads is clean. Whichever lands second carries an empty split. - I ran `git merge-tree` of #1542 against the 23 other open PRs that change `lower.rs` or `wave64_tests.rs`. 15 are clean, among them #845, #1504 and #1460. #1450 (Wave32 lowering for known compute kernels, `lds.rs` and `mod.rs` only) is clean too. - **#981** and **#978** (whole-wave sections) merge cleanly with main but conflict with #1542. Each has one conflict region, at the old inline `mod tests` in `lower.rs`: they add tests there, and #1542 moves that module into `lower/tests.rs`. The conflict is mechanical (move their new tests into the new file). #1460 would cause the same conflict. - #894, #857, #849, #831, #822 and #809 already conflict with main. For #822 I compared conflict regions: two in `lower.rs`, at the same places with main and with #1542. #822 rewrites the split check and still lists `ds_bpermute` as crossing halves, so a rebase onto #1542 would have to drop it there too. - #845 (DPP and `ds_swizzle` inactive lanes, which we reported on) does not touch `ds_bpermute_b32`. The two merge cleanly. #1504 lists `ds_permute`/`ds_bpermute` as not covered by its paired form, and merges cleanly too. **Not tested** - Native 64-lane hosts (this card has 32-lane waves only), so none of the width-64 code, and AMD or Intel cards. - A real dispatch on WARP (it refuses both pipelines). - `ds_bpermute_b32` in a title shader (the checkerboard shadow masks named in the old comment), the game and any title capture. - Whether `s_cbranch_execz` in the temporary test's second variant became a real DXIL branch. - Groups other than 64 and 128 threads, and LDS in the same program. - Merging alongside #1460, #981 or #978. - `VICTORY_SHADER_OPT`, clippy, `cargo xtask policy`, the release build, and the rest of the workspace. AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
nick0451 commented 2026-11-28 22:35:38 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nick0451 on 2026-11-28T22:35:38Z.


Tested in play: RTX 3090 24 GB (driver 610.88), i9-14900K, Windows 11. A release build of this PR merged onto main 923e38c, run in turn with main and four other PR builds. Series S, DLSS Performance, frame generation off. The same frozen save, outdoors on a balcony, standing still. A warm-up start per build, then two rounds, each run 40 s to settle and 60 s measured, then a screenshot. Main: 25.4 and 24.8 fps, 10 compute programs refused (no wave32 lowering). I compare round 2 only, because round 1 was slow for every new build.

  • No crash in the measured runs, no device loss and no ERROR line. The picture matches main, and the same 10 programs are refused as on main, so nothing in this scene visibly depends on this change.
  • fps in round 2: 24.7 against 24.8-25.4 for main, within this setup's noise.
  • So this is a no-harm check; the case it fixes did not show in this scene.

The first start of every new build in this session crashed while loading at +0x23cf683 (main and all five PRs alike; see #628), so that is not from this change.

Tested with an AI assistant (Claude Code); results are from this PC.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7246844936 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1542#issuecomment-7246844936). Originally posted by [nick0451](https://github.com/nick0451) on 2026-11-28T22:35:38Z. --- Tested in play: RTX 3090 24 GB (driver 610.88), i9-14900K, Windows 11. A release build of this PR merged onto main `923e38c`, run in turn with main and four other PR builds. Series S, DLSS Performance, frame generation off. The same frozen save, outdoors on a balcony, standing still. A warm-up start per build, then two rounds, each run 40 s to settle and 60 s measured, then a screenshot. Main: 25.4 and 24.8 fps, 10 compute programs refused (`no wave32 lowering`). I compare round 2 only, because round 1 was slow for every new build. - No crash in the measured runs, no device loss and no `ERROR` line. The picture matches main, and the same 10 programs are refused as on main, so nothing in this scene visibly depends on this change. - fps in round 2: 24.7 against 24.8-25.4 for main, within this setup's noise. - So this is a no-harm check; the case it fixes did not show in this scene. The first start of every new build in this session crashed while loading at `+0x23cf683` (main and all five PRs alike; see #628), so that is not from this change. Tested with an AI assistant (Claude Code); results are from this PC.
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
trustno1-coder/VIctory-NVIDIA!1542
No description provided.