xdxr: check the update source and bound the builder's reads (RT-XDXR-UPDATE-SOURCE-CHECK) #2222
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!2222
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2222"
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?
@DadaCap on GitHub · 2026-11-26 06:51 UTC · original
DadaCap:xdxr-update-source-check→main· +8391 −7876 · 7 files · 1 commits · merged 2026-11-26 16:41 UTCClaimed in the coordination issue as: #1608
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
@djrolfes on GitHub · 2026-11-26 08:43 UTC · original
Independent validation on Linux/Wine (NVIDIA RTX 3070 Ti, Vulkan 1.4, subgroup 32, Windows cross-build cherry-picked on top of
a73a57e13+ local runtime test stack):xdxr_build_output,xdxr_descs,xdxr_build,d3d12_xdxr_rt): 4/4 passed.#2222: repeatableVK_ERROR_DEVICE_LOSTwithREAD_INVALIDpast the arena + NVIDIAXid 31/Xid 109on an uncheckpointed AS build/update path.#2222(77275065b): 0 fault addresses, 0READ_INVALID, 0Xid 31, 0Xid 109— the XDXR memory fault was completely eliminated. (The run later hit a separate zero-fault-address direct-queue timeout, unrelated to XDXR.)AI-assisted validation.
@qhukz13 on GitHub · 2026-11-26 12:13 UTC · original
I reviewed
77275065by reading the code against maina73a57e13. There is noglslcon this machine, so I did not regenerate the.inc, and my Windows PC is down today, so I have no GPU run. djrolfes's retail A/B above is the strong evidence that this is the fault seen at the world start.The checks read right to me:
SCRATCH_REFIT(byte 28) is written by one invocation inMODE_CHECK, and a barrier follows. Every later dispatch then reads the same word, so a workgroup that uses shared memory leaves as a whole. Nothing in the fallback build touches that word:MODE_INITwrites bytes 0-20, the kept scan writes 24, and the sort arrays start at 64. So the verdict cannot flip halfway through the fallback.MODE_INITasbegin(). The geometry dispatches carry neither flag and run in both cases. They write the same element records either way, because an update pushes no different triangle or instance state.layout_nodebounds the walk. It checks the node type, the 64-byte boundary andrel / node_size() < pc.arg0.arg0isl.nodesforMODE_PROPAGATE(base()). Theptr_unit < 2^26guard keepsunit * 64from wrapping.parent_slotkeeps the parent-table read inside the body.Two questions:
What does an update cost now?
update_finishrecords both tails every time. For a BLAS above 1,024 elements that is about 32 dispatches, each with a barrier, of which only the copy, check, clear, propagate and header did work before:A dispatch the verdict skips still launches all its workgroups,
64 * tiles()for the radix steps. Each workgroup returns after one load, and the barriers serialize the queue. Skinned and animated BLASes are updated every frame, so on a small GPU this can add up. Did the retail run show any frame-time change? If it does matter,MODE_CHECKcould write the group counts forvkCmdDispatchIndirect, so the skipped tail launches 0 groups.VertexCountas a hard bound. Before, an index pastVertexCountwas read, which the old comment called "as on the console". Now a descriptor withVertexCount0, or one smaller than what the index buffer actually uses, silently loses those triangles from the BLAS. D3D12 calls that input invalid, but a console title only has to satisfy the console's builder. If the game's descriptors under-declare it, the raytraced shadows and reflections lose geometry with no message. Two things would make that visible:If they turn out common, a clamp to the vertex buffer's size (from the resource the VA lands in) would keep both the fault fix and the geometry.
Neither changes the fault fix itself.
AI-assisted (Claude Code).
@DadaCap on GitHub · 2026-11-26 12:39 UTC · original
Thank you for the careful read, in particular the check that nothing in the fallback build touches the verdict word.
MODE_CHECKwriting the group counts forvkCmdDispatchIndirectso the unused tail launches 0 groups. I'd rather keep that as a follow-up than grow this pull request, unless a reviewer prefers it here.VertexCountas a hard bound. Fair: a title whose descriptors under-declare it would lose triangles from the BLAS with no message, and the rays would miss that geometry. I don't have the count yet. I'll measure it with a local diagnostic (a counter of triangles the bound made inactive, read back once per run) in a retail run and post the number here. If it turns out to be more than a stray index, clamping to the size of the resource the vertex VA lands in, as you suggest, keeps both the fault fix and the geometry, and I'll switch to that.(Reply written with Claude Code.)
@DadaCap on GitHub · 2026-11-26 13:05 UTC · original
Follow-up on the
VertexCountquestion: I counted it. A local diagnostic (not part of this pull request) has the build kernel count every triangle the bound makes inactive, with a counter read back without a stall. Retail run, RTX 5080, about 10 min with the world rendered (25 world frames), this change applied: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 on GitHub · 2026-11-26 16:34 UTC · original · reviewed
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 astructure 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.hpassesthe desc's value.
vertex_countword.xdxr_build_output,xdxr_descs,xdxr_builder_validation,xdxr_build,xdxr_build_check(67 s) andvk_xdxr_postbuild_readbackpass. I did notcheck that the new cases in
vk_xdxr_build_testfail on main.Generated by Claude Code
@kawaii-shakal on GitHub · 2026-11-26 16:35 UTC · original · reviewed
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 astructure 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.hpassesthe desc's value.
vertex_countword.xdxr_build_output,xdxr_descs,xdxr_builder_validation,xdxr_build,xdxr_build_check(67 s) andvk_xdxr_postbuild_readbackpass. I did notcheck that the new cases in
vk_xdxr_build_testfail on main.Generated by Claude Code
@aslan2142 on GitHub · 2026-11-26 16:41 UTC · original
Merging.
VertexCountbounds the vertex reads.main56bdd7e88+ this PR (77275065b), Mesa 26.3.1:check_no_game_data.pyis clean on the changed files.xdxr_build.incregenerates byte-identical with glslc.xdxr_buildandxdxr_build_checkpass on llvmpipe, the integrated RDNA2 GPU and the RX 7900 XTX (RADV), with no kernel reset.main(llvmpipe only).main.LEONIDA_RT_AS=off: 666 s with no fault, up to the title's own breakpoint. No regression, but this PR's code does not run with that setting.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)