mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 22:15:52 +01:00
[PR #690] xdxr: a paired BLAS keeps one 64-byte leaf a pair (RT-XDXR-PAIR-DENSE) #730
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#730
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/690
Author: @kawaii-shakal
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:rt-xdxr-pair-dense📝 Commits (10+)
dcac757d3d12: serialize and deserialize XDXR acceleration structures (RT-XDXR-SERIALIZE)c779bd3xdxr: a paired BLAS keeps one 64-byte leaf a pair (RT-XDXR-PAIR-DENSE)a98d676xdxr: write a pair's leaf when placing it, not in place (RT-XDXR-PAIR-DENSE)acb9bb5test: the XDXR postbuild readback-stage case takes the postbuild type argument489d2b2test: the XDXR postbuild readback-stage case takes the postbuild type argument78d3d92Merge upstream XDXR address handling into serializationfb2ea85Merge updated XDXR serialization into dense pairing8f7ea15Size title-placed XDXR scratch for dense pairingb8d18a9Merge upstream main into XDXR serialization7e63e1dMerge updated XDXR serialization into dense pairing📊 Changes
16 files changed (+13084 additions, -8413 deletions)
View changed files
📝
README.md(+1 -1)📝
docs/bvh.md(+56 -16)📝
docs/d3d12_vulkan.md(+4 -2)📝
docs/xdxr.md(+1 -1)📝
runtime/shims/d3d12_vulkan_device.cpp(+30 -15)📝
runtime/src/vulkan_backend.h(+11 -8)📝
runtime/src/vulkan_replay.h(+28 -11)📝
runtime/src/xdxr_build.comp(+291 -74)📝
runtime/src/xdxr_build.h(+82 -15)📝
runtime/src/xdxr_build.inc(+12164 -8248)📝
runtime/test/d3d12_xdxr_rt_test.cpp(+240 -16)📝
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(+76 -3)📝
tests/test_xdxr_bvh.py(+28 -0)📝
tools/xdxr_bvh.py(+23 -0)📄 Description
Claimed in the coordination issue as: RT-XDXR-PAIR-DENSE (claim)
Depends on: #626 (the same shader; this branch is on top of it, so the first commit here is #626's: the change is d0021a43e)
What and why
TRI1 pairing in the XDXR GPU builder left the sibling's leaf unused in the element region, so a paired BLAS was exactly as large as an unpaired one. README calls this "TRI1 pairing (no memory saved yet)";
docs/bvh.md§7a lists it under "Not done yet". Now a paired build keeps one 64-byte leaf record a pair, as the console's runtime BLASes do (§4a: oneLeafper entry, an entry holding the second primitive). The nodes follow directly. The build,COMPACTED_SIZEand aCOMPACTcopy are 64 bytes a pair smaller.How (
runtime/src/xdxr_build.comp,.h):FLAG_PAIR,MODE_TRIANGLESwrites the leaves to scratch.MODE_PAIR, split out ofMODE_NODES, chooses the pairs once the tree is known (same rule as before). It records each pair and its rotation and marks the sibling's leaf as dropped; it writes no leaf (see the fix below).MODE_LEAF_COUNT/SCAN/INDEX, sharingtile_indexwith the kept-node scan) gives each its place.MODE_LEAF_PLACEcopies them densely into the element region, building a pair's leaf from the two staged ones.MODE_NODESand everything after usenodes_off()=elements_off + 64 * kept, also written to the header'soffsetToNodes. Pointers and parent table entries are written for the final places, so nothing moves afterwards.numElementsstays the triangle count, astools/xdxr_bvh.py build_blaswrites it.ALLOW_UPDATE. This isXdxrLayout::compute(..., pairing), andrecord_blaspairs only with such a layout.GetRaytracingAccelerationStructurePrebuildInfonow mapsALLOW_UPDATEand asks for the same layout as the build.pc.arg0, which is the vertex stride inMODE_TRIANGLES.Checks:
check-buildreports any 64-byte unit of a BLAS's element region that no triangle pointer names (unreferenced_leaves). A unit test shows it catches the old layout.vk_xdxr_build_test:blas_grid_unpaired) and requires the sizes to differ by exactly 64 bytes per TRI1 child;COMPACTED_SIZE;COMPACT-copies it (blas_paired_compacted, traced bycheck-build).d3d12_xdxr_rt_test:ALLOW_UPDATEone;It used to reuse the
ALLOW_UPDATEbuild's scratch, which is now too small for a paired build.Fix after review (1b859ca6d)
On an Apple M5 Pro (MoltenVK 1.4.2) the paired cases failed, and the counts changed between runs (thanks @GeorgiyDemo).
MODE_PAIRrewrote the first triangle's staged leaf from vertices it had loaded from that same leaf in the same dispatch. The SPIRV-Cross in MoltenVK 1.4.2 can move such a load after the store, which is the rule at the top ofxdxr_build.comp. NowMODE_PAIRonly records the pair (FIRST | siblingandk | kd << 2for the first triangle), andMODE_LEAF_PLACEbuilds the leaf word by word from the two unchanged staged leaves. Sizes are unchanged; the scratch takes 4 more bytes a triangle. On the RTX 5070 Ti,ctest -R "xdxr|khr_as_copy"passes 7/7 in three runs without and three withLEONIDA_VK_VALIDATION=1. Not re-run on Apple here.Tested
Windows 11 Pro 26300, MSVC 19.50.35721.0, Vulkan SDK 1.4.363.0, shader regenerated with
glslc --target-env=vulkan1.2 -O -mfmt=c(shaderc v2026.4),spirv-valclean.ctest -R "xdxr|khr_as_copy": 7/7 passed, both without and withLEONIDA_VK_VALIDATION=1(synchronization validation). Everyxdxr_build_checkandd3d12_xdxr_rt_checkscene: 0 validation errors, 0 rays differing from brute force.blas_paired_grid(288 triangles, 80 pairs)blas_paired_sort_tiles(7,200 triangles, 2,208 pairs)d3d12_blas_paired(428 triangles, 61 pairs)blas_paired_grid_box16(162 triangles, 81 pairs)Whole
ctest -C RelWithDebInfo: 293 run, 292 passed. The one failure isd3d12_execute_indirect_validation, which fails onmaintoo (#337 / #306).python -I tests/test_xdxr_bvh.py(49 tests),python -I tools/xdxr_bvh.py selftest --seed 1 --rays 200, everytests/test_docs_*.py: OK.python -I scripts/check_no_game_data.pyon every changed file: clean.Not measured: build time. A paired build adds five dispatches, and builds that do not pair are unchanged.
GPUs tested: NVIDIA GeForce RTX 5070 Ti (Blackwell, PCI 10de:2c05), driver 617.42, Vulkan 1.4.351, Windows 11 Pro 26300
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase). (on top of #626, which merges cleanly withmain)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.