[PR #626] d3d12: serialize and deserialize XDXR acceleration structures (RT-XDXR-SERIALIZE) #665

Open
opened 2026-11-26 20:18:38 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/626
Author: @kawaii-shakal
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: rt-xdxr-serialize


📝 Commits (5)

  • dcac757 d3d12: serialize and deserialize XDXR acceleration structures (RT-XDXR-SERIALIZE)
  • acb9bb5 test: the XDXR postbuild readback-stage case takes the postbuild type argument
  • 78d3d92 Merge upstream XDXR address handling into serialization
  • b8d18a9 Merge upstream main into XDXR serialization
  • 0980d4e Merge upstream/main into rt-xdxr-serialize

📊 Changes

14 files changed (+9428 additions, -8306 deletions)

View changed files

📝 README.md (+1 -1)
📝 docs/bvh.md (+27 -5)
📝 docs/d3d12_vulkan.md (+4 -2)
📝 docs/xdxr.md (+1 -1)
📝 runtime/shims/d3d12_vulkan_device.cpp (+20 -9)
📝 runtime/src/vulkan_backend.h (+6 -4)
📝 runtime/src/vulkan_replay.h (+28 -11)
📝 runtime/src/xdxr_build.comp (+106 -6)
📝 runtime/src/xdxr_build.h (+46 -9)
📝 runtime/src/xdxr_build.inc (+8912 -8244)
📝 runtime/test/d3d12_xdxr_rt_test.cpp (+201 -11)
📝 runtime/test/replay_khr_as_copy_postbuild_test.cpp (+48 -2)
📝 runtime/test/replay_readback_stages_test.cpp (+1 -1)
📝 runtime/test/vk_xdxr_build_test.cpp (+27 -0)

📄 Description

Claimed in the coordination issue as: RT-XDXR-SERIALIZE (claim)

What and why

The README's "Ray tracing (BVH)" row and docs/bvh.md listed serialization as the builder's gap ("Not done yet: serialization"): on main, CopyRaytracingAccelerationStructure with SERIALIZE / DESERIALIZE and the SERIALIZATION postbuild info were refused at replay as unsupported for XDXR structures. This implements them.

  • runtime/src/xdxr_build.comp: MODE_SERIALIZE, MODE_DESERIALIZE, and MODE_POSTBUILD answering SERIALIZATION (16 bytes) next to the two sizes. The serialized form is:

    • D3D12's 56-byte D3D12_SERIALIZED_RAYTRACING_ACCELERATION_STRUCTURE_HEADER: the layer's own driver matching identifier (xdxr_build.h xdxr_serialized_id; GUID = ASCII Leonida XDXR AS , versioning data = header version 6 and serialized layout version 1), the serialized size, the deserialized size (the structure's own) and the pointer count;
    • one 8-byte BLAS address per INSTANCE record of a TLAS, in record order, read from the record (+60, 256-byte units);
    • then the structure's bytes as they are (the records are position-independent).

    DESERIALIZE copies the bytes back and writes each INSTANCE record's BLAS address from the pointer list, so BLASes an application moved and re-pointed are the ones the TLAS names.

  • runtime/src/xdxr_build.inc is regenerated with the command in xdxr_build_spv.h (glslc --target-env=vulkan1.2 -O -mfmt=c, shaderc v2026.4). That glslc reproduces the committed include for main's shader byte for byte, so the large diff is only the ID renumbering of this change; spirv-val --target-env vulkan1.2 accepts the module.

  • Replay (vulkan_replay.h, vulkan_backend.h): passes the copy mode and postbuild type through, steps SERIALIZATION descs 16 bytes apart, and bounds SERIALIZE / DESERIALIZE by the destination only, since a serialized structure is larger than the structure (bounding by the source too truncated a TLAS whose buffer is exactly its size). VISUALIZATION_DECODE_FOR_TOOLS and TOOLS_VISUALIZATION stay refused.

  • CheckDriverMatchingIdentifier (was a stub answering UNRECOGNIZED): COMPATIBLE_WITH_DEVICE for the layer's identifier, INCOMPATIBLE_VERSION for the same GUID with other versioning data, UNRECOGNIZED otherwise and always with LEONIDA_RT_AS=khr (the KHR path still refuses serialization; out of scope).

  • Docs: docs/bvh.md gets a Serialization paragraph; docs/d3d12_vulkan.md, docs/xdxr.md and the README row are updated.

Not measured, and said so in docs/bvh.md: the console's own serialized payload. XboxBvhBuilder.dll writes SERIALIZATION postbuild info in a handler of its own (docs/xdxr.md section 4); this layer's payload after the pointers is its own, and a blob carrying the console's identifier would be UNRECOGNIZED. Whether the game serializes at all is still open, like the rehydrate-or-rebuild question the README row ends with.

Tested

Windows 11 Pro 26300, MSVC 14.50 (VS 2026 Build Tools), Vulkan SDK 1.4.363.0, cmake --build runtime/build --config RelWithDebInfo.

  • d3d12_xdxr_rt now serializes the test's BLAS and three-instance TLAS, checks the SERIALIZATION postbuild info (56 + size and 56 + 3*8 + size), the headers, the identifier through CheckDriverMatchingIdentifier (and the two negative answers), the TLAS's three pointers and the payload bytes; deserializes the BLAS to another address, rewrites the TLAS's serialized pointers to it with CopyBufferRegion (state transitions UNORDERED_ACCESS → COPY_SOURCE → COPY_DEST → NON_PIXEL_SHADER_RESOURCE), deserializes the TLAS, and requires both copies to equal the originals byte for byte except the three instance BLAS addresses. d3d12_xdxr_rt_check then traces rays through the dumped copies against brute force:
    • d3d12_blas_deserialized: 0/1000 rays differ (711 hits); d3d12_tlas_deserialized: 0/1000 rays differ (776 hits).
  • Negative control: with MODE_DESERIALIZE ignoring the pointer list, d3d12_xdxr_rt fails with "deserialized TLAS: an instance's BLAS address is not the moved BLAS's".
  • replay_khr_as_copy_postbuild covers the replay contract: modes 3/4 reach xdxr_copy with their mode and destination-only bound, mode 2 is unsupported, SERIALIZATION descs land 16 bytes apart, a 24-byte destination for two of them is invalid_copy, TOOLS_VISUALIZATION is unsupported.
  • All 11 ray-tracing CTests (xdxr|dxr|khr_as|indirect_rt) pass on both GPUs below (bvh_builder skips, as on main).
  • Whole runtime suite (ctest -C RelWithDebInfo, RTX 5070 Ti): 292/293 pass. The one failure, d3d12_execute_indirect_validation (5 of 49 parity cases), fails identically on main with this change stashed; it is the known argument-range parity issue (#337, #306).
  • python -I scripts/check_no_game_data.py on every changed file, tests/test_text_write_line_endings.py: clean.
  • git merge-tree with main 21625bca8 and with #485 (which also touches xdxr_build.h): no conflicts.

GPUs tested: NVIDIA GeForce RTX 5070 Ti (Blackwell, driver 617.42, Vulkan 1.4.351); AMD Radeon 610M (Ryzen 9 7900X iGPU, AMD proprietary driver 2026.04.17, Vulkan 1.4.315, selected with LEONIDA_VK_DEVICE=radeon); Windows 11.

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/626 **Author:** [@kawaii-shakal](https://github.com/kawaii-shakal) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `rt-xdxr-serialize` --- ### 📝 Commits (5) - [`dcac757`](https://github.com/ubiquitarianism/leonida/commit/dcac757ab0606b7facda55357363819f94ebc9ed) d3d12: serialize and deserialize XDXR acceleration structures (RT-XDXR-SERIALIZE) - [`acb9bb5`](https://github.com/ubiquitarianism/leonida/commit/acb9bb5e4a217a7b50f99b3d2fae0e7a0964ec61) test: the XDXR postbuild readback-stage case takes the postbuild type argument - [`78d3d92`](https://github.com/ubiquitarianism/leonida/commit/78d3d923f7335753af365bb8b7ebf002a046b9a2) Merge upstream XDXR address handling into serialization - [`b8d18a9`](https://github.com/ubiquitarianism/leonida/commit/b8d18a97eff0325de35e254ab583e78f9a7f66b7) Merge upstream main into XDXR serialization - [`0980d4e`](https://github.com/ubiquitarianism/leonida/commit/0980d4e1e401a40ebb60a165a7771182a45c1e34) Merge upstream/main into rt-xdxr-serialize ### 📊 Changes **14 files changed** (+9428 additions, -8306 deletions) <details> <summary>View changed files</summary> 📝 `README.md` (+1 -1) 📝 `docs/bvh.md` (+27 -5) 📝 `docs/d3d12_vulkan.md` (+4 -2) 📝 `docs/xdxr.md` (+1 -1) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+20 -9) 📝 `runtime/src/vulkan_backend.h` (+6 -4) 📝 `runtime/src/vulkan_replay.h` (+28 -11) 📝 `runtime/src/xdxr_build.comp` (+106 -6) 📝 `runtime/src/xdxr_build.h` (+46 -9) 📝 `runtime/src/xdxr_build.inc` (+8912 -8244) 📝 `runtime/test/d3d12_xdxr_rt_test.cpp` (+201 -11) 📝 `runtime/test/replay_khr_as_copy_postbuild_test.cpp` (+48 -2) 📝 `runtime/test/replay_readback_stages_test.cpp` (+1 -1) 📝 `runtime/test/vk_xdxr_build_test.cpp` (+27 -0) </details> ### 📄 Description Claimed in the coordination issue as: RT-XDXR-SERIALIZE ([claim](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7127809054)) ### What and why The README's "Ray tracing (BVH)" row and `docs/bvh.md` listed serialization as the builder's gap ("Not done yet: serialization"): on `main`, `CopyRaytracingAccelerationStructure` with `SERIALIZE` / `DESERIALIZE` and the `SERIALIZATION` postbuild info were refused at replay as unsupported for XDXR structures. This implements them. - **`runtime/src/xdxr_build.comp`**: `MODE_SERIALIZE`, `MODE_DESERIALIZE`, and `MODE_POSTBUILD` answering `SERIALIZATION` (16 bytes) next to the two sizes. The serialized form is: - D3D12's 56-byte `D3D12_SERIALIZED_RAYTRACING_ACCELERATION_STRUCTURE_HEADER`: the layer's own driver matching identifier (`xdxr_build.h` `xdxr_serialized_id`; GUID = ASCII `Leonida XDXR AS `, versioning data = header version 6 and serialized layout version 1), the serialized size, the deserialized size (the structure's own) and the pointer count; - one 8-byte BLAS address per INSTANCE record of a TLAS, in record order, read from the record (+60, 256-byte units); - then the structure's bytes as they are (the records are position-independent). `DESERIALIZE` copies the bytes back and writes each INSTANCE record's BLAS address from the pointer list, so BLASes an application moved and re-pointed are the ones the TLAS names. - **`runtime/src/xdxr_build.inc`** is regenerated with the command in `xdxr_build_spv.h` (`glslc --target-env=vulkan1.2 -O -mfmt=c`, shaderc v2026.4). That glslc reproduces the committed include for `main`'s shader byte for byte, so the large diff is only the ID renumbering of this change; `spirv-val --target-env vulkan1.2` accepts the module. - **Replay** (`vulkan_replay.h`, `vulkan_backend.h`): passes the copy mode and postbuild type through, steps `SERIALIZATION` descs 16 bytes apart, and bounds `SERIALIZE` / `DESERIALIZE` by the destination only, since a serialized structure is larger than the structure (bounding by the source too truncated a TLAS whose buffer is exactly its size). `VISUALIZATION_DECODE_FOR_TOOLS` and `TOOLS_VISUALIZATION` stay refused. - **`CheckDriverMatchingIdentifier`** (was a stub answering `UNRECOGNIZED`): `COMPATIBLE_WITH_DEVICE` for the layer's identifier, `INCOMPATIBLE_VERSION` for the same GUID with other versioning data, `UNRECOGNIZED` otherwise and always with `LEONIDA_RT_AS=khr` (the KHR path still refuses serialization; out of scope). - **Docs**: `docs/bvh.md` gets a *Serialization* paragraph; `docs/d3d12_vulkan.md`, `docs/xdxr.md` and the README row are updated. Not measured, and said so in `docs/bvh.md`: the console's own serialized payload. `XboxBvhBuilder.dll` writes `SERIALIZATION` postbuild info in a handler of its own (`docs/xdxr.md` section 4); this layer's payload after the pointers is its own, and a blob carrying the console's identifier would be `UNRECOGNIZED`. Whether the game serializes at all is still open, like the rehydrate-or-rebuild question the README row ends with. ### Tested Windows 11 Pro 26300, MSVC 14.50 (VS 2026 Build Tools), Vulkan SDK 1.4.363.0, `cmake --build runtime/build --config RelWithDebInfo`. - `d3d12_xdxr_rt` now serializes the test's BLAS and three-instance TLAS, checks the `SERIALIZATION` postbuild info (`56 + size` and `56 + 3*8 + size`), the headers, the identifier through `CheckDriverMatchingIdentifier` (and the two negative answers), the TLAS's three pointers and the payload bytes; deserializes the BLAS to another address, rewrites the TLAS's serialized pointers to it with `CopyBufferRegion` (state transitions UNORDERED_ACCESS → COPY_SOURCE → COPY_DEST → NON_PIXEL_SHADER_RESOURCE), deserializes the TLAS, and requires both copies to equal the originals byte for byte except the three instance BLAS addresses. `d3d12_xdxr_rt_check` then traces rays through the dumped copies against brute force: - `d3d12_blas_deserialized`: 0/1000 rays differ (711 hits); `d3d12_tlas_deserialized`: 0/1000 rays differ (776 hits). - Negative control: with `MODE_DESERIALIZE` ignoring the pointer list, `d3d12_xdxr_rt` fails with "deserialized TLAS: an instance's BLAS address is not the moved BLAS's". - `replay_khr_as_copy_postbuild` covers the replay contract: modes 3/4 reach `xdxr_copy` with their mode and destination-only bound, mode 2 is unsupported, `SERIALIZATION` descs land 16 bytes apart, a 24-byte destination for two of them is `invalid_copy`, `TOOLS_VISUALIZATION` is unsupported. - All 11 ray-tracing CTests (`xdxr|dxr|khr_as|indirect_rt`) pass on both GPUs below (`bvh_builder` skips, as on `main`). - Whole runtime suite (`ctest -C RelWithDebInfo`, RTX 5070 Ti): 292/293 pass. The one failure, `d3d12_execute_indirect_validation` (5 of 49 parity cases), fails identically on `main` with this change stashed; it is the known argument-range parity issue (#337, #306). - `python -I scripts/check_no_game_data.py` on every changed file, `tests/test_text_write_line_endings.py`: clean. - `git merge-tree` with `main` 21625bca8 and with #485 (which also touches `xdxr_build.h`): no conflicts. GPUs tested: NVIDIA GeForce RTX 5070 Ti (Blackwell, driver 617.42, Vulkan 1.4.351); AMD Radeon 610M (Ryzen 9 7900X iGPU, AMD proprietary driver 2026.04.17, Vulkan 1.4.315, selected with `LEONIDA_VK_DEVICE=radeon`); Windows 11. AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#665
No description provided.