The base is 8a242efeb, the merge of main and #984. 68 files conflicted; they were resolved in seven groups by
one rule: the same change in two forms keeps the base's form, everything only #939 has is kept, and where the
two solve one problem in two ways the base's is the frame and #939's plugs into it.
A, the Xbox proxy (d3d12_xs_device.cpp/.h, d3d12_xs.cpp, d3d12_xs_pso_stream.cpp/.h, d3d12_xs_alloc_size.h,
d3d12_xs_desc_clean.h, device_proxy_test.cpp, queue_proxy_test.cpp): the base's files with #939's additions
ported in. Device slot 57 asks #939's NativeGraphicsFactory first and falls back to the base's
proxy_create_graphics_pipeline_from_native_code on E_NOTIMPL. Kept from #939: the providers (texture lease,
raw texture view, resource by address, constant view, descriptor mapping, depth-stencil UAV, texture pages),
the title-backed descriptor mirror, slot 13's feature answers, GPU labels on list slots 71/72. Dropped: #939's
duplicates of the boot ladder routes, its fallback window, its slot 133 stand-in.
A2 (xs_proxy_mock_test.cpp): the base's test with #939's slot 70 raw-buffer case; presentation cases follow
#939's rule that a device which ever had a handler has no queue fallback.
B1, the Vulkan device (d3d12_vulkan_device.cpp, d3d12_com.cpp/.h, shader_library.h, queue_families.h,
pipeline_cache_file.h, startup_trace.h): one lazy-pipeline mechanism, the base's; #939's pending_base_compile
and first_use_backend_pipelines dropped, prepare_on_bind and cold_graphics_compile kept. create_texture keeps
the base's signature; #939's deferred backing is folded into the base's placed-memory binder. #939's quad
lists as triangle indices.
B2, the D3D12 tests (d3d12_existing_heap, a8_dimensions, pipeline_cache_seed, title_va, rect_list,
shader_library, loader_tls_index0, draw, compute, xmem_placed, shader_library_corpus): the base's tests where
both carry the same case, #939's cases added (rebound tables, linear texture map, large vertex batch,
executable shaders, default A8 views).
C, the backend (vulkan_replay.h, vulkan_backend.h, vulkan_bindless.h, vulkan_scratch.h, vulkan_present.h,
rect_list_geometry.h, vk_test_device.h, vk_pipeline_check.cpp, vk_store_test.cpp, bindless_sizing_test.cpp,
replay_texture_barrier_test.cpp): the base's prepare_draw and lazy compute, its #1055 release rule and its
rectangle generator; #939's rectangle variants, GPU quad index expansion, 1D/3D and depth-stencil UAVs, the
label fence on the base's submit.
D, memory, services, presentation (xmem.cpp/.h, xg_xs.cpp, xg_xs_test.cpp, title_va_alias.h and its test,
main.cpp, frame_pacer.h, xbox_present.cpp/.h; xgameruntime_offline.cpp for one comment): the base's xmem with
#939's label hooks, file-backed sections and pin_mapped_data; both texture computers in xg_xs.cpp, the base's
answering first; --first-run-ui kept without host speech in its profile.
E, build, tools, docs (runtime/CMakeLists.txt, make_game.py, tools/rdna2spirv.py, tools/shader_disasm.py,
scripts, tests, docs; docs/README.md and tests/test_exe_shaders_stage.py beyond the conflicts): the base's
v_dot4 decode, #281's disassembler form and tests/semantic/test_fspx_dot4_op_sel_disasm.py dropped; the
base's executable-shader step with #939's cache fix; 366 registered tests.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
16 KiB
The pipeline library in shaders.rpf
Status: measured on the 1.0.2.1 package. shaders.rpf holds one more file behind its 26,503 shader entries:
a library of precompiled pipelines, with 25,471 graphics and 2,693 compute pipeline records and the 21,522 native
RDNA2 programs they run. tools/shader_carve.py reads only the raw-deflate shader entries, so until now nothing
read this file. No program, blob or record is reproduced here; the tables hold counts, sizes and offsets.
1. Where it is
The archive's data area has two parts. The first 274 MB are the shader entries shader_carve.py reads (name,
kind, sizes, raw deflate). The rest, from file offset 0x10579000, is 4,205 zlib streams: 4,204 inflate to
65,536 bytes and the last to 27,436. Concatenated, they form one 275,540,780-byte file. That is the 33.4%
stream coverage world_census.md measured for shaders.rpf. The gaps between the streams are 0
to 12 bytes.
tools/shader_library.py finds the first stream that inflates to the header below and appends streams until it
has the size the header gives. It fails if the sizes don't match exactly.
No shaders elsewhere. The other 74 RPF9 and TTPF archives of the package (214 GB: the root archives except
movies.rpf, and everything under pack/ and data/) were scanned raw and through every zlib stream (about 420 GB
inflated) for DXBC, XBCH, FSSM, FSPX and the shader entries' _Wrapped names. There are no shader entries,
and none of the 148 XBCH/FSSM hits is a record: no XBCH inflates to an FSSM blob, and no FSSM has a code
offset with an s_endpgm after it. The same checks accept the 52 records of XboxBvhBuilder.dll and 200 of 200
carved FSSM blobs. No DXBC hit has a valid header. So the game's shader programs are the shader entries, this
library and the two DLLs' containers (embedded_shaders.md), as far as raw and zlib data go.
2. Layout
All values little-endian.
| offset | size | field |
|---|---|---|
| 0x00 | 4 | 'P' 'S' 00 09 |
| 0x04 | 32 | name, NUL-padded: 0x65F41EDD |
| 0x24 | 36 | version string, NUL-padded: 930.048.020 |
| 0x48 | 8 | hash |
| 0x50 | 4 × 4 | graphics pipelines G = 25,471, compute pipelines C = 2,693, blobs B = 54,576, programs P = 21,522 |
| 0x60 | 4 | blob section size, 31,120,020 |
| 0x64 | 4 | code section size, 240,894,464 |
| 0x80 | G × 0x70 | graphics pipeline records |
| C × 24 | compute pipeline records | |
| B × 8 | blob table: (offset, size) into the blob section | |
| P × 8 | program table: (offset, size) into the code section; every offset is 256-byte aligned | |
| blob section, then code section |
The sections add up to the file size exactly: 0x80 + 25,471 × 0x70 + 2,693 × 24 + 54,576 × 8 + 21,522 × 8 + 31,120,020 + 240,894,464 = 275,540,780. Every blob and program entry lies inside its section. The blob entries are contiguous; the program entries are in increasing offset order.
Graphics record (0x70 bytes): u64 hash, u32 state blob, u32 pipeline blob, 40 bytes not decoded, then seven (u32 program, u32 stage blob) pairs. 0xFFFFFFFF means no program. The slot gives the stage. Slot 0 is the pixel shader, slot 1 the vertex shader and slot 2 the mesh shader. The source containers named in §3 have those stages in every use §3 links: 24,090 of the 24,111 slot-0 uses, 13,388 of 13,409 slot-1 and all 12,062 slot-2. No linked use names a source of another stage. Slot 6 is used by 2 records with one program and no stage blob; it is not identified. Slots 3 to 5 are never used.
| stages | pipelines |
|---|---|
| VS + PS | 13,383 |
| MS + PS | 10,726 |
| MS only | 1,336 |
| VS only | 24 |
| VS + PS + slot 6 | 2 |
The state blob is 388 to 472 bytes (5,680 distinct). The pipeline blob holds the input layout, with element
names such as POSITION, COLOR, TEXCOORD, NORMAL, TANGENT, BLENDWEIGHT and BLENDINDICES for vertex
pipelines (80 bytes, with no elements, for mesh pipelines).
Compute record (24 bytes): u64 hash, u32 state blob, u32 blob, u32 program, u32 layout blob. The four parts have the sizes and shapes of the four FSPX kinds:
| record field | size | FSPX kind |
|---|---|---|
| state blob | 28 bytes in all 2,693 | kind 0, dispatch state: thread-group size in words 3-4, wave32 flag (word 4 bit 20), RSRC1, RSRC2 |
| blob | 20 bytes in all 2,693 | kind 1 |
| program | kind 6 | |
| layout blob | 56 to 10,552 bytes | kind 7 |
1,529 of the 2,684 compute programs set the wave32 flag. 90 set RSRC2 TG_SIZE_EN (bit 10), which none of the
2,689 carved compute shaders do.
Programs. 52 to 239,464 bytes (median 3,968; 238,829,764 in total), padded to 256 bytes with s_code_end.
21,463 of them start with the 36-byte prologue FSPX programs have, three 12-byte VOP3 opcode-0x180 words with
literals (fspx_unpack.code_range finds it); 59 have none. The code runs from there to the last 4-byte-aligned
s_endpgm, as for FSSM blobs. 579 of the first 3,000 pixel programs have more than one. Ending at the first one,
as for FSPX, cut off code their branches reach: 2,281 "branch target outside code" and 1,662 "branch into data" over
all stages.
Each program belongs to exactly one stage: 9,996 PS, 7,498 MS, 2,684 CS, 1,343 VS and the one slot-6 program.
3. Where the programs come from
A graphics stage blob and a compute layout blob share one layout. Word 0 is the kind (2 for a graphics stage, 3
for compute). Then comes a head of 16 bytes (kind 2) or 24 bytes (kind 3), whose last word is tagged 0x40. Then
come 32-byte records tagged 0x41 or 0x42, then a word 0x43, a 16-byte digest and 12 zero bytes. All 20,318
distinct stage and layout blobs follow this. In FSPX, the 16 bytes after kind 7's 0x43 word are the container's
HASH digest (fspx.md). Here they are too: 21,509 of the 21,522 programs have the HASH digest of
one of the carved containers, and every linked program has its container's stage (2,680 CS, 9,991 PS, 7,498 MS,
1,340 VS; the carve index's stage comes from the container's DXIL program header). They come from 6,522
distinct carved shaders, and a source has 1 to 257 programs.
None of the programs is byte-identical to its source's FSSM code. Only 47 distinct code bodies, from
s_inst_prefetch to the first s_endpgm, occur in both. So the library holds pipeline builds: the same
shaders compiled again with their pipeline's state. The 13 programs whose digest names no carved container (4 CS,
5 PS, 3 VS, the slot-6 program) are the only ones with no source in the shader entries.
For a VS or PS program without native wave-size metadata, a 32-bit EXEC operation and an agreeing wave32
flag in every FSSM payload of its matching DXBC source distinguish a wave32 program that uses s_bfm_b64
as scalar data. The translator keeps its existing behavior when the source is absent, the payloads disagree,
or the library code has another strict wave64 marker. Synthetic cases are in
tests/semantic/test_fspx_wave_size.py.
Containers and programs
The carved corpus is counted two ways, and the two numbers are both right (BL-5 in boot_leads.md):
| Count | What it counts | 1.0.2.1 |
|---|---|---|
| Containers | carved DXBC files, one row of the carve index each |
26,503 |
| Programs | tag-0x0D payloads (XBCH → FSSM) inside them |
26,698 |
The difference is 195 containers that hold two payloads. All 195 are vertex shaders; every other container holds one:
| Stage | Containers | Payloads | Containers with two |
|---|---|---|---|
vs |
2,236 | 2,431 | 195 |
ms |
9,282 | 9,282 | 0 |
ps |
12,101 | 12,101 | 0 |
gs |
195 | 195 | 0 |
cs |
2,689 | 2,689 | 0 |
So 195 is the geometry-shader count because of what the second payload is, not because geometry shaders are counted twice or missed: it is the same vertex shader built for the export-shader stage of a legacy geometry-shader pipeline (design.md, "VS as ES (two-payload VS containers)"). The carve skips nothing here.
tools/fssm_unpack.py prints these counts after it unpacks (programs: … payloads in … containers, then one
line per stage when it is given the carve index, whose stage field it reads). It still writes one program per
container, the last payload by default, so the 195 export-stage variants are not translated; which payload a
geometry-shader pipeline selects is open (fssm_crosscheck.md §6).
Measured on an own 1.0.2.1 copy from the build's index.json and fssm_index.json. The synthetic case is
test_program_counts_separate_containers_from_payloads in tests/test_fssm_unpack.py.
4. Tool
python -I tools/shader_library.py <package>/shaders.rpf --out <work>/library --disasm --carve <work>/shaders/dxbc
python -I tools/rdna2spirv.py <work>/library/disasm --out <work>/library/spirv
- It writes
fspx/<name>.codeandfspx/<name>.json, the layoutfspx_unpack.pywrites andrdna2spirv.pyreads (native_blob,cs_dispatch_state). A compute program also getsfspx/<name>.state, its record's state blob (FSPX kind 0) as it is, whose SHA-256 is the index'sfspx_state_sha256; every compute program has exactly one (2,684 programs, 2,693 records). It also writesindex.jsonwith each program's stage, andlibrary.jsonwith the header and both pipeline tables, stage to program name. Programs are namedlib_<stage>_<index>. --disasmwritesdisasm/<name>.sfor the code after the prologue, asfspx_unpack.py --disasmdoes.--carvenames each program's source shaders. It copies the first source container to<name>.dxbc, because the translator reads the stage's signatures andPSV0from there. Pipeline compilation keeps the D3D12 stage interface.--savewrites the reassembled library. A saved file is also accepted as input.--stageslimits the output to some stages.
The output is game data and must stay in your work folder. tests/test_shader_library.py builds libraries and
archives by hand and covers the header, both tables, the size checks, the search in an archive and the digest
walk. It also checks the --carve copy, the translator's reads of the compute sidecar and the compute .state.
In the build. make_game.py's shaders stage runs this for the compute stage after the FSPX step
(library_shaders): --stages cs --disasm --carve into <work>/shaders/library, then rdna2spirv.py into
<work>/shaders/spirv/library with the stage's --wave64-emulate and fallback flags. The runtime's shader library
reads that index next to fspx/ and finds its entries by fspx_code_sha256 and fspx_state_sha256
(fspx.md, "Build and run-time lookup"). That is how the executable creates these pipelines: it reads the
library through DirectStorage zlib requests and passes each compute record's four parts to Xbox device slot 67,
DeserializeComputePipelineStateX, as kinds 0, 1, 6 and 7, so the code key is the program's bytes as the table gives
them and the state key is the record's state blob. The step is redone as a whole when shaders.rpf, the tools,
llvm-mc, the wave64 mode or the flags change (library_build.json, written last), and a clash of both keys between
different modules fails it, as for the FSPX step. Graphics pipelines are not translated by the build.
Resuming a compute-only batch on Linux
Run tools/shader_library.py with --stages cs --disasm --jobs 2 and the carved containers, or select the
kind-6 hashes with --compute-hashes. For an unpacked library with its input index.json, use the compute batch.
python3 -I scripts/translate_pipeline_compute.py /path/to/unpacked --out /path/to/spirv/library --wave64-emulate
Use a dedicated output folder. The two workers run at nice 19. Each has a 768 MiB address-space limit and uses one
SPIRV-Tools process at a time (four processes total). --jobs 1 uses a single worker and --memory-mib changes
the per-process limit. A rerun checks each module against its checksum and the listing, source container, FSPX
sidecars, toolchain and wave mode. It retries failures. Only validated modules enter the runtime index. Its
atomic replacement follows both workers, so an interrupted run leaves the previous index readable. A partial
run exits nonzero and writes the reasons to failures.json, keyed by kind-6 and kind-0 SHA-256. Old modules
can still be used by a runtime that already opened the preceding index.
Among 2,680 compute programs, 46 start with two 12-byte literal-bearing VOP3 NOP hash carriers. Their body
starts at byte 24. The three-record form starts at byte 36. The no-op measurements are in docs/fspx.md.
A hash literal can resemble an instruction. shader_library.py excludes both complete carrier records before
looking for the end of the program. LLVM input uses one dword per line, including within multiword instructions,
so its diagnostic for an invalid word echoes at most four source bytes.
5. Translation
With --carve and rdna2spirv.py at main aa2988cc (llvm-mc 23, gfx1013), 17,955 of the 21,522 programs
translate and pass spirv-val:
| stage | programs | pass spirv-val |
|---|---|---|
| VS | 1,343 | 1,333 (99.3%) |
| MS | 7,498 | 7,059 (94.1%) |
| PS | 9,996 | 7,719 (77.2%) |
| CS | 2,684 | 1,844 (68.7%) |
| slot 6 | 1 | 0 (stage not identified) |
What stops the rest, by the translator's message:
- 2,533 programs: "reachable instruction with normalized encoding". llvm-mc rejects scalar register tuples that
run into
vcc(SGPRs 106 and 107):s_load_dwordx8/x4/x16writings[100:107],s[104:107]ors[92:107], and image instructions whose resource iss[100:107]. In the compute programs alone that is 37,952 SMEM, 22,248 MIMG and 2,298 MUBUF words. The same words with the register field one tuple lower decode; withgfx1030they don't either. The FSSM shaders don't use these tuples; the pipeline builds use them often. The translator now decodes these words from the blob withrdna2_decode(restore_vcc_tuples) and reads them as the[s100,...,vcc_lo,vcc_hi]lists it already takes (design.md Scalar/buffer memory); synthetic cases are intests/semantic/test_vcc_tuple_fallback.py. The count above was measured before this change; it has not been re-run on the real library. - 443: an instruction llvm-mc prints with another encoding than the blob's (
v_fma_mix*,v_interp_p2_f16): the existingcheck_printed_encodingsrefusal. - 90 CS: "CS thread-group-size SGPR": RSRC2
TG_SIZE_EN, which no FSSM compute shader sets. - 68 translate but fail
spirv-val, mostly "requires a previous definition". - Fewer than 30 each:
ds_append,s_bitreplicate_b64_b32ands_flbit_i32_b64on a lane mask,v_cmpand mask destinations, 25 branches into data, 10 undecodable words that can't be re-anchored, and a fewvcc/ttmpoperands. - Programs with no source container: a PS or MS one has no signatures and is
Unsupported(the reads now raise that instead ofFileNotFoundError, which stopped the whole run). A VS that fetches no inputs translates without one.
None of the programs has been run on a GPU.
6. What this changes
- Pipeline pairing is in the package. d3d12_vulkan.md question 14 asks whether a PSO pairs two code-base stages, and says the pairing is in the executable. The graphics records give it for 25,471 pipelines: each names its VS or MS and its PS. Each source can be found through §3.
- A second compiled form of 6,522 shaders. The pipeline builds differ from the FSSM code. Which form the game runs for a pipeline is not measured here (that needs the executable). Either way, a translated pipeline build can be compared with the translated FSSM shader of the same pipeline.
- Not decoded. The graphics state blob, the 40 bytes in each graphics record, the compute kind-1 blob, the records inside the stage blobs, and slot 6.