shader: lower composite s_waitcnt forms in pixel_aot #659

Merged
Holastor merged 2 commits from upstream-pr/665 into main 2026-11-22 19:14:36 +00:00
Holastor commented 2026-11-22 18:30:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-22T18:30:16Z.


Summary

Support arbitrary counter combinations in s_waitcnt (vmcnt, lgkmcnt, expcnt in any order) as well as raw 0 / 0x0 forms in tools/pixel_aot.py, and synchronize tools/scan_unsupported_shaders.py pattern matching.

Background & Motivation

In the GFX10 (RDNA 2) ISA, s_waitcnt encodes up to three hardware counters:

  • vmcnt (Vector Memory Counter, 6-bit: 0..63)
  • lgkmcnt (LDS, GDS, Kcache, Message Counter, 6-bit: 0..63)
  • expcnt (Export Counter, 3-bit: 0..7)

Real compiler-generated GFX1013 shader binaries frequently emit composite forms such as:

  • s_waitcnt vmcnt(7) lgkmcnt(0)
  • s_waitcnt vmcnt(7) lgkmcnt(63)
  • s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
  • s_waitcnt 0

Previously, pixel_aot.py only accepted isolated lgkmcnt(0) or vmcnt(N) or the exact sequence vmcnt(0) lgkmcnt(0). All composite sequences were rejected, causing s_waitcnt to be the #1 blocker across the entire 8,145 shader census (blocking 7,870 shaders / 96.6% of shaders with 878,578 occurrences).

Implementation Details

  1. tools/pixel_aot.py:

    • Parses space-separated tokens in s_waitcnt <tokens>.
    • Validates counter fields:
      • vmcnt: 0..63 (raises ValueError("VM wait count exceeds the gfx10 six-bit field") on overflow).
      • lgkmcnt: 0..63 (raises ValueError("LGKM wait count exceeds the gfx10 six-bit field") on overflow).
      • expcnt: 0..7 (raises ValueError("Export wait count exceeds the gfx10 three-bit field") on overflow).
    • Rejects duplicate counters (has_vm, has_lgkm, has_exp) and malformed tokens cleanly with ValueError.
    • Semantics:
      • When lgkmcnt == 0, clears pending constant buffer loads. When lgkmcnt > 0, preserves pending state.
      • When vmcnt == 0, clears sample_dest. When vmcnt > 0, updates outstanding sample window issue > samples - limit.
      • Supports raw 0 and 0x0 payload, clearing both sample_dest and pending.
  2. tools/scan_unsupported_shaders.py:

    • Updates SUPPORTED_INSTRUCTIONS_REGEX to recognize composite sequences of vmcnt, lgkmcnt, expcnt within their respective valid bounds, as well as 0 / 0x0.
  3. tests/pixel_aot_check.py:

    • Adds test coverage for legal composite waits (vmcnt(7) lgkmcnt(0), vmcnt(7) lgkmcnt(63), lgkmcnt(0) vmcnt(0), vmcnt(0) expcnt(0) lgkmcnt(0), 0, 0x0).
    • Verifies constant read dependencies: lgkmcnt(0) clears pending and allows reading constant registers; lgkmcnt(63) keeps pending and correctly raises Constant read before load completion.
    • Negative controls: out-of-range counts (lgkmcnt(64), expcnt(8)), duplicate tokens (vmcnt(0) vmcnt(1), lgkmcnt(0) lgkmcnt(1)), and malformed tokens (s_waitcnt invalid).
  4. tests/rdna2_tools_check.py:

    • Updates is_instruction_supported checks to assert True on valid composite forms and False on out-of-range or malformed forms.

Verification

python -B tests/pixel_aot_check.py
# Result: 0 (all checks passed)

python -B tests/rdna2_tools_check.py
# Ran 50 tests in 0.783s - OK (skipped=1)

python -B tests/pso_readiness_check.py
# Result: PSO census, evidence states, and native hash control passed

python -B tests/form_coverage_check.py
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py
# All passed cleanly
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6546097308 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/665). Originally posted by [Holastor](https://github.com/Holastor) on 2026-11-22T18:30:16Z. --- ### Summary Support arbitrary counter combinations in `s_waitcnt` (`vmcnt`, `lgkmcnt`, `expcnt` in any order) as well as raw `0` / `0x0` forms in `tools/pixel_aot.py`, and synchronize `tools/scan_unsupported_shaders.py` pattern matching. ### Background & Motivation In the GFX10 (RDNA 2) ISA, `s_waitcnt` encodes up to three hardware counters: - `vmcnt` (Vector Memory Counter, 6-bit: 0..63) - `lgkmcnt` (LDS, GDS, Kcache, Message Counter, 6-bit: 0..63) - `expcnt` (Export Counter, 3-bit: 0..7) Real compiler-generated GFX1013 shader binaries frequently emit composite forms such as: - `s_waitcnt vmcnt(7) lgkmcnt(0)` - `s_waitcnt vmcnt(7) lgkmcnt(63)` - `s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)` - `s_waitcnt 0` Previously, `pixel_aot.py` only accepted isolated `lgkmcnt(0)` or `vmcnt(N)` or the exact sequence `vmcnt(0) lgkmcnt(0)`. All composite sequences were rejected, causing `s_waitcnt` to be the #1 blocker across the entire 8,145 shader census (blocking 7,870 shaders / 96.6% of shaders with 878,578 occurrences). ### Implementation Details 1. **`tools/pixel_aot.py`**: - Parses space-separated tokens in `s_waitcnt <tokens>`. - Validates counter fields: - `vmcnt`: 0..63 (raises `ValueError("VM wait count exceeds the gfx10 six-bit field")` on overflow). - `lgkmcnt`: 0..63 (raises `ValueError("LGKM wait count exceeds the gfx10 six-bit field")` on overflow). - `expcnt`: 0..7 (raises `ValueError("Export wait count exceeds the gfx10 three-bit field")` on overflow). - Rejects duplicate counters (`has_vm`, `has_lgkm`, `has_exp`) and malformed tokens cleanly with `ValueError`. - Semantics: - When `lgkmcnt == 0`, clears `pending` constant buffer loads. When `lgkmcnt > 0`, preserves `pending` state. - When `vmcnt == 0`, clears `sample_dest`. When `vmcnt > 0`, updates outstanding sample window `issue > samples - limit`. - Supports raw `0` and `0x0` payload, clearing both `sample_dest` and `pending`. 2. **`tools/scan_unsupported_shaders.py`**: - Updates `SUPPORTED_INSTRUCTIONS_REGEX` to recognize composite sequences of `vmcnt`, `lgkmcnt`, `expcnt` within their respective valid bounds, as well as `0` / `0x0`. 3. **`tests/pixel_aot_check.py`**: - Adds test coverage for legal composite waits (`vmcnt(7) lgkmcnt(0)`, `vmcnt(7) lgkmcnt(63)`, `lgkmcnt(0) vmcnt(0)`, `vmcnt(0) expcnt(0) lgkmcnt(0)`, `0`, `0x0`). - Verifies constant read dependencies: `lgkmcnt(0)` clears `pending` and allows reading constant registers; `lgkmcnt(63)` keeps `pending` and correctly raises `Constant read before load completion`. - Negative controls: out-of-range counts (`lgkmcnt(64)`, `expcnt(8)`), duplicate tokens (`vmcnt(0) vmcnt(1)`, `lgkmcnt(0) lgkmcnt(1)`), and malformed tokens (`s_waitcnt invalid`). 4. **`tests/rdna2_tools_check.py`**: - Updates `is_instruction_supported` checks to assert `True` on valid composite forms and `False` on out-of-range or malformed forms. ### Verification ```powershell python -B tests/pixel_aot_check.py # Result: 0 (all checks passed) python -B tests/rdna2_tools_check.py # Ran 50 tests in 0.783s - OK (skipped=1) python -B tests/pso_readiness_check.py # Result: PSO census, evidence states, and native hash control passed python -B tests/form_coverage_check.py python -B tests/docs_links_check.py python -B tests/bidi_controls_check.py # All passed cleanly ```
upstream-sync closed this pull request 2026-11-24 06:44:13 +00:00
JB2WIN commented 2026-11-24 06:48:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-22T19:09:24Z.


Independent Windows run of this PR on physical hardware:

  • Commit under test: aea3b2d (PR head), built from source
  • Windows 11 (10.0.26200.9974), VS Build Tools 2026 (MSVC 19.51), SDK 10.0.26100.8249 (DXC 1.8.2502.11), dev preset
  • NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP 10.0.26100.9818, D3D12 debug layer enabled

ctest --preset dev --no-tests=error -R '^pixel_aot_' -V: 22/22 passed on hardware and WARP, no skips. The debug layer reported debug_errors=0 on all 498 draws.

I didn't run any mutations.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7084152247 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/665#issuecomment-7084152247). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-22T19:09:24Z. --- Independent Windows run of this PR on physical hardware: - Commit under test: `aea3b2d` (PR head), built from source - Windows 11 (10.0.26200.9974), VS Build Tools 2026 (MSVC 19.51), SDK 10.0.26100.8249 (DXC 1.8.2502.11), dev preset - NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP 10.0.26100.9818, D3D12 debug layer enabled `ctest --preset dev --no-tests=error -R '^pixel_aot_' -V`: **22/22 passed** on hardware and WARP, no skips. The debug layer reported `debug_errors=0` on all 498 draws. I didn't run any mutations. AI-assisted.
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!659
No description provided.