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 (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)) |

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
32 changes: 27 additions & 5 deletions docs/bvh.md
Original file line number Diff line number Diff line change
Expand Up @@ -1155,11 +1155,33 @@ 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
`64 * (totalSizeIn64BNodes + 1)`, and compaction gives back the room the layout left for more nodes. 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 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.

```powershell
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
29 changes: 20 additions & 9 deletions runtime/shims/d3d12_vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4272,7 +4272,8 @@ struct DeviceState {
// copy by it). The source's size comes from its build when the layer saw it, else from its header only.
bool resolve_xdxr_copy(leonida::CopyAccelerationStructure& c) {
if (!context || !context->xdxr_acceleration_structures()) return true;
const std::uint64_t known = bvh_known_size(c.src_va);
const bool deserialize = c.mode == leonida::XdxrBuilder::copy_deserialize;
const std::uint64_t known = deserialize ? 0 : bvh_known_size(c.src_va);
const std::uint64_t want = known ? known : leonida::XdxrLayout::header_size;
const std::uint64_t title_dst = c.dst_va;
std::uint64_t out = 0, room = 0;
Expand All @@ -4284,15 +4285,15 @@ struct DeviceState {
return bvh_refuse(bvh_copy_dst, c.dst_va, want), false;
c.dst_va = out;
c.dst_room = room;
if (known) bvh_note_size(title_dst, known);
if (known && c.mode != leonida::XdxrBuilder::copy_serialize) bvh_note_size(title_dst, known);
return true;
}

// A postbuild: its destination (8 bytes a source) and each source structure's header, which it reads.
// A postbuild: its destination and each source structure's header, which it reads.
bool resolve_xdxr_postbuild(leonida::AccelerationStructurePostbuild& info) {
if (!context || !context->xdxr_acceleration_structures()) return true;
std::uint64_t out = 0, room = 0;
const std::uint64_t bytes = 8ull * info.sources.size();
const std::uint64_t bytes = std::uint64_t(leonida::XdxrBuilder::postbuild_size(info.type)) * info.sources.size();
if (!bvh_va(info.dest_va, bytes, true, out, &room) || (out & 7))
return bvh_refuse(bvh_postbuild_dst, info.dest_va, bytes), false;
info.dest_va = out;
Expand Down Expand Up @@ -17991,12 +17992,22 @@ class Device final
return E_INVALIDARG;
}

// STUB
// Serialized acceleration structures this device writes start with leonida::xdxr_serialized_id (xdxr_build.h):
// the same GUID and versioning data are compatible, the same GUID with other versioning data is another layout.
// With LEONIDA_RT_AS=khr nothing is serialized (the KHR path refuses SERIALIZE), so nothing is recognised.
D3D12_DRIVER_MATCHING_IDENTIFIER_STATUS STDMETHODCALLTYPE CheckDriverMatchingIdentifier(
D3D12_SERIALIZED_DATA_TYPE type, const D3D12_SERIALIZED_DATA_DRIVER_MATCHING_IDENTIFIER*) override {
return type == D3D12_SERIALIZED_DATA_RAYTRACING_ACCELERATION_STRUCTURE
? D3D12_DRIVER_MATCHING_IDENTIFIER_UNRECOGNIZED
: D3D12_DRIVER_MATCHING_IDENTIFIER_UNSUPPORTED_TYPE;
D3D12_SERIALIZED_DATA_TYPE type, const D3D12_SERIALIZED_DATA_DRIVER_MATCHING_IDENTIFIER* id) override {
if (type != D3D12_SERIALIZED_DATA_RAYTRACING_ACCELERATION_STRUCTURE)
return D3D12_DRIVER_MATCHING_IDENTIFIER_UNSUPPORTED_TYPE;
if (!id || !state_.info.xdxr_acceleration_structures || !state_.info.buffer_device_address)
return D3D12_DRIVER_MATCHING_IDENTIFIER_UNRECOGNIZED;
static_assert(sizeof(D3D12_SERIALIZED_DATA_DRIVER_MATCHING_IDENTIFIER) == sizeof(leonida::xdxr_serialized_id));
const auto* ours = reinterpret_cast<const unsigned char*>(leonida::xdxr_serialized_id);
if (std::memcmp(&id->DriverOpaqueGUID, ours, sizeof(GUID)) != 0)
return D3D12_DRIVER_MATCHING_IDENTIFIER_UNRECOGNIZED;
return std::memcmp(id->DriverOpaqueVersioningData, ours + sizeof(GUID), sizeof(id->DriverOpaqueVersioningData)) == 0
? D3D12_DRIVER_MATCHING_IDENTIFIER_COMPATIBLE_WITH_DEVICE
: D3D12_DRIVER_MATCHING_IDENTIFIER_INCOMPATIBLE_VERSION;
}

// STUB
Expand Down
10 changes: 6 additions & 4 deletions runtime/src/vulkan_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -1263,13 +1263,15 @@ class VulkanContext {
xdxr_pair(b));
}
};
replay_.xdxr_copy = [this](VkCommandBuffer cb, std::uint64_t src, std::uint64_t dst, std::uint64_t bytes) {
replay_.xdxr_copy = [this](VkCommandBuffer cb, std::uint64_t src, std::uint64_t dst, std::uint64_t bytes,
std::uint32_t mode, std::uint64_t source_bytes) {
const std::uint64_t base = replay_.heap_base;
xdxr_->record_copy(cb, base + src, base + dst, bytes);
xdxr_->record_copy(cb, base + src, base + dst, bytes, mode, source_bytes);
};
replay_.xdxr_postbuild = [this](VkCommandBuffer cb, std::uint64_t src, std::uint64_t dest) {
replay_.xdxr_postbuild = [this](VkCommandBuffer cb, std::uint64_t src, std::uint64_t dest,
std::uint32_t type) {
const std::uint64_t base = replay_.heap_base;
xdxr_->record_postbuild(cb, base + src, base + dest);
xdxr_->record_postbuild(cb, base + src, base + dest, type);
};
} else {
xdxr_.reset();
Expand Down
Loading
Loading