diff options
| author | Joao vitor alves <177051894+Joaovitor404silva@users.noreply.github.com> | 2026-11-22 15:42:01 -0300 |
|---|---|---|
| committer | Joao vitor alves <177051894+Joaovitor404silva@users.noreply.github.com> | 2026-11-22 17:48:57 -0300 |
| commit | feee3e6c1fbdfc0713323bcd64935d39bb1663cb (patch) | |
| tree | 8ee6ba345e312359a8820e5334e445cf9a5fd875 /docs | |
| parent | f847748cc76bd3777f9c070c4034eb2fc1c04e64 (diff) | |
Real-shader sandbox: placed props through a translated VS/PS pair
vk_sandbox draws the props around a point with one translated game VS/PS
pair chosen by signature and descriptor layout: a real camera through the
VS constants, DiffuseTex albedo through the bindless set and the PS's own
S#, depth, and a fly/walk/drive window. tools/sandbox.py packs the scene
(tools/sandbox_scene.py), picks the pair and runs it; --check prints
counts only. docs/sandbox.md has the table layout and the measurements.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PiKMETzszqwfnV8QQyzocY
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/README.md | 1 | ||||
| -rw-r--r-- | docs/sandbox.md | 86 |
2 files changed, 87 insertions, 0 deletions
diff --git a/docs/README.md b/docs/README.md index 5eff8e3c1..f8dcfd0c3 100644 --- a/docs/README.md +++ b/docs/README.md | |||
| @@ -73,6 +73,7 @@ method, scope and caveats. No game data is included. | |||
| 73 | | [fspx.md](fspx.md) | `FSPX`, the FidelityFX DLL's native compute programs (its shaders' `ACCC` part): directory as the DLL reads it, kind-0 dispatch state, the hash prologue, `gfx1030` for its `v_dot4` code; 13 of 29 translate with `tools/fspx_unpack.py`. | | 73 | | [fspx.md](fspx.md) | `FSPX`, the FidelityFX DLL's native compute programs (its shaders' `ACCC` part): directory as the DLL reads it, kind-0 dispatch state, the hash prologue, `gfx1030` for its `v_dot4` code; 13 of 29 translate with `tools/fspx_unpack.py`. | |
| 74 | | [first_light.md](first_light.md) | The first draw of a real game model with its own translated VS/PS on a GPU: 4,213 vertices / 7,968 triangles, 78.1% coverage on an RTX 2060 SUPER; `tools/first_light.py`, the `vk_harness` mesh mode, and the same draw through the D3D12 layer (`d3d12_first_light`). | | 74 | | [first_light.md](first_light.md) | The first draw of a real game model with its own translated VS/PS on a GPU: 4,213 vertices / 7,968 triangles, 78.1% coverage on an RTX 2060 SUPER; `tools/first_light.py`, the `vk_harness` mesh mode, and the same draw through the D3D12 layer (`d3d12_first_light`). | |
| 75 | | [embedded_shaders.md](embedded_shaders.md) | DXBC containers embedded in the package's DLLs: 52 in `XboxBvhBuilder.dll` (console `FSSM` via the `XDAT`/`XBCH` record; 51/52 pass `spirv-val` today) and 29 `ACCC`/`FSPX` in the FidelityFX upscaler; the scan/extract tool and the one rule still missing. | | 75 | | [embedded_shaders.md](embedded_shaders.md) | DXBC containers embedded in the package's DLLs: 52 in `XboxBvhBuilder.dll` (console `FSSM` via the `XDAT`/`XBCH` record; 51/52 pass `spirv-val` today) and 29 `ACCC`/`FSPX` in the FidelityFX upscaler; the scan/extract tool and the one rule still missing. | |
| 76 | | [sandbox.md](sandbox.md) | Placed world props through one translated VS/PS pair with a real camera, TTPF albedo and the game's sampler: 442 of 446 draws textured; fly/walk/drive window, `tools/sandbox.py --check`. | | ||
| 76 | | [coder.md](coder.md) | The compressed mass in `story000_script.rpf`: entry framing (`align16(entry+8)` payload), the 32-value tag alphabet, deflate-shaped but proprietary, variable-length 7/8-bit LSB-first codes with no stored table, and the `n7 = 116..127` search that finishes it. | | 77 | | [coder.md](coder.md) | The compressed mass in `story000_script.rpf`: entry framing (`align16(entry+8)` payload), the 32-value tag alphabet, deflate-shaped but proprietary, variable-length 7/8-bit LSB-first codes with no stored table, and the `n7 = 116..127` search that finishes it. | |
| 77 | | [mission_logic.md](mission_logic.md) | Mission state tables: 0x20 record layout (band counter, byte offsets), the 64-byte pool element with world transforms, case-folding joaat keys, 53.5 % of states named, 113 state-set clusters covering 82.4 % of files. | | 78 | | [mission_logic.md](mission_logic.md) | Mission state tables: 0x20 record layout (band counter, byte offsets), the 64-byte pool element with world transforms, case-folding joaat keys, 53.5 % of states named, 113 state-set clusters covering 82.4 % of files. | |
| 78 | 79 | ||
diff --git a/docs/sandbox.md b/docs/sandbox.md new file mode 100644 index 000000000..e86fdfe81 --- /dev/null +++ b/docs/sandbox.md | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | # Real-shader sandbox: placed props through the game's own translated shaders | ||
| 2 | |||
| 3 | Follows [first_light.md](first_light.md) §5: a real camera through a vertex shader's constants, a TTPF albedo | ||
| 4 | through the bindless set with the game's sampler, and many placed world props instead of one model. Measured on | ||
| 5 | 2026-11-22 from one retail Xbox Series install (1.0.2.1), on an NVIDIA GeForce RTX 4070 Ti SUPER (driver 621.24). | ||
| 6 | Nothing below reproduces game data; every number is a count. | ||
| 7 | |||
| 8 | ## 1. What runs | ||
| 9 | |||
| 10 | `tools/sandbox.py` packs the props around a point (`tools/sandbox_scene.py`), picks one translated VS/PS pair from | ||
| 11 | the work folder and runs `runtime/test/vk_sandbox`, which draws every prop with that pair: vertex buffers at | ||
| 12 | locations 0–2 (position, normal, UV), a D32 depth buffer, one indexed draw per mesh and one descriptor table per | ||
| 13 | draw. `--window` opens a window to fly, walk or drive through the scene; `--check` renders one frame headless and | ||
| 14 | prints only counts. | ||
| 15 | |||
| 16 | The shaders are not stand-ins: the VS transforms each vertex with the world rows and view-projection it loads from | ||
| 17 | the heap and lights it with its own `max(0.25, n·l)`; the PS samples the albedo through the T# it loads and the | ||
| 18 | S# literal in its code, and multiplies by the VS colour. Lighting beyond that, shadows and the G-buffer passes are | ||
| 19 | not part of this pair. | ||
| 20 | |||
| 21 | ## 2. How the pair is chosen | ||
| 22 | |||
| 23 | The material → program table is in the executable (#2519), so the pair is chosen by what the shaders read, from | ||
| 24 | `<work>/shaders/spirv/index.json` and the listings in `<work>/shaders/dxbc/disasm`: | ||
| 25 | |||
| 26 | | | Vertex shader | Pixel shader | | ||
| 27 | |---|---|---| | ||
| 28 | | inputs | POSITION (xyz), NORMAL (xyz), TEXCOORD (xy) | SV_Position, TEXCOORD, COLOR | | ||
| 29 | | user data | user SGPR 8 only (`ptr32_lo`) | user SGPR 8 (`ptr32_lo`) | | ||
| 30 | | bindings | none | 0, 1, 2 (images, samplers, hash table) | | ||
| 31 | | listing | three `s_load_dwordx4` from `s[8:9]` at 0x0, 0x40, 0x60; a 4-dword buffer load at 0x30 and a 16-dword one at 0x160 | one `s_load_dwordx8` from `s[8:9]` + 0x20; one `image_sample`; `exp mrt0` | | ||
| 32 | |||
| 33 | On the 1.0.2.1 corpus 3 VS and 231 PS match the signatures, and 2 VS and 4 PS also match the listing patterns; | ||
| 34 | they share one table layout. `tests/test_sandbox_pick.py` checks the picker on hand-written listings. | ||
| 35 | |||
| 36 | ## 3. The table the pair reads | ||
| 37 | |||
| 38 | User SGPR 8 is a 32-bit pointer (the shaders force the high dword to 0) to one table in the heap: | ||
| 39 | |||
| 40 | | Offset | Descriptor | Contents (byte offsets in the buffer) | | ||
| 41 | |---|---|---| | ||
| 42 | | 0x00 | V# | world rows 0–2 at 0x00, 0x10, 0x20 (xyz each), translation at 0x30; world = x·row0 + y·row1 + z·row2 + row3 | | ||
| 43 | | 0x20 | T# | the albedo image (8 dwords) | | ||
| 44 | | 0x40 | V# | light direction at 0xa0; view-projection at 0x160, clip = wx·r0 + wy·r1 + wz·r2 + r3 (D3D clip, y up, z 0..1) | | ||
| 45 | | 0x60 | V# | colour at 0x00 (rgb × the lighting term, alpha as is) | | ||
| 46 | |||
| 47 | `vk_sandbox` writes raw V#s (stride 0, NUM_RECORDS = the buffer's bytes, OOB_SELECT 3), registers each texture's | ||
| 48 | T# words and the PS's S# literal in the descriptor hash table, builds the sampler from those S# words | ||
| 49 | (`gfx10::decode`), and draws through a negative-height viewport so the D3D-convention matrices stay unchanged. | ||
| 50 | |||
| 51 | ## 4. Reproduce it | ||
| 52 | |||
| 53 | ```sh | ||
| 54 | python -I tools/world_index.py ... --entities-out <work>/entities.jsonl # placements (docs/world.md) | ||
| 55 | rpf9dump models "<package>/levels.rpf" <work>/assets | ||
| 56 | rpf9dump ttpf "<package>/data/ttdb/maps/ttdb_maps_<n>_7.ttpf" <work>/ttpf_maps # n = 0..7 | ||
| 57 | rpf9dump ttpf "<package>/data/ttdb/terrain/ttdb_terrain_<n>_7.ttpf" <work>/ttpf_terrain # n = 0..7 | ||
| 58 | cmake --build runtime/build --target vk_sandbox | ||
| 59 | python -I tools/sandbox.py --work <work> --entities <work>/entities.jsonl --models <work>/assets \ | ||
| 60 | --textures <work>/ttpf_maps --textures <work>/ttpf_terrain [--center X Y] --window | ||
| 61 | ``` | ||
| 62 | |||
| 63 | Window keys: WASD move, right mouse button held to look, Q/E down/up (fly), Shift faster, 1 fly, 2 walk (eye 1.7 m | ||
| 64 | over the highest scene triangle under the camera), 3 drive (eye 1.2 m, accelerates and steers), P screenshot, | ||
| 65 | Esc quit. `--center` is in RAGE world metres; without it the densest 50 m cell of resolved props is used. | ||
| 66 | |||
| 67 | ## 5. Measured | ||
| 68 | |||
| 69 | | | | | ||
| 70 | |---|---| | ||
| 71 | | map pools (8) | 133,697 textures exported, 0 failed, 7,030 skipped | | ||
| 72 | | terrain pools (8) | 46,115 exported, 0 failed, 26,903 skipped (`rpf9dump`'s limits in [textures.md](textures.md)) | | ||
| 73 | | test scene (one `levels.rpf` window) | 600 entities within 120 m, 150 placed (402 have no exported model in that window), 446 draws, 178 meshes, 345,782 triangles | | ||
| 74 | | albedo | the material's DiffuseTex reference (`Param` = `joaat("DiffuseTex")` = `C8E8C282`): 422 of 446 draws textured with 93 textures from the map and terrain pools (69 with the map pools alone). Two-layer blend materials have no DiffuseTex: 11 references each, two albedos, two normal maps, packed maps and a blend mask; the first layer's albedo (`Param` `346394EA`, name unknown) brings it to 442 of 446 draws and 107 textures | | ||
| 75 | | `--check` (640×360) | 114,503 pixels covered, 4,736 distinct colours (147 with the textures left out) | | ||
| 76 | | window | about 90 frames per second with a `vkQueueWaitIdle` per frame; a 60-frame windowed run ends on the same pixels as the headless render | | ||
| 77 | | walk / drive | eye at 1.70 m / 1.20 m over the roof the camera starts above | | ||
| 78 | |||
| 79 | ## 6. Limits and next | ||
| 80 | |||
| 81 | * One pair, one forward pass. The world's own material shaders pull vertices (`SV_VertexID` only) and write the | ||
| 82 | G-buffer; drawing those needs their vertex fetch tables and the lighting passes that read the G-buffer. | ||
| 83 | * The scene stores mip 0 box-scaled to 256 px (`--tex-size`), so the sampler's LOD range is clamped to 0. | ||
| 84 | * Ground following uses the scene's own triangles; there is no collision against walls. | ||
| 85 | * Draws are not culled or sorted, and every frame waits for the GPU; a large `--max-props` gets slow (each prop is | ||
| 86 | one draw per mesh: 150 props gave 446 draws). | ||