fix: zero masked sources of DS swizzles in VIctory #284

Open
Tiimonprog wants to merge 4 commits from upstream-pr/284 into main
Tiimonprog commented 2026-11-26 00:44:18 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Tiimonprog on 2026-11-26T00:44:18Z.


Change

VIctory’s DS swizzle lowering passes a masked source value to the cross-lane read. Select zero for an EXEC-masked source before the read, as the existing bpermute lowering already does.

The new synthetic wave64 regression activates only even lanes. A quad reversal reads inactive odd lanes, while a swap-16 reads active even lanes. Inactive destinations retain their sentinel. Before the fix, RTX 4060 Laptop returned 4 at thread 0, dword 1 instead of 0. After the fix, all 256 output dwords match the expected values.

Verification

Run from third_party/victory, Rust 1.98.1 MSVC, Windows 11, NVIDIA RTX 4060 Laptop (driver 32.0.16.2124):

cargo test --locked -p victory-shader guarded_swizzles -- --nocapture
→ 1 passed; 0 failed (GPU dispatch executed)
cargo test --locked -p victory-shader -- --test-threads=1
→ 243 passed; 0 failed; 2 ignored
cargo build --locked --profile diag -p victory --features diagnostics
→ Finished diag profile (two existing victory-gpu warnings)

Intel UHD and WARP were also probed using a temporary local adapter-selection change, excluded from this PR. Both refused this 32-lane program at pipeline creation, so the regression did not execute there. The test uses the existing helper that returns early on unsupported hardware. The full test run above used the unchanged host helper.

Oracle and test data

The test encodes its own small RDNA program and checks 64 lanes × 4 dwords against explicit expected values, including zero from inactive sources, live source values and preserved inactive destinations. No game inputs were used. In-game graphics and performance effects have not been measured.

Created with OpenAI Codex assistance.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:6616870000 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/284). Originally posted by [Tiimonprog](https://github.com/Tiimonprog) on 2026-11-26T00:44:18Z. --- ## Change VIctory’s DS swizzle lowering passes a masked source value to the cross-lane read. Select zero for an EXEC-masked source before the read, as the existing bpermute lowering already does. The new synthetic wave64 regression activates only even lanes. A quad reversal reads inactive odd lanes, while a swap-16 reads active even lanes. Inactive destinations retain their sentinel. Before the fix, RTX 4060 Laptop returned 4 at thread 0, dword 1 instead of 0. After the fix, all 256 output dwords match the expected values. ## Verification Run from `third_party/victory`, Rust 1.98.1 MSVC, Windows 11, NVIDIA RTX 4060 Laptop (driver 32.0.16.2124): ``` cargo test --locked -p victory-shader guarded_swizzles -- --nocapture → 1 passed; 0 failed (GPU dispatch executed) cargo test --locked -p victory-shader -- --test-threads=1 → 243 passed; 0 failed; 2 ignored cargo build --locked --profile diag -p victory --features diagnostics → Finished diag profile (two existing victory-gpu warnings) ``` Intel UHD and WARP were also probed using a temporary local adapter-selection change, excluded from this PR. Both refused this 32-lane program at pipeline creation, so the regression did not execute there. The test uses the existing helper that returns early on unsupported hardware. The full test run above used the unchanged host helper. ## Oracle and test data The test encodes its own small RDNA program and checks 64 lanes × 4 dwords against explicit expected values, including zero from inactive sources, live source values and preserved inactive destinations. No game inputs were used. In-game graphics and performance effects have not been measured. Created with OpenAI Codex assistance.
Tiimonprog commented 2026-11-26 00:48:50 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Tiimonprog on 2026-11-26T00:48:50Z.


Added c8b9fff, an opt-in deterministic GPU sweep with 256 generated wave64 programs. Each performs an in-place QUAD_PERM, changes EXEC, then performs a BITMASK_PERM. The set covers all 256 quad selectors and varying sparse, empty and full masks. It compares 32,768 output dwords against an independent CPU calculation.

Run from third_party/victory:

cargo test --locked -p victory-shader generated_swizzle_sweep -- --ignored --nocapture

Measured on RTX 4060 Laptop, driver 32.0.16.2124: 256 cases passed (5.83 s in one run). nvidia-smi also confirmed the test process on the NVIDIA adapter. To replay one case, set SWIZZLE_CASE=0 (valid range 0–255). The sweep requires a GPU accepting these 32-lane shaders and fails explicitly if device or pipeline creation fails. It is opt-in because ordinary CI may lack that hardware.

With the lowering restored to the pre-fix version, case 0 fails at lane 8: [9, 31], expected [9, 0]. With the fix, all cases pass, including replay of case 0. No additional mismatch was found in this set. The earlier full-suite result in the description predates this added opt-in test.

AI assistance: OpenAI Codex.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7179138865 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/284#issuecomment-7179138865). Originally posted by [Tiimonprog](https://github.com/Tiimonprog) on 2026-11-26T00:48:50Z. --- Added `c8b9fff`, an opt-in deterministic GPU sweep with 256 generated wave64 programs. Each performs an in-place QUAD_PERM, changes EXEC, then performs a BITMASK_PERM. The set covers all 256 quad selectors and varying sparse, empty and full masks. It compares 32,768 output dwords against an independent CPU calculation. Run from `third_party/victory`: ``` cargo test --locked -p victory-shader generated_swizzle_sweep -- --ignored --nocapture ``` Measured on RTX 4060 Laptop, driver 32.0.16.2124: 256 cases passed (5.83 s in one run). `nvidia-smi` also confirmed the test process on the NVIDIA adapter. To replay one case, set `SWIZZLE_CASE=0` (valid range 0–255). The sweep requires a GPU accepting these 32-lane shaders and fails explicitly if device or pipeline creation fails. It is opt-in because ordinary CI may lack that hardware. With the lowering restored to the pre-fix version, case 0 fails at lane 8: `[9, 31]`, expected `[9, 0]`. With the fix, all cases pass, including replay of case 0. No additional mismatch was found in this set. The earlier full-suite result in the description predates this added opt-in test. AI assistance: OpenAI Codex.
Tiimonprog commented 2026-11-26 01:03:09 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Tiimonprog on 2026-11-26T01:03:09Z.


Added two commits, 13f1bf9 and 8dcc8d6, extending validation of this fix.

The divergent-loop sweep covers 260 dispatch cases across four partner mappings (XOR 1, 16, 32 and 63), including empty/full entry masks and per-lane exits after 1–8 rounds. It checks values, iteration counts, reads inside the loop and reads after reconvergence against a CPU calculation. WAVE64_LOOP_CASE=131 replays one case (valid range 0–259).

Both generated sweeps now pass synthetic DXBC/XDAT/XBCH/FSSM containers through the public translate() entry point, including native parsing, spill handling and automatic translation-form selection for a 32-lane host. The loop sweep also dispatches the explicit paired form if its result differs. A new GPU-independent round-trip test checks the code, stage settings and root bindings of the synthetic container.

Measured on Windows, RTX 4060 Laptop, driver 32.0.16.2124, Rust 1.98.1 MSVC:

cargo test --locked -p victory-shader generated_ -- --ignored --test-threads=1
2 passed; 516 selected-path dispatch cases; 99,328 output dwords matched the CPU oracle

cargo test --locked -p victory-shader -- --test-threads=1
244 passed; 0 failed; 4 ignored

cargo xtask policy
asset policy: 201 files ok

Negative controls were local and restored afterward. Removing the paired bpermute source guard makes loop case 131 fail (lane 0 reads 34 instead of 33). Restoring the swizzle lowering to its pre-fix version makes public-path swizzle case 0 fail at lane 8 ([9, 31] instead of [9, 0]). Both generated sweeps pass with the original bpermute guard and this PR’s swizzle fix restored. No additional mismatch was found in these cases. In-game effects remain unmeasured.

Created with OpenAI Codex assistance.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7179381952 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/284#issuecomment-7179381952). Originally posted by [Tiimonprog](https://github.com/Tiimonprog) on 2026-11-26T01:03:09Z. --- Added two commits, 13f1bf9 and 8dcc8d6, extending validation of this fix. The divergent-loop sweep covers 260 dispatch cases across four partner mappings (XOR 1, 16, 32 and 63), including empty/full entry masks and per-lane exits after 1–8 rounds. It checks values, iteration counts, reads inside the loop and reads after reconvergence against a CPU calculation. WAVE64_LOOP_CASE=131 replays one case (valid range 0–259). Both generated sweeps now pass synthetic DXBC/XDAT/XBCH/FSSM containers through the public translate() entry point, including native parsing, spill handling and automatic translation-form selection for a 32-lane host. The loop sweep also dispatches the explicit paired form if its result differs. A new GPU-independent round-trip test checks the code, stage settings and root bindings of the synthetic container. Measured on Windows, RTX 4060 Laptop, driver 32.0.16.2124, Rust 1.98.1 MSVC: ```text cargo test --locked -p victory-shader generated_ -- --ignored --test-threads=1 2 passed; 516 selected-path dispatch cases; 99,328 output dwords matched the CPU oracle cargo test --locked -p victory-shader -- --test-threads=1 244 passed; 0 failed; 4 ignored cargo xtask policy asset policy: 201 files ok ``` Negative controls were local and restored afterward. Removing the paired bpermute source guard makes loop case 131 fail (lane 0 reads 34 instead of 33). Restoring the swizzle lowering to its pre-fix version makes public-path swizzle case 0 fail at lane 8 ([9, 31] instead of [9, 0]). Both generated sweeps pass with the original bpermute guard and this PR’s swizzle fix restored. No additional mismatch was found in these cases. In-game effects remain unmeasured. Created with OpenAI Codex assistance.
LooperSalty commented 2026-11-27 16:24:22 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-27T16:24:22Z.


The fix is still needed on the current base: in third_party/victory/crates/victory-shader/src/emit/lower.rs (main), the ds_swizzle_b32 branch reads x = self.vgprs(inst, addr…) without zeroing EXEC-masked source lanes, while the ds_bpermute path selects 0 for them. But third_party/victory is now the Vice-Tay base (#454), and the branch conflicts in wave64_tests.rs (two adjacent additions). Please rebase on main, keep both sides' tests, check that the generated loop/swizzle tests and the pub(crate) mod tests / wave64_uav_container helper in native.rs still compile against the new base, and post the result of cargo test -p victory-shader (GPU or WARP).

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7223222978 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/284#issuecomment-7223222978). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-27T16:24:22Z. --- The fix is still needed on the current base: in `third_party/victory/crates/victory-shader/src/emit/lower.rs` (main), the `ds_swizzle_b32` branch reads `x = self.vgprs(inst, addr…)` without zeroing EXEC-masked source lanes, while the `ds_bpermute` path selects 0 for them. But `third_party/victory` is now the Vice-Tay base (#454), and the branch conflicts in `wave64_tests.rs` (two adjacent additions). Please rebase on main, keep both sides' tests, check that the generated loop/swizzle tests and the `pub(crate) mod tests` / `wave64_uav_container` helper in `native.rs` still compile against the new base, and post the result of `cargo test -p victory-shader` (GPU or WARP).
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/284:upstream-pr/284'
git switch 'upstream-pr/284'

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/284'
git switch 'upstream-pr/284'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/284'
git switch 'upstream-pr/284'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/284'
git switch 'main'
git merge --squash 'upstream-pr/284'
git switch 'main'
git merge --ff-only 'upstream-pr/284'
git switch 'main'
git merge 'upstream-pr/284'
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
LooperSalty/AnyXboxX!284
No description provided.