shader: lower s_denorm_mode as a tracked MODE write #3651

Merged
lambirou merged 4 commits from upstream-pr/3651 into main 2026-12-02 23:53:45 +00:00
lambirou commented 2026-11-30 21:24:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-30T21:24:59Z.


Problem

gfx1013 lists SOPP s_denorm_mode in both coverage references, but pixel_aot refused it and did not track MODE[7:4]. A shader that writes the denormal mode therefore could not be translated, and the form stayed unobserved in gfx1013 and gfx1030. No open pull request covered it.

Change

pixel_aot now lowers s_denorm_mode as a MODE[7:4] write:

  • LLVM 15.0.7 encodes it as SOPP opcode 0x25 with SIMM16[3:0]: bfa50000 through bfa5000f. The disassembler prints the 16 low values in decimal (s_denorm_mode 15) and wider immediates in hex (s_denorm_mode 0x100, s_denorm_mode 0xffff).
  • MODE[5:4] is the binary32 field and MODE[7:6] the binary16/binary64 field. Each two-bit value is 0 flush input and output, 1 allow input and flush output, 2 flush input and allow output, 3 preserve both.
  • All 16 four-bit values are tracked. s_getreg_b32 of hwreg(HW_REG_MODE, 4, 4), hwreg(HW_REG_MODE, 4, 2) or hwreg(HW_REG_MODE, 6, 2) reads the whole field or a subfield after the program writes it. s_setreg_imm32_b32 and s_setreg_b32 write the same fields (their denormal targets accept the preserve values). s_round_mode and the denormal field are disjoint, and the last write wins.
  • Only preserve is modelled for floating-point operations. A binary32, binary16 or binary64 operation whose relevant field is not 3 is refused by type, with the mode value and name in the message. A mixed form such as v_cvt_f32_f16 requires both fields and is refused conservatively if either is not preserve. The existing half_denorm="preserve" declaration is still required for binary16 lowerings.
  • Malformed operands, non-LLVM-15 hex or padded spellings, an immediate wider than SIMM16[3:0], a write after the colour export, a masked region and a uniform skip block are refused with distinct messages.
  • The CTest registrations are in tests/cmake/sopp_denorm_mode.cmake, auto-included by CMakeLists.txt as documented in tests/cmake/README.md: pixel_aot_sopp_denorm_mode_hardware and pixel_aot_sopp_denorm_mode_warp, each with its own FORM_COVERAGE_RECORD.

The controls cover every value, the subfield reads, the s_setreg and s_round_mode interactions, the float-operation gates and the refusals. The draw writes s_denorm_mode 15, reads the whole field, writes s_round_mode 0xc, reads it again, writes the binary32 and binary16/binary64 subfields with both s_setreg forms, reads each, mixes constant-buffer words and exports through the lossless R32G32B32A32_UINT target. Four wrong references must each report pixel_mismatch.

Verification

Run from the branch at a208d311:

python -B tests/pixel_aot_check.py
python -B tests/form_coverage_check.py
python -B tests/rdna2_tools_check.py
cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^(pixel_aot_sopk_hwreg|pixel_aot_sopp_)' -V

Results:

  • pixel_aot_check.py: pass (all controls, including the new check_sopp_denorm_mode_controls).
  • form_coverage_check.py: pass. The same check pins exactly one new form and measures gfx1013 1145 -> 1146 and gfx1030 1136 -> 1137, both changed only by SOPP s_denorm_mode.
  • rdna2_tools_check.py: 161 tests, 19 skips. The skips are the LLVM-dependent subtests on this Windows host; the relevant scanner checks ran and passed.
  • LLVM 15.0.7 binary check: pass, including the s_denorm_mode encodings, both printed spellings, the s_setreg/s_getreg encodings and the draw body round trip. On this Windows host the same binary path was run with LLVM 15.0.7 clang -cc1as as the assembler and LLVM-C.dll as the disassembler; CI uses llvm-mc-15.
  • Full cmake --build --preset dev: pass.
  • ctest for pixel_aot_sopk_hwreg_* and pixel_aot_sopp_*: 6/6 passed. The new hardware test passed on an AMD Radeon RX 9060 XT (driver 32.0.32029.2010), Windows 11 build 26300; the WARP test passed on WARP. The existing sopk_hwreg and s_round_mode draws also passed after the shared MODE changes.
  • docs_links_check.py: 192 Markdown files, 745 links, pass.

Limits

The console's initial MODE value and its denormal behavior are not measured. The draw checks the translator's tracked value through s_getreg_b32, not the console's MODE register. The entry state for binary16 lowerings still comes from the explicit half_denorm="preserve" declaration. Non-preserving modes are tracked as state but no floating-point operation is lowered under them; s_setreg denormal targets accept only the preserving values, while s_denorm_mode can write any of the 16 values and a later float operation is refused if its field is not preserve. Mixed-precision operations are handled conservatively.

Refs #312.

AI-assisted: yes.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5574038198 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3651). Originally posted by [lambirou](https://github.com/lambirou) on 2026-11-30T21:24:59Z. --- ## Problem gfx1013 lists SOPP s_denorm_mode in both coverage references, but pixel_aot refused it and did not track MODE[7:4]. A shader that writes the denormal mode therefore could not be translated, and the form stayed unobserved in gfx1013 and gfx1030. No open pull request covered it. ## Change pixel_aot now lowers s_denorm_mode as a MODE[7:4] write: - LLVM 15.0.7 encodes it as SOPP opcode 0x25 with SIMM16[3:0]: bfa50000 through bfa5000f. The disassembler prints the 16 low values in decimal (s_denorm_mode 15) and wider immediates in hex (s_denorm_mode 0x100, s_denorm_mode 0xffff). - MODE[5:4] is the binary32 field and MODE[7:6] the binary16/binary64 field. Each two-bit value is 0 flush input and output, 1 allow input and flush output, 2 flush input and allow output, 3 preserve both. - All 16 four-bit values are tracked. s_getreg_b32 of hwreg(HW_REG_MODE, 4, 4), hwreg(HW_REG_MODE, 4, 2) or hwreg(HW_REG_MODE, 6, 2) reads the whole field or a subfield after the program writes it. s_setreg_imm32_b32 and s_setreg_b32 write the same fields (their denormal targets accept the preserve values). s_round_mode and the denormal field are disjoint, and the last write wins. - Only preserve is modelled for floating-point operations. A binary32, binary16 or binary64 operation whose relevant field is not 3 is refused by type, with the mode value and name in the message. A mixed form such as v_cvt_f32_f16 requires both fields and is refused conservatively if either is not preserve. The existing half_denorm="preserve" declaration is still required for binary16 lowerings. - Malformed operands, non-LLVM-15 hex or padded spellings, an immediate wider than SIMM16[3:0], a write after the colour export, a masked region and a uniform skip block are refused with distinct messages. - The CTest registrations are in tests/cmake/sopp_denorm_mode.cmake, auto-included by CMakeLists.txt as documented in tests/cmake/README.md: pixel_aot_sopp_denorm_mode_hardware and pixel_aot_sopp_denorm_mode_warp, each with its own FORM_COVERAGE_RECORD. The controls cover every value, the subfield reads, the s_setreg and s_round_mode interactions, the float-operation gates and the refusals. The draw writes s_denorm_mode 15, reads the whole field, writes s_round_mode 0xc, reads it again, writes the binary32 and binary16/binary64 subfields with both s_setreg forms, reads each, mixes constant-buffer words and exports through the lossless R32G32B32A32_UINT target. Four wrong references must each report pixel_mismatch. ## Verification Run from the branch at a208d311: python -B tests/pixel_aot_check.py python -B tests/form_coverage_check.py python -B tests/rdna2_tools_check.py cmake --preset dev cmake --build --preset dev ctest --preset dev --no-tests=error -R '^(pixel_aot_sopk_hwreg|pixel_aot_sopp_)' -V Results: - pixel_aot_check.py: pass (all controls, including the new check_sopp_denorm_mode_controls). - form_coverage_check.py: pass. The same check pins exactly one new form and measures gfx1013 1145 -> 1146 and gfx1030 1136 -> 1137, both changed only by SOPP s_denorm_mode. - rdna2_tools_check.py: 161 tests, 19 skips. The skips are the LLVM-dependent subtests on this Windows host; the relevant scanner checks ran and passed. - LLVM 15.0.7 binary check: pass, including the s_denorm_mode encodings, both printed spellings, the s_setreg/s_getreg encodings and the draw body round trip. On this Windows host the same binary path was run with LLVM 15.0.7 clang -cc1as as the assembler and LLVM-C.dll as the disassembler; CI uses llvm-mc-15. - Full cmake --build --preset dev: pass. - ctest for pixel_aot_sopk_hwreg_* and pixel_aot_sopp_*: 6/6 passed. The new hardware test passed on an AMD Radeon RX 9060 XT (driver 32.0.32029.2010), Windows 11 build 26300; the WARP test passed on WARP. The existing sopk_hwreg and s_round_mode draws also passed after the shared MODE changes. - docs_links_check.py: 192 Markdown files, 745 links, pass. ## Limits The console's initial MODE value and its denormal behavior are not measured. The draw checks the translator's tracked value through s_getreg_b32, not the console's MODE register. The entry state for binary16 lowerings still comes from the explicit half_denorm="preserve" declaration. Non-preserving modes are tracked as state but no floating-point operation is lowered under them; s_setreg denormal targets accept only the preserving values, while s_denorm_mode can write any of the 16 values and a later float operation is refused if its field is not preserve. Mixed-precision operations are handled conservatively. Refs #312. AI-assisted: yes.
lukaslw-lab commented 2026-12-01 02:37:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-01T02:37:20Z.

Review: APPROVED


Reviewed fd5dee74 by reading the diff; not built or run.

Verdict: approve. MODE[7:4] is tracked straight-line, and every float op is gated on its field. No MUST, no SHOULD.

  • NIT The lower() docstring says the s_setreg forms of MODE[7:4] accept "every four-bit value" as a write (tools/pixel_aot.py:4493-4495), and the header comment says "a write may set any of the 16 values" (:735-736). Only s_denorm_mode does that. Both s_setreg paths refuse anything other than preserve (:4862, :4925), and the tests pin that refusal (hwreg(HW_REG_MODE, 4, 4), 14 → "Unsupported denormal mode"). The wording should say so.
  • Checked, no finding:
    • The SIMM16[1:0] → binary32 / [3:2] → binary16·64 split and the four value names match LLVM's FP_DENORM_* encoding.
    • The gate (:4972-4979) runs after every MODE-handling continue and before any ALU lowering, so a float op cannot bypass it. The early continues in the loop are branch/join bookkeeping only. A mnemonic match on _f32/_f16/_f64 (plus fma_mix) over-gates moves like v_interp_mov_f32, which is safe.
    • Straight-line tracking is sufficient: a uniform skip block admits only vector ALU and s_nop, and a masked region only the listed SALU forms. So neither s_denorm_mode nor s_setreg can sit on one path of a join and leave a path-dependent mode.
    • s_getreg_b32 of a field is refused until the program writes it, so the assumed entry value is never reported as fact.
    • The new CMake fragment only registers the pixel_aot_sopp_denorm_mode_{hardware,warp} tests (skip 77).

Tests: the pixel_aot_check.py controls prove all 16 s_denorm_mode values, the per-field refusal at the first float op, the s_setreg/s_getreg round trips, the spelling refusals and the LLVM 15 encodings. CI ran pixel_aot_check.py, form_coverage_check.py and rdna2_tools_check.py at this head. The draw tests are outside the pr filter.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6124179108 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3651#pullrequestreview-6124179108). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-01T02:37:20Z. **Review:** APPROVED --- Reviewed `fd5dee74` by reading the diff; not built or run. **Verdict: approve.** MODE[7:4] is tracked straight-line, and every float op is gated on its field. No MUST, no SHOULD. - **NIT** The `lower()` docstring says the s_setreg forms of MODE[7:4] accept "every four-bit value" as a write (`tools/pixel_aot.py:4493-4495`), and the header comment says "a write may set any of the 16 values" (`:735-736`). Only `s_denorm_mode` does that. Both s_setreg paths refuse anything other than preserve (`:4862`, `:4925`), and the tests pin that refusal (`hwreg(HW_REG_MODE, 4, 4), 14` → "Unsupported denormal mode"). The wording should say so. - Checked, no finding: - The SIMM16[1:0] → binary32 / [3:2] → binary16·64 split and the four value names match LLVM's `FP_DENORM_*` encoding. - The gate (`:4972-4979`) runs after every MODE-handling `continue` and before any ALU lowering, so a float op cannot bypass it. The early `continue`s in the loop are branch/join bookkeeping only. A mnemonic match on `_f32/_f16/_f64` (plus `fma_mix`) over-gates moves like `v_interp_mov_f32`, which is safe. - Straight-line tracking is sufficient: a uniform skip block admits only vector ALU and `s_nop`, and a masked region only the listed SALU forms. So neither `s_denorm_mode` nor `s_setreg` can sit on one path of a join and leave a path-dependent mode. - `s_getreg_b32` of a field is refused until the program writes it, so the assumed entry value is never reported as fact. - The new CMake fragment only registers the `pixel_aot_sopp_denorm_mode_{hardware,warp}` tests (skip 77). Tests: the `pixel_aot_check.py` controls prove all 16 `s_denorm_mode` values, the per-field refusal at the first float op, the s_setreg/s_getreg round trips, the spelling refusals and the LLVM 15 encodings. CI ran `pixel_aot_check.py`, `form_coverage_check.py` and `rdna2_tools_check.py` at this head. The draw tests are outside the `pr` filter.
R0Y00 commented 2026-12-02 05:45:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T05:45:41Z.

Review: COMMENTED


The trial merge conflicts in tests/pixel_aot_check.py: the main SOPP terminal checks and the new denorm-mode checks occupy the same registration sites. Please retain both in the controls, binary and draw selections, and rerun ^(pixel_aot_sopk_hwreg|pixel_aot_sopp_) on the updated head. The older approval covers fd5dee74.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6145407119 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3651#pullrequestreview-6145407119). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T05:45:41Z. **Review:** COMMENTED --- The trial merge conflicts in `tests/pixel_aot_check.py`: the main SOPP terminal checks and the new denorm-mode checks occupy the same registration sites. Please retain both in the controls, binary and draw selections, and rerun `^(pixel_aot_sopk_hwreg|pixel_aot_sopp_)` on the updated head. The older approval covers `fd5dee74`.
R0Y00 commented 2026-12-02 19:02:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T19:02:58Z.

Review: APPROVED


Reviewed ab295a02 on the updated branch. The conflict resolution retains main's terminal SOPP gate. The draw checks exercise denorm preservation and flushing; MODE-dependent reads retain the gate when the relevant state is unknown. Independent Windows 11 build 26300 / MSVC Debug ctest --preset dev --no-tests=error -V -j 1 -R '^pixel_aot_sopp_denorm_mode_(warp|hardware)$' passed 2/2, with WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 for the GPU fixtures.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6157023947 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3651#pullrequestreview-6157023947). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T19:02:58Z. **Review:** APPROVED --- Reviewed ab295a02 on the updated branch. The conflict resolution retains main's terminal SOPP gate. The draw checks exercise denorm preservation and flushing; MODE-dependent reads retain the gate when the relevant state is unknown. Independent Windows 11 build 26300 / MSVC Debug `ctest --preset dev --no-tests=error -V -j 1 -R '^pixel_aot_sopp_denorm_mode_(warp|hardware)$'` passed 2/2, with WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 for the GPU fixtures.
R0Y00 commented 2026-12-02 19:05:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T19:05:11Z.

Review: COMMENTED


The reviewed revision passed both focused draws. After #3605 and #3675 landed, a trial merge into 521318af conflicts in docs/experiments.md and tests/pixel_aot_check.py. Please retain the f16 pack/SDWA and subvector registrations and their coverage entries alongside the denorm controls, then rerun the Windows check on the updated head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6157057427 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3651#pullrequestreview-6157057427). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T19:05:11Z. **Review:** COMMENTED --- The reviewed revision passed both focused draws. After #3605 and #3675 landed, a trial merge into `521318af` conflicts in `docs/experiments.md` and `tests/pixel_aot_check.py`. Please retain the f16 pack/SDWA and subvector registrations and their coverage entries alongside the denorm controls, then rerun the Windows check on the updated head.
R0Y00 commented 2026-12-02 23:53:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T23:53:03Z.

Review: APPROVED


Re-reviewed 677db1ca. The MODE field split, last-write rule and conservative non-preserve refusals remain intact after the branch update. On Windows, python -B tests/pixel_aot_check.py and python -B tests/form_coverage_check.py both passed. I also ran the exact head's draw-sopp-denorm-mode script against the source-built offscreen runner on inbox WARP and RTX 4060 Laptop, both exit 0 with the four wrong-reference controls checked. The trial merge with main 1c4601ff was clean and Windows, Linux Python and gfx1013 fixture CI passed at this head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6161189271 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3651#pullrequestreview-6161189271). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T23:53:03Z. **Review:** APPROVED --- Re-reviewed `677db1ca`. The MODE field split, last-write rule and conservative non-preserve refusals remain intact after the branch update. On Windows, `python -B tests/pixel_aot_check.py` and `python -B tests/form_coverage_check.py` both passed. I also ran the exact head's `draw-sopp-denorm-mode` script against the source-built offscreen runner on inbox WARP and RTX 4060 Laptop, both exit 0 with the four wrong-reference controls checked. The trial merge with `main` `1c4601ff` was clean and Windows, Linux Python and gfx1013 fixture CI passed at this head.
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!3651
No description provided.