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

Merged
tedin7 merged 2 commits from upstream-pr/2141 into main 2026-11-25 02:30:31 +00:00
tedin7 commented 2026-11-25 01:29:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:29:55Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6595030812 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2141). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:29:55Z. --- 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.
chatgpt-codex-connector[bot commented 2026-11-25 02:01:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T01:43:19Z.

Review: COMMENTED


💡 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".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050321776 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2141#pullrequestreview-6050321776). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T01:43:19Z. **Review:** COMMENTED --- <!-- 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>
chatgpt-codex-connector[bot commented 2026-11-25 02:02:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T01:36:10Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7149737773 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2141#issuecomment-7149737773). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T01:36:10Z. --- <!-- 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>
chatgpt-codex-connector[bot commented 2026-11-25 02:02:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T01:43:19Z.

Code review location: tools/startup/gfx2hlsl.py; line 785

@@ -744,6 +752,45 @@ def lower(self, base, asm, ops, mods):
             raise Unsupported('%s requires descriptor FORMAT and DST_SEL' % base)
         raise Unsupported(base)
 
+    # VOP1/VOP2 with a DPP16 quad_perm source (AMD RDNA 2 ISA, "Data-Parallel Primitives"): lane i of
+    # each aligned group of four reads src0 from lane quad_perm[i] of that group. The three exchanges
+    # map onto the SM 6.0 quad intrinsics, which read the other lane of the 2x2 pixel quad and keep
+    # helper lanes active. Only a pixel stage at entry EXEC qualifies: the hardware returns 0 or the old
+    # value for a source lane whose EXEC bit is off, and the intrinsics have no such case. Broadcast
+    # and pair permutations, DPP8, row shifts, partial masks and source modifiers stay refused.
+    def dpp(self, base, ops, mods):
+        perm = None
+        for m in mods:
+            match = re.fullmatch(r'quad_perm:\[([0-3]),([0-3]),([0-3]),([0-3])\]', m)
+            if match and perm is None:
+                perm = tuple(int(x) for x in match.groups())
+            elif m not in ('row_mask:0xf', 'bank_mask:0xf', 'bound_ctrl:0', 'bound_ctrl:1'):
+                raise Unsupported('%s_dpp with %s' % (base, m))
+        intrinsic = QUAD_SWAPS.get(perm)
+        if not intrinsic:
+            raise Unsupported('%s_dpp quad_perm %s: only the swaps [1,0,3,2], [2,3,0,1] and [3,2,1,0] are lowered'
+                              % (base, perm))
+        if base == 'v_mov_b32':
+            arity, text, kind = 1, '{0}', 'u'
+        elif base in VEC_U:
+            (arity, text), kind = VEC_U[base], 'u'
+        elif base in VEC_F and base not in ('v_fmac_f32', 'v_mac_f32'):
+            (arity, text), kind = VEC_F[base], 'f'
+        else:
+            raise Unsupported('%s_dpp' % base)
+        if len(ops) != arity + 1 or any(not re.fullmatch(r'v\d+', o) for o in ops):
+            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)

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 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4689077929 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2141#discussion_r4689077929). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T01:43:19Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 785 ~~~~diff @@ -744,6 +752,45 @@ def lower(self, base, asm, ops, mods): raise Unsupported('%s requires descriptor FORMAT and DST_SEL' % base) raise Unsupported(base) + # VOP1/VOP2 with a DPP16 quad_perm source (AMD RDNA 2 ISA, "Data-Parallel Primitives"): lane i of + # each aligned group of four reads src0 from lane quad_perm[i] of that group. The three exchanges + # map onto the SM 6.0 quad intrinsics, which read the other lane of the 2x2 pixel quad and keep + # helper lanes active. Only a pixel stage at entry EXEC qualifies: the hardware returns 0 or the old + # value for a source lane whose EXEC bit is off, and the intrinsics have no such case. Broadcast + # and pair permutations, DPP8, row shifts, partial masks and source modifiers stay refused. + def dpp(self, base, ops, mods): + perm = None + for m in mods: + match = re.fullmatch(r'quad_perm:\[([0-3]),([0-3]),([0-3]),([0-3])\]', m) + if match and perm is None: + perm = tuple(int(x) for x in match.groups()) + elif m not in ('row_mask:0xf', 'bank_mask:0xf', 'bound_ctrl:0', 'bound_ctrl:1'): + raise Unsupported('%s_dpp with %s' % (base, m)) + intrinsic = QUAD_SWAPS.get(perm) + if not intrinsic: + raise Unsupported('%s_dpp quad_perm %s: only the swaps [1,0,3,2], [2,3,0,1] and [3,2,1,0] are lowered' + % (base, perm)) + if base == 'v_mov_b32': + arity, text, kind = 1, '{0}', 'u' + elif base in VEC_U: + (arity, text), kind = VEC_U[base], 'u' + elif base in VEC_F and base not in ('v_fmac_f32', 'v_mac_f32'): + (arity, text), kind = VEC_F[base], 'f' + else: + raise Unsupported('%s_dpp' % base) + if len(ops) != arity + 1 or any(not re.fullmatch(r'v\d+', o) for o in ops): + 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) ~~~~ --- **<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 -->
chatgpt-codex-connector[bot commented 2026-11-25 02:02:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T01:43:19Z.

Code review location: tests/startup_gfx2hlsl_dpp_quad_swap_check.py; line 75

@@ -0,0 +1,317 @@
+"""DPP16 quad swaps in the pixel stage of tools/startup/gfx2hlsl.py (#2125, item B).
+
+  (no arguments)                       translation controls, pure Python
+  binary <llvm-mc>                     reassemble the fixture sources and compare them with the words built here
+  draw <dxc> <offscreen_check> <warp|hardware> [fxc]
+                                       compile the translated pair with DXC vs_6_0/ps_6_0, draw 16 x 16 pixels
+                                       and compare every pixel with the quad reference below
+
+In a DPP16 `quad_perm:[a,b,c,d]` source, lane i of each aligned group of four reads lane perm[i] of that group
+(AMD RDNA 2 ISA reference, "Data-Parallel Primitives"; LLVM 15 AMDGPU `quad_perm`). The three exchanges
+[1,0,3,2], [2,3,0,1] and [3,2,1,0] flip lane bit 0, bit 1 and both, which for the 2x2 pixel quad (lane = 2 * y + x)
+is the pixel at x ^ 1, y ^ 1 or both. The lowering is QuadReadAcrossX, QuadReadAcrossY and QuadReadAcrossDiagonal
+(SM 6.0), which read helper lanes too, so a quad that is only partly covered still gets a value for every lane.
+Only a pixel stage at entry EXEC is lowered; FXC (ps_5_1) has no quad intrinsic, so a pair that needs one is
+compiled with DXC as vs_6_0/ps_6_0 and refused when no DXC is found.
+
+The fixtures read the packed screen position (x | y << 16) in v0 and OR 0x40000000 into every exported word so
+the words are normal binary32 values. The reference is written here from the lane rule with integers: the exchanged
+source is the position of the pixel at x ^ 1 and/or y ^ 1. Mutations of the translated text (an exchange that
+reads the wrong neighbour, and no exchange) must read a different image.
+"""
+import os
+import re
+import struct
+import subprocess
+import sys
+import tempfile
+from pathlib import Path
+
+HERE = Path(__file__).resolve().parent
+sys.path.insert(0, str(HERE.parent / 'tools'))
+sys.path.insert(0, str(HERE.parent / 'tools' / 'startup'))
+sys.path.insert(0, str(HERE))
+import disasm_rdna2 as D  # noqa: E402
+import gfx2hlsl as G  # noqa: E402
+from startup_flat_param_check import assemble  # noqa: E402
+from startup_image_3d_check import FULLSCREEN_VS, VS_WORDS, compile_hlsl, root_blob  # noqa: E402
+
+WIDTH = HEIGHT = 16
+MASK = 0xffffffff
+FLAG = 0x40000000
+PACKED = (0x8000, 0x8000)  # SPI_PS_INPUT_ENA/ADDR: the packed screen position only, in v0
+V_OR = 0x1c
+SWAPS = {(1, 0, 3, 2): ('X', 1, 0), (2, 3, 0, 1): ('Y', 0, 1), (3, 2, 1, 0): ('Diagonal', 1, 1)}
+failures = []
+
+
+def check(label, ok, detail=''):
+    print('%s: %s' % (label, 'ok' if ok else 'MISMATCH'))
+    if not ok:
+        failures.append(label)
+        if detail:
+            print('  ' + detail)
+
+
+def ctrl(perm):
+    return perm[0] | perm[1] << 2 | perm[2] << 4 | perm[3] << 6
+
+
+def dpp_text(mnemonic, ops, perm, extra=' row_mask:0xf bank_mask:0xf'):
+    return '%s %s quad_perm:[%s]%s' % (mnemonic, ops, ','.join(map(str, perm)), extra)
+
+
+def vop1_dpp(op, vdst, src, perm, bank=0xf, row=0xf, bound=0):
+    return struct.pack('<2I', 0x7e000000 | vdst << 17 | op << 9 | 250,
+                       src | ctrl(perm) << 8 | bound << 19 | bank << 24 | row << 28)
+
+
+def vop2_dpp(op, vdst, src0, vsrc1, perm, bank=0xf, row=0xf, bound=0):
+    return struct.pack('<2I', op << 25 | vdst << 17 | vsrc1 << 9 | 250,
+                       src0 | ctrl(perm) << 8 | bound << 19 | bank << 24 | row << 28)
+
+
+def vop1_mov_literal(vdst, value):
+    return struct.pack('<2I', 0x7e000000 | vdst << 17 | 1 << 9 | 255, value)

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 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4689077946 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2141#discussion_r4689077946). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T01:43:19Z. **Code review location:** `tests/startup_gfx2hlsl_dpp_quad_swap_check.py`; line 75 ~~~~diff @@ -0,0 +1,317 @@ +"""DPP16 quad swaps in the pixel stage of tools/startup/gfx2hlsl.py (#2125, item B). + + (no arguments) translation controls, pure Python + binary <llvm-mc> reassemble the fixture sources and compare them with the words built here + draw <dxc> <offscreen_check> <warp|hardware> [fxc] + compile the translated pair with DXC vs_6_0/ps_6_0, draw 16 x 16 pixels + and compare every pixel with the quad reference below + +In a DPP16 `quad_perm:[a,b,c,d]` source, lane i of each aligned group of four reads lane perm[i] of that group +(AMD RDNA 2 ISA reference, "Data-Parallel Primitives"; LLVM 15 AMDGPU `quad_perm`). The three exchanges +[1,0,3,2], [2,3,0,1] and [3,2,1,0] flip lane bit 0, bit 1 and both, which for the 2x2 pixel quad (lane = 2 * y + x) +is the pixel at x ^ 1, y ^ 1 or both. The lowering is QuadReadAcrossX, QuadReadAcrossY and QuadReadAcrossDiagonal +(SM 6.0), which read helper lanes too, so a quad that is only partly covered still gets a value for every lane. +Only a pixel stage at entry EXEC is lowered; FXC (ps_5_1) has no quad intrinsic, so a pair that needs one is +compiled with DXC as vs_6_0/ps_6_0 and refused when no DXC is found. + +The fixtures read the packed screen position (x | y << 16) in v0 and OR 0x40000000 into every exported word so +the words are normal binary32 values. The reference is written here from the lane rule with integers: the exchanged +source is the position of the pixel at x ^ 1 and/or y ^ 1. Mutations of the translated text (an exchange that +reads the wrong neighbour, and no exchange) must read a different image. +""" +import os +import re +import struct +import subprocess +import sys +import tempfile +from pathlib import Path + +HERE = Path(__file__).resolve().parent +sys.path.insert(0, str(HERE.parent / 'tools')) +sys.path.insert(0, str(HERE.parent / 'tools' / 'startup')) +sys.path.insert(0, str(HERE)) +import disasm_rdna2 as D # noqa: E402 +import gfx2hlsl as G # noqa: E402 +from startup_flat_param_check import assemble # noqa: E402 +from startup_image_3d_check import FULLSCREEN_VS, VS_WORDS, compile_hlsl, root_blob # noqa: E402 + +WIDTH = HEIGHT = 16 +MASK = 0xffffffff +FLAG = 0x40000000 +PACKED = (0x8000, 0x8000) # SPI_PS_INPUT_ENA/ADDR: the packed screen position only, in v0 +V_OR = 0x1c +SWAPS = {(1, 0, 3, 2): ('X', 1, 0), (2, 3, 0, 1): ('Y', 0, 1), (3, 2, 1, 0): ('Diagonal', 1, 1)} +failures = [] + + +def check(label, ok, detail=''): + print('%s: %s' % (label, 'ok' if ok else 'MISMATCH')) + if not ok: + failures.append(label) + if detail: + print(' ' + detail) + + +def ctrl(perm): + return perm[0] | perm[1] << 2 | perm[2] << 4 | perm[3] << 6 + + +def dpp_text(mnemonic, ops, perm, extra=' row_mask:0xf bank_mask:0xf'): + return '%s %s quad_perm:[%s]%s' % (mnemonic, ops, ','.join(map(str, perm)), extra) + + +def vop1_dpp(op, vdst, src, perm, bank=0xf, row=0xf, bound=0): + return struct.pack('<2I', 0x7e000000 | vdst << 17 | op << 9 | 250, + src | ctrl(perm) << 8 | bound << 19 | bank << 24 | row << 28) + + +def vop2_dpp(op, vdst, src0, vsrc1, perm, bank=0xf, row=0xf, bound=0): + return struct.pack('<2I', op << 25 | vdst << 17 | vsrc1 << 9 | 250, + src0 | ctrl(perm) << 8 | bound << 19 | bank << 24 | row << 28) + + +def vop1_mov_literal(vdst, value): + return struct.pack('<2I', 0x7e000000 | vdst << 17 | 1 << 9 | 255, value) ~~~~ --- **<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 -->
upstream-sync closed this pull request 2026-11-25 03:01:02 +00:00
tedin7 commented 2026-11-25 03:01:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:30:57Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050871262 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2141#pullrequestreview-6050871262). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:30:57Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-25 03:01:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:30:59Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050871568 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2141#pullrequestreview-6050871568). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:30:59Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-25 03:01:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:30:57Z.

Code review location: tools/startup/gfx2hlsl.py; line 785

@@ -744,6 +752,45 @@ def lower(self, base, asm, ops, mods):
             raise Unsupported('%s requires descriptor FORMAT and DST_SEL' % base)
         raise Unsupported(base)
 
+    # VOP1/VOP2 with a DPP16 quad_perm source (AMD RDNA 2 ISA, "Data-Parallel Primitives"): lane i of
+    # each aligned group of four reads src0 from lane quad_perm[i] of that group. The three exchanges
+    # map onto the SM 6.0 quad intrinsics, which read the other lane of the 2x2 pixel quad and keep
+    # helper lanes active. Only a pixel stage at entry EXEC qualifies: the hardware returns 0 or the old
+    # value for a source lane whose EXEC bit is off, and the intrinsics have no such case. Broadcast
+    # and pair permutations, DPP8, row shifts, partial masks and source modifiers stay refused.
+    def dpp(self, base, ops, mods):
+        perm = None
+        for m in mods:
+            match = re.fullmatch(r'quad_perm:\[([0-3]),([0-3]),([0-3]),([0-3])\]', m)
+            if match and perm is None:
+                perm = tuple(int(x) for x in match.groups())
+            elif m not in ('row_mask:0xf', 'bank_mask:0xf', 'bound_ctrl:0', 'bound_ctrl:1'):
+                raise Unsupported('%s_dpp with %s' % (base, m))
+        intrinsic = QUAD_SWAPS.get(perm)
+        if not intrinsic:
+            raise Unsupported('%s_dpp quad_perm %s: only the swaps [1,0,3,2], [2,3,0,1] and [3,2,1,0] are lowered'
+                              % (base, perm))
+        if base == 'v_mov_b32':
+            arity, text, kind = 1, '{0}', 'u'
+        elif base in VEC_U:
+            (arity, text), kind = VEC_U[base], 'u'
+        elif base in VEC_F and base not in ('v_fmac_f32', 'v_mac_f32'):
+            (arity, text), kind = VEC_F[base], 'f'
+        else:
+            raise Unsupported('%s_dpp' % base)
+        if len(ops) != arity + 1 or any(not re.fullmatch(r'v\d+', o) for o in ops):
+            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)

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4689552403 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2141#discussion_r4689552403). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:30:57Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 785 ~~~~diff @@ -744,6 +752,45 @@ def lower(self, base, asm, ops, mods): raise Unsupported('%s requires descriptor FORMAT and DST_SEL' % base) raise Unsupported(base) + # VOP1/VOP2 with a DPP16 quad_perm source (AMD RDNA 2 ISA, "Data-Parallel Primitives"): lane i of + # each aligned group of four reads src0 from lane quad_perm[i] of that group. The three exchanges + # map onto the SM 6.0 quad intrinsics, which read the other lane of the 2x2 pixel quad and keep + # helper lanes active. Only a pixel stage at entry EXEC qualifies: the hardware returns 0 or the old + # value for a source lane whose EXEC bit is off, and the intrinsics have no such case. Broadcast + # and pair permutations, DPP8, row shifts, partial masks and source modifiers stay refused. + def dpp(self, base, ops, mods): + perm = None + for m in mods: + match = re.fullmatch(r'quad_perm:\[([0-3]),([0-3]),([0-3]),([0-3])\]', m) + if match and perm is None: + perm = tuple(int(x) for x in match.groups()) + elif m not in ('row_mask:0xf', 'bank_mask:0xf', 'bound_ctrl:0', 'bound_ctrl:1'): + raise Unsupported('%s_dpp with %s' % (base, m)) + intrinsic = QUAD_SWAPS.get(perm) + if not intrinsic: + raise Unsupported('%s_dpp quad_perm %s: only the swaps [1,0,3,2], [2,3,0,1] and [3,2,1,0] are lowered' + % (base, perm)) + if base == 'v_mov_b32': + arity, text, kind = 1, '{0}', 'u' + elif base in VEC_U: + (arity, text), kind = VEC_U[base], 'u' + elif base in VEC_F and base not in ('v_fmac_f32', 'v_mac_f32'): + (arity, text), kind = VEC_F[base], 'f' + else: + raise Unsupported('%s_dpp' % base) + if len(ops) != arity + 1 or any(not re.fullmatch(r'v\d+', o) for o in ops): + 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) ~~~~ --- 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 commented 2026-11-25 03:01:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:30:58Z.

Code review location: tests/startup_gfx2hlsl_dpp_quad_swap_check.py; line 75

@@ -0,0 +1,317 @@
+"""DPP16 quad swaps in the pixel stage of tools/startup/gfx2hlsl.py (#2125, item B).
+
+  (no arguments)                       translation controls, pure Python
+  binary <llvm-mc>                     reassemble the fixture sources and compare them with the words built here
+  draw <dxc> <offscreen_check> <warp|hardware> [fxc]
+                                       compile the translated pair with DXC vs_6_0/ps_6_0, draw 16 x 16 pixels
+                                       and compare every pixel with the quad reference below
+
+In a DPP16 `quad_perm:[a,b,c,d]` source, lane i of each aligned group of four reads lane perm[i] of that group
+(AMD RDNA 2 ISA reference, "Data-Parallel Primitives"; LLVM 15 AMDGPU `quad_perm`). The three exchanges
+[1,0,3,2], [2,3,0,1] and [3,2,1,0] flip lane bit 0, bit 1 and both, which for the 2x2 pixel quad (lane = 2 * y + x)
+is the pixel at x ^ 1, y ^ 1 or both. The lowering is QuadReadAcrossX, QuadReadAcrossY and QuadReadAcrossDiagonal
+(SM 6.0), which read helper lanes too, so a quad that is only partly covered still gets a value for every lane.
+Only a pixel stage at entry EXEC is lowered; FXC (ps_5_1) has no quad intrinsic, so a pair that needs one is
+compiled with DXC as vs_6_0/ps_6_0 and refused when no DXC is found.
+
+The fixtures read the packed screen position (x | y << 16) in v0 and OR 0x40000000 into every exported word so
+the words are normal binary32 values. The reference is written here from the lane rule with integers: the exchanged
+source is the position of the pixel at x ^ 1 and/or y ^ 1. Mutations of the translated text (an exchange that
+reads the wrong neighbour, and no exchange) must read a different image.
+"""
+import os
+import re
+import struct
+import subprocess
+import sys
+import tempfile
+from pathlib import Path
+
+HERE = Path(__file__).resolve().parent
+sys.path.insert(0, str(HERE.parent / 'tools'))
+sys.path.insert(0, str(HERE.parent / 'tools' / 'startup'))
+sys.path.insert(0, str(HERE))
+import disasm_rdna2 as D  # noqa: E402
+import gfx2hlsl as G  # noqa: E402
+from startup_flat_param_check import assemble  # noqa: E402
+from startup_image_3d_check import FULLSCREEN_VS, VS_WORDS, compile_hlsl, root_blob  # noqa: E402
+
+WIDTH = HEIGHT = 16
+MASK = 0xffffffff
+FLAG = 0x40000000
+PACKED = (0x8000, 0x8000)  # SPI_PS_INPUT_ENA/ADDR: the packed screen position only, in v0
+V_OR = 0x1c
+SWAPS = {(1, 0, 3, 2): ('X', 1, 0), (2, 3, 0, 1): ('Y', 0, 1), (3, 2, 1, 0): ('Diagonal', 1, 1)}
+failures = []
+
+
+def check(label, ok, detail=''):
+    print('%s: %s' % (label, 'ok' if ok else 'MISMATCH'))
+    if not ok:
+        failures.append(label)
+        if detail:
+            print('  ' + detail)
+
+
+def ctrl(perm):
+    return perm[0] | perm[1] << 2 | perm[2] << 4 | perm[3] << 6
+
+
+def dpp_text(mnemonic, ops, perm, extra=' row_mask:0xf bank_mask:0xf'):
+    return '%s %s quad_perm:[%s]%s' % (mnemonic, ops, ','.join(map(str, perm)), extra)
+
+
+def vop1_dpp(op, vdst, src, perm, bank=0xf, row=0xf, bound=0):
+    return struct.pack('<2I', 0x7e000000 | vdst << 17 | op << 9 | 250,
+                       src | ctrl(perm) << 8 | bound << 19 | bank << 24 | row << 28)
+
+
+def vop2_dpp(op, vdst, src0, vsrc1, perm, bank=0xf, row=0xf, bound=0):
+    return struct.pack('<2I', op << 25 | vdst << 17 | vsrc1 << 9 | 250,
+                       src0 | ctrl(perm) << 8 | bound << 19 | bank << 24 | row << 28)
+
+
+def vop1_mov_literal(vdst, value):
+    return struct.pack('<2I', 0x7e000000 | vdst << 17 | 1 << 9 | 255, value)

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4689552620 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2141#discussion_r4689552620). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:30:58Z. **Code review location:** `tests/startup_gfx2hlsl_dpp_quad_swap_check.py`; line 75 ~~~~diff @@ -0,0 +1,317 @@ +"""DPP16 quad swaps in the pixel stage of tools/startup/gfx2hlsl.py (#2125, item B). + + (no arguments) translation controls, pure Python + binary <llvm-mc> reassemble the fixture sources and compare them with the words built here + draw <dxc> <offscreen_check> <warp|hardware> [fxc] + compile the translated pair with DXC vs_6_0/ps_6_0, draw 16 x 16 pixels + and compare every pixel with the quad reference below + +In a DPP16 `quad_perm:[a,b,c,d]` source, lane i of each aligned group of four reads lane perm[i] of that group +(AMD RDNA 2 ISA reference, "Data-Parallel Primitives"; LLVM 15 AMDGPU `quad_perm`). The three exchanges +[1,0,3,2], [2,3,0,1] and [3,2,1,0] flip lane bit 0, bit 1 and both, which for the 2x2 pixel quad (lane = 2 * y + x) +is the pixel at x ^ 1, y ^ 1 or both. The lowering is QuadReadAcrossX, QuadReadAcrossY and QuadReadAcrossDiagonal +(SM 6.0), which read helper lanes too, so a quad that is only partly covered still gets a value for every lane. +Only a pixel stage at entry EXEC is lowered; FXC (ps_5_1) has no quad intrinsic, so a pair that needs one is +compiled with DXC as vs_6_0/ps_6_0 and refused when no DXC is found. + +The fixtures read the packed screen position (x | y << 16) in v0 and OR 0x40000000 into every exported word so +the words are normal binary32 values. The reference is written here from the lane rule with integers: the exchanged +source is the position of the pixel at x ^ 1 and/or y ^ 1. Mutations of the translated text (an exchange that +reads the wrong neighbour, and no exchange) must read a different image. +""" +import os +import re +import struct +import subprocess +import sys +import tempfile +from pathlib import Path + +HERE = Path(__file__).resolve().parent +sys.path.insert(0, str(HERE.parent / 'tools')) +sys.path.insert(0, str(HERE.parent / 'tools' / 'startup')) +sys.path.insert(0, str(HERE)) +import disasm_rdna2 as D # noqa: E402 +import gfx2hlsl as G # noqa: E402 +from startup_flat_param_check import assemble # noqa: E402 +from startup_image_3d_check import FULLSCREEN_VS, VS_WORDS, compile_hlsl, root_blob # noqa: E402 + +WIDTH = HEIGHT = 16 +MASK = 0xffffffff +FLAG = 0x40000000 +PACKED = (0x8000, 0x8000) # SPI_PS_INPUT_ENA/ADDR: the packed screen position only, in v0 +V_OR = 0x1c +SWAPS = {(1, 0, 3, 2): ('X', 1, 0), (2, 3, 0, 1): ('Y', 0, 1), (3, 2, 1, 0): ('Diagonal', 1, 1)} +failures = [] + + +def check(label, ok, detail=''): + print('%s: %s' % (label, 'ok' if ok else 'MISMATCH')) + if not ok: + failures.append(label) + if detail: + print(' ' + detail) + + +def ctrl(perm): + return perm[0] | perm[1] << 2 | perm[2] << 4 | perm[3] << 6 + + +def dpp_text(mnemonic, ops, perm, extra=' row_mask:0xf bank_mask:0xf'): + return '%s %s quad_perm:[%s]%s' % (mnemonic, ops, ','.join(map(str, perm)), extra) + + +def vop1_dpp(op, vdst, src, perm, bank=0xf, row=0xf, bound=0): + return struct.pack('<2I', 0x7e000000 | vdst << 17 | op << 9 | 250, + src | ctrl(perm) << 8 | bound << 19 | bank << 24 | row << 28) + + +def vop2_dpp(op, vdst, src0, vsrc1, perm, bank=0xf, row=0xf, bound=0): + return struct.pack('<2I', op << 25 | vdst << 17 | vsrc1 << 9 | 250, + src0 | ctrl(perm) << 8 | bound << 19 | bank << 24 | row << 28) + + +def vop1_mov_literal(vdst, value): + return struct.pack('<2I', 0x7e000000 | vdst << 17 | 1 << 9 | 255, value) ~~~~ --- 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.
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!2133
No description provided.