Repository navigation
d3d12: serialize and deserialize XDXR acceleration structures (RT-XDXR-SERIALIZE) - #626
kawaii-shakal wants to merge 5 commits into
Conversation
|
Tested 387cdbf on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300), native Windows: pass Built at this head with
|
387cdbf to
f51ef5c
Compare
|
Rebased onto main AI-assisted. |
…R-SERIALIZE) CopyRaytracingAccelerationStructure with SERIALIZE / DESERIALIZE and the SERIALIZATION postbuild info were refused at replay, the gap the README's "Ray tracing (BVH)" row and docs/bvh.md listed for the XDXR builder. xdxr_build.comp gains MODE_SERIALIZE and MODE_DESERIALIZE, and MODE_POSTBUILD answers SERIALIZATION (16 bytes) next to the two sizes. The serialized form is D3D12's 56-byte header (the layer's own driver matching identifier, xdxr_build.h xdxr_serialized_id; the serialized size; the deserialized size, which is the structure's; the pointer count), one 8-byte BLAS address per INSTANCE record of a TLAS read from the record (+60, 256-byte units), then the structure's bytes. DESERIALIZE copies the bytes back and writes each instance's BLAS address from the pointer list, so BLASes the application moved and re-pointed are the ones the TLAS names. xdxr_build.inc is regenerated with the command xdxr_build_spv.h gives (glslc from shaderc v2026.4, which reproduces the committed include for main's shader byte for byte). The replay passes the copy mode and postbuild type through, steps SERIALIZATION descs 16 bytes apart, and bounds SERIALIZE / DESERIALIZE by the destination only (a serialized structure is larger than the structure). CheckDriverMatchingIdentifier recognises the identifier. d3d12_xdxr_rt_test serializes a BLAS and a three-instance TLAS, checks the headers, pointers and bytes, deserializes the BLAS elsewhere, rewrites the TLAS's pointers to it, deserializes the TLAS and dumps both for the ray check; replay_khr_as_copy_postbuild_test covers the replay contract. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
f51ef5c to
dcac757
Compare
|
Rebased again, onto main AI-assisted. |
… argument replay_readback_stages_test (from main's VK-XDXR-POSTBUILD-READBACK-STAGE) assigned a three-argument lambda to xdxr_postbuild, which this branch gives a fourth (the postbuild type), so the runtime tests did not build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
CI fix: |
Codex integrated title-placement bounds with serialization, regenerated the synthetic builder shader, and added a portable round-trip check.
Conflicts with ProjectLeonida#2222 (RT-XDXR-UPDATE-SOURCE-CHECK), resolved: - Shader modes: this branch uses 19 and 20 (serialize, deserialize), so main's MODE_CHECK = 19 becomes 26, in xdxr_build.comp and xdxr_build.h. 21-25 stay free for the pair modes of ProjectLeonida#690, which builds on this branch, so the two branches number the modes alike. Both sides' code is kept. - SCRATCH_REFIT moves from byte 28 to byte 32, as in ProjectLeonida#690, where byte 28 is the kept leaf count. Nothing here uses either byte. - xdxr_build.inc regenerated with glslc (shaderc 2023.8, --target-env=vulkan1.2 -O -mfmt=c); spirv-val passes. Tested: full ctest, 113 of 113, on Mesa lavapipe (llvmpipe, LLVM 19.1.7). Changes made by Claude Code (AI-assisted). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JPqXc6svM4pbBagTsVEYA3
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 (d3d12: ExecuteIndirect accepts the argument ranges newer D3D12 runtimes accept (D3D-EXECIND-RANGE) #337, d3d12_execute_indirect_validation_test: handle Windows 11 26300 relaxed max=0 and padded-stride bounds #306).python -I scripts/check_no_game_data.pyon every changed file,tests/test_text_write_line_endings.py: clean.git merge-treewithmain21625bc and with XDXR-BUILDER-PREVALIDATE: pre-validate XdxrBuilder inputs and avoid 32-bit workgroup overflow #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