[PR #485] [MERGED] XDXR-BUILDER-PREVALIDATE: pre-validate XdxrBuilder inputs and avoid 32-bit workgroup overflow #535

Closed
opened 2026-11-26 20:18:12 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/485
Author: @xroneyaa
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @QemmHD

Base: main ← Head: fix/xdxr-builder-validation


📝 Commits (1)

  • d2f6033 xdxr_build: pre-validate build inputs and avoid 32-bit workgroup overflow

📊 Changes

3 files changed (+198 additions, -4 deletions)

View changed files

📝 runtime/CMakeLists.txt (+5 -0)
📝 runtime/src/xdxr_build.h (+10 -4)
➕ runtime/test/xdxr_builder_validation_test.cpp (+183 -0)

📄 Description

Claimed in the coordination issue as: XDXR-BUILDER-PREVALIDATE

What and why

XdxrBuilder::record_blas() previously recorded begin()/refit_begin() and all mode_triangles dispatches into VkCommandBuffer cb before checking first != layout.elements, leaving partial dispatches in cb on mismatch, and accumulated first in std::uint32_t (which could overflow back to layout.elements). Both record_blas() and record_tlas() also did not check for uncomputed layouts (layout.size == 0) or null dst/scratch addresses before recording, and XdxrBuilder::dispatch() computed (threads + 63) / 64 in 32 bits.

This pre-validates !layout.size || !dst || !scratch, sums geometry triangle counts in std::uint64_t up front in record_blas(), checks (layout.elements && !instances) up front in record_tlas(), and widens (std::uint64_t(threads) + 63u) / 64u in dispatch(). Adds CPU-only unit test runtime/test/xdxr_builder_validation_test.cpp registered as xdxr_builder_validation in runtime/CMakeLists.txt.

Tested

  • Rebuilt xdxr_builder_validation_test, vk_xdxr_build_test, and d3d12_xdxr_rt_test with 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 (with VK_LOADER_LAYERS_DISABLE=~implicit~) -> 4/4 Passed (xdxr_builder_validation 0.01 s, xdxr_build 0.30 s, xdxr_build_check 72.71 s, d3d12_xdxr_rt 0.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 0

GPUs tested: NVIDIA GeForce RTX 3060 Ti, driver 610.88, Windows 11 (xdxr_build, xdxr_build_check, d3d12_xdxr_rt); xdxr_builder_validation runs CPU-only with a mock Vulkan dispatch table

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed (n/a — no translator rule added).

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/485 **Author:** [@xroneyaa](https://github.com/xroneyaa) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@QemmHD](https://github.com/QemmHD) **Base:** `main` ← **Head:** `fix/xdxr-builder-validation` --- ### 📝 Commits (1) - [`d2f6033`](https://github.com/ubiquitarianism/leonida/commit/d2f6033ee7dd1304f939590eb6af9496638712fa) xdxr_build: pre-validate build inputs and avoid 32-bit workgroup overflow ### 📊 Changes **3 files changed** (+198 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+5 -0) 📝 `runtime/src/xdxr_build.h` (+10 -4) ➕ `runtime/test/xdxr_builder_validation_test.cpp` (+183 -0) </details> ### 📄 Description Claimed in the coordination issue as: XDXR-BUILDER-PREVALIDATE ### What and why `XdxrBuilder::record_blas()` previously recorded `begin()`/`refit_begin()` and all `mode_triangles` dispatches into `VkCommandBuffer cb` before checking `first != layout.elements`, leaving partial dispatches in `cb` on mismatch, and accumulated `first` in `std::uint32_t` (which could overflow back to `layout.elements`). Both `record_blas()` and `record_tlas()` also did not check for uncomputed layouts (`layout.size == 0`) or null `dst`/`scratch` addresses before recording, and `XdxrBuilder::dispatch()` computed `(threads + 63) / 64` in 32 bits. This pre-validates `!layout.size || !dst || !scratch`, sums geometry triangle counts in `std::uint64_t` up front in `record_blas()`, checks `(layout.elements && !instances)` up front in `record_tlas()`, and widens `(std::uint64_t(threads) + 63u) / 64u` in `dispatch()`. Adds CPU-only unit test `runtime/test/xdxr_builder_validation_test.cpp` registered as `xdxr_builder_validation` in `runtime/CMakeLists.txt`. ### Tested - Rebuilt `xdxr_builder_validation_test`, `vk_xdxr_build_test`, and `d3d12_xdxr_rt_test` with 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` (with `VK_LOADER_LAYERS_DISABLE=~implicit~`) -> 4/4 Passed (`xdxr_builder_validation` 0.01 s, `xdxr_build` 0.30 s, `xdxr_build_check` 72.71 s, `d3d12_xdxr_rt` 0.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 0 GPUs tested: NVIDIA GeForce RTX 3060 Ti, driver 610.88, Windows 11 (`xdxr_build`, `xdxr_build_check`, `d3d12_xdxr_rt`); `xdxr_builder_validation` runs CPU-only with a mock Vulkan dispatch table AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed (n/a — no translator rule added). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:18:12 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#535
No description provided.