shader: lower v_swap_b32 in pixel_aot #771

Manually merged
github merged 2 commits from gh-pr/771/head into gh-pr/771/base 2026-11-26 22:17:08 +00:00
Owner

@⁠JB2WIN on GitHub · 2026-11-23 01:59 UTC · original
JB2WIN:shader/v-swap → main · +203 −3 · 7 files · 2 commits · merged 2026-11-23 03:56 UTC

Change

tools/pixel_aot.py now lowers VOP1 v_swap_b32 vD, vS, with an optional _e32 suffix. The two VGPRs exchange their old values. Every vector entry names an immutable precise float temporary, so the lowering swaps the two tracked entries and emits no HLSL. A self swap is a no-op.

  • Operands: both must be VGPRs in v0..v255 and both must hold tracked numeric values. LLVM 15.0.7 itself rejects an SGPR operand ("invalid operand"). v_swap_b32 v1, v2 encodes as [0x02,0xcb,0x02,0x7e].
  • Refused:
    • _e64, DPP, SDWA, modifiers, SGPR operands and v256;
    • untracked or non-numeric registers;
    • pending loads;
    • a register with an outstanding sample.
  • Scanner: a pattern for v_swap_b32(?:_e32)? vD, vS was added, and the opcode is now in the known VOP1 set.

AI-assisted (Claude Code).

Verification

Environment: Windows 11 10.0.26200.9974, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP 10.0.26100.9818. The D3D12 debug layer was enabled. Head is rebased on f714d2f.

  • New draw draw-swap (pixel_aot_swap_{hardware,warp}). The program moves s44..s47 into v18..v21 and then runs three swaps:

    • two independent swaps;
    • a chained swap;
    • a self swap.

    Each export is read back at full width and compared against an independent Python reference. The words are normal binary32 bit patterns, because the values pass through float VGPRs.

  • Mutants: each must report a mismatch, and each does:

    • a one-way copy;
    • two sequential copies without a snapshot;
    • a reordered chain;
    • the self swap replaced by a copy.

    Python assertions before the draw check that every mutant changes the expected words.

  • Dev-time check (not committed): with the new branch removed, the controls fail.

  • Results:

    • ctest --preset dev --no-tests=error -R "^pixel_aot_swap_": 2/2 passed (4.5 s on hardware, 1.7 s on WARP).
    • Full ctest --preset dev --no-tests=error -j4: 334 of 336 passed. Neither failure involves this change:
      • pixel_aot_predicate_rounding_hardware timed out at 60 s. That mode is at or past its limit on this adapter on main (see my note on #448).
      • bvh_differential_warp failed once under parallel load and passed when rerun on its own (0.25 s).
    • The skips are bvh_wave64_hardware, bvh_wave64_warp and wave_shuffle_warp.
    • tests/pixel_aot_check.py binary with LLVM 15.0.7, using a local clang -cc1as shim for llvm-mc, exits 0.
    • The controls, form_coverage_check.py, rdna2_tools_check.py, pso_readiness_check.py and docs_links_check.py all pass.

🤖 Generated with Claude Code

**@⁠JB2WIN** on GitHub · 2026-11-23 01:59 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/771) `JB2WIN:shader/v-swap` → `main` · +203 −3 · 7 files · 2 commits · merged 2026-11-23 03:56 UTC ## Change `tools/pixel_aot.py` now lowers VOP1 `v_swap_b32 vD, vS`, with an optional `_e32` suffix. The two VGPRs exchange their old values. Every vector entry names an immutable `precise float` temporary, so the lowering swaps the two tracked entries and emits no HLSL. A self swap is a no-op. - **Operands:** both must be VGPRs in v0..v255 and both must hold tracked numeric values. LLVM 15.0.7 itself rejects an SGPR operand ("invalid operand"). `v_swap_b32 v1, v2` encodes as `[0x02,0xcb,0x02,0x7e]`. - **Refused:** - `_e64`, DPP, SDWA, modifiers, SGPR operands and `v256`; - untracked or non-numeric registers; - pending loads; - a register with an outstanding sample. - **Scanner:** a pattern for `v_swap_b32(?:_e32)? vD, vS` was added, and the opcode is now in the known VOP1 set. AI-assisted (Claude Code). ## Verification Environment: Windows 11 10.0.26200.9974, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP 10.0.26100.9818. The D3D12 debug layer was enabled. Head is rebased on `f714d2f`. - **New draw `draw-swap`** (`pixel_aot_swap_{hardware,warp}`). The program moves s44..s47 into v18..v21 and then runs three swaps: - two independent swaps; - a chained swap; - a self swap. Each export is read back at full width and compared against an independent Python reference. The words are normal binary32 bit patterns, because the values pass through float VGPRs. - **Mutants:** each must report a mismatch, and each does: - a one-way copy; - two sequential copies without a snapshot; - a reordered chain; - the self swap replaced by a copy. Python assertions before the draw check that every mutant changes the expected words. - **Dev-time check (not committed):** with the new branch removed, the controls fail. - **Results:** - `ctest --preset dev --no-tests=error -R "^pixel_aot_swap_"`: 2/2 passed (4.5 s on hardware, 1.7 s on WARP). - Full `ctest --preset dev --no-tests=error -j4`: 334 of 336 passed. Neither failure involves this change: - `pixel_aot_predicate_rounding_hardware` timed out at 60 s. That mode is at or past its limit on this adapter on `main` (see my note on #448). - `bvh_differential_warp` failed once under parallel load and passed when rerun on its own (0.25 s). - The skips are `bvh_wave64_hardware`, `bvh_wave64_warp` and `wave_shuffle_warp`. - `tests/pixel_aot_check.py binary` with LLVM 15.0.7, using a local `clang -cc1as` shim for `llvm-mc`, exits 0. - The controls, `form_coverage_check.py`, `rdna2_tools_check.py`, `pso_readiness_check.py` and `docs_links_check.py` all pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Exchange the two tracked VGPR entries (e32, VGPR operands only, as LLVM 15
accepts). No HLSL is emitted because every entry names an immutable
temporary. Adds scanner support, controls, an LLVM 15 binary fixture,
form coverage and an integer-export draw with four mutants
(pixel_aot_swap_*).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:17:05 +00:00
github manually merged commit e724a3230d into gh-pr/771/base 2026-11-26 22:17:07 +00:00
Author
Owner

@⁠JB2WIN on GitHub · 2026-11-23 02:36 UTC · original

Semantics source: LLVM 15.0.7 VOP1Instructions.td gives V_SWAP_B32 two VGPR outputs ($vdst, $vdst1) and two VGPR inputs, tied with "$vdst = $src1, $vdst1 = $src0". So each register receives the other's old value. The operand classes are VGPR_32 only, and there is no VOP3 form (Asm64 = "", Ins64 = (ins)). That matches the refused SGPR, _e64, DPP and SDWA spellings here. On gfx10 it is encoded as VOP1Only opcode 0x065 (L815).

**@⁠JB2WIN** on GitHub · 2026-11-23 02:36 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/771#issuecomment-7090072173) Semantics source: LLVM 15.0.7 [`VOP1Instructions.td`](https://github.com/llvm/llvm-project/blob/llvmorg-15.0.7/llvm/lib/Target/AMDGPU/VOP1Instructions.td#L473-L487) gives `V_SWAP_B32` two VGPR outputs (`$vdst`, `$vdst1`) and two VGPR inputs, tied with `"$vdst = $src1, $vdst1 = $src0"`. So each register receives the other's old value. The operand classes are `VGPR_32` only, and there is no VOP3 form (`Asm64 = ""`, `Ins64 = (ins)`). That matches the refused SGPR, `_e64`, DPP and SDWA spellings here. On gfx10 it is encoded as `VOP1Only` opcode 0x065 (L815).
This discussion has been locked. Commenting is limited to contributors.
No description provided.