shader: lower DPP16 quad swaps in gfx2hlsl (Part of #2125) #2141

Manually merged
github merged 2 commits from gh-pr/2141/head into gh-pr/2141/base 2026-11-26 23:59:45 +00:00
Owner

@⁠tedin7 on GitHub · 2026-11-25 01:29 UTC · original
tedin7:x2w-2125b-dpp-quad-swap → main · +430 −3 · 4 files · 2 commits · merged 2026-11-25 02:30 UTC

Part of #2125

What this unblocks: pixel shaders that swap values inside a 2x2 pixel quad (quad_perm:[1,0,3,2], [2,3,0,1], [3,2,1,0], about 8,971 instructions) now translate instead of being refused.

Changes:

  • tools/startup/gfx2hlsl.py: lower the three swaps in v_mov_b32_dpp and the VOP2 integer and binary32 forms to QuadReadAcrossX, QuadReadAcrossY and QuadReadAcrossDiagonal. Only src0 is exchanged. Broadcasts, pair perms, partial masks, row_mirror, DPP8, fi:1, modifiers, SGPR sources, vertex stages, unknown EXEC and branches are still refused (broadcast and pair belong to the other items on #2125).
  • A pair that uses a swap is compiled with DXC as vs_6_0/ps_6_0, because the intrinsics need SM 6.0. X2W_DXC or dxc on PATH is used. Pairs without a swap still use fxc 5.1.
  • tests/startup_gfx2hlsl_dpp_quad_swap_check.py, registered in CMakeLists.txt (controls plus WARP/hardware draw). It draws 16x16 and reads pixels back against a CPU quad reference, with mutations (X to Y, Y to diagonal, diagonal to X, no exchange, dropped swap) that must fail.
  • docs/experiments.md: new paragraph.

Verification:

  • Linux: python3 tests/startup_gfx2hlsl_dpp_quad_swap_check.py PASS (translation, refusals, no-dxc refusal).
  • Linux: python3 tests/startup_gfx2hlsl_swap_check.py and python3 tests/startup_translator_check.py PASS.
  • NOT run locally: the binary llvm-mc check and the WARP draw (no dxc, offscreen_check or Windows here). Needs the Win2025 gate: ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_dpp_quad_swap_' -V.

Draft until the Win2025 WARP run passes and a peer reviews it.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 01:29 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2141) `tedin7:x2w-2125b-dpp-quad-swap` → `main` · +430 −3 · 4 files · 2 commits · merged 2026-11-25 02:30 UTC Part of #2125 What this unblocks: pixel shaders that swap values inside a 2x2 pixel quad (`quad_perm:[1,0,3,2]`, `[2,3,0,1]`, `[3,2,1,0]`, about 8,971 instructions) now translate instead of being refused. Changes: - `tools/startup/gfx2hlsl.py`: lower the three swaps in `v_mov_b32_dpp` and the VOP2 integer and binary32 forms to `QuadReadAcrossX`, `QuadReadAcrossY` and `QuadReadAcrossDiagonal`. Only src0 is exchanged. Broadcasts, pair perms, partial masks, row_mirror, DPP8, fi:1, modifiers, SGPR sources, vertex stages, unknown EXEC and branches are still refused (broadcast and pair belong to the other items on #2125). - A pair that uses a swap is compiled with DXC as vs_6_0/ps_6_0, because the intrinsics need SM 6.0. `X2W_DXC` or `dxc` on PATH is used. Pairs without a swap still use fxc 5.1. - `tests/startup_gfx2hlsl_dpp_quad_swap_check.py`, registered in `CMakeLists.txt` (controls plus WARP/hardware draw). It draws 16x16 and reads pixels back against a CPU quad reference, with mutations (X to Y, Y to diagonal, diagonal to X, no exchange, dropped swap) that must fail. - `docs/experiments.md`: new paragraph. Verification: - Linux: `python3 tests/startup_gfx2hlsl_dpp_quad_swap_check.py` PASS (translation, refusals, no-dxc refusal). - Linux: `python3 tests/startup_gfx2hlsl_swap_check.py` and `python3 tests/startup_translator_check.py` PASS. - NOT run locally: the `binary` llvm-mc check and the WARP draw (no dxc, offscreen_check or Windows here). Needs the Win2025 gate: `ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_dpp_quad_swap_' -V`. Draft until the Win2025 WARP run passes and a peer reviews it. AI-assisted; commands listed were executed locally.
quad_perm [1,0,3,2], [2,3,0,1] and [3,2,1,0] with full masks in v_mov_b32 and the VOP2 integer and binary32 forms. A pair that uses one is compiled with DXC as SM 6.0. Adds a 16x16 pixel readback against a quad reference with mutation controls.
Part of #2125. A quad swap now needs an earlier s_wqm of exec into itself; without it the
swap is refused, since the hardware masks inactive source lanes of a partly covered quad and
QuadReadAcross does not. A restored older EXEC copy drops the proof. The fixture flag is the
inline 2.0 so the llvm-mc round trip matches.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:59:44 +00:00
github manually merged commit a351c0fb57 into gh-pr/2141/base 2026-11-26 23:59:45 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 01:36 UTC · original · edited 2026-11-25 01:43 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T01:43:21.624579Z b888984 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 01:36 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2141#issuecomment-7149737773) · edited 2026-11-25 01:43 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"b88898493c0b1962352b02eee76789f5f95632f9","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-25T01:43:21.624579Z">2026-11-25T01:43:21.624579Z</relative-time> | `b888984` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
@ -747,0 +786,4 @@
raise Unsupported('%s_dpp needs VGPR operands without modifiers' % base)
if (getattr(self, 'kind', None) != 'ps' or getattr(self, 'has_branches', True) or getattr(self, 'blocks', True)
or not getattr(self, 'exec_known', False)):
raise Unsupported('%s_dpp requires a straight-line pixel shader with entry EXEC' % base)
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 01:43 UTC · original

P1 Badge Require whole-quad EXEC before lowering a quad swap

For a pixel shader that executes DPP before entering whole-quad mode, a partially covered primitive can have inactive neighbours even though exec_known is true: that flag only records that EXEC still equals its entry mask. The accepted DPP forms mask inactive source lanes, whereas QuadReadAcross* reads helper lanes, so translated pixels at triangle edges can receive a neighbour's value instead of the hardware's zero/preserved result. Require a proven whole-quad EXEC state, or model/refuse inactive-source cases. The fullscreen 16×16 fixture does not exercise partial-quad coverage.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 01:43 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2141#discussion_r4689077929) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Require whole-quad EXEC before lowering a quad swap** For a pixel shader that executes DPP before entering whole-quad mode, a partially covered primitive can have inactive neighbours even though `exec_known` is true: that flag only records that EXEC still equals its entry mask. The accepted DPP forms mask inactive source lanes, whereas `QuadReadAcross*` reads helper lanes, so translated pixels at triangle edges can receive a neighbour's value instead of the hardware's zero/preserved result. Require a proven whole-quad EXEC state, or model/refuse inactive-source cases. The fullscreen 16×16 fixture does not exercise partial-quad coverage. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 01:43 UTC · original

P2 Badge Match the assembler's inline encoding for the fixture flag

Running the new binary mode with LLVM 20 fails both fixtures. llvm-mc --show-encoding (documented as “Show instruction encodings”) encodes v_mov_b32_e32 v9, 0x40000000 as the four-byte inline 2.0 form (0x7e1202f4), while this helper records the eight-byte literal form (0x7e1202ff, 0x40000000). Because check_binary() compares the complete byte streams, the advertised round-trip fails even though the DPP encodings match. Use a flag without an inline encoding, or generate the canonical inline move.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 01:43 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2141#discussion_r4689077946) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Match the assembler's inline encoding for the fixture flag** Running the new `binary` mode with LLVM 20 fails both fixtures. `llvm-mc --show-encoding` (documented as “Show instruction encodings”) encodes `v_mov_b32_e32 v9, 0x40000000` as the four-byte inline `2.0` form (`0x7e1202f4`), while this helper records the eight-byte literal form (`0x7e1202ff, 0x40000000`). Because `check_binary()` compares the complete byte streams, the advertised round-trip fails even though the DPP encodings match. Use a flag without an inline encoding, or generate the canonical inline move. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -747,0 +786,4 @@
raise Unsupported('%s_dpp needs VGPR operands without modifiers' % base)
if (getattr(self, 'kind', None) != 'ps' or getattr(self, 'has_branches', True) or getattr(self, 'blocks', True)
or not getattr(self, 'exec_known', False)):
raise Unsupported('%s_dpp requires a straight-line pixel shader with entry EXEC' % base)
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 02:30 UTC · original

Fixed in a351c0fb.

  • The quad swap is now refused unless an earlier s_wqm_b64 exec, exec proved whole-quad EXEC. A later write to EXEC, or a restored older EXEC copy, drops the proof. New controls: fixtures without s_wqm are refused, and a copy/wqm/restore sequence is refused.
  • Verification: Linux tests/startup_gfx2hlsl_dpp_quad_swap_check.py PASS, ... binary llvm-mc PASS, 53 related Python checks PASS (tools/run_checks_parallel.py). Win2025: x2w_pipe.py win2025 2141, ctest -R '^startup_gfx2hlsl_dpp_quad_swap_' 3/3 passed on dev and on release (controls, warp, hardware).

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 02:30 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2141#discussion_r4689552403) Fixed in a351c0fb. - The quad swap is now refused unless an earlier `s_wqm_b64 exec, exec` proved whole-quad EXEC. A later write to EXEC, or a restored older EXEC copy, drops the proof. New controls: fixtures without `s_wqm` are refused, and a copy/wqm/restore sequence is refused. - Verification: Linux `tests/startup_gfx2hlsl_dpp_quad_swap_check.py` PASS, `... binary llvm-mc` PASS, 53 related Python checks PASS (`tools/run_checks_parallel.py`). Win2025: `x2w_pipe.py win2025 2141`, `ctest -R '^startup_gfx2hlsl_dpp_quad_swap_'` 3/3 passed on dev and on release (controls, warp, hardware). AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 02:30 UTC · original

Fixed in a351c0fb.

  • The fixture flag is now v_mov_b32 v9, 2.0, the inline constant 244 (0x7e1202f4), so the words match the assembler. The fixtures also start with s_wqm_b64 exec, exec.
  • Verification: tests/startup_gfx2hlsl_dpp_quad_swap_check.py binary <llvm-mc> PASS for both fixtures (LLVM 19 locally); Win2025 dev and release 3/3 passed.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 02:30 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2141#discussion_r4689552620) Fixed in a351c0fb. - The fixture flag is now `v_mov_b32 v9, 2.0`, the inline constant 244 (`0x7e1202f4`), so the words match the assembler. The fixtures also start with `s_wqm_b64 exec, exec`. - Verification: `tests/startup_gfx2hlsl_dpp_quad_swap_check.py binary <llvm-mc>` PASS for both fixtures (LLVM 19 locally); Win2025 dev and release 3/3 passed. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 01:43 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b88898493c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 01:43 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2141#pullrequestreview-6050321776) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `b88898493c` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
This discussion has been locked. Commenting is limited to contributors.
No description provided.