Skip to content

d3d12: continue prepare() past KHR ARRAY_OF_POINTERS TLAS builds - #8138

Open
daviddddddw12 wants to merge 1 commit into
ItsNotRexed:mainfrom
daviddddddw12:fix/replay-khr-tlas-early-return
Open

daviddddddw12 wants to merge 1 commit into
ItsNotRexed:mainfrom
daviddddddw12:fix/replay-khr-tlas-early-return

Conversation

@daviddddddw12

Copy link
Copy Markdown

Claimed in: #7913 (comment)

Depends on: none

Root cause

In leonida::prepare() (runtime/src/vulkan_replay.h), the BuildAccelerationStructure branch returned unconditionally on vk.prepare_khr_instances(*build, p.khr_instances) when a KHR TLAS build used D3D12_ELEMENTS_LAYOUT_ARRAY_OF_POINTERS (instance_pointers && instance_count):

return vk.prepare_khr_instances(*build, p.khr_instances);

When staging succeeded (ReplayResult::success), prepare() returned early out of the command loop, leaving every subsequent command in the list unprepared (buffer_copies empty, wrote_readback unset, trailing CopyBuffer falling through to vkCmdCopyImageToBuffer(VK_NULL_HANDLE) in emit() with Vulkan validation errors and an access violation) and skipping all post-loop query validation and segment planning (plan_statistics_segments, plan_occlusion_segments).

Fix

Only return early from prepare() when vk.prepare_khr_instances(...) != ReplayResult::success, so valid ARRAY_OF_POINTERS TLAS builds continue preparing the rest of the command list and running post-loop checks.

Verification (red before / green after)

Tested on Windows 11 Pro (build 26300), MSVC 19.44.35230.0, Vulkan SDK 1.4.363.0, AMD Radeon RX 6700 XT (driver 32.0.21045.29003), no game files.

Red on unpatched origin/main (dde82f27e):

  • replay_khr_tlas_pointers_test.exe failed (RED_CPU_EXIT=1) on all post-TLAS command-preparation, emission, error-propagation, and occlusion-segment planning checks.
  • LEONIDA_RT_AS=khr LEONIDA_VK_VALIDATION=1 d3d12_indirect_rt_test.exe crashed (0xC0000005 / -1073741819) after Vulkan validation errors (vkCmdCopyImageToBuffer(): srcImage is VK_NULL_HANDLE, dstBuffer is VK_NULL_HANDLE, regionCount must be greater than 0) on the CopyBufferRegion following BuildRaytracingAccelerationStructure(&tlas_ptr_build).

Green after fix:

  • replay_khr_tlas_pointers_test.exe: PASS (replay_khr_tlas_pointers: prepare/emit and query checks continue past KHR ARRAY_OF_POINTERS TLAS)
  • LEONIDA_RT_AS=khr LEONIDA_VK_VALIDATION=1 d3d12_indirect_rt_test.exe: PASS (0 validation errors) on AMD Radeon RX 6700 XT (including [PASS] CopyBufferRegion after ARRAY_OF_POINTERS TLAS build ran (0xcafebabe))
  • Default XDXR (LEONIDA_RT_AS unset) + LEONIDA_VK_VALIDATION=1 d3d12_indirect_rt_test.exe: PASS (0 validation errors) on AMD Radeon RX 6700 XT
  • ctest --test-dir runtime/build -R ^replay_|^d3d12_indirect_rt|^vk_command_replay --output-on-failure: 12/12 passed (100% tests passed out of 12)
  • python -I scripts/check_no_game_data.py runtime/src/vulkan_replay.h runtime/CMakeLists.txt runtime/test/replay_khr_tlas_pointers_test.cpp runtime/test/d3d12_indirect_rt_test.cpp: PASS

AI-assisted (Antigravity / Gemini 4).

@AirKyzzZ

AirKyzzZ commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested ee9c0f44b on RTX 2060 (NVIDIA 566.14), Windows 10 22H2, clang-cl 23.1.6 with the MSVC 14.44 STL, RelWithDebInfo: pass for replay_khr_tlas_pointers, the GPU half not reached on this machine.

  • replay_khr_tlas_pointers: passes. With main's runtime/src/vulkan_replay.h it fails all 8 checks (post-TLAS CopyBuffer is prepared, emit runs build_as then copy_buffer, all four query commands prepared past KHR TLAS, ...).
  • d3d12_indirect_rt fails here before the new case, with and without LEONIDA_RT_AS=khr, the same way on main 34702237c as on this head: [rt] d3d12: ExecuteCommandLists failed: invalid copy or resolve; nothing was submitted, then FAIL: RayQueryKHR ARRAY expected hit=1 miss=0, got hit=0 miss=0. So that is the existing failure reported in GPU test results (one comment per GPU and driver) #166 (bisected there to cc4b37449), not from this PR, and the new CopyBufferRegion after ARRAY_OF_POINTERS TLAS build check never runs here.

No game files. AI-assisted (Claude Code).

@lohant27-netizen

Copy link
Copy Markdown

Tested ee9c0f44b on Windows 11 (10.0.26300), NVIDIA GeForce RTX 5070 (driver 32.0.16.2101, subgroup 32), MSVC with SDK 10.0.26100, Release, merged onto main 77fa308f9 together with #8180, #8159, #8152, #8138 and #8155 (no conflicts): pass.

@ikurta92-png

Copy link
Copy Markdown

Tested ee9c0f44b on NVIDIA GeForce RTX 3060 (Ampere), driver 617.42, Windows 11 Pro 10.0.26300, MSVC 19.51 (VS 2026), RelWithDebInfo: pass; adding what the control looks like on NVIDIA, since it differs from the RX 6700 XT crash in the description.

  • This PR, LEONIDA_VK_VALIDATION off and on: replay_khr_tlas_pointers_test, d3d12_indirect_rt_test (default XDXR and LEONIDA_RT_AS=khr) and vk_command_replay_test all exit 0, d3d12_indirect_rt_test: PASS (0 validation errors) in both AS modes.
  • Control (runtime/src/vulkan_replay.h from the parent dde82f27e, both tests rebuilt): replay_khr_tlas_pointers_test exits 1 with FAIL: post-TLAS query lifecycle prepared and readback marked. d3d12_indirect_rt_test exits 1 in both AS modes, but no access violation here: it fails with copy after ARRAY_OF_POINTERS TLAS build expected 0xcafebabe, got 0x00000000, and with validation on the layer reports VUID-vkCmdCopyImageToBuffer-srcImage-parameter, -dstBuffer-parameter and -regionCount-arraylength for that copy, i.e. the unprepared command is recorded with null handles. So on this driver the early return shows up as a silently wrong readback rather than a crash.

AI-assisted (Claude Code). Synthetic tests only, no game files.

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