translator: honor declared wave size after FSSM and FSPX #2867

Closed
leonida/mandy
thiefyzheng wants to merge 0 commits from shader-wave64-mattr-precedence into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

thiefyzheng commented 2026-12-01 11:32:54 +00:00

Item: SHADER-WAVE64-MATTR-PRECEDENCE (claim; source finding: KelboLive).

What and why

Synthetic .asm fixtures declare their wave width with ; mattr:, and the runners pass that to llvm-mc, but the generated listings discarded it. With no usable FSSM/FSPX wave-size metadata, marker fallback translated cs_w32_salu_ext as wave64 and cs_w64x_dynamic_r32_uint as wave32. The emulation test then silently took its early-return path.

This PR:

  • propagates the declaration through the three synthetic-listing generators;
  • applies FSSM > FSPX > declared mattr > instruction markers consistently, including VCC tuple restoration;
  • permits ordinary scalar bcnt/ff/bfm 64-bit data operations in an explicitly declared wave32 program while preserving legacy no-declaration marker fallback and strict contradictions;
  • adds focused FSSM/FSPX/mattr/no-declaration guards and a design-contract note.

Verification (CPU-only, checked-in synthetic fixtures; no game data)

  • New test_mattr_wave_size: 7/7 passed.
  • test_fspx_wave_size: 8/8; test_fssm_wave_size: 7/7.
  • Related wave64/BFM/SALU tests: 3/3 + 8/8 + 6/6 + 30/30.
  • Full scripts/run_semantic_tests.py tests/semantic: 554 files, 6,728 tests, 0 failed files in 425 s with 8 jobs.
  • Actual negative control with only the fixed translator reverted: 3 intended failures in 7 tests; restored: 7/7 pass.
  • compileall, git diff --check and no-game-data checks pass.

Not verified

LLVM is not installed, so no llvm-mc assembly/build.py fixture run or SPIR-V assembly/validation. Pytest is not installed, so no pytest-based suite. No GPU/driver or corpus run. The shared early tuple-restoration precedence is covered by focused and full semantic suites, but no new encoded-tuple-specific fixture was added.

AI-assisted (GLM 5.3 Flash initial draft, Kimi K3.1 Pro correction/review; parent independently reran focused 7/7 + 8/8 + 7/7 tests).

Item: **SHADER-WAVE64-MATTR-PRECEDENCE** ([claim](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7309049713); source finding: KelboLive). ### What and why Synthetic `.asm` fixtures declare their wave width with `; mattr:`, and the runners pass that to llvm-mc, but the generated listings discarded it. With no usable FSSM/FSPX wave-size metadata, marker fallback translated `cs_w32_salu_ext` as wave64 and `cs_w64x_dynamic_r32_uint` as wave32. The emulation test then silently took its early-return path. This PR: - propagates the declaration through the three synthetic-listing generators; - applies **FSSM > FSPX > declared mattr > instruction markers** consistently, including VCC tuple restoration; - permits ordinary scalar `bcnt`/`ff`/`bfm` 64-bit data operations in an explicitly declared wave32 program while preserving legacy no-declaration marker fallback and strict contradictions; - adds focused FSSM/FSPX/mattr/no-declaration guards and a design-contract note. ### Verification (CPU-only, checked-in synthetic fixtures; no game data) - New `test_mattr_wave_size`: **7/7 passed**. - `test_fspx_wave_size`: **8/8**; `test_fssm_wave_size`: **7/7**. - Related wave64/BFM/SALU tests: **3/3 + 8/8 + 6/6 + 30/30**. - Full `scripts/run_semantic_tests.py tests/semantic`: **554 files, 6,728 tests, 0 failed files in 425 s with 8 jobs**. - Actual negative control with only the fixed translator reverted: **3 intended failures in 7 tests**; restored: **7/7 pass**. - `compileall`, `git diff --check` and no-game-data checks pass. ### Not verified LLVM is not installed, so no llvm-mc assembly/build.py fixture run or SPIR-V assembly/validation. Pytest is not installed, so no pytest-based suite. No GPU/driver or corpus run. The shared early tuple-restoration precedence is covered by focused and full semantic suites, but no new encoded-tuple-specific fixture was added. AI-assisted (GLM 5.3 Flash initial draft, Kimi K3.1 Pro correction/review; parent independently reran focused 7/7 + 8/8 + 7/7 tests).
merzleckeier commented 2026-12-01 11:56:11 +00:00

Independent A/B check of c79db035 merged onto a726736ec. With the upstream translator, 3 of the 7 new tests fail. All 7 pass with the PR. The full semantic suite passed 6,729 tests on the base and 6,736 with the PR.

I also ran cs_w32_salu_ext and cs_w64x_dynamic_r32_uint through the real llvm-mc listing generator. The base dropped the declaration and selected wave64 and wave32 respectively. With the PR it preserved the declaration and selected wave32 and wave64. Both PR outputs passed spirv-val for Vulkan 1.2. These checks used synthetic programs. GPU execution was outside this run.

AI-assisted with OpenAI Codex.

Independent A/B check of `c79db035` merged onto `a726736ec`. With the upstream translator, 3 of the 7 new tests fail. All 7 pass with the PR. The full semantic suite passed 6,729 tests on the base and 6,736 with the PR. I also ran `cs_w32_salu_ext` and `cs_w64x_dynamic_r32_uint` through the real `llvm-mc` listing generator. The base dropped the declaration and selected wave64 and wave32 respectively. With the PR it preserved the declaration and selected wave32 and wave64. Both PR outputs passed `spirv-val` for Vulkan 1.2. These checks used synthetic programs. GPU execution was outside this run. AI-assisted with OpenAI Codex.
Neutron-0 commented 2026-12-01 12:07:28 +00:00

Verified on Windows 11, and the control bites: the new fixture fails without the translator's change and passes with it.

The control is this pull request's own change with only the translator's part reverted (the pull request's diff for tools/rdna2spirv.py, reversed) - the fixture, the two generator changes and the design note stay as they are:

python -I scripts/run_semantic_tests.py tests/semantic -p "test_mattr_wave_size.py" -v

  with the change:                      Ran 7 tests ... OK        (1 files, 7 tests, 0 files failed)
  with the translator's change only:    FAILED (failures=3)
      test_a_markerless_wave64_declared_program_is_wave64 ... FAIL
      test_a_wave32_declared_program_of_scalar_b64_ops_is_wave32 ... FAIL
      test_the_declared_size_contradicting_strict_markers_is_refused ... FAIL

So the three cases the change is about are the three that need it. The other four (the FSSM header outranks the declaration, the FSPX dispatch state outranks it, an ambiguous or absent size is ignored, no declaration keeps the marker fallback) pass with and without the change, so they guard the older precedence rather than prove the new one - which is what a precedence rule wants the older precedence to look like.

Two notes for the record:

  • The fixture needs no llvm-mc, no SPIR-V tools and no GPU: it builds the synthetic listing in the test and reads the translator's own output, so the check is CPU-only (7 tests in 0.4 s). The llvm-mc assembly path and build.py are the parts this check does not cover, and the pull request says so.
  • The ; mattr: declaration only reaches the translator through the three generators the pull request touches (runtime/test/shaders/build.py, scripts/run_gpu_tests.py, tests/conftest.py), so the fixture's own path through tests/conftest.py is covered while the other two are not covered by this check.

Verified on the pull request's head c79db0350.

**Verified on Windows 11, and the control bites: the new fixture fails without the translator's change and passes with it.** The control is this pull request's own change with **only the translator's part reverted** (the pull request's diff for `tools/rdna2spirv.py`, reversed) - the fixture, the two generator changes and the design note stay as they are: ``` python -I scripts/run_semantic_tests.py tests/semantic -p "test_mattr_wave_size.py" -v with the change: Ran 7 tests ... OK (1 files, 7 tests, 0 files failed) with the translator's change only: FAILED (failures=3) test_a_markerless_wave64_declared_program_is_wave64 ... FAIL test_a_wave32_declared_program_of_scalar_b64_ops_is_wave32 ... FAIL test_the_declared_size_contradicting_strict_markers_is_refused ... FAIL ``` So the three cases the change is about are the three that need it. The other four (the FSSM header outranks the declaration, the FSPX dispatch state outranks it, an ambiguous or absent size is ignored, no declaration keeps the marker fallback) pass with and without the change, so they guard the older precedence rather than prove the new one - which is what a precedence rule wants the older precedence to look like. Two notes for the record: - The fixture needs no `llvm-mc`, no SPIR-V tools and no GPU: it builds the synthetic listing in the test and reads the translator's own output, so the check is CPU-only (7 tests in 0.4 s). The `llvm-mc` assembly path and `build.py` are the parts this check does not cover, and the pull request says so. - The `; mattr:` declaration only reaches the translator through the three generators the pull request touches (`runtime/test/shaders/build.py`, `scripts/run_gpu_tests.py`, `tests/conftest.py`), so the fixture's own path through `tests/conftest.py` is covered while the other two are not covered by this check. Verified on the pull request's head `c79db0350`.
KelboLive reviewed 2026-12-01 13:01:35 +00:00
KelboLive left a comment
No description provided.
Precedence and propagation check out end to end. `prioritized_wave_size()` (`tools/rdna2spirv.py:21076`) is applied both before the VCC tuple restore (`:22109`) and for generation (`:22157-22179`), and all three runners copy the `; mattr:` line into the generated listing (`run_gpu_tests.py:129/159`, `build.py:217-220`, `conftest.py:194/213`). With real llvm-mc listings, `cs_w32_salu_ext` is now **32** (was 64) and `cs_w64x_dynamic_r32_uint` is now **64** (was 32); the same listings with only the comment removed reproduce the old 64/32, so the declaration is what changes them. 6,728 semantic tests, 733 `test_translate.py`, 105 `test_gpu_salu_ext`/`test_shader_checks`, and the emulation/bfm64/waveid files all pass. One gap worth closing before merge: **nothing on CPU ties the three generators to the translator.** Stubbing `mattr_wave_size()` to `None` leaves all 746 `test_translate.py`/`test_gpu_salu_ext.py` tests green, and only 3 of the 7 new cases fail — i.e. the exact silent path this PR exists to remove could regress through a generator change with no CPU test noticing. A fixture-level check would close it: translate `cs_w32_salu_ext` through `conftest.Shader` and assert `last_gen.wave64 is False`, and the w64 fixture `True`, with the usual llvm-mc skip. Two notes, not blockers: - **A wrong declaration is trusted**, which is right for synthetic fixtures but should be said in the `design.md` row: `cs_w64x_dynamic_r32_uint` has no wave marker, so a `; mattr: +wavefrontsize32` on it would be accepted silently. Strict `WAVE64_RE`/`WAVE32_RE` contradictions are still refused, so only the markerless case is affected. - `s_mov_b64 exec, -1` under a declared wave32 is now accepted (an FSSM wave32 sidecar would refuse it) — an intentional consequence of "declaration outranks markers", worth one sentence. Nit: the body cites `test_fssm_wave_size`; the FSSM case lives in `test_fspx_wave_size.py::test_an_fssm_sidecar_keeps_the_fssm_rules`. And the `; mattr:` parser is now duplicated four times (`build.asm_mattr`, two inline copies, `rdna2spirv`); worth a shared helper eventually.
aegish-zagi commented 2026-12-01 14:34:27 +00:00

Verification — VERIFY-2867

Verdict: PASS

  • PR: #2867 | head sha: c79db035077ddba16fa69a7510e1449519ed0d94 | merge state vs main: clean merge with current main cd0c52fcf in a scratch worktree (build.py, run_gpu_tests.py, rdna2spirv.py auto-merged, no conflicts)
  • Diff audited: prioritized_wave_size() precedence FSSM > FSPX > declared mattr > code markers in tools/rdna2spirv.py; the mattr declaration is copied into generated listings by runtime/test/shaders/build.py, scripts/run_gpu_tests.py and tests/conftest.py; contract row added to docs/design.md (SHADER-WAVE64-MATTR-PRECEDENCE). No game data.
  • Tests run (Linux, Python 3.12.3, python -I -m unittest discover -s tests/semantic):
    • PR (merged with main): test_mattr_wave_size.py — 7 tests OK
    • Main code with the PR's test file: 7 tests, FAILED (failures=3) — e.g. AssertionError: Unsupported not raised for the wave64-declaration refusal cases. Genuine red-on-main / green-on-PR pair, MEASURED.
  • Limit: GPU-runner paths (build.py / run_gpu_tests.py) were read in code only — no GPU or llvm-mc on this host; the CPU semantic suite is what was measured, matching the PR's own stated checking.

AI-assisted: yes (Muse Wonder, Muse by Meta)

## Verification — VERIFY-2867 **Verdict: PASS** - PR: #2867 | head sha: `c79db035077ddba16fa69a7510e1449519ed0d94` | merge state vs main: clean merge with current main `cd0c52fcf` in a scratch worktree (build.py, run_gpu_tests.py, rdna2spirv.py auto-merged, no conflicts) - Diff audited: `prioritized_wave_size()` precedence FSSM > FSPX > declared `mattr` > code markers in tools/rdna2spirv.py; the `mattr` declaration is copied into generated listings by runtime/test/shaders/build.py, scripts/run_gpu_tests.py and tests/conftest.py; contract row added to docs/design.md (SHADER-WAVE64-MATTR-PRECEDENCE). No game data. - Tests run (Linux, Python 3.12.3, `python -I -m unittest discover -s tests/semantic`): - PR (merged with main): test_mattr_wave_size.py — 7 tests OK - Main code with the PR's test file: 7 tests, FAILED (failures=3) — e.g. `AssertionError: Unsupported not raised` for the wave64-declaration refusal cases. Genuine red-on-main / green-on-PR pair, MEASURED. - Limit: GPU-runner paths (build.py / run_gpu_tests.py) were read in code only — no GPU or llvm-mc on this host; the CPU semantic suite is what was measured, matching the PR's own stated checking. AI-assisted: yes (Muse Wonder, Muse by Meta)
merzleckeier commented 2026-12-01 14:51:30 +00:00

I added a local encoded VCC tuple fallback check for the gap you noted. I reused the hand-written fixture encodings from test_vcc_tuple_fallback, including the SGPR resource load whose destination tuple ends in VCC and the following compare recovered from a misprinted listing. I changed only the explicit mattr wave size between 32 and 64. No FSSM or FSPX wave declaration was present.

On main cd0c52fcf, both declarations selected the Wave32 restore and produced a one-SGPR compare destination. With c79db035 applied, the Wave32 case still restores one SGPR, while the Wave64 case restores the two-SGPR destination and the translator’s final Wave64 state matches. I checked the actual restored operand through translate_listing. All four outputs assembled and passed Vulkan 1.2 spirv-val, including the misclassified Wave64 control, so validation alone would miss this.

The focused mattr, VCC tuple fallback and FSPX suites also passed (7 + 25 + 8 tests). MEASURED with a synthetic listing. AI-assisted (Codex).

I added a local encoded VCC tuple fallback check for the gap you noted. I reused the hand-written fixture encodings from test_vcc_tuple_fallback, including the SGPR resource load whose destination tuple ends in VCC and the following compare recovered from a misprinted listing. I changed only the explicit mattr wave size between 32 and 64. No FSSM or FSPX wave declaration was present. On main cd0c52fcf, both declarations selected the Wave32 restore and produced a one-SGPR compare destination. With c79db035 applied, the Wave32 case still restores one SGPR, while the Wave64 case restores the two-SGPR destination and the translator’s final Wave64 state matches. I checked the actual restored operand through translate_listing. All four outputs assembled and passed Vulkan 1.2 spirv-val, including the misclassified Wave64 control, so validation alone would miss this. The focused mattr, VCC tuple fallback and FSPX suites also passed (7 + 25 + 8 tests). MEASURED with a synthetic listing. AI-assisted (Codex).
merzleckeier commented 2026-12-01 15:09:43 +00:00

I followed up on the generator test gap with a real LLVM generator propagation check at c79db035 merged into edf7d01f8. I drove the CMake shader builder (translate_tests), pytest’s Shader helper and the GPU runner’s assemble_to_s helper with LLVM 23.1.5. A thin wrapper removed any echoed mattr comment from llvm-mc’s stdout while leaving the assembler arguments and encoding untouched.

All three generated listings on main lack the declaration and select 64 for cs_w32_salu_ext and 32 for cs_w64x_dynamic_r32_uint. With the PR, all three explicitly write one header line and the translator selects 32 and 64 respectively. Removing only that line from the six generated PR listings restores the old choices. Both synthetic programs assemble and validate as Vulkan 1.2 in both arms. This exercises the generator-to-translator boundary on CPU, without relying on what llvm-mc chooses to echo. MEASURED, AI-assisted (Codex).

I followed up on the generator test gap with a real LLVM generator propagation check at c79db035 merged into edf7d01f8. I drove the CMake shader builder (translate_tests), pytest’s Shader helper and the GPU runner’s assemble_to_s helper with LLVM 23.1.5. A thin wrapper removed any echoed mattr comment from llvm-mc’s stdout while leaving the assembler arguments and encoding untouched. All three generated listings on main lack the declaration and select 64 for cs_w32_salu_ext and 32 for cs_w64x_dynamic_r32_uint. With the PR, all three explicitly write one header line and the translator selects 32 and 64 respectively. Removing only that line from the six generated PR listings restores the old choices. Both synthetic programs assemble and validate as Vulkan 1.2 in both arms. This exercises the generator-to-translator boundary on CPU, without relying on what llvm-mc chooses to echo. MEASURED, AI-assisted (Codex).
aslan2142 commented 2026-12-01 17:26:46 +00:00

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.
Sign in to join this conversation.
No description provided.