Repository navigation
xdxr: check the update source and bound the builder's reads (RT-XDXR-UPDATE-SOURCE-CHECK) - #2222
Conversation
…s by VertexCount An update whose source is not a structure of this layout (one the title never built, which D3D12 leaves undefined) made the refit follow its parent table anywhere. MODE_CHECK now compares the copied header with the layout, and the update records both tails: the refit runs when the check passes, a full build when it fails. The refit walk follows only pointers to the layout's nodes. A vertex index at or past the geometry's VertexCount is no longer read: its triangle is inactive. XdxrTriangles carries vertex_count from the desc. vk_xdxr_build_test: blas_vertex_count and eight update-source cases (zero, random, another element count, garbage tree; large and small-sort). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gt9hwRYcpySx4P4ncQ3wD5
|
Independent validation on Linux/Wine (NVIDIA RTX 3070 Ti, Vulkan 1.4, subgroup 32, Windows cross-build cherry-picked on top of
AI-assisted validation. |
|
I reviewed The checks read right to me:
Two questions:
Neither changes the fault fix itself. AI-assisted (Claude Code). |
|
Thank you for the careful read, in particular the check that nothing in the fallback build touches the verdict word.
(Reply written with Claude Code.) |
|
Follow-up on the So in the part of the game reached so far, the title never declares fewer vertices than its index buffers use, and the bound drops no geometry from the BLASes; it only guards the out-of-range case. If a later scene turns out to under-declare, the clamp to the vertex resource's size you suggested is still the way to keep that geometry, but nothing here calls for it yet. No device loss in that run either. (Reply written with Claude Code.) |
kawaii-shakal
left a comment
There was a problem hiding this comment.
Reviewed by Claude Code (AI-assisted) on my behalf. Approving.
MODE_CHECKthen a flaggedMODE_INIT/update_finishis a sound way to survive an update whose source is not a
structure of this layout. Both finishes are recorded and the GPU picks one, so the CPU never reads back. The extra
dispatches early-exit.vertex_countdefaults to 0xffffffff, so callers without a desc keep today's behaviour.vulkan_backend.hpasses
the desc's value.- Push block 104 -> 108 bytes, matching the shader's new
vertex_countword. - Checked at 2222's head on Linux with Mesa lavapipe (llvmpipe, LLVM 19.1.7):
xdxr_build_output,xdxr_descs,
xdxr_builder_validation,xdxr_build,xdxr_build_check(67 s) andvk_xdxr_postbuild_readbackpass. I did not
check that the new cases invk_xdxr_build_testfail on main.
Generated by Claude Code
kawaii-shakal
left a comment
There was a problem hiding this comment.
Reviewed by Claude Code (AI-assisted) on my behalf. Approving.
MODE_CHECKthen a flaggedMODE_INIT/update_finishis a sound way to survive an update whose source is not a
structure of this layout. Both finishes are recorded and the GPU picks one, so the CPU never reads back. The extra
dispatches early-exit.vertex_countdefaults to 0xffffffff, so callers without a desc keep today's behaviour.vulkan_backend.hpasses
the desc's value.- Push block 104 -> 108 bytes, matching the shader's new
vertex_countword. - Checked at 2222's head on Linux with Mesa lavapipe (llvmpipe, LLVM 19.1.7):
xdxr_build_output,xdxr_descs,
xdxr_builder_validation,xdxr_build,xdxr_build_check(67 s) andvk_xdxr_postbuild_readbackpass. I did not
check that the new cases invk_xdxr_build_testfail on main.
Generated by Claude Code
|
Merging.
Thanks @DadaCap, @djrolfes for the A/B run and @qhukz13 for the review. AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2) |
Conflicts with ProjectLeonida#2222 (RT-XDXR-UPDATE-SOURCE-CHECK), resolved: - Shader modes: this branch already uses 19-25 (serialize, deserialize and the pair modes), so main's MODE_CHECK = 19 becomes 26, in xdxr_build.comp and xdxr_build.h. Both sides' code is kept. - Scratch: main's SCRATCH_REFIT was byte 28, which here is SCRATCH_LEAF_COUNT. An update that falls back to a full paired build would have overwritten the verdict with the leaf count and run both tails. SCRATCH_REFIT moves to byte 32, which nothing else uses. - layout_node() (from ProjectLeonida#2222) bounded parent pointers by pc.nodes_off. A paired build places its nodes at nodes_off(), right after the kept leaves, so every parent was rejected and no box was propagated: all blas_paired_* cases of xdxr_build_check missed every ray. It now uses nodes_off(). Updates never pair (the layer pairs only builds without ALLOW_UPDATE), so refit_source_ok keeps pc.nodes_off. - xdxr_build.inc regenerated with glslc (shaderc 2023.8, --target-env=vulkan1.2 -O -mfmt=c); spirv-val passes. Tested: full ctest, 113 of 113, on Mesa lavapipe (llvmpipe, LLVM 19.1.7), xdxr_build_check included. Changes made by Claude Code (AI-assisted). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JPqXc6svM4pbBagTsVEYA3
Conflicts with ProjectLeonida#2222 (RT-XDXR-UPDATE-SOURCE-CHECK), resolved: - Shader modes: this branch uses 19 and 20 (serialize, deserialize), so main's MODE_CHECK = 19 becomes 26, in xdxr_build.comp and xdxr_build.h. 21-25 stay free for the pair modes of ProjectLeonida#690, which builds on this branch, so the two branches number the modes alike. Both sides' code is kept. - SCRATCH_REFIT moves from byte 28 to byte 32, as in ProjectLeonida#690, where byte 28 is the kept leaf count. Nothing here uses either byte. - xdxr_build.inc regenerated with glslc (shaderc 2023.8, --target-env=vulkan1.2 -O -mfmt=c); spirv-val passes. Tested: full ctest, 113 of 113, on Mesa lavapipe (llvmpipe, LLVM 19.1.7). Changes made by Claude Code (AI-assisted). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JPqXc6svM4pbBagTsVEYA3
Claimed in the coordination issue as: #1608 (comment)
Depends on: none. It merges cleanly with current
main, #2002, #1874 and #1418. It conflicts with #690 inruntime/src/xdxr_build.comp,runtime/src/xdxr_build.hand the generatedruntime/src/xdxr_build.inc(both change the builder's modes and push constants); whichever lands second redoes those hunks and regenerates the.inc.What and why
Two ways the XDXR builder (
xdxr_build.comp) read memory it had no reason to touch:VertexCount. The builder read every vertex its index named. An index at or past the geometry'sVertexCount(garbage in the index buffer, orVertexCount0) read past the vertex buffer, possibly by gigabytes.The fix
MODE_CHECK(new, one invocation): after the source is copied, it compares the header wordsbuild_headerwrites that the layout fixes (flags and version, element count, node, element and parent offsets, the root pointer) and the size against the layout, and writes the verdict to a scratch word.FLAG_IF_REFIT, a full build's steps (MODE_INITandfinish) carryFLAG_IF_BUILD, and each dispatch returns at once unless the verdict picks it (XdxrBuilder::refit_begin/update_finish). A source that fails the check is rebuilt from the update's geometry and nothing else of it is read.layout_node,parent_slot), so a source that passes the check but holds a garbage tree still ends and stays inside the structure.vertex()returns NaN for an index at or pastVertexCount, which makes its triangle inactive as a NaN vertex already did.XdxrTriangles::vertex_countcarries the desc'sVertexCount(vulkan_backend.h); the default bounds nothing, for callers with no desc. The push block grows by one word (static_assert108 bytes).docs/bvh.mdstates the bound; the comment ind3d12_vulkan_device.cppthat said such indices read past the buffer now says they are not read.xdxr_build.incregenerated withglslc --target-env=vulkan1.2 -O -mfmt=c(Vulkan SDK 1.4.363.1);main's.compreproducesmain's.incbyte for byte with the same command.Tested
vk_xdxr_build_test(hand-made geometry, no game data):blas_vertex_count: an unindexed geometry whose last triangle lies pastVertexCountover finite vertices, an index far past the buffer, andVertexCount0; the reference treats those triangles as inactive andxdxr_bvh.py check-buildvalidates the result.gta6rtand the XDXR/BVH test targets (Windows 11, MSVC, Ninja, RelWithDebInfo) and ranctest -R "xdxr|bvh": 11 passed (xdxr_build_output,xdxr_descs,xdxr_builder_validation,xdxr_build,xdxr_build_check,d3d12_xdxr_rt,d3d12_xdxr_rt_check,xbox_bvh_builder,xbox_bvh_builder_console,xbox_bvh_builder_check,vk_xdxr_postbuild_readback), 1 skipped (bvh_builder, which skips in this configuration). Not run: the full ctest suite and the translator suite (no translator change).python -I scripts/check_no_game_data.pyon the changed files: clean.python -I tests/test_text_write_line_endings.py: OK.GPUs tested: NVIDIA GeForce RTX 5080, driver 621.24, Windows 11 (the ctest entries and the game runs).
AI-assisted: yes (Claude Code, Opus 5.5)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator rule)🤖 Generated with Claude Code
https://claude.ai/code/session_01Gt9hwRYcpySx4P4ncQ3wD5