Repository navigation
XDXR: CopyRaytracingAccelerationStructure (clone, compact) and postbuild sizes (D3D-178) - #1844
Conversation
…R one Two `const auto* build` in one else-if chain: the second hides the first and MSVC /W4 warns (C4456) in every file that includes the header (reported by @zneel on ItsNotRexed#1667). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The radix sort's fixed latency dominated small builds (2,000 triangles: 0.81 ms with the sort, 0.08 ms without, on an RTX 2050; the 10k regression @exhawk measured on ItsNotRexed#1572). Up to 1,024 keys are now sorted in one workgroup's shared memory (bitonic, ties by element index: the stable order; 8 KiB, within the 16 KiB minimum with the radix arrays), and the radix tiles are 256 elements (4 chunks instead of 32 per workgroup). RTX 2050: 1,000 triangles 0.24 ms, 2,000 0.28 ms (0.83), 10,000 0.38 ms (0.81), 100,000 2.3 ms (2.5); 1M 21.9 ms (20.3, the larger scan). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An update (same topology, new positions or instance transforms) now keeps the source's tree and recomputes its boxes: the source is copied to the destination unless it is the destination (MODE_COPY), the elements are rewritten at their slots, MODE_LEVEL with arg2 = 1 recomputes each node's boxes from the children it already points to, and the header gets the new bounds. No Morton pass, no sort, and the parent table is kept. RTX 2050: 1,000 triangles 0.07 ms (build 0.19), 100,000 1.02 ms (2.24), 1,000,000 9.8 ms (22.0); Iris Xe 13.1 ms for 1M (47.9). - XdxrBuilder::record_blas / record_tlas take `update_from`; the Vulkan backend passes the source (or the destination, for an in-place update) when the D3D12 build has PERFORM_UPDATE. - vk_xdxr_build_test: a 3,000-triangle BLAS refitted in place (radix-sort tree), an R32-indexed grid refitted into another buffer (its untouched source is checked too), and the TLAS refitted after its instances move; the timing mode also times refits. - d3d12_xdxr_rt_test: the BLAS is built with ALLOW_UPDATE, its soup moves, and a PERFORM_UPDATE in place is checked as d3d12_blas_update. - tools/xdxr_bvh.py check-build: the case being checked answers reads at its address first (an in-place update leaves two dumps at one address). A sabotaged refit (no box pass) fails every update case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ild sizes CopyRaytracingAccelerationStructure and EmitRaytracingAccelerationStructure- PostbuildInfo were not implemented, and the postbuild descs of BuildRaytracingAccelerationStructure were ignored. - CLONE and COMPACT copy the structure's bytes (MODE_COPY_AS). XDXR records are position-independent: node pointers count from the structure's start and a TLAS names its BLASes by address. The size comes from the source header, so a copy can follow a build in the same list; the destination resource bounds it. - COMPACTED_SIZE and CURRENT_SIZE (MODE_POSTBUILD) are totalSizeIn64BNodes * 64: a build is already exactly its layout's size. Written for EmitRaytracingAccelerationStructurePostbuildInfo and for each postbuild desc of a build, after it. - New IR commands CopyAccelerationStructure and AccelerationStructurePostbuild. Serialization, deserialization and tools visualization are refused at replay. With LEONIDA_RT_AS=khr the postbuild descs stay ignored, as before. - vk_xdxr_build_test: a clone of blas_random, its COMPACTED_SIZE (== layout size), a compaction into exactly that size with a guard word after it, and a clone of the refitted TLAS. - d3d12_xdxr_rt_test: EmitRaytracingAccelerationStructurePostbuildInfo for both structures and a TLAS rebuild with a CURRENT_SIZE desc (all equal to the prebuild sizes), then COMPACT into a buffer of that size, checked as d3d12_blas_compacted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ingTier The layer keeps answering NOT_SUPPORTED (no CreateStateObject or DispatchRays), although its XDXR acceleration structures are what the game's own traversal shaders read. The first-boot trace shows whether the game asks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested
Synthetic fixtures only. This run did not enable the Vulkan validation layer. AI-assisted verification. |
|
Tested 9fd1aae on an NVIDIA GeForce RTX 3050 Laptop GPU, driver 32.0.16.2101, Windows 11, native MSVC (VS 2022 Build Tools, Ninja, RelWithDebInfo): pass.
This covers the MSVC and native-Windows gaps listed under "Not run". AMD and the validation layers are still not run. AI-assisted (Claude Code). |
0xTehuti
left a comment
There was a problem hiding this comment.
Tested 9fd1aae on NVIDIA GeForce RTX 2070 SUPER (driver 595.79), Windows 11 24H2, MSVC 19.44 (VS 2022 Community), Ninja RelWithDebInfo: pass
- Build: Clean compile and link with native MSVC and Ninja.
- XDXR validation:
python -I tests/test_xdxr_bvh.py: 27/27 passed.vk_xdxr_build_test+xdxr_bvh.py check-build --rays 1000: 0 validation errors, 0/1,000 rays differ across all cases (blas_clone,blas_compacted,tlas_refit_clone, etc.).d3d12_xdxr_rt_test+xdxr_bvh.py check-build --rays 1000: 0 validation errors, 0/1,000 rays differ (d3d12_blas,d3d12_blas_compacted,d3d12_blas_update,d3d12_tlas).
LEONIDA_RT_AS=khr:d3d12_xdxr_rtskips as expected andd3d12_indirect_rtpasses (0.33s).- Full clean-room test suite:
ctest100% passed;d3d12_vulkan_device_test,d3d12_sampler2_test, andd3d12_descriptor_testall pass.
No game files used or added. AI-assisted.
|
Tested This adds an Intel Xe-LP verification alongside the existing NVIDIA runs:
AI-assisted. |
…or do now Three corrections from @romainveurrier's review (the D3D-178 owner): - the translator reads all four triangle node types, TRI0-TRI3, with the barycentric remap byte (ItsNotRexed#1525), while the GPU builder writes TRI0 leaves; the row said "TRI0/TRI1 leaves" for both; - the XDXR-vs-KHR default is decided: the layer builds XDXR records by default and `LEONIDA_RT_AS=khr` keeps ItsNotRexed#743's path (ItsNotRexed#1667), so only the rehydrate-or-rebuild question is still open; - the row now says that `PERFORM_UPDATE` refits instead of rebuilding (ItsNotRexed#1789), and that clone, compaction and the compacted/current postbuild sizes work (ItsNotRexed#1844), checked against the CPU reference on synthetic scenes. The measured parts of the row (the recovered build descriptions, the packs, the 8 of 10 sampled BLAS) are unchanged. Docs only: the documentation suites pass, with the same three duplicated-row failures the parent commit has.
|
Tested ad43d63 on NVIDIA GeForce RTX 5060 (Blackwell, driver 617.42, Vulkan 1.4.351), Windows 11 Pro build 26300, MSVC (VS 2026), LLVM_MC set, scripts\build_runtime.ps1, then ctest -j 4: pass for this change. xdxr_build, xdxr_build_check, xdxr_descs, d3d12_xdxr_rt and d3d12_xdxr_rt_check pass (bvh_builder skips without LEONIDA_GAME_DIR). 100 of 101 run tests pass; the one failure is d3d12_draw ("fence signal 4 is not above 20"), the pre-existing fence failure that #1807 fixes, unrelated to this PR. (Run with an AI coding agent.) |
Item: D3D-178 (#313).
Built on #1743 and #1789, both merged at the same heads this branch contains. This PR's own changes are 9fd1aae (copies, postbuild) and ad43d63 (open question 22).
What
CopyRaytracingAccelerationStructureandEmitRaytracingAccelerationStructurePostbuildInfoweren't implemented, and the postbuild descs passed toBuildRaytracingAccelerationStructurewere silently ignored. The usual engine pattern (build withALLOW_COMPACTION, readCOMPACTED_SIZE, allocate,COMPACT) therefore didn't work. Now:CLONE/COMPACTcopy the structure's bytes (MODE_COPY_AS). XDXR records are position-independent: node pointers count from the structure's start, and a TLAS names its BLASes by address, which a clone must keep. The size comes from the source header (totalSizeIn64BNodes), so a copy can follow a build in the same command list. The destination resource bounds it.COMPACTED_SIZE/CURRENT_SIZE(MODE_POSTBUILD) are bothtotalSizeIn64BNodes * 64, because a build is already exactly its layout's size (the prebuild size). Compaction saves nothing, but it works, and the values are right. They are written forEmitRaytracingAccelerationStructurePostbuildInfo, and for each postbuild desc of a build, after the build.Refused, not faked:
SERIALIZE/DESERIALIZE,VISUALIZATION_DECODE_FOR_TOOLS, and theSERIALIZATION/TOOLS_VISUALIZATIONpostbuild types are refused at replay as unsupported.LEONIDA_RT_AS=khr: postbuild descs stay ignored, as before, so the list doesn't fail on that path.IR: new commands
CopyAccelerationStructureandAccelerationStructurePostbuild, with D3D12's alignment checks (256-byte structures, 8-byte postbuild destinations) at record time.Docs: open question 22 in
docs/d3d12_vulkan.md§8.2 (ad43d63): does the game gate ray tracing onRaytracingTier? The layer keeps answeringNOT_SUPPORTED, since there's noCreateStateObjectorDispatchRays, and the first-boot trace will show whether the game asks. Changing the answer is left as a maintainer decision for then.Tests
vk_xdxr_build_test:blas_random, checked by rays;COMPACTED_SIZEread back and asserted equal to the layout size;d3d12_xdxr_rt_test, through the D3D12 API:EmitRaytracingAccelerationStructurePostbuildInfo(COMPACTED_SIZE)for the BLAS and the TLAS;CURRENT_SIZEpostbuild desc;CopyRaytracingAccelerationStructure(COMPACT)of the updated BLAS into a buffer of exactly its compacted size, checked asd3d12_blas_compacted.Tested (Fedora 44)
xdxr_build,d3d12_xdxr_rt(with their checks) andd3d12_indirect_rtpass on both GPUs;d3d12_blas_compactedgives 0/1,000 differing rays;LEONIDA_RT_AS=khr, the XDXR tests skip andd3d12_indirect_rtpasses;mainunder Wine (the clang 22.1.8 crash infsr_dispatch/bvh_builder;device_proxy,d3d12_present,d3d12_indirect_zero).python -I tests/test_xdxr_bvh.pyOK;xdxr_build.incmatchesglslc --target-env=vulkan1.2 -O -mfmt=c.No game files. AI-assisted (Claude Code).
🤖 Generated with Claude Code