Repository navigation
Runtime: replace full LayoutTracker clone in VulkanQueue::execute with O(touched) rollback journal (D3D-244) - #1872
Conversation
|
Tested Without Cause: Checked: I added a one-shot Full AI-assisted. |
|
Thanks @Thatters for catching that under Re-verified on Windows 11 (MinGW-w64
AI-assisted. |
|
Confirmed with the validation layer on:
AI-assisted. |
|
Tested 6907e70 on AMD Radeon RX 7600 (RDNA3), AMD 26.11.2 (LLPC), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363.0: rollback retest passed.
AI-assisted (Claude Code, reviewed with Codex). No game files. |
|
Tested 6907e70 on NVIDIA GeForce RTX 5060 (Blackwell, driver 617.42, Vulkan 1.4.351), Windows 11 Pro build 26300, MSVC (VS 2026), LLVM_MC set, scripts\build_runtime.ps1, then ctest -j 4: pass for this change. layout_tracker_rollback and vk_queue_tracker_rollback pass; 108 of 109 run tests pass. The one failure is d3d12_draw ("fence signal 4 is not above 30"), which fails the same way on main 003e781 here and is fixed by #1807. GitHub now shows a conflict with main, so this result is for the current head before a rebase. (Run with an AI coding agent.) |
6907e70 to
20006d6
Compare
|
Tested 20006d6 on Windows 11 (MSVC BuildTools 2022, Ninja, RelWithDebInfo, -j 4; no Vulkan validation layer installed), one GPU at a time, device line confirmed: AMD Radeon RDNA2 iGPU (driver 26.10.1) and NVIDIA RTX 5080 (driver 616.92). Ran AI-assisted. |
|
Tested 20006d6 on Intel UHD 770 (driver 32.0.101.7088), Windows 11, MSVC 19.44, Vulkan SDK 1.4.357: pass. |
…h O(touched) rollback journal (D3D-244)
…ue_tracker_rollback_test
|
Rebased cleanly onto Re-verified on Windows 11 (
AI-assisted. |
20006d6 to
1ea4ecc
Compare
|
Tested on NVIDIA GeForce RTX 5080, driver 621.24, Windows 11 (10.0.26200), Vulkan device API 1.4.357: pass Checked out PR head
|
|
Tested 1ea4ecc on NVIDIA RTX 4070 SUPER (driver 616.92), Windows 11 26200, MSVC 14.44, Vulkan SDK 1.4.363, RelWithDebInfo: pass, no regression against main 561b65a.
|
|
Tested
Not run: other GPUs/vendors, Linux, anything that needs game files. No game files. AI-assisted (Claude Code). |
Claimed in #1745 as D3D-244 (claim). Follow-up to #1744 (D3D-225, which removed the full
LayoutTrackerclone fromVulkanPresenter::submit()); independent of #901 (per-command barrier/copy vectors inprepare/emit).What and why
VulkanQueue::execute()(runtime/src/vulkan_backend.h) previously cloned the entire device-wideLayoutTracker(auto next_tracker = context_.tracker_;) on everyExecuteCommandListscall while holding the globaltracker_mutex_, so failed submissions could discard uncommitted layout transitions.Because
LayoutTrackerstores anstd::unordered_map<ResourceId, Entry>with astd::vector<VkImageLayout>per tracked texture, cloning it copies every live texture in the device even when a batch touches only a handful of subresources — thousands of heap allocations per submission undertracker_mutex_.Changes
runtime/src/vulkan_replay.h(LayoutTracker::Transaction):LayoutTracker::Transactionguard that mutatesLayoutTrackerin place and appends(ResourceId, subresource_index, previous_layout)to a reusableundo_log_only whenset()actually changes a subresource's layout.commit()runs in O(1) without touching or cloning unmodified resources (reusingundo_log_capacity up to 4,096 entries and releasing oversized spikes).rollback()(and~Transaction()if uncommitted) walksundo_log_in reverse order with a per-resource lookup cache, restoring multi-step transitions on the same subresource, partial mip/layer ranges, and separate depth/stencil planes to their exact initial states.LayoutTracker(e.g.,VulkanPresenterprior to Runtime: O(1) LayoutTracker rollback and unlock tracker_mutex before vkQueuePresentKHR in VulkanPresenter #1744) stay unaffected.runtime/src/vulkan_backend.h(VulkanQueue::execute()):auto next_tracker = context_.tracker_;+context_.tracker_ = std::move(next_tracker);withLayoutTracker::Transaction tracker_tx(context_.tracker_);undertracker_lock, callingtracker_tx.commit()on successful submit andtracker_tx.rollback()on failedvkEndCommandBufferorvkQueueSubmit.resource_mutex_ -> tracker_mutex_ -> submit_mutex_) and lifetime ordering (tracker_txdestroyed beforetracker_lock) are unchanged.runtime/test/layout_tracker_rollback_test.cpp+runtime/CMakeLists.txt(layout_tracker_rollback):operator newcheck proving 0 heap allocations across 400 steady-state commit/rollback transactions with 2,048 live tracked textures.runtime/test/vk_queue_tracker_rollback_test.cpp+runtime/CMakeLists.txt(vk_queue_tracker_rollback,SKIP_RETURN_CODE 77):ExecuteCommandListsfailing atvkQueueSubmit: rolls back both layers of a GPU-poisoned (0x5A)UNDEFINEDcommitted texture while preserving 1,024 untouched textures; retry commits, clears layer 0, and runs deferred zero-fill on layer 1 (0x00readback).vkEndCommandBuffer: rolls back multi-step layout transitions without invokingvkQueueSubmit.VulkanQueue::execute()calls with 16 vs 2,048 live tracked textures (allocs_2048 <= allocs_16 + 64).Verification (synthetic tests only, no game data)
Built on Windows 11 with MinGW-w64
g++ 16.2.0(-std=c++20 -O2 -Wall -Wextra, Vulkan-Headers1.4.363.0, 0 warnings in touched/new code):layout_tracker_rollback_test: PASS (0 heap allocations across 400 steady-state commit/rollback rounds with 2,048 tracked textures)d3d12_state_map_test,replay_clear_gate_test,replay_copy_offset_test,replay_readback_stages_test,replay_cpu_bench --self-test: all PASS0x8086:0xa7a8, driver101.7092, Vulkan1.4.323):vk_queue_tracker_rollback_test: 3/3 PASS — 10 executes: 16 textures =41 allocs (2.3–2.4 us/exec), 2,048 textures =40 allocs (2.0 us/exec)vk_queue_query_sync_test,vk_command_replay_test,depth24_convert_test,vk_presenter_sync_test: all PASS621.24):vk_queue_tracker_rollback_test: 3/3 PASS — 10 executes: 16 textures =41–43 allocs (13.6–16.4 us/exec), 2,048 textures =40–41 allocs (10.6–18.0 us/exec)vk_queue_query_sync_test,vk_command_replay_test,depth24_convert_test,vk_presenter_sync_test: all PASSorigin/main003e7812):VulkanQueue::execute()toauto next_tracker = context_.tracker_;failsvk_queue_tracker_rollback_testatline 333: allocs_2048 <= allocs_16 + 64(exit=1) on both GPUs:431 allocs (3.8 us/exec)→ 2,048 textures =41,070 allocs (147.9 us/exec)(~1,027× more allocations, ~74× slower per execute than this PR)433 allocs (18.3 us/exec)→ 2,048 textures =41,070 allocs (168.5 us/exec)(~1,000× more allocations, ~10–13× slower per execute than this PR)tracker_tx.rollback()on failed submit failsvk_queue_tracker_rollback_testatline 193: context.layout(1, 0) == VK_IMAGE_LAYOUT_UNDEFINED(exit=1).AI-assisted.