Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ itself measured about 10 frames a second at the same place earlier that day (med
| Music/radio config | ? Measured. **1,589** audio-config records with exact durations and AWC stream ids; station grouping and content-id lists; no per-track start offsets ([notes](docs/audio_config.md)) |
| PE loader and import shims | ⚠️ Runs a stand-in executable end to end (`gta6rt --run`: CRT startup, statics, heap, files, threads, GDK imports through the shims, exit code back). Controllers through a GameInput shim on SDL3 (any controller SDL supports, rumble, DualSense trigger effects and lightbar; built when SDL3 is installed or with `-DLEONIDA_SDL3_FETCH=ON`, [notes](docs/gameinput.md)). `--trace-d3d12` logs every D3D12 call and its outcome for the first boot. Runs the game's own executable through the story load ([report](docs/linux_proton.md)) |
| Xbox D3D12 → Vulkan | ⚠️ In progress. A Vulkan-backed device behind the Xbox-ABI proxy creates queues, command lists, fences, descriptor heaps, committed, placed and reserved resources, render-target and depth views (3D targets included), texture views and samplers (2D, cube, 1D and 3D views, the depth and stencil planes of depth-stencil textures, packed formats such as B5G6R5, B4G4R4A4 and R9G9B9E5, buffer SRVs — raw, structured and typed; they go into the bindless set), root signatures, pipelines and query heaps, and draws run on Vulkan. Barriers, clears, uploads, copies (BC included), colour resolves, predication, CPU-side texture reads and writes, and occlusion, timestamp and pipeline-statistics queries run on Vulkan, checked on one GPU. The console-shaped command-list proxy, the measured `PresentX` queue slots (30/32, layout-detected) wired to the presentation core, and `AllocateUploadMemory` (list slot 148, a mapped-upload arena whose addresses translate to buffer device addresses in root descriptors and IA/SO views) cover the console-ABI surface the package measures. Still open: the console list tail and the descriptor-table record model ([plan](docs/d3d12_vulkan.md), [console ABI](docs/d3d12_xs_console_abi.md)) |
| Ray tracing (BVH) | ⚠️ In progress. `BuildRaytracingAccelerationStructure` builds BLASes and TLASes on the GPU in the console's XDXR BVH4 layout (the default; `LEONIDA_RT_AS=khr` uses Vulkan's own acceleration structures instead), which the translated shaders walk themselves through `image_bvh_intersect_ray` (all four triangle node types, TRI0-TRI3, with the barycentric remap byte); the GPU builder writes TRI0 and TRI1 leaves. Updates refit instead of rebuilding, and clone, compaction and the compacted/current postbuild sizes work; checked against a CPU reference on synthetic scenes. The build descriptions are recovered from the package's `XboxBvhBuilder.dll` ([notes](docs/xdxr.md)). The game's `*_bvh4.rpf` packs are measured: offline-built, dehydrated BLASes that rehydrate through that DLL with their geometry from the drawables in `levels.rpf` (measured on 8 of the 10 sampled BLAS; [notes](docs/bvh.md)). Not done in the builder: serialization. TRI1 pairing (no memory saved yet) and BOX16 nodes for `MINIMIZE_MEMORY` BLASes (an assumed switch) are in ([notes](docs/bvh.md)). Open: whether the game rehydrates the packs or rebuilds them ([#313](https://github.com/ItsNotRexed/Leonida/issues/313)) |
| Ray tracing (BVH) | ⚠️ In progress. `BuildRaytracingAccelerationStructure` builds BLASes and TLASes on the GPU in the console's XDXR BVH4 layout (the default; `LEONIDA_RT_AS=khr` uses Vulkan's own acceleration structures instead), which the translated shaders walk themselves through `image_bvh_intersect_ray` (all four triangle node types, TRI0-TRI3, with the barycentric remap byte); the GPU builder writes TRI0 and TRI1 leaves. Updates refit instead of rebuilding, and clone, compaction and the compacted/current postbuild sizes work; checked against a CPU reference on synthetic scenes. The build descriptions are recovered from the package's `XboxBvhBuilder.dll` ([notes](docs/xdxr.md)). The game's `*_bvh4.rpf` packs are measured: offline-built, dehydrated BLASes that rehydrate through that DLL with their geometry from the drawables in `levels.rpf` (measured on 8 of the 10 sampled BLAS; [notes](docs/bvh.md)). Serialization and deserialization work too, under the layer's own driver identifier, with the BLAS pointers an application rewrites honoured; checked on an RTX 5070 Ti and a Radeon 610M ([notes](docs/bvh.md)). TRI1 pairing (one 64-byte leaf a pair: 14% smaller on a 7,200-triangle grid) and BOX16 nodes for `MINIMIZE_MEMORY` BLASes (an assumed switch) are in ([notes](docs/bvh.md)). Open: whether the game rehydrates the packs or rebuilds them ([#313](https://github.com/ItsNotRexed/Leonida/issues/313)) |

The table above is written by hand. To measure it on your own checkout (unit and runtime tests, which rows of
the translator contract were confirmed on a GPU, measured imports, your corpus counts and, with `--github`, CI
Expand Down
72 changes: 56 additions & 16 deletions docs/bvh.md
Original file line number Diff line number Diff line change
Expand Up @@ -1099,26 +1099,42 @@ zeroed 64-byte unit after the last node it wrote, and the header's size counts i
64-byte node would otherwise be read past the structure, or past a compacted copy of it.

**TRI1 pairing.** A bottom-level build without `ALLOW_UPDATE` pairs triangles into TRI0/TRI1 leaves, as the console
builder does in its offline BLASes (§4a, check 4 of "How a match is verified"). The pass that writes the nodes
pairs each triangle child of a node with a later triangle child of the same node (among its at most four children)
builder does in its offline BLASes (§4a, check 4 of "How a match is verified"). A pass after the tree is known
(`MODE_PAIR`) pairs each triangle child of a node with a later triangle child of the same node (among its at most four children)
when four things hold. The two must share an edge in opposite directions, with the same two vertices bit for bit. They must come from
the same geometry, since a leaf holds one `GeometryIndexAndFlags`. And both must be active. The first triangle is
rotated so the shared edge is slots 1 -> 2, the sibling's third vertex goes in slot 3, its primitive index in
`PrimitiveIndex2`, and each node type's remap byte returns D3D12's barycentrics for its own vertex order. The node
still has one child per triangle, each with its own box: the TRI1 child points at the first triangle's leaf, and the
sibling's own leaf is left unused. The tree, the layout and the sizes are therefore the same as without pairing.
Nothing is saved yet: reclaiming the unused leaves would need a compaction that moves records and rewrites pointers,
and compaction here copies bytes. What pairing gives is the console's leaf format, with a pair's two triangles in
one 64-byte record. Because pairs never cross nodes, one thread owns each leaf it rewrites, and both pointers of a
pair have the same parent, so the parent table has one writer per entry. The pass records each triangle's pointer
still has one child per triangle, each with its own box: the TRI1 child points at the first triangle's leaf, so the
tree is the same as without pairing.

The leaves are laid out densely, one 64-byte record a pair, as the console's are (§4a: one `Leaf` per entry, an entry
holding the second primitive). A paired build writes its leaves to scratch first; once the pairs are chosen, a scan
over the leaves that stay (the dropped ones are the siblings') gives each its place, they are copied into the
element region in element order, and the nodes start right after the last one. `offsetToNodes` (+40) says where, and
the nodes, their pointers and the parent table are written for those places directly, so nothing is moved
afterwards. `numElements` stays the triangle count, as `build_blas` writes it, the count of triangle pointers. The
build is therefore 64 bytes smaller per pair: its header's size, `COMPACTED_SIZE` and `CURRENT_SIZE`, and what a
`COMPACT` copy keeps. The prebuild room is unchanged (a leaf per triangle, since the pairs are not known before the
build); the scratch grows by 80 bytes a triangle for the leaves and their bookkeeping, and only for a bottom-level
build without `ALLOW_UPDATE` (`XdxrLayout::pair`, which `GetRaytracingAccelerationStructurePrebuildInfo` reads from
the same flag). On the 288-triangle grid of `vk_xdxr_build_test`, 80 pairs make it 34,048 bytes against 39,168
unpaired; the 7,200-triangle grid's 2,208 pairs, 846,848 against 988,160 (14%). The pairing step only records each
pair and its rotation; the step that copies the leaves into the structure writes a pair's leaf from the two staged
ones, so no invocation stores to a word it loaded earlier in the same dispatch (the SPIRV-Cross reordering in MoltenVK
1.4.2 noted in `xdxr_build.comp`; rewriting the first triangle's staged leaf in place lost pairs on an Apple M5 Pro).
Because pairs never cross nodes, one thread owns each pair, and both pointers of a
pair have the same parent, so the parent table has one writer per entry. The node pass records each triangle's pointer
(TRI0, or TRI1 for the sibling) in scratch, so the bottom-up box pass finds the sibling's slot through the first
triangle's leaf. On a sorted grid of 7,200 triangles, 2,208 of the 3,600 possible pairs form (2,625 with the tree of four
consecutive elements: a radix-tree node often has an inner node among its children, and only triangle children
pair). A refit rewrites every leaf as one triangle, so a structure that may be updated is
not paired. **ASSUMPTION:** that pairing only siblings is close enough. The console builder's pairing rule is not
traced; `tools/xdxr_bvh.py` `build_blas(pair=True)` pairs greedily over the whole mesh instead, and both traverse
the same way. `check-build` compares barycentrics as well as hits, and checks that a paired case has TRI1 nodes and
that cases that must not pair (other geometry, same direction) have none.
the same way. `check-build` compares barycentrics as well as hits, and checks that a paired case has TRI1 nodes,
that cases that must not pair (other geometry, same direction) have none, and that no 64-byte unit of a BLAS's
element region is left without a triangle pointer (`unreferenced_leaves`: the unused sibling leaves the builder
kept before it laid the leaves out densely).

The node count depends on the keys. A kept node has two children only when both of its binary children are
elements, so with N elements there are at most (3N - 2) / 4 nodes. `XdxrLayout` computes the result and scratch
Expand Down Expand Up @@ -1155,12 +1171,36 @@ names its BLASes by address, which a clone keeps. The size comes from the source
a copy can follow a build in the same command list, and it is bounded by the destination resource. A build's size
is the nodes it wrote, so `COMPACTED_SIZE` and `CURRENT_SIZE` (from
`EmitRaytracingAccelerationStructurePostbuildInfo` or the postbuild descs of a build) are both
`64 * (totalSizeIn64BNodes + 1)`, and compaction gives back the room the layout left for more nodes. Serialization, deserialization and the tools-visualization
mode are refused at replay as unsupported, not faked. In `LEONIDA_RT_AS=khr` mode the postbuild descs stay ignored,
as before.

Not done yet: serialization; a compaction that reclaims the leaves that pairing leaves unused. A surface-area
collapse of the radix tree, or treelet restructuring, would trim a few more steps.
`64 * (totalSizeIn64BNodes + 1)`, and compaction gives back the room the layout left for more nodes and, in a
paired build, the 64 bytes a pair its leaves no longer take. The
tools-visualization copy mode and postbuild type are refused at replay as unsupported, not faked. In
`LEONIDA_RT_AS=khr` mode the postbuild descs stay ignored and serialization is refused, as before.

**Serialization.** `CopyRaytracingAccelerationStructure` with `SERIALIZE` writes D3D12's serialized form
(`xdxr_build.comp` `MODE_SERIALIZE`): the 56-byte `D3D12_SERIALIZED_RAYTRACING_ACCELERATION_STRUCTURE_HEADER`, then
`NumBottomLevelAccelerationStructurePointersAfterHeader` 8-byte BLAS addresses, then the structure's bytes as they
are. The header's driver matching identifier is the layer's own (`xdxr_build.h` `xdxr_serialized_id`: the GUID is the
ASCII `Leonida XDXR AS `, the versioning data the header version 6 and the serialized layout version 1), and
`CheckDriverMatchingIdentifier` answers `COMPATIBLE_WITH_DEVICE` for it, `INCOMPATIBLE_VERSION` for the same GUID
with other versioning data, and `UNRECOGNIZED` otherwise (always, with `LEONIDA_RT_AS=khr`). A TLAS carries one
pointer per INSTANCE record, in record order, read from the record's BLAS address (+60, 256-byte units; 0 for an
instance without a BLAS); a BLAS carries none. The deserialized size is the structure's own. `DESERIALIZE` copies the
bytes back and writes each INSTANCE record's BLAS address from the pointer list, so an application that moved its
BLASes (deserialized them elsewhere) and rewrote the pointers gets a TLAS that names them; the rest of the record
stays, since a deserialized BLAS is the same structure and its records count from its own start. The `SERIALIZATION`
postbuild desc (16 bytes) gives the serialized size, `56 + 8 * pointers + 64 * (totalSizeIn64BNodes + 1)`, and the
pointer count. Both copies are bounded by the destination resource only, since a serialized structure is larger than
the structure. The payload after the pointers is this layer's: the console's own serialized form (`XboxBvhBuilder.dll`
writes `SERIALIZATION` postbuild info in a handler of its own, [xdxr.md](xdxr.md) section 4) is not measured, and a
blob with the console's identifier would be `UNRECOGNIZED`. `d3d12_xdxr_rt_test` serializes a BLAS and a three-instance
TLAS, deserializes the BLAS to another address, rewrites the TLAS's pointers to it and deserializes the TLAS; the
copies must equal the originals byte for byte but for the three BLAS addresses, and `d3d12_xdxr_rt_check` traces
1,000 rays through each against brute force (RTX 5070 Ti, NVIDIA 617.42, and the Ryzen 9 7900X's Radeon 610M, AMD
2026.04.17, Windows 11: 0 rays differ).

Not done yet: a surface-area collapse of the radix tree, or treelet restructuring, would trim a few more steps; the
room the layout keeps for the most nodes a tree can have, and for a leaf per triangle, is only given back by a
`COMPACT` copy.

```powershell
python -I tools/xdxr_bvh.py selftest --seed 1 --rays 400 # build BLASes, compare closest hits with brute force
Expand Down
6 changes: 4 additions & 2 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -4832,8 +4832,10 @@ Vulkan AS would be invisible to them. Two paths:
DEFAULT and READBACK lists are refused as `unsupported` before submission, since their mapped bytes can still hold
an earlier frame's pointers when the CPU prepares the build. Completed staging buffers
are reused, so a per-frame rebuild does not allocate memory each frame. Updates refit the source structure instead of rebuilding it, `CopyRaytracingAccelerationStructure` clones and compacts, and the
postbuild compacted and current sizes are written ([bvh.md](bvh.md) §7a). Serialization and the Xbox
batched/streaming builds are not implemented. The
postbuild compacted and current sizes are written ([bvh.md](bvh.md) §7a), and so are serialization,
deserialization (with the BLAS pointers the application rewrites) and the `SERIALIZATION` postbuild info, under
the layer's own driver matching identifier ([bvh.md](bvh.md), *Serialization*). The Xbox batched/streaming builds
are not implemented. The
reported `RaytracingTier` is unchanged (`NOT_SUPPORTED`). Checked by `runtime/test/d3d12_xdxr_rt_test.cpp` through
the D3D12 API.

Expand Down
2 changes: 1 addition & 1 deletion docs/xdxr.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Default for type 0's `0x08` value when it is negative (or when there is no type-
| `InfoType` | In `XboxBvhBuilder.dll` |
|---|---|
| 0 `COMPACTED_SIZE`, 3 `CURRENT_SIZE` | written by one handler |
| 2 `SERIALIZATION` | written by another handler |
| 2 `SERIALIZATION` | written by another handler (the layer writes its own serialized form; [bvh.md](bvh.md), *Serialization*) |
| 1 `TOOLS_VISUALIZATION` and other values | ignored, no error |
| `0x10` `D3D12XBOX_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_OFFLINE_STATISTICS` | thrown as `E_INVALIDARG` by `0xe6a0` before any work, for every build: the DLL only supports it for offline BVH builds |

Expand Down
Loading
Loading