mesh: accept the whole-register scratch-base setup in the bounded lowerers (Part of #1998) #2500

Merged
Leyukaka merged 1 commit from upstream-pr/2508 into main 2026-11-25 20:12:53 +00:00
Leyukaka commented 2026-11-25 19:00:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-25T19:00:03Z.


Part of #1998: the flat-scratch setup found by the mesh loop census (census comment, claim).

The two s_setreg_imm32_b32 writes to HW_REG_FLAT_SCR_LO/HI were the first refusal for 4,274 of 4,458 programs in the census. This lowers a whole-register immediate write to either half to nothing in the bounded mesh lowerers. It uses the same rule as compute_store_aot.py, with the immediate spelling pattern copied from there.

Soundness

  • Only scratch_* and flat_* memory instructions and s_getreg_b32 of these registers read the scratch base.
  • The wave model does not track the written value, and it only checks the instructions it executes. So run_group scans the whole decoded program first. If the program holds an accepted write and any scratch_*, flat_* or s_getreg_* instruction, on any path, it is refused. The mesh lowerers lower none of these for any register.
  • Still refused:
    • a field write (hwreg(HW_REG_FLAT_SCR_LO, 0, 16));
    • the s_setreg_b32 SGPR form;
    • a non-immediate source;
    • every other hardware register.
  • tools/mesh_dynamic_aot.py uses the same Wave/run_group, so it gets the same rule.
  • In the census, a program with the setup and a reader is now refused before execution, so mesh_loop_census.py places it "after execution". The docs note this.

Tests

  • tests/mesh_entry_check.py flat-scratch is a new CPU mode, registered as mesh_entry_flat_scratch_cpu and listed in AGENTS.md. It checks:
    • The program with the two writes prefixed lowers to the same text as the program without them.
    • scratch_load_dword, flat_load_dword and s_getreg_b32 ..., hwreg(HW_REG_FLAT_SCR_LO) are each refused with "may be observed by " while sitting on a branch arm that no wave executes. Each arm also lowers unchanged without the writes.
    • The four refused write forms are refused.
  • tests/mesh_dynamic_aot_check.py repeats the equivalence and the skipped scratch load, with the same control, for the run-time lowerer.
  • tests/mesh_loop_census_check.py now expects the setup fixture to reach its latch in both census runs (as decoded, and with the writes replaced by s_nop).

Mutation checks, run by hand. Each one fails at least one of the tests above:

  • removing the scan;
  • removing the acceptance;
  • dropping s_getreg_, flat_ or scratch_ from the scan;
  • accepting any immediate spelling.

Run locally (Windows, Python 3.14): all pass.

  • mesh_entry_check.py in the flat-scratch, skipped and exec-restore modes;
  • the mesh_dynamic_aot, mesh_loop_census, mesh_entry_aot_cli, mesh_dynamic_geometry, mesh_heap_sampler, mesh_clip_cull, mesh_lane_spill, mesh_scc_any_lane, mesh_amplification_refusal and mesh_join_descriptor checks.

No GPU or draw tests were run. Programs without the writes are not affected: both the scan and the skip only act on a matching write.

docs/experiments.md: a short section after the loop census, and the census paragraph updated.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6611583966 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2508). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-25T19:00:03Z. --- Part of #1998: the flat-scratch setup found by the mesh loop census ([census comment](https://github.com/R0Y00/Xbox2Windows/issues/1998#issuecomment-7159243592), [claim](https://github.com/R0Y00/Xbox2Windows/issues/1998#issuecomment-7171420965)). The two `s_setreg_imm32_b32` writes to `HW_REG_FLAT_SCR_LO`/`HI` were the first refusal for 4,274 of 4,458 programs in the census. This lowers a whole-register immediate write to either half to nothing in the bounded mesh lowerers. It uses the same rule as `compute_store_aot.py`, with the immediate spelling pattern copied from there. **Soundness** - Only `scratch_*` and `flat_*` memory instructions and `s_getreg_b32` of these registers read the scratch base. - The wave model does not track the written value, and it only checks the instructions it executes. So `run_group` scans the whole decoded program first. If the program holds an accepted write and any `scratch_*`, `flat_*` or `s_getreg_*` instruction, on any path, it is refused. The mesh lowerers lower none of these for any register. - Still refused: - a field write (`hwreg(HW_REG_FLAT_SCR_LO, 0, 16)`); - the `s_setreg_b32` SGPR form; - a non-immediate source; - every other hardware register. - `tools/mesh_dynamic_aot.py` uses the same `Wave`/`run_group`, so it gets the same rule. - In the census, a program with the setup and a reader is now refused before execution, so `mesh_loop_census.py` places it "after execution". The docs note this. **Tests** - `tests/mesh_entry_check.py flat-scratch` is a new CPU mode, registered as `mesh_entry_flat_scratch_cpu` and listed in AGENTS.md. It checks: - The program with the two writes prefixed lowers to the same text as the program without them. - `scratch_load_dword`, `flat_load_dword` and `s_getreg_b32 ..., hwreg(HW_REG_FLAT_SCR_LO)` are each refused with "may be observed by <op>" while sitting on a branch arm that no wave executes. Each arm also lowers unchanged without the writes. - The four refused write forms are refused. - `tests/mesh_dynamic_aot_check.py` repeats the equivalence and the skipped scratch load, with the same control, for the run-time lowerer. - `tests/mesh_loop_census_check.py` now expects the setup fixture to reach its latch in both census runs (as decoded, and with the writes replaced by `s_nop`). **Mutation checks**, run by hand. Each one fails at least one of the tests above: - removing the scan; - removing the acceptance; - dropping `s_getreg_`, `flat_` or `scratch_` from the scan; - accepting any immediate spelling. **Run locally** (Windows, Python 3.14): all pass. - `mesh_entry_check.py` in the `flat-scratch`, `skipped` and `exec-restore` modes; - the `mesh_dynamic_aot`, `mesh_loop_census`, `mesh_entry_aot_cli`, `mesh_dynamic_geometry`, `mesh_heap_sampler`, `mesh_clip_cull`, `mesh_lane_spill`, `mesh_scc_any_lane`, `mesh_amplification_refusal` and `mesh_join_descriptor` checks. No GPU or draw tests were run. Programs without the writes are not affected: both the scan and the skip only act on a matching write. `docs/experiments.md`: a short section after the loop census, and the census paragraph updated. AI-assisted.
tedin7 commented 2026-11-25 20:04:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T19:07:14Z.

Review: COMMENTED


Review of head a879d63f (comment only).

No blocking findings. What I checked:

  • flat_scratch_write accepts only the whole-register immediate write of FLAT_SCR_LO/HI with the same immediate spellings as compute_store_aot.py. Field writes, the SGPR form and other hardware registers still fall through to the unsupported-instruction path.
  • run_group scans the whole decoded program before running, so a reader on a skipped arm is still caught. Both Wave.run and tools/mesh_dynamic_aot.py go through run_group, so the rule covers both.
  • No other open or merged PR covers this slice (searched the repo for scratch-base / mesh).
  • CMake test and AGENTS.md entry match the new flat-scratch mode.

Commands run (Linux, clean worktree of the exact head):

  • python3 tests/mesh_entry_check.py flat-scratch: pass
  • python3 tests/mesh_dynamic_aot_check.py, python3 tests/mesh_loop_census_check.py: pass
  • python3 tests/docs_links_check.py, python3 tests/bidi_controls_check.py, git diff --check origin/main...HEAD: pass
  • Mutations, each made flat-scratch fail: removing the run_group pre-scan; dropping flat_ from the observer list; matching only the LO half.

Not run here: Win2025 (CPU-only Python change, no shader lowering).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6063407217 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2508#pullrequestreview-6063407217). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T19:07:14Z. **Review:** COMMENTED --- Review of head a879d63f (comment only). No blocking findings. What I checked: - `flat_scratch_write` accepts only the whole-register immediate write of FLAT_SCR_LO/HI with the same immediate spellings as `compute_store_aot.py`. Field writes, the SGPR form and other hardware registers still fall through to the unsupported-instruction path. - `run_group` scans the whole decoded program before running, so a reader on a skipped arm is still caught. Both `Wave.run` and `tools/mesh_dynamic_aot.py` go through `run_group`, so the rule covers both. - No other open or merged PR covers this slice (searched the repo for scratch-base / mesh). - CMake test and AGENTS.md entry match the new `flat-scratch` mode. Commands run (Linux, clean worktree of the exact head): - `python3 tests/mesh_entry_check.py flat-scratch`: pass - `python3 tests/mesh_dynamic_aot_check.py`, `python3 tests/mesh_loop_census_check.py`: pass - `python3 tests/docs_links_check.py`, `python3 tests/bidi_controls_check.py`, `git diff --check origin/main...HEAD`: pass - Mutations, each made `flat-scratch` fail: removing the `run_group` pre-scan; dropping `flat_` from the observer list; matching only the `LO` half. Not run here: Win2025 (CPU-only Python change, no shader lowering). AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 21:01:12 +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!2500
No description provided.