Repository navigation
D3D-412: TLAS instances fold the BLAS leaf frame and store +64 in the console order - #4011
wildheathen wants to merge 1 commit into
Conversation
05b92df to
69ce3a4
Compare
|
Independent RTX 3080 / NVIDIA 616.64 verification of rebased I independently regenerated the shader after combining the GLSL with main's radix-offset change. The result exactly matches the published rebased blob |
Flyander
left a comment
There was a problem hiding this comment.
Reviewed the rebased head 69ce3a4. The added leaf-frame transform and TLAS instance layout are covered by the reported independent GPU and CPU-oracle checks, and the regenerated shader matches the documented source change. I found no distinct blocking issue.
|
Tested
AI-assisted (Claude). No game files. |
|
Tested Negative control. With
So the check catches a GPU builder that writes the old The GLSL and Python rotation tables are the same. Your evidence compares
Only the last bit of a product can differ, since the GPU may fuse multiply-adds. With the PR's own blob, all 20 cases agree with brute force, so that last bit doesn't change a hit here. AI-assisted (Claude Code). |
|
Tested 69ce3a4 (merged onto main aa2988c) on NVIDIA GeForce RTX 4060 Ti, driver 610.88 (32.0.16.1088), Windows 11 26200, MSVC 14.51.36231 (VS 2026), Vulkan SDK 1.4.363.0: pass
AI-assisted (Claude). |
… console order A console BLAS keeps its leaves and nodes in the frame of its compressionParams (docs/bvh.md 4a): (R * v - t) * s, sceneBounds in object space. XboxBvhBuilder.dll's LoadInstances folds that frame into each instance's world-to-object matrix whenever any of bits 24-31 is set, and sets INST_SCALED_LOCAL_SPACE in the root-pointer word. Both Leonida TLAS builders stored the plain inverse and never read the BLAS's +0x3C. Every BLAS of the shipped *_bvh4 packs has a frame. The same 12 floats were also in the wrong order. The console stores the translation first (+64..+72) and then the 3x3 row by row (+76, +88, +100), and the game's RT compute shaders read them that way. Leonida wrote and read a row-major 3x4 there. - tools/xdxr_bvh.py: leaf_frame / to_leaf_frame; build_blas(compression=) builds a BLAS in a frame; build_tlas folds the frame and sets bit 30 (the identity flag needs a clear scale bit and rotation 0); +64 is packed and read in trace() in the console order; check_build takes a BLAS's object_triangles for the instances that place it, and its TLAS t comparison gains abs_tol=1e-6. - runtime/src/xdxr_build.comp build_instance: the same composition, flags and order; xdxr_build.inc regenerated with the command in xdxr_build_spv.h. - runtime/test/vk_xdxr_build_test.cpp: two leaf-frame BLAS (scale and translation; scale and rotation 21) and a TLAS over them, checked by xdxr_build_check. - tests/test_xdxr_bvh.py: LeafFrame tests and the +64 order; docs/bvh.md: 4a and the INSTANCE row.
69ce3a4 to
458c1dd
Compare
|
Rebased on Two conflicts:
The non-conflicting hunks applied line for line. Tested on RTX 5080, Windows 11, MSVC (VS 18 Build Tools), Vulkan SDK 1.4.363.0:
#3944 still touches the same three files, so whichever lands second needs a rebase and a regenerated AI-assisted. |
|
Independent check of rebased I also resolved the overlap with #8155 ( As an integration control, I used a framed BLAS with a TLAS instance that permutes the axes, translates and mixes scales AI-assisted verification. Synthetic geometry only. |
|
Thanks @senyurah, both for the check and for trying the #8155 combination. On the different word stream: On #8155: agreed that it belongs on top. Its stabilized inverse goes before the leaf-frame fold, as you did. Your extreme-scale probe failing on #4011 alone is the case #8155 fixes, not a regression here. #8155 already lists AI-assisted. |
Claimed in the coordination issue as: D3D-412, claim (from the finding).
What and why
A console BLAS keeps its leaves and nodes in the frame of its
compressionParams(docs/bvh.md§4a):(R * v - t) * s. ItssceneBoundsstay in object space. The console'sLoadInstances(inXboxBvhBuilder.dll, read from its DXIL) does two things whenever any of bits 24-31 is set:INST_SCALED_LOCAL_SPACE(0x40000000) into the root-pointer word.A traversal then only applies the matrix at record
+64.The same 12 floats had a second difference: their order. The console does not store the world-to-object matrix as a row-major 3x4. It stores its translation first (
+64,+68,+72), then the 3x3 row by row (+76,+88,+100).+0keeps the D3D12 object-to-world 3x4 as given. Both Leonida builders andtrace()used row-major 3x4 at+64, which is self-consistent but not what the game's RT shaders read: they would take(1, 0, 0)as the translation of an identity instance. This PR writes and reads the console order. Evidence (offsets and counts only):LoadInstances' stores put (t0, t1, t2, r00) at+64, (r01, r02, r10, r11) at+80and (r12, r20, r21, r22) at+96, traced back to the inverse it computes.All 64 RT compute shaders in the shader archive (40
image_bvh_intersect_ray, 24image_bvh64_intersect_ray) read the instance record the same way. Their instance branch loads+48..+63and the 12 floats. It masks the+56word with0x3FFFFFFFand tests only its bit 31, never0x40000000and never the BLAS's+0x3C. In the 32-bit ones, row 0 of the transform uses+76/+80/+84for x, y and z, and the identity-rotation path adds only+64/+68/+72. Both Leonida TLAS builders stored the plain inverse instead and never read the BLAS's+0x3C. That is invisible with their own BLAS, which are uncompressed, but every BLAS of a shipped*_bvh4pack has a frame: all 1,237 ofshared_minigame000_bvh4and all 271,627 ofcore_bvh4set bit 31. A TLAS over rehydrated console BLAS (RT-212, TEST-376) would therefore be traversed in the wrong space.tools/xdxr_bvh.py:leaf_frame/to_leaf_framedecode the word;build_blas(..., compression=)builds a BLAS in a frame, as console BLAS are: leaves and nodes in the frame,sceneBoundsin object space, the word at+60;build_tlasfolds(R * M^-1 - t) * sinto+64and sets bit 30. The identity flag needs a clear scale bit and rotation index 0, as inLoadInstances;+64is written (_pack_world_to_object) and read intrace()(_unpack_world_to_object) in the console order;check_buildtakes a BLAS's object-space triangles (object_triangles) for the instances that place it.runtime/src/xdxr_build.compbuild_instance: the same composition, flags and+64order.xdxr_build.incis regenerated with the command inxdxr_build_spv.h(glslc from shaderc v2026.4; the unchanged source regenerates byte-identical).runtime/test/vk_xdxr_build_test.cpp: two BLAS in a frame (scale plus translation; scale plus rotation index 21), built from triangles mapped into the frame and then given object-space bounds and the word, and a TLAS of three instances over them.xdxr_build_checktraces it against brute force.docs/bvh.md: §4a and the INSTANCE row say what the traversal sees, the+64order included.Tested
Windows 11, RTX 5080 (driver 621.24), MSVC 14.51, Python 3.14:
python -I tests/test_xdxr_bvh.py: 38 tests OK.test_world_to_object_is_translation_then_rowspins the+64order with a rotated and shifted instance. It and the four existing assertions on+64fail with the row-major order. The four newLeafFrametests fail before the change (withbuild_tlasstoring the plain inverse, the TLAS gives other hits than brute force, and the record has no bit 30); with the fold disabled again, all four fail.vk_xdxr_build_test+xdxr_bvh.py check-build, before the shader change:tlas_leaf_frame258 of 1,000 rays differ from brute force. After it, every case agrees with brute force,blas_leaf_frame,blas_leaf_frame_rotatedandtlas_leaf_frameincluded (ctest runs it with 1,000 rays; see below).ctest, rebased onmainaa2988cc(xdxr_build.incregenerated from the merged shader; the unchangedmainshader regenerates its own.incbyte-identical with this glslc): 153 of 153 pass.d3d12_xdxr_rt_checktraces the D3D12 layer's own TLAS, so the GPU builder and the walker agree on the new order. On the way, before the tolerance change below, 131 of 132 passed. The one failure wasxdxr_build_checkon the existingtlascase: the new cases shift the shared random ray sequence, and one new ray hits the same triangle att= 1.62e-4, 2e-8 away from brute force. That is aboverel_tol=1e-4, but it is the float32 inverse's absolute rounding, so the TLAS comparison gainsabs_tol=1e-6. The sametlas.binpasses 1,000 rays with the old sequence. After the change, the sixxdxr/bvhtests pass,xdxr_build_checkincluded.python -m pytest tests -q --tb=no --ignore=tests/semanticon this branch and on its parentf847748c: the same 41 failures in both (tools that need numpy/Pillow, absent here, and the duplicated docs rows), and 12 more passing on the branch.LoadInstancesholds its 64 rotations as a 576-float table. All 64 equal_rotation(i)bit for bit, with the table read as columns. The shader applies them asR * v(columnkofRtimes componentk), toM^-1's columns and its translation, which is the(R * M^-1 - t) * sthe builders write. Both builders also match brute force with rotation index 21.shared_minigame000_bvh4and all 271,627 ofcore_bvh4set bit 31 (1,237 and 28,410 of them bit 30), and none uses a rotation;+64words are bit-identical to the console's, since the console composes in float32dot4steps and the CPU encoder in double, rounded once (the order is verified, the last bits are not);sceneBounds;Checklist
CONTRIBUTING.md): synthetic scenes only. The DXIL reading and the pack counts were done locally, and only offsets and counts are quoted.docs/design.md: not applicable, the translator is not touched.AI-assisted.