shader: lower DPP16 quad pair broadcasts in gfx2hlsl (Part of #2125) #2132

Merged
tedin7 merged 4 commits from upstream-pr/2140 into main 2026-11-25 03:12:05 +00:00
tedin7 commented 2026-11-25 01:29:29 +00:00 (Migrated from github.com)

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


Part of #2125

What this unblocks: item C of #2125, the four DPP16 pair broadcasts (quad_perm:[1,1,3,3], [0,0,2,2], [2,3,2,3], [0,1,0,1], 2,419 instructions) in pixel programs. Until now every _dpp spelling stopped translation.

The translator models one lane. In a pixel stage the other lane of a pair is rebuilt from ddx_fine (horizontal pair) or ddy_fine (vertical pair) of each 16-bit half of the register. Those halves are integers below 2^17, so the float32 difference is exact. The lane that takes the other word is picked from the parity of SV_Position. The permuted word goes to a scratch register, so v_add_nc_u32_dpp v3, v1, v1 still reads the pixel's own word as its second source. The quad must run together with its helper lanes, so the form is accepted only in straight-line pixel code with the full entry mask. Everything else is refused by name: other permutations (items A and B), row_*, wave_*, partial masks, fi, vertex stages, branches, a changed EXEC, scalar sources.

Not covered: items A and B (separate PRs), D and E (overlap #2032). Related open PR #2038 handles the identity quad_perm:[0,1,2,3]; the two touch lower() in different places and should merge without a semantic conflict.

Verification:

  • python3 -B tests/startup_gfx2hlsl_dpp_pair_check.py -> PASS (CPU quad model of the emitted text for all four patterns, three mutations that must differ, 15 refusals)
  • python3 -B tests/startup_gfx2hlsl_dpp_pair_check.py binary /usr/lib/llvm-19/bin/llvm-mc -> PASS (fixture words match the assembler for gfx1013)
  • python3 -B tests/startup_gfx2hlsl_{swap,op_refusals,refusals,operand_count,cndmask_neg,sdwa,vopc_sdwa}_check.py -> exit 0
  • Not run yet: the D3D12 draws startup_gfx2hlsl_dpp_pair_warp and startup_gfx2hlsl_dpp_pair_hardware (16 x 16 pixels per pattern against a CPU reference; wrong sign, wrong lanes, wrong axis and permuted second source must fail). They need the Windows build and are the gate before Ready.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6595025514 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2140). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:29:29Z. --- Part of #2125 What this unblocks: item C of #2125, the four DPP16 pair broadcasts (`quad_perm:[1,1,3,3]`, `[0,0,2,2]`, `[2,3,2,3]`, `[0,1,0,1]`, 2,419 instructions) in pixel programs. Until now every `_dpp` spelling stopped translation. The translator models one lane. In a pixel stage the other lane of a pair is rebuilt from `ddx_fine` (horizontal pair) or `ddy_fine` (vertical pair) of each 16-bit half of the register. Those halves are integers below 2^17, so the float32 difference is exact. The lane that takes the other word is picked from the parity of `SV_Position`. The permuted word goes to a scratch register, so `v_add_nc_u32_dpp v3, v1, v1` still reads the pixel's own word as its second source. The quad must run together with its helper lanes, so the form is accepted only in straight-line pixel code with the full entry mask. Everything else is refused by name: other permutations (items A and B), `row_*`, `wave_*`, partial masks, `fi`, vertex stages, branches, a changed EXEC, scalar sources. Not covered: items A and B (separate PRs), D and E (overlap #2032). Related open PR #2038 handles the identity `quad_perm:[0,1,2,3]`; the two touch `lower()` in different places and should merge without a semantic conflict. Verification: - `python3 -B tests/startup_gfx2hlsl_dpp_pair_check.py` -> PASS (CPU quad model of the emitted text for all four patterns, three mutations that must differ, 15 refusals) - `python3 -B tests/startup_gfx2hlsl_dpp_pair_check.py binary /usr/lib/llvm-19/bin/llvm-mc` -> PASS (fixture words match the assembler for gfx1013) - `python3 -B tests/startup_gfx2hlsl_{swap,op_refusals,refusals,operand_count,cndmask_neg,sdwa,vopc_sdwa}_check.py` -> exit 0 - Not run yet: the D3D12 draws `startup_gfx2hlsl_dpp_pair_warp` and `startup_gfx2hlsl_dpp_pair_hardware` (16 x 16 pixels per pattern against a CPU reference; wrong sign, wrong lanes, wrong axis and permuted second source must fail). They need the Windows build and are the gate before Ready. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-25 02:01:55 +00:00 (Migrated from github.com)

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

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f7257bc85d

ℹ️ 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:6050320700 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2140#pullrequestreview-6050320700). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T01:43:13Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `f7257bc85d` <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:35:33Z.


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:16.131415Z f7257bc 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:7149725691 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2140#issuecomment-7149725691). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T01:35:33Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"f7257bc85d73cb91183000c802e25cf6dc2abb1c","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:16.131415Z">2026-11-25T01:43:16.131415Z</relative-time> | `f7257bc` | 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:13Z.

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

@@ -671,6 +677,51 @@ def one(self, name, asm):
             self.uniform_v.add(dst)
         return term
 
+    def dpp(self, base, asm, ops, mods):
+        """A DPP16 spelling whose SRC0 is a quad pair broadcast (#2125 item C).
+
+        RDNA 2 ISA section 12.19 (DPP16): lane i of a quad reads SRC0 of lane quad_perm[i] of the same quad. A pair
+        broadcast ([1,1,3,3], [0,0,2,2], [2,3,2,3], [0,1,0,1]) moves one lane of every horizontal or vertical pair
+        into the other and leaves the first lane alone. The model has one lane, so the other lane's word is rebuilt
+        from the quad's fine derivative of each 16-bit half (ddx_fine / ddy_fine over exactly representable floats:
+        the difference of the pair, added to or subtracted from this lane's half). That needs all four lanes of the
+        quad to run the instruction in the same flow, as in a pixel shader with helper lanes: straight-line code and
+        the full entry mask. Every other control (other permutations, row_*, wave_*, a partial row or bank mask,
+        fi, a vertex stage) is refused by name, since the single lane cannot read a neighbour."""
+        perms = [m for m in mods if m.startswith('quad_perm:')]
+        rest = [m for m in mods if not m.startswith('quad_perm:')]
+        if len(perms) != 1:
+            raise Unsupported('%s_dpp with %s' % (base, ' '.join(mods)))
+        for m in rest:
+            if m not in ('row_mask:0xf', 'bank_mask:0xf', 'bound_ctrl:0', 'bound_ctrl:1'):
+                raise Unsupported('%s_dpp with %s' % (base, m))
+        # With all four lanes active no source lane is disabled, so bound_ctrl has nothing to replace.
+        perm = tuple(int(c) for c in re.findall(r'\d', perms[0]))
+        axis = DPP_PAIR.get(perm)
+        if axis is None:
+            raise Unsupported('%s_dpp with %s' % (base, perms[0]))
+        if (self.kind != 'ps' or getattr(self, 'has_branches', True) or not getattr(self, 'exec_known', False) or
+                getattr(self, 'fetched', False)):
+            raise Unsupported('%s_dpp %s outside straight-line pixel code with the full entry mask' % (base, perms[0]))

P1 Badge Require a proven whole-quad mask before lowering DPP

At a primitive edge, the entry EXEC mask can leave the selected neighbour inactive even while exec_known is true: that flag is initialized at entry and also stays true when a saved entry mask is restored after WQM. Native DPP16 with FI=0 must respect inactive-source/bound_ctrl behavior in that case, whereas this lowering reconstructs a D3D helper-lane value and unconditionally writes it. Consequently, accepted shaders without an established WQM mask, or after an exact-mask restore, can silently produce different edge pixels. Track a proven whole-quad execution state, or refuse these cases rather than treating an unchanged entry mask as proof that every source lane is active.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4689076917 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2140#discussion_r4689076917). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T01:43:13Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 705 ~~~~diff @@ -671,6 +677,51 @@ def one(self, name, asm): self.uniform_v.add(dst) return term + def dpp(self, base, asm, ops, mods): + """A DPP16 spelling whose SRC0 is a quad pair broadcast (#2125 item C). + + RDNA 2 ISA section 12.19 (DPP16): lane i of a quad reads SRC0 of lane quad_perm[i] of the same quad. A pair + broadcast ([1,1,3,3], [0,0,2,2], [2,3,2,3], [0,1,0,1]) moves one lane of every horizontal or vertical pair + into the other and leaves the first lane alone. The model has one lane, so the other lane's word is rebuilt + from the quad's fine derivative of each 16-bit half (ddx_fine / ddy_fine over exactly representable floats: + the difference of the pair, added to or subtracted from this lane's half). That needs all four lanes of the + quad to run the instruction in the same flow, as in a pixel shader with helper lanes: straight-line code and + the full entry mask. Every other control (other permutations, row_*, wave_*, a partial row or bank mask, + fi, a vertex stage) is refused by name, since the single lane cannot read a neighbour.""" + perms = [m for m in mods if m.startswith('quad_perm:')] + rest = [m for m in mods if not m.startswith('quad_perm:')] + if len(perms) != 1: + raise Unsupported('%s_dpp with %s' % (base, ' '.join(mods))) + for m in rest: + if m not in ('row_mask:0xf', 'bank_mask:0xf', 'bound_ctrl:0', 'bound_ctrl:1'): + raise Unsupported('%s_dpp with %s' % (base, m)) + # With all four lanes active no source lane is disabled, so bound_ctrl has nothing to replace. + perm = tuple(int(c) for c in re.findall(r'\d', perms[0])) + axis = DPP_PAIR.get(perm) + if axis is None: + raise Unsupported('%s_dpp with %s' % (base, perms[0])) + if (self.kind != 'ps' or getattr(self, 'has_branches', True) or not getattr(self, 'exec_known', False) or + getattr(self, 'fetched', False)): + raise Unsupported('%s_dpp %s outside straight-line pixel code with the full entry mask' % (base, perms[0])) ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Require a proven whole-quad mask before lowering DPP** At a primitive edge, the entry EXEC mask can leave the selected neighbour inactive even while `exec_known` is true: that flag is initialized at entry and also stays true when a saved entry mask is restored after WQM. Native DPP16 with `FI=0` must respect inactive-source/`bound_ctrl` behavior in that case, whereas this lowering reconstructs a D3D helper-lane value and unconditionally writes it. Consequently, accepted shaders without an established WQM mask, or after an exact-mask restore, can silently produce different edge pixels. Track a proven whole-quad execution state, or refuse these cases rather than treating an unchanged entry mask as proof that every source lane is active. 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:14Z.

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

@@ -671,6 +677,51 @@ def one(self, name, asm):
             self.uniform_v.add(dst)
         return term
 
+    def dpp(self, base, asm, ops, mods):
+        """A DPP16 spelling whose SRC0 is a quad pair broadcast (#2125 item C).
+
+        RDNA 2 ISA section 12.19 (DPP16): lane i of a quad reads SRC0 of lane quad_perm[i] of the same quad. A pair
+        broadcast ([1,1,3,3], [0,0,2,2], [2,3,2,3], [0,1,0,1]) moves one lane of every horizontal or vertical pair
+        into the other and leaves the first lane alone. The model has one lane, so the other lane's word is rebuilt
+        from the quad's fine derivative of each 16-bit half (ddx_fine / ddy_fine over exactly representable floats:
+        the difference of the pair, added to or subtracted from this lane's half). That needs all four lanes of the
+        quad to run the instruction in the same flow, as in a pixel shader with helper lanes: straight-line code and
+        the full entry mask. Every other control (other permutations, row_*, wave_*, a partial row or bank mask,
+        fi, a vertex stage) is refused by name, since the single lane cannot read a neighbour."""
+        perms = [m for m in mods if m.startswith('quad_perm:')]
+        rest = [m for m in mods if not m.startswith('quad_perm:')]
+        if len(perms) != 1:
+            raise Unsupported('%s_dpp with %s' % (base, ' '.join(mods)))
+        for m in rest:
+            if m not in ('row_mask:0xf', 'bank_mask:0xf', 'bound_ctrl:0', 'bound_ctrl:1'):
+                raise Unsupported('%s_dpp with %s' % (base, m))
+        # With all four lanes active no source lane is disabled, so bound_ctrl has nothing to replace.
+        perm = tuple(int(c) for c in re.findall(r'\d', perms[0]))
+        axis = DPP_PAIR.get(perm)
+        if axis is None:
+            raise Unsupported('%s_dpp with %s' % (base, perms[0]))
+        if (self.kind != 'ps' or getattr(self, 'has_branches', True) or not getattr(self, 'exec_known', False) or
+                getattr(self, 'fetched', False)):
+            raise Unsupported('%s_dpp %s outside straight-line pixel code with the full entry mask' % (base, perms[0]))
+        if len(ops) < 2:
+            raise Unsupported('%s_dpp with %d operands' % (base, len(ops)))
+        # The permuted word goes to a scratch register (v256, beyond the 256 hardware registers), so a second source
+        # naming the same register, or a destination that is the source, still reads the right lane.
+        src = re.fullmatch(r'([-|]*)v(\d+)(\|?)', ops[1])
+        if not src:
+            raise Unsupported('%s_dpp source %s' % (base, ops[1]))
+        word = 'v%s' % src.group(2)

P2 Badge Record the original DPP source as a used VGPR

When DPP is the only reader of a pixel-entry VGPR, constructing word directly bypasses self.u() and never records that source in used_v. For example, translating v_mov_b32_dpp v2, v0 with the accepted pair controls, packed-position input in v0, and an export referencing only v2 produces declarations for v2 and v256 but neither declares nor initializes v0. The newly accepted shader therefore fails during HLSL compilation. Resolve the original source through self.u() or explicitly register its use before replacing it with the scratch operand; the current fixtures hide this because their preceding multiply already records the source register.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4689076922 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2140#discussion_r4689076922). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T01:43:14Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 713 ~~~~diff @@ -671,6 +677,51 @@ def one(self, name, asm): self.uniform_v.add(dst) return term + def dpp(self, base, asm, ops, mods): + """A DPP16 spelling whose SRC0 is a quad pair broadcast (#2125 item C). + + RDNA 2 ISA section 12.19 (DPP16): lane i of a quad reads SRC0 of lane quad_perm[i] of the same quad. A pair + broadcast ([1,1,3,3], [0,0,2,2], [2,3,2,3], [0,1,0,1]) moves one lane of every horizontal or vertical pair + into the other and leaves the first lane alone. The model has one lane, so the other lane's word is rebuilt + from the quad's fine derivative of each 16-bit half (ddx_fine / ddy_fine over exactly representable floats: + the difference of the pair, added to or subtracted from this lane's half). That needs all four lanes of the + quad to run the instruction in the same flow, as in a pixel shader with helper lanes: straight-line code and + the full entry mask. Every other control (other permutations, row_*, wave_*, a partial row or bank mask, + fi, a vertex stage) is refused by name, since the single lane cannot read a neighbour.""" + perms = [m for m in mods if m.startswith('quad_perm:')] + rest = [m for m in mods if not m.startswith('quad_perm:')] + if len(perms) != 1: + raise Unsupported('%s_dpp with %s' % (base, ' '.join(mods))) + for m in rest: + if m not in ('row_mask:0xf', 'bank_mask:0xf', 'bound_ctrl:0', 'bound_ctrl:1'): + raise Unsupported('%s_dpp with %s' % (base, m)) + # With all four lanes active no source lane is disabled, so bound_ctrl has nothing to replace. + perm = tuple(int(c) for c in re.findall(r'\d', perms[0])) + axis = DPP_PAIR.get(perm) + if axis is None: + raise Unsupported('%s_dpp with %s' % (base, perms[0])) + if (self.kind != 'ps' or getattr(self, 'has_branches', True) or not getattr(self, 'exec_known', False) or + getattr(self, 'fetched', False)): + raise Unsupported('%s_dpp %s outside straight-line pixel code with the full entry mask' % (base, perms[0])) + if len(ops) < 2: + raise Unsupported('%s_dpp with %d operands' % (base, len(ops))) + # The permuted word goes to a scratch register (v256, beyond the 256 hardware registers), so a second source + # naming the same register, or a destination that is the source, still reads the right lane. + src = re.fullmatch(r'([-|]*)v(\d+)(\|?)', ops[1]) + if not src: + raise Unsupported('%s_dpp source %s' % (base, ops[1])) + word = 'v%s' % src.group(2) ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Record the original DPP source as a used VGPR** When DPP is the only reader of a pixel-entry VGPR, constructing `word` directly bypasses `self.u()` and never records that source in `used_v`. For example, translating `v_mov_b32_dpp v2, v0` with the accepted pair controls, packed-position input in `v0`, and an export referencing only `v2` produces declarations for `v2` and `v256` but neither declares nor initializes `v0`. The newly accepted shader therefore fails during HLSL compilation. Resolve the original source through `self.u()` or explicitly register its use before replacing it with the scratch operand; the current fixtures hide this because their preceding multiply already records the source register. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-25 03:01:02 +00:00 (Migrated from github.com)

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

Review: COMMENTED


No description provided.

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

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

Review: COMMENTED


No description provided.

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

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T02:22:26Z.

Review: CHANGES_REQUESTED


Independent Windows readback on aeb7f502: WARP passes all four 16×16 pairs and the controls. On RTX 4060 Laptop (32.0.16.1656, DXC from Windows SDK 10.0.26100.0, debug layer enabled), all four positive pair cases fail. For [0,1,0,1], the first mismatch is at (0,1): expected 00000000 9b5d0000 9b5d0000 00010000, actual 9b5d0000 36ba0000 9b5d0000 00010000, with 128/256 differing pixels and zero debug messages. The same runner passes #2141's SM6 quad swaps and their mutations on this adapter.

Please keep the integer-lane reference and check why the derivative-based pair reconstruction differs on hardware, or build the four pair mappings on the same SM6 quad-read path as the swaps, with an original vs candidate readback. Include an odd boundary or a partially covered quad in the shared follow-up so helper-lane behavior is observable.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050762987 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2140#pullrequestreview-6050762987). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T02:22:26Z. **Review:** CHANGES_REQUESTED --- Independent Windows readback on aeb7f502: WARP passes all four 16×16 pairs and the controls. On RTX 4060 Laptop (32.0.16.1656, DXC from Windows SDK 10.0.26100.0, debug layer enabled), all four positive pair cases fail. For `[0,1,0,1]`, the first mismatch is at (0,1): expected `00000000 9b5d0000 9b5d0000 00010000`, actual `9b5d0000 36ba0000 9b5d0000 00010000`, with 128/256 differing pixels and zero debug messages. The same runner passes #2141's SM6 quad swaps and their mutations on this adapter. Please keep the integer-lane reference and check why the derivative-based pair reconstruction differs on hardware, or build the four pair mappings on the same SM6 quad-read path as the swaps, with an original vs candidate readback. Include an odd boundary or a partially covered quad in the shared follow-up so helper-lane behavior is observable.
tedin7 commented 2026-11-25 03:01:23 +00:00 (Migrated from github.com)

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


Thanks for the independent RTX readback.

Root cause: the pair lowering rebuilt the other lane's word from ddx_fine / ddy_fine of each 16-bit half. A hardware derivative is not required to be the exact difference of the two pixels' values, so WARP matched and RTX did not. The derivative path is gone.

Fix in d5d0ea9c: each lane now reads the four lanes of its quad with the shader model 6.0 QuadReadLaneAt (constant lane arguments, all four reads unconditional, the same quad-read path as the swaps) and keeps the lane quad_perm names for its position. The integer-lane reference is unchanged. The stage compiles with DXC ps_6_0 through the same needs_sm6 / find_dxc pipeline step as #2141, and the FXC leg is dropped for this test.

Regression test: tests/startup_gfx2hlsl_dpp_pair_check.py now asserts there is no derivative in the text, models the four-lane read on the CPU, and the draw mutations (opposite lanes, the lane's own word, a transposed lane index, second source permuted) must each fail the 16x16 readback.

Verification (Win2025, WARP only, x2w_pipe.py win2025 2140 --targets offscreen_check --regex '^startup_gfx2hlsl_dpp_pair'): dev 3/3 and release 3/3 (startup_gfx2hlsl_dpp_pair, _warp, _hardware). Linux: startup_gfx2hlsl_*, startup_translator_check.py, docs_links_check.py pass. The VM has no RTX, so the hardware run here is WARP; please re-run your RTX readback on d5d0ea9c.

The odd boundary / partially covered quad case is not in this change. I will add it to the shared follow-up with #2141.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7150989721 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2140#issuecomment-7150989721). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:38:36Z. --- Thanks for the independent RTX readback. Root cause: the pair lowering rebuilt the other lane's word from `ddx_fine` / `ddy_fine` of each 16-bit half. A hardware derivative is not required to be the exact difference of the two pixels' values, so WARP matched and RTX did not. The derivative path is gone. Fix in d5d0ea9c: each lane now reads the four lanes of its quad with the shader model 6.0 `QuadReadLaneAt` (constant lane arguments, all four reads unconditional, the same quad-read path as the swaps) and keeps the lane `quad_perm` names for its position. The integer-lane reference is unchanged. The stage compiles with DXC `ps_6_0` through the same `needs_sm6` / `find_dxc` pipeline step as #2141, and the FXC leg is dropped for this test. Regression test: `tests/startup_gfx2hlsl_dpp_pair_check.py` now asserts there is no derivative in the text, models the four-lane read on the CPU, and the draw mutations (opposite lanes, the lane's own word, a transposed lane index, second source permuted) must each fail the 16x16 readback. Verification (Win2025, WARP only, `x2w_pipe.py win2025 2140 --targets offscreen_check --regex '^startup_gfx2hlsl_dpp_pair'`): dev 3/3 and release 3/3 (`startup_gfx2hlsl_dpp_pair`, `_warp`, `_hardware`). Linux: `startup_gfx2hlsl_*`, `startup_translator_check.py`, `docs_links_check.py` pass. The VM has no RTX, so the hardware run here is WARP; please re-run your RTX readback on d5d0ea9c. The odd boundary / partially covered quad case is not in this change. I will add it to the shared follow-up with #2141. 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:20:11Z.

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

@@ -671,6 +677,51 @@ def one(self, name, asm):
             self.uniform_v.add(dst)
         return term
 
+    def dpp(self, base, asm, ops, mods):
+        """A DPP16 spelling whose SRC0 is a quad pair broadcast (#2125 item C).
+
+        RDNA 2 ISA section 12.19 (DPP16): lane i of a quad reads SRC0 of lane quad_perm[i] of the same quad. A pair
+        broadcast ([1,1,3,3], [0,0,2,2], [2,3,2,3], [0,1,0,1]) moves one lane of every horizontal or vertical pair
+        into the other and leaves the first lane alone. The model has one lane, so the other lane's word is rebuilt
+        from the quad's fine derivative of each 16-bit half (ddx_fine / ddy_fine over exactly representable floats:
+        the difference of the pair, added to or subtracted from this lane's half). That needs all four lanes of the
+        quad to run the instruction in the same flow, as in a pixel shader with helper lanes: straight-line code and
+        the full entry mask. Every other control (other permutations, row_*, wave_*, a partial row or bank mask,
+        fi, a vertex stage) is refused by name, since the single lane cannot read a neighbour."""
+        perms = [m for m in mods if m.startswith('quad_perm:')]
+        rest = [m for m in mods if not m.startswith('quad_perm:')]
+        if len(perms) != 1:
+            raise Unsupported('%s_dpp with %s' % (base, ' '.join(mods)))
+        for m in rest:
+            if m not in ('row_mask:0xf', 'bank_mask:0xf', 'bound_ctrl:0', 'bound_ctrl:1'):
+                raise Unsupported('%s_dpp with %s' % (base, m))
+        # With all four lanes active no source lane is disabled, so bound_ctrl has nothing to replace.
+        perm = tuple(int(c) for c in re.findall(r'\d', perms[0]))
+        axis = DPP_PAIR.get(perm)
+        if axis is None:
+            raise Unsupported('%s_dpp with %s' % (base, perms[0]))
+        if (self.kind != 'ps' or getattr(self, 'has_branches', True) or not getattr(self, 'exec_known', False) or
+                getattr(self, 'fetched', False)):
+            raise Unsupported('%s_dpp %s outside straight-line pixel code with the full entry mask' % (base, perms[0]))

Fixed in aeb7f502. The DPP lowering now needs a proven whole-quad mask: s_wqm_b64/b32 exec, exec on the entry mask sets whole_quad, and restoring a saved exact mask clears it. Without that proof, or after an exact restore, the shader is refused by name. Fixtures now open with s_wqm_b64 exec, exec.

Regression tests in tests/startup_gfx2hlsl_dpp_pair_check.py: refuse without WQM, refuse after s_mov_b64 exec, s[4:5] restore, accept after WQM with an unrestored saved copy. They fail on the previous commit and pass now.

Verification:

  • python3 -B tests/startup_gfx2hlsl_dpp_pair_check.py: PASS
  • python3 -B tools/run_checks_parallel.py -j 4 tests/startup_gfx2hlsl_*_check.py tests/startup_translator_check.py tests/startup_buffer_address_check.py tests/docs_links_check.py tests/mesh_dynamic_geometry_check.py tests/startup_ngg_slice_check.py tests/run_checks_parallel_check.py: all 41 passed
  • Win2025 x2w_pipe.py win2025 2140 --regex '^startup_gfx2hlsl_dpp_pair': dev 3/3 and release 3/3 passed (controls, WARP draw, hardware draw)

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4689436270 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2140#discussion_r4689436270). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:20:11Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 705 ~~~~diff @@ -671,6 +677,51 @@ def one(self, name, asm): self.uniform_v.add(dst) return term + def dpp(self, base, asm, ops, mods): + """A DPP16 spelling whose SRC0 is a quad pair broadcast (#2125 item C). + + RDNA 2 ISA section 12.19 (DPP16): lane i of a quad reads SRC0 of lane quad_perm[i] of the same quad. A pair + broadcast ([1,1,3,3], [0,0,2,2], [2,3,2,3], [0,1,0,1]) moves one lane of every horizontal or vertical pair + into the other and leaves the first lane alone. The model has one lane, so the other lane's word is rebuilt + from the quad's fine derivative of each 16-bit half (ddx_fine / ddy_fine over exactly representable floats: + the difference of the pair, added to or subtracted from this lane's half). That needs all four lanes of the + quad to run the instruction in the same flow, as in a pixel shader with helper lanes: straight-line code and + the full entry mask. Every other control (other permutations, row_*, wave_*, a partial row or bank mask, + fi, a vertex stage) is refused by name, since the single lane cannot read a neighbour.""" + perms = [m for m in mods if m.startswith('quad_perm:')] + rest = [m for m in mods if not m.startswith('quad_perm:')] + if len(perms) != 1: + raise Unsupported('%s_dpp with %s' % (base, ' '.join(mods))) + for m in rest: + if m not in ('row_mask:0xf', 'bank_mask:0xf', 'bound_ctrl:0', 'bound_ctrl:1'): + raise Unsupported('%s_dpp with %s' % (base, m)) + # With all four lanes active no source lane is disabled, so bound_ctrl has nothing to replace. + perm = tuple(int(c) for c in re.findall(r'\d', perms[0])) + axis = DPP_PAIR.get(perm) + if axis is None: + raise Unsupported('%s_dpp with %s' % (base, perms[0])) + if (self.kind != 'ps' or getattr(self, 'has_branches', True) or not getattr(self, 'exec_known', False) or + getattr(self, 'fetched', False)): + raise Unsupported('%s_dpp %s outside straight-line pixel code with the full entry mask' % (base, perms[0])) ~~~~ --- Fixed in aeb7f502. The DPP lowering now needs a proven whole-quad mask: `s_wqm_b64/b32 exec, exec` on the entry mask sets `whole_quad`, and restoring a saved exact mask clears it. Without that proof, or after an exact restore, the shader is refused by name. Fixtures now open with `s_wqm_b64 exec, exec`. Regression tests in `tests/startup_gfx2hlsl_dpp_pair_check.py`: refuse without WQM, refuse after `s_mov_b64 exec, s[4:5]` restore, accept after WQM with an unrestored saved copy. They fail on the previous commit and pass now. Verification: - `python3 -B tests/startup_gfx2hlsl_dpp_pair_check.py`: PASS - `python3 -B tools/run_checks_parallel.py -j 4 tests/startup_gfx2hlsl_*_check.py tests/startup_translator_check.py tests/startup_buffer_address_check.py tests/docs_links_check.py tests/mesh_dynamic_geometry_check.py tests/startup_ngg_slice_check.py tests/run_checks_parallel_check.py`: all 41 passed - Win2025 `x2w_pipe.py win2025 2140 --regex '^startup_gfx2hlsl_dpp_pair'`: dev 3/3 and release 3/3 passed (controls, WARP draw, hardware draw) 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:20:13Z.

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

@@ -671,6 +677,51 @@ def one(self, name, asm):
             self.uniform_v.add(dst)
         return term
 
+    def dpp(self, base, asm, ops, mods):
+        """A DPP16 spelling whose SRC0 is a quad pair broadcast (#2125 item C).
+
+        RDNA 2 ISA section 12.19 (DPP16): lane i of a quad reads SRC0 of lane quad_perm[i] of the same quad. A pair
+        broadcast ([1,1,3,3], [0,0,2,2], [2,3,2,3], [0,1,0,1]) moves one lane of every horizontal or vertical pair
+        into the other and leaves the first lane alone. The model has one lane, so the other lane's word is rebuilt
+        from the quad's fine derivative of each 16-bit half (ddx_fine / ddy_fine over exactly representable floats:
+        the difference of the pair, added to or subtracted from this lane's half). That needs all four lanes of the
+        quad to run the instruction in the same flow, as in a pixel shader with helper lanes: straight-line code and
+        the full entry mask. Every other control (other permutations, row_*, wave_*, a partial row or bank mask,
+        fi, a vertex stage) is refused by name, since the single lane cannot read a neighbour."""
+        perms = [m for m in mods if m.startswith('quad_perm:')]
+        rest = [m for m in mods if not m.startswith('quad_perm:')]
+        if len(perms) != 1:
+            raise Unsupported('%s_dpp with %s' % (base, ' '.join(mods)))
+        for m in rest:
+            if m not in ('row_mask:0xf', 'bank_mask:0xf', 'bound_ctrl:0', 'bound_ctrl:1'):
+                raise Unsupported('%s_dpp with %s' % (base, m))
+        # With all four lanes active no source lane is disabled, so bound_ctrl has nothing to replace.
+        perm = tuple(int(c) for c in re.findall(r'\d', perms[0]))
+        axis = DPP_PAIR.get(perm)
+        if axis is None:
+            raise Unsupported('%s_dpp with %s' % (base, perms[0]))
+        if (self.kind != 'ps' or getattr(self, 'has_branches', True) or not getattr(self, 'exec_known', False) or
+                getattr(self, 'fetched', False)):
+            raise Unsupported('%s_dpp %s outside straight-line pixel code with the full entry mask' % (base, perms[0]))
+        if len(ops) < 2:
+            raise Unsupported('%s_dpp with %d operands' % (base, len(ops)))
+        # The permuted word goes to a scratch register (v256, beyond the 256 hardware registers), so a second source
+        # naming the same register, or a destination that is the source, still reads the right lane.
+        src = re.fullmatch(r'([-|]*)v(\d+)(\|?)', ops[1])
+        if not src:
+            raise Unsupported('%s_dpp source %s' % (base, ops[1]))
+        word = 'v%s' % src.group(2)

Fixed in aeb7f502. The source register now goes through self.u(), so it is recorded in used_v and declared and initialized even when DPP is its only reader.

Regression test: v_mov_b32_dpp v2, v0 with an export of only v2 must declare and initialize v0 before the lowering (tests/startup_gfx2hlsl_dpp_pair_check.py). It fails on the previous commit and passes now.

Verification:

  • python3 -B tests/startup_gfx2hlsl_dpp_pair_check.py: PASS
  • Win2025 x2w_pipe.py win2025 2140 --regex '^startup_gfx2hlsl_dpp_pair': dev 3/3 and release 3/3 passed

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4689436667 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2140#discussion_r4689436667). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:20:13Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 713 ~~~~diff @@ -671,6 +677,51 @@ def one(self, name, asm): self.uniform_v.add(dst) return term + def dpp(self, base, asm, ops, mods): + """A DPP16 spelling whose SRC0 is a quad pair broadcast (#2125 item C). + + RDNA 2 ISA section 12.19 (DPP16): lane i of a quad reads SRC0 of lane quad_perm[i] of the same quad. A pair + broadcast ([1,1,3,3], [0,0,2,2], [2,3,2,3], [0,1,0,1]) moves one lane of every horizontal or vertical pair + into the other and leaves the first lane alone. The model has one lane, so the other lane's word is rebuilt + from the quad's fine derivative of each 16-bit half (ddx_fine / ddy_fine over exactly representable floats: + the difference of the pair, added to or subtracted from this lane's half). That needs all four lanes of the + quad to run the instruction in the same flow, as in a pixel shader with helper lanes: straight-line code and + the full entry mask. Every other control (other permutations, row_*, wave_*, a partial row or bank mask, + fi, a vertex stage) is refused by name, since the single lane cannot read a neighbour.""" + perms = [m for m in mods if m.startswith('quad_perm:')] + rest = [m for m in mods if not m.startswith('quad_perm:')] + if len(perms) != 1: + raise Unsupported('%s_dpp with %s' % (base, ' '.join(mods))) + for m in rest: + if m not in ('row_mask:0xf', 'bank_mask:0xf', 'bound_ctrl:0', 'bound_ctrl:1'): + raise Unsupported('%s_dpp with %s' % (base, m)) + # With all four lanes active no source lane is disabled, so bound_ctrl has nothing to replace. + perm = tuple(int(c) for c in re.findall(r'\d', perms[0])) + axis = DPP_PAIR.get(perm) + if axis is None: + raise Unsupported('%s_dpp with %s' % (base, perms[0])) + if (self.kind != 'ps' or getattr(self, 'has_branches', True) or not getattr(self, 'exec_known', False) or + getattr(self, 'fetched', False)): + raise Unsupported('%s_dpp %s outside straight-line pixel code with the full entry mask' % (base, perms[0])) + if len(ops) < 2: + raise Unsupported('%s_dpp with %d operands' % (base, len(ops))) + # The permuted word goes to a scratch register (v256, beyond the 256 hardware registers), so a second source + # naming the same register, or a destination that is the source, still reads the right lane. + src = re.fullmatch(r'([-|]*)v(\d+)(\|?)', ops[1]) + if not src: + raise Unsupported('%s_dpp source %s' % (base, ops[1])) + word = 'v%s' % src.group(2) ~~~~ --- Fixed in aeb7f502. The source register now goes through `self.u()`, so it is recorded in `used_v` and declared and initialized even when DPP is its only reader. Regression test: `v_mov_b32_dpp v2, v0` with an export of only `v2` must declare and initialize `v0` before the lowering (`tests/startup_gfx2hlsl_dpp_pair_check.py`). It fails on the previous commit and passes now. Verification: - `python3 -B tests/startup_gfx2hlsl_dpp_pair_check.py`: PASS - Win2025 `x2w_pipe.py win2025 2140 --regex '^startup_gfx2hlsl_dpp_pair'`: dev 3/3 and release 3/3 passed AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 04:03:56 +00:00
R0Y00 commented 2026-11-25 04:03:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T03:08:07Z.

Review: APPROVED


Independent RTX and WARP readbacks now match the CPU reference on the exact revised head. The three DPP forms and the LLVM 15 round-trip are covered.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6051272125 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2140#pullrequestreview-6051272125). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T03:08:07Z. **Review:** APPROVED --- Independent RTX and WARP readbacks now match the CPU reference on the exact revised head. The three DPP forms and the LLVM 15 round-trip are covered.
R0Y00 commented 2026-11-25 04:04:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T03:06:32Z.


I resolved the main conflicts at 71ec807d and kept the pair permutations, swaps, and single-lane broadcasts as separate cases. The source-built draw and mutation checks for all three passed on WARP and RTX 4060 Laptop (32.0.16.1656), with no skips. LLVM 15 also reproduced all four pair encodings and the explicit bound bit. This replaces my earlier RTX result for the derivative variant. Please keep the original narrow scope while the final CI runs.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7151597091 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2140#issuecomment-7151597091). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T03:06:32Z. --- I resolved the main conflicts at `71ec807d` and kept the pair permutations, swaps, and single-lane broadcasts as separate cases. The source-built draw and mutation checks for all three passed on WARP and RTX 4060 Laptop (`32.0.16.1656`), with no skips. LLVM 15 also reproduced all four pair encodings and the explicit bound bit. This replaces my earlier RTX result for the derivative variant. Please keep the original narrow scope while the final CI runs.
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!2132
No description provided.