shader: lower v_swap_b32 in pixel_aot #765

Merged
JB2WIN merged 2 commits from upstream-pr/771 into main 2026-11-23 03:56:02 +00:00
JB2WIN commented 2026-11-23 01:59:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-23T01:59:48Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6550718671 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/771). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-23T01:59:48Z. --- ## 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)
upstream-sync closed this pull request 2026-11-24 06:44:42 +00:00
JB2WIN commented 2026-11-24 06:48:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-23T02:36:34Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7090072173 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/771#issuecomment-7090072173). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-23T02:36:34Z. --- 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).
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
R0Y00/Xbox2Windows!765
No description provided.