XDXR-BUILDER-PREVALIDATE: pre-validate XdxrBuilder inputs and avoid 32-bit workgroup overflow #485
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!485
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/485/head"
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?
@xroneyaa on GitHub · 2026-11-24 06:10 UTC · original
xroneyaa:fix/xdxr-builder-validation→main· +198 −4 · 3 files · 1 commits · merged 2026-11-24 16:25 UTCClaimed in the coordination issue as: XDXR-BUILDER-PREVALIDATE
What and why
XdxrBuilder::record_blas()previously recordedbegin()/refit_begin()and allmode_trianglesdispatches intoVkCommandBuffer cbbefore checkingfirst != layout.elements, leaving partial dispatches incbon mismatch, and accumulatedfirstinstd::uint32_t(which could overflow back tolayout.elements). Bothrecord_blas()andrecord_tlas()also did not check for uncomputed layouts (layout.size == 0) or nulldst/scratchaddresses before recording, andXdxrBuilder::dispatch()computed(threads + 63) / 64in 32 bits.This pre-validates
!layout.size || !dst || !scratch, sums geometry triangle counts instd::uint64_tup front inrecord_blas(), checks(layout.elements && !instances)up front inrecord_tlas(), and widens(std::uint64_t(threads) + 63u) / 64uindispatch(). Adds CPU-only unit testruntime/test/xdxr_builder_validation_test.cppregistered asxdxr_builder_validationinruntime/CMakeLists.txt.Tested
xdxr_builder_validation_test,vk_xdxr_build_test, andd3d12_xdxr_rt_testwith MSVC 19.50 / Ninja (0 warnings in touched files)ctest --test-dir runtime/build -R "^(xdxr_builder_validation|xdxr_build|xdxr_build_check|d3d12_xdxr_rt)$" --output-on-failure(withVK_LOADER_LAYERS_DISABLE=~implicit~) -> 4/4 Passed (xdxr_builder_validation0.01 s,xdxr_build0.30 s,xdxr_build_check72.71 s,d3d12_xdxr_rt0.71 s)python -I scripts/check_no_game_data.py runtime/src/xdxr_build.h runtime/test/xdxr_builder_validation_test.cpp runtime/CMakeLists.txt-> exit 0GPUs tested: NVIDIA GeForce RTX 3060 Ti, driver 610.88, Windows 11 (
xdxr_build,xdxr_build_check,d3d12_xdxr_rt);xdxr_builder_validationruns CPU-only with a mock Vulkan dispatch tableAI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed (n/a — no translator rule added).@Oliwettoo on GitHub · 2026-11-24 10:39 UTC · original
Looks good. The important part is that
record_blasnow checks the triangle total before anything is recorded into the command buffer: onmaina mismatch returnedfalseonly after the build dispatches were already in it. Builtxdxr_builder_validation_testwith g++ and Vulkan-Headers on Linux: it passes with the PR and fails againstmain'sxdxr_build.h, so it guards the change. Nit: the newadd_testsits in its ownif(BUILD_TESTING), unlike the other tests in thatVulkan::Headersblock; either is fine, but matching the neighbours keeps it uniform. Ship. AI-assisted review.@kawaii-shakal on GitHub · 2026-11-24 11:39 UTC · original
Independent run on Windows: passes, with and without validation.
Head
d2f6033eebuilt as it is (RelWithDebInfo, MSVC 19.50.35721.0),ctest -R xdxr:LEONIDA_VK_VALIDATION1(Khronos validation with synchronization validation, Vulkan SDK 1.4.363.0)xdxr_builder_validation; all 30xdxr_build_checkscenes (BOX16, paired TRI1, refit, clone, compacted, TLAS) report 0 validation errors and 0 rays differingRead the diff as well: checking the triangle inputs before anything is dispatched, rather than inside the recorded work, and computing the workgroup count in 64 bits so
(threads + 63) / 64cannot wrap, both look right to me.GPU: NVIDIA GeForce RTX 5070 Ti, driver 617.42, Vulkan 1.4.351, Windows 11 Pro 26300.
AI-assisted.
@QemmHD on GitHub · 2026-11-24 16:25 UTC · original
Merging.
Why merged: The xdxr builder checks the BLAS triangle total and null addresses before anything is recorded, and the dispatch-count overflow is fixed. The CMake change only adds the new test target.
Why it's good: xdxr_builder_validation, xdxr_build, xdxr_build_output and xdxr_descs all pass both plain and under validation.
Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Alone on main, its tests passed both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #388, #418, #421, #434, #470, #484, #485, #486 and #488 merged onto main
1504c1af6(a225e593e). There the repo-consistency set gives 566 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 306/308. The 2 failures are the same pre-existing ones as main (d3d12_execute_indirect_validation, d3d12_depth_resolve), with the same skip set. git merge-tree against current main98a977b4b: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.AI-assisted (Claude Code, Claude Opus 5.5).