shader: admit s_nop and satisfied waits in pixel_aot masked regions #1016

Merged
MasterDomino merged 3 commits from upstream-pr/1023 into main 2026-11-23 22:27:22 +00:00
MasterDomino commented 2026-11-23 21:52:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-23T21:52:46Z.


Refs #987

Stage 1 as approved in #987: s_nop and waits whose counters are already satisfied in the tracked state may sit inside a masked region, under either opener, with or without the s_cbranch_execz skip. Scalar ALU (stage 2) and scalar loads stay out.

Change

tools/pixel_aot.py, region check only:

  • s_nop <imm> is admitted.
  • A wait is admitted only if every counter it names has nothing outstanding:
    • vmcnt: sample_dest is empty (no sample, title or scratch load outstanding);
    • lgkmcnt: pending is empty (no scalar load outstanding);
    • expcnt: never busy, because only s_endpgm may follow an export;
    • vscnt: refused once any scratch store has been lowered, because the store counter is not tracked.
  • Loads leave sample_dest and pending only through a wait, and overwriting an outstanding destination is already refused. So an empty set means nothing is outstanding, and the admitted wait resolves nothing whether the wave runs or skips it.
  • A wait that names a busy counter is refused with Wait would resolve outstanding <counter> work in a masked region. This includes waits whose count would not block (for example vmcnt(3) with one sample outstanding), because exact outstanding counts are not tracked.
  • After the region check, the existing wait handler still validates every wait. SGPR operands, field widths, duplicate tokens, s_waitcnt_depctr, other hints and all other scalar instructions stay refused. The save pair, restore target, skip placement and EXEC rules are unchanged.

Admitted forms: s_waitcnt with any of vmcnt, lgkmcnt and expcnt (or 0), and s_waitcnt_vmcnt, _lgkmcnt, _expcnt and _vscnt with null.

Tests

tests/pixel_aot_check.py:

  • check_region_wait_controls (runs with the other controls):
    • Each admitted form, and all of them together, placed before, between and after the two region writes, under both openers, with and without the skip. The lowered HLSL must be identical to the program without them, after renaming the instruction-numbered temporaries.
    • Refusals with a load outstanding, under both openers. The region opens after the prologue's s_buffer_load_dwordx4 (scalar load and sample outstanding) or after its lgkmcnt(0) (sample only), and each case must give the message that names the busy counter. In the second position lgkmcnt waits are admitted while vmcnt waits and s_waitcnt 0 are refused.
    • s_waitcnt_vscnt null, 0x0 after a scratch store is refused, while the same program without the wait is accepted.
    • SGPR operands, an over-wide count, s_waitcnt_depctr, s_inst_prefetch and s_clause stay refused, and an s_nop between the opener and the skip is refused.
  • check_region_wait_draw, new CTest entries pixel_aot_region_waits_warp and _hardware: the ramp region with every admitted form, under both openers and with and without the skip, on mixed (0.5), full (10) and empty (-1) masks. A reference with the writes applied to every lane must mismatch.
  • LLVM round trip: the four programs, with the skip in label form, join the binary fixtures.
  • Changed expectations:
    • Two refusal lists in check_masked_controls and check_cmpx_controls used s_waitcnt lgkmcnt(0) in a fully drained region. Stage 1 admits that, so the entry is now s_inst_prefetch 0x3, which stays refused. check_region_wait_controls covers which waits stay refused.
    • s_nop 0 is no longer in the region-body refusal list.

docs/experiments.md documents the rule, the controls and the measured draws.

Results

Environment:

  • Commit 79c0be8 on cd87907 (main), dev preset. The full suite rows below ran on the same change rebased on 2d8a0cc; after the final rebase onto cd87907 (no pixel_aot changes upstream in between) the controls, the LLVM round trip, the coverage/docs/bidi checks and all eight region draws (exec_regions, cmpx_regions, region_body, region_waits on WARP and hardware) were rerun and pass.
  • Windows 11 26H2, build 26300.9974
  • MSVC 19.44.35221, Windows SDK 10.0.26100.0, DXC 1.8.2502.11, Python 3.13.1
  • AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31044.16, and in-box WARP
  • D3D12 debug layer enabled
Command Result
python -B tests/pixel_aot_check.py (controls) pass
python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <LLVM-C.dll> with LLVM 15.0.7 pass
ctest --preset dev --no-tests=error -R '^pixel_aot_region_waits_(warp|hardware)$' -V pass on both, 3/3 runs
ctest --preset dev --no-tests=error -E '_hardware$' -j 8 411/413 pass; 2 capability skips (bvh_wave64_warp, wave_shuffle_warp: WARP lane range 4..4)
ctest --preset dev --no-tests=error -R '_hardware$' -j 1 145/149 pass. The 4 failures are RDNA 4 results that fail identically on main: #958, #369, #1011, and pixel_aot_dpp_extra_hardware (new with #423; its subnormal case expects NaN in channel 2 and gets 0x80000010; WARP passes).
form_coverage_check, docs_links_check, bidi_controls_check (and rdna2_tools_check, shader_census_check before the rebase) pass

Negative controls:

  • With the tools/pixel_aot.py change reverted, the controls fail at the first admitted form (Instruction cannot run in a masked region: s_nop 0).
  • With the busy-counter refusal disabled, they fail at Wait would resolve outstanding lgkm work ... s_waitcnt lgkmcnt(0).
  • With the store-counter refusal disabled, they fail at the scratch-store case.
  • The draw fails on both backends when given a reference with the two written values swapped (mixed and full masks mismatch; the empty mask still passes).
  • The round trip fails with Execution skip does not target the matching restore when the new fixtures' skip label is moved inside the body.

Limits:

  • These are desktop D3D12 draws of source-built fixtures. Admitting a no-op does not establish anything about real shaders beyond these forms.
  • The whole-shader scan of one local input (12,101 PS records, the same population as #711) shows no change in any record's first refusal. Those records stop on other errors before reaching a region, so the scan cannot show this change's effect.

AI-assisted.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6569577539 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1023). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-23T21:52:46Z. --- Refs #987 Stage 1 as approved in #987: `s_nop` and waits whose counters are already satisfied in the tracked state may sit inside a masked region, under either opener, with or without the `s_cbranch_execz` skip. Scalar ALU (stage 2) and scalar loads stay out. ## Change `tools/pixel_aot.py`, region check only: - `s_nop <imm>` is admitted. - A wait is admitted only if every counter it names has nothing outstanding: - `vmcnt`: `sample_dest` is empty (no sample, title or scratch load outstanding); - `lgkmcnt`: `pending` is empty (no scalar load outstanding); - `expcnt`: never busy, because only `s_endpgm` may follow an export; - `vscnt`: refused once any scratch store has been lowered, because the store counter is not tracked. - Loads leave `sample_dest` and `pending` only through a wait, and overwriting an outstanding destination is already refused. So an empty set means nothing is outstanding, and the admitted wait resolves nothing whether the wave runs or skips it. - A wait that names a busy counter is refused with `Wait would resolve outstanding <counter> work in a masked region`. This includes waits whose count would not block (for example `vmcnt(3)` with one sample outstanding), because exact outstanding counts are not tracked. - After the region check, the existing wait handler still validates every wait. SGPR operands, field widths, duplicate tokens, `s_waitcnt_depctr`, other hints and all other scalar instructions stay refused. The save pair, restore target, skip placement and EXEC rules are unchanged. Admitted forms: `s_waitcnt` with any of `vmcnt`, `lgkmcnt` and `expcnt` (or `0`), and `s_waitcnt_vmcnt`, `_lgkmcnt`, `_expcnt` and `_vscnt` with `null`. ## Tests `tests/pixel_aot_check.py`: - **`check_region_wait_controls`** (runs with the other controls): - Each admitted form, and all of them together, placed before, between and after the two region writes, under both openers, with and without the skip. The lowered HLSL must be identical to the program without them, after renaming the instruction-numbered temporaries. - Refusals with a load outstanding, under both openers. The region opens after the prologue's `s_buffer_load_dwordx4` (scalar load and sample outstanding) or after its `lgkmcnt(0)` (sample only), and each case must give the message that names the busy counter. In the second position `lgkmcnt` waits are admitted while `vmcnt` waits and `s_waitcnt 0` are refused. - `s_waitcnt_vscnt null, 0x0` after a scratch store is refused, while the same program without the wait is accepted. - SGPR operands, an over-wide count, `s_waitcnt_depctr`, `s_inst_prefetch` and `s_clause` stay refused, and an `s_nop` between the opener and the skip is refused. - **`check_region_wait_draw`**, new CTest entries `pixel_aot_region_waits_warp` and `_hardware`: the ramp region with every admitted form, under both openers and with and without the skip, on mixed (0.5), full (10) and empty (-1) masks. A reference with the writes applied to every lane must mismatch. - **LLVM round trip:** the four programs, with the skip in label form, join the `binary` fixtures. - **Changed expectations:** - Two refusal lists in `check_masked_controls` and `check_cmpx_controls` used `s_waitcnt lgkmcnt(0)` in a fully drained region. Stage 1 admits that, so the entry is now `s_inst_prefetch 0x3`, which stays refused. `check_region_wait_controls` covers which waits stay refused. - `s_nop 0` is no longer in the region-body refusal list. `docs/experiments.md` documents the rule, the controls and the measured draws. ## Results Environment: - Commit `79c0be8` on `cd87907` (`main`), `dev` preset. The full suite rows below ran on the same change rebased on `2d8a0cc`; after the final rebase onto `cd87907` (no `pixel_aot` changes upstream in between) the controls, the LLVM round trip, the coverage/docs/bidi checks and all eight region draws (`exec_regions`, `cmpx_regions`, `region_body`, `region_waits` on WARP and hardware) were rerun and pass. - Windows 11 26H2, build 26300.9974 - MSVC 19.44.35221, Windows SDK 10.0.26100.0, DXC 1.8.2502.11, Python 3.13.1 - AMD Radeon RX 9070 XT (`1002:7550`), driver 32.0.31044.16, and in-box WARP - D3D12 debug layer enabled | Command | Result | |---|---| | `python -B tests/pixel_aot_check.py` (controls) | pass | | `python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <LLVM-C.dll>` with LLVM 15.0.7 | pass | | `ctest --preset dev --no-tests=error -R '^pixel_aot_region_waits_(warp\|hardware)$' -V` | pass on both, 3/3 runs | | `ctest --preset dev --no-tests=error -E '_hardware$' -j 8` | 411/413 pass; 2 capability skips (`bvh_wave64_warp`, `wave_shuffle_warp`: WARP lane range 4..4) | | `ctest --preset dev --no-tests=error -R '_hardware$' -j 1` | 145/149 pass. The 4 failures are RDNA 4 results that fail identically on `main`: #958, #369, #1011, and `pixel_aot_dpp_extra_hardware` (new with #423; its subnormal case expects NaN in channel 2 and gets `0x80000010`; WARP passes). | | `form_coverage_check`, `docs_links_check`, `bidi_controls_check` (and `rdna2_tools_check`, `shader_census_check` before the rebase) | pass | Negative controls: - With the `tools/pixel_aot.py` change reverted, the controls fail at the first admitted form (`Instruction cannot run in a masked region: s_nop 0`). - With the busy-counter refusal disabled, they fail at `Wait would resolve outstanding lgkm work ... s_waitcnt lgkmcnt(0)`. - With the store-counter refusal disabled, they fail at the scratch-store case. - The draw fails on both backends when given a reference with the two written values swapped (mixed and full masks mismatch; the empty mask still passes). - The round trip fails with `Execution skip does not target the matching restore` when the new fixtures' skip label is moved inside the body. Limits: - These are desktop D3D12 draws of source-built fixtures. Admitting a no-op does not establish anything about real shaders beyond these forms. - The whole-shader scan of one local input (12,101 PS records, the same population as #711) shows no change in any record's first refusal. Those records stop on other errors before reaching a region, so the scan cannot show this change's effect. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:45:53 +00:00
R0Y00 commented 2026-11-24 06:49:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T21:58:54Z.


I reproduced s_waitcnt_expcnt s5, 0x0 being accepted under both openers at 79c0be85. The existing export-wait parser also accepts an SGPR outside a masked region. I pushed fcb34088 to keep that existing path and reject the SGPR operand inside either opener. The focused WARP and RTX 4060 Laptop draws, Python controls and LLVM 15 binary round trip all pass.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7115172017 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1023#issuecomment-7115172017). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T21:58:54Z. --- I reproduced `s_waitcnt_expcnt s5, 0x0` being accepted under both openers at `79c0be85`. The existing export-wait parser also accepts an SGPR outside a masked region. I pushed `fcb34088` to keep that existing path and reject the SGPR operand inside either opener. The focused WARP and RTX 4060 Laptop draws, Python controls and LLVM 15 binary round trip all pass.
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!1016
No description provided.