Fix ds_bpermute_b32 lane selection on Wave32 hosts #1542
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1542"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_b32gathers 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.rswithin the asset-policy limit.Validation
cargo xtask policypassed for all 307 files.Strict workspace Clippy stops at the unused
colourvariable and the manually checked division already present on upstream77df871e.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 reportsWaveLaneCountMin/Max32-32, so no 64-lane host ran.5ed4465ba, merged onto maind4b5d5170(--no-ff, clean, no conflicts). The PR's base is77df871e, 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 still5ed4465baand main stilld4b5d5170when I finished.What changes. Apart from the test split, the code change is three hunks in
lower.rs:wave64_why_reasonsgets ads_permutearm.ds_bpermutefrom its "crosses halves" list. A wave64 program withds_bpermute_b32is now split into two Wave32 halves on a 32-lane card instead of being refused.ds_bpermute_b32lowering. The source lane is wrapped within the caller's 32-lane half. Activity comes from aWaveActiveBallotof the guard (the half's ballot word on a 64-lane host wave), and an inactive source gives 0. The earlyErr("a lane permute across two host waves")is gone.The split is a pure move. With the old inline
mod tests { ... }taken out oflower.rsand de-indented by one level, it is byte-identical to the newlower/tests.rs. It is also byte-identical to #1460'slower/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'sds_bpermute_b32lowering 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
The filter matches the PR's new test,
emit::wave64_tests::backward_permute_wraps_within_its_half_and_zeros_inactive_sources, and the existingemit::tests::a_backward_permute_reads_the_lane_its_address_names(which only lowers; it opens no device).permute GPU readback passed for 64 threads at width 32and... 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 barecontinueand prints nothing. On the 3070, only width 32 runs. Width 64 is lowered and validated, but never dispatched. WithVICTORY_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
GetDesc1of the adapter behinddevice.GetAdapterLuid(), and theD3D12_OPTIONS1wave lane counts, forHost::new(false)andHost::new(true):Host::newfalse10de:24840x0true1414:008c0x2(software)VICTORY_WARP=1false1414:008c0x2(software)The PR's test uses
Host::new(false): the 3070 in default runs, WARP withVICTORY_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 putss_cbranch_execz +2over 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.The parameter is incorrect.)GFX10 code at 0x34: a lane permute across two host waves is not supported(0x38for the branch variant)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.VICTORY_WARP=1, 3 runs: 2 passed, 1 failed, 0 ignored each.All six runs failed the same way, at
wave64_tests.rs:187: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_b32loweringI reverse-applied only the lowering hunk (hunk 3). It builds, with the same single warning.
width 32readback 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)d4b5d5170: 349 passed, 0 failed, 8 ignored (309 s).d4b5d5170: 348 passed, 0 failed, 8 ignored (312 s).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:13896on main,:13895on the merge).CI
gh pr checks 1542: only thelabelcheck (pass). I did not run clippy orcargo xtask policy. The PR has no comments or reviews yet.Overlap
lower/tests.rsis byte-identical to this PR's, andgit merge-treeof the two heads is clean. Whichever lands second carries an empty split.git merge-treeof #1542 against the 23 other open PRs that changelower.rsorwave64_tests.rs. 15 are clean, among them #845, #1504 and #1460. #1450 (Wave32 lowering for known compute kernels,lds.rsandmod.rsonly) is clean too.mod testsinlower.rs: they add tests there, and #1542 moves that module intolower/tests.rs. The conflict is mechanical (move their new tests into the new file). #1460 would cause the same conflict.lower.rs, at the same places with main and with #1542. #822 rewrites the split check and still listsds_bpermuteas crossing halves, so a rebase onto #1542 would have to drop it there too.ds_swizzleinactive lanes, which we reported on) does not touchds_bpermute_b32. The two merge cleanly. #1504 listsds_permute/ds_bpermuteas not covered by its paired form, and merges cleanly too.Not tested
ds_bpermute_b32in a title shader (the checkerboard shadow masks named in the old comment), the game and any title capture.s_cbranch_execzin the temporary test's second variant became a real DXIL branch.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.
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.ERRORline. The picture matches main, and the same 10 programs are refused as on main, so nothing in this scene visibly depends on this change.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.