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:
authorJan Trencansky <jan.trencansky@protonmail.com>2026-11-24 20:26:00 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-24 20:26:00 -0500
commit154e4ec034902deffa4b89b2cbca9a949f38baec (patch)
tree1b2ef5656de42c172291bc6009efa4c510650815 /docs/embedded_shaders.md
parenteb6a08cd359d98b5777e70d54d0ae8a75879495a (diff)
parent8a242efebf823aeb23c72d17c3d666daf0bbd3e2 (diff)
Merge the #984 result (main + RT-PROTON-STORY-LOAD) into #939
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>
Diffstat (limited to 'docs/embedded_shaders.md')
-rw-r--r--docs/embedded_shaders.md80
1 files changed, 59 insertions, 21 deletions
diff --git a/docs/embedded_shaders.md b/docs/embedded_shaders.md
index a1277dfc7..29a1b3cf2 100644
--- a/docs/embedded_shaders.md
+++ b/docs/embedded_shaders.md
@@ -8,8 +8,9 @@ hold counts, offsets, chunk names and module identifiers.
8## 1. Why they matter 8## 1. Why they matter
9 9
10`tools/shader_carve.py` carves `shaders.rpf` only. Two DLLs in the same package carry compute programs of their 10`tools/shader_carve.py` carves `shaders.rpf` only. Two DLLs in the same package carry compute programs of their
11own, and `make_game.py`'s `shaders` stage translates both sets after the game's shaders (section 7 for the 11own, and the game executable carries graphics programs inline; `make_game.py`'s `shaders` stage translates all
12builder, [fspx.md](fspx.md) for FidelityFX): 12three sets after the game's shaders (section 7 for the builder and the executable, [fspx.md](fspx.md) for
13FidelityFX):
13 14
14* `XboxBvhBuilder.dll`, Microsoft's XDXR acceleration-structure builder. Its constructor creates compute PSOs 15* `XboxBvhBuilder.dll`, Microsoft's XDXR acceleration-structure builder. Its constructor creates compute PSOs
15 through device slot 62, and the builder is on the critical path for ray tracing. 16 through device slot 62, and the builder is on the critical path for ray tracing.
@@ -42,7 +43,7 @@ validator rejects it (the scan reports both counts).
42### Retail executable (`game_scarlett_master.exe`, RT-5) 43### Retail executable (`game_scarlett_master.exe`, RT-5)
43 44
44Scanning the retail executable (120,181,760 bytes, SHA-256 `e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993`) 45Scanning the retail executable (120,181,760 bytes, SHA-256 `e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993`)
45with `tools/pe_shader_containers.py` finds **10** valid DXBC containers (9,520 bytes total, file offsets 46for literal DXBC headers finds **10** valid containers (9,520 bytes total, file offsets
46`0x688cd3c`..`0x688fdf6`, sizes 924–992 bytes) and 1 rejected `DXBC` hit: 47`0x688cd3c`..`0x688fdf6`, sizes 924–992 bytes) and 1 rejected `DXBC` hit:
47 48
48* **Stages (`PSV0`):** **1** vertex shader (`0x688cd3c`, 992 bytes) and **9** pixel shaders (924–980 bytes). Unlike the 49* **Stages (`PSV0`):** **1** vertex shader (`0x688cd3c`, 992 bytes) and **9** pixel shaders (924–980 bytes). Unlike the
@@ -53,6 +54,9 @@ with `tools/pe_shader_containers.py` finds **10** valid DXBC containers (9,520 b
53 unpack via `tools/fssm_unpack.py` (10/10 `FSSM`, 1,245–4,176 bytes), disassemble cleanly via `tools/shader_disasm.py --backend python` 54 unpack via `tools/fssm_unpack.py` (10/10 `FSSM`, 1,245–4,176 bytes), disassemble cleanly via `tools/shader_disasm.py --backend python`
54 (10/10 clean), translate via `tools/rdna2spirv.py` (10/10 translated, all wave64 tier A), and pass `vk_pipeline_check` 55 (10/10 clean), translate via `tools/rdna2spirv.py` (10/10 translated, all wave64 tier A), and pass `vk_pipeline_check`
55 on an NVIDIA GeForce RTX 5060 Laptop GPU (driver `617.14`, Windows 11): **10/10 modules and 10/10 pipelines OK** (1 VS, 9 PS, 0 failed, 0 skipped). 56 on an NVIDIA GeForce RTX 5060 Laptop GPU (driver `617.14`, Windows 11): **10/10 modules and 10/10 pipelines OK** (1 VS, 9 PS, 0 failed, 0 skipped).
57 The build now extracts and translates these 10 in its own `exe` stage (section 7), and the runtime loads them
58 from `<shaders>/exe/index.json`; one of them is the VS that 14 graphics PSOs named and could not create before
59 that step existed (section 7, measured).
56 60
57**Every one of the 52 containers carries two representations of its program:** 61**Every one of the 52 containers carries two representations of its program:**
58 62
@@ -290,14 +294,59 @@ The last line also gets `--wave64-emulate` and the fallback flags of the build,
290 emulated modules made at the default cap, `RadixAlloc` is refused (`declares 37084 bytes of workgroup memory`, 294 emulated modules made at the default cap, `RadixAlloc` is refused (`declares 37084 bytes of workgroup memory`,
291 `0x80004001`) after 28 creations. 295 `0x80004001`) after 28 creations.
292 296
297**Packed pixel shaders.** The executable also holds two native pixel shaders in SGD5 records. Their header file
298offsets are `0x688ecf6` and `0x688f17f`. Both stored lengths include the 12-byte header. Raw deflate yields a
299complete DXBC of 1,324 or 1,052 bytes. Their FSSM SHA-256 keys are
300`cae1e27820adde6a6cb35e308290164ad8cf7107f0fe147d50a2053d7ceeb4b8` and
301`879cb2e326c5e5333935a0b2b1dd9c3c2adc1b03e546d1f84f993d912b4f66b0`. The first is
302`PS_ClearMulti4_f05fef9c_Wrapped`, requested by two graphics streams whose lookup failed with the old index.
303`pe_shader_containers.py` checks the stored lengths, inflates the complete stream and validates the inner
304container. It appends packed XBCH records after the plain containers to preserve their existing file names.
305Three other packed DXBCs have no native XBCH entry. The 12 native programs (1 VS, 11 PS) all translate, pass
306`spirv-val`, and compile with the pipeline checker's partner stubs on an RTX 4070.
307
308The clear shader lookup failed for two distinct graphics state keys.
309
310- `589de82a8d0f07c4eaa73fa3d25a69c3c6d0eb79cca5bc970f129313a180b207`
311- `550e747ba7a5fd9b1467ed8c33be3276ed434621d919c6aa179bdb629086389d`
312
313Both use the VS `exe/container_00` (FSSM `01ac7810dcabd62afcd904b231e90d9a031a51808a700e3349290bec5f0d426f`)
314and the recovered PS `exe/container_10`. Both declare two render targets, RT0 format 87 (BGRA8 UNORM) and
315DSV format 20 (D32 FLOAT S8X24 UINT). Their translated VS and PS pass the pairwise interface check.
316
317**The executable's native containers (`exe_shaders()`).** After the builder's step, the same stage runs
318`pe_shader_containers.py <game>/game_scarlett_master.exe --extract <work>/shaders/exe`, then `fssm_unpack.py`,
319`shader_disasm.py` and `rdna2spirv.py` as in the recipe above, into `<work>/shaders/spirv/exe`. The executable
320passes these containers inline to `CreatePipelineState`, so no archive holds them; the key is `fssm_sha256` again.
321The step is reused on the same conditions as the builder's (the image, the three tools before the translator, the
322translator, llvm-mc, the wave64 mode and the fallback flags) and reports every program left untranslated on every
323run. Measured on 1.0.2.1: **12/12 translate and pass `spirv-val`** (1 VS, 11 PS, 1,245–4,239 bytes); the VS's
324SHA-256 is `01ac7810dcabd62afcd904b231e90d9a031a51808a700e3349290bec5f0d426f`.
325`tests/test_exe_shaders_stage.py` covers the step on synthetic VS/PS `PSV0` containers without game data.
326
327**That VS is why 14 graphics PSOs failed (measured).** On the base commit, a 100 s boot refused **14** of 50,469
328`CreatePipelineState` calls, every one with `no translated vs for FSSM sha256 01ac...`: none of the 26,503 indexed
329`fssm` blobs has that SHA-256, because the container is in the executable and the build never extracted it. The
330translator supports it (all 10 executable containers unpack, disassemble and translate cleanly, wave64 tier A), so
331the gap was extraction, not translation. With this step and the runtime index, the same boot creates all 14
332(**0 failed**, 10 `exe` entries loaded). The 14 calls have 13 distinct signatures (one repeats) and share one
333paired PS (`452212e59d983c3b6404328105153b5b26a435f5d7780dbcedc0c46a51ecec60`, `exe/container_06`, a colour
334passthrough); their target layouts are R8G8B8A8_UNORM and R8G8B8A8_UNORM_SRGB, R11G11B10_FLOAT, R10G10B10A2_UNORM,
335A8_UNORM and B8G8R8A8_UNORM, with and without D32_FLOAT_S8X24_UINT, plus one 5-RT layout. The VS has only
336`SV_VertexID` as an input and reads two streams (position, colour) out of the title's memory through a descriptor
337in its root arguments, so these are quad/UI draws (Scaleform-style), not a texture composite; the B8G8R8A8 layouts
338can write a backbuffer-format target. A 150 s boot with late-frame captures (`LEONIDA_CAPTURE_EVERY=300`, frames
3391 to 6,901, so the last ones about 110 s in) was still all black (24/24 frames, mean rgb 0.00), so this VS was not
340the black-frame cause; see the presentation notes for that.
341
293**Run time.** `ShaderLibrary::load(dir)` (`runtime/src/shader_library.h`) reads `<dir>/index.json`, then 342**Run time.** `ShaderLibrary::load(dir)` (`runtime/src/shader_library.h`) reads `<dir>/index.json`, then
294`<dir>/fspx/index.json`, `<dir>/bvh/index.json`, and `<dir>/exe/index.json` when they are there. The builder's 343`<dir>/fspx/index.json`, `<dir>/bvh/index.json` and `<dir>/exe/index.json` when they are there. The builder's
295entries are named `bvh/<name>` and the executable's `exe/<name>`, the path of their module below `<dir>`, and both 344entries are named `bvh/<name>` and the executable's `exe/<name>`, the path of their module below `<dir>`, and go
296go into the table of the game's shaders, so graphics and compute pipeline creation find them through the lookup they 345into the table of the game's shaders, so `create_graphics` and `create_compute` find them through the lookups they
297already had (`fssm_program()` / `compute_program()` gives an `FSSM` program, looked up by `(stage, fssm_sha256)`). A 346already had (`compute_program()` gives an `FSSM` program, looked up by `(cs, fssm_sha256)`). A missing or
298missing or unreadable subfolder `index.json` leaves the other indexes loaded, and the main index is still required. 347unreadable `bvh/index.json` or `exe/index.json` leaves the other indexes loaded, and the main index is still
299`bvh_size()` and `exe_size()` count those entries, which `shader_library_corpus_test` leaves out of the entries a 348required. `bvh_size()` and `exe_size()` count those entries, which `shader_library_corpus_test` leaves out of the
300carved container must reach, like the FSPX ones. 349entries a carved container must reach, like the FSPX ones.
301 350
302**Measured: `LEONIDA_BVH_DEVICE=vulkan bvh_builder_test`** (package 1.0.2.1, `LEONIDA_BVH_RECORD62=1`, 351**Measured: `LEONIDA_BVH_DEVICE=vulkan bvh_builder_test`** (package 1.0.2.1, `LEONIDA_BVH_RECORD62=1`,
303`LEONIDA_SHADERS` on a folder holding this step's output and an empty main index, since only this step was run). 352`LEONIDA_SHADERS` on a folder holding this step's output and an empty main index, since only this step was run).
@@ -394,14 +443,3 @@ reason to run again, a second run that leaves no duplicate containers, the repor
394every run and the failure when nothing translates. `shader_library_test` covers the `bvh/` and `exe/` indexes (found 443every run and the failure when nothing translates. `shader_library_test` covers the `bvh/` and `exe/` indexes (found
395by the container's program hash, counted apart, a broken or missing index beside the others) and `d3d12_compute_test` 444by the container's program hash, counted apart, a broken or missing index beside the others) and `d3d12_compute_test`
396creates a pipeline through slot 62 whose only translation is in `<shaders>/bvh/index.json`. 445creates a pipeline through slot 62 whose only translation is in `<shaders>/bvh/index.json`.
397
398**Retail executable (`exe_shaders()`).** After `bvh_shaders()`, `make_game.py`'s `shaders` stage runs
399`exe_shaders()` on `<game>/game_scarlett_master.exe` when present (skipping cleanly and dropping any stale
400`<work>/shaders/spirv/exe/index.json` and `exe_build.json` when the package has no executable). It runs the same
401four tools into `<work>/shaders/exe` and `<work>/shaders/spirv/exe` (without `--max-shared-memory`, since the
402executable's containers are 1 VS + 9 PS graphics shaders), tracking inputs in `exe_build.json` and logging
403translated/missing counts on every run. Measured on 1.0.2.1: 10 of 10 programs translate and pass `spirv-val`
404natively and with `--wave64-emulate`, `ShaderLibrary::load` finds all 10 (`1 VS + 9 PS`) by `(stage, fssm_sha256)`,
405and `vk_pipeline_check` passes 10/10 modules and 10/10 pipelines (0 failed, 0 skipped) on an AMD Radeon RX 9070 XT
406(RADV GFX1201, Mesa 26.2.6) and an AMD Ryzen 7 9800X3D integrated GPU (RADV RAPHAEL_MENDOCINO, Mesa 26.2.6).
407`tests/test_exe_shaders_stage.py` covers the step on synthetic VS/PS `PSV0` containers without game data.