Shaders: return zero for inactive compute swizzle sources #1416

Open
github-bot wants to merge 1 commit from github-bot/gh-1416 into main AGit
Owner

@⁠EatCodeSleep2 on GitHub · 2026-11-24 17:54 UTC · original
EatCodeSleep2:fix/swizzle-inactive-compute-lanes-1242 → main · +91 −2 · 2 files · 1 commits · open

Addresses the compute part of VIC-BT-018 in #1242. For ds_swizzle_b32, ballot the instruction guard over the executing host wave and test the selected source bit. When the source is absent from the workgroup tail or masked by EXEC, read from a valid host lane and return zero. The pixel, vertex and mesh paths need separate validation.

The synthetic wave32 test reads back both bitmask and quad swizzles with active and masked sources. A one-thread group covers a source absent from the hardware wave. On main that case returned 0xdeadbeef instead of zero. The regression passes on the hardware adapter. WARP skips wave32 because it does not support the requested size. The shader suite passed 120 tests with the existing v_med3_f32 host NaN failure excluded. Shader Clippy with warnings as errors passes.

AI use: Codex wrote and tested the change.

**@⁠EatCodeSleep2** on GitHub · 2026-11-24 17:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/1416) `EatCodeSleep2:fix/swizzle-inactive-compute-lanes-1242` → `main` · +91 −2 · 2 files · 1 commits · open Addresses the compute part of VIC-BT-018 in #1242. For ds_swizzle_b32, ballot the instruction guard over the executing host wave and test the selected source bit. When the source is absent from the workgroup tail or masked by EXEC, read from a valid host lane and return zero. The pixel, vertex and mesh paths need separate validation. The synthetic wave32 test reads back both bitmask and quad swizzles with active and masked sources. A one-thread group covers a source absent from the hardware wave. On main that case returned 0xdeadbeef instead of zero. The regression passes on the hardware adapter. WARP skips wave32 because it does not support the requested size. The shader suite passed 120 tests with the existing v_med3_f32 host NaN failure excluded. Shader Clippy with warnings as errors passes. AI use: Codex wrote and tested the change.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:30:55 +00:00
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 17:59 UTC · original

Independent verification of \54dea15\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200) / Rust 1.98.1 MSVC:

  • Merge check vs \main\ (\ fe310e): clean
  • \cargo test -p victory-shader --lib valu_tests\ (real RX 9060 XT GPU execution): 14 passed, 0 failed (including \ds_swizzle_reads_only_active_compute_lanes\ across bitmask and quad modes, narrowed EXEC, and 1/2-thread groups)
  • \cargo clippy -p victory-shader --all-targets -- -D warnings\ (default and --all-features): clean
  • \cargo xtask policy: 154 files ok

Code audit looks clean: ballot of the EXEC guard + \lane_bit_at\ + clamping the DXIL
ead_lane\ source index to \lane\ before selecting \␀\ keeps inactive/out-of-group source lanes well-defined in DXIL.

AI-assisted; synthetic tests only, no game files.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 17:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/1416#issuecomment-7140003820) Independent verification of \54dea15\ on **Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200\) / Rust 1.98.1 MSVC**: - Merge check vs \main\ (\ fe310e\): clean - \cargo test -p victory-shader --lib valu_tests\ (real RX 9060 XT GPU execution): **14 passed, 0 failed** (including \ds_swizzle_reads_only_active_compute_lanes\ across bitmask and quad modes, narrowed EXEC, and 1/2-thread groups) - \cargo clippy -p victory-shader --all-targets -- -D warnings\ (default and \--all-features\): clean - \cargo xtask policy\: 154 files ok Code audit looks clean: ballot of the EXEC guard + \lane_bit_at\ + clamping the DXIL \ ead_lane\ source index to \lane\ before selecting \␀\ keeps inactive/out-of-group source lanes well-defined in DXIL. *AI-assisted; synthetic tests only, no game files.*
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 18:10 UTC · original

Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at 54dea15. cargo test -p victory-shader --lib -- --test-threads=1 gives 121 passed, 0 failed, 1 ignored. ds_swizzle_reads_only_active_compute_lanes needs wave32, so this is the case it was written for: NVIDIA's only wave size is 32 (WaveLaneCountMin = Max = 32), and the test ran on the hardware adapter. WARP skips it here too, as your description says.

**@⁠marquezinii** on GitHub · 2026-11-24 18:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/1416#issuecomment-7140271729) Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at `54dea15`. `cargo test -p victory-shader --lib -- --test-threads=1` gives 121 passed, 0 failed, 1 ignored. `ds_swizzle_reads_only_active_compute_lanes` needs wave32, so this is the case it was written for: NVIDIA's only wave size is 32 (`WaveLaneCountMin` = `Max` = 32), and the test ran on the hardware adapter. WARP skips it here too, as your description says.
Author
Owner

@⁠acetonahard-code on GitHub · 2026-11-24 19:22 UTC · original

Tested this on a GPU with SM 6.6 support (RTX 4070 SUPER, driver 621.14, Windows 11, repo toolchain), merged into current main (ffe310e).

cargo test -p victory-shader passed failed ignored
main 120 0 1
main + this PR 121 0 1
main, --all-features 120 0 1
main + this PR, --all-features 121 0 1
  • The new test passes.
  • Run with --nocapture, and no "no SM 6.6 ... device; skipped" lines were printed, so no GPU test skipped for lack of a device.
  • cargo clippy --all-targets -- -D warnings, with and without --all-features: clean.
  • Minor: cargo fmt --check would rewrap one block this PR adds (lower.rs). main isn't rustfmt-clean either, so take it or leave it.

I didn't test with game data.


Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.

**@⁠acetonahard-code** on GitHub · 2026-11-24 19:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/1416#issuecomment-7142000696) Tested this on a GPU with SM 6.6 support (RTX 4070 SUPER, driver 621.14, Windows 11, repo toolchain), merged into current `main` (ffe310e). | `cargo test -p victory-shader` | passed | failed | ignored | |---|---|---|---| | `main` | 120 | 0 | 1 | | `main` + this PR | 121 | 0 | 1 | | `main`, `--all-features` | 120 | 0 | 1 | | `main` + this PR, `--all-features` | 121 | 0 | 1 | - The new test passes. - Run with `--nocapture`, and no "no SM 6.6 ... device; skipped" lines were printed, so no GPU test skipped for lack of a device. - `cargo clippy --all-targets -- -D warnings`, with and without `--all-features`: clean. - Minor: `cargo fmt --check` would rewrap one block this PR adds (`lower.rs`). `main` isn't rustfmt-clean either, so take it or leave it. I didn't test with game data. --- <sub>Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.</sub>
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-24 20:44 UTC · original

Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head 54dea15 onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 21,724 with this PR.

No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 121, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-24 20:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/1416#issuecomment-7143984779) ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head 54dea15 onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on `main`, 21,724 with this PR. No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 121, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:26 UTC · original

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/1416#issuecomment-7149550812) <!-- victory-triage v1 head=54dea150f6f4485643a39855e89e949ff1e7f8c4 verdict=needs-rebase at=2026-11-25T01:26:34Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-shader/src/emit/valu_tests.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-25 09:18 UTC · original

Compared 54dea150 with its parent ffe310eb using the same five Wave32 compute swizzles on Windows 11 build 26300.10075. On an RTX 5080 (driver 621.40) this change fixes all three inactive-source cases. On Microsoft WARP 1.0.22 it fixes the two masked-source cases, but both active-neighbor swaps start returning zero.

Source Offset Threads Expected RTX parent → PR WARP 1.0.22 parent → PR
Absent neighbor 0x041f 1 0 0xdeadbeef → 0 0 → 0
Masked neighbor 0x041f 2 0 0xdeadbeef → 0 0xdeadbeef → 0
Masked neighbor 0x80b1 2 0 0xdeadbeef → 0 0xdeadbeef → 0
Active neighbor, bitmask swap 0x041f 2 0xdeadbeef 0xdeadbeef → 0xdeadbeef 0xdeadbeef → 0
Active neighbor, quad swap 0x80b1 2 0xdeadbeef 0xdeadbeef → 0xdeadbeef 0xdeadbeef → 0

The RTX went from 2/5 to 5/5. Standalone WARP scored 3/5 on both commits, with different failing cases. Built-in WARP 10.0.26100.10068 skipped all five because it could not run the requested Wave32 mode.

To reproduce the first failure, run ds_swizzle_reads_only_active_compute_lanes on the PR head with the x64 WARP 1.0.22 DLL beside the test executable and WARP selected. The original assertion stops on the fourth case. For the table I recorded all five readbacks before asserting, then replayed the same fixture against the parent compiler. I verified the loaded WARP DLL path and its hash against the Microsoft package.

**@⁠steven-seagull27** on GitHub · 2026-11-25 09:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/1416#issuecomment-7158145410) Compared `54dea150` with its parent `ffe310eb` using the same five Wave32 compute swizzles on Windows 11 build 26300.10075. On an RTX 5080 (driver 621.40) this change fixes all three inactive-source cases. On Microsoft WARP 1.0.22 it fixes the two masked-source cases, but both active-neighbor swaps start returning zero. | Source | Offset | Threads | Expected | RTX parent → PR | WARP 1.0.22 parent → PR | | --- | --- | ---: | --- | --- | --- | | Absent neighbor | `0x041f` | 1 | `0` | `0xdeadbeef` → `0` | `0` → `0` | | Masked neighbor | `0x041f` | 2 | `0` | `0xdeadbeef` → `0` | `0xdeadbeef` → `0` | | Masked neighbor | `0x80b1` | 2 | `0` | `0xdeadbeef` → `0` | `0xdeadbeef` → `0` | | Active neighbor, bitmask swap | `0x041f` | 2 | `0xdeadbeef` | `0xdeadbeef` → `0xdeadbeef` | `0xdeadbeef` → `0` | | Active neighbor, quad swap | `0x80b1` | 2 | `0xdeadbeef` | `0xdeadbeef` → `0xdeadbeef` | `0xdeadbeef` → `0` | The RTX went from 2/5 to 5/5. Standalone WARP scored 3/5 on both commits, with different failing cases. Built-in WARP 10.0.26100.10068 skipped all five because it could not run the requested Wave32 mode. To reproduce the first failure, run `ds_swizzle_reads_only_active_compute_lanes` on the PR head with the x64 WARP 1.0.22 DLL beside the test executable and WARP selected. The original assertion stops on the fourth case. For the table I recorded all five readbacks before asserting, then replayed the same fixture against the parent compiler. I verified the loaded WARP DLL path and its hash against the Microsoft package.
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 02:07 UTC · original

@⁠EatCodeSleep2 I resolved the conflict on your 54dea150 branch against main 63bcca43. Merged #1582 already covers the compute source ballot. Git would retain both ballots if I resolved only the conflict it reports in valu_tests.rs. The branch I tested keeps main's shared lowering and your regression coverage. It tags each lane's value and adds two full-wave controls, so an active neighbor can be distinguished from reading the caller's own lane. Fast-forwardable test branch

Backend Wave32 swizzle results
RTX 5080, Windows, driver 621.40 7/7 correct
Built-in WARP, wave width 4 All seven skipped before dispatch
App-local WARP 1.0.22 5/7 correct. Both active-neighbor swaps in two-thread groups returned 0 instead of lane 1's 0xdeadbef0. Both swaps succeeded in 32-thread groups.

An independent DXC shader isolates the failure to the ballot of a partially occupied wave. Two active lanes directly read each other's distinct values correctly on both adapters. The RTX returns ballot 0x3; WARP 1.0.21, 1.0.22 and 1.65535.22-preview all return 0 for both lanes. A 32-thread Wave32 control returned 0xffffffff on RTX and WARP 1.0.22. This also distinguishes the failure from the full-wave dynamic lane permutation in #2949. Expected active-lane ballot semantics

[WaveSize(32)]
[numthreads(2, 1, 1)]
void main(uint id : SV_GroupIndex) {
    uint lane = WaveGetLaneIndex();
    uint mask = WaveActiveBallot(true).x;
    uint neighbor = WaveReadLaneAt(0xface0000u | id, lane ^ 1u);
    RWByteAddressBuffer outBuf = ResourceDescriptorHeap[2];
    outBuf.Store4(id * 32, uint4(lane, mask, neighbor, WaveGetLaneCount()));
}

I compiled this with dxc -T cs_6_6 -E main -O3 and dispatched one group with a raw UAV at heap index 2. Lane 0 returned (0, 3, 0xface0001, 32) on RTX and (0, 0, 0xface0001, 32) on all three WARP packages. I also checked a bitwise-OR substitute. It fixes the two-thread control but gives 0xffff for 17 active lanes where the RTX gives 0x1ffff, so it would be unsafe to generalize this workaround across group sizes.

The branch passes strict shader Clippy. The no-device control fails explicitly. To pick up the test changes on the original PR branch:

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr1416-swizzle-nov26
git merge --ff-only FETCH_HEAD
cargo test -p victory-shader --lib --locked ds_swizzle_reads_only_active_compute_lanes -- --nocapture
**@⁠steven-seagull27** on GitHub · 2026-11-26 02:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/1416#issuecomment-7180489798) @⁠EatCodeSleep2 I resolved the conflict on your `54dea150` branch against main `63bcca43`. Merged #1582 already covers the compute source ballot. Git would retain *both* ballots if I resolved only the conflict it reports in `valu_tests.rs`. The branch I tested keeps main's shared lowering and your regression coverage. It tags each lane's value and adds two full-wave controls, so an active neighbor can be distinguished from reading the caller's own lane. [Fast-forwardable test branch](https://github.com/steven-seagull27/VIctory/commit/26932f2e2f9703151fcda6fa22e14bec718b9e15) | Backend | Wave32 swizzle results | |---|---| | RTX 5080, Windows, driver 621.40 | 7/7 correct | | Built-in WARP, wave width 4 | All seven skipped before dispatch | | App-local WARP 1.0.22 | 5/7 correct. Both active-neighbor swaps in two-thread groups returned `0` instead of lane 1's `0xdeadbef0`. Both swaps succeeded in 32-thread groups. | An independent DXC shader isolates the failure to **the ballot of a partially occupied wave**. Two active lanes directly read each other's distinct values correctly on both adapters. The RTX returns ballot `0x3`; WARP 1.0.21, 1.0.22 and 1.65535.22-preview all return `0` for both lanes. A 32-thread Wave32 control returned `0xffffffff` on RTX and WARP 1.0.22. This also distinguishes the failure from the full-wave dynamic lane permutation in #2949. [Expected active-lane ballot semantics](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/waveballot) ```hlsl [WaveSize(32)] [numthreads(2, 1, 1)] void main(uint id : SV_GroupIndex) { uint lane = WaveGetLaneIndex(); uint mask = WaveActiveBallot(true).x; uint neighbor = WaveReadLaneAt(0xface0000u | id, lane ^ 1u); RWByteAddressBuffer outBuf = ResourceDescriptorHeap[2]; outBuf.Store4(id * 32, uint4(lane, mask, neighbor, WaveGetLaneCount())); } ``` I compiled this with `dxc -T cs_6_6 -E main -O3` and dispatched one group with a raw UAV at heap index 2. Lane 0 returned `(0, 3, 0xface0001, 32)` on RTX and `(0, 0, 0xface0001, 32)` on all three WARP packages. I also checked a bitwise-OR substitute. It fixes the two-thread control but gives `0xffff` for 17 active lanes where the RTX gives `0x1ffff`, so it would be unsafe to generalize this workaround across group sizes. The branch passes strict shader Clippy. The no-device control fails explicitly. To pick up the test changes on the original PR branch: ```sh git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr1416-swizzle-nov26 git merge --ff-only FETCH_HEAD cargo test -p victory-shader --lib --locked ds_swizzle_reads_only_active_compute_lanes -- --nocapture ```
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/valu_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/1416/head:github-bot/gh-1416'
git switch 'github-bot/gh-1416'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1416'
git switch 'github-bot/gh-1416'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1416'
git switch 'github-bot/gh-1416'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1416'
git switch 'main'
git merge --squash 'github-bot/gh-1416'
git switch 'main'
git merge --ff-only 'github-bot/gh-1416'
git switch 'main'
git merge 'github-bot/gh-1416'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1416
No description provided.