fix(victory-shader): bypass EXEC on v_writelane_b32 and mask lane indices #300

Open
github-bot wants to merge 3 commits from github-bot/gh-300 into main AGit
Owner

@⁠mauroalvare on GitHub · 2026-11-26 01:51 UTC · original
mauroalvare:fix/victory-writelane-readlane → main · +163 −1 · 3 files · 3 commits · open

Change

In VIctory's RDNA2-to-DXIL translator (third_party/victory/crates/victory-shader/src/emit/lower.rs), v_writelane_b32 and v_readlane_b32 diverged from AMD RDNA 2 ISA semantics in two ways:

  1. v_writelane_b32 obeyed EXEC (guard): valu_op finished v_writelane_b32 with int(self, r) (self.write_i(inst, r, guard)), wrapping the lane write in select(guard, r, old). On RDNA 2, v_writelane_b32 ignores EXEC — compilers rely on this to spill SGPRs into VGPR lanes inside guarded blocks and wave-wide branches (including every branch in the paired wave64-on-wave32 form on NVIDIA). Passing None as the guard to write_i preserves RDNA 2 semantics.
  2. Unmasked lane indices in v_writelane_b32 and v_readlane_b32: On RDNA 2, src1 is masked to the low 5 bits (wave32) or low 6 bits (wave64). Previously v_writelane_b32 masked lane & 63 only in the paired form (self.twin.is_some()), and v_readlane_b32 did not mask lane in the split wave64 exchange path (cl == lane failed whenever upper bits were set) or in the non-exchange compute path (passing an out-of-range lane index to DXIL waveReadLaneAt is undefined behavior). Both now mask lane to wave_size - 1.

Linked issue: none

Verification

Base SHA: c4c93bdc413191a9dc909998d2d53080a3f0c880 (LooperSalty/AnyXboxX:main)
Hardware: Windows 11, Ryzen 7 9700X, NVIDIA GeForce RTX 5070 Ti (driver 621.40), dxil.dll 10.0.26100.0, Rust 1.98.1 (MSVC).

Before the fix (failing on base c4c93bd on RTX 5070 Ti):

cargo test --locked -p victory-shader writelane_ignores_exec -- --test-threads=1 --nocapture
-> FAILED: thread 0, dword 1: 0x5, the console's 0xdeadbeef

After the fix (from third_party/victory):

cargo test --locked -p victory-shader writelane_ignores_exec -- --test-threads=1 --nocapture
-> ran on the hardware device: writelane ignored EXEC and readlane/writelane masked lane indices in wave32, paired wave64, and exchange wave64
-> test result: ok. 1 passed; 0 failed; 0 ignored
cargo test --locked -p victory-shader -- --test-threads=1
-> test result: ok. 243 passed; 0 failed; 2 ignored
cargo xtask policy
-> asset policy: 200 files ok

Oracle and test data

The new regression test writelane_ignores_exec_and_masks_lane_index_in_wave32_and_paired_wave64 in third_party/victory/crates/victory-shader/src/emit/wave64_tests.rs synthesizes three minimal GFX10 compute shaders (wave32 with EXEC narrowed to even lanes writing inactive lane 37 & 31 = 5; paired wave64 on 32-lane host writing inactive lane 109 & 63 = 45 inside if (v0 < 32); split wave64 exchange reading/writing lanes 104 & 63 = 40 and 69 & 63 = 5). All three are validated with dxil.dll and executed on the RTX 5070 Ti against AMD RDNA 2 ISA semantics (also matching PrototypeScarlett/emu/rdna2_exec_vop3.py).

No game, console, or SDK files were used.

Checklist

  • The PR covers a single reviewable behaviour.
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success.
  • README: unchanged (not applicable).
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none (synthetic tests only).
  • Code taken from another project: none.

AI assistance: investigated, implemented, tested on RTX 5070 Ti, and drafted with Antigravity (Gemini).

**@⁠mauroalvare** on GitHub · 2026-11-26 01:51 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/300) `mauroalvare:fix/victory-writelane-readlane` → `main` · +163 −1 · 3 files · 3 commits · open ## Change In VIctory's RDNA2-to-DXIL translator (`third_party/victory/crates/victory-shader/src/emit/lower.rs`), `v_writelane_b32` and `v_readlane_b32` diverged from AMD RDNA 2 ISA semantics in two ways: 1. **`v_writelane_b32` obeyed `EXEC` (`guard`)**: `valu_op` finished `v_writelane_b32` with `int(self, r)` (`self.write_i(inst, r, guard)`), wrapping the lane write in `select(guard, r, old)`. On RDNA 2, `v_writelane_b32` ignores `EXEC` — compilers rely on this to spill SGPRs into VGPR lanes inside guarded blocks and wave-wide branches (including every branch in the paired wave64-on-wave32 form on NVIDIA). Passing `None` as the guard to `write_i` preserves RDNA 2 semantics. 2. **Unmasked lane indices in `v_writelane_b32` and `v_readlane_b32`**: On RDNA 2, `src1` is masked to the low 5 bits (wave32) or low 6 bits (wave64). Previously `v_writelane_b32` masked `lane & 63` only in the paired form (`self.twin.is_some()`), and `v_readlane_b32` did not mask `lane` in the split wave64 `exchange` path (`cl == lane` failed whenever upper bits were set) or in the non-exchange compute path (passing an out-of-range lane index to DXIL `waveReadLaneAt` is undefined behavior). Both now mask `lane` to `wave_size - 1`. Linked issue: none ## Verification Base SHA: `c4c93bdc413191a9dc909998d2d53080a3f0c880` (`LooperSalty/AnyXboxX:main`) Hardware: Windows 11, Ryzen 7 9700X, NVIDIA GeForce RTX 5070 Ti (driver `621.40`), `dxil.dll` `10.0.26100.0`, Rust `1.98.1` (MSVC). Before the fix (failing on base `c4c93bd` on RTX 5070 Ti): ``` cargo test --locked -p victory-shader writelane_ignores_exec -- --test-threads=1 --nocapture -> FAILED: thread 0, dword 1: 0x5, the console's 0xdeadbeef ``` After the fix (from `third_party/victory`): ``` cargo test --locked -p victory-shader writelane_ignores_exec -- --test-threads=1 --nocapture -> ran on the hardware device: writelane ignored EXEC and readlane/writelane masked lane indices in wave32, paired wave64, and exchange wave64 -> test result: ok. 1 passed; 0 failed; 0 ignored cargo test --locked -p victory-shader -- --test-threads=1 -> test result: ok. 243 passed; 0 failed; 2 ignored cargo xtask policy -> asset policy: 200 files ok ``` ## Oracle and test data The new regression test `writelane_ignores_exec_and_masks_lane_index_in_wave32_and_paired_wave64` in `third_party/victory/crates/victory-shader/src/emit/wave64_tests.rs` synthesizes three minimal GFX10 compute shaders (wave32 with `EXEC` narrowed to even lanes writing inactive lane `37 & 31 = 5`; paired wave64 on 32-lane host writing inactive lane `109 & 63 = 45` inside `if (v0 < 32)`; split wave64 `exchange` reading/writing lanes `104 & 63 = 40` and `69 & 63 = 5`). All three are validated with `dxil.dll` and executed on the RTX 5070 Ti against AMD RDNA 2 ISA semantics (also matching `PrototypeScarlett/emu/rdna2_exec_vop3.py`). No game, console, or SDK files were used. ## Checklist - [x] The PR covers a single reviewable behaviour. - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. - [x] README: unchanged (not applicable). - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none (synthetic tests only). - [x] Code taken from another project: none. *AI assistance: investigated, implemented, tested on RTX 5070 Ti, and drafted with Antigravity (Gemini).*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:42:22 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/300/head:github-bot/gh-300'
git switch 'github-bot/gh-300'

Merge

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