You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
d3d12: continue prepare() past KHR ARRAY_OF_POINTERS TLAS builds - #8138
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):
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))
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 main34702237c 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.
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 main77fa308f9 together with #8180, #8159, #8152, #8138 and #8155 (no conflicts): pass.
replay_khr_tlas_pointers and d3d12_indirect_rt pass.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claimed in: #7913 (comment)
Depends on: none
Root cause
In
leonida::prepare()(runtime/src/vulkan_replay.h), theBuildAccelerationStructurebranch returned unconditionally onvk.prepare_khr_instances(*build, p.khr_instances)when a KHR TLAS build usedD3D12_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_copiesempty,wrote_readbackunset, trailingCopyBufferfalling through tovkCmdCopyImageToBuffer(VK_NULL_HANDLE)inemit()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()whenvk.prepare_khr_instances(...) != ReplayResult::success, so validARRAY_OF_POINTERSTLAS 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.exefailed (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.execrashed (0xC0000005/-1073741819) after Vulkan validation errors (vkCmdCopyImageToBuffer(): srcImage is VK_NULL_HANDLE,dstBuffer is VK_NULL_HANDLE,regionCount must be greater than 0) on theCopyBufferRegionfollowingBuildRaytracingAccelerationStructure(&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)onAMD Radeon RX 6700 XT(including[PASS] CopyBufferRegion after ARRAY_OF_POINTERS TLAS build ran (0xcafebabe))LEONIDA_RT_ASunset) +LEONIDA_VK_VALIDATION=1 d3d12_indirect_rt_test.exe:PASS (0 validation errors)onAMD Radeon RX 6700 XTctest --test-dir runtime/build -R ^replay_|^d3d12_indirect_rt|^vk_command_replay --output-on-failure:12/12passed (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:PASSAI-assisted (Antigravity / Gemini 4).