xbox_bvh_builder: scan every postbuild description for 0x10; rehydrate scratch regions cannot wrap (RT-XDXR-POSTBUILD-SCAN-AND-SCRATCH) #2544
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2544
Loading…
Reference in a new issue
No description provided.
Delete branch "rt-xdxr-postbuild-scan-scratch"
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 successfully merged and closed
Claimed in the coordination issue as: RT-XDXR-POSTBUILD-SCAN-AND-SCRATCH (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7231769520)
What and why
Item 3 of @kevincommits' Finding 19 in #1608 (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7231649637). Thanks for the report.
runtime/shims/xbox_bvh_builder.cppserves XboxBvhBuilder.dll's exports with the layer's own builder:builder_build_batched2x, postbuild descriptions past 16. The DLL refuses an element that asks for the offline-statistics postbuild type (0x10), so the shim skips such an element. But the shim kept 16 other descriptions and thenbreak. A 0x10 description at index 17 or later was never seen, and the element was built instead of skipped. Now the descriptions past 16 are still dropped (logged once) but scanned, so 0x10 at any index skips the element.builder_rehydrate_batched2x, scratch regions. Each element with no scratch gets a region of one shared scratch buffer. It was sized as(size + 255) / 256 * 256and summed without a bound. A size within 255 of 2^64 wrapped to 0, and a large total wrapped to a small one. The buffer was then too small and the regions overlapped. Now an element whose aligned region would not fit in the 64-bit total gets no region: it is skipped as one without scratch, with a log line, and the rest of the batch is unaffected.Both rules move unchanged otherwise into a small header,
shims/xbox_bvh_builder_rules.h(filter_postbuild,add_scratch_region), so they can be tested without a device.Overlap: no open PR touches
xbox_bvh_builder.cpp.Tested
Windows 11, MSVC (VS 18), RelWithDebInfo, on
main431ceba4f.xbox_bvh_builder_rules:breakand arithmetic in the header, 5 checks fail (0x10 at 17 and 19, and the three wrap cases). All pass with the change.ctest -R "^xbox_bvh_builder": 4/4 pass, including the GPU testxbox_bvh_builder, its console variant and thexdxr_bvh.py check-buildray check.scripts/check_no_game_data.py: clean.Not tested: a game boot. No title is known to send more than 16 postbuild descriptions or a scratch size near 2^64; these are guards.
GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code
#2544 | head e7280be1666f8ed3706a533be527be5bb8d442c4 (merged cleanly with main 02f71ccfe78160997a02950607be583af87e1180) |
ctest --test-dir runtime/build -C RelWithDebInfo -R "^(xbox_bvh_builder_rules|xbox_bvh_builder)$" --output-on-failure(LEONIDA_VK_VALIDATION=1) | red on main:xbox_bvh_builder_rules_test.cppfails to compile (C1083: missingxbox_bvh_builder_rules.h; onmain,xbox_bvh_builder.cppstopped scanning postbuild descriptions atn_kept == 16and could wrap 64-bitscratch_bytesalignment/addition) | green on PR+main:2/2CTests pass (xbox_bvh_builder_rules20/20CPU checks in0.05s, andxbox_bvh_builder26/26GPU/shim checks in1.59son RTX 3090 with0Khronos validation errors);test_ci_registration.py18/18OK,check_no_game_data.py0violations | Windows 11, RTX 3090 (610.88), Vulkan SDK 1.4.363.1 | AI-assisted: yesReviewed the diff and tested merged onto
main(493867366) with Ninja Release (MSVC).Moving the BVH builder validation/sizing rules into
xbox_bvh_builder_rules.hwith dedicated CPU rule tests keepsxbox_bvh_builder.cppcleaner while preserving full GPU BVH builder behaviour.Tests run
ctest --output-on-failure -R "^(xbox_bvh_builder_rules|xbox_bvh_builder|xbox_bvh_builder_check)$": 3/3 passed (xbox_bvh_builder_rules0.02 s,xbox_bvh_builder1.43 s,xbox_bvh_builder_check12.81 s).GPUs tested: NVIDIA GeForce RTX 5070 12 GB (Windows 11, driver 610.88, Vulkan 1.4.341; VK_LAYER_KHRONOS_validation not installed locally).
AI-assisted (Antigravity, Gemini).
RUN (Windows 11, red/green)
Tested heads: PR head
e7280be1666f8ed3706a533be527be5bb8d442c4(one commit on431ceba4f);mainat1bc055e6c2dedaa0de23ec79d8c4007c1dff1fb3.git merge-tree --write-tree main pr-2544merges cleanly.Machine: Windows 11 Pro 10.0.26300, MSVC 14.44 (VS 2022 Build Tools), RelWithDebInfo, Ninja, 8 jobs. GPU NVIDIA GeForce RTX 3090 24 GB, driver 621.40.
Commands (only the two test targets and their dependencies were built, not the whole runtime):
GREEN (PR head): 4/4 passed:
xbox_bvh_builder_rules(new, CPU),xbox_bvh_builder(GPU),xbox_bvh_builder_console,xbox_bvh_builder_check(thexdxr_bvh.py check-buildray check). The new test reports "0 failure(s)".RED (behavioural): the PR's new header is the whole change under test, so reverting the non-test files would only remove the header and the target. Instead the header
runtime/shims/xbox_bvh_builder_rules.hwas kept and the two rules put back to the old logic (breakafter 16 kept descriptions; no overflow checks inadd_scratch_region). Rebuiltxbox_bvh_builder_rules_testand ranctest -R "^xbox_bvh_builder_rules$": FAILED with 5 failures, as the PR says:The edit was reverted afterwards. The rules test covers the header only; I checked that
xbox_bvh_builder.cppcalls the header's functions, so the tested code is the code the shim runs.Link check: merged into main 1bc055e6c, gta6rt.exe builds and links (RelWithDebInfo, MSVC 19.44); no new imports vs main.
Windows 11 + MSVC
19.44+ RTX 3090 Verification — PASS (e7280be166)Verified
e7280be166(RT-XDXR-POSTBUILD-SCAN-AND-SCRATCH) merged ontoorigin/main(e66c65b950/16f5053047,0conflicts, plus a 5-way combined merge alongside#1146,#988,#955, and#1738) on native Windows 11 (10.0.26200.9974) with MSVC19.44.35228, NVIDIA GeForce RTX 3090, andVK_LAYER_KHRONOS_validation1.4.363.1.Checks Run
xbox_bvh_builder_rules_test.exe,/W4 /WX):origin/main):runtime/shims/xbox_bvh_builder_rules.habsent (xbox_bvh_builder.cpppreviously stopped scanning postbuild descriptors atn_kept == 16, missing0x10offline-statistics descriptors at index>= 16, and computed(size + kAlign - 1) / kAlign * kAlignwithout 64-bit overflow guards).xbox_bvh_builder_rules_test.exe): compiled with0warnings under/W4 /WXand passed (0 failure(s),rc=0), covering0x10at indices{0, 5, 16, 17, 19}of20, truncation past16without0x10,nullptrinput, andUINT64_MAXalignment/total overflow boundaries.xbox_bvh_builder_test& BVH ray-check on NVIDIA GeForce RTX 3090:xbox_bvh_builder_test.exe --console(LEONIDA_BVH_BUILDER=console):rc=0.xbox_bvh_builder_test.exe <cases_dir>on NVIDIA GeForce RTX 3090 (LEONIDA_VK_VALIDATION=1):rc=0,0validation errors.python -I tools/xdxr_bvh.py check-build <cases_dir> --rays 1000:rc=0.tests/test_ctest_registration.pyandtests/test_ci_registration.pypassed (rc=0).AI-assisted.
Merged after enlight3d (Thib)'s red/green run (RUN, RTX 3090, driver 621.40, Windows 11: green with this PR, red without it, and
gta6rt.exestill links) and a re-check here: no conflict withmain5c8a9de7d, same head as run,no-game-datagreen, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known onmainor Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ).AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.