upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/docs/embedded_shaders.md
diff options
context:
space:
mode:
authorSuarezPM <SuarezPM@users.noreply.github.com>2026-11-22 11:23:56 -0300
committerSuarezPM <SuarezPM@users.noreply.github.com>2026-11-22 11:34:05 -0300
commit5ecb637a028ae604f4dbaa3b4e992a6db1378de0 (patch)
treeedfb5b87505723cbee43c92f3dce08cae1b20532 /docs/embedded_shaders.md
parentce5380a65e8ffcb9859618f7847c95408737ba33 (diff)
Docs: the embedded shader containers; the BVH builder's programs are console FSSM
The 52 containers in XboxBvhBuilder.dll carry an LLVM bitcode blob and an XDAT/XBCH record. The console record decompresses to FSSM: 52/52 unpack, 42 translate, 41 pass spirv-val with the existing translator. The 10 left need global_atomic_fmax/fmin, buffer_load_ushort and tbuffer_load_format_x (format 8), plus one OpSelectionMerge emission bug. Correct the DXIL-front-end premise in d3d12_vulkan.md (4.8, 7.1, 7.2, M6, Q7, Q20, A.2) and index the new note.
Diffstat (limited to 'docs/embedded_shaders.md')
-rw-r--r--docs/embedded_shaders.md125
1 files changed, 125 insertions, 0 deletions
diff --git a/docs/embedded_shaders.md b/docs/embedded_shaders.md
new file mode 100644
index 000000000..0f74f0fc3
--- /dev/null
+++ b/docs/embedded_shaders.md
@@ -0,0 +1,125 @@
1# Shader containers embedded in the package's DLLs
2
3**Status: measured** on the 1.0.2.1 package. This note covers the shader programs that ship outside
4`shaders.rpf`: the DXBC containers inside the package's DLLs, what each one carries, and what the measurement
5changes for the ray-tracing and upscaling paths. No container, shader or payload is reproduced here; the tables
6hold counts, offsets, chunk names and module identifiers.
7
8## 1. Why they matter
9
10`make_game.py`'s `shaders` stage carves `shaders.rpf` only (`make_game.py`:655). Two DLLs in the same package
11carry compute programs of their own:
12
13* `XboxBvhBuilder.dll`, Microsoft's XDXR acceleration-structure builder. Its constructor creates compute PSOs
14 through device slot 62, and the builder is on the critical path for ray tracing.
15* `amd_fidelityfx_upscaler_xbox.dll`, the FidelityFX 4.1.1 upscaler. Its programs are the `ACCC`/`FSPX` format
16 covered in [fspx.md](fspx.md); this note only counts them.
17
18`tools/pe_shader_containers.py` scans a binary for DXBC containers, validates the chunk table, reads the `ILDN`
19module name and reports what each container carries. `--extract` writes the containers and an `index.json` the
20translator reads; extracted shaders are game data and must stay in the user's work folder.
21
22```sh
23python -I tools/pe_shader_containers.py <dll> --json <work>/containers.json --extract <work>/embedded/dxbc
24```
25
26## 2. Inventory
27
28The 16 DLLs and the package's root files were scanned. All the containers are in two DLLs:
29
30| image | containers | bytes | min / median / max | chunks |
31|---|---:|---:|---:|---|
32| `XboxBvhBuilder.dll` | 52 | 674,404 | 4,072 / 7,454 / 74,508 | `SFI0 ISG1 OSG1 PSV0 RTS0 STAT ILDN HASH DXIL` |
33| `amd_fidelityfx_upscaler_xbox.dll` | 29 | 289,656 | 1,764 / 5,176 / 42,616 | `SFI0 ISG1 OSG1 PSV0 RTS0 HASH ACCC` |
34| other 14 DLLs | 0 | 0 | — | — |
35
36The 29 `ACCC` containers hold `FSPX` payloads ([fspx.md](fspx.md)); the 52 `DXIL` containers are the subject of
37this note. The FSR DLL has one rejected `DXBC` hit: the bytes are an immediate in its own magic check, and the
38validator rejects it (the scan reports both counts).
39
40**Every one of the 52 containers carries two representations of its program:**
41
42* an LLVM bitcode blob in the `DXIL` chunk (`BC C0 DE`, 1,820 to 70,276 bytes), and
43* an `XDAT` directory with tag `0x0d` whose payload starts with `XBCH`: the console program. The same chunk also
44 holds tag `0x07` (a second `DXIL` program header) and tag `0x12` (a 16-byte hash). The `STAT` chunk holds a
45 second, different bitcode blob, not the same one.
46
47The bitcode is what a PC D3D12 compiler consumes; the runtime path is the `XBCH` record. The constructor passes
48the **whole container** to the compute-PSO call: at `0x180021330` it loads `DAT_180025700` with size `0x1134`
49(4,404 bytes, the size of container 0, `CopyAndCompactBVH`) and calls `FUN_18000c470`, whose vtable call at
50`+0x1f0` (slot 62) receives that pointer, its size and two zero words. `FUN_18001d400` adds two more PSOs,
51`XDXR PostBuildInfoQuery` (0x14a4 bytes) and `XDXR GetBVHCompactedSize`. `bvh_builder_test` measures **53** PSO
52creations during construction over the **52** containers ([d3d12_vulkan.md](d3d12_vulkan.md) A.2), so one
53container is created twice; which one is **Open**.
54
55## 3. The 52 modules
56
57The `ILDN` PDB path gives one module per container, all under
58`X:\americas\src\dev\rage\3rdparty\Microsoft\XboxBvhBuilder\Build\Release\Output\XboxBvhBuilder\` (Microsoft's
59component integrated into RAGE, not Rockstar shader code). Grouped by phase:
60
61| phase | modules |
62|---|---|
63| sort (11) | `BitonicPreSortCS`, `BitonicPreSort64CS`, `BitonicInnerSortCS`, `BitonicInnerSort64CS`, `BitonicOuterSortCS`, `BitonicOuterSort64CS`, `RadixCount`, `RadixAlloc`, `RadixReset`, `CalculateMortonCodes`, `CalculateMortonCodes64` |
64| prefix (7) | `PrefixSum64`, `PrefixSum128`, `PrefixSum256`, `PrefixSum512`, `PrefixSum1024`, `PrefixSum2048`, `PrefixSum4096` |
65| kdop (3) | `BuildKDOP`, `ResetKDOP`, `BuildApexPointMap` |
66| build (7) | `ConstructBVH4`, `BuildBVHSplits`, `BuildBVHSplits64`, `SplitInstances`, `FindTreelets`, `RearrangeBVHs`, `RearrangeTriangles` |
67| refit (2) | `RefitBVH4`, `CopyForBVHUpdate` |
68| load (6) | `LoadTriangles`, `ReloadTriangles`, `LoadInstances`, `LoadProceduralGeometry`, `ReloadProcedurals`, `ResetToIndexBuffer` |
69| path tracing (6) | `PT_ConstructBVH4`, `PT_BeginPass`, `PT_LoadInstances`, `PT_WriteInstances`, `PT_WritePartitions`, `PT_WriteOfflinePartition` |
70| rehydration (3) | `Box16Rehydration`, `Box32Rehydration`, `LeafRehydration` |
71| headers/util (7) | `DecompressHeader`, `InitHeaders`, `InitPartitionedHeaders`, `GetBVHCompactedSize`, `CopyCounters`, `ResetCounterValues`, `CopyAndCompactBVH` |
72
73## 4. They are console FSSM, and the existing translator already takes them
74
75The `XBCH` record has the same shape as the game's own shaders: `XBCH` + stored/unpacked sizes + a zlib stream
76that expands to `FSSM` ([fssm_crosscheck.md](fssm_crosscheck.md)). On all 52 containers:
77
78| step | result |
79|---|---|
80| `tools/fssm_unpack.py` | **52/52** decompress to a valid `FSSM` blob (716 B to 101,320 B, median 2,200 B) |
81| `tools/shader_disasm.py --mcpu gfx1013` | **52/52** disassemble; 42 with no invalid word, 10 with invalid words in the code |
82| `tools/rdna2spirv.py` | **42** translate to SPIR-V assembly; **41** assemble and pass `spirv-val` |
83
84The 10 untranslated programs stop at four rules, and the one SPIR-V assembly failure is a separate emission bug:
85
86| module(s) | blocker |
87|---|---|
88| `BuildKDOP`, `LoadInstances`, `ReloadProcedurals`, `LoadProceduralGeometry`, `LoadTriangles` | `global_atomic_fmax` |
89| `PT_LoadInstances` | `global_atomic_fmin` |
90| `Box16Rehydration`, `Box32Rehydration`, `ReloadTriangles` | `buffer_load_ushort` |
91| `LeafRehydration` | `tbuffer_load_format_x GFX10_FORMAT_8_UINT` |
92| `FindTreelets` | translates, but its assembly fails with `OpSelectionMerge must immediately precede either an OpBranchConditional...` |
93
94Reproduction, after `--extract` above:
95
96```sh
97python -I tools/fssm_unpack.py <work>/embedded/dxbc
98python -I tools/shader_disasm.py <work>/embedded/dxbc/fssm --out <work>/embedded/dxbc/disasm --mcpu gfx1013
99python -I tools/rdna2spirv.py <work>/embedded/dxbc/disasm --out <work>/embedded/spirv
100```
101
102## 5. What this changes
103
104* **The RT builder does not need a DXIL path for the console code.** Its programs are RDNA2 `FSSM`, and 41 of
105 52 already pass `spirv-val` with the translator the project uses for the game's 26,503 shaders. The bitcode in
106 the same container is a second representation (the one the PC-compiler experiment measured); it is not what
107 the console runtime executes.
108* **The four missing rules are small and have real fixtures.** `global_atomic_fmax`/`fmin` cover 6 programs,
109 `buffer_load_ushort` 3 and `tbuffer_load_format_x` with format 8 one. They are ordinary translator rules, not
110 a new compiler backend.
111* **The rehydration programs are the ones closest to the shipped data.** `Box16Rehydration`,
112 `Box32Rehydration` and `LeafRehydration` are exactly the programs that would turn the dehydrated BVH packs
113 into runtime trees ([bvh.md](bvh.md) §3.1). Two of the four rules stand between them and translation.
114* **What is still open.** None of the 52 has been executed on a GPU; translation and `spirv-val` do not prove the
115 output. Which of them the game actually creates is a call-site question (RT-5). The module-to-pipeline order
116 above comes from `ILDN`, not from a runtime trace. The `STAT` bitcode and the `0x07 NOBC` record are not
117 explained.
118
119## 6. Tool and tests
120
121`tools/pe_shader_containers.py` is standard library only and reads the file, never runs it. It accepts a
122container only when the chunk table is sorted, 4-byte aligned, entirely inside the declared total and its last
123chunk ends exactly at that total; that is what rejects the FSR DLL's `DXBC` immediate. The synthetic tests in
124`tests/test_pe_shader_containers.py` build containers by hand (no game data) and cover the accepted layout, a
125bare magic, a truncated chunk, an `ACCC`/`FSPX` container, the `ILDN` name and the extraction index.