Skip to content

XDXR: serialize acceleration structures and record batched builds (RT-148) - #4494

Open
opit80 wants to merge 1 commit into
ItsNotRexed:mainfrom
opit80:rt148-xdxr-serialize-batched
Open

opit80 wants to merge 1 commit into
ItsNotRexed:mainfrom
opit80:rt148-xdxr-serialize-batched

Conversation

@opit80

@opit80 opit80 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-148 (claim; status)

What and why

Implements D3D12 serialize and deserialize for raw XDXR BVH4 buffers. The GPU writes the documented 56-byte DXR header, the TLAS BLAS-address array, and the BVH4 bytes. Deserialization checks the format identifier, the header and buffer lengths, and the TLAS references before copying. It applies the caller's BLAS addresses so a TLAS can be restored after its BLAS moves.

The format uses the RT-151 size field, which excludes the 64-byte BVH4 header. One shader helper reads the size for serialization, deserialization validation, and the 16-byte serialization postbuild result. The format identifier is at version 2 because the earlier development build used the pre-RT-151 size field. RT-151

Behaviour change

  • CopyRaytracingAccelerationStructure supports SERIALIZE and DESERIALIZE on XDXR. A rejected GPU copy leaves the destination intact and reports the reason when the queue retires the submission.
  • EmitRaytracingAccelerationStructurePostbuildInfo and builds can report the serialized byte count and TLAS pointer count.
  • The standalone XDXR batch adapter accepts the measured Xbox BatchedDesc2 layout and default-equivalent stream settings. It validates the descriptions before recording, then uses one existing build per entry. UAV barriers between entries allow scratch reuse and let a later TLAS consume an earlier BLAS.

Scope

Serialization is for the runtime's uncompressed XDXR layout. Actual serialized copies are limited to a 32-bit byte range. Streaming support covers default-equivalent settings. Offline statistics and other unsupported postbuild types are rejected. The shipping Xbox call route still needs a measured ABI binding.

The upstream base includes clone, compact and the size queries in 9fd1aaed, and @esteban-dcp's RT-151 header-size correction in 8ab01bbe. Clone/compact implementation, RT-151 implementation

Interaction with #3315 (RT-214)

The shared runtime_bvh_bytes helper checks the BVH4 size and BOX32 root together. RT-214 adds a 64-byte BOX16 root and a spare 64-byte unit for MINIMIZE_MEMORY BLASes. Until that layout is supported, a BOX16 root produces a diagnostic and the serialization size query returns zero. Whichever PR lands second will adapt the helper and regenerate xdxr_build.inc. RT-214

#3944 excludes RT-148 from its scope. At 82bcd9a1, ten of its fourteen changed files overlap with this branch, including the shader and its generated include. If it lands first, rebase this branch, regenerate the include and re-run the XDXR tests. #3944

Tested

MSVC 19.44.35229, Ninja RelWithDebInfo -j 4, Vulkan SDK 1.4.363.0, NVIDIA GeForce RTX 5070 Ti, driver 617.42.

  • Build and shader verification passed. Both branch and baseline builds emitted one existing C4456 in runtime/test/xgameruntime_test.cpp:492. The generated shader passed spirv-val --target-env vulkan1.2, and regenerating xdxr_build.inc produced the same SHA-256.
  • The synthetic GPU fixture recorded two builds that reused scratch and wrote separate postbuild results. The streamed TLAS matched the standard build byte for byte. BLAS and TLAS blobs measured 48,824 and 720 bytes, and the restored TLAS used three relocated BLAS references.
  • The fixture rejected an unknown stream record and offline statistics. The offline-statistics rejection left the first build unrecorded. Five invalid blobs left the restored destination unchanged. A BOX16 root produced diagnostics in deserialization and in the serialization size query, which returned zero.

AI-assisted (Claude Code orchestration; GPT/GLM/Hy4 sub-agents).

Checklist

  • Fixtures are synthetic and use no game files.
  • The upstream RT-151 dependency and the standalone entry point have been verified.
  • The RTX 5070 Ti synthetic fixture and normal and validation CTest results have been recorded.

…-148)

Write the DXR header and raw BVH4 payload on the GPU, and restore TLAS references from the serialized address table. Check the format and ranges before writing the destination.

Record the measured batch descriptors through the existing XDXR build path. Cover round trips, default stream settings and rejected inputs with synthetic GPU fixtures.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Built d3d12_xdxr_rt_test at 6e5eb2da and ran it on Windows 11, RTX 5070 Ti (temp output dir, deleted after):

d3d12_xdxr_rt: batched/streamed builds, BLAS and TLAS serialization round trips, invalid blobs rejected; BLAS 48,768 bytes (prebuild 48,768), TLAS (prebuild 640), exit 0. The invalid cases were refused individually (unsupported stream settings/postbuild info, incompatible driver id, bad BLAS pointer, invalid layout/range, wrong root type). No blocking issue.

@itsonlysimbo

Copy link
Copy Markdown
Contributor

Tested 6e5eb2da merged onto main 03b09a08 (4 behind; merges cleanly) on RTX 4070, NVIDIA 621.14, Windows 11 (10.0.26300), MSVC 19.44, Ninja, RelWithDebInfo, Vulkan SDK 1.4.363: pass.

  • xdxr_descs, xdxr_build, xdxr_build_check, d3d12_xdxr_rt and d3d12_xdxr_rt_check pass.
  • ctest: 145 passed, 10 skipped, 0 failed; run_gpu_tests.py: 164/210 passed, 46 skipped, 0 failed, same as main 03b09a08.

AI-assisted (Claude Code).

@justr4mzi

Copy link
Copy Markdown
Contributor

Verified 6e5eb2da on Windows 11 25H2 + AMD Radeon RX 6700 XT (gfx1031, Adrenalin 26.11.2, Vulkan 1.4.315, MSVC 19.44.35230.0 RelWithDebInfo).

Hardware & CTest results (LEONIDA_VK_VALIDATION=1)

  • Built [15/15] (xdxr_descs_test, vk_xdxr_build_test, d3d12_xdxr_rt_test) with 0 compiler warnings.
  • ctest -R "xdxr" --output-on-failure:
    • Standard: 5/5 passed (86.36 s: xdxr_descs 0.03s, xdxr_build 1.09s, xdxr_build_check 64.53s, d3d12_xdxr_rt 1.04s, d3d12_xdxr_rt_check 19.58s).
    • LEONIDA_VK_VALIDATION=1 + VK_LAYER_KHRONOS_validation: 5/5 passed (74.70 s).
  • Direct vk_xdxr_build_test.exe (LEONIDA_VK_VALIDATION=1): vk_xdxr_build_test: built every case (0 validation errors).
  • Direct d3d12_xdxr_rt_test.exe (LEONIDA_VK_VALIDATION=1): d3d12_xdxr_rt: batched/streamed builds, BLAS and TLAS serialization round trips, invalid blobs rejected (BLAS 48768 bytes (prebuild 48768), TLAS (prebuild 640), all stream/postbuild/deserialize operations 2..7 cleanly rejected, 0 validation errors).
  • Direct xdxr_descs_test.exe: xdxr_descs: ok (checked against d3d12.h).

Python, docs & hygiene checks

  • python -I tests/test_xdxr_bvh.py: 37/37 OK (2.242 s).
  • All 7 tests/test_docs_*.py suites: 7/7 passed.
  • python -I scripts/check_no_game_data.py (rc=0), git diff --check clean.

AI-assisted (Gemini, Antigravity).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants