tombox-xshader: fix two translator panics; sweep the decoder and translator over LLVM's GFX10 vectors #51

Closed
github-bot wants to merge 1 commit from gh-pr/51/head into gh-pr/51/base
Owner

@⁠realkodr on GitHub · 2026-11-21 21:33 UTC · original
realkodr:xshader/translator-panics → main · +41332 −0 · 6 files · 90 commits · closed without merging

Library / area: tombox-xshader (translator, decoder tests)

Exports changed (exports.txt rows): none

Source of the behaviour: instruction encodings from the LLVM Project's AMDGPU assembler and disassembler tests (llvm-project 901520f, Apache-2.0 WITH LLVM-exception). No new instruction semantics: the two fixes turn panics into refusals or into the translation the neighbouring registers already get.

Two translator panics

Both are on encodings LLVM's assembler accepts. The workspace keeps overflow checks on in release, so they panic there too. d3d12_xs catches the unwind, so a title would see "translator panicked", not a crash.

  1. Unlowered SMEM opcodes. Any SMEM opcode other than the loads fell through to the s_buffer_load path, where 1 << (op - 8) overflows: a subtract overflow for the scratch loads (5..7) and a shift overflow from 0x28 up (s_dcache_discard, s_get_waveid_in_workgroup, every atomic). Stores (0x10..0x1a) did not panic but were reported as "unresolved constant buffer". All are now refused as "unsupported SMEM op".
  2. v255 as a 32-bit operand of a 64-bit operation. hi64() added 1 to the register number of every operand, including the 32-bit ones, so v_cvt_f64_i32 v[5:6], v255 or v_ldexp_f64 v[5:6], v[1:2], v255 overflowed a u8. These now translate. A 64-bit operand based at v255 would need v256 and is refused.

How they were found, and the test that keeps them fixed

tools/dev/llvm_vectors.py collects every (encoding, assembly) pair that LLVM's GFX10 MC tests check: 40,984 unique encodings. tests/llvm_vectors.rs runs them with no title dump, DXC or GPU:

  • each vector decodes to one instruction of the encoded length (literals, SDWA and DPP dwords, NSA address dwords);
  • a vector cut short inside an instruction still decodes;
  • the translator returns for every vector as a one-instruction pixel and compute shader. It may refuse, but it does not panic.

On main the last check reports 358 panics. With the fix all six tests pass in about 2 s in a debug build. The decoder had no length errors.

Overlap

#49 checks opcode names per opcode against gfx1013, so this PR does not check names. The two add different files and touch different parts of hlsl.rs.

Notes

  • The vectors are three text files (0.4 to 1.1 MB) because tools/publish_source.py skips files over 2 MB. They are test data only, credited in crates/tombox-xshader/THIRD_PARTY.
  • hlsl.rs still has two more Opnd::Vgpr(n + 1) sites (64-bit vector shifts, buffer_atomic_cmpswap). No LLVM vector reaches them with v255, so I left them alone.

Tests

  • cargo test -p tombox-xshader --test llvm_vectors: 6 pass, both natively on Linux and as a Windows binary under Wine 11.21.

  • --lib --test opcodes --test synthetic: 12 / 22 / 9 pass on Linux.

  • cargo check -p tombox-xshader --all-targets --target x86_64-pc-windows-msvc passes.

  • Not run on native Windows. The GPU suites (exec, isa_sweep) were not run for this change.

  • cargo test -p tombox-xshader --test llvm_vectors passes

  • No game or console files and no binaries included

  • No fake success; anything not possible is left missing with a note

🤖 Generated with Claude Code

**@⁠realkodr** on GitHub · 2026-11-21 21:33 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/51) `realkodr:xshader/translator-panics` → `main` · +41332 −0 · 6 files · 90 commits · closed without merging **Library / area:** tombox-xshader (translator, decoder tests) **Exports changed (exports.txt rows):** none **Source of the behaviour:** instruction encodings from the LLVM Project's AMDGPU assembler and disassembler tests (llvm-project `901520f`, Apache-2.0 WITH LLVM-exception). No new instruction semantics: the two fixes turn panics into refusals or into the translation the neighbouring registers already get. ### Two translator panics Both are on encodings LLVM's assembler accepts. The workspace keeps overflow checks on in release, so they panic there too. `d3d12_xs` catches the unwind, so a title would see "translator panicked", not a crash. 1. **Unlowered SMEM opcodes.** Any SMEM opcode other than the loads fell through to the `s_buffer_load` path, where `1 << (op - 8)` overflows: a subtract overflow for the scratch loads (5..7) and a shift overflow from 0x28 up (`s_dcache_discard`, `s_get_waveid_in_workgroup`, every atomic). Stores (0x10..0x1a) did not panic but were reported as "unresolved constant buffer". All are now refused as "unsupported SMEM op". 2. **v255 as a 32-bit operand of a 64-bit operation.** `hi64()` added 1 to the register number of every operand, including the 32-bit ones, so `v_cvt_f64_i32 v[5:6], v255` or `v_ldexp_f64 v[5:6], v[1:2], v255` overflowed a `u8`. These now translate. A 64-bit operand based at v255 would need v256 and is refused. ### How they were found, and the test that keeps them fixed `tools/dev/llvm_vectors.py` collects every (encoding, assembly) pair that LLVM's GFX10 MC tests check: 40,984 unique encodings. `tests/llvm_vectors.rs` runs them with no title dump, DXC or GPU: - each vector decodes to one instruction of the encoded length (literals, SDWA and DPP dwords, NSA address dwords); - a vector cut short inside an instruction still decodes; - the translator returns for every vector as a one-instruction pixel and compute shader. It may refuse, but it does not panic. On `main` the last check reports 358 panics. With the fix all six tests pass in about 2 s in a debug build. The decoder had no length errors. ### Overlap #49 checks opcode names per opcode against gfx1013, so this PR does not check names. The two add different files and touch different parts of `hlsl.rs`. ### Notes - The vectors are three text files (0.4 to 1.1 MB) because `tools/publish_source.py` skips files over 2 MB. They are test data only, credited in `crates/tombox-xshader/THIRD_PARTY`. - `hlsl.rs` still has two more `Opnd::Vgpr(n + 1)` sites (64-bit vector shifts, `buffer_atomic_cmpswap`). No LLVM vector reaches them with v255, so I left them alone. ### Tests - `cargo test -p tombox-xshader --test llvm_vectors`: 6 pass, both natively on Linux and as a Windows binary under Wine 11.21. - `--lib --test opcodes --test synthetic`: 12 / 22 / 9 pass on Linux. - `cargo check -p tombox-xshader --all-targets --target x86_64-pc-windows-msvc` passes. - Not run on native Windows. The GPU suites (`exec`, `isa_sweep`) were not run for this change. - [x] `cargo test -p tombox-xshader --test llvm_vectors` passes - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note 🤖 Generated with [Claude Code](https://claude.com/claude-code)
LLVM's AMDGPU assembler and disassembler tests pair each instruction's
assembly with its exact encoding. tools/dev/llvm_vectors.py collects
every such pair for GFX10 (40,984 unique encodings) into
tests/data/llvm_gfx10/, and tests/llvm_vectors.rs runs them on any
host, with no title dump, DXC or GPU:

- each vector decodes to one instruction of the encoded length
  (literals, SDWA and DPP dwords, NSA address dwords);
- a vector cut short inside an instruction still decodes;
- the translator returns for every vector as a one-instruction pixel
  and compute shader: it may refuse, but it does not panic.

Without the previous commit the last check reports 358 panics. With
it, all six tests pass in about 2 s in a debug build.

Opcode names are left to the per-opcode table in #49. The data is
three files because tools/publish_source.py skips files over 2 MB. It
is test data only and is credited in the crate's THIRD_PARTY file.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:08:31 +00:00
github-bot closed this pull request 2026-11-26 06:08:31 +00:00
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-21 21:44 UTC · original

Overlap note with #49 (mine): both use LLVM's GFX10 MC vectors, for different checks. #49 commits a gfx1013 opcode→name reference (LLVM + AMD RDNA1/2 XML) and checks every name in rdna2/mnem.rs. That found the VOP2 0x36-0x38 f16 ops are v_fmac/fmamk/fmaak_f16 (fused), not v_mac/madmk/madak_f16, plus a few non-existent VOP3 fallback names. This PR sweeps the decoder and translator for panics. They look complementary; if one lands first I'll rebase #49 to share the vector source, so the repo doesn't end up with two copies.

**@⁠QuentinDanblon** on GitHub · 2026-11-21 21:44 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/51#issuecomment-7069688736) Overlap note with #49 (mine): both use LLVM's GFX10 MC vectors, for different checks. #49 commits a gfx1013 opcode→name reference (LLVM + AMD RDNA1/2 XML) and checks every name in `rdna2/mnem.rs`. That found the VOP2 0x36-0x38 f16 ops are `v_fmac/fmamk/fmaak_f16` (fused), not `v_mac/madmk/madak_f16`, plus a few non-existent VOP3 fallback names. This PR sweeps the decoder and translator for panics. They look complementary; if one lands first I'll rebase #49 to share the vector source, so the repo doesn't end up with two copies.
Author
Owner

@⁠realkodr on GitHub · 2026-11-21 23:18 UTC · original

Agreed, they're complementary. #49 is welcome to reuse tools/dev/llvm_vectors.py and the vectors under tests/data/llvm_gfx10/. If #49 lands first, I'll rebase this onto whatever vector source it uses instead.

**@⁠realkodr** on GitHub · 2026-11-21 23:18 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/51#issuecomment-7070784099) Agreed, they're complementary. #49 is welcome to reuse `tools/dev/llvm_vectors.py` and the vectors under `tests/data/llvm_gfx10/`. If #49 lands first, I'll rebase this onto whatever vector source it uses instead.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 13:12 UTC · original

Main's history was rewritten, which auto-closed this PR (sorry for the noise). The two panic fixes are good. Please send them as their own PR. valu.txt is over the 1 MiB file limit: split it, or generate it at build time. Strip comment lines. To resubmit: git fetch this repo, branch from the current main, cherry-pick only your own commits (the old branch is based on the previous history and cannot be merged), and open a new PR.

**@⁠omonkeyz** on GitHub · 2026-11-22 13:12 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/51#issuecomment-7079646820) Main's history was rewritten, which auto-closed this PR (sorry for the noise). The two panic fixes are good. Please send them as their own PR. valu.txt is over the 1 MiB file limit: split it, or generate it at build time. Strip comment lines. To resubmit: `git fetch` this repo, branch from the current `main`, cherry-pick only your own commits (the old branch is based on the previous history and cannot be merged), and open a new PR.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.