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

Open
github-bot wants to merge 1 commit from github-bot/gh-599 into main AGit
Owner

@⁠tahffo68hk-hash on GitHub · 2026-11-24 09:39 UTC · original
tahffo68hk-hash:fix/vk-khr-tlas-prepare-early-return → main · +174 −1 · 3 files · 1 commits · open

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 辅助:是。
**@⁠tahffo68hk-hash** on GitHub · 2026-11-24 09:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/599) `tahffo68hk-hash:fix/vk-khr-tlas-prepare-early-return` → `main` · +174 −1 · 3 files · 1 commits · open ## 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>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:10:56 +00:00
Author
Owner

@⁠trigger337 on GitHub · 2026-11-24 09:48 UTC · original

Hardware verification report for vk_khr_tlas_prepare_test on native AMD RDNA2 GPU:

Environment:

  • GPU: AMD Radeon RX 6900 XT (RADV NAVI21, RDNA2, subgroup size 32..64)
  • Driver: Mesa 26.2.5-cachyos1.1 (Vulkan 1.4.333)
  • Host: Linux CachyOS (x86_64, kernel 7.3.1-2-cachyos)
  • Compiler: GCC 15.2.1 / CMake 4.2.0-rc2
  • Tree: PR #599 (fix/vk-khr-tlas-prepare-early-return)

Execution & Results:

  • Target: cmake --build runtime/build/linux --target vk_khr_tlas_prepare_test
  • Binary output:
    device: AMD Radeon RX 6900 XT (RADV NAVI21)
    subgroup sizes: 32..64 (default 64), requirable in stages 0xf0, subgroupSizeControl on, computeFullSubgroups on
    vk_khr_tlas_prepare_test: PASS (trailing GPU copy readback + validation verified)
    
  • CTest: ctest --test-dir runtime/build/linux -R vk_khr_tlas_prepare: 1/1 passed (0.02s).

Confirms trailing GPU copy readback and validation pass on physical AMD Radeon RX 6900 XT under Vulkan 1.4.

agent: yes
AI-assisted: yes

**@⁠trigger337** on GitHub · 2026-11-24 09:48 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/599#issuecomment-7127924132) Hardware verification report for `vk_khr_tlas_prepare_test` on native AMD RDNA2 GPU: **Environment:** - GPU: AMD Radeon RX 6900 XT (RADV NAVI21, RDNA2, subgroup size 32..64) - Driver: Mesa 26.2.5-cachyos1.1 (Vulkan 1.4.333) - Host: Linux CachyOS (x86_64, kernel 7.3.1-2-cachyos) - Compiler: GCC 15.2.1 / CMake 4.2.0-rc2 - Tree: PR #599 (`fix/vk-khr-tlas-prepare-early-return`) **Execution & Results:** - Target: `cmake --build runtime/build/linux --target vk_khr_tlas_prepare_test` - Binary output: ``` device: AMD Radeon RX 6900 XT (RADV NAVI21) subgroup sizes: 32..64 (default 64), requirable in stages 0xf0, subgroupSizeControl on, computeFullSubgroups on vk_khr_tlas_prepare_test: PASS (trailing GPU copy readback + validation verified) ``` - CTest: `ctest --test-dir runtime/build/linux -R vk_khr_tlas_prepare`: 1/1 passed (0.02s). Confirms trailing GPU copy readback and validation pass on physical AMD Radeon RX 6900 XT under Vulkan 1.4. agent: yes AI-assisted: yes
This pull request has changes conflicting with the target branch.
  • runtime/CMakeLists.txt
  • runtime/src/vulkan_replay.h
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/599/head:github-bot/gh-599'
git switch 'github-bot/gh-599'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-599'
git switch 'github-bot/gh-599'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-599'
git switch 'github-bot/gh-599'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-599'
git switch 'main'
git merge --squash 'github-bot/gh-599'
git switch 'main'
git merge --ff-only 'github-bot/gh-599'
git switch 'main'
git merge 'github-bot/gh-599'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.