compute: lower the discarded-cache and wave-id SMEM forms #3638

Manually merged
github merged 9 commits from github-bot/gh-3636 into gh-pr/3636/base 2026-12-02 05:43:22 +00:00 AGit
Owner

@⁠lambirou on GitHub · 2026-11-30 19:00 UTC · original
lambirou:compute/smem-misc → main · +592 −7 · 6 files · 9 commits · merged 2026-12-02 05:42 UTC

Stacked on #3634 (compute/smem-cache-noops): the diff includes that commit until #3634 lands. Rebase after it merges. The branch also merges origin/main at d5970858 without conflicts.

Part of the SMEM slice (P2). This adds s_dcache_discard, s_dcache_discard_x2 and s_get_waveid_in_workgroup.

  • s_dcache_discard and _x2 are cacheless no-ops like the other SMEM cache controls, but their operands are still parsed and bounded. LLVM 15.0.7's gfx1013 assembler establishes the spelling: both take an aligned SGPR pair (not a quad); a quad, an odd pair or a modifier is rejected.
  • s_get_waveid_in_workgroup returns the wave index within the workgroup (tid.x / wave width), which is 0 for the one-wave model; a group whose width is not statically known is refused. Its SGPR result arrives through LGKM like a scalar load: the destination stays pending until s_waitcnt lgkmcnt(0), and a read before that wait is refused as Unresolved scalar move source.

Tests

Head 1479e86a on Windows 11 build 26300 (AMD Radeon RX 9060 XT 1002:7590, driver 32.0.32029.2010; Microsoft Basic Render Driver 1414:008c, driver 10.0.26100.10068), after merging origin/main at d5970858:

ctest --preset dev --no-tests=error -R '^(compute_store_aot_smem_wide_loads|compute_store_aot_smem_stores|compute_store_aot_(warp|hardware)|compute_store_aot_smem_stores_(warp|hardware)|compute_store_aot_smem_cache_(controls|cli)|compute_store_aot_smem_misc_(controls|cli))$' -j 1

passed 10/10 in 131.8 s: the wide-load and store text modes, the two WARP draws, the two hardware draws, the cache controls/CLI and the misc controls/CLI. No skips. The misc controls now put the LGKM wait before the read, check the one-wave and declared-wave32 wave-ID values, and require a read before the wait to fail with Unresolved scalar move source; the discard spellings and their refusals are unchanged.

  • tests/compute_store_check.py smem-misc-controls passed (7.4 s) and smem-misc-cli passed (21.2 s; LLVM 15.0.7's clang integrated assembler and LLVM-C.dll, fourteen containers).
  • tests/compute_store_check.py smem-cache-controls and smem-cache-cli passed; smem-wide-loads and smem-stores passed.
  • tests/form_coverage_check.py passed; tests/docs_links_check.py passed (192 Markdown files, 745 links).
  • The wave-shift mutation (5 to 6) and an odd discard pair both fail the controls; a wave-ID SGPR read before its wait is refused.
  • Expected delta: +3 forms on gfx1013; none of the three is in the RDNA 2 reference, so gfx1030 is unchanged. After #3634 and this PR: 1,746/1,968 and 1,642/1,863.

The Linux compute_store_check.py binary mode needs llvm-mc, which this Windows host does not have; it was not run locally. CI's Linux LLVM step still runs it.

Limits

The discard is a no-op property of the cacheless compute model, not a measurement of the native cache; the wave-id value is verified in the emitted HLSL and the LLVM/CLI round-trip, not by a GPU draw. No console measurement was made.

AI-assisted.

**@⁠lambirou** on GitHub · 2026-11-30 19:00 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3636) `lambirou:compute/smem-misc` → `main` · +592 −7 · 6 files · 9 commits · merged 2026-12-02 05:42 UTC **Stacked on #3634** (`compute/smem-cache-noops`): the diff includes that commit until #3634 lands. Rebase after it merges. The branch also merges `origin/main` at `d5970858` without conflicts. Part of the SMEM slice (P2). This adds `s_dcache_discard`, `s_dcache_discard_x2` and `s_get_waveid_in_workgroup`. - `s_dcache_discard` and `_x2` are cacheless no-ops like the other SMEM cache controls, but their operands are still parsed and bounded. LLVM 15.0.7's gfx1013 assembler establishes the spelling: both take an aligned SGPR pair (not a quad); a quad, an odd pair or a modifier is rejected. - `s_get_waveid_in_workgroup` returns the wave index within the workgroup (`tid.x / wave width`), which is 0 for the one-wave model; a group whose width is not statically known is refused. Its SGPR result arrives through LGKM like a scalar load: the destination stays pending until `s_waitcnt lgkmcnt(0)`, and a read before that wait is refused as `Unresolved scalar move source`. ## Tests Head `1479e86a` on Windows 11 build 26300 (AMD Radeon RX 9060 XT `1002:7590`, driver `32.0.32029.2010`; Microsoft Basic Render Driver `1414:008c`, driver `10.0.26100.10068`), after merging `origin/main` at `d5970858`: `ctest --preset dev --no-tests=error -R '^(compute_store_aot_smem_wide_loads|compute_store_aot_smem_stores|compute_store_aot_(warp|hardware)|compute_store_aot_smem_stores_(warp|hardware)|compute_store_aot_smem_cache_(controls|cli)|compute_store_aot_smem_misc_(controls|cli))$' -j 1` passed 10/10 in 131.8 s: the wide-load and store text modes, the two WARP draws, the two hardware draws, the cache controls/CLI and the misc controls/CLI. No skips. The misc controls now put the LGKM wait before the read, check the one-wave and declared-wave32 wave-ID values, and require a read before the wait to fail with `Unresolved scalar move source`; the discard spellings and their refusals are unchanged. - `tests/compute_store_check.py smem-misc-controls` passed (7.4 s) and `smem-misc-cli` passed (21.2 s; LLVM 15.0.7's clang integrated assembler and `LLVM-C.dll`, fourteen containers). - `tests/compute_store_check.py smem-cache-controls` and `smem-cache-cli` passed; `smem-wide-loads` and `smem-stores` passed. - `tests/form_coverage_check.py` passed; `tests/docs_links_check.py` passed (192 Markdown files, 745 links). - The wave-shift mutation (5 to 6) and an odd discard pair both fail the controls; a wave-ID SGPR read before its wait is refused. - Expected delta: **+3 forms on gfx1013**; none of the three is in the RDNA 2 reference, so gfx1030 is unchanged. After #3634 and this PR: **1,746/1,968** and **1,642/1,863**. The Linux `compute_store_check.py binary` mode needs `llvm-mc`, which this Windows host does not have; it was not run locally. CI's Linux LLVM step still runs it. ## Limits The discard is a no-op property of the cacheless compute model, not a measurement of the native cache; the wave-id value is verified in the emitted HLSL and the LLVM/CLI round-trip, not by a GPU draw. No console measurement was made. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 19:04:36 +00:00
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-11-30 19:52 UTC · original · reviewed

Reviewed 7e92b4ca by reading the delta over #3634 (83b60bd3); not built or run.

Verdict: comment. No MUST. One SHOULD that also changes the fixture, so worth fixing before merge.

  • SHOULD s_get_waveid_in_workgroup is an SMEM instruction, and its SGPR result arrives through the LGKM counter like any scalar load, so the guest must s_waitcnt lgkmcnt(0) before reading it. The scalar loads put their destinations in pending (tools/compute_store_aot.py:1833, :1849), and alu_word refuses a pending SGPR until the wait. The wave-ID branch writes scalar[dst] without pending.add(dst) (:1481-1495), so a read straight after it is accepted. The fixture is exactly that shape: smem_misc_waveid_program emits s_get_waveid_in_workgroup s4 then v_mov_b32_e32 v15, s4 (tests/compute_store_check.py, smem_misc_waveid_program). Suggest: add dst to pending, put s_waitcnt lgkmcnt(0) in the fixture, and add a refusal case for the read before the wait.
  • Checked, no finding:
    • Wave ID: local.x >> 5 is the guest wave index for a 1D wave32 group (also for a partial last wave). It folds to 0 for ≤ 32 threads and for the declared one-wave wave64 LDS group. 2D/3D groups and an undeclared width stay refused. Same rules as the s_bcnt1_i32_b32 exec_lo lowering.
    • Discards: even pair within s0-s105, signed 21-bit immediate or sN [offset:], everything else refused. As a no-op after an s_store_* it keeps the stored data, which is one outcome hardware also allows (the line may already be written back).
    • The docs section matches the code and the refusal strings.

Tests: smem-misc-controls checks the HLSL text and every refusal, and records the three forms. smem-misc-cli round-trips them through LLVM 15 and the CLI. Neither is in the Windows pr preset filter, and the Linux LLVM step runs only compute_store_check.py binary. So CI ran only form_coverage_check.py, and the new modes have only the author's local run. The wave-ID value is not checked on a device.

**@⁠lukaslw-lab** on GitHub · 2026-11-30 19:52 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3636#pullrequestreview-6119427164) · **reviewed** Reviewed `7e92b4ca` by reading the delta over #3634 (`83b60bd3`); not built or run. **Verdict: comment.** No MUST. One SHOULD that also changes the fixture, so worth fixing before merge. - **SHOULD** `s_get_waveid_in_workgroup` is an SMEM instruction, and its SGPR result arrives through the LGKM counter like any scalar load, so the guest must `s_waitcnt lgkmcnt(0)` before reading it. The scalar loads put their destinations in `pending` (`tools/compute_store_aot.py:1833`, `:1849`), and `alu_word` refuses a pending SGPR until the wait. The wave-ID branch writes `scalar[dst]` without `pending.add(dst)` (`:1481-1495`), so a read straight after it is accepted. The fixture is exactly that shape: `smem_misc_waveid_program` emits `s_get_waveid_in_workgroup s4` then `v_mov_b32_e32 v15, s4` (`tests/compute_store_check.py`, `smem_misc_waveid_program`). Suggest: add `dst` to `pending`, put `s_waitcnt lgkmcnt(0)` in the fixture, and add a refusal case for the read before the wait. - Checked, no finding: - Wave ID: `local.x >> 5` is the guest wave index for a 1D wave32 group (also for a partial last wave). It folds to 0 for ≤ 32 threads and for the declared one-wave wave64 LDS group. 2D/3D groups and an undeclared width stay refused. Same rules as the `s_bcnt1_i32_b32 exec_lo` lowering. - Discards: even pair within `s0`-`s105`, signed 21-bit immediate or `sN [offset:]`, everything else refused. As a no-op after an `s_store_*` it keeps the stored data, which is one outcome hardware also allows (the line may already be written back). - The docs section matches the code and the refusal strings. Tests: `smem-misc-controls` checks the HLSL text and every refusal, and records the three forms. `smem-misc-cli` round-trips them through LLVM 15 and the CLI. Neither is in the Windows `pr` preset filter, and the Linux LLVM step runs only `compute_store_check.py binary`. So CI ran only `form_coverage_check.py`, and the new modes have only the author's local run. The wave-ID value is not checked on a device.
s_get_waveid_in_workgroup writes an SGPR through the SMEM pipeline, so its result must wait for s_waitcnt lgkmcnt(0) like a scalar load. Add the destination to pending, put the wait in the fixture and refuse a read that precedes it. The discard forms and their refusals are unchanged.
Author
Owner

@⁠lambirou on GitHub · 2026-11-30 20:24 UTC · original

Thanks for the review. Fixed in 1479e86a:

  • s_get_waveid_in_workgroup now adds its SGPR destination to pending, so the result is unreadable until s_waitcnt lgkmcnt(0) clears it, like the scalar loads.
  • smem_misc_waveid_program now emits s_waitcnt lgkmcnt(0) before v_mov_b32_e32 v15, s4.
  • A new refusal case reads s4 before the wait and expects the exact message Unresolved scalar move source. The discard forms and their refusals are unchanged.

I merged origin/main at d5970858 without conflicts. The targeted entries passed 10/10 (131.8 s), including the two WARP and two hardware draws, with no skips: ctest --preset dev --no-tests=error -R '^(compute_store_aot_smem_wide_loads|compute_store_aot_smem_stores|compute_store_aot_(warp|hardware)|compute_store_aot_smem_stores_(warp|hardware)|compute_store_aot_smem_cache_(controls|cli)|compute_store_aot_smem_misc_(controls|cli))$' -j 1. tests/form_coverage_check.py and tests/docs_links_check.py also pass. The PR body records the commands and results; CI is running on the new head.

**@⁠lambirou** on GitHub · 2026-11-30 20:24 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3636#issuecomment-7290878337) Thanks for the review. Fixed in `1479e86a`: - `s_get_waveid_in_workgroup` now adds its SGPR destination to `pending`, so the result is unreadable until `s_waitcnt lgkmcnt(0)` clears it, like the scalar loads. - `smem_misc_waveid_program` now emits `s_waitcnt lgkmcnt(0)` before `v_mov_b32_e32 v15, s4`. - A new refusal case reads `s4` before the wait and expects the exact message `Unresolved scalar move source`. The discard forms and their refusals are unchanged. I merged `origin/main` at `d5970858` without conflicts. The targeted entries passed 10/10 (131.8 s), including the two WARP and two hardware draws, with no skips: `ctest --preset dev --no-tests=error -R '^(compute_store_aot_smem_wide_loads|compute_store_aot_smem_stores|compute_store_aot_(warp|hardware)|compute_store_aot_smem_stores_(warp|hardware)|compute_store_aot_smem_cache_(controls|cli)|compute_store_aot_smem_misc_(controls|cli))$' -j 1`. `tests/form_coverage_check.py` and `tests/docs_links_check.py` also pass. The PR body records the commands and results; CI is running on the new head.
# Conflicts:
#	docs/experiments.md
#	tests/compute_store_check.py
#	tests/form_coverage_check.py
# Conflicts:
#	docs/experiments.md
#	tests/compute_store_check.py
#	tests/form_coverage_check.py
# Conflicts:
#	docs/experiments.md
#	tests/compute_store_check.py
#	tests/form_coverage_check.py
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-01 01:35 UTC · original · reviewed

Reviewed 0db3e0b9 by reading the diff; not built or run. Our point was at 7e92b4ca. The PR's own fix since then is 1479e86a; the rest is #3634's commits and merges of main.

Verdict: comment. The wave-ID fix is right. No MUST. One SHOULD: at this head the evidence in docs/experiments.md contradicts itself about LLVM 15 on the same host.

  • SHOULD Both paragraphs describe Windows 11 build 26300. #3634's cache paragraph (docs/experiments.md:4672-4675) says the cache CLI entry "returned 77 (skipped) on that host because LLVM 15's clang integrated assembler and LLVM-C.dll were not installed; no LLVM 15 round trip has been run". This PR's paragraph (:4730) says "the four entries passed with LLVM 15.0.7's clang integrated assembler and LLVM-C.dll", and those four include compute_store_aot_smem_cache_cli. The PR body and your 20:24 comment report 10/10 with "no skips", also including smem_cache_cli, 13 minutes after the 20:11 correction on #3634. If LLVM 15 was installed in between, #3634's paragraph should say the cache round trip ran. If not, the misc CLI result here is not established either. Please make the two agree with what actually ran.
  • Checked, no finding:
    • 1479e86a: the wave-ID destination goes into pending after the range and already-pending checks, so a read needs s_waitcnt lgkmcnt(0), like the scalar loads. The fixture now has the wait. The new refusal (wait=False → Unresolved scalar move source) reaches the read-before-wait path.
    • The discard and wave-ID lowerings we checked at 7e92b4ca are otherwise unchanged. #3634's commits match what we approved there.

Tests: CI passed at this head. smem-misc-controls and smem-misc-cli are still outside the pr filter and the Linux check list, so the wave-ID refusal has only your local run.

**@⁠lukaslw-lab** on GitHub · 2026-12-01 01:35 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3636#pullrequestreview-6123623453) · **reviewed** Reviewed `0db3e0b9` by reading the diff; not built or run. Our point was at `7e92b4ca`. The PR's own fix since then is `1479e86a`; the rest is #3634's commits and merges of main. **Verdict: comment.** The wave-ID fix is right. No MUST. One SHOULD: at this head the evidence in `docs/experiments.md` contradicts itself about LLVM 15 on the same host. - **SHOULD** Both paragraphs describe Windows 11 build 26300. #3634's cache paragraph (`docs/experiments.md:4672-4675`) says the cache CLI entry "returned 77 (skipped) on that host because LLVM 15's clang integrated assembler and `LLVM-C.dll` were not installed; no LLVM 15 round trip has been run". This PR's paragraph (`:4730`) says "the four entries passed with LLVM 15.0.7's clang integrated assembler and `LLVM-C.dll`", and those four include `compute_store_aot_smem_cache_cli`. The PR body and your 20:24 comment report 10/10 with "no skips", also including `smem_cache_cli`, 13 minutes after the 20:11 correction on #3634. If LLVM 15 was installed in between, #3634's paragraph should say the cache round trip ran. If not, the misc CLI result here is not established either. Please make the two agree with what actually ran. - Checked, no finding: - `1479e86a`: the wave-ID destination goes into `pending` after the range and already-pending checks, so a read needs `s_waitcnt lgkmcnt(0)`, like the scalar loads. The fixture now has the wait. The new refusal (`wait=False` → `Unresolved scalar move source`) reaches the read-before-wait path. - The discard and wave-ID lowerings we checked at `7e92b4ca` are otherwise unchanged. #3634's commits match what we approved there. Tests: CI passed at this head. `smem-misc-controls` and `smem-misc-cli` are still outside the `pr` filter and the Linux check list, so the wave-ID refusal has only your local run.
github-bot changed target branch from main to gh-pr/3636/base 2026-12-02 05:43:01 +00:00
github manually merged commit 0db3e0b9b6 into gh-pr/3636/base 2026-12-02 05:43:04 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 05:41 UTC · original · approved these changes

Confirmed #3634 is already on main and the remaining diff keeps the validated cache controls. Exact head 0db3e0b9: python -B tests/compute_store_check.py passed in smem-misc-controls, smem-cache-controls, smem-wide-loads, and smem-stores modes. python -B tests/form_coverage_check.py passed. Locally changing the generated local.x >> 5u to >> 6u made the 64-thread control fail at the expected wave-ID assertion; the source was restored. This run validates lowering and refusal behavior.

**@⁠R0Y00** on GitHub · 2026-12-02 05:41 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3636#pullrequestreview-6145370104) · **approved these changes** Confirmed #3634 is already on main and the remaining diff keeps the validated cache controls. Exact head `0db3e0b9`: `python -B tests/compute_store_check.py` passed in `smem-misc-controls`, `smem-cache-controls`, `smem-wide-loads`, and `smem-stores` modes. `python -B tests/form_coverage_check.py` passed. Locally changing the generated `local.x >> 5u` to `>> 6u` made the 64-thread control fail at the expected wave-ID assertion; the source was restored. This run validates lowering and refusal behavior.
This discussion has been locked. Commenting is limited to contributors.
No description provided.