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

Closed
tedin7 wants to merge 1 commit from upstream-pr/2784 into main
tedin7 commented 2026-11-26 08:50:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T08:50:39Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6622955566 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2784). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T08:50:39Z. --- 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 commented 2026-11-26 10:04:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T09:33:35Z.


@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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7188152325 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2784#issuecomment-7188152325). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T09:33:35Z. --- @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.
chatgpt-codex-connector[bot commented 2026-11-26 10:04:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T09:33:44Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7188155769 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2784#issuecomment-7188155769). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T09:33:44Z. --- <!-- 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>
upstream-sync closed this pull request 2026-11-26 11:02:48 +00:00
tedin7 commented 2026-11-26 11:02:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T10:12:50Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7189060786 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2784#issuecomment-7189060786). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T10:12:50Z. --- 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

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!2776
No description provided.