# FSSM / RDNA2 cross-check against SCARAB Status: facts checked 2026-11-21 against `p-portela/SCARAB` (`d304fa2`) and the Leonida tree at `793b06f`. This note records **facts and measurements, not code**. SCARAB is GPL-3.0-only; Leonida is GPL-3.0-or-later. No SCARAB code was copied. Any later code adaptation needs the GPL-3.0 notice and attribution to Pedro Portela / SCARAB. The corpus used for the measurements is the local Leonida extraction: **26,503 `.dxbc` containers and 26,503 decompressed `.fssm` blobs**. Only counts and container fields are reported here; no game data is included. SCARAB's own counts (25,321 extracted streams, 25,782 parseable blobs, 25,889 payloads) come from a different title build and are not directly comparable. The short version: - The FSSM unwrap is **not the same** as `tools/fssm_unpack.py`. Leonida parses the XDAT directory and selects tag `0x0D`; SCARAB scans for `XBCH`. Both are correct on the common shape, but they disagree on duplicate entries (below). - SCARAB's **code start is 24 bytes early**: on the Leonida corpus the code starts at `u32[0xC0] + 0x28`, not `+0x10`. The bytes at `+0x10` are a fixed two-record descriptor. - SCARAB's **"RDNA2 / gfx10.3"** label is not supported by the encoding. The stream decodes as **gfx10.1.3 (`gfx1013`)**, the PS5/custom RDNA1.5 target; `gfx1030` is markedly worse. - SCARAB's **"XBSC ISA"** is the name of the vendor DLL (`xbsc_xs.dll`), not a distinct ISA. The extracted files are a 1,542-name AMD mnemonic list plus 856 prose sentences; they contain no numeric encodings apart from the standard VOP3 base-plus-offset convention. - SCARAB's family classifier is sound; its VOP1/VOP2/SOP1 **mnemonic tables and length model** are not. Leonida's `llvm-mc` path is the better decoder. - **Leonida bug found, since fixed:** `xdat_entries` kept only the last of a container's two `0x0D` entries. 195/26,503 containers have two distinct `XBCH` payloads. #2479 added `xdat_entries_all` and a `payload=` choice; `tests/test_fssm_crosscheck.py` pins both. ## 1. Container and unwrap | Claim | SCARAB source | Leonida behaviour / measurement | Verdict | |---|---|---|---| | Outer file is a DXBC-shaped container; chunk table at `0x1C` (count) / `0x20` (offsets); chunks are `SFI0;ISG1;OSG1;PSV0;HASH;DXIL;PRIV`. | `components/shader-bridge/fssm_lib.py` docstring; `fssm_to_rdna2.py` docstring | 26,503/26,503 have exactly that chunk set; `fssm_unpack.parts()` uses the same table. | **Verified** | | `DXIL` chunk payload starts with `u32 0x00010066`, `u32 0x61`, `DXIL`, `u32 0x106`, `containerSize`, `partCount`. | `fssm_lib.py` docstring | The first word is the DxilProgramHeader **ProgramVersion**, not a marker: `0x66` PS (12,101), `0x10066` VS (2,236), `0x20066` GS (195), `0x50066` CS (2,689), `0xD0066` MS (9,282). The next word is that shader's program-header **size** (0x61 in SCARAB's sample, not constant). `0x106` is constant, `0x10 == DXIL chunk size - 12`, `0x14 == part count` (3 or 4). | **Corrected** | | `XDAT` holds the part table; `XBCH` is one of its sections. | `fssm_lib.py` docstring (describes `XDAT`, but the code scans for `XBCH` and never parses the directory) | `tools/fssm_unpack.py` parses `XDAT`: count/header at `+4/+8`, 12-byte entries at `+12`; tags `0x07` (DxilProgramHeader/NOBC), `0x0D` (XBCH), `0x12` (hash). 26,503/26,503 have that tag set. The header word is `0x24` (36) in all 26,503, but 195 containers have `count = 4` and a fourth entry beyond that declared header size; the count-based loop is what reads it. | **Corrected** | | `XBCH` = fourcc, `u32 version=3`, `u32 compressedSize`, `u32 0`, `u32 uncompressedSize`, `u32 0`, then zlib. | `fssm_lib.py`, `fssm_to_rdna2.py` | 26,503/26,503: version 3; both zero words 0; `compressedSize == entry size - 24`; decompressed length `== uncompressedSize`; zlib magic `78 9c`; result starts `FSSM` v0x101. | **Verified** | | The unwrap is a full chain `.dxbc -> DXIL chunk -> XBCH -> zlib -> FSSM`. | `fssm_lib.fssm_from_dxbc()` | `fssm_unpack.unpack()` does the same, but selects the `XBCH` by XDAT tag and checks the decompressed length. SCARAB scans for `XBCH` (the extractor additionally requires version 3) and does not check the length. | **Equivalent in result, different in mechanism** | | A bare `FSSM` blob is accepted as input. | `fssm_to_rdna2.unwrap()` | `fssm_unpack.unpack()` accepts only `.dxbc`; the rest of Leonida (`shader_disasm.py`) accepts a bare `.fssm`. | **Minor input-form gap** | | `FSSM` magic is asserted after decompression. | `fssm_lib.fssm_from_dxbc()` | `fssm_unpack.unpack()` also rejects a payload that doesn't start with `FSSM` (`ValueError`, counted as a problem, nothing written). All 26,503 are `FSSM`, so there is no corpus failure. | **Verified** | | **Duplicate XDAT tag `0x0D`.** | `fssm_lib` / `fssm_to_rdna2` pick the **first** version-3 `XBCH` | `xdat_entries` was a dict, so the **last** tag-`0x0D` entry won. 195/26,503 containers (all `$VS_*` VoxelizeGeneric) have **two different** tag-`0x0D` payloads; the two FSSM payloads differ in code size and content. Since #2479 `xdat_entries_all` returns every entry in directory order and `unpack(payload=…)` picks one; `xdat_entries` keeps the last-wins view for old callers. | **Corrected — real Leonida bug, fixed in #2479** | ### The duplicate-XBCH exception (the important one) `tools/fssm_unpack.py` does: ```python ents = {} for k in range(count): tag, off, size = ... ents[tag] = dxil[off:off + size] ``` For the 195 `$VS_*` containers the directory holds two entries with tag `0x0D` (`count = 4`, but the header word stays `0x24`, so the fourth entry is beyond the declared header size). The first payload and the second payload both decompress to `FSSM` v0x101, but their code differs. In the measured pair the first is 3,679 bytes and starts with a GS/ES-like prologue (`s_bfm_b64`, `s_barrier`, no `exp`); the second is 3,551 bytes and has two `exp` instructions. The 24-byte descriptor at `code_off + 0x10` is identical in the measured pairs, so they belong to the same container record. Leonida writes the second payload as `.fssm` by default; `fssm_unpack.py --payload first` writes the first instead, which is the one SCARAB takes when it scans from the start. The default is unchanged, so the two projects still extract **different payloads** for these containers unless that flag is passed. The authoritative mapping (which payload the game's pipeline uses) is not established here. Covered by `tests/test_fssm_crosscheck.py::DuplicateXbchTest`: `test_xdat_entries_all_preserves_both_payloads_in_order` pins the directory order, `test_xdat_entries_keeps_the_last_payload_per_tag` the compatibility view, and `test_unpack_selects_first_or_last_payload` the `payload=` choice. ## 2. FSSM header and code range | Claim | SCARAB source | Leonida behaviour / measurement | Verdict | |---|---|---|---| | `0x00 FSSM`, `0x04 u32 0x101`, `0x08 u64 len-16`, `0x10 u64 6`. | `fssm_parse.py`, `docs/fssm-analysis.md` | 26,503/26,503 match all four. | **Verified** | | `0xC0 u64 code_off`, `0xC8 u64 code_size`, `0xE8 u64 code_end`, `0xF0 u64 meta_ptr`. | `fssm_parse.py` | Same fields. `code_off` is 8-aligned: 11,971 blobs are `0 mod 16`, 14,532 are `8 mod 16`. `code_size` is `0 mod 16` in all 26,503. `meta_ptr` is `0xDEADBEEFDEADBEEF` in 635. | **Verified** | | `code_end == code_off + code_size` in 99.9%. | `fssm_parse.is_code_consistent()`, `docs/fssm-analysis.md` | 26,486/26,503. The 17 exceptions are not malformed: `code_end` is the `0xDEADBEEFDEADBEEF` "unset" sentinel. `code_off + code_size` is still valid in all 17. SCARAB's `fssm_to_rdna2.code_words()` uses `code_end` as the slice end, so for these 17 it would read from `code_off + 0x10` to EOF, including the metadata and name record. | **Verified claim; exception missing** | | `code_off + 0x00..0x10` is a 16-byte sub-header, `code_off + 0x10` is raw instructions. | `fssm_parse.py`, `fssm_to_rdna2.py`, `include/shader_bridge.h`, `docs/fssm-analysis.md`, `docs/shader-abi-notes.md` | **Wrong on this corpus.** The code starts at `code_off + 0x28`. `code_off + 0x10..0x28` is a fixed 24-byte block: dwords 0 and 3 have `0xD580` in their high 16 bits in 26,503/26,503; dwords 1 and 4 are `0x03FE0000` or `0x03FF0000`; dwords 2 and 5 vary. LLVM rejects the single word at `+0x10` in 100/100 sampled blobs; the single word at `+0x28` is a valid one-word instruction in 100/100. The family census over all 26,503 gives SOPP 25,715 (all opcode 32 = `s_inst_prefetch`) and SOP1 788 (all opcode 4 = `s_swappc_b64`). | **Corrected** | | The 16-byte sub-header is `(0,0,0,0)` or `(8,1,0,0)`. | `fssm_to_rdna2.py` docstring, `fssm_parse.py` | Those two values cover 14,965/26,503 (56.5%). Other common values: `(0x2110080,8,0,0)` 8,119, `(1,1,0,0)` 1,794, `(0x2100080,8,0,0)` 767. The tuple is not a two-value enum. | **Incomplete** | | `0x18`/`0x20` are sentinel-filled slots. | `docs/fssm-analysis.md` | Both are `0xDEADBEEFDEADBEEF` in 26,503/26,503. | **Verified** | | `0x78` is a `(2,N)` pair; `0x80` is `0x44`/`0x45`. | `docs/fssm-analysis.md` | `0x78` low word is `2` in all; high word is `0` (14,532), `2` (9,282), or `3` (2,689). `0x80` is `0x44` (17,221) or `0x45` (9,282). | **Verified** | | Code is padded with `0xBF9F0000` (`s_code_end`) up to `code_end`; `code_end` is the code end. | `fssm_parse.py`, `fssm_to_rdna2.py` | The last `s_endpgm` is immediately followed by a run of `s_code_end` words up to `code_end` in 26,486/26,486 valid blobs. The last `s_endpgm` is the real program end; the filler is not code. Leonida stops at the last `s_endpgm`, SCARAB includes the filler. | **Behavioural difference; Leonida's end is cleaner** | | Multiple programs per blob. | Not stated in SCARAB; `branch_report` walks the whole section | In the code range of the 26,486 blobs with a valid `code_end`: `s_endpgm` count is 1 in 18,558; 2 in 5,799; 3 in 1,535; 4 in 232; 5+ in 362. Leonida's last-`s_endpgm` range covers all of them. | **Missing fact in SCARAB** | | The post-`code_end` tail is 16 bytes of `0xBF9F0000` filler, a u32 header and a zero word, a 20-byte-record table ended by `0xFFFFFFFF`, then `u32 0, u16 0, u16 len, name`. | `fssm_header.binding_table` | 26,503/26,503 blobs parse. 5,640,704 records (mean 212.8, max 385, 17 empty). Header is 4 in 24,572, 3 in 1,914 and 0 in the 17 `code_end = DEAD` blobs. The tail name is a substring of the container name in all 26,503 cases, exact in 691. At least 40 bytes follow the name and are not parsed. | **Verified; layout corrected** | ### Why `+0x28` matters SCARAB's extractor emits `payload[code_off + 0x10 : code_end]`. On the Leonida corpus that is 6 dwords of the fixed descriptor followed by the real program, then 28-42+ `s_code_end` filler dwords. The descriptor is not harmless padding: its first word fails LLVM in 100/100 sampled blobs, so it changes the first decoded instruction and the instruction count. SCARAB's observation that its walk is "never lower" than the vendor is consistent with this: both decoders see the same extra 6 words, and the filler adds more. The constant 0x18 shift does not invalidate relative branch targets, which is why `branch_report` still looks healthy. Leonida's rule is `u32[0xC0] + 0x28` to the last `s_endpgm` (also `docs/design.md`, "Disassembling shaders"). The 17 `code_end = DEAD` blobs are handled because the last `s_endpgm` is used instead of `code_end`. ### Initial float mode (SHADER-190) The 1.0.2.1 scan tested 88 aligned little-endian words in each of the 26,503 indexed FSSM blobs as possible packed `PGM_RSRC1` registers carrying `FLOAT_MODE`, `DX10_CLAMP` and `IEEE`. It covered 78 word starts at FSSM offsets `0x00` through `0x134` and 10 at `code_off + 0x00` through `code_off + 0x24`, inclusive. Local Python scripts walked the exported DXBC `index.json`, opened the matching `fssm/.fssm` for each row, and read each candidate with `struct.unpack_from("