mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:45:54 +01:00
[PR #2222] [MERGED] xdxr: check the update source and bound the builder's reads (RT-XDXR-UPDATE-SOURCE-CHECK) #2226
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#2226
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/2222
Author: @DadaCap
Created: 11/26/2026
Status: ✅ Merged
Merged: 11/26/2026
Merged by: @aslan2142
Base:
main← Head:xdxr-update-source-check📝 Commits (1)
7727506xdxr: check an update's source before refitting it; bound vertex reads by VertexCount📊 Changes
7 files changed (+8391 additions, -7876 deletions)
View changed files
📝
docs/bvh.md(+4 -1)📝
runtime/shims/d3d12_vulkan_device.cpp(+2 -2)📝
runtime/src/vulkan_backend.h(+1 -0)📝
runtime/src/xdxr_build.comp(+49 -2)📝
runtime/src/xdxr_build.h(+45 -14)📝
runtime/src/xdxr_build.inc(+8241 -7853)📝
runtime/test/vk_xdxr_build_test.cpp(+49 -4)📄 Description
Claimed in the coordination issue as: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7184751281
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
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.