[PR #2002] runtime: guard XdxrBuilder empty dispatches, layout failure reset, and pipeline cleanup (RT-XDXR-BUILD-LAYOUT-EMPTY-AND-DISPATCH-GUARDS) #2009

Open
opened 2026-11-26 21:19:43 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2002
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/rt-xdxr-build-layout-empty-and-dispatch-guards


📝 Commits (1)

  • 6c462cc runtime: guard XdxrBuilder empty dispatches, layout failure reset, and pipeline cleanup

📊 Changes

2 files changed (+169 additions, -34 deletions)

View changed files

📝 runtime/src/xdxr_build.h (+55 -26)
📝 runtime/test/xdxr_builder_validation_test.cpp (+114 -8)

📄 Description

Claim: RT-XDXR-BUILD-LAYOUT-EMPTY-AND-DISPATCH-GUARDS (claim comment #7170142282 on #1608).

Problem

In runtime/src/xdxr_build.h:

  1. Half-populated layout on overflow: XdxrLayout::compute() populated tlas, box16, node_size, elements, element_size, and nodes before checking the 32-bit offset / 29-bit unit limit and returning false, leaving a failed layout partially initialized.
  2. 32-bit wrap in tiles() and kept_tiles(): (sort_size + radix_tile - 1) / radix_tile and (inner() + radix_tile - 1) / radix_tile wrap uint32_t near UINT32_MAX (returning 0 instead of 2^24).
  3. Zero-workgroup dispatch + wasted barrier on empty BLAS/TLAS: finish() unconditionally dispatched mode_morton with count = l.sort_size, emitting vkCmdDispatch(cb, 0, 1, 1) and a compute-to-compute vkCmdPipelineBarrier whenever sort_size == 0.
  4. Overflow-prone 64 * tiles round-trip: finish() multiplied tile group counts by 64 (64 * l.tiles(), 64 * l.kept_tiles()) before dispatch() divided back by 64, which can overflow uint32_t for large tile counts.
  5. Null VkCommandBuffer and partial make_pipeline() cleanup: record_blas / record_tlas / record_copy / record_postbuild did not guard !cb, and make_pipeline() left layout_ alive on vkCreateShaderModule or vkCreateComputePipelines failure until ~XdxrBuilder().

Fix

  • Reset *this = XdxrLayout{}; before returning false on overflow in XdxrLayout::compute().
  • Make tiles() and kept_tiles() overflow-free (n ? 1u + (n - 1u) / radix_tile : 0u).
  • Add dispatch_groups() (skipping groups == 0), guard !threads in dispatch(), skip mode_morton when l.sort_size == 0, and dispatch exact tile/workgroup counts directly in finish().
  • Guard !cb in record_blas, record_tlas, record_copy, and record_postbuild.
  • Build into local VkPipelineLayout / VkPipeline handles in make_pipeline(), destroying layout immediately on shader-module or pipeline failure so a failed XdxrBuilder keeps layout_ and pipeline_ null.
  • Expand runtime/test/xdxr_builder_validation_test.cpp (0 CMakeLists.txt edits) to cover all 5 fixes.

Verification

  • AI-assisted: yes (Antigravity agent by Google DeepMind).
  • GPUs tested: none (host is macOS arm64; no retail files).
  • Ran runtime/test/xdxr_builder_validation_test.cpp cleanly under:
    • clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror -Wno-missing-field-initializers
    • clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror -Wno-missing-field-initializers
    • clang++ -std=c++20 -O2 -Wall -Wextra -Werror -Wno-missing-field-initializers
  • Ran python3 -I scripts/check_no_game_data.py runtime/src/xdxr_build.h runtime/test/xdxr_builder_validation_test.cpp and python3 -I tests/test_text_write_line_endings.py: all passed.

🔄 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/2002 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/rt-xdxr-build-layout-empty-and-dispatch-guards` --- ### 📝 Commits (1) - [`6c462cc`](https://github.com/ubiquitarianism/leonida/commit/6c462cc77aee7224aca9df62e3fa6062d4aee46e) runtime: guard XdxrBuilder empty dispatches, layout failure reset, and pipeline cleanup ### 📊 Changes **2 files changed** (+169 additions, -34 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/xdxr_build.h` (+55 -26) 📝 `runtime/test/xdxr_builder_validation_test.cpp` (+114 -8) </details> ### 📄 Description Claim: `RT-XDXR-BUILD-LAYOUT-EMPTY-AND-DISPATCH-GUARDS` (claim comment `#7170142282` on #1608). ### Problem In `runtime/src/xdxr_build.h`: 1. **Half-populated layout on overflow**: `XdxrLayout::compute()` populated `tlas`, `box16`, `node_size`, `elements`, `element_size`, and `nodes` before checking the 32-bit offset / 29-bit unit limit and returning `false`, leaving a failed layout partially initialized. 2. **32-bit wrap in `tiles()` and `kept_tiles()`**: `(sort_size + radix_tile - 1) / radix_tile` and `(inner() + radix_tile - 1) / radix_tile` wrap `uint32_t` near `UINT32_MAX` (returning `0` instead of `2^24`). 3. **Zero-workgroup dispatch + wasted barrier on empty BLAS/TLAS**: `finish()` unconditionally dispatched `mode_morton` with `count = l.sort_size`, emitting `vkCmdDispatch(cb, 0, 1, 1)` and a compute-to-compute `vkCmdPipelineBarrier` whenever `sort_size == 0`. 4. **Overflow-prone `64 * tiles` round-trip**: `finish()` multiplied tile group counts by 64 (`64 * l.tiles()`, `64 * l.kept_tiles()`) before `dispatch()` divided back by 64, which can overflow `uint32_t` for large tile counts. 5. **Null `VkCommandBuffer` and partial `make_pipeline()` cleanup**: `record_blas` / `record_tlas` / `record_copy` / `record_postbuild` did not guard `!cb`, and `make_pipeline()` left `layout_` alive on `vkCreateShaderModule` or `vkCreateComputePipelines` failure until `~XdxrBuilder()`. ### Fix - Reset `*this = XdxrLayout{};` before returning `false` on overflow in `XdxrLayout::compute()`. - Make `tiles()` and `kept_tiles()` overflow-free (`n ? 1u + (n - 1u) / radix_tile : 0u`). - Add `dispatch_groups()` (skipping `groups == 0`), guard `!threads` in `dispatch()`, skip `mode_morton` when `l.sort_size == 0`, and dispatch exact tile/workgroup counts directly in `finish()`. - Guard `!cb` in `record_blas`, `record_tlas`, `record_copy`, and `record_postbuild`. - Build into local `VkPipelineLayout` / `VkPipeline` handles in `make_pipeline()`, destroying `layout` immediately on shader-module or pipeline failure so a failed `XdxrBuilder` keeps `layout_` and `pipeline_` null. - Expand `runtime/test/xdxr_builder_validation_test.cpp` (0 `CMakeLists.txt` edits) to cover all 5 fixes. ### Verification - **AI-assisted**: yes (Antigravity agent by Google DeepMind). - **GPUs tested**: none (host is macOS arm64; no retail files). - Ran `runtime/test/xdxr_builder_validation_test.cpp` cleanly under: - `clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror -Wno-missing-field-initializers` - `clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror -Wno-missing-field-initializers` - `clang++ -std=c++20 -O2 -Wall -Wextra -Werror -Wno-missing-field-initializers` - Ran `python3 -I scripts/check_no_game_data.py runtime/src/xdxr_build.h runtime/test/xdxr_builder_validation_test.cpp` and `python3 -I tests/test_text_write_line_endings.py`: all passed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#2009
No description provided.