shader: lower s_bitset0/1_b32 in gfx2hlsl (#2023 Item J) #2630

Merged
SimSalabimse merged 2 commits from upstream-pr/2638 into main 2026-11-26 00:17:03 +00:00
SimSalabimse commented 2026-11-26 00:00:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-26T00:00:44Z.


Change

Part of #2023 Item J (s_bitset1_b32, with the natural pair s_bitset0_b32) in tools/startup/gfx2hlsl.py.

Ordinary vertex/pixel pipelines that only need an in-place scalar bit set or clear were refusing at these SOP1 forms. The lowering matches pixel_aot / #1579:

  • s_bitset0_b32: D = D & ~(1u << (S0 & 31))
  • s_bitset1_b32: D = D | (1u << (S0 & 31))
  • SCC unchanged
  • Lane-mask and descriptor-bearing SGPRs refused
  • Known constant destination + known bit index folds

Claim before coding. Base is main at e3dda42b.

AI-assisted.

Verification

Commit under test: this PR head.

python3 -B tests/startup_gfx2hlsl_s_bitset_check.py
# all ok

python3 -B tests/startup_gfx2hlsl_s_bitcmp_check.py
python3 -B tests/startup_gfx2hlsl_handler_arity_check.py
python3 -B tests/startup_gfx2hlsl_scalar_arity_check.py
python3 -B tests/startup_translator_check.py
python3 -B tests/docs_links_check.py

All passed on Linux (CPU evaluation of the translated text). Windows WARP/hardware draws were not run here; the fixture is device-free.

CTest filter once configured: ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_bitset$' -V.

Evidence and follow-up

  • Hand-assembled SOP1 encodings via disasm_rdna2 / gfx2hlsl.decode; no retail bytes.
  • Negative control: mutating the emitted expression to drop the bit update diverges from the ISA reference.
  • 64-bit s_bitset*_b64 stays refused (out of Item J scope).

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6616312868 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2638). Originally posted by [SimSalabimse](https://github.com/SimSalabimse) on 2026-11-26T00:00:44Z. --- ## Change Part of [#2023](https://github.com/R0Y00/Xbox2Windows/issues/2023) **Item J** (`s_bitset1_b32`, with the natural pair `s_bitset0_b32`) in `tools/startup/gfx2hlsl.py`. Ordinary vertex/pixel pipelines that only need an in-place scalar bit set or clear were refusing at these SOP1 forms. The lowering matches `pixel_aot` / #1579: - `s_bitset0_b32`: `D = D & ~(1u << (S0 & 31))` - `s_bitset1_b32`: `D = D | (1u << (S0 & 31))` - SCC unchanged - Lane-mask and descriptor-bearing SGPRs refused - Known constant destination + known bit index folds [Claim](https://github.com/R0Y00/Xbox2Windows/issues/2023#issuecomment-7178247360) before coding. Base is `main` at `e3dda42b`. AI-assisted. ## Verification Commit under test: this PR head. ```bash python3 -B tests/startup_gfx2hlsl_s_bitset_check.py # all ok python3 -B tests/startup_gfx2hlsl_s_bitcmp_check.py python3 -B tests/startup_gfx2hlsl_handler_arity_check.py python3 -B tests/startup_gfx2hlsl_scalar_arity_check.py python3 -B tests/startup_translator_check.py python3 -B tests/docs_links_check.py ``` All passed on Linux (CPU evaluation of the translated text). Windows WARP/hardware draws were not run here; the fixture is device-free. CTest filter once configured: `ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_bitset$' -V`. ## Evidence and follow-up - Hand-assembled SOP1 encodings via `disasm_rdna2` / `gfx2hlsl.decode`; no retail bytes. - Negative control: mutating the emitted expression to drop the bit update diverges from the ISA reference. - 64-bit `s_bitset*_b64` stays refused (out of Item J scope). ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets.
upstream-sync closed this pull request 2026-11-26 01:01:59 +00:00
tedin7 commented 2026-11-26 01:02:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T00:11:10Z.

Review: COMMENTED


Review of head 8b477af4 (comment only, no approval and no merge).

Duplicate slice (blocking the merge decision). #2420 (open, opened 2026-11-25 16:08Z) already lowers s_bitset0_b32 and s_bitset1_b32 in tools/startup/gfx2hlsl.py for #2023 Item J, with its own test tests/startup_gfx2hlsl_bitset_check.py and the same CMake and windows.yml wiring. This PR covers the same two opcodes. Only one of them can land, and the two add different test file names, so both would also add duplicate test registrations. I leave the choice to @R0Y00. #2420 is currently CONFLICTING with main and this PR is MERGEABLE, which may matter for the decision.

Code (tools/startup/gfx2hlsl.py, scalar_bitset)

  • Semantics match the ISA: D &= ~(1u << (S0 & 31)) and D |= (1u << (S0 & 31)), SCC unchanged, D read before write.
  • Lane masks and sub-range or high SGPRs are refused; constant D with constant S0 folds correctly.
  • No defect found in the lowering itself.

Test gap. tests/startup_gfx2hlsl_s_bitset_check.py evaluates the translated text on the CPU only. For a shader/math lowering we need a real D3D12 WARP GPU readback compared with a CPU reference. The PR states WARP was not run. Please add a WARP readback case (extend the existing WARP shader test suite) before this is merge-ready.

Checks run locally (worktree on the PR head): git diff --stat origin/main...HEAD, diff read for tools/, CMakeLists.txt, .github/, AGENTS.md, and a search for other PRs on the same opcodes (gh pr list --search s_bitset).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6066787672 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2638#pullrequestreview-6066787672). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T00:11:10Z. **Review:** COMMENTED --- Review of head 8b477af4 (comment only, no approval and no merge). **Duplicate slice (blocking the merge decision).** #2420 (open, opened 2026-11-25 16:08Z) already lowers `s_bitset0_b32` and `s_bitset1_b32` in `tools/startup/gfx2hlsl.py` for #2023 Item J, with its own test `tests/startup_gfx2hlsl_bitset_check.py` and the same CMake and `windows.yml` wiring. This PR covers the same two opcodes. Only one of them can land, and the two add different test file names, so both would also add duplicate test registrations. I leave the choice to @R0Y00. #2420 is currently CONFLICTING with main and this PR is MERGEABLE, which may matter for the decision. **Code (tools/startup/gfx2hlsl.py, `scalar_bitset`)** - Semantics match the ISA: `D &= ~(1u << (S0 & 31))` and `D |= (1u << (S0 & 31))`, SCC unchanged, D read before write. - Lane masks and sub-range or high SGPRs are refused; constant D with constant S0 folds correctly. - No defect found in the lowering itself. **Test gap.** `tests/startup_gfx2hlsl_s_bitset_check.py` evaluates the translated text on the CPU only. For a shader/math lowering we need a real D3D12 WARP GPU readback compared with a CPU reference. The PR states WARP was not run. Please add a WARP readback case (extend the existing WARP shader test suite) before this is merge-ready. **Checks run locally** (worktree on the PR head): `git diff --stat origin/main...HEAD`, diff read for `tools/`, `CMakeLists.txt`, `.github/`, `AGENTS.md`, and a search for other PRs on the same opcodes (`gh pr list --search s_bitset`). AI-assisted; commands listed were executed locally.
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!2630
No description provided.