gfx2hlsl: a 32-bit integer scalar result ends the lane-mask tag of its register #2784

Closed
github-bot wants to merge 1 commit from gh-pr/2784/head into gh-pr/2784/base
Owner

@⁠tedin7 on GitHub · 2026-11-26 08:50 UTC · original
tedin7:x2w-mask-numeric-clear → main · +33 −0 · 2 files · 1 commits · closed without merging

Part of #1723

What this unblocks: a real pixel or compute program that reuses a scalar register for a number after it held a lane mask (for example a descriptor field extracted with s_bfe_u32 and then fed to s_max_u32) no longer stops at s_max_u32 reads lane mask sN as numeric data; the translator goes on to the next, genuine, refusal.
Source: AMD "RDNA 2" Instruction Set Architecture reference guide, SOP2 instructions S_BFE_U32 and S_MAX_U32 (scalar results are plain 32-bit data) and the EXEC / VCC lane-mask definitions.

What changed (tools/startup/gfx2hlsl.py, propagate_mask_tags):

  • A 32-bit integer scalar op that writes a number (s_add/sub/addc/subb, s_mul/mulk/addk, s_mul_hi, s_min/max, s_lshl/lshr/ashr, s_bfe, s_bfm, s_absdiff) ends the lane-mask tag of its destination register. Before, those handlers left the old tag on the register, so the number was later refused as a mask.
  • Why it is exact: the tag is a refusal marker. A mask used as a source of these ops is already refused in a group of more than one thread (and exact in a one-thread group), so the result of such an op is always a plain number; the destination holds no mask after it. Mask writers (s_mov/and/or/xor/andn2/orn2/nand/nor/xnor/not/wqm, s_cselect_b64, saveexec) are untouched and keep tagging.
  • What stays refused: any real mask as a numeric source (control in the test), s_cmp of a real mask, the high word of a wave64 mask.

Tests (tests/startup_gfx2hlsl_mask_overwrite_check.py): in the pixel and compute stages, each of seven numeric ops over a register that a v_cmp made a mask clears the tag and the following s_max_u32 of the result translates; a real mask as the source of s_max_u32 is still refused. Turning the new branch off makes the check fail.

Verification (Linux only):

  • python3 -B tests/startup_gfx2hlsl_mask_overwrite_check.py: PASS (fails with the new branch disabled)
  • the full Linux Python check list of the workflow: only the failures origin/main has in the same environment
  • python3 -B tests/startup_gfx2hlsl_compute_check.py, startup_gfx2hlsl_readfirstlane_uniform_check.py, startup_compute_readfirstlane_check.py: PASS
  • 173 existing translation shapes compared with origin/main: all unchanged

Win2025 WARP dev+release: pending Stage-2.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-26 08:50 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2784) `tedin7:x2w-mask-numeric-clear` → `main` · +33 −0 · 2 files · 1 commits · closed without merging Part of #1723 What this unblocks: a real pixel or compute program that reuses a scalar register for a number after it held a lane mask (for example a descriptor field extracted with `s_bfe_u32` and then fed to `s_max_u32`) no longer stops at `s_max_u32 reads lane mask sN as numeric data`; the translator goes on to the next, genuine, refusal. Source: AMD "RDNA 2" Instruction Set Architecture reference guide, SOP2 instructions S_BFE_U32 and S_MAX_U32 (scalar results are plain 32-bit data) and the EXEC / VCC lane-mask definitions. What changed (`tools/startup/gfx2hlsl.py`, `propagate_mask_tags`): - A 32-bit integer scalar op that writes a number (`s_add/sub/addc/subb`, `s_mul/mulk/addk`, `s_mul_hi`, `s_min/max`, `s_lshl/lshr/ashr`, `s_bfe`, `s_bfm`, `s_absdiff`) ends the lane-mask tag of its destination register. Before, those handlers left the old tag on the register, so the number was later refused as a mask. - Why it is exact: the tag is a refusal marker. A mask used as a source of these ops is already refused in a group of more than one thread (and exact in a one-thread group), so the result of such an op is always a plain number; the destination holds no mask after it. Mask writers (`s_mov/and/or/xor/andn2/orn2/nand/nor/xnor/not/wqm`, `s_cselect_b64`, saveexec) are untouched and keep tagging. - What stays refused: any real mask as a numeric source (control in the test), `s_cmp` of a real mask, the high word of a wave64 mask. Tests (`tests/startup_gfx2hlsl_mask_overwrite_check.py`): in the pixel and compute stages, each of seven numeric ops over a register that a `v_cmp` made a mask clears the tag and the following `s_max_u32` of the result translates; a real mask as the source of `s_max_u32` is still refused. Turning the new branch off makes the check fail. Verification (Linux only): - `python3 -B tests/startup_gfx2hlsl_mask_overwrite_check.py`: PASS (fails with the new branch disabled) - the full Linux Python check list of the workflow: only the failures `origin/main` has in the same environment - `python3 -B tests/startup_gfx2hlsl_compute_check.py`, `startup_gfx2hlsl_readfirstlane_uniform_check.py`, `startup_compute_readfirstlane_check.py`: PASS - 173 existing translation shapes compared with `origin/main`: all unchanged Win2025 WARP dev+release: pending Stage-2. AI-assisted; commands listed were executed locally.
s_bfe/lshr/min/max/add/mul/ashr and the like left the old mask tag on a register they overwrite with a number, so a later
numeric read (s_max_u32 of a descriptor field) was refused as a read of a lane mask. The tag now ends at the write.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:22:31 +00:00
github-bot closed this pull request 2026-11-27 01:22:31 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 09:33 UTC · original

@⁠MasterDomino Ready for review: head 473429b53c92ec72f717c7616003fdb84b150471 (CI green on this head).

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP), dev and release /O2, same regex on both:

python3 x2w_pipe.py win2025 2784 --regex 'startup_gfx2hlsl_mask_overwrite|startup_gfx2hlsl_compute|readfirstlane' --keep-release
ctest --preset dev     -R 'startup_gfx2hlsl_mask_overwrite|startup_gfx2hlsl_compute|readfirstlane' --no-tests=error   -> 54/54 passed
ctest --preset release -R 'startup_gfx2hlsl_mask_overwrite|startup_gfx2hlsl_compute|readfirstlane' --no-tests=error   -> 54/54 passed

The run lists startup_gfx2hlsl_mask_overwrite_check and startup_gfx2hlsl_mask_overwrite_controls among the 54, plus the compute and readfirstlane checks.

Independent review on this head: a mask used as a source of a numeric scalar op is still refused (same register as source and destination, s_mov copies, s_and/or/xor/andn2 results, wave32 and wave64 pair cases); the only program that changes from refused to translated is the intended one (a number written over a register that held a lane mask). The new check fails on main (28 checks) and passes on this head. 173 existing translation shapes are unchanged against main.

Not covered by this PR and the same on main: a wave64 pair whose high word alone is overwritten with a number, and the result of s_cselect_b32 of a mask, are not tagged. A test for the copy and pair cases would pin the current behaviour; it is not needed for this change.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-26 09:33 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2784#issuecomment-7188152325) @⁠MasterDomino Ready for review: head `473429b53c92ec72f717c7616003fdb84b150471` (CI green on this head). Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP), dev and release /O2, same regex on both: ``` python3 x2w_pipe.py win2025 2784 --regex 'startup_gfx2hlsl_mask_overwrite|startup_gfx2hlsl_compute|readfirstlane' --keep-release ctest --preset dev -R 'startup_gfx2hlsl_mask_overwrite|startup_gfx2hlsl_compute|readfirstlane' --no-tests=error -> 54/54 passed ctest --preset release -R 'startup_gfx2hlsl_mask_overwrite|startup_gfx2hlsl_compute|readfirstlane' --no-tests=error -> 54/54 passed ``` The run lists `startup_gfx2hlsl_mask_overwrite_check` and `startup_gfx2hlsl_mask_overwrite_controls` among the 54, plus the compute and readfirstlane checks. Independent review on this head: a mask used as a source of a numeric scalar op is still refused (same register as source and destination, `s_mov` copies, `s_and/or/xor/andn2` results, wave32 and wave64 pair cases); the only program that changes from refused to translated is the intended one (a number written over a register that held a lane mask). The new check fails on main (28 checks) and passes on this head. 173 existing translation shapes are unchanged against main. Not covered by this PR and the same on main: a wave64 pair whose high word alone is overwritten with a number, and the result of `s_cselect_b32` of a mask, are not tagged. A test for the copy and pair cases would pin the current behaviour; it is not needed for this change. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-26 09:33 UTC · original · edited 2026-11-26 09:38 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-26T09:38:30.878354Z 473429b Draft marked ready
ℹ️ About Codex in GitHub

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

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

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

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-26 09:33 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2784#issuecomment-7188155769) · edited 2026-11-26 09:38 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"473429b53c92ec72f717c7616003fdb84b150471","has_any_findings":false,"has_unresolved_findings":false,"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-26T09:38:30.878354Z">2026-11-26T09:38:30.878354Z</relative-time> | `473429b` | 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>
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 10:12 UTC · original

Withdrawn: shader translation is moving to the native C++ frontend (see #870), so we are not continuing this change to the Python translator. The branch stays available if any part is useful later. Thank you to everyone who reviewed and tested it.

**@⁠tedin7** on GitHub · 2026-11-26 10:12 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2784#issuecomment-7189060786) Withdrawn: shader translation is moving to the native C++ frontend (see #870), so we are not continuing this change to the Python translator. The branch stays available if any part is useful later. Thank you to everyone who reviewed and tested it.

Pull request closed

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