Skip to content

XDXR builder: BOX16 nodes for MINIMIZE_MEMORY BLASes, and TRI1 pairing - #3315

Open
zneel wants to merge 7 commits into
ItsNotRexed:mainfrom
zneel:xdxr-tri1-box16
Open

zneel wants to merge 7 commits into
ItsNotRexed:mainfrom
zneel:xdxr-tri1-box16

Conversation

@zneel

@zneel zneel commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claim: #2716 (comment). Item ID: not assigned yet; I asked in #3232. This is the README ray-tracing row's "Not done in the builder: TRI1 pairing, BOX16 nodes". It is separate from @opit80's RT-148 (serialization, batched/streaming builds); a split is proposed in #3232.

What changes

BOX16 inner nodes. A bottom-level BuildRaytracingAccelerationStructure with MINIMIZE_MEMORY now writes BOX16 nodes instead of BOX32:

  • 64 bytes per node instead of 128, with half-float boxes. The tree is the same.
  • A BLAS is about a fifth smaller: 39,040 bytes against 48,768 for the BLAS in d3d12_xdxr_rt_test, and 90,880 against 113,536 for 1,000 random triangles.
  • Prebuild info, the build and its refits all take the choice from the same flags (xdxr_box16), so the sizes stay exact.
  • Top-level builds stay BOX32. They are in world space, where a half's step is 2 m at 2 km.

How the boxes are rounded:

  • Each child box is rounded outward (min toward -inf, max toward +inf) from the exact box, which stays in scratch, so the rounding never adds up from level to level.
  • The rounding is integer code. packHalf2x16's rounding mode is implementation-defined, and AMD's driver rounds toward zero.
  • Beyond the half range, a bound becomes ±inf on its outward side and ±65504 on its inward side.
  • No half denormals are produced. A bound below 2^-14 in magnitude becomes 0 or ±2^-14, whichever is on its outward side, because a decoder that flushes denormals would otherwise shrink the box.
  • tools/xdxr_bvh.py half_round gets the same denormal rule.

A BOX16 layout ends with one zeroed 64-byte unit. The translator's image_bvh_intersect_ray loads a box node's 112 bytes of BOX32 bounds before it checks the node type, and the root is the last node, so a 64-byte root would otherwise be read past the structure.

TRI1 pairing. A bottom-level build without ALLOW_UPDATE pairs triangles, as the console builder does in its offline BLASes (docs/bvh.md §4a):

  • The pass that writes the nodes above the leaves pairs a triangle with a later sibling, among that node's at most four children.
  • The two must share an edge in opposite directions (the same vertex bits), come from the same geometry, and both be active.
  • The first triangle is rotated so the shared edge is slots 1 → 2. The sibling's third vertex goes in slot 3 and its primitive index in PrimitiveIndex2. Each node type's remap byte returns D3D12's barycentrics.
  • Every triangle keeps its own child pointer and box. So the tree, the layout and the sizes are unchanged, and the sibling's own leaf is left unused.
  • Nothing is saved yet. What pairing gives is the console's leaf format and the TRI1 path the game's shaders take. Reclaiming the unused leaves would need a relocating compaction (follow-up).
  • Pairs never cross nodes. So each rewritten leaf has one owner thread, and each parent-table entry has one writer.
  • A refit rewrites the leaves one triangle each, so:
    • the layer never pairs ALLOW_UPDATE builds
    • record_blas ignores pair on updates
    • replay now refuses a PERFORM_UPDATE without ALLOW_UPDATE, which D3D12 forbids anyway, instead of corrupting a paired BLAS

MINIMIZE_MEMORY is now also passed to the KHR path (LEONIDA_RT_AS=khr) as VK_BUILD_ACCELERATION_STRUCTURE_LOW_MEMORY_BIT_KHR, in both the build and the size query. This is untested: d3d12_xdxr_rt_test skips in KHR mode.

ASSUMPTIONS:

  • That MINIMIZE_MEMORY is the console's switch for BOX16. The offline packs have BOX16 roots, but how XboxBvhBuilder.dll chooses at run time is not traced. The one traced datum (docs/xdxr.md §3: a bottom-level path needing MINIMIZE_MEMORY and a stream value above 10.0) suggests the flag alone may not be the whole rule.
  • That pairing only siblings is close enough to the console builder's pairing rule, which is not traced either.

Tests

vk_xdxr_build_test, checked by xdxr_bvh.py check-build:

  • Five blas_box16_* cases: random triangles, the radix-sort path, an inactive triangle, extreme coordinates (past 65504, below 2^-14, ±1e30, ±0) and a refit.
  • Six blas_paired_* cases: indexed grids in BOX32 and BOX16, a transform, a mixed scene with a NaN vertex, the radix-sort path (2,625 pairs over 7,200 triangles), and a grid whose triangles start at varied vertices, so all nine (TRI0, TRI1) rotations occur.
  • Two blas_unpaired_* cases that must form no pairs: pairs split across two geometries, and edges shared in the same direction. Their candidate triangles do end up as siblings (11 and 14 such pairs), so the cases are not vacuous.

check-build gains these checks:

  • Every BOX16 word is compared bit for bit with encode_box16 of the exact box of the triangles under it.
  • Barycentrics are compared with brute force, not just t and the primitive.
  • Per-case expectations are enforced: "pairs" (some TRI1 nodes, or none), "box16" (only BOX16 or only BOX32 inner nodes) and "all_rotations".

d3d12_xdxr_rt_test (through the D3D12 API):

  • A MINIMIZE_MEMORY BLAS: its prebuild size is smaller, its postbuild size equals it, and it is updated in place.
  • A BLAS without ALLOW_UPDATE is paired (48 TRI1) at the same prebuild size.
  • The ALLOW_UPDATE BLASes must have no pairs.

The checks were tested by breaking the code on purpose:

  • Each of these makes check-build fail: dropping the geometry rule, allowing same-direction edges, a wrong remap byte, a reference that allows denormals, a swapped rounding direction, and a BOX32 dump labelled BOX16.
  • One rule is not caught: dropping the inactive-triangle rule changes no result. That is expected, because an inactive triangle's box is empty either way, so the rule is only conservative.

Results:

  • ctest 153/153 run serially after the rebase onto aa2988cc (7 skipped and 1 disabled, as on main).
  • python -I tests/test_xdxr_bvh.py 40/40.
  • xdxr_bvh.py selftest passes.
  • glslc from Vulkan SDK 1.4.363.0 reproduces main's xdxr_build.inc byte for byte from main's .comp.

Tested on AMD Radeon RX 9070 XT (RDNA4), driver 26.11.2, Windows 11 Pro 10.0.26300, Ryzen 7 9800X3D / 64 GB, MSVC 14.51.

Reviews: three independent AI review passes, one regular and two adversarial. None found a correctness bug in valid D3D12 usage. Between them they:

  • cross-checked half_directed against half_round bit for bit (2M float32 patterns)
  • checked the rotation and remap formulas against _remap_for (6,000 rotations) and fuzzed a port of the pairing over 300k sibling groups
  • emulated the translator's own traversal (float32 slab test, half decode, slot tables, remap byte) on 27 GPU dumps (0 rays differ) and fired 3,978 exact rays at shared edges

Their findings are fixed: the KHR size-query flag, updates without ALLOW_UPDATE, rotation coverage, the "box16" expectation, the BOX16 root over-read, and the docs.

Limits

  • An update whose MINIMIZE_MEMORY flag differs from its build's is refitted with the wrong layout. D3D12 requires the flags to match, but this can't be detected when the command is recorded; see the warning at xdxr_box16.
  • No test runs the translated image_bvh_intersect_ray on builder output. check-build traces with the Python reference's rules.

Found while doing this (translator, not changed here)

  • tools/rdna2spirv.py's box test has no min > max check, unlike the Python reference's _box_test. So an element whose box is empty (an inactive triangle, a masked or BLAS-less instance) is still traversed and its leaf tested, and a NaN vertex returns NaN.
  • This already happens on main with BOX32 (±inf boxes), and BOX16 (±65504) behaves the same.
  • Either the translator rejects min > max, or the builder writes a NaN min.x for such children (the translator does reject that).

Overlaps

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@MatyEjsr

Copy link
Copy Markdown

Tested db3e5fd7 on NVIDIA GeForce RTX 3090 (Ampere, driver 32.0.16.1742 / 617.42), Windows 11 (10.0.26200), VS 2022 Build Tools (MSVC 19.44.35230.0, Ninja RelWithDebInfo), Windows SDK 10.0.26100.0, Vulkan SDK 1.4.363.0, llvm-mc 23.1.5 (WSL Arch): pass.

  • python -I tests/test_xdxr_bvh.py: 36/36 OK (1.5s).
  • Incremental scripts\build_runtime.ps1 (171 actions): clean build, exit 0.
  • Targeted ctest -R ^(xdxr_descs|xdxr_build|xdxr_build_check|d3d12_xdxr_rt)$ (validation off): 4/4 pass — all 30 BVH cases in xdxr_build_check (including all BOX16 and TRI1 paired/rotation cases) had 0 validation errors and 0 differing rays vs brute force; d3d12_xdxr_rt confirmed MINIMIZE_MEMORY BLAS 39040 bytes (BOX16) and BLAS 48768 bytes.
  • Targeted ctest -R ^(vk_sync_validation|xdxr_build|xdxr_build_check|d3d12_xdxr_rt)$ with LEONIDA_VK_VALIDATION=1 and VK_LOADER_LAYERS_DISABLE=~implicit~: 4/4 pass, vk_sync_validation confirmed active, 0 validation errors across xdxr_build and d3d12_xdxr_rt.
  • python -I scripts/run_gpu_tests.py --build runtime/build --filter bvh: 2/2 passed (cs_bvh, cs_bvh32).
  • Full ctest (validation off, no game files): 132 passed, 8 skipped, 1 disabled (gameinput), 0 failed (149.6s, including d3d12_xdxr_rt_check).

AI-assisted.

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Windows + GPU check: AMD Radeon RX 9070 (RDNA4), Windows 11, MSVC Release, Vulkan SDK 1.4.363. Tested head db3e5fd merged onto main f847748 (clean merge), full build, full ctest -C Release -j 4: 100% tests passed out of 132 | new failures vs main: none. The main baseline on the same machine passes 132/132.

AI-assisted (Claude Code); runs on my machine.

@bielfreedom

Copy link
Copy Markdown

Tested db3e5fd7 (on its base f847748c) on AMD Radeon RX 9070 XT (RDNA4), AMD driver 32.0.32029.2010 (subgroup 32..64), Windows 11 Pro build 26200, MSVC build of runtime/, with Vulkan validation on (LEONIDA_VK_VALIDATION=1, Vulkan SDK 1.4.363, VK_LOADER_LAYERS_DISABLE=~implicit~): pass.

  • xdxr_build, xdxr_build_check, d3d12_xdxr_rt, d3d12_xdxr_rt_check and xdxr_descs pass. Full ctest: 129/129, 0 validation errors.
  • tests/test_xdxr_bvh.py: 36 OK.
  • Package-gated bvh_builder_test with LEONIDA_GAME_DIR set to my own 1.0.2.1 copy (outcome only): on the PC D3D12 device, XboxBvhBuilder(device, false) returns after 63 ms, 53 slot-62 CreateComputePipelineState calls, the destructor returns, OK (0 failures). With LEONIDA_BVH_DEVICE=vulkan it fails on the first slot-62 call (no translated shaders: set LEONIDA_SHADERS), but main f847748c does exactly the same, so that is setup (the DLL's embedded shaders aren't translated), not this PR.

AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head merged with main f847748, MSVC 14.51):

  • RTX 4080 SUPER: d3d12_xdxr_rt and xdxr_build pass.
  • Intel UHD 770 (VK_LOADER_DRIVERS_DISABLE=*nv*): d3d12_xdxr_rt and xdxr_build pass.
  • Negative control: with the builder files (d3d12_com.cpp, d3d12_vulkan_device.cpp, vulkan_backend.h, xdxr_build.comp/.h/.inc) reverted to main, d3d12_xdxr_rt fails on both GPUs, and vk_xdxr_build_test no longer compiles (XdxrLayout::compute and record_blas signatures).

Only these two tests were built and run, not the full ctest. No concerns.

@crastinator

Copy link
Copy Markdown
Contributor

Tested db3e5fd merged into main f847748c (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: 185/199 native, 185/199 with LEONIDA_W64_EMULATE=1 (the skips are the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 41/41.
  • tests/test_xdxr_bvh.py: 36 passed.

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

@DaniSBR1

Copy link
Copy Markdown
Contributor

Two things from an RX 5700 XT (RDNA1, RADV) that bear on BOX16 nodes.

  1. The translator's image_bvh_intersect_ray loaded the box32 words for box16 nodes too, up to byte 112 of a 64-byte node. When a box16 node ends its buffer, the read leaves the allocation. Here that was a GPUVM page fault and a lost device, with a BOX16 BLAS from tools/xdxr_bvh.py. Translator: a BVH box node reads only its own words #3803 makes each box node read only its own layout. So a BOX16 BLAS from this PR is safe to traverse with it, and not before if its last node ends the buffer.
  2. BOX16 isn't faster to traverse here. A translated closest-hit traversal of a 100k-triangle BLAS with incoherent rays takes 14.1 ms with BOX16 and 13.0 ms with BOX32 (with Translator: a BVH box node reads only its own words #3803): unpacking the halves costs about what the smaller node saves. That fits using it for MINIMIZE_MEMORY only.

Separately, I posted a finding about the tree shape in this file (four consecutive Morton children per node vs a radix tree, about 2× the traversal steps) in #3574 (finding). Tell me whether you'd like to take it.

AI-assisted (Claude Code); the runs are on my own RX 5700 XT.

@zneel

zneel commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@DaniSBR1, thanks for both measurements.

  1. A BOX16 BLAS from this PR doesn't end on a node. XdxrLayout::compute adds one zeroed 64-byte unit after the nodes when box16 is set (runtime/src/xdxr_build.h, the pad lines, commit db3e5fd). The prebuild and postbuild sizes include it. The root is the last node, so the 112-byte read from it stays inside the structure, on main's translator as well as with Translator: a BVH box node reads only its own words #3803. Your page fault came from a tools/xdxr_bvh.py BLAS, which has no spare unit. So Translator: a BVH box node reads only its own words #3803 isn't a prerequisite for XDXR builder: BOX16 nodes for MINIMIZE_MEMORY BLASes, and TRI1 pairing #3315; it still fixes the Python BLASes and the ~10% on BOX32. Once Translator: a BVH box node reads only its own words #3803 lands, the spare unit could go, but runtime_bvh_bytes in RT-148 would need to agree, so I'd leave it until then.
  2. Agreed. That's why only MINIMIZE_MEMORY gets BOX16.

On the tree shape (#3574): please take it after #3315 lands, rather than folding it in. #3315 is tested on six GPUs as it is, and a new tree shape needs its own review. One thing to watch: the builder's prebuild sizes are exact because the node count depends only on the element count. A radix tree collapsed to four children has a variable node count, so it needs an upper bound, or a compaction, for prebuild info. TRI1 pairing only needs siblings under the same node, so it should carry over as long as leaves stay grouped under their parents.

AI-assisted (Claude Code).

@iurysf

iurysf commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Code read of db3e5fd7 (GPU tests are already in; this is what they don't show): looks good, one robustness suggestion.

  • The generated runtime/src/xdxr_build.inc is exactly this PR's .comp: glslc --target-env=vulkan1.2 -O -mfmt=num
    (Vulkan SDK 1.4.363.1) gives the same 21,280 words, so nothing is in the binary that isn't in the source.
  • I ported half_directed line by line and compared it with tools/xdxr_bvh.py half_round on 597,666 cases (random
    bit patterns plus ±0, ±inf, 65504 and one ulp above, 65536, 2^-14 and just below, denormals), both directions: 0
    differences.
  • The spare BOX16 unit is always fully zeroed: MODE_INIT now dispatches at least 16 threads, and the parent table always
    has at least 16 entries (it is rounded to 64 bytes), so the extra threads stay inside it.
  • pair_children only touches its own node's leaves and takes each child's box from scratch, rotation is cyclic (winding
    kept), and pairing never runs on a TLAS or a refit. xdxr_box16/xdxr_pair are applied the same way in prebuild info,
    xdxr_check and xdxr_record. The translator already walks type-4 BOX16 nodes and the TRI1 slot/remap tables
    (tools/rdna2spirv.py:10328-10571), so the output is consumable. Only the end-to-end test you mention is missing.
  • Suggestion: the WARNING at xdxr_box16 says an update whose MINIMIZE_MEMORY differs from its build "writes past
    the structure". A BOX16 build refitted as BOX32 writes 128-byte nodes into a 64-byte-node structure, i.e. into
    whatever follows it in the arena. D3D12 forbids that input, but the layer records every build itself, so keeping
    dst_va → box16 (and size) and refusing a mismatching update in xdxr_check would turn silent corruption into a
    refused command. Not blocking.

Ran on Windows 11, Python 3.14: tests/test_xdxr_bvh.py (36 OK), tools/xdxr_bvh.py selftest (paired grid, BOX32 and
BOX16: 0 validation errors, 0/400 rays differ). Didn't rebuild the runtime; four GPUs already did.

AI-assisted code read (Claude).

zneel and others added 7 commits November 22, 2026 23:29
A bottom-level BuildRaytracingAccelerationStructure with MINIMIZE_MEMORY now
writes BOX16 inner nodes (64 bytes, half boxes) instead of BOX32 (128 bytes):
the same tree, about a fifth smaller. Prebuild info, the build and its refits
take the choice from the same flags (xdxr_box16), so the sizes stay exact.
Top-level builds keep BOX32 (world space: a half's step is 2 m at 2 km).

Each child box is rounded outward from the exact box kept in scratch, in
integer code (packHalf2x16's rounding is implementation-defined; AMD rounds
toward zero). Past the half range a bound goes to +-inf outward and +-65504
inward, so empty slots stay empty; below the smallest normal half it goes to
0 or +-2^-14, never a denormal a flushing decoder would shrink.
tools/xdxr_bvh.py half_round gets the same denormal rule, and check-build now
compares every BOX16 word bit for bit with encode_box16 of the exact box of
the triangles under it.

Tests: five blas_box16_* cases in vk_xdxr_build_test (radix and small sort,
an inactive triangle, values past 65504 and below 2^-14, a refit), and a
MINIMIZE_MEMORY BLAS plus its in-place update through the D3D12 API in
d3d12_xdxr_rt_test (prebuild and postbuild sizes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
glslc --target-env=vulkan1.2 -O -mfmt=c xdxr_build.comp -o xdxr_build.inc
(Vulkan SDK 1.4.363.0's glslc; it reproduces the previous blob byte for byte
from the previous .comp).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A bottom-level build without ALLOW_UPDATE now pairs triangles, as the
console builder does in its offline BLASes. The pass that writes the nodes
above the leaves pairs a triangle with a later sibling (among that node's at
most four children) that shares an edge in the opposite direction (the same
vertex bits), from the same geometry, both active. The first triangle is
rotated to put the shared edge in slots 1 -> 2, the sibling's third vertex
goes in slot 3, its primitive in PrimitiveIndex2, and each node type's remap
byte returns D3D12's barycentrics for its own vertex order.

The node keeps one child per triangle with its own box, so the tree, the
layout and the sizes do not change; the TRI1 child points at the first
leaf and the sibling's leaf is left unused. Pairs never cross nodes: one
thread owns each rewritten leaf and each parent-table entry. A refit
rewrites the leaves one triangle each, so the layer does not pair builds
with ALLOW_UPDATE (xdxr_pair), and record_blas ignores `pair` for updates.

check-build now compares barycentrics as well as hits, and checks a case's
"pairs" field: at least one TRI1 node, or none. New cases: paired grids
(BOX32 and BOX16), a transform, a mixed scene, the radix path, and two that
must not pair (pairs split across geometries, edges shared in the same
direction), plus a D3D12 BLAS without ALLOW_UPDATE. Mutating the geometry or
the direction rule, or the remap byte, fails check-build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
glslc --target-env=vulkan1.2 -O -mfmt=c xdxr_build.comp -o xdxr_build.inc

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…omments)

- GetRaytracingAccelerationStructurePrebuildInfo's KHR path passes
  LOW_MEMORY for MINIMIZE_MEMORY, as the build now does (Vulkan sizes a build
  with identical flags).
- check-build enforces a case's "box16" field (only BOX16 or only BOX32
  inner nodes), so a BOX16 case that came out BOX32 cannot pass the bit
  check vacuously; the vk and D3D12 BOX16 cases set it.
- Comments: half_round's inward overflow, the remap byte's positions, what
  the half-rounding table test covers, and what an update that breaks
  D3D12's flag or ALLOW_UPDATE rules would do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, rotation coverage, docs)

- xdxr_check refuses PERFORM_UPDATE without ALLOW_UPDATE (D3D12 requires
  it): a structure built without it may be paired, and a refit would leave
  its TRI1 children reading wrong vertices.
- blas_paired_rotations: a grid whose triangles start at varied vertices,
  so pairs use all nine (TRI0, TRI1) rotations; check-build asserts it
  ("all_rotations"). Before, the sibling rotation kd = 1 never occurred.
- BOX32 cases now say "box16": false, so a stray BOX16 is caught too.
- docs/bvh.md cites the one traced BOX16-related datum (docs/xdxr.md: a
  bottom-level path needing MINIMIZE_MEMORY and a stream value above 10),
  notes that world-space BLASes only get looser boxes; README says pairing
  saves no memory yet and the BOX16 switch is assumed; comments rewrapped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tes per box node)

tools/rdna2spirv.py's image_bvh_intersect_ray loads a box node's BOX32
bounds (112 bytes) before it selects BOX16 or BOX32, and the root is the
last node, so a BOX16 root was read 48 bytes past the structure. A BOX16
layout now ends with one zeroed 64-byte unit (MODE_INIT clears it); the
D3D12 test's BOX16 BLAS is 39,040 bytes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DaniSBR1

Copy link
Copy Markdown
Contributor

@zneel, thanks. You're right: I overstated it in my claim. Your BOX16 BLASes end with the spare unit, so main's translator stays inside them. The fault came from a tools/xdxr_bvh.py BLAS. #3803 still matters for those and for box32.

I'll take the tree shape after #3315 lands, as its own PR. On prebuild sizes: a radix tree collapsed to four children has at most N − 1 inner nodes (the binary tree's own count), against about N/3 now. So the plan is to reserve that bound and report the real size through the postbuild COMPACTED_SIZE. A compaction can then reclaim the rest. I'll keep the leaves grouped under their parents, so TRI1 pairing carries over.

AI-assisted (Claude Code).

@DoubleD17

Copy link
Copy Markdown

Independent Windows check of c2f3eaa308a2c67a48987e772f7feea3a16b519c on a GeForce RTX 5070 (Blackwell, NVIDIA 621.14, 32-wide subgroups). Built x64 RelWithDebInfo with VS 2022, MSVC 19.44 and Windows SDK 10.0.26100.0. Both native tests used the default XDXR path.

  • xdxr_build passed. The CPU checker matched the 30 GPU-generated cases against brute force with 0 differing rays out of 26,200 and 0 BVH structure errors. This included paired TRI1 rotations and BOX16 refits.
  • d3d12_xdxr_rt passed. The 7 GPU-generated D3D12 cases matched on all 7,000 rays with 0 BVH structure errors. For the same input geometry, MINIMIZE_MEMORY reduced the BLAS from 48,768 to 39,040 bytes (19.9%). The paired case contained 48 TRI1 records.
  • python -I tests/test_xdxr_bvh.py -q passed 40 tests.

I ran tools/xdxr_bvh.py check-build <case-dir> --rays 1000 directly with Python 3.13 on each CTest output directory after CMake picked a Store Python executable that CTest could not launch. All scenes were synthetic. AI-assisted verification.

@PAYS0

PAYS0 commented Nov 23, 2026

Copy link
Copy Markdown

Written and tested by a Claude Code session on my PC; I'm posting it for that session.

Tested c2f3eaa3 on AMD's Windows driver (an RDNA2 iGPU) and on an RTX 5070, against main 03b09a08: pass. There's one cross-vendor note below. It comes from code that's already on main, so it isn't a blocker.

Setup: Windows 11 Pro 26200, VS 2022 (MSVC), Vulkan SDK 1.4.363.0, Python 3.13. Built with LEONIDA_BUILD_WINDOWS_RUNTIME=OFF: this machine has Windows SDK 10.0.22621, so d3d12_xdxr_rt isn't built here.

  • AMD Radeon(TM) Graphics, gfx1036 (Ryzen 5 7600X iGPU), AMD driver 32.0.21042.62, subgroup 32..64.
  • NVIDIA GeForce RTX 5070, 617.42.

Results on both GPUs

  • ctest -R "^xdxr": xdxr_descs, xdxr_build and xdxr_build_check pass. All 30 cases give 0 validation errors and 0 differing rays, including the 13 new ones (blas_box16_*, blas_paired_*, blas_unpaired_*). The TRI1 counts are the same on both GPUs: 92, 81, 51, 171, 2625 and 20.
  • tests/test_xdxr_bvh.py: 40 passed (37 on main). xdxr_bvh.py selftest is clean.
  • The committed xdxr_build.inc is exactly what glslc --target-env=vulkan1.2 -O -mfmt=c (v2026.4) gives for this head's .comp, and it passes spirv-val (@iurysf checked the same at db3e5fd7).
  • The 17 cases that main also has keep their sizes and still pass, and 11 of them are byte-identical to main. blas_one, blas_five, blas_empty and the TLAS cases change bytes only in the parent table's unused tail. With MODE_INIT now run on at least 16 entries, that tail is 0xffffffff, where main left whatever the buffer held.
  • Timing mode (vk_xdxr_build_test <dir> N, default layout), at 100k and 1M random triangles: builds and refits are within noise of main on both GPUs. At 1M, a build takes 119 ms against 122 ms on the gfx1036, and 3.44 ms against 3.48 ms on the RTX 5070.

Cross-vendor bytes
26 of the 30 cases are byte-identical between the two GPUs.

  • The three TLAS cases differ only in the BLAS address and in 1-ULP differences in the inverse transform. main shows the same.
  • blas_box16_extremes has the same leaves but a different tree:
    • morton() quantizes (c - cmin) / extent. For the element whose centre is cmax, that's x/x.
    • The gfx1036 gives 1.0 (bin 1023) and the RTX 5070 gives 1 − 2⁻²⁴ (bin 1022). So triangles 12 and 25 get different keys, and the sort order changes.
    • I recomputed the Morton order from the case's triangles both ways. The gfx1036's tree matches it with exact division, and the RTX 5070's with reciprocal-then-multiply.
    • Both trees validate and trace the same.
    • morton() is the same on main; this PR's new case is the first to show it.

If identical trees across vendors matter, for comparing builds or for #4098's radix tree, selecting 1.0 for the max centre removes this case:

vec3 c = (lo + hi) * 0.5;
vec3 t = mix(clamp((c - cmin) / extent, 0.0, 1.0), vec3(1.0), equal(c, cmax));
uvec3 q = uvec3(t * 1023.0);

I tried it with xdxr_build.inc regenerated:

  • All 27 BLAS cases are then byte-identical across the two GPUs.
  • The gfx1036's output doesn't change at all.
  • On the RTX 5070, only blas_box16_extremes changes.

A key whose quotient falls within an ULP of another bin edge could still differ. This only removes the edge every build has. I haven't tested it beyond these 30 cases.

Synthetic cases only, no game files. AI-assisted (Claude Code).

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.

10 participants