Skip to content

XDXR builds: PERFORM_UPDATE refits instead of rebuilding (D3D-178) - #1789

Merged
ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
romainveurrier:rt/xdxr-refit
Nov 22, 2026
Merged

ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
romainveurrier:rt/xdxr-refit

Conversation

@romainveurrier

Copy link
Copy Markdown
Contributor

Item: D3D-178 (#313), a follow-up to the merged #1572/#1667.

Depends on: #1743. This branch contains #1743's two commits; this PR's own change is the last commit, f6d6121.

What

BuildRaytracingAccelerationStructure with PERFORM_UPDATE used to rebuild the structure from scratch. D3D12 promises the same topology for an update (new positions, or new instance transforms), so the XDXR builder now refits:

  1. Copy: a new MODE_COPY copies the source to the destination unless they're the same buffer. It is also a building block for CopyRaytracingAccelerationStructure later.
  2. Leaves: MODE_TRIANGLES / MODE_INSTANCES rewrite the elements at their slots, as a build does.
  3. Nodes: MODE_LEVEL with arg2 = 1 recomputes each node's boxes, level by level, from the children it already points to. An instance's ParentNode is restored the same way.
  4. Header: MODE_HEADER writes the new bounds.

The tree's grouping and the parent table are kept, so there is no Morton pass and no sort. A refit is valid for any motion. It only traverses more slowly as geometry moves away from where it was built, which is the usual refit trade-off, and the application chooses it by asking for an update.

Triangles RTX 2050 build RTX 2050 refit Iris Xe build Iris Xe refit
1,000 0.19 ms 0.07 ms 1.19 ms 0.38 ms
10,000 0.42 ms 0.16 ms 1.79 ms 0.38 ms
100,000 2.24 ms 1.02 ms 7.97 ms 1.53 ms
1,000,000 22.0 ms 9.8 ms 47.9 ms 13.1 ms

(best of 3 single submissions, device-local memory; vk_xdxr_build_test <dir> <n> now times both)

  • XdxrBuilder::record_blas / record_tlas take update_from. The Vulkan backend passes SourceAccelerationStructureData, or the destination when no source is given, if the D3D12 build has PERFORM_UPDATE.
  • Prebuild info: UpdateScratchDataSizeInBytes stays the build's scratch size, which covers a refit.

Tests

  • vk_xdxr_build_test, three new cases:
    • a 3,000-triangle BLAS on the radix-sort path, refitted in place after every vertex moves;
    • an R32-indexed grid with a 16-byte stride, refitted into another buffer, with its untouched source checked as _source;
    • the TLAS refitted in place after its instances move and turn.
  • d3d12_xdxr_rt_test through the D3D12 API: the BLAS is built with ALLOW_UPDATE, its soup moves in the upload buffer, and a PERFORM_UPDATE in place is checked as d3d12_blas_update.
  • tools/xdxr_bvh.py check-build: the case being checked now answers reads at its own address first. An in-place update leaves two dumps at one address, before and after.
  • Negative control: with the node pass removed, so the boxes go stale, every update case fails, both the validator's containment check and the rays, while the untouched source still passes.

Tested (Fedora 44)

  • Native ctest: 28/28 on an RTX 2050 (NVIDIA 620.70.06), an Iris Xe (Mesa 26.2.7) and llvmpipe. Every case gives 0 differing rays, refits included.
  • Wine 11.21 with clang-cl 22.1.8 and xwin:
    • xdxr_build, d3d12_xdxr_rt (with their checks) and d3d12_indirect_rt pass on both GPUs;
    • with LEONIDA_RT_AS=khr, the XDXR tests skip and d3d12_indirect_rt passes;
    • full suite: the same 5 failures as main under Wine (the clang 22.1.8 crash in fsr_dispatch/bvh_builder; device_proxy, d3d12_present, d3d12_indirect_zero).
  • python -I tests/test_xdxr_bvh.py OK; xdxr_build.inc matches glslc --target-env=vulkan1.2 -O -mfmt=c.
  • Not run: MSVC, an AMD GPU, validation layers.

No game files. AI-assisted (Claude Code).

🤖 Generated with Claude Code

romainveurrier and others added 3 commits November 22, 2026 14:41
…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>
@crastinator

Copy link
Copy Markdown
Contributor

Tested f6d6121 merged into main 003e7812 (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • Whole run_gpu_tests.py: 161/170 native, 161/170 with LEONIDA_W64_EMULATE=1. The only skips are the eight *_m* D3D12 fixtures and ps_w64x_readlane (RADV can't require a 64-wide fragment subgroup), the same as on main.
  • xdxr_build and xdxr_build_check pass in ctest (33/33).

No game files. AI-assisted (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit ef15a21 into ItsNotRexed:main Nov 22, 2026
2 of 4 checks passed
wildheathen added a commit to wildheathen/Leonida that referenced this pull request Nov 22, 2026
…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.
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.

3 participants