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).

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.

1 participant