[PR #599] vulkan_replay: do not return early from prepare() on KHR TLAS ARRAY_OF_POINTERS (VK-KHR-TLAS-PREPARE-EARLY-RETURN) #641

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/599
Author: @tahffo68hk-hash
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: fix/vk-khr-tlas-prepare-early-return


📝 Commits (1)

  • f5f73d9 vulkan_replay: do not return early from prepare() on KHR TLAS ARRAY_OF_POINTERS (VK-KHR-TLAS-PREPARE-EARLY-RETURN)

📊 Changes

3 files changed (+174 additions, -1 deletions)

View changed files

📝 runtime/CMakeLists.txt (+15 -0)
📝 runtime/src/vulkan_replay.h (+2 -1)
➕ runtime/test/vk_khr_tlas_prepare_test.cpp (+157 -0)

📄 Description

Summary

In prepare() (runtime/src/vulkan_replay.h), the BuildAccelerationStructure branch for KHR TLAS ARRAY_OF_POINTERS builds ended with an unconditional return:

if (build->is_tlas && build->instance_pointers && build->instance_count) {
    if (!vk.prepare_khr_instances || !vk.host_at || !vk.buffer_at) return ReplayResult::unsupported;
    return vk.prepare_khr_instances(*build, p.khr_instances);
}

When vk.prepare_khr_instances() succeeded (ReplayResult::success), prepare() immediately returned out of the command loop, completely abandoning every subsequent command in the same CommandList:

  • Subsequent copies, draws, dispatches, barriers, and queries were never prepared (silently dropped on fresh PreparedLists, or left with stale Prepared entries from previous executions on reused VulkanQueue::prepared_ storage).
  • Subsequent validation errors (e.g. OOB copies or unclosed queries) were never checked.
  • out.wrote_readback, out.readback_src_stages, plan_statistics_segments(), and plan_occlusion_segments() at the end of prepare() were all skipped.

Fix

  • Only return early when vk.prepare_khr_instances() fails:
    if (const auto r = vk.prepare_khr_instances(*build, p.khr_instances); r != ReplayResult::success) return r;
  • Add a real Vulkan GPU regression test runtime/test/vk_khr_tlas_prepare_test.cpp (registered as vk_khr_tlas_prepare in runtime/CMakeLists.txt) that records a KHR TLAS ARRAY_OF_POINTERS build followed by:
    1. A real GPU CopyBufferRegion into a host-readable buffer, verifying real GPU execution and exact host readback.
    2. An out-of-bounds CopyBufferRegion, verifying prepare() still rejects it with ReplayResult::invalid_copy.

Verification (Real Dual-GPU Hardware)

  • Before fix on NVIDIA GeForce RTX 5060 Ti:
    FAIL runtime/test/vk_khr_tlas_prepare_test.cpp:144: std::memcmp(dst_ptr, expected, sizeof(expected)) == 0 (trailing GPU copy silently dropped; readback buffer remained poisoned 0x5A).
  • After fix on NVIDIA GeForce RTX 5060 Ti:
    vk_khr_tlas_prepare_test: PASS (trailing GPU copy readback + validation verified)
  • After fix on AMD Radeon(TM) Graphics (GFX1036):
    vk_khr_tlas_prepare_test: PASS (trailing GPU copy readback + validation verified)

Coordination

  • Claimed on #14 as VK-KHR-TLAS-PREPARE-EARLY-RETURN (no overlapping open PRs or claims).
  • AI-assisted: yes.
中文翻译

摘要

runtime/src/vulkan_replay.h 中 prepare() 在处理 KHR TLAS ARRAY_OF_POINTERS 构建时直接执行了 return vk.prepare_khr_instances(*build, p.khr_instances);。当 staging 成功返回 ReplayResult::success 时,prepare() 会直接跳出整个命令循环,导致同一命令列表中位于该 TLAS 构建之后的所有命令全部被跳过:

  • 后续拷贝、绘制、计算、屏障与查询均不会被准备(首次执行时静默丢弃,复用 VulkanQueue::prepared_ 时还会残留上一帧的旧数据);
  • 后续命令的合法性校验与读回阶段标记丢失;
  • 函数末尾的 plan_statistics_segments() 与 plan_occlusion_segments() 被完全跳过。

修复

  • 仅在 vk.prepare_khr_instances() 返回非 ReplayResult::success 时提前返回。
  • 新增真实 Vulkan GPU 回归测试 runtime/test/vk_khr_tlas_prepare_test.cpp(CMake 注册名 vk_khr_tlas_prepare),验证 KHR TLAS ARRAY_OF_POINTERS 之后的真实 GPU 拷贝读回与越界拷贝校验。

真实双卡 GPU 验证

  • 修复前(NVIDIA RTX 5060 Ti):后续 GPU 拷贝被静默丢弃,读回缓冲区仍为 0x5A,测试失败。
  • 修复后(NVIDIA RTX 5060 Ti):PASS (trailing GPU copy readback + validation verified)。
  • 修复后(AMD Radeon Graphics / GFX1036):PASS (trailing GPU copy readback + validation verified)。

协同

  • 已在 #14 认领 VK-KHR-TLAS-PREPARE-EARLY-RETURN。
  • AI 辅助:是。

🔄 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/599 **Author:** [@tahffo68hk-hash](https://github.com/tahffo68hk-hash) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/vk-khr-tlas-prepare-early-return` --- ### 📝 Commits (1) - [`f5f73d9`](https://github.com/ubiquitarianism/leonida/commit/f5f73d9a071cfd468ae472be4561f433736ca1ae) vulkan_replay: do not return early from prepare() on KHR TLAS ARRAY_OF_POINTERS (VK-KHR-TLAS-PREPARE-EARLY-RETURN) ### 📊 Changes **3 files changed** (+174 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+15 -0) 📝 `runtime/src/vulkan_replay.h` (+2 -1) ➕ `runtime/test/vk_khr_tlas_prepare_test.cpp` (+157 -0) </details> ### 📄 Description ## Summary In `prepare()` (`runtime/src/vulkan_replay.h`), the `BuildAccelerationStructure` branch for KHR TLAS `ARRAY_OF_POINTERS` builds ended with an unconditional `return`: ```cpp if (build->is_tlas && build->instance_pointers && build->instance_count) { if (!vk.prepare_khr_instances || !vk.host_at || !vk.buffer_at) return ReplayResult::unsupported; return vk.prepare_khr_instances(*build, p.khr_instances); } ``` When `vk.prepare_khr_instances()` succeeded (`ReplayResult::success`), `prepare()` immediately returned out of the command loop, completely abandoning every subsequent command in the same `CommandList`: - Subsequent copies, draws, dispatches, barriers, and queries were never prepared (silently dropped on fresh `PreparedList`s, or left with stale `Prepared` entries from previous executions on reused `VulkanQueue::prepared_` storage). - Subsequent validation errors (e.g. OOB copies or unclosed queries) were never checked. - `out.wrote_readback`, `out.readback_src_stages`, `plan_statistics_segments()`, and `plan_occlusion_segments()` at the end of `prepare()` were all skipped. ### Fix - Only return early when `vk.prepare_khr_instances()` fails: `if (const auto r = vk.prepare_khr_instances(*build, p.khr_instances); r != ReplayResult::success) return r;` - Add a real Vulkan GPU regression test `runtime/test/vk_khr_tlas_prepare_test.cpp` (registered as `vk_khr_tlas_prepare` in `runtime/CMakeLists.txt`) that records a KHR TLAS `ARRAY_OF_POINTERS` build followed by: 1. A real GPU `CopyBufferRegion` into a host-readable buffer, verifying real GPU execution and exact host readback. 2. An out-of-bounds `CopyBufferRegion`, verifying `prepare()` still rejects it with `ReplayResult::invalid_copy`. ### Verification (Real Dual-GPU Hardware) - **Before fix** on NVIDIA GeForce RTX 5060 Ti: `FAIL runtime/test/vk_khr_tlas_prepare_test.cpp:144: std::memcmp(dst_ptr, expected, sizeof(expected)) == 0` (trailing GPU copy silently dropped; readback buffer remained poisoned `0x5A`). - **After fix** on **NVIDIA GeForce RTX 5060 Ti**: `vk_khr_tlas_prepare_test: PASS (trailing GPU copy readback + validation verified)` - **After fix** on **AMD Radeon(TM) Graphics (GFX1036)**: `vk_khr_tlas_prepare_test: PASS (trailing GPU copy readback + validation verified)` ### Coordination - Claimed on #14 as `VK-KHR-TLAS-PREPARE-EARLY-RETURN` (no overlapping open PRs or claims). - AI-assisted: yes. <details> <summary>中文翻译</summary> ## 摘要 `runtime/src/vulkan_replay.h` 中 `prepare()` 在处理 KHR TLAS `ARRAY_OF_POINTERS` 构建时直接执行了 `return vk.prepare_khr_instances(*build, p.khr_instances);`。当 staging 成功返回 `ReplayResult::success` 时,`prepare()` 会直接跳出整个命令循环,导致同一命令列表中位于该 TLAS 构建之后的所有命令全部被跳过: - 后续拷贝、绘制、计算、屏障与查询均不会被准备(首次执行时静默丢弃,复用 `VulkanQueue::prepared_` 时还会残留上一帧的旧数据); - 后续命令的合法性校验与读回阶段标记丢失; - 函数末尾的 `plan_statistics_segments()` 与 `plan_occlusion_segments()` 被完全跳过。 ### 修复 - 仅在 `vk.prepare_khr_instances()` 返回非 `ReplayResult::success` 时提前返回。 - 新增真实 Vulkan GPU 回归测试 `runtime/test/vk_khr_tlas_prepare_test.cpp`(CMake 注册名 `vk_khr_tlas_prepare`),验证 KHR TLAS `ARRAY_OF_POINTERS` 之后的真实 GPU 拷贝读回与越界拷贝校验。 ### 真实双卡 GPU 验证 - **修复前(NVIDIA RTX 5060 Ti)**:后续 GPU 拷贝被静默丢弃,读回缓冲区仍为 `0x5A`,测试失败。 - **修复后(NVIDIA RTX 5060 Ti)**:`PASS (trailing GPU copy readback + validation verified)`。 - **修复后(AMD Radeon Graphics / GFX1036)**:`PASS (trailing GPU copy readback + validation verified)`。 ### 协同 - 已在 #14 认领 `VK-KHR-TLAS-PREPARE-EARLY-RETURN`。 - AI 辅助:是。 </details> --- <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#641
No description provided.