startup: translate v_swap_b32 in gfx2hlsl #1789

Closed
tedin7 wants to merge 2 commits from upstream-pr/1796 into main
tedin7 commented 2026-11-24 18:49:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T18:49:32Z.


The translator refused the VOP1 v_swap_b32 vdst, vsrc with Unsupported: v_swap_b32. In the offline shader-archive census of #1723, 2 of the 1,171 pixel and vertex program pairs stop on it (one of the root-independent single-pair rows).

What changes

  • op_v_swap_b32 in tools/startup/gfx2hlsl.py emits { uint swap_tmp = vA; vA = vB; vB = swap_tmp; }, guarded by if (exec & 1) when the exec mask is not known, nothing when both registers are the same, and it drops the proven-uniform status of both registers.
  • The instruction has no output or source modifier and no VOP3 form (LLVM 19 rejects v_swap_b32_e64 on gfx1010 and gfx1030), so a scalar or constant source, a modifier or a wrong operand count is refused; the SDWA spelling stays refused by the decoder.
  • Docs: a section in docs/experiments.md. Test registration in CMakeLists.txt and the Linux Python list of windows.yml.

Evidence

  • New tests/startup_gfx2hlsl_swap_check.py (synthetic only, no title data). It builds the VOP1 word from the public field layout (AMD RDNA 2 ISA, opcode 101) and checks it against the bytes LLVM 19 assembles for v_swap_b32 v1, v2 (02 cb 02 7e). It covers the emitted exchange, the exec guard, the same-register case, a later read of the swapped register, the uniform status, five refusals, a modifier and the SDWA spelling.
  • Linux, executed locally: the new check and startup_gfx2hlsl_{cndmask_neg,sdwa,operand_count,capture,smem_offset}, startup_translator, startup_flat_param, startup_inline_sampler and startup_sampler_heap checks pass; git diff --check origin/main...HEAD, docs_links_check and bidi_controls_check pass.
  • Mutations that make the new check fail (each restored afterwards): write the source twice instead of exchanging, drop the exec guard, keep the uniform status, accept a scalar source.

Limits

  • Not run on Windows: the emitted text is compared, not compiled with DXC or drawn.
  • The two census pairs may stop on a later instruction after this change.
  • Overlap: git merge-tree against every open PR shows no conflict that is not already present between that PR and main. No open PR touches v_swap_b32 in gfx2hlsl.py (#1785 and #1669 only mention it in pixel_aot).

Part of #870; related to #1723.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6589023934 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1796). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T18:49:32Z. --- The translator refused the VOP1 `v_swap_b32 vdst, vsrc` with `Unsupported: v_swap_b32`. In the offline shader-archive census of #1723, 2 of the 1,171 pixel and vertex program pairs stop on it (one of the root-independent single-pair rows). ## What changes - `op_v_swap_b32` in tools/startup/gfx2hlsl.py emits `{ uint swap_tmp = vA; vA = vB; vB = swap_tmp; }`, guarded by `if (exec & 1)` when the exec mask is not known, nothing when both registers are the same, and it drops the proven-uniform status of both registers. - The instruction has no output or source modifier and no VOP3 form (LLVM 19 rejects `v_swap_b32_e64` on gfx1010 and gfx1030), so a scalar or constant source, a modifier or a wrong operand count is refused; the SDWA spelling stays refused by the decoder. - Docs: a section in docs/experiments.md. Test registration in CMakeLists.txt and the Linux Python list of windows.yml. ## Evidence - New tests/startup_gfx2hlsl_swap_check.py (synthetic only, no title data). It builds the VOP1 word from the public field layout (AMD RDNA 2 ISA, opcode 101) and checks it against the bytes LLVM 19 assembles for `v_swap_b32 v1, v2` (`02 cb 02 7e`). It covers the emitted exchange, the exec guard, the same-register case, a later read of the swapped register, the uniform status, five refusals, a modifier and the SDWA spelling. - Linux, executed locally: the new check and startup_gfx2hlsl_{cndmask_neg,sdwa,operand_count,capture,smem_offset}, startup_translator, startup_flat_param, startup_inline_sampler and startup_sampler_heap checks pass; `git diff --check origin/main...HEAD`, docs_links_check and bidi_controls_check pass. - Mutations that make the new check fail (each restored afterwards): write the source twice instead of exchanging, drop the exec guard, keep the uniform status, accept a scalar source. ## Limits - Not run on Windows: the emitted text is compared, not compiled with DXC or drawn. - The two census pairs may stop on a later instruction after this change. - Overlap: `git merge-tree` against every open PR shows no conflict that is not already present between that PR and main. No open PR touches `v_swap_b32` in gfx2hlsl.py (#1785 and #1669 only mention it in pixel_aot). Part of #870; related to #1723. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-24 20:00:38 +00:00
tedin7 commented 2026-11-24 20:01:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:14:31Z.


Closing this draft for now to help keep the open PR queue manageable; the branch stays preserved on the fork so it can be reopened once the queue clears.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7141809153 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1796#issuecomment-7141809153). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T19:14:31Z. --- Closing this draft for now to help keep the open PR queue manageable; the branch stays preserved on the fork so it can be reopened once the queue clears.

Pull request closed

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!1789
No description provided.