Shaders: return zero for inactive compute swizzle sources #1415

Open
EatCodeSleep2 wants to merge 1 commit from upstream-pr/1416 into main
EatCodeSleep2 commented 2026-11-24 17:54:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by EatCodeSleep2 on 2026-11-24T17:54:08Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6588060065 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1416). Originally posted by [EatCodeSleep2](https://github.com/EatCodeSleep2) on 2026-11-24T17:54:08Z. --- 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.
geiyiliyabumo commented 2026-11-24 18:06:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T17:59:43Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140003820 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1416#issuecomment-7140003820). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T17:59:43Z. --- 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.*
marquezinii commented 2026-11-24 19:04:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T18:10:46Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140271729 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1416#issuecomment-7140271729). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T18:10:46Z. --- 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.
catminou4 commented 2026-11-24 20:02:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T19:24:58Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96. GPU/valu execution tests are Windows-gated and were not run here.

Console ds_swizzle in compute now ballots the EXEC guard over the host lanes present and reads zero for lanes that are absent or masked off (previously an inactive source lane could leak a neighbor's value). lane_bit_at is factored out of the existing path; the DXIL read stays defined by selecting the lane index for inactive sources. Five valu cases cover bitmask/quad modes × narrowed EXEC × 1/2 threads (Windows-only); macOS 96 green.

Note: adds the same build_valu_cs_with_threads/run_cases_with_wave_size harness as #1412 in valu_tests.rs — identical hunks, so these two PRs will conflict textually; whichever lands second rebases.

<!-- greyfinch-sync:Marvisak/VIctory:review:6045875628 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1416#pullrequestreview-6045875628). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T19:24:58Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), `cargo test -p victory-shader --locked` → 96. GPU/valu execution tests are Windows-gated and were not run here. Console `ds_swizzle` in compute now ballots the EXEC guard over the host lanes present and reads zero for lanes that are absent or masked off (previously an inactive source lane could leak a neighbor's value). `lane_bit_at` is factored out of the existing path; the DXIL read stays defined by selecting the lane index for inactive sources. Five valu cases cover bitmask/quad modes × narrowed EXEC × 1/2 threads (Windows-only); macOS 96 green. Note: adds the same `build_valu_cs_with_threads`/`run_cases_with_wave_size` harness as #1412 in `valu_tests.rs` — identical hunks, so these two PRs will conflict textually; whichever lands second rebases.
acetonahard-code commented 2026-11-24 20:03:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by acetonahard-code on 2026-11-24T19:22:22Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142000696 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1416#issuecomment-7142000696). Originally posted by [acetonahard-code](https://github.com/acetonahard-code) on 2026-11-24T19:22:22Z. --- 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>
sinan-cmyk commented 2026-11-24 21:03:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T20:44:04Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143984779 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1416#issuecomment-7143984779). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T20:44:04Z. --- ### 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).
Marvisak commented 2026-11-25 02:06:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:26:35Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149550812 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1416#issuecomment-7149550812). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:26:35Z. --- <!-- 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)_
steven-seagull27 commented 2026-11-25 10:07:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-25T09:18:05Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158145410 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1416#issuecomment-7158145410). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-25T09:18:05Z. --- 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 commented 2026-11-26 03:05:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T02:07:51Z.


@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
<!-- greyfinch-sync:Marvisak/VIctory:comment:7180489798 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1416#issuecomment-7180489798). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-26T02:07:51Z. --- @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 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/1416:upstream-pr/1416'
git switch 'upstream-pr/1416'

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 'main'
git merge --no-ff 'upstream-pr/1416'
git switch 'upstream-pr/1416'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1416'
git switch 'upstream-pr/1416'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1416'
git switch 'main'
git merge --squash 'upstream-pr/1416'
git switch 'main'
git merge --ff-only 'upstream-pr/1416'
git switch 'main'
git merge 'upstream-pr/1416'
git push origin 'main'
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
Marvisak/VIctory!1415
No description provided.