mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 22:10:52 +01:00
[PR #626] d3d12: serialize and deserialize XDXR acceleration structures (RT-XDXR-SERIALIZE) #665
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#665
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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)
dcac757d3d12: serialize and deserialize XDXR acceleration structures (RT-XDXR-SERIALIZE)acb9bb5test: the XDXR postbuild readback-stage case takes the postbuild type argument78d3d92Merge upstream XDXR address handling into serializationb8d18a9Merge upstream main into XDXR serialization0980d4eMerge 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.mdlisted serialization as the builder's gap ("Not done yet: serialization"): onmain,CopyRaytracingAccelerationStructurewithSERIALIZE/DESERIALIZEand theSERIALIZATIONpostbuild info were refused at replay as unsupported for XDXR structures. This implements them.runtime/src/xdxr_build.comp:MODE_SERIALIZE,MODE_DESERIALIZE, andMODE_POSTBUILDansweringSERIALIZATION(16 bytes) next to the two sizes. The serialized form is:D3D12_SERIALIZED_RAYTRACING_ACCELERATION_STRUCTURE_HEADER: the layer's own driver matching identifier (xdxr_build.hxdxr_serialized_id; GUID = ASCIILeonida 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;DESERIALIZEcopies 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.incis regenerated with the command inxdxr_build_spv.h(glslc --target-env=vulkan1.2 -O -mfmt=c, shaderc v2026.4). That glslc reproduces the committed include formain's shader byte for byte, so the large diff is only the ID renumbering of this change;spirv-val --target-env vulkan1.2accepts the module.Replay (
vulkan_replay.h,vulkan_backend.h): passes the copy mode and postbuild type through, stepsSERIALIZATIONdescs 16 bytes apart, and boundsSERIALIZE/DESERIALIZEby 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_TOOLSandTOOLS_VISUALIZATIONstay refused.CheckDriverMatchingIdentifier(was a stub answeringUNRECOGNIZED):COMPATIBLE_WITH_DEVICEfor the layer's identifier,INCOMPATIBLE_VERSIONfor the same GUID with other versioning data,UNRECOGNIZEDotherwise and always withLEONIDA_RT_AS=khr(the KHR path still refuses serialization; out of scope).Docs:
docs/bvh.mdgets a Serialization paragraph;docs/d3d12_vulkan.md,docs/xdxr.mdand the README row are updated.Not measured, and said so in
docs/bvh.md: the console's own serialized payload.XboxBvhBuilder.dllwritesSERIALIZATIONpostbuild info in a handler of its own (docs/xdxr.mdsection 4); this layer's payload after the pointers is its own, and a blob carrying the console's identifier would beUNRECOGNIZED. 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_rtnow serializes the test's BLAS and three-instance TLAS, checks theSERIALIZATIONpostbuild info (56 + sizeand56 + 3*8 + size), the headers, the identifier throughCheckDriverMatchingIdentifier(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 withCopyBufferRegion(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_checkthen 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).MODE_DESERIALIZEignoring the pointer list,d3d12_xdxr_rtfails with "deserialized TLAS: an instance's BLAS address is not the moved BLAS's".replay_khr_as_copy_postbuildcovers the replay contract: modes 3/4 reachxdxr_copywith their mode and destination-only bound, mode 2 is unsupported,SERIALIZATIONdescs land 16 bytes apart, a 24-byte destination for two of them isinvalid_copy,TOOLS_VISUALIZATIONis unsupported.xdxr|dxr|khr_as|indirect_rt) pass on both GPUs below (bvh_builderskips, as onmain).ctest -C RelWithDebInfo, RTX 5070 Ti): 292/293 pass. The one failure,d3d12_execute_indirect_validation(5 of 49 parity cases), fails identically onmainwith this change stashed; it is the known argument-range parity issue (#337, #306).python -I scripts/check_no_game_data.pyon every changed file,tests/test_text_write_line_endings.py: clean.git merge-treewithmain21625bca8and with #485 (which also touchesxdxr_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
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).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.