Repository navigation
Runtime: retain D3D12 fence semaphores across queued and in-flight GPU work - #3969
pmilewsskiedu-gif wants to merge 1 commit into
Conversation
Flyander
left a comment
There was a problem hiding this comment.
Reviewed the fence lifetime ownership paths: pending waits, deferred operations, successful queue submissions, sparse binds, retries, and per-queue retirement are all represented in the diff. The new synthetic test covers released fences, retry, cross-queue use, and a deliberately stalled in-flight signal. I found no additional blocker in this change.
|
Tested
|
|
Tested
I did not run the negative control on unpatched AI-assisted (Claude Code). |
|
Tested a36918b on Windows 11, AMD Radeon iGPU gfx1036 (driver 26.10.1) and RTX 5080 (driver 616.92): No Vulkan validation layer is installed here, so no VUID check was possible. No negative control run. AI-assisted. |
0xTehuti
left a comment
There was a problem hiding this comment.
Independent Hardware Verification & Review: PR #3969
Environment & Testbed
- OS: Windows 11 Pro x64 (Build 26100.1742)
- GPU: NVIDIA GeForce RTX 2070 SUPER (TU104 Turing, 8192 MB VRAM)
- Driver: NVIDIA Game Ready Driver 595.79 (Vulkan 1.4.304)
- Toolchain: MSVC 19.44.35225.0 (VS 2022 Community), Ninja 1.13, CMake 4.4, Windows SDK 10.0.26100.0, Vulkan Headers 1.4.363
- Validation Layers:
VK_LAYER_KHRONOS_validationactive viaLEONIDA_VK_VALIDATION=1
Test Execution & Results
1. Native Fence Lifetime Test (d3d12_fence_lifetime_test.exe)
- Native Host WARP Reference:
48/48released-fence pending waits completed successfully. - RTX 2070 SUPER Native Run: PASS. All 51 timelines retired, 0 stale handles, 0 validation errors.
- RTX 2070 SUPER under Vulkan Validation (
LEONIDA_VK_VALIDATION=1):5/5consecutive regression runs PASS (exit code 0).- Verified scenarios:
- 48 released-fence pending wait iterations.
- Synthetic
VK_ERROR_OUT_OF_HOST_MEMORYinjection duringvkQueueSubmitverifying retry preservation of pending guest waits. - Concurrent multi-queue waits on a shared released fence.
- Unsubmitted queue destruction releasing held timelines.
- In-flight GPU signal stalled behind a host timeline semaphore gate verifying deferred destruction until GPU gate release and queue idle.
2. Full CTest Synchronization Suite
Executed with Vulkan validation active (ctest --test-dir runtime/build --output-on-failure -V -R "^(d3d12_fence_|d3d12_queue_|d3d12_multithread|vk_queue_query_sync|d3d12_buffer_tiles)"):
vk_queue_query_sync: PASSED (0.39s)d3d12_multithread: PASSED (0.31s)d3d12_queue_wait: PASSED (1.29s)d3d12_queue_wait_timeout: PASSED (0.77s)d3d12_queue_handover: PASSED (6.35s)d3d12_buffer_tiles: PASSED (0.09s)d3d12_fence_timing: PASSED (2.12s)d3d12_fence_events: PASSED (0.86s)d3d12_fence_lifetime: PASSED (0.25s)d3d12_fence_waiter: PASSED (0.03s)
Overall pass rate: 10/10 tests passed (100%), 0 failures, 0 Vulkan validation errors.
Code Review & Correctness Assessment
- Decoupled Timeline Lifetime (
runtime/src/vulkan_backend.h,runtime/shims/d3d12_com.cpp):VulkanFence::Timelinesafely wraps the nativeVkSemaphorein an atomic shared owner (std::shared_ptr<Timeline>).- Releasing the D3D12 COM fence wrapper drops the COM ownership without blocking the CPU thread on queue idle or prematurely destroying the underlying Vulkan semaphore.
- Queue Lifecycle Retention (
VulkanQueue::in_flight_fences_,wait_lifetimes_):- Queue wait, signal, and sparse-bind paths correctly capture shared owners into
wait_lifetimes_and promote them toin_flight_fences_tied to the queue's internal progress ticket. - Retired tickets pop cleanly during command buffer recycling (
collect_fences) and queue destruction. - Retries on transient submission failure preserve pending wait lifetimes.
- Queue wait, signal, and sparse-bind paths correctly capture shared owners into
- Repository Conventions & Quality:
- Code adheres strictly to repository standards;
git diff --checkis completely clean with no trailing whitespace or style deviations.
- Code adheres strictly to repository standards;
Disclosures & Compliance
- Clean-room verification: Zero game assets, shaders, binaries, dumps, or private keys used.
- AI-assisted testing and verification: Verified and audited autonomously using Antigravity on RTX 2070 SUPER hardware.
Correctness defect
On current
mainaa2988c,ID3D12CommandQueue::Wait(fence, 1)stores a rawVkSemaphoreinVulkanQueue::waits_. Releasing the last COM reference to that fence immediately callsvkDestroySemaphorefromVulkanFence::~VulkanFence, even when the queue has not submitted its wait yet or a signal/wait is already in-flight. The next queue submission can reference a destroyed semaphore. No game files are involved.The identical 48-iteration synthetic host D3D12 WARP scenario (fence created with initial value 1,
Wait(fence, 1), release fence, then submitSignal(done, n)) completes 48/48. On unmodified Leonida main, with RTX 4060 Ti Vulkan validation enabled, a hookedvkQueueSubmitdetects a previously destroyed wait handle on iteration 0: test exits 1,destroyed use=1. The hook rejects that invalid call before reaching the real driver, so this is a deterministic API-lifetime negative control, not an observed GPU memory corruption or a real Vulkan VUID.Production fix
vkQueueSubmitfailures; keep COM Release event cancellation and CPU deferred-signal callback lifetime safe. Preserve the current cross-queue Wait-before-Signal scheduling and existing CPU fence ordering.Verification
aa2988ccin a separate detached baseline worktree: RED, exit 1, first invalid queued wait detected; native WARP comparison passes.VK_ERROR_OUT_OF_HOST_MEMORYqueue-submit failure and higher-value retry, concurrent two-queue waits on a released fence, unsubmitted-queue cleanup, and an actual queued GPU signal stalled behind a host-signaled Vulkan timeline gate to check there is no premature destruction and eventual retirement.vk_queue_query_sync,d3d12_multithread,d3d12_queue_wait,d3d12_queue_wait_timeout,d3d12_queue_handover,d3d12_buffer_tiles,d3d12_fence_timing,d3d12_fence_events,d3d12_fence_lifetime.git diff --checkclean.Original commit:
a36918b4965443f8c2fcd832233d03e0b92d1aaa. Four project files, +378/-21. Baseaa2988cc. Coordination claim before implementation: #3796 (comment) (claims carried forward to #3918). Independent from still-open #3789 transient Signal retry and existing #655/#770 placed alias ownership; preserves the current-main held-queue behavior (PR #2951 itself is OPEN) and merged #1161 CPU/GPU ordering.Limitations: The Vulkan OOM is synthetically injected before driver execution; physical device OOM and other GPU vendors were not tested. No full-suite claim or authentic game execution; GTA VI title executable remains unavailable. No proprietary game code, shaders, logs, keys, assets, executable or disassembly. AI-assisted implementation and testing.