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

Closed
tahffo68hk-hash wants to merge 1 commit from upstream-pr/599 into main
tahffo68hk-hash commented 2026-11-24 09:39:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tahffo68hk-hash on 2026-11-24T09:39:21Z.


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 辅助:是。
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5469680534 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/599). Originally posted by [tahffo68hk-hash](https://github.com/tahffo68hk-hash) on 2026-11-24T09:39:21Z. --- ## 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>
trigger337 commented 2026-11-24 09:48:47 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by trigger337 on 2026-11-24T09:48:47Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7127924132 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/599#issuecomment-7127924132). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T09:48:47Z. --- 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
MoonEyes commented 2026-11-27 23:20:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T23:20:08Z.


Hi @tahffo68hk-hash, thanks for this pull request. It currently conflicts with main (conflicting file(s): runtime/CMakeLists.txt, runtime/src/vulkan_replay.h), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7230060324 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/599#issuecomment-7230060324). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-27T23:20:08Z. --- Hi @tahffo68hk-hash, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `runtime/CMakeLists.txt`, `runtime/src/vulkan_replay.h`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-12-01 16:30:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:30:56Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317733722 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/599#issuecomment-7317733722). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:30:56Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!599
No description provided.