Skip to content

vulkan_replay: continue prepare() after KHR TLAS ARRAY_OF_POINTERS build - #8267

Open
pablocpas wants to merge 1 commit into
ItsNotRexed:mainfrom
pablocpas:fix/khr-tlas-prepare-tail
Open

pablocpas wants to merge 1 commit into
ItsNotRexed:mainfrom
pablocpas:fix/khr-tlas-prepare-tail

Conversation

@pablocpas

Copy link
Copy Markdown

Claimed in #8047 (#8047 (comment)). Depends on: none. Regression introduced in cc4b374 (#4060).

Problem

Inside prepare()'s command loop in runtime/src/vulkan_replay.h (line 3047), the KHR TLAS ARRAY_OF_POINTERS branch returned the result of vk.prepare_khr_instances(*build, p.khr_instances) unconditionally:

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 prepare_khr_instances succeeded (ReplayResult::success), prepare() exited the loop immediately:

  • No command after the TLAS build was prepared (Prepared entries kept VK_NULL_HANDLE handles, wrote_readback / readback_src_stages missed trailing readback copies, and emit() ran against unprepared commands).
  • Trailing invalid/unresolved commands were never rejected.
  • Post-loop query checks and planning (plan_statistics_segments / plan_occlusion_segments) were skipped.

Fix

  • Check prepare_khr_instances and return early only when r != ReplayResult::success, matching every other helper in prepare().
  • Add a portable CPU regression test runtime/test/replay_khr_tlas_tail_test.cpp (registered as replay_khr_tlas_tail in runtime/CMakeLists.txt) covering:
    1. Trailing CopyBuffer (into a host_readable buffer) and Dispatch after a KHR ARRAY_OF_POINTERS TLAS build (both prepare() state and emit() calls).
    2. Two consecutive KHR ARRAY_OF_POINTERS TLAS builds.
    3. Rejection of an unresolved command after the TLAS build.
    4. Post-loop overlapping occlusion query planning (plan_occlusion_segments) around the TLAS build.
    5. Preserved error propagation when prepare_khr_instances fails.

Tested

  • OS / Compiler / GPU: Linux, GCC 16.2.1 (CMake + Ninja, RelWithDebInfo), AMD Radeon 780M Graphics (RADV PHOENIX, Mesa 26.2.6, Vulkan 1.4.354).
  • Before fix: replay_khr_tlas_tail_test failed 10/10 assertions on unpatched main (dde82f27e).
  • After fix:
    • replay_khr_tlas_tail_test: PASS (replay KHR TLAS ARRAY_OF_POINTERS tail preparation OK).
    • LEONIDA_VK_VALIDATION=1 ctest --test-dir runtime/build/linux --output-on-failure: 63 passed, 1 skipped (shader_library_corpus, no game files), 1 pre-existing failure (vk_queue, 10 sync-validation hazards in backlog test; vk_queue passes 1/1 without LEONIDA_VK_VALIDATION=1).
    • python3 -I scripts/check_no_game_data.py runtime/src/vulkan_replay.h runtime/CMakeLists.txt runtime/test/replay_khr_tlas_tail_test.cpp: PASS.

Synthetic tests only, no game files. AI-assisted.

Copilot AI balanced review requested due to automatic review settings November 23, 2026 18:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@KarolKurzyna

Copy link
Copy Markdown
Contributor

Independent Windows 11 MSVC + dual-GPU review of 707eb2767e (PASS, AI-assisted, synthetic tests only, no game data).

Environment

  • OS / Toolchain: Windows 11 x64, MSVC 19.52.37029 (x64, Ninja), CMake 4.3.1-msvc1, Vulkan loader 1.4.363, VK_LOADER_LAYERS_DISABLE=~implicit~, LEONIDA_VK_VALIDATION=1.
  • GPU 1 (hardware Vulkan KHR RT): NVIDIA GeForce RTX 3070 Ti (driver 621.24, Vulkan 1.4.357).
  • GPU 2 (non-RT iGPU): Intel(R) UHD Graphics 770 (Xe-LP, driver 101.6129, Vulkan 1.3.295).

Build & Code Audit

  • Built cleanly with MSVC (0 new warnings) across replay_khr_tlas_tail_test, vk_command_replay_test, and d3d12_dxr_validation_test.
  • Audited runtime/src/vulkan_replay.h:3032-3085: the early unconditional return vk.prepare_khr_instances(...) at line 3047 was the only stray success return inside prepare()'s command loop; replacing it with an error-only return cleanly restores preparation of trailing commands and post-loop query planning while preserving error propagation.
  • python -I scripts/check_no_game_data.py runtime/src/vulkan_replay.h runtime/CMakeLists.txt runtime/test/replay_khr_tlas_tail_test.cpp: clean.

Test Results (LEONIDA_VK_VALIDATION=1, 0 validation errors)

  • CPU: replay_khr_tlas_tail_test.exe — PASS (replay KHR TLAS ARRAY_OF_POINTERS tail preparation OK, all 5 scenarios).
  • RTX 3070 Ti:
    • vk_command_replay_test.exe: PASS (0 validation errors).
    • d3d12_dxr_validation_test.exe (default / XDXR): PASS (0 validation errors).
    • d3d12_dxr_validation_test.exe (LEONIDA_RT_AS=khr, hardware Vulkan KHR RT): PASS (0 validation errors).
  • Intel UHD Graphics 770:
    • vk_command_replay_test.exe: PASS (0 validation errors).

@MartinIndra02

Copy link
Copy Markdown

Independent build + test: PASS

AI-assisted (Claude Code). Windows 11 x64, MSVC 19.44.35220, Ninja RelWithDebInfo. CPU-only tests; machine GPU NVIDIA GeForce RTX 3080 driver 621.24 / 32.0.16.2124 (not used).

Head 707eb2767, merged locally with current main dfe4e4ad3 (vulkan_replay.h and CMakeLists.txt auto-merged). Reconfigured for the new target.

Test PR (merged) runtime/src/vulkan_replay.h reverted to main
replay_khr_tlas_tail_test.exe exit 0, replay KHR TLAS ARRAY_OF_POINTERS tail preparation OK exit 1: FAIL: list 1 trailing copy prepared, ... trailing readback tracked, ... trailing dispatch prepared, ... emitted trailing copy, ... emitted trailing dispatch, FAIL: list 2 both tlas builds staged, ...
replay_readback_stages_test.exe exit 0 not run
replay_texture_barrier_test.exe exit 0 not run

The fix is right: before it, a successful prepare_khr_instances returned from prepare() in the middle of the command loop, so everything after the first ARRAY_OF_POINTERS TLAS build (copies, readbacks, dispatches, a second TLAS build, the query planning after the loop) was never prepared. Errors still propagate. No issues found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants