shader: lower s_setreg_b32 and s_getreg_b32 for the MODE rounding field in pixel_aot #1777

Manually merged
github merged 1 commit from gh-pr/1777/head into gh-pr/1777/base 2026-11-26 23:32:45 +00:00
Owner

@⁠JB2WIN on GitHub · 2026-11-24 18:25 UTC · original
JB2WIN:shader/sopk-setreg → main · +335 −18 · 5 files · 1 commits · merged 2026-11-24 18:38 UTC

Change

tools/pixel_aot.py now lowers two of the five SOPK forms that the gfx1013 coverage still lists as uncovered: s_setreg_b32 and s_getreg_b32. Each is accepted only where its effect is known.

s_setreg_b32 hwreg(...), sN takes the same targets as s_setreg_imm32_b32:

  • MODE[3:2] rounding field: accepted when the SGPR holds a known integer that is exactly 0 (RNE) or 3 (RTZ). It then sets the rounding state the same way the immediate form does, so a following rounding binary16/binary64 form is refused under RTZ and allowed again after a write of RNE.
    • LLVM 15 SIISelLowering.cpp (4354–4417) builds SetMask = WidthMask << Offset, so the hardware takes the low size bits. Even so, a value with higher bits set (for example 0x103 or 0xffffffff) is refused instead of truncated. Values 1 and 2 are refused as before.
  • Whole FLAT_SCR_LO/HI: accepted from any SGPR, because no lowered instruction observes the value (the same reasoning as for the immediate form).
  • Refused: an unknown SGPR for the MODE field, every other register or field, vcc_lo/m0/null sources, immediates and pairs.

s_getreg_b32 sD, hwreg(HW_REG_MODE, 2, 2) is accepted only after the program has written that field itself, with either setreg form. The MODE value at shader entry is only assumed, so a read before any write is refused (MODE rounding is read before the program writes it).

  • Result: the known field value, right-aligned with every other bit zero (0 or 3). It becomes a known scalar constant, so later instructions can use it. LLVM 15 reads a getreg field the same way in SIISelLowering.cpp (3553–3572).
  • Refused: every other register or field, including FLAT_SCR (Unsupported hardware register read).

Masked regions: neither form runs inside one (they are not in REGION_SALU), so the rounding state is tracked in straight-line code. A control shows that a write before a skip, followed by a read after the join, works.

Spelling and encoding (LLVM 15.0.7, gfx1013): s_setreg_b32 hwreg(HW_REG_MODE, 2, 2), s0 is 810880b9 and s_getreg_b32 s0, hwreg(HW_REG_MODE, 2, 2) is 810800b9. A whole FLAT_SCR register prints as hwreg(HW_REG_FLAT_SCR_LO). The field encoding follows SIDefines.h; the operand order follows SOPInstructions.td (878–899).

Not covered here: s_call_b64 and s_subvector_loop_begin/end would need call and subvector-loop models, which pixel_aot does not have. form_coverage_check.py now asserts that they stay refused.

Changed controls: these controls already expected a refusal. They still refuse the same input; only the expected message is more specific now:

  • getreg of FLAT_SCR_LO
  • setreg from an unbound SGPR
  • getreg before any write
  • setreg of MODE (6, 2)

form_coverage_check.py moves s_getreg_b32 out of the refused-neighbour list and counts both forms as covered.

Test

New mode draw-sopk-hwreg, registered as pixel_aot_sopk_hwreg_hardware and _warp (60 s timeout, skip code 77, its own FORM_COVERAGE_RECORD). The program is part of the LLVM 15 round trip, and a binary check pins the encodings above.

  • Draw: reads back the field after setreg writes of 0 and 3 through the integer readback and compares bit for bit.
  • Wrong references: five wrong references, among them the field not right-aligned and 3 instead of 0, must report pixel_mismatch.
  • Rejection controls: unknown SGPR, values 1/2/0x103, other registers and fields, getreg before setreg, malformed operands.
  • Mutations: each of these turns the controls red: accepting getreg before setreg, accepting an unknown SGPR, and a field that is not right-aligned.
  • Against main: with main's tools/pixel_aot.py the mode fails with Unsupported instruction 21: s_setreg_b32 hwreg(HW_REG_MODE, 2, 2), s48.

The semantics come from LLVM 15. They are not checked against the ISA document and not measured on a console.

tools/scan_unsupported_shaders.py is unchanged. A static scan cannot know the SGPR value, so it keeps reporting the register forms as unsupported.

On commit a1011264 (rebased on f58d2425), with an NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), WARP 10.0.26100.9818, Windows 11 build 26200 and the debug layer unavailable:

ctest --preset dev --no-tests=error -R '^pixel_aot_sopk_hwreg_' -V   # 2/2 passed, none skipped
ctest --preset dev --no-tests=error                                 # 1093/1093 passed; 25 capability skips, none from this change

The pure checks and the LLVM 15.0.7 binary round trip pass.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠JB2WIN** on GitHub · 2026-11-24 18:25 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1777) `JB2WIN:shader/sopk-setreg` → `main` · +335 −18 · 5 files · 1 commits · merged 2026-11-24 18:38 UTC ## Change `tools/pixel_aot.py` now lowers two of the five SOPK forms that the gfx1013 coverage still lists as uncovered: `s_setreg_b32` and `s_getreg_b32`. Each is accepted only where its effect is known. **`s_setreg_b32 hwreg(...), sN`** takes the same targets as `s_setreg_imm32_b32`: - **MODE[3:2] rounding field:** accepted when the SGPR holds a known integer that is exactly 0 (RNE) or 3 (RTZ). It then sets the rounding state the same way the immediate form does, so a following rounding binary16/binary64 form is refused under RTZ and allowed again after a write of RNE. - LLVM 15 `SIISelLowering.cpp` (4354–4417) builds `SetMask = WidthMask << Offset`, so the hardware takes the low `size` bits. Even so, a value with higher bits set (for example `0x103` or `0xffffffff`) is refused instead of truncated. Values 1 and 2 are refused as before. - **Whole FLAT_SCR_LO/HI:** accepted from any SGPR, because no lowered instruction observes the value (the same reasoning as for the immediate form). - **Refused:** an unknown SGPR for the MODE field, every other register or field, `vcc_lo`/`m0`/`null` sources, immediates and pairs. **`s_getreg_b32 sD, hwreg(HW_REG_MODE, 2, 2)`** is accepted only after the program has written that field itself, with either setreg form. The MODE value at shader entry is only assumed, so a read before any write is refused (`MODE rounding is read before the program writes it`). - **Result:** the known field value, right-aligned with every other bit zero (0 or 3). It becomes a known scalar constant, so later instructions can use it. LLVM 15 reads a getreg field the same way in `SIISelLowering.cpp` (3553–3572). - **Refused:** every other register or field, including FLAT_SCR (`Unsupported hardware register read`). **Masked regions:** neither form runs inside one (they are not in `REGION_SALU`), so the rounding state is tracked in straight-line code. A control shows that a write before a skip, followed by a read after the join, works. **Spelling and encoding** (LLVM 15.0.7, gfx1013): `s_setreg_b32 hwreg(HW_REG_MODE, 2, 2), s0` is `810880b9` and `s_getreg_b32 s0, hwreg(HW_REG_MODE, 2, 2)` is `810800b9`. A whole FLAT_SCR register prints as `hwreg(HW_REG_FLAT_SCR_LO)`. The field encoding follows `SIDefines.h`; the operand order follows `SOPInstructions.td` (878–899). **Not covered here:** `s_call_b64` and `s_subvector_loop_begin/end` would need call and subvector-loop models, which pixel_aot does not have. `form_coverage_check.py` now asserts that they stay refused. **Changed controls:** these controls already expected a refusal. They still refuse the same input; only the expected message is more specific now: - getreg of FLAT_SCR_LO - setreg from an unbound SGPR - getreg before any write - setreg of MODE (6, 2) `form_coverage_check.py` moves `s_getreg_b32` out of the refused-neighbour list and counts both forms as covered. ## Test New mode `draw-sopk-hwreg`, registered as `pixel_aot_sopk_hwreg_hardware` and `_warp` (60 s timeout, skip code 77, its own `FORM_COVERAGE_RECORD`). The program is part of the LLVM 15 round trip, and a binary check pins the encodings above. - **Draw:** reads back the field after setreg writes of 0 and 3 through the integer readback and compares bit for bit. - **Wrong references:** five wrong references, among them the field not right-aligned and 3 instead of 0, must report `pixel_mismatch`. - **Rejection controls:** unknown SGPR, values 1/2/`0x103`, other registers and fields, getreg before setreg, malformed operands. - **Mutations:** each of these turns the controls red: accepting getreg before setreg, accepting an unknown SGPR, and a field that is not right-aligned. - **Against `main`:** with `main`'s `tools/pixel_aot.py` the mode fails with `Unsupported instruction 21: s_setreg_b32 hwreg(HW_REG_MODE, 2, 2), s48`. The semantics come from LLVM 15. They are not checked against the ISA document and not measured on a console. `tools/scan_unsupported_shaders.py` is unchanged. A static scan cannot know the SGPR value, so it keeps reporting the register forms as unsupported. On commit `a1011264` (rebased on `f58d2425`), with an NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), WARP 10.0.26100.9818, Windows 11 build 26200 and the debug layer unavailable: ```powershell ctest --preset dev --no-tests=error -R '^pixel_aot_sopk_hwreg_' -V # 2/2 passed, none skipped ctest --preset dev --no-tests=error # 1093/1093 passed; 25 capability skips, none from this change ``` The pure checks and the LLVM 15.0.7 binary round trip pass. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
s_setreg_b32 takes the targets of s_setreg_imm32_b32: the MODE[3:2]
rounding field from an SGPR that holds a known 0 or 3, and whole
FLAT_SCR_LO/HI writes from any SGPR. s_getreg_b32 reads only
MODE[3:2], and only after the program has written it, so the result is
the known value right-aligned. New mode draw-sopk-hwreg; every other
register, field, value and an unknown SGPR stay refused.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:32:44 +00:00
github manually merged commit a101126422 into gh-pr/1777/base 2026-11-26 23:32:45 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 18:38 UTC · original · reviewed

Dual-platform peer review at head_sha: a101126422224c66d38084037d5a20f475bbb515

Findings

No blocking issues (0 P1, 0 P2).

  • tools/pixel_aot.py: lowers s_setreg_b32 for hwreg(HW_REG_MODE, 2, 2) (requiring a bound, non-pending, non-conditional SGPR holding exact integer 0 or 3, refusing 1, 2, upper bits, non-integer/unknown SGPRs, and special registers) and whole HW_REG_FLAT_SCR_LO/HI (any bound SGPR), and lowers s_getreg_b32 for hwreg(HW_REG_MODE, 2, 2) only after a prior write in the program (returning right-aligned 0 or 3 into scalar[dst] and scalar_mask[dst], with TrackedScalar.__setitem__ clearing conditional). Both are excluded from masked regions, uniform skip blocks, and post-export code, and added to _check_two_exits.
  • tests/pixel_aot_check.py, tests/form_coverage_check.py, CMakeLists.txt, docs/experiments.md: cover static lowering/refusal controls, LLVM assemble/disassemble encoding and round-trip checks, WARP draw with 5 negative-reference mismatch controls, +2 gfx1013 form coverage accounting, test-only CMake registration (pixel_aot_sopk_hwreg_${adapter}), and clean-room neutral docs.

Verification

  • Linux:
    • git diff --check origin/main...HEAD: clean.
    • python3 -B tests/docs_links_check.py: passed (17 Markdown files, 366 links).
    • python3 -B tests/bidi_controls_check.py: passed (1302 tracked files).
    • python3 -B tests/pixel_aot_check.py: passed.
    • check_sopk_hwreg_binary + SOPK_HWREG_BODY assemble/disassemble round-trip with llvm-mc-19, llvm-objcopy-19, /usr/lib/llvm-19/lib/libLLVM-19.so: passed (40 instructions).
    • python3 -B tests/form_coverage_check.py: passed.
    • python3 -B tests/rdna2_tools_check.py: passed (148 tests, 18 skipped).
    • Local mutation checks (each restored via git checkout -- .):
      1. Changed s_getreg_b32 assignment from mode_rounding to mode_rounding << 2 -> tests/pixel_aot_check.py failed in check_sopk_hwreg_controls (exit 1).
      2. Bypassed if mode_rounding is None: guard with if False: -> tests/pixel_aot_check.py failed in check_mode_register_controls (exit 1).
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Python checks: tests/form_coverage_check.py ok (17.18s).
    • Debug (--preset dev): ctest --preset dev -R '^(pixel_aot_sopk_hwreg_warp|pixel_aot_warp|rdna2_tools_check)$' --parallel 6 --no-tests=error --output-on-failure: 3/3 passed (13.89s: pixel_aot_sopk_hwreg_warp 4.64s, rdna2_tools_check 9.82s, pixel_aot_warp 13.82s).
    • Release /O2 (--preset release): ctest --preset release -R '^(pixel_aot_sopk_hwreg_warp|pixel_aot_warp|rdna2_tools_check)$' --parallel 6 --no-tests=error --output-on-failure: 3/3 passed (14.09s: pixel_aot_sopk_hwreg_warp 3.86s, rdna2_tools_check 10.88s, pixel_aot_warp 14.00s).

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 18:38 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1777#pullrequestreview-6045179220) · **reviewed** Dual-platform peer review at `head_sha`: `a101126422224c66d38084037d5a20f475bbb515` ### Findings No blocking issues (0 P1, 0 P2). - `tools/pixel_aot.py`: lowers `s_setreg_b32` for `hwreg(HW_REG_MODE, 2, 2)` (requiring a bound, non-pending, non-conditional SGPR holding exact integer `0` or `3`, refusing `1`, `2`, upper bits, non-integer/unknown SGPRs, and special registers) and whole `HW_REG_FLAT_SCR_LO`/`HI` (any bound SGPR), and lowers `s_getreg_b32` for `hwreg(HW_REG_MODE, 2, 2)` only after a prior write in the program (returning right-aligned `0` or `3` into `scalar[dst]` and `scalar_mask[dst]`, with `TrackedScalar.__setitem__` clearing `conditional`). Both are excluded from masked regions, uniform skip blocks, and post-export code, and added to `_check_two_exits`. - `tests/pixel_aot_check.py`, `tests/form_coverage_check.py`, `CMakeLists.txt`, `docs/experiments.md`: cover static lowering/refusal controls, LLVM assemble/disassemble encoding and round-trip checks, WARP draw with 5 negative-reference mismatch controls, +2 `gfx1013` form coverage accounting, test-only CMake registration (`pixel_aot_sopk_hwreg_${adapter}`), and clean-room neutral docs. ### Verification - **Linux**: - `git diff --check origin/main...HEAD`: clean. - `python3 -B tests/docs_links_check.py`: passed (17 Markdown files, 366 links). - `python3 -B tests/bidi_controls_check.py`: passed (1302 tracked files). - `python3 -B tests/pixel_aot_check.py`: passed. - `check_sopk_hwreg_binary` + `SOPK_HWREG_BODY` assemble/disassemble round-trip with `llvm-mc-19`, `llvm-objcopy-19`, `/usr/lib/llvm-19/lib/libLLVM-19.so`: passed (40 instructions). - `python3 -B tests/form_coverage_check.py`: passed. - `python3 -B tests/rdna2_tools_check.py`: passed (148 tests, 18 skipped). - **Local mutation checks** (each restored via `git checkout -- .`): 1. Changed `s_getreg_b32` assignment from `mode_rounding` to `mode_rounding << 2` -> `tests/pixel_aot_check.py` failed in `check_sopk_hwreg_controls` (exit 1). 2. Bypassed `if mode_rounding is None:` guard with `if False:` -> `tests/pixel_aot_check.py` failed in `check_mode_register_controls` (exit 1). - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)**: - Python checks: `tests/form_coverage_check.py` ok (`17.18s`). - **Debug (`--preset dev`)**: `ctest --preset dev -R '^(pixel_aot_sopk_hwreg_warp|pixel_aot_warp|rdna2_tools_check)$' --parallel 6 --no-tests=error --output-on-failure`: **3/3 passed** (`13.89s`: `pixel_aot_sopk_hwreg_warp` `4.64s`, `rdna2_tools_check` `9.82s`, `pixel_aot_warp` `13.82s`). - **Release `/O2` (`--preset release`)**: `ctest --preset release -R '^(pixel_aot_sopk_hwreg_warp|pixel_aot_warp|rdna2_tools_check)$' --parallel 6 --no-tests=error --output-on-failure`: **3/3 passed** (`14.09s`: `pixel_aot_sopk_hwreg_warp` `3.86s`, `rdna2_tools_check` `10.88s`, `pixel_aot_warp` `14.00s`). AI-assisted; commands listed were executed locally.
This discussion has been locked. Commenting is limited to contributors.
No description provided.