shader: lower s_bitset0_b32 and s_ff0_i32_b32 in gfx2hlsl (Part of #1723) #2040

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

@⁠tedin7 on GitHub · 2026-11-24 23:32 UTC · original
tedin7:x2w-r21-scalar-twins-a → main · +160 −1 · 3 files · 5 commits · closed without merging

Part of #1723

What this unblocks: startup shaders that use the RDNA2 scalar address/bit helpers s_lshl2_add_u32, s_lshl3_add_u32, s_bitset0_b32 and s_ff0_i32_b32 now translate instead of stopping at "Unsupported".

Change

  • tools/startup/gfx2hlsl.py: lowering for the four scalar ops.
    • s_lshl2_add_u32 / s_lshl3_add_u32: D = (S0 << n) + S1; SCC is the carry out of the 64-bit sum (bits shifted out of S0 or a wrapped add). SCC is computed before the destination write, so a destination aliasing a source is correct.
    • s_bitset0_b32: clears bit S0[4:0] of the destination (read-modify-write); SCC unchanged.
    • s_ff0_i32_b32: uint(firstbitlow(~S0)), which is 0xffffffff (-1) when no bit is zero; SCC unchanged.
    • Lane-mask sources, descriptor data and destinations outside s0..s105/m0 are refused.
  • tests/startup_gfx2hlsl_scalar_twins_check.py, registered in CMakeLists.txt as startup_gfx2hlsl_scalar_twins: builds instruction words from the decoder layouts, translates, runs the emitted lines on an integer evaluator over edge values and compares with an integer reference (including destination aliasing and SCC).

Verification

Run on the Linux worker (Python only, no GPU):

  • python3 -B tests/startup_gfx2hlsl_scalar_twins_check.py on origin/main: fails (Unsupported: s_lshl2_add_u32).
  • Same command with this change: startup_gfx2hlsl_scalar_twins_check: ok.
  • python3 -B tests/startup_gfx2hlsl_sop2_complement_check.py: PASS.
  • python3 -B tests/startup_gfx2hlsl_scalar_m0_check.py: controls passed.
  • python3 -B tests/startup_gfx2hlsl_bit_alu_check.py: ok.

Win2025 commands: not run (no Windows host in this worker).

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 23:32 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2040) `tedin7:x2w-r21-scalar-twins-a` → `main` · +160 −1 · 3 files · 5 commits · closed without merging Part of #1723 What this unblocks: startup shaders that use the RDNA2 scalar address/bit helpers `s_lshl2_add_u32`, `s_lshl3_add_u32`, `s_bitset0_b32` and `s_ff0_i32_b32` now translate instead of stopping at "Unsupported". ## Change - `tools/startup/gfx2hlsl.py`: lowering for the four scalar ops. - `s_lshl2_add_u32` / `s_lshl3_add_u32`: `D = (S0 << n) + S1`; SCC is the carry out of the 64-bit sum (bits shifted out of S0 or a wrapped add). SCC is computed before the destination write, so a destination aliasing a source is correct. - `s_bitset0_b32`: clears bit `S0[4:0]` of the destination (read-modify-write); SCC unchanged. - `s_ff0_i32_b32`: `uint(firstbitlow(~S0))`, which is `0xffffffff` (-1) when no bit is zero; SCC unchanged. - Lane-mask sources, descriptor data and destinations outside s0..s105/m0 are refused. - `tests/startup_gfx2hlsl_scalar_twins_check.py`, registered in `CMakeLists.txt` as `startup_gfx2hlsl_scalar_twins`: builds instruction words from the decoder layouts, translates, runs the emitted lines on an integer evaluator over edge values and compares with an integer reference (including destination aliasing and SCC). ## Verification Run on the Linux worker (Python only, no GPU): - `python3 -B tests/startup_gfx2hlsl_scalar_twins_check.py` on `origin/main`: fails (`Unsupported: s_lshl2_add_u32`). - Same command with this change: `startup_gfx2hlsl_scalar_twins_check: ok`. - `python3 -B tests/startup_gfx2hlsl_sop2_complement_check.py`: PASS. - `python3 -B tests/startup_gfx2hlsl_scalar_m0_check.py`: controls passed. - `python3 -B tests/startup_gfx2hlsl_bit_alu_check.py`: ok. Win2025 commands: not run (no Windows host in this worker). AI-assisted; commands listed were executed locally.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:51:36 +00:00
github-bot closed this pull request 2026-11-26 23:51:36 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:32 UTC · original · edited 2026-11-24 23:36 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:36:37.626305Z e9e35fc 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:32 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2040#issuecomment-7147517535) · edited 2026-11-24 23:36 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"e9e35fc4382cf8c0e8b46636a1c0c773220d9cdc","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:36:37.626305Z">2026-11-24T23:36:37.626305Z</relative-time> | `e9e35fc` | 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>
@ -4255,2 +4294,4 @@
's_sext_i32_i8': ('uint(int({0} << 24) >> 24)', None),
's_sext_i32_i16': ('uint(int({0} << 16) >> 16)', None),
# s_ff0_i32_b32: index of the lowest zero bit, -1 when every bit is set; SCC unchanged.
's_ff0_i32_b32': ('uint(firstbitlow(~{0}))', None),
Author
Owner

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

P2 Badge Reject lane-mask inputs before lowering s_ff0_i32_b32

When this instruction reads exec_lo, vcc_lo, or an SGPR tracked in self.masks, dispatch through SCA bypasses the whole-word guards used by the other new lowerings. These masks contain only the current lane's bit in the translated shader. For example, when the guest's EXEC_LO is 0xffffffff, the emitted uint(firstbitlow(~exec)) evaluates to 1 because translated exec is 1, rather than the required 0xffffffff. This silently mistranslates valid shaders; reject lane-mask sources, including copied masks, unless a full-wave representation is available.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:36 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2040#discussion_r4688048696) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Reject lane-mask inputs before lowering s_ff0_i32_b32** When this instruction reads `exec_lo`, `vcc_lo`, or an SGPR tracked in `self.masks`, dispatch through `SCA` bypasses the whole-word guards used by the other new lowerings. These masks contain only the current lane's bit in the translated shader. For example, when the guest's `EXEC_LO` is `0xffffffff`, the emitted `uint(firstbitlow(~exec))` evaluates to `1` because translated `exec` is `1`, rather than the required `0xffffffff`. This silently mistranslates valid shaders; reject lane-mask sources, including copied masks, unless a full-wave representation is available. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

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

P2 Badge Allow numeric symbolic values through the source validator

When an operand is a root constant or a value read by a literal-offset s_buffer_load_dword*, its symbolic tag is ud or fixed_buffer_word; both already represent complete numeric values supported by Stage.S(). This check incorrectly classifies them as descriptor data. For example, s_lshl2_add_u32 s4, s8, s3 raises Unsupported when s8 holds a root constant, and s_bitset0_b32 similarly rejects a numeric root-constant destination. The new operations therefore reject ordinary scalar inputs even though moving the same value through a temporary makes them work. Allow these numeric tags while retaining the descriptor and pointer refusals.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:36 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2040#discussion_r4688048703) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Allow numeric symbolic values through the source validator** When an operand is a root constant or a value read by a literal-offset `s_buffer_load_dword*`, its symbolic tag is `ud` or `fixed_buffer_word`; both already represent complete numeric values supported by `Stage.S()`. This check incorrectly classifies them as descriptor data. For example, `s_lshl2_add_u32 s4, s8, s3` raises `Unsupported` when `s8` holds a root constant, and `s_bitset0_b32` similarly rejects a numeric root-constant destination. The new operations therefore reject ordinary scalar inputs even though moving the same value through a temporary makes them work. Allow these numeric tags while retaining the descriptor and pointer refusals. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-25 00:15 UTC · original

#2027 is now on main and supplies the s_lshl2_add_u32 and s_lshl3_add_u32 handlers, including the SCC proof and discard-destination control. Please keep those definitions from main when updating this branch and limit its remaining diff to s_bitset0_b32 and s_ff0_i32_b32. That leaves the two operations independently reviewable and keeps the existing lane-mask and numeric-symbol findings applicable to this smaller slice.

**@⁠R0Y00** on GitHub · 2026-11-25 00:15 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2040#issuecomment-7148313520) #2027 is now on main and supplies the `s_lshl2_add_u32` and `s_lshl3_add_u32` handlers, including the SCC proof and discard-destination control. Please keep those definitions from main when updating this branch and limit its remaining diff to `s_bitset0_b32` and `s_ff0_i32_b32`. That leaves the two operations independently reviewable and keeps the existing lane-mask and numeric-symbol findings applicable to this smaller slice.
Author
Owner

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

Updated in 90959dc6: removed the duplicate s_lshl2_add_u32 / s_lshl3_add_u32 handlers and kept main's SCC uniformity and discard-destination control; this PR now covers s_bitset0_b32 and s_ff0_i32_b32 only.

**@⁠tedin7** on GitHub · 2026-11-25 00:38 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2040#issuecomment-7148722621) Updated in 90959dc6: removed the duplicate s_lshl2_add_u32 / s_lshl3_add_u32 handlers and kept main's SCC uniformity and discard-destination control; this PR now covers s_bitset0_b32 and s_ff0_i32_b32 only.
@ -4255,2 +4294,4 @@
's_sext_i32_i8': ('uint(int({0} << 24) >> 24)', None),
's_sext_i32_i16': ('uint(int({0} << 16) >> 16)', None),
# s_ff0_i32_b32: index of the lowest zero bit, -1 when every bit is set; SCC unchanged.
's_ff0_i32_b32': ('uint(firstbitlow(~{0}))', None),
Author
Owner

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

Fixed in 10ec331e (rebased on main, push pending): s_ff0_i32_b32 now refuses lane-mask sources (exec/vcc/copied masks); test added.

**@⁠tedin7** on GitHub · 2026-11-25 00:57 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2040#discussion_r4688732542) Fixed in 10ec331e (rebased on main, push pending): s_ff0_i32_b32 now refuses lane-mask sources (exec/vcc/copied masks); test added.
Author
Owner

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

Fixed in 10ec331e (rebased on main, push pending): ud and fixed_buffer_word symbols are now accepted as numeric sources; test added.

**@⁠tedin7** on GitHub · 2026-11-25 00:57 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2040#discussion_r4688732733) Fixed in 10ec331e (rebased on main, push pending): ud and fixed_buffer_word symbols are now accepted as numeric sources; test added.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 13:51 UTC · original

Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is.

We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 13:51 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2040#issuecomment-7164401022) Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is. We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here. AI-assisted; commands listed were executed locally.
Author
Owner

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e9e35fc438

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