Skip to content

rdna2spirv, fssm_header: read authoritative wave size from FSSM 0xD4 bit 5 - #1900

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
TheAirborneCoder:fssm-wave-size
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
TheAirborneCoder:fssm-wave-size

Conversation

@TheAirborneCoder

Copy link
Copy Markdown
Contributor

Claim: #1745 (comment)

Summary

tools/rdna2spirv.py previously inferred g.wave64 solely from instruction-text markers (WAVE64_RE plus _b64 exec/vcc operands, and stage == "ms"), which left 2,287 markerless wave64 shaders (287 CS, 943 PS, 1,057 VS — including 11 CS using v_readlane_b32, 35 v_readfirstlane_b32, 29 ds_swizzle_b32, and 14 s_barrier) misclassified as wave32 (subgroup_size = 32 and skipped by --wave64-emulate).

Across all 26,503 unpacked .fssm blobs in the corpus (26,503 / 26,503 start with b"FSSM" and have length >= 0xD8), FSSM header u32 at +0xD4 bit 5 (0x20) is the authoritative WAVE32 flag (1 = wave32, 0 = wave64) with 0 contradictions against GFX10 machine-code wave markers:

  • Wave32 (2,662): 1,535 / 2,689 CS, 1,127 / 12,101 PS, 0 / 2,236 VS, 0 / 9,282 MS, 0 / 195 GS.
  • Wave64 (23,841): 1,154 / 2,689 CS, 10,974 / 12,101 PS, 2,236 / 2,236 VS, 9,282 / 9,282 MS, 195 / 195 GS.

Changes

  • tools/fssm_header.py: Added WAVE_FLAGS_OFFSET = 0xD4, FLAG_WAVE32 = 0x20, and wave_size(blob) returning 32 or 64 (or None when < 0xD8 bytes or non-FSSM magic, preserving zero-prefixed synthetic headers), plus summarize(), tally() (wave_sizes), CLI text, and --json reporting.
  • tools/rdna2spirv.py: Reads fssm_header.wave_size() from the sidecar fssm/<name>.fssm when present, cross-checks against code-level wave64 (WAVE64_RE / _b64 exec/vcc) and wave32 (_(?:saveexec|wrexec)_b32) markers (refusing any contradiction with Unsupported), and falls back cleanly to the instruction scan when no FSSM-magic sidecar is present (FSPX and synthetic .s fixtures).
  • Tests: Extended tests/test_fssm_header.py (WaveSizeTest + CLI/JSON checks) and added tests/test_fssm_wave_size.py (7 standalone pure-stdlib tests, zero game data, no llvm-mc/spirv-val/GPU needed).
  • docs/design.md: Recorded the u32[0xD4] bit 5 rule and full 26,503-blob corpus counts in the contract table and tools/fssm_header.py notes.

Testing (AI-assisted)

Tested on Windows 11 (Python 3.14.7, CPU + read-only 26,503-blob corpus verification; zero game data committed):

  • python -m compileall -q make_game.py tools tests — OK
  • python -I make_game.py --help — OK
  • python -I tests/test_fssm_header.py — 40/40 OK
  • python -I tests/test_fssm_crosscheck.py — 6/6 OK
  • python -I tests/test_fssm_wave_size.py — 7/7 OK
  • python -I tests/test_shader_meta.py — 15/15 OK
  • python -I tests/test_docs_links.py — 5/5 OK
  • fssm_header.py full 26,503-blob corpus tally: wave_sizes: {'wave32': 2662, 'wave64': 23841}, 0 header-vs-code contradictions.

@Youssefrah16

Copy link
Copy Markdown

Tested 9a967e19 on NVIDIA GeForce RTX 4060 Laptop GPU (Ada, 32-wide, driver 616.87, Vulkan 1.4.351) and AMD Radeon 680M (gfx1035, RDNA2, driver 26.5.1, Vulkan 1.4.315), Windows 11 10.0.26300: pass (AI-assisted).

  • python -I tests/test_fssm_header.py -v: 40/40 OK
  • python -I tests/test_fssm_wave_size.py -v: 7/7 OK
  • scripts/run_gpu_tests.py --filter cs_w64x_ballot (spirv-val OK): 1/1 PASS on both RTX 4060 (LEONIDA_W64_EMULATE=1) and AMD Radeon 680M (LEONIDA_W64_EMULATE=0, native wave64).

@Impre-visible

Copy link
Copy Markdown

Tested 9a967e1 on NVIDIA GeForce GTX 1660 (Turing, TU116, subgroup 32..32), driver 620.73.04 (proprietary, Vulkan 1.4.357), Arch Linux (kernel 6.18): pass, with one side effect on a synthetic fixture worth a look.

Native build of runtime/ from this head (Ninja, RelWithDebInfo, clang 23.1.5), llvm-mc 23.1.5, SPIRV-Tools v2026.4. Base is main 6a6704d.

  • build.py, this head against main 6a6704d: 185 modules on both sides, all 185 byte-identical.
  • One index.json entry changes: ps_m15 goes from wave64: false to wave64: true (and wave64_emulated: true). Its listing has no wave64 marker, but build.py writes it a hand-built FSSM blob that starts with the FSSM magic and has 0 at 0xD4, so the new rule reads it as wave64. The module itself is unchanged. ps_m15 is drawn by d3d12_translated_draw_test, which is a Windows test and was not run here, so I can't say whether that test or the layer reads the flag. If it matters, the fixture's blob could set bit 5 at 0xD4.
  • tests/test_fssm_header.py (pytest): 40 passed; tests/test_fssm_wave_size.py: 7 passed; tests/semantic: 1644 OK
  • build.py: 185 translated, 185 pass spirv-val; check.py: 122 of 157 pass, 35 skipped
  • run_gpu_tests.py: 178/178 translated and pass spirv-val; 133/173 passed, 40 skipped, 0 failed; with LEONIDA_W64_EMULATE=1: 164/173 passed, 9 skipped (8 fixtures run by the d3d12 tests, 1 needs a 64-wide fragment subgroup), 0 failed

Not covered here: the corpus counts the description gives.

AI-assisted run (Claude). Synthetic test shaders only, no game files involved.

@itsonlysimbo

Copy link
Copy Markdown
Contributor

Tested 9a967e19 on Windows 11 (10.0.26300), Python 3.12.10: pass.

  • tests/test_fssm_header.py 40/40 OK, tests/test_fssm_wave_size.py 7/7 OK.
  • python -m unittest discover -s tests/semantic: 1644 tests OK, same as main 6a6704df.

AI-assisted (Claude Code).

@TheAirborneCoder

Copy link
Copy Markdown
Contributor Author

Thanks @Youssefrah16 and @Impre-visible for testing!

On ps_m15's index.json wave64 field (false -> true):

  • runtime/test/shaders/build.py's asm_fssm() synthesizes a toy 0x110-byte blob (b"FSSM" + bytes(0xFC) + scale), leaving u32[0xD4] == 0 (bit 5 == 0, i.e. wave64, matching 10,974 / 12,101 of the game's PS blobs).
  • ps_m15.asm has no wave/lane instructions (s_getpc_b64, s_load_dwordx4, v_interp_p1/p2_f32, v_fma_f32, v_mul_f32, exp), so the emitted SPIR-V is byte-identical.
  • Checked runtime/ for ShaderEntry::wave64: CreateGraphicsPipelineState (d3d12_translated_draw_test) does not read entry->wave64 at all — only CreateComputePipelineState (runtime/shims/d3d12_vulkan_device.cpp:2311) reads it to log a diagnostic note on compute PSOs.

@zneel

zneel commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Tested 9a967e19 on AMD Radeon RX 9070 XT (RDNA4, subgroup 32..64), AMD 26.11.2, Windows 11 Pro 10.0.26300, AMD Ryzen 7 9800X3D CPU (64 GB RAM): pass. This includes the Windows draw of ps_m15 that @Impre-visible couldn't run.

Runtime and test programs built from this head (MSVC 14.51, Ninja, RelWithDebInfo), native Windows llvm-mc 21.1.8, Vulkan SDK 1.4.363.0, Python 3.12.10. No game files.

run result
ctest -R d3d12_translated_draw Passed. The build translated ps_m15 with this head, and generated/m15_shaders/spirv/index.json has wave64: true, wave64_emulated: true, wave64_graphics: "A"
run_gpu_tests.py (whole suite, native wave64) 164/173, 0 failed
same with LEONIDA_W64_EMULATE=1 164/173, 0 failed
pytest tests/test_fssm_header.py tests/test_fssm_wave_size.py tests/test_translate.py 525 passed, 2 skipped
unittest discover -s tests/semantic 1644 OK

So the wave64: false → true flip on the synthetic ps_m15 doesn't break the translated draw on Windows with a native-wave64 GPU, which agrees with your reading that the graphics PSO path doesn't use entry->wave64. The 9 suite skips are the 8 fixtures the d3d12 tests run, plus ps_w64x_readlane (#2085).

Not covered: the game-corpus counts, since there's no game copy here.

AI-assisted (Claude Code); I checked the results.

@ItsNotRexed
ItsNotRexed merged commit 3b5ac8f into ItsNotRexed:main Nov 22, 2026
10 of 11 checks passed
@XFlawless1

Copy link
Copy Markdown
Contributor

Tested 9a967e1 on Ubuntu (Linux 7.0), Python 3.14.4, LLVM 21.1.8, llvmpipe (Mesa 26.0.8): tests pass. I have one question, and it still applies on main after the merge.

  • pytest tests --ignore=tests/semantic → 4422 passed, 5 failed (the same 5 as main 6a6704d). tests/semantic → 1644 OK. Trial merge onto 4eb6155: test_fssm_header, test_fssm_wave_size, test_fssm_crosscheck, test_shader_meta → 68 passed.
  • Negative control: with only tools/rdna2spirv.py reverted to main (6a6704d), 4 of 7 tests in test_fssm_wave_size fail (wave64 from the header for CS/PS/VS/GS, readlane mask, emulate, contradiction).

Question: the refusal fires on any WAVE64_RE hit, and that regex also matches 64-bit scalar ops on ordinary SGPRs. On main ec8ec4c, tests/test_fssm_wave_size.py's translate_case with make_fssm(32) and a PS that starts with s_mov_b64 s[2:3], -1; s_bcnt1_i32_b64 s4, s[2:3] (or s_bfm_b64 s[2:3], 4, 0) raises Unsupported: FSSM wave32 header contradicts wave64 code. Before this PR it translated. Was the 0-contradiction count taken with this same code_w64 check? If not, refusing only on markers that prove EXEC is 64 lanes (exec_hi, *_saveexec_b64/*_wrexec_b64, a _b64 op on exec/vcc) would keep valid wave32 code. Translated and spirv-val counts over the corpus, before and after, would settle it.
Docs nit: 23,841 − 21,545 = 2,296, not 2,287. Also CS 1,154 − 923 = 231, which is less than 287, so the earlier-scan figures and the markerless counts come from different marker sets. AI-assisted (Claude Code).

ItsNotRexed pushed a commit that referenced this pull request Nov 22, 2026
docs/design.md's "Wave size" row kept both versions after the FSSM wave-size
flag (#1900) landed: it opened with the old marker figure in bold (21,545),
gave the FSSM figure with a stray closing "**", and repeated the old marker
breakdown twice. README.md's status table still said 21,545.

The row now states the FSSM u32[0xD4] bit 5 counts once and keeps the code
markers as the superseded estimate. The README says 23,841.

Checked on a full-corpus translation (own 1.0.2.1 copy, counts only): at
ec8ec4c the index marks exactly 23,841 wave64 (PS 10,974, mesh 9,282,
VS 2,236, CS 1,154, GS 195) and 2,662 wave32 (CS 1,535, PS 1,127). At
6a6704d the code markers made 21,538 of 26,487 translated shaders wave64,
and they call exactly the row's 2,287 (943 PS, 1,057 VS, 287 CS) wave32.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants