xdxr: a paired BLAS keeps one 64-byte leaf a pair (RT-XDXR-PAIR-DENSE) #690
Open
github-bot
wants to merge 11 commits from
github-bot/gh-690 into main
AGit
pull from: github-bot/gh-690
merge into: github:main
github:main
github:docs/animation-merge-remnants
github:docs/story-dedup-and-cli
github:docs/restofworld-merge-remnants
github:docs/gamedata-dedup-tables
github:docs/textures-bcpack-tables-and-cli
github:docs/exe-fail-fast-shims-sync
github:fix/address-guard-wraparound-parity
github:fix/cvt-f16-denorm-and-clamp
github:docs/pso-cache-scope-note
github:docs/viewer-readme
github:docs/textures-arrays-dds-preview
github:docs/conformance-readme-status
github:fix/docs-validators-fences-urls
github:claude/loop-total
github:claude/pops-collision-seed
github:claude/dstorage-hold-page-reads
github:claude/host-image-copy-switch
github:feat/gdk-lifecycle-window-hook
github:claude/d16s8-uav-nvidia-fallback
github:feat/mfplat-offline-shim
github:claude/gameinput-slow-reader
github:fix/rt-null-barrier-clear
github:claude/depth-resolve-sample-positions
github:integration/palmetto-parity
github:claude/valu-literal-sext
github:claude/slot74-pool-handle
github:claude/rgb9e5-uint-alias-view
github:claude/fssm-root-layout-tables
github:feat/gdk-speech-display-lifecycle
github:asset-audio-skip-current
github:qemmhd/old-9940-rectangle-quad-lists
github:feat/ws2-offline-shim
github:qemmhd/rt-d16-unorm-uav
github:feat/xs-device-stops-7-9
github:qemmhd/rt-depth-same-base-shapes
github:qemmhd/rt-lazy-attachment-variant
github:feat/acphal-xma2-decoder
github:asset-audio-skip
github:codex/coord-claim-check-20261124-7e48
github:feat/xs-frame-pacing-presentx
github:feat/xs-device-vm-options
github:old-pr/9844
github:old-pr/9978
github:old-pr/9815
github:old-pr/10057
github:old-pr/9874
github:old-pr/9965
github:old-pr/9863
github:old-pr/10068
github:old-pr/10066
github:old-pr/10067
github:old-pr/10007
github:old-pr/10061
github:old-pr/10065
github:old-pr/10059
github:old-pr/10063
github:old-pr/10055
github:old-pr/10062
github:old-pr/10042
github:old-pr/10041
github:old-pr/10049
github:old-pr/10047
github:old-pr/10046
github:old-pr/10045
github:old-pr/10056
github:old-pr/10043
github:old-pr/10036
github:old-pr/10034
github:old-pr/9984
github:old-pr/10052
github:old-pr/10038
github:old-pr/10033
github:old-pr/10028
github:old-pr/10050
github:old-pr/9891
github:old-pr/9889
github:old-pr/10051
github:old-pr/10019
github:old-pr/10027
github:old-pr/10029
github:old-pr/10031
github:old-pr/10026
github:old-pr/9941
github:old-pr/10030
github:old-pr/10040
github:old-pr/9990
github:old-pr/10021
github:old-pr/9962
github:old-pr/10022
github:old-pr/10020
github:old-pr/10015
github:old-pr/10025
github:old-pr/9886
github:old-pr/10048
github:old-pr/10014
github:old-pr/10011
github:old-pr/9861
github:old-pr/10010
github:old-pr/10008
github:old-pr/9860
github:old-pr/10006
github:old-pr/9920
github:old-pr/9995
github:old-pr/10000
github:old-pr/10016
github:old-pr/10004
github:old-pr/10023
github:old-pr/9982
github:old-pr/9981
github:old-pr/9983
github:old-pr/9970
github:old-pr/9969
github:old-pr/9968
github:old-pr/9971
github:old-pr/9972
github:old-pr/9942
github:old-pr/9963
github:old-pr/9960
github:old-pr/9964
github:old-pr/9985
github:old-pr/9973
github:old-pr/9862
github:old-pr/9953
github:old-pr/10017
github:old-pr/9952
github:old-pr/9955
github:old-pr/9946
github:old-pr/9954
github:old-pr/9938
github:old-pr/9956
github:old-pr/9856
github:old-pr/9947
github:old-pr/9924
github:old-pr/9961
github:old-pr/9927
github:old-pr/9979
github:old-pr/10032
github:old-pr/9926
github:old-pr/5237
github:old-pr/9951
github:old-pr/9931
github:old-pr/9902
github:old-pr/9921
github:old-pr/9994
github:old-pr/9775
github:old-pr/9768
github:old-pr/9905
github:old-pr/9936
github:old-pr/9901
github:old-pr/9904
github:old-pr/9906
github:old-pr/9988
github:old-pr/9908
github:old-pr/9909
github:old-pr/9911
github:old-pr/9912
github:old-pr/9913
github:old-pr/9887
github:old-pr/9916
github:old-pr/9919
github:old-pr/9925
github:old-pr/9933
github:old-pr/9935
github:old-pr/9918
github:old-pr/9879
github:old-pr/9880
github:old-pr/9881
github:old-pr/9996
github:old-pr/9876
github:old-pr/9892
github:old-pr/9899
github:old-pr/9915
github:old-pr/9914
github:old-pr/9872
github:old-pr/9869
github:old-pr/9866
github:old-pr/9819
github:old-pr/10012
github:old-pr/9857
github:old-pr/9893
github:old-pr/9897
github:old-pr/9928
github:old-pr/9868
github:old-pr/9917
github:old-pr/9940
github:old-pr/9873
github:old-pr/9816
github:old-pr/10009
github:old-pr/9900
github:old-pr/9966
github:old-pr/9859
github:old-pr/9843
github:old-pr/9991
github:old-pr/10058
github:old-pr/9883
github:old-pr/9838
github:old-pr/9835
github:old-pr/9959
github:old-pr/9895
github:old-pr/9837
github:old-pr/9858
github:old-pr/9865
github:old-pr/9864
github:old-pr/9840
github:old-pr/9820
github:old-pr/4669
github:old-pr/9848
github:old-pr/9850
github:old-pr/9810
github:old-pr/9799
github:old-pr/9853
github:old-pr/9875
github:old-pr/9831
github:old-pr/9796
github:old-pr/9801
github:old-pr/9813
github:old-pr/9794
github:old-pr/7417
github:old-pr/9781
github:old-pr/9806
github:old-pr/9958
github:old-pr/9809
github:old-pr/9791
github:old-pr/9792
github:old-pr/10053
github:old-pr/9784
github:old-pr/9789
github:old-pr/9849
github:old-pr/9846
github:old-pr/9773
github:old-pr/9785
github:old-pr/9803
github:old-pr/9826
github:old-pr/9839
github:old-pr/9922
github:old-pr/9948
github:old-pr/7189
github:old-pr/9957
github:old-pr/9823
github:old-pr/9807
github:old-pr/9851
github:old-pr/9774
github:old-pr/9830
github:old-pr/9836
github:old-pr/9822
github:old-pr/9783
github:old-pr/9833
github:old-pr/9890
github:old-pr/9770
github:old-pr/9769
github:old-pr/9772
github:old-pr/9787
github:old-pr/9852
github:old-pr/9834
github:old-pr/9845
github:old-pr/9871
github:old-pr/9771
github:old-pr/9776
github:old-pr/10005
github:old-pr/9949
github:old-pr/9923
github:old-pr/9805
github:old-pr/9829
github:old-pr/9790
github:old-pr/9827
github:old-pr/9929
github:old-pr/9855
github:old-pr/9934
github:old-pr/9907
github:old-pr/9910
github:old-pr/9779
github:old-pr/9780
github:old-pr/9885
github:old-pr/9882
github:old-pr/9877
github:old-pr/9998
github:old-pr/4251
github:old-pr/9987
github:old-pr/9989
github:old-pr/9950
github:old-pr/9777
github:old-pr/10044
github:old-pr/9884
github:old-pr/2906
github:old-pr/5076
github:old-pr/9937
github:old-pr/9986
github:old-pr/3014
github:old-pr/9943
github:old-pr/9939
github:old-pr/4682
github:old-pr/4765
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
bug
Something isn't working
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
question
Further information is requested
wontfix
This will not be worked on
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!690
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-690"
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?
@kawaii-shakal on GitHub · 2026-11-24 12:08 UTC · original
kawaii-shakal:rt-xdxr-pair-dense→main· +13084 −8413 · 16 files · 11 commits · openClaimed 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
@abnalstlll-byte on GitHub · 2026-11-24 12:21 UTC · original · approved these changes
Reviewed and verified RT-XDXR-PAIR-DENSE. Reclaiming unused 64-byte leaf units during TRI1 pairing in the GPU BVH builder produces densely packed element regions with zero unreferenced leaf gaps, reducing BLAS memory footprints. Cleanly validated by unreferenced_leaves in ools/xdxr_bvh.py and ests/test_xdxr_bvh.py. Approved.
@GeorgiyDemo on GitHub · 2026-11-24 12:34 UTC · original
Tested
d0021a43eon Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), MoltenVK 1.4.2 (subgroup 4..32).ctest -R xdxron a build of this head:xdxr_build_checkfails; onmaind42773d07the same two tests pass (4/4 withxdxr_build/xdxr_build_output/xdxr_descs), and on the parent commit387cdbf94(#626 alone, built separately here)xdxr_build_checkpasses withblas_paired_grid80 TRI1 / 0 validation errors / 0 of 1000 rays differing andblas_paired_rotations128 TRI1 / 0 / 0. So the failure is in this pairing change, not in its base.Three runs of
xdxr_build_checkat this head, same binary:blas_paired_compactedblas_paired_gridblas_paired_grid_box16blas_paired_rotationsblas_paired_sort_tilesThe messages are
child box N of 0x… is not inside its parent's boxandbuilt with pairing, but no TRI1 node is reachable, followed byN of 1000 rays differ from brute force(the test reported 36 problems in total).blas_paired_mixed(60 TRI1) andblas_paired_transform(20 TRI1) pass;blas_paired_sort_tilesloses its TRI1 nodes entirely.The counts vary between identical runs on the same binary, which looks like a race in the pairing step rather than a fixed layout error, and it may be specific to this driver — I have no Windows or AMD GPU here to compare. Worth checking the ordering of the sibling/TRI1 publication in
xdxr_build.comp.Everything else on this head passed:
xdxr_build,xdxr_build_output,xdxr_descs. Synthetic fixtures only, no game data. AI-assisted.@kawaii-shakal on GitHub · 2026-11-24 14:40 UTC · original
Thanks, that was a real bug, and your guess was right: it was the ordering in the pairing step.
MODE_PAIRrewrote the first triangle's staged leaf (rotated vertices, slot 3) from values it had loaded from that same leaf earlier in the same dispatch. That is exactly what the note at the top ofxdxr_build.compforbids for MoltenVK 1.4.2's SPIRV-Cross, which can move such a load after the store. So the rotation read partly rewritten vertices, depending on scheduling.Fixed in 1b859ca6d.
MODE_PAIRnow only records the pair: the sibling's partner, as before, and for the first triangleFIRST | siblingplus the rotationk | kd << 2.MODE_LEAF_PLACEthen builds the pair's leaf word by word from the two staged leaves, which nothing writes afterMODE_TRIANGLES, so no invocation stores to a word it loaded. Sizes are unchanged (34,048 / 846,848 / 12,160 bytes as before), and the scratch takes 4 more bytes a triangle.On RTX 5070 Ti (driver 617.42):
ctest -R "xdxr|khr_as_copy"7/7 in three runs without and three withLEONIDA_VK_VALIDATION=1, 0 rays differing in every scene. I can't run it on Apple here; if you have a moment to re-runxdxr_build_checkat 1b859ca6d, that would confirm it.@LewisCodesWebsites on GitHub · 2026-11-24 16:49 UTC · original
Tested 1b859ca6d (with #626 underneath, on main
21625bc) on AMD Radeon 660M (RDNA2 iGPU, ray query supported), Adrenalin 32.0.21045.1000, Windows 11 26200:ctest -R "xdxr|rt"passes 26/26 with this PR, includingxdxr_build_checkandd3d12_xdxr_rt_check, the same 26/26 as on main without it. No regressions on AMD. AI-assisted.@kawaii-shakal on GitHub · 2026-11-24 23:53 UTC · original
Rebased onto #626's new head
f51ef5c85(on main364ab4eab) as1700de85b. The only conflict was intests/test_xdxr_bvh.py: main addedtest_nan_child_box_at_root_is_rejectednext to this PR's dense-leaf tests, and both are kept. The file passes 56 of 56.xdxr_build.incmatchesglslcoutput. On an RTX 5070 Ti (driver 617.42, Windows 11 26300), all 8ctest -R xdxrtests pass, includingxdxr_build_check,d3d12_xdxr_rt_checkandvk_xdxr_postbuild_readback.AI-assisted.
@kawaii-shakal on GitHub · 2026-11-25 02:31 UTC · original
Rebased onto #626's new head
dcac757ab(main3ff2a2adc) asa98d67626. The only conflict was the README ray-tracing row; I kept this PR's version, which drops the 'no memory saved yet' note and keeps serialization.tests/test_xdxr_bvh.pypasses 56 of 56 andxdxr_build.incmatchesglslc. On an RTX 5070 Ti (617.42, Windows 11 26300),ctest -R 'xdxr|khr_as_copy'passes 9 of 9.AI-assisted.
@kawaii-shakal on GitHub · 2026-11-25 08:43 UTC · original
CI fix:
runtime/test/replay_readback_stages_test.cpp(added on main indfadf4ce5) assigned a three-argument lambda toxdxr_postbuild, which this branch gives a fourth (the postbuild type), sowindowsandlinux-gpu-toolsfailed at Build. That case now takes the extra argument (489d2b285).replay_readback_stages_testandreplay_khr_as_copy_postbuild_testbuild and pass on Windows 11 (MSVC 19.50).@kawaii-shakal on GitHub · 2026-11-26 19:14 UTC · original
Merged current main in
dbf2361e(Claude Code, AI-assisted). The conflict with #2222 needed more than a merge:layout_node()bounds parent pointers bypc.nodes_off, but a paired build places its nodes atnodes_off(), right after the kept leaves. Every parent was rejected and no box was propagated, so allblas_paired_*cases ofxdxr_build_checkmissed every ray. It now usesnodes_off(). Updates never pair, sorefit_source_okkeepspc.nodes_off.SCRATCH_REFITwas byte 28, which here isSCRATCH_LEAF_COUNT. It moves to byte 32, andMODE_CHECKmoves from 19 to 26, since 19-25 are taken here.
Full ctest, 113 of 113, on Mesa lavapipe,
xdxr_build_checkincluded. Worth a re-run on a hardware GPU.Generated by Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.