shader: lower v_readlane_b32 and v_permlanex16_b32 in gfx2hlsl (Part of #1723) #2032

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

@⁠tedin7 on GitHub · 2026-11-24 23:30 UTC · original
tedin7:x2w-r20-readlane-perm → main · +67 −0 · 3 files · 2 commits · closed without merging

Part of #1723

What this unblocks: Run 20 census #17 (40/39 pairs), v_readlane_b32 and v_permlanex16_b32.

Branch: x2w-r20-readlane-perm (local, not pushed).

Changes in tools/startup/gfx2hlsl.py:

  • v_readlane_b32 sD, vS, sel: sD = vS, only when vS is a proven uniform VGPR (same rule as v_readfirstlane_b32). The model runs one lane, so any lane gives the same word. The lane select may be an SGPR or inline constant.
  • v_permlanex16_b32 vD, vS, s0, s1: vD = vS for a proven uniform vS; vD stays uniform.
  • Refused: non-uniform source, branches or unknown exec, VGPR lane select, non-SGPR destination, and any modifier (the fetch-inactive and bound_ctrl flags change inactive-lane results the one-lane model cannot see).

Verification:

  • python3 -I tests/startup_gfx2hlsl_readlane_perm_check.py -> PASS (new test, registered in CMakeLists.txt as startup_gfx2hlsl_readlane_perm).
  • Same test with origin/main tools -> fails with Unsupported: v_readlane_b32.
  • python3 -I tests/startup_uniform_lane_check.py -> PASS
  • python3 -I tests/startup_gfx2hlsl_op_refusals_check.py -> PASS
  • Not run: Win2025 build and CTest (this host is Linux, Python tests only).

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 23:30 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2032) `tedin7:x2w-r20-readlane-perm` → `main` · +67 −0 · 3 files · 2 commits · closed without merging Part of #1723 What this unblocks: Run 20 census #17 (40/39 pairs), `v_readlane_b32` and `v_permlanex16_b32`. Branch: `x2w-r20-readlane-perm` (local, not pushed). Changes in `tools/startup/gfx2hlsl.py`: - `v_readlane_b32 sD, vS, sel`: `sD = vS`, only when `vS` is a proven uniform VGPR (same rule as `v_readfirstlane_b32`). The model runs one lane, so any lane gives the same word. The lane select may be an SGPR or inline constant. - `v_permlanex16_b32 vD, vS, s0, s1`: `vD = vS` for a proven uniform `vS`; `vD` stays uniform. - Refused: non-uniform source, branches or unknown exec, VGPR lane select, non-SGPR destination, and any modifier (the fetch-inactive and bound_ctrl flags change inactive-lane results the one-lane model cannot see). Verification: - `python3 -I tests/startup_gfx2hlsl_readlane_perm_check.py` -> PASS (new test, registered in CMakeLists.txt as `startup_gfx2hlsl_readlane_perm`). - Same test with `origin/main` tools -> fails with `Unsupported: v_readlane_b32`. - `python3 -I tests/startup_uniform_lane_check.py` -> PASS - `python3 -I tests/startup_gfx2hlsl_op_refusals_check.py` -> PASS - Not run: Win2025 build and CTest (this host is Linux, Python tests only). AI-assisted; commands listed were executed locally.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:51:02 +00:00
github-bot closed this pull request 2026-11-26 23:51:03 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:31 UTC · original · edited 2026-11-24 23:37 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-24T23:37:40.839920Z 5d64e8b PR opened
ℹ️ 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-24 23:31 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2032#issuecomment-7147487395) · edited 2026-11-24 23:37 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"5d64e8bcc5058f90b2c39f124b5590186c4343ff","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-24T23:37:40.839920Z">2026-11-24T23:37:40.839920Z</relative-time> | `5d64e8b` | PR opened | <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>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:37 UTC · original

P1 Badge Prove source-lane activity before collapsing cross-row permutes

On a pixel wave with a sparse entry EXEC mask, exec_known only means EXEC still equals its entry value, and uniform_v is populated by a conversion that writes active lanes only. Consequently, an accepted v_permlanex16_b32 v5, v4, 0, 0 in lane 0 can select inactive lane 16: with default FI=0/BOUND_CTRL=0, it retains the old v5, whereas this path emits v5 = v4 and marks the result uniform. For example, initializing v5 to 9 and converting a scalar-buffer value of 1.0 into v4 produces 9 on the guest but 1 in the translation. Require proof that selected source lanes are active, or model/refuse the inactive-source case before applying this identity.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2032#discussion_r4688059217) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Prove source-lane activity before collapsing cross-row permutes** On a pixel wave with a sparse entry EXEC mask, `exec_known` only means EXEC still equals its entry value, and `uniform_v` is populated by a conversion that writes active lanes only. Consequently, an accepted `v_permlanex16_b32 v5, v4, 0, 0` in lane 0 can select inactive lane 16: with default FI=0/BOUND_CTRL=0, it retains the old `v5`, whereas this path emits `v5 = v4` and marks the result uniform. For example, initializing `v5` to 9 and converting a scalar-buffer value of 1.0 into `v4` produces 9 on the guest but 1 in the translation. Require proof that selected source lanes are active, or model/refuse the inactive-source case before applying this identity. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠denn0x on GitHub · 2026-11-25 00:55 UTC · original

Thanks. One question on the uniform rule, and some numbers.

Inactive lanes. uniform_v is set when a VGPR is written from a uniform SGPR while exec still equals the entry mask. Lanes outside that mask never receive the word. v_readlane_b32 reads the named lane whatever EXEC says, so take a partly filled wave and a lane select that names a lane outside the entry mask. As I read the ISA, the hardware returns whatever that lane's VGPR still holds, but the translation returns the uniform word.

v_permlanex16_b32 without FI likewise depends on whether the source lane is active. I have not built a hardware case for either. Is the uniform proof meant to cover lanes that are not in the entry mask? If not, the restriction would need either a source written for every lane (whole-wave or v_writelane), or a note that the result is only proven for active lane selects.

Coverage on real programs (a private executable's ordinary pixel/vertex requests, decode and translate only, aggregate counts):

  • 503 requests use v_readlane_b32 in the pixel stage.
  • Their first refusal is the same with and without this PR. Most stop earlier, at v_readfirstlane_b32 requires a proven uniform source.
  • None of the uses I see have a uniform source:
    • v_readlane_b32 sN, vM, 31 (852) and v_permlanex16_b32 ..., 0, 0 (1,085) appear together with row_mirror / row_half_mirror DPP. That looks like a wave reduction.
    • v_writelane_b32 / v_readlane_b32 pairs with lane constants 0, 1, 2, ... (hundreds per lane index) look like SGPR values spilled into the lanes of one VGPR.

The spill shape can be lowered exactly without a cross-lane model: each lane index of that VGPR becomes a separate scalar slot, written by v_writelane and read by v_readlane with the same constant. That could be a separate item if someone wants it.

**@⁠denn0x** on GitHub · 2026-11-25 00:55 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2032#issuecomment-7149021486) Thanks. One question on the uniform rule, and some numbers. **Inactive lanes.** `uniform_v` is set when a VGPR is written from a uniform SGPR while exec still equals the entry mask. Lanes outside that mask never receive the word. `v_readlane_b32` reads the named lane whatever EXEC says, so take a partly filled wave and a lane select that names a lane outside the entry mask. As I read the ISA, the hardware returns whatever that lane's VGPR still holds, but the translation returns the uniform word. `v_permlanex16_b32` without FI likewise depends on whether the source lane is active. I have not built a hardware case for either. Is the uniform proof meant to cover lanes that are not in the entry mask? If not, the restriction would need either a source written for every lane (whole-wave or `v_writelane`), or a note that the result is only proven for active lane selects. **Coverage on real programs** (a private executable's ordinary pixel/vertex requests, decode and translate only, aggregate counts): - 503 requests use `v_readlane_b32` in the pixel stage. - Their first refusal is the same with and without this PR. Most stop earlier, at `v_readfirstlane_b32 requires a proven uniform source`. - None of the uses I see have a uniform source: - `v_readlane_b32 sN, vM, 31` (852) and `v_permlanex16_b32 ..., 0, 0` (1,085) appear together with `row_mirror` / `row_half_mirror` DPP. That looks like a wave reduction. - `v_writelane_b32` / `v_readlane_b32` pairs with lane constants 0, 1, 2, ... (hundreds per lane index) look like SGPR values spilled into the lanes of one VGPR. The spill shape can be lowered exactly without a cross-lane model: each lane index of that VGPR becomes a separate scalar slot, written by `v_writelane` and read by `v_readlane` with the same constant. That could be a separate item if someone wants it.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 00:56 UTC · original

Fixed in f2a28b42 (rebased on main, push pending). Agreed: uniformity is only proven over active lanes, so the selected source lane can be inactive. The same hole exists in v_readlane_b32. Both ops now refuse with "requires every selected source lane to be proven active", and the test asserts the refusals. Ran locally: python3 -B tests/startup_gfx2hlsl_readlane_perm_check.py and every tests/startup_gfx2hlsl_*check.py (all pass).

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 00:56 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2032#discussion_r4688725886) Fixed in f2a28b42 (rebased on main, push pending). Agreed: uniformity is only proven over active lanes, so the selected source lane can be inactive. The same hole exists in v_readlane_b32. Both ops now refuse with "requires every selected source lane to be proven active", and the test asserts the refusals. Ran locally: python3 -B tests/startup_gfx2hlsl_readlane_perm_check.py and every tests/startup_gfx2hlsl_*check.py (all pass). AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 10:46 UTC · original

@⁠denn0x thanks, you are right: the uniform proof only covers lanes in the entry mask, so it cannot vouch for a lane select outside it.

Fixed in f2a28b42: v_readlane_b32 and v_permlanex16_b32 are now refused, because the selected source lane may be inactive and its VGPR content is not provable. The check is tests/startup_gfx2hlsl_readlane_perm_check.py (see the comment near line 36, which covers the sparse-EXEC permlanex16 case).

Thank you for the coverage numbers. The lane-spill shape (v_writelane_b32 / v_readlane_b32 with matching constants) can be lowered exactly as separate scalar slots, so it can be a separate item.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 10:46 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2032#issuecomment-7160161594) @⁠denn0x thanks, you are right: the uniform proof only covers lanes in the entry mask, so it cannot vouch for a lane select outside it. Fixed in f2a28b42: `v_readlane_b32` and `v_permlanex16_b32` are now refused, because the selected source lane may be inactive and its VGPR content is not provable. The check is `tests/startup_gfx2hlsl_readlane_perm_check.py` (see the comment near line 36, which covers the sparse-EXEC permlanex16 case). Thank you for the coverage numbers. The lane-spill shape (`v_writelane_b32` / `v_readlane_b32` with matching constants) can be lowered exactly as separate scalar slots, so it can be a separate item. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 10:59 UTC · original

Closing: main already lowers v_readlane_b32 for SGPR spill slots (so this PR's refusal definition shadows it and would break startup_gfx2hlsl_sgpr_spill_check.py), and v_permlanex16_b32 is already refused by default.

**@⁠tedin7** on GitHub · 2026-11-25 10:59 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2032#issuecomment-7160434128) Closing: `main` already lowers `v_readlane_b32` for SGPR spill slots (so this PR's refusal definition shadows it and would break `startup_gfx2hlsl_sgpr_spill_check.py`), and `v_permlanex16_b32` is already refused by default.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:37 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5d64e8bcc5

ℹ️ 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-24 23:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2032#pullrequestreview-6049161717) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `5d64e8bcc5` <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>

Pull request closed

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