shader: accept scratch-base and binary16 rounding-mode s_setreg_imm32_b32 writes in pixel_aot #634

Merged
rasptum merged 2 commits from upstream-pr/640 into main 2026-11-22 17:30:02 +00:00
rasptum commented 2026-11-22 17:09:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-22T17:09:09Z.


Change

pixel_aot control-flow validation already lets s_setreg_imm32_b32 through, but lower() rejected every form of it. The fixed-profile archive rescan in docs/experiments.md lists it as the second most common first rejection of the first general profile (2,007 PS records).

s_setreg_imm32_b32 writes hardware state, so this PR accepts it only where the effect on the lowered program is known, and rejects everything else by name.

Accepted:

  • A whole-register write to HW_REG_FLAT_SCR_LO or HW_REG_FLAT_SCR_HI with any 32-bit immediate. These hold the scratch base address. Only scratch_* and flat_* memory instructions and s_getreg_b32 can observe it, and none of them is lowered, so the write changes no result. The controls pin that: each of those readers must still be rejected after the write, so a later PR that lowers one of them has to revisit this.
  • hwreg(HW_REG_MODE, 2, 2) with 0 or 3. LLVM's SIDefines.h names MODE bits 3:2 the rounding mode shared by binary16 and binary64 results (0 nearest even, 3 toward zero). The lowerer tracks the value as state. Entry is taken as nearest even, which the existing v_cvt_f16_f32, v_pk_*_f16 and v_fma_mix*_f16 lowerings already assume. While round toward zero is selected, every binary16 or binary64 form is rejected by name except v_cvt_f32_f16 (exact) and v_cvt_pkrtz_f16_f32 (always truncates).

Rejected, each with a diagnostic that names the line:

  • any other register (STATUS, TRAPSTS, LDS_ALLOC, GPR_ALLOC, IB_STS, SHADER_CYCLES);
  • any other MODE field or width, including the binary32 rounding field, the denormal fields and a whole-register MODE write;
  • MODE[3:2] values 1 and 2 (directed rounding) and anything outside the two-bit field;
  • a partial scratch-base write, and a write between the color export and s_endpgm;
  • v_cvt_f16_f32, v_pk_*_f16, v_fma_mix*_f16, v_dot2_f32_f16, 16-bit interpolation and any other _f16 or _f64 form while round toward zero is selected;
  • s_setreg_b32 and s_getreg_b32, which stay unsupported.

Not done on purpose: a truncating v_cvt_f16_f32. It did not occur under round toward zero in the input I counted (below), and its overflow result on this hardware is not something I can measure, so it stays rejected instead of guessed.

The denormal fields of MODE relate to #312. No write to them occurred in the counted input, and this PR keeps them rejected, so it does not change what #312 and #363 established.

tools/scan_unsupported_shaders.py gets the two matching patterns so its line classifier agrees with the translator. tools/pixel_cb_read.py already skipped hwreg(HW_REG_MODE, 2, 2), 0|3 and is unchanged.

Verification

Environment: Windows 10 Pro 19045, Python 3.13, LLVM 15.0.7 (clang as assembler, llvm-objcopy, LLVM-C.dll), DXC from Windows SDK 10.0.26100.0. Branch based on b03f754. The round trip, coverage check and WARP draw were rerun after the last rebase; the hardware run and the pure-Python checks were last run a few commits earlier.

Command Result
python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <LLVM-C.dll> exit 0
python -B tests/pixel_aot_check.py draw <dxc> <offscreen_check> warp exit 0, WARP 10.0.19041.5794, debug layer enabled, 0 debug errors
python -B tests/pixel_aot_check.py draw <dxc> <offscreen_check> hardware exit 1 at the existing scalar fixture, see below
python -B tests/form_coverage_check.py form coverage checks passed
the 20 pure-Python checks listed in AGENTS.md all exit 0

Hardware run: NVIDIA GeForce RTX 3060, driver 32.0.15.9636, debug layer enabled. The run stops at a pixel_mismatch in the existing scalar fixture (channel 0, expected_bits=3fa0c000 actual_bits=3fa04000). Unmodified efecacf stops at the same fixture with the same bits on this adapter, so it is not caused by this PR, and I am not counting the hardware run as a pass. I can open a separate issue with the details if that is useful. The new check_mode_register_draw runs before that point and passed on this adapter; run on its own it passes on both WARP and the RTX 3060.

The new fixture (mode_program()):

  • opens with both scratch-base writes, widens a half under round toward zero, restores nearest even for two v_cvt_f16_f32 narrowings whose truncated results differ, then selects round toward zero again before a second widening and the pack;
  • is part of the LLVM 15 assemble and disassemble round trip;
  • must translate exactly like the same program with s_nop 0 in place of each of its five writes;
  • is drawn on both backends with two constant sets; a truncated reference in either narrowing channel must report pixel_mismatch.

Negative controls in check_mode_register_controls(): 19 rejected register, field and width spellings; six rejected MODE[3:2] values; the four scratch-base readers; s_setreg_b32 and s_getreg_b32; a write between export and s_endpgm; dropping the nearest-even restore from the fixture; round toward zero before v_cvt_f16_f32 and before v_pk_add_f16; seven further _f16 and _f64 forms under round toward zero. I also checked by hand that adding v_cvt_f16_f32 to the exempt list makes the controls fail.

tests/form_coverage_check.py now requires that the fixture records s_setreg_imm32_b32 and that the register forms are not recorded.

Evidence and follow-up

Limited observation from one local input, counted with a throwaway script on top of resource_inventory.scene_records, pixel_aot.container_code and pixel_aot.disassemble. Counts use linear instruction order, so they are approximate for programs with branches. Of 12,101 PS records, 825 were not decoded by the count.

Observation (PS records) Count
scratch-base pair FLAT_SCR_LO = 0, FLAT_SCR_HI = 0x400 2,011
... of those, pair at the second and third instruction 2,011
... of those, with any scratch_* or flat_* instruction 0
contains hwreg(HW_REG_MODE, 2, 2), 3 4,187
... of those, 16-bit interpolation while 3 is selected 4,187
... of those, a rounding _f16 or _f64 form while 3 is selected 0
contains hwreg(HW_REG_MODE, 2, 2), 0 996
any other register, field or value (all stages) 0

The scratch-base pair also opens 8,011 of 9,282 MS, 837 of 2,236 VS and 387 of 2,689 CS records, again with no scratch or flat access. MS, VS and CS records only ever write MODE[3:2] = 0.

So the 2,007 first rejections match the scratch-base pair, not a floating-point mode write. What this measures: which writes occur in that input. What stays a hypothesis: that entry holds nearest even (the compiler emitting 3 before 16-bit interpolation and 0 before rounding half operations fits LLVM's mode-register pass, but pipeline state was not observed), and anything about title pipeline state or startup.

Effect on the same input, python -B tools/shader_profile_audit.py <archive> --llvm <LLVM-C.dll> at efecacf and with this change: accepted records are unchanged (PS 853, MS 2, CS 13 in both runs). This PR does not make any additional record translate. It removes one first rejection and exposes the next one:

PS first rejection of the first general profile efecacf this change
unsupported s_setreg_imm32_b32 2,011 0
Unresolved constant buffer binding 2,927 4,411
unbound entry SGPR s17 564 754
unbound entry SGPR s14 97 229
unsupported s_mov_b32 662 767
Unbound pixel input v2 at v_cvt_u32_f32_e32 232 304
other reasons, combined 4,755 4,783

No record first stops at one of the new diagnostics. (efecacf gives 2,011 where the rescan text in docs/experiments.md, measured at an earlier commit, says 2,007; I left that text as the historical measurement.)

Follow-ups this does not cover: v_interp_p1ll_f16 and v_interp_p2_f16 (the reason the 4,187 records select round toward zero), a truncating v_cvt_f16_f32 once its overflow result can be established, and branches, which most of the affected records contain.

Overlap: no open PR mentions s_setreg in its diff. #612, #541, #540 and #528 also add lines to the pattern list in tools/scan_unsupported_shaders.py, and #358 edits text next to the scheduling-hint paragraph in docs/experiments.md; both are adjacent-line conflicts at most. #333 listed s_getreg/s_setreg as still open in SOPK.

Refs #312 (context only; the denormal fields stay rejected).

AI-assisted: written with Claude Code, reviewed and run locally before submitting.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6545252068 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/640). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-22T17:09:09Z. --- ## Change `pixel_aot` control-flow validation already lets `s_setreg_imm32_b32` through, but `lower()` rejected every form of it. The fixed-profile archive rescan in `docs/experiments.md` lists it as the second most common first rejection of the first general profile (2,007 PS records). `s_setreg_imm32_b32` writes hardware state, so this PR accepts it only where the effect on the lowered program is known, and rejects everything else by name. Accepted: - A whole-register write to `HW_REG_FLAT_SCR_LO` or `HW_REG_FLAT_SCR_HI` with any 32-bit immediate. These hold the scratch base address. Only `scratch_*` and `flat_*` memory instructions and `s_getreg_b32` can observe it, and none of them is lowered, so the write changes no result. The controls pin that: each of those readers must still be rejected after the write, so a later PR that lowers one of them has to revisit this. - `hwreg(HW_REG_MODE, 2, 2)` with 0 or 3. LLVM's `SIDefines.h` names MODE bits 3:2 the rounding mode shared by binary16 and binary64 results (0 nearest even, 3 toward zero). The lowerer tracks the value as state. Entry is taken as nearest even, which the existing `v_cvt_f16_f32`, `v_pk_*_f16` and `v_fma_mix*_f16` lowerings already assume. While round toward zero is selected, every binary16 or binary64 form is rejected by name except `v_cvt_f32_f16` (exact) and `v_cvt_pkrtz_f16_f32` (always truncates). Rejected, each with a diagnostic that names the line: - any other register (`STATUS`, `TRAPSTS`, `LDS_ALLOC`, `GPR_ALLOC`, `IB_STS`, `SHADER_CYCLES`); - any other MODE field or width, including the binary32 rounding field, the denormal fields and a whole-register MODE write; - MODE[3:2] values 1 and 2 (directed rounding) and anything outside the two-bit field; - a partial scratch-base write, and a write between the color export and `s_endpgm`; - `v_cvt_f16_f32`, `v_pk_*_f16`, `v_fma_mix*_f16`, `v_dot2_f32_f16`, 16-bit interpolation and any other `_f16` or `_f64` form while round toward zero is selected; - `s_setreg_b32` and `s_getreg_b32`, which stay unsupported. Not done on purpose: a truncating `v_cvt_f16_f32`. It did not occur under round toward zero in the input I counted (below), and its overflow result on this hardware is not something I can measure, so it stays rejected instead of guessed. The denormal fields of MODE relate to #312. No write to them occurred in the counted input, and this PR keeps them rejected, so it does not change what #312 and #363 established. `tools/scan_unsupported_shaders.py` gets the two matching patterns so its line classifier agrees with the translator. `tools/pixel_cb_read.py` already skipped `hwreg(HW_REG_MODE, 2, 2), 0|3` and is unchanged. ## Verification Environment: Windows 10 Pro 19045, Python 3.13, LLVM 15.0.7 (`clang` as assembler, `llvm-objcopy`, `LLVM-C.dll`), DXC from Windows SDK 10.0.26100.0. Branch based on `b03f754`. The round trip, coverage check and WARP draw were rerun after the last rebase; the hardware run and the pure-Python checks were last run a few commits earlier. | Command | Result | |---|---| | `python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <LLVM-C.dll>` | exit 0 | | `python -B tests/pixel_aot_check.py draw <dxc> <offscreen_check> warp` | exit 0, WARP 10.0.19041.5794, debug layer enabled, 0 debug errors | | `python -B tests/pixel_aot_check.py draw <dxc> <offscreen_check> hardware` | exit 1 at the existing `scalar` fixture, see below | | `python -B tests/form_coverage_check.py` | `form coverage checks passed` | | the 20 pure-Python checks listed in `AGENTS.md` | all exit 0 | Hardware run: NVIDIA GeForce RTX 3060, driver 32.0.15.9636, debug layer enabled. The run stops at a `pixel_mismatch` in the existing `scalar` fixture (channel 0, `expected_bits=3fa0c000 actual_bits=3fa04000`). Unmodified `efecacf` stops at the same fixture with the same bits on this adapter, so it is not caused by this PR, and I am not counting the hardware run as a pass. I can open a separate issue with the details if that is useful. The new `check_mode_register_draw` runs before that point and passed on this adapter; run on its own it passes on both WARP and the RTX 3060. The new fixture (`mode_program()`): - opens with both scratch-base writes, widens a half under round toward zero, restores nearest even for two `v_cvt_f16_f32` narrowings whose truncated results differ, then selects round toward zero again before a second widening and the pack; - is part of the LLVM 15 assemble and disassemble round trip; - must translate exactly like the same program with `s_nop 0` in place of each of its five writes; - is drawn on both backends with two constant sets; a truncated reference in either narrowing channel must report `pixel_mismatch`. Negative controls in `check_mode_register_controls()`: 19 rejected register, field and width spellings; six rejected MODE[3:2] values; the four scratch-base readers; `s_setreg_b32` and `s_getreg_b32`; a write between export and `s_endpgm`; dropping the nearest-even restore from the fixture; round toward zero before `v_cvt_f16_f32` and before `v_pk_add_f16`; seven further `_f16` and `_f64` forms under round toward zero. I also checked by hand that adding `v_cvt_f16_f32` to the exempt list makes the controls fail. `tests/form_coverage_check.py` now requires that the fixture records `s_setreg_imm32_b32` and that the register forms are not recorded. ## Evidence and follow-up Limited observation from one local input, counted with a throwaway script on top of `resource_inventory.scene_records`, `pixel_aot.container_code` and `pixel_aot.disassemble`. Counts use linear instruction order, so they are approximate for programs with branches. Of 12,101 PS records, 825 were not decoded by the count. | Observation (PS records) | Count | |---|---:| | scratch-base pair `FLAT_SCR_LO = 0`, `FLAT_SCR_HI = 0x400` | 2,011 | | ... of those, pair at the second and third instruction | 2,011 | | ... of those, with any `scratch_*` or `flat_*` instruction | 0 | | contains `hwreg(HW_REG_MODE, 2, 2), 3` | 4,187 | | ... of those, 16-bit interpolation while 3 is selected | 4,187 | | ... of those, a rounding `_f16` or `_f64` form while 3 is selected | 0 | | contains `hwreg(HW_REG_MODE, 2, 2), 0` | 996 | | any other register, field or value (all stages) | 0 | The scratch-base pair also opens 8,011 of 9,282 MS, 837 of 2,236 VS and 387 of 2,689 CS records, again with no scratch or flat access. MS, VS and CS records only ever write MODE[3:2] = 0. So the 2,007 first rejections match the scratch-base pair, not a floating-point mode write. What this measures: which writes occur in that input. What stays a hypothesis: that entry holds nearest even (the compiler emitting 3 before 16-bit interpolation and 0 before rounding half operations fits LLVM's mode-register pass, but pipeline state was not observed), and anything about title pipeline state or startup. Effect on the same input, `python -B tools/shader_profile_audit.py <archive> --llvm <LLVM-C.dll>` at `efecacf` and with this change: accepted records are unchanged (PS 853, MS 2, CS 13 in both runs). This PR does not make any additional record translate. It removes one first rejection and exposes the next one: | PS first rejection of the first general profile | `efecacf` | this change | |---|---:|---:| | `unsupported s_setreg_imm32_b32` | 2,011 | 0 | | `Unresolved constant buffer binding` | 2,927 | 4,411 | | unbound entry SGPR `s17` | 564 | 754 | | unbound entry SGPR `s14` | 97 | 229 | | `unsupported s_mov_b32` | 662 | 767 | | `Unbound pixel input v2 at v_cvt_u32_f32_e32` | 232 | 304 | | other reasons, combined | 4,755 | 4,783 | No record first stops at one of the new diagnostics. (`efecacf` gives 2,011 where the rescan text in `docs/experiments.md`, measured at an earlier commit, says 2,007; I left that text as the historical measurement.) Follow-ups this does not cover: `v_interp_p1ll_f16` and `v_interp_p2_f16` (the reason the 4,187 records select round toward zero), a truncating `v_cvt_f16_f32` once its overflow result can be established, and branches, which most of the affected records contain. Overlap: no open PR mentions `s_setreg` in its diff. #612, #541, #540 and #528 also add lines to the pattern list in `tools/scan_unsupported_shaders.py`, and #358 edits text next to the scheduling-hint paragraph in `docs/experiments.md`; both are adjacent-line conflicts at most. #333 listed `s_getreg`/`s_setreg` as still open in SOPK. Refs #312 (context only; the denormal fields stay rejected). AI-assisted: written with Claude Code, reviewed and run locally before submitting. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:44:06 +00:00
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!634
No description provided.