Repository navigation
Conversation
… pair TRI1 pairing (ItsNotRexed#3315) put a pair's two triangles in the first one's leaf but left the sibling's own leaf unused, so a paired BLAS was as large as an unpaired one. docs/bvh.md 7a listed "a compaction that reclaims the leaves that pairing leaves unused" as not done. This writes the leaves after the pairs are known, packed, so a paired build ends a leaf earlier per pair, and COMPACTED_SIZE, CURRENT_SIZE and COMPACT give that back. What changes (runtime/src/xdxr_build.comp, xdxr_build.h) - With FLAG_PAIR, MODE_TRIANGLES stages each triangle in scratch (its vertices' bits, GeometryIndexAndFlags, its primitive index) instead of writing its leaf. - New passes after MODE_KEPT_INDEX: - MODE_PAIR: one thread per kept node. Same pairing rule as before (siblings, shared edge in opposite directions, same geometry, both active), but it records the pairs instead of writing leaves. - MODE_LEAF_COUNT, MODE_LEAF_SCAN, MODE_LEAF_INDEX: number the leaves, one per unpaired triangle or pair, in element order. A count per tile of 256 elements, the existing one-workgroup scan, then an index per tile, as for the kept nodes. - MODE_LEAF_WRITE: writes them from offsetToElements on. - The nodes start right after the last leaf (nodes_base()). MODE_NODES points a paired sibling's child at its pair's leaf as TRI1, as before. The tree, the TRI1 leaf format, the remap bytes and the one parent per leaf do not change. - Builds without pairing are unchanged (same records, same size). Updates never pair (ALLOW_UPDATE), so a refit still finds the nodes at the layout's offset. - XdxrLayout::compute takes `pair`: the prebuild result size stays the unpaired one (the bound), and the scratch grows by 56 bytes per triangle plus 8 per tile of 256. The pairing arrays come before the box accumulators, because MODE_TRIANGLES uses pc.arg0 for the vertex stride. GetRaytracingAccelerationStructurePrebuildInfo now maps ALLOW_UPDATE so that it asks for that scratch exactly when the build may pair, and the replay computes the same layout. record_blas pairs only when the layout has room for it. - xdxr_build.inc regenerated with glslc --target-env=vulkan1.2 -O -mfmt=c (Vulkan SDK 1.4.363.0, the same output as main's .inc for main's .comp). Tests (no game files) - tools/xdxr_bvh.py: leaf_packing(). check-build runs it on every BLAS case: each 64-byte unit from offsetToElements to offsetToNodes must be the leaf of exactly one reachable TRI0 pointer, a TRI1 pointer must share a TRI0's leaf, and no leaf may lie outside that range. tests/test_xdxr_bvh.py checks it on the CPU encoder's builds, plus a mutation that leaves a leaf unreferenced. - Negative control: check-build with leaf_packing on the cases written by ItsNotRexed#3315's builder fails exactly the six paired cases ("leaf at ... has 0 TRI0 pointers"), and no other case. - d3d12_xdxr_rt_test, for the BLAS built without ALLOW_UPDATE: - its scratch comes from its own prebuild info, which must be larger than the ALLOW_UPDATE one's; - its COMPACTED_SIZE must be below the unpaired build's (same tree), by at most one leaf per two triangles; - it is compacted into a buffer of exactly that size and written as d3d12_blas_paired_compacted for check-build. - Measured on an RX 7900 XTX: blas_paired_sort_tiles (a 7,200-triangle grid) is 846,848 bytes instead of 988,160 (2,208 pairs, 14% smaller). The D3D12 test's BLAS is 54,464 bytes instead of 58,368 (61 pairs). Tested on an AMD Radeon RX 7900 XTX (Windows 11, driver 32.0.32029.2010, MSVC 14.44, Vulkan SDK 1.4.363.0): - xdxr_build_output, xdxr_descs, xdxr_build, xdxr_build_check, d3d12_xdxr_rt, d3d12_xdxr_rt_check and d3d12_vulkan_device pass. Every ray matches brute force in every case. - tests/test_xdxr_bvh.py passes (48 tests). - Full ctest on main 9565440 plus this change: 254 of 258 pass. The 4 that fail (vk_queue_query_sync, d3d12_texture_tiles, d3d12_indirect_dispatch_count, d3d12_pipeline_library_host) fail the same way on main without it, on this machine. - run_gpu_tests.py: all 242 test shaders translate and pass spirv-val. 220 of 236 GPU tests pass, 16 are skipped, none fails. - On this branch (main 1cc6e3c plus this commit), built again: the XDXR tests above, cs_bvh, cs_bvh32, tests/test_xdxr_bvh.py and the tests/test_docs_*.py checks pass. Not done, or not verified - Only tested on one GPU (RDNA3). Not run on NVIDIA, Intel, RADV, MoltenVK, llvmpipe or under Wine. The new passes are plain compute with shared memory and barriers, like the kept-node passes; no subgroup operations. - Build time with pairing was not measured: five more dispatches and a staging round trip per triangle. - Still not paired: - Structures that may be updated (ALLOW_UPDATE). An update would have to find each triangle's leaf again, and vertex-bit matching is not stable under motion. - Pairs across nodes. A leaf has one parent table entry, so both pointers must share a parent. AI-assisted (Claude). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflict in GetRaytracingAccelerationStructurePrebuildInfo: main checks desc before the XDXR branch now; the XDXR layout keeps the pairing scratch (ALLOW_UPDATE mapped, xdxr_pair). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent NVIDIA check of Of 30 emitted structures, exactly six shrank. All six were paired cases. For each, the byte reduction was exactly 64 times the number of TRI1 nodes reported by the checker. For example, the BOX16 paired grid went from 17,344 to 12,160 bytes (81 pairs); the sort-tiles case went from 988,160 to 846,848 (2,208 pairs). The two fixtures that request pairing but cannot form a legal pair kept their original sizes. The PR passed |
|
Tested b6f421b on Windows 11, Python 3.15.2, NVIDIA RTX 4060 Ti (driver 621.24; CPU-only checks, no game files, no GPU/llvm-mc/MSVC used): pass. Ran the test files this PR adds or changes, from a clean checkout of the PR head: AI-assisted (Claude Code). |
|
Tested Tested on: Windows 11 Pro (Build 26200), AMD Ryzen 5 5500, 16 GB RAM, AMD Radeon RX 5600 XT (
AI-assisted. |
Claimed in the coordination issue as: PROC-401
Depends on: none. It conflicts with #5092 (
docs/bvh.md,runtime/src/xdxr_build.inc) and #4640 (runtime/src/vulkan_backend.h); whichever lands second rebases.What and why
TRI1 pairing (#3315) put a pair's two triangles in the first one's leaf but left the sibling's own leaf unused, so
a paired BLAS was as large as an unpaired one. docs/bvh.md 7a listed "a compaction that reclaims the leaves that
pairing leaves unused" as not done. This writes the leaves after the pairs are known, packed, so a paired build
ends a leaf earlier per pair, and COMPACTED_SIZE, CURRENT_SIZE and COMPACT give that back.
What changes (runtime/src/xdxr_build.comp, xdxr_build.h)
primitive index) instead of writing its leaf.
same geometry, both active), but it records the pairs instead of writing leaves.
order. A count per tile of 256 elements, the existing one-workgroup scan, then an index per tile, as for the kept
nodes.
pair's leaf as TRI1, as before. The tree, the TRI1 leaf format, the remap bytes and the one parent per leaf do not
change.
still finds the nodes at the layout's offset.
pair: the prebuild result size stays the unpaired one (the bound), and the scratchgrows by 56 bytes per triangle plus 8 per tile of 256. The pairing arrays come before the box accumulators,
because MODE_TRIANGLES uses pc.arg0 for the vertex stride. GetRaytracingAccelerationStructurePrebuildInfo now
maps ALLOW_UPDATE so that it asks for that scratch exactly when the build may pair, and the replay computes the
same layout. record_blas pairs only when the layout has room for it.
main's .inc for main's .comp).
Tested
Tests (no game files)
to offsetToNodes must be the leaf of exactly one reachable TRI0 pointer, a TRI1 pointer must share a TRI0's leaf,
and no leaf may lie outside that range. tests/test_xdxr_bvh.py checks it on the CPU encoder's builds, plus a
mutation that leaves a leaf unreferenced.
paired cases ("leaf at ... has 0 TRI0 pointers"), and no other case.
(2,208 pairs, 14% smaller). The D3D12 test's BLAS is 54,464 bytes instead of 58,368 (61 pairs).
Tested on an AMD Radeon RX 7900 XTX (Windows 11, driver 32.0.32029.2010, MSVC 14.44, Vulkan SDK 1.4.363.0):
d3d12_vulkan_device pass. Every ray matches brute force in every case.
d3d12_texture_tiles, d3d12_indirect_dispatch_count, d3d12_pipeline_library_host) fail the same way on main
without it, on this machine.
none fails.
d3d12_xdxr_rt, d3d12_xdxr_rt_check, cs_bvh, cs_bvh32, tests/test_xdxr_bvh.py and the tests/test_docs_*.py checks
pass. d3d12_vulkan_device fails there, and it fails the same way on that main without this change (3 of 3 runs
on this machine), so it is not from this PR.
Not done, or not verified
are plain compute with shared memory and barriers, like the kept-node passes; no subgroup operations.
vertex-bit matching is not stable under motion.
AI-assisted: yes (Claude)
Checklist
docs/design.md, with how it was confirmed. (No new translator rule in this PR.)🤖 Generated with Claude Code