shader: lower s_bitset1_b32 and s_ff1_i32_b32 in gfx2hlsl (Part of #1723) #2021

Closed
tedin7 wants to merge 2 commits from upstream-pr/2028 into main
tedin7 commented 2026-11-24 23:27:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T23:27:06Z.


Part of #1723

What this unblocks: Run 20 census #18 (39/38 pairs).

Branch: x2w-r20-s-bitset-ff1 (commit 4daaa514, local, not pushed).

Changes in tools/startup/gfx2hlsl.py:

  • s_bitset1_b32: D | (1u << (S0 & 31)), SCC unchanged.
  • s_bitset0_b32 (sibling, same path): D & ~(1u << (S0 & 31)), SCC unchanged.
  • s_ff1_i32_b32: S0 == 0u ? 0xffffffffu : firstbitlow(S0), SCC unchanged.
  • The three are word-only: lane masks, exec/vcc destinations, and descriptor data are refused, as for s_pack_hh_b32_b16.

Verification:

  • python3 -I tests/startup_gfx2hlsl_s_bitset_ff1_check.py -> PASS (new test, registered in CMakeLists.txt as startup_gfx2hlsl_s_bitset_ff1).
  • Same test against origin/main tools -> fails with Unsupported: s_bitset1_b32.
  • python3 -I tests/startup_gfx2hlsl_sop2_complement_check.py -> PASS
  • python3 -I tests/startup_gfx2hlsl_vcvt_omod_check.py -> PASS
  • Checked before starting: no s_bitset*/s_ff1 in tools/startup/ on main; open PR #1579 touches only tools/compute_store_aot.py.
  • Not run: Win2025 build and CTest (this host is Linux, Python tests only).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6593494882 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2028). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T23:27:06Z. --- Part of #1723 What this unblocks: Run 20 census #18 (39/38 pairs). Branch: `x2w-r20-s-bitset-ff1` (commit 4daaa514, local, not pushed). Changes in `tools/startup/gfx2hlsl.py`: - `s_bitset1_b32`: `D | (1u << (S0 & 31))`, SCC unchanged. - `s_bitset0_b32` (sibling, same path): `D & ~(1u << (S0 & 31))`, SCC unchanged. - `s_ff1_i32_b32`: `S0 == 0u ? 0xffffffffu : firstbitlow(S0)`, SCC unchanged. - The three are word-only: lane masks, exec/vcc destinations, and descriptor data are refused, as for `s_pack_hh_b32_b16`. Verification: - `python3 -I tests/startup_gfx2hlsl_s_bitset_ff1_check.py` -> PASS (new test, registered in CMakeLists.txt as `startup_gfx2hlsl_s_bitset_ff1`). - Same test against `origin/main` tools -> fails with `Unsupported: s_bitset1_b32`. - `python3 -I tests/startup_gfx2hlsl_sop2_complement_check.py` -> PASS - `python3 -I tests/startup_gfx2hlsl_vcvt_omod_check.py` -> PASS - Checked before starting: no `s_bitset*`/`s_ff1` in `tools/startup/` on main; open PR #1579 touches only `tools/compute_store_aot.py`. - Not run: Win2025 build and CTest (this host is Linux, Python tests only). AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-25 00:05:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:31:59Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4daaa51474

ℹ️ 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:6049096705 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2028#pullrequestreview-6049096705). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:31:59Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `4daaa51474` <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 01:01:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:27:20Z.


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:32:01.771657Z 4daaa51 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7147419231 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2028#issuecomment-7147419231). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:27:20Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"4daaa51474e239de2b57a51135f90c551bc92916","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:32:01.771657Z">2026-11-24T23:32:01.771657Z</relative-time> | `4daaa51` | 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>
chatgpt-codex-connector[bot commented 2026-11-25 01:02:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:31:59Z.

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

@@ -1736,6 +1741,10 @@ def declarations(self):
     's_min_i32': ('uint(min(int({0}), int({1})))', None), 's_max_i32': ('uint(max(int({0}), int({1})))', None),
     's_bfe_u32': ('({0} >> ({1} & 31)) & ((1u << (({1} >> 16) & 127)) - 1)', '$ != 0'),
     's_brev_b32': ('reversebits({0})', None),
+    # s_bitset0/1_b32 read-modify-write the destination: {0} is the old D, {1} is S0; SCC unchanged.
+    's_bitset0_b32': ('({0} & ~(1u << ({1} & 31)))', None), 's_bitset1_b32': ('({0} | (1u << ({1} & 31)))', None),
+    # s_ff1_i32_b32: index of the lowest set bit, -1 when none; SCC unchanged.
+    's_ff1_i32_b32': ('({0} == 0u ? 0xffffffffu : firstbitlow({0}))', None),

P1 Badge Document the expanded startup scalar instruction support

This expands the startup translator's accepted instruction set, but neither README.md nor docs/experiments.md is updated. AGENTS.md explicitly requires a documentation update when a public capability or reproduction command changes. The existing startup scalar documentation covers complement logic and high-halfword packing, but omits these new operations, their word-only restrictions, and the startup_gfx2hlsl_s_bitset_ff1 reproduction command. Update the capability and reproduction documentation, distinguishing the Python-only verification from the unrun Windows/GPU checks.

AGENTS.md reference: AGENTS.md:L209-L210

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688001815 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2028#discussion_r4688001815). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:31:59Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 1747 ~~~~diff @@ -1736,6 +1741,10 @@ def declarations(self): 's_min_i32': ('uint(min(int({0}), int({1})))', None), 's_max_i32': ('uint(max(int({0}), int({1})))', None), 's_bfe_u32': ('({0} >> ({1} & 31)) & ((1u << (({1} >> 16) & 127)) - 1)', '$ != 0'), 's_brev_b32': ('reversebits({0})', None), + # s_bitset0/1_b32 read-modify-write the destination: {0} is the old D, {1} is S0; SCC unchanged. + 's_bitset0_b32': ('({0} & ~(1u << ({1} & 31)))', None), 's_bitset1_b32': ('({0} | (1u << ({1} & 31)))', None), + # s_ff1_i32_b32: index of the lowest set bit, -1 when none; SCC unchanged. + 's_ff1_i32_b32': ('({0} == 0u ? 0xffffffffu : firstbitlow({0}))', None), ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Document the expanded startup scalar instruction support** This expands the startup translator's accepted instruction set, but neither `README.md` nor `docs/experiments.md` is updated. `AGENTS.md` explicitly requires a documentation update when a public capability or reproduction command changes. The existing startup scalar documentation covers complement logic and high-halfword packing, but omits these new operations, their word-only restrictions, and the `startup_gfx2hlsl_s_bitset_ff1` reproduction command. Update the capability and reproduction documentation, distinguishing the Python-only verification from the unrun Windows/GPU checks. AGENTS.md reference: [AGENTS.md:L209-L210](https://github.com/R0Y00/Xbox2Windows/blob/4daaa51474e239de2b57a51135f90c551bc92916/AGENTS.md#L209-L210) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-25 02:01:27 +00:00 (Migrated from github.com)

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

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050168114 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2028#pullrequestreview-6050168114). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:28:30Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-25 02:02:05 +00:00 (Migrated from github.com)

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


Fixed and pushed in da2d757a (docs updated, tests pass).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7149334948 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2028#issuecomment-7149334948). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:13:43Z. --- Fixed and pushed in da2d757a (docs updated, tests pass).
tedin7 commented 2026-11-25 02:02:14 +00:00 (Migrated from github.com)

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

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

@@ -1736,6 +1741,10 @@ def declarations(self):
     's_min_i32': ('uint(min(int({0}), int({1})))', None), 's_max_i32': ('uint(max(int({0}), int({1})))', None),
     's_bfe_u32': ('({0} >> ({1} & 31)) & ((1u << (({1} >> 16) & 127)) - 1)', '$ != 0'),
     's_brev_b32': ('reversebits({0})', None),
+    # s_bitset0/1_b32 read-modify-write the destination: {0} is the old D, {1} is S0; SCC unchanged.
+    's_bitset0_b32': ('({0} & ~(1u << ({1} & 31)))', None), 's_bitset1_b32': ('({0} | (1u << ({1} & 31)))', None),
+    # s_ff1_i32_b32: index of the lowest set bit, -1 when none; SCC unchanged.
+    's_ff1_i32_b32': ('({0} == 0u ? 0xffffffffu : firstbitlow({0}))', None),

Fixed in da2d757a. docs/experiments.md now describes s_bitset0_b32, s_bitset1_b32 and s_ff1_i32_b32, the word-only restrictions, and the startup_gfx2hlsl_s_bitset_ff1 ctest command. It states that only Python verification was run, with no Windows/WARP/GPU run. Verification (Linux): python3 tests/startup_gfx2hlsl_s_bitset_ff1_check.py -> PASS.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688947761 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2028#discussion_r4688947761). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:28:30Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 1747 ~~~~diff @@ -1736,6 +1741,10 @@ def declarations(self): 's_min_i32': ('uint(min(int({0}), int({1})))', None), 's_max_i32': ('uint(max(int({0}), int({1})))', None), 's_bfe_u32': ('({0} >> ({1} & 31)) & ((1u << (({1} >> 16) & 127)) - 1)', '$ != 0'), 's_brev_b32': ('reversebits({0})', None), + # s_bitset0/1_b32 read-modify-write the destination: {0} is the old D, {1} is S0; SCC unchanged. + 's_bitset0_b32': ('({0} & ~(1u << ({1} & 31)))', None), 's_bitset1_b32': ('({0} | (1u << ({1} & 31)))', None), + # s_ff1_i32_b32: index of the lowest set bit, -1 when none; SCC unchanged. + 's_ff1_i32_b32': ('({0} == 0u ? 0xffffffffu : firstbitlow({0}))', None), ~~~~ --- Fixed in da2d757a. docs/experiments.md now describes s_bitset0_b32, s_bitset1_b32 and s_ff1_i32_b32, the word-only restrictions, and the `startup_gfx2hlsl_s_bitset_ff1` ctest command. It states that only Python verification was run, with no Windows/WARP/GPU run. Verification (Linux): `python3 tests/startup_gfx2hlsl_s_bitset_ff1_check.py` -> PASS. AI-assisted; commands listed were executed locally.
RavenCurseBurg commented 2026-11-25 07:01:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T06:12:57Z.


I verified dfc97d6d on Windows x64 with a separate device readback. LLVM 15.0.7 assembled fourteen source-built gfx1013 pixel programs. Each went through this PR's Pipeline.hlsl_ps(), DXC 1.9.2609 and a 4×4 draw. WARP and a physical D3D12 adapter each matched every output component for all fourteen programs. The probes cover indices 0, 31, 32, 37 and 0xffffffff, SGPR source/destination aliasing, zero and high-bit FF1 inputs, and incoming SCC clear/set. Omitting the set or clear, returning zero for FF1 of zero, or inverting the SCC seed produced the expected mismatches on both backends. The existing Python controls also passed.

The standalone reproduction script is one file on top of the reviewed commit. Run python -B tests/startup_sop1_device_probe.py <LLVM-15-bin> <dxc> <offscreen_check> warp, then repeat with hardware. I used the renderer built from upstream ab9a020c.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7154560978 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2028#issuecomment-7154560978). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T06:12:57Z. --- I verified `dfc97d6d` on Windows x64 with a separate device readback. LLVM 15.0.7 assembled fourteen source-built gfx1013 pixel programs. Each went through this PR's `Pipeline.hlsl_ps()`, DXC 1.9.2609 and a 4×4 draw. WARP and a physical D3D12 adapter each matched every output component for all fourteen programs. The probes cover indices 0, 31, 32, 37 and `0xffffffff`, SGPR source/destination aliasing, zero and high-bit FF1 inputs, and incoming SCC clear/set. Omitting the set or clear, returning zero for FF1 of zero, or inverting the SCC seed produced the expected mismatches on both backends. The existing Python controls also passed. The [standalone reproduction script](https://github.com/RavenCurseBurg/Xbox2Windows/blob/d07f35c705b2f2bfae8e493c18100d3876ef03da/tests/startup_sop1_device_probe.py) is one file on top of the reviewed commit. Run `python -B tests/startup_sop1_device_probe.py <LLVM-15-bin> <dxc> <offscreen_check> warp`, then repeat with `hardware`. I used the [renderer built from upstream `ab9a020c`](https://github.com/RavenCurseBurg/Xbox2Windows/actions/runs/45551525537).
tedin7 commented 2026-11-25 12:01:55 +00:00 (Migrated from github.com)

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


Thank you @RavenCurseBurg for the independent device readback at dfc97d6d: fourteen programs matched on WARP and on a physical adapter, with the expected mismatches on the mutations. Recorded as extra evidence for this PR.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7161666918 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2028#issuecomment-7161666918). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T11:54:38Z. --- Thank you @RavenCurseBurg for the independent device readback at `dfc97d6d`: fourteen programs matched on WARP and on a physical adapter, with the expected mismatches on the mutations. Recorded as extra evidence for this PR. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 14:04:27 +00:00
tedin7 commented 2026-11-25 14:05:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:51:40Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7164396462 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2028#issuecomment-7164396462). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T13:51:40Z. --- 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.

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