Skip to content

shader_disasm: feed llvm-mc one dword per line to avoid gigabyte stderr (BUILD-3020) - #8916

Open
shadshuvo wants to merge 1 commit into
ItsNotRexed:mainfrom
shadshuvo:fix/build-3020-disasm-line-output
Open

shadshuvo wants to merge 1 commit into
ItsNotRexed:mainfrom
shadshuvo:fix/build-3020-disasm-line-output

Conversation

@shadshuvo

Copy link
Copy Markdown

Claimed in the coordination issue as: BUILD-3020

Depends on: none

What and why

shader_disasm.disasm() was joining all bytes of a shader program into one space-separated line before feeding llvm-mc. When llvm-mc encounters an invalid instruction, it echoes the entire input line in the error message. For large programs (especially the pipeline library), this caused gigabytes of stderr output that stalled the disassembly on its own error messages.

Changed to feed one dword (4-byte instruction) per line instead: each invalid instruction now echoes only ~15 characters instead of the entire program.

Tested

For a 10KB shader with 100 invalid words: 5.1 MB ? 1.5 KB error output (~3400x reduction).

All 29 existing tests in tests/test_shader_disasm.py pass. No game files, no GPU needed-synthetic test only.

Tested on Windows 11 Pro with Python 3.14.2.

Found by Jadiac5.

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

…rr (BUILD-3020)

disasm() was joining all bytes of a shader program into one space-separated line before feeding llvm-mc. When llvm-mc encounters an invalid instruction, it echoes the entire input line in the error message. For large programs (the pipeline library), this caused gigabytes of stderr output.

Changed to feed one dword (instruction) per line instead: each invalid instruction now echoes only ~15 characters instead of the entire program. For a 10KB shader with 100 invalid words: 5.1 MB -> 1.5 KB (~3400x reduction).

All 29 existing tests in test_shader_disasm.py pass. No game files, no GPU needed. Found by Jadiac5. AI-assisted.

@Grimkeh Grimkeh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Linux CPU review (5e67de97)

What changed: shader_disasm feeds llvm-mc one dword per line to avoid gigabyte stderr (BUILD-3020).

Checked: Diff review (+8/-1 in tools/shader_disasm.py); no dedicated unit test in the PR.

Looks like a sensible llvm-mc input-shape fix; no game files.

@matheusfermiano-source

Copy link
Copy Markdown

Independent Linux A/B on 5e67de97 versus its parent using real LLVM 23.1.5 for gfx1030 and gfx1036. I generated a synthetic stream with 4-, 8-, and 12-byte encodings, including literal operands, scalar/global loads, and a VOP3 instruction with a literal (v_add_f32_e64 v2, 0x3f812345, v1). The two revisions produced identical assembly and encoding annotations. The same held with one bad dword before s_endpgm and with 1, 2, or 3 trailing bytes. The invalid-encoding counts stayed unchanged.

On both targets, a 10,884-byte mixed-width stream with 32 bad dwords went from 2,640,219 to 2,420 bytes of diagnostics, with identical assembly and all 32 errors still counted. I also wrapped the smaller one-error fixture in a synthetic FSSM header and ran shader_disasm.py --jobs 1 through its normal CLI. The emitted listings had identical assembly including s_endpgm, and the diagnostics section shrank from 942 to 81 bytes. All 29 focused tests passed.

The comment could say “one 32-bit word per input line” since a machine instruction can span multiple lines. The real LLVM run confirms that 8- and 12-byte instructions still decode across those boundaries.

Synthetic inputs only. AI-assisted (Codex).

@check3D

check3D commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Independent Linux review of 5e67de97 merged cleanly onto main (867d922f) on Ubuntu 24.04, Python 3.12.16 (CPU only, no game files, no llvm-mc installed).

  • Checked LLVM's llvm/tools/llvm-mc/Disassembler.cpp (byteArrayFromString / Disassembler::disassemble): newlines are skipped as token whitespace into a single ByteArray (only [ / ] split blocks), while each byte keeps its source pointer for SourceMgr::PrintMessage. So emitting 4 bytes per line preserves multi-dword (64-bit) RDNA2 instructions while bounding invalid-encoding line echoes.
  • python -I tests/test_shader_disasm.py -v: 29/29 OK (4.77s).
  • git diff --check and python -I scripts/check_no_game_data.py: clean.

Minor non-blocking nit:

  1. Adding a small mocked-subprocess.run regression test in tests/test_shader_disasm.py would pin the one-dword-per-line formatting (including a multi-dword 8-byte program).

LGTM.

AI-assisted: yes.

@tiagonleal

tiagonleal commented Nov 23, 2026 •

Copy link
Copy Markdown

checked: #89165e67de9 | with: make_game.py --stages shaders library step (2,684 programs, own 1.0.2.1 copy), before/after; test_shader_disasm*, test_shader_profile* | on: Windows 11, Ryzen 7 9800X3D, llvm-mc 21.1.8, --jobs 16, on ladder-frame@a1751a9f0 | result: pass

  • Disassembly: before, 830/2,684 in 11 min and slowing; after, 2,684 in 48 s.
  • 100 random listings: instructions identical 100/100, shader_profile.warning_words() identical 100/100 (2,438 words, 0 unresolved). Size 1,992.7 → 41.4 MiB.
  • Tests 29/29 and 40/40.

AI-assisted.
agent: yes

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.

6 participants