startup: translate v_swap_b32 in gfx2hlsl #1796

Closed
github-bot wants to merge 2 commits from gh-pr/1796/head into gh-pr/1796/base
Owner

@⁠tedin7 on GitHub · 2026-11-24 18:49 UTC · original
tedin7:x2w-frontier-gfx-slice → main · +222 −0 · 5 files · 2 commits · closed without merging

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.

**@⁠tedin7** on GitHub · 2026-11-24 18:49 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1796) `tedin7:x2w-frontier-gfx-slice` → `main` · +222 −0 · 5 files · 2 commits · closed without merging 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:33:59 +00:00
github-bot closed this pull request 2026-11-26 23:33:59 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 19:14 UTC · original

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.

**@⁠tedin7** on GitHub · 2026-11-24 19:14 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1796#issuecomment-7141809153) 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

This discussion has been locked. Commenting is limited to contributors.
No description provided.