xdxr: a paired BLAS keeps one 64-byte leaf a pair (RT-XDXR-PAIR-DENSE) #690
Closed
leonida/mandy
kawaii-shakal wants to merge 0 commits from
rt-xdxr-pair-dense into main
pull from: rt-xdxr-pair-dense
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!690
Loading…
Reference in a new issue
No description provided.
Delete branch "rt-xdxr-pair-dense"
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 closed
This pull request cannot be reopened because the branch was deleted.
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
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.
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.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.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.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.
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.
CI fix:
runtime/test/replay_readback_stages_test.cpp(added on main in dfadf4ce5) 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).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
Hi @kawaii-shakal, thanks for this pull request. It currently conflicts with
main(conflicting file(s):runtime/src/xdxr_build.h), so it carries theneeds rebaselabel. CONTRIBUTING.md asks authors to rebase their branch onmain; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.AI-assisted (Claude Code, Claude Opus 5.5).
Updated: main is merged in (
9d10175) and theruntime/src/xdxr_build.hconflict is resolved; the needs-rebase label is gone. I'm keeping the PR open, but I can't run the GPU tests myself for about a week. If someone with an RT-capable GPU can run the xdxr tests on the current head before then, that would help; otherwise I'll report back after that.Generated by Claude Code
Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (
d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools,d3d12/, or general docs), please feel free to reopen it.