Shaders: return zero for inactive compute swizzle sources (port of upstream VIctory #1416) #1030

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

@⁠Moon0755 on GitHub · 2026-11-25 16:45 UTC · original
Moon0755:fix/ds-swizzle-inactive-lanes → main · +86 −0 · 2 files · 1 commits · open

Ports upstream Marvisak/VIctory#1416 (EatCodeSleep2), scoped to native compute waves (self.s.mesh.is_none() && self.exchange.is_none()) so mesh shaders and split wave64-exchange compute paths are unaffected.

Problem

On RDNA2 / Xbox Series X, ds_swizzle_b32 returns 0 when the selected source lane is masked off by EXEC or absent from the workgroup tail. Previously, Lower::ds lowered ds_swizzle_b32 directly to self.read_lane(x, src) (WaveReadLaneAt), which returns undefined / stale data (such as 0xdeadbeef) when the source lane is inactive or out of bounds.

What changed

  • crates/victory-shader/src/emit/lower.rs:
    • Factor Lower::lane_bit_at out of Lower::lane_bit.
    • In ds_swizzle_b32 for native compute waves (self.s.threads.is_some() && self.s.mesh.is_none() && self.exchange.is_none()), ballot the instruction guard via dx.op.waveActiveBallot, test the selected src lane bit with lane_bit_at, redirect inactive reads to the current lane so WaveReadLaneAt stays well-defined, and select 0 when the source lane is inactive.
  • crates/victory-shader/src/emit/valu_tests.rs (ds_swizzle_reads_only_active_compute_lanes):
    • Add a synthetic test covering 5 bitmask-mode (0x041f) and quad-mode (0x80b1) swizzles across 1-thread (absent source lane) and 2-thread (v_cmpx-masked and active) workgroups. All 5 shaders are lowered and validated via dxil.dll; execution runs on SM 6.6 hardware adapters and skips cleanly on WARP where fixed WaveSize(32) is unsupported (E_INVALIDARG).

Verification

Verified on Windows (windows-latest + dxil.dll) via a temporary scoped CI branch on the fork:

  • CI run: https://github.com/Moon0755/victory-fork/actions/runs/45656613462
  • cargo clippy -p victory-shader -p xtask --all-targets --locked -- -D warnings: passed
  • cargo clippy -p victory-shader -p xtask --all-targets --all-features --locked -- -D warnings: passed
  • cargo test -p victory-shader -p xtask --locked -- --nocapture: victory-shader 216 passed; 0 failed; 3 ignored (test emit::valu_tests::ds_swizzle_reads_only_active_compute_lanes ... ok, all 5 shaders validated via dxil.dll; WARP skipped WaveSize(32) compute pipeline creation as expected); xtask 4 passed; 0 failed (including repository_passes_policy).

Note: CI checks were scoped to -p victory-shader -p xtask because upstream/main (fxceless/victory-fork) currently has unrelated pre-existing Clippy errors in crates/victory-gpu.

— Neon

**@⁠Moon0755** on GitHub · 2026-11-25 16:45 UTC · [original](https://github.com/fxceless/victory-fork/pull/1030) `Moon0755:fix/ds-swizzle-inactive-lanes` → `main` · +86 −0 · 2 files · 1 commits · open Ports upstream [Marvisak/VIctory#1416](https://github.com/Marvisak/VIctory/pull/1416) (`EatCodeSleep2`), scoped to native compute waves (`self.s.mesh.is_none() && self.exchange.is_none()`) so mesh shaders and split wave64-exchange compute paths are unaffected. ## Problem On RDNA2 / Xbox Series X, `ds_swizzle_b32` returns `0` when the selected source lane is masked off by `EXEC` or absent from the workgroup tail. Previously, `Lower::ds` lowered `ds_swizzle_b32` directly to `self.read_lane(x, src)` (`WaveReadLaneAt`), which returns undefined / stale data (such as `0xdeadbeef`) when the source lane is inactive or out of bounds. ## What changed - **`crates/victory-shader/src/emit/lower.rs`**: - Factor `Lower::lane_bit_at` out of `Lower::lane_bit`. - In `ds_swizzle_b32` for native compute waves (`self.s.threads.is_some() && self.s.mesh.is_none() && self.exchange.is_none()`), ballot the instruction `guard` via `dx.op.waveActiveBallot`, test the selected `src` lane bit with `lane_bit_at`, redirect inactive reads to the current lane so `WaveReadLaneAt` stays well-defined, and select `0` when the source lane is inactive. - **`crates/victory-shader/src/emit/valu_tests.rs` (`ds_swizzle_reads_only_active_compute_lanes`)**: - Add a synthetic test covering 5 bitmask-mode (`0x041f`) and quad-mode (`0x80b1`) swizzles across 1-thread (absent source lane) and 2-thread (`v_cmpx`-masked and active) workgroups. All 5 shaders are lowered and validated via `dxil.dll`; execution runs on SM 6.6 hardware adapters and skips cleanly on WARP where fixed `WaveSize(32)` is unsupported (`E_INVALIDARG`). ## Verification Verified on Windows (`windows-latest` + `dxil.dll`) via a temporary scoped CI branch on the fork: - CI run: https://github.com/Moon0755/victory-fork/actions/runs/45656613462 - `cargo clippy -p victory-shader -p xtask --all-targets --locked -- -D warnings`: passed - `cargo clippy -p victory-shader -p xtask --all-targets --all-features --locked -- -D warnings`: passed - `cargo test -p victory-shader -p xtask --locked -- --nocapture`: `victory-shader` `216 passed; 0 failed; 3 ignored` (`test emit::valu_tests::ds_swizzle_reads_only_active_compute_lanes ... ok`, all 5 shaders validated via `dxil.dll`; WARP skipped `WaveSize(32)` compute pipeline creation as expected); `xtask` `4 passed; 0 failed` (including `repository_passes_policy`). Note: CI checks were scoped to `-p victory-shader -p xtask` because `upstream/main` (`fxceless/victory-fork`) currently has unrelated pre-existing Clippy errors in `crates/victory-gpu`. — Neon
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:56:18 +00:00
Author
Owner

@⁠HAL9000RELOADED on GitHub · 2026-11-25 18:00 UTC · original

A hardware run of the new tests of nine upstream ports by the same author: this one and #948, #951, #957, #1019, #1026, #1036, #1040, #1042. Until now they had run only on WARP in CI. As far as the descriptions show, this PR's test had not run anywhere yet, because WARP skips it (fixed WaveSize(32)). The table is kept here, and each of the other eight links to it.

Setup

  • Machine: Radeon RX 7900 XTX (RDNA3, waves of 32 to 64 lanes), Adrenalin 32.0.32015.7029, Windows 10 Pro 22H2 (19045), Rust 1.98.1.
  • Agility SDK: #402's runtime (Agility SDK 1.620), since Windows 10's in-box D3D12 stops at SM 6.5.
  • Tools: DXIL validator and PC dxc from SDK 10.0.26100.
  • Tree: each PR merged onto main 0b0074e + #402 + the stack-headroom test fix from Marvisak/VIctory#742; then cargo test -p victory-shader --lib, and each new test with --nocapture.
  • How the card was confirmed: WARP stays below SM 6.6 here and skips, so every case ran on the hardware device. No test printed "no SM 6.6 hardware device".
  • No game data used.
PR new tests on the RX 7900 XTX run before on
#948 vop3_unsigned_add_sub_clamp pass WARP (CI)
#951 signed_scalar_add_sub_scc_matches_rdna2 pass WARP (CI)
#957 image_resinfo_returns_zero_depth_for_a_2d_view pass WARP (CI); DXIL check
#1019 typed_float_loads_preserve_nan_bits pass WARP (CI); DXIL check
#1026 legacy_mad_fuses_its_product_and_flushes_its_sources pass WARP (CI)
#1030 ds_swizzle_reads_only_active_compute_lanes pass none: skipped on WARP (fixed WaveSize(32))
#1036 cmp16_ignores_op_sel_as_rdna2_does, cmp16_sdwa_preserves_word_selects pass WARP (CI); DXIL check
#1040 v_div_fixup_f16_follows_the_isa_special_cases pass WARP (CI)
#1042 v_pk_int16_clamp_saturates_as_rdna2 pass WARP (CI); DXIL check

Regressions: none. victory-shader gives 215 passed on the base and 216 passed (217 for #1036, which adds two tests) with each PR, 0 failed.

**@⁠HAL9000RELOADED** on GitHub · 2026-11-25 18:00 UTC · [original](https://github.com/fxceless/victory-fork/pull/1030#issuecomment-7170315986) A hardware run of the new tests of nine upstream ports by the same author: this one and #948, #951, #957, #1019, #1026, #1036, #1040, #1042. Until now they had run only on WARP in CI. As far as the descriptions show, this PR's test had not run anywhere yet, because WARP skips it (fixed `WaveSize(32)`). The table is kept here, and each of the other eight links to it. **Setup** - **Machine:** Radeon RX 7900 XTX (RDNA3, waves of 32 to 64 lanes), Adrenalin 32.0.32015.7029, Windows 10 Pro 22H2 (19045), Rust 1.98.1. - **Agility SDK:** #402's runtime (Agility SDK 1.620), since Windows 10's in-box D3D12 stops at SM 6.5. - **Tools:** DXIL validator and PC dxc from SDK 10.0.26100. - **Tree:** each PR merged onto `main` `0b0074e` + #402 + the stack-headroom test fix from Marvisak/VIctory#742; then `cargo test -p victory-shader --lib`, and each new test with `--nocapture`. - **How the card was confirmed:** WARP stays below SM 6.6 here and skips, so every case ran on the hardware device. No test printed "no SM 6.6 hardware device". - No game data used. | PR | new tests | on the RX 7900 XTX | run before on | |---|---|---|---| | #948 | `vop3_unsigned_add_sub_clamp` | pass | WARP (CI) | | #951 | `signed_scalar_add_sub_scc_matches_rdna2` | pass | WARP (CI) | | #957 | `image_resinfo_returns_zero_depth_for_a_2d_view` | pass | WARP (CI); DXIL check | | #1019 | `typed_float_loads_preserve_nan_bits` | pass | WARP (CI); DXIL check | | #1026 | `legacy_mad_fuses_its_product_and_flushes_its_sources` | pass | WARP (CI) | | #1030 | `ds_swizzle_reads_only_active_compute_lanes` | pass | **none**: skipped on WARP (fixed `WaveSize(32)`) | | #1036 | `cmp16_ignores_op_sel_as_rdna2_does`, `cmp16_sdwa_preserves_word_selects` | pass | WARP (CI); DXIL check | | #1040 | `v_div_fixup_f16_follows_the_isa_special_cases` | pass | WARP (CI) | | #1042 | `v_pk_int16_clamp_saturates_as_rdna2` | pass | WARP (CI); DXIL check | **Regressions:** none. victory-shader gives 215 passed on the base and 216 passed (217 for #1036, which adds two tests) with each PR, 0 failed.
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/1030/head:github-bot/gh-1030'
git switch 'github-bot/gh-1030'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1030'
git switch 'github-bot/gh-1030'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1030'
git switch 'github-bot/gh-1030'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1030'
git switch 'main'
git merge --squash 'github-bot/gh-1030'
git switch 'main'
git merge --ff-only 'github-bot/gh-1030'
git switch 'main'
git merge 'github-bot/gh-1030'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.