Skip to content

Runtime: bound FenceWaitDispatcher's vkWaitSemaphores to 100 ms slices - #3285

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
sixtyBR:fix/fence-dispatcher-bounded-wait
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
sixtyBR:fix/fence-dispatcher-bounded-wait

Conversation

@sixtyBR

@sixtyBR sixtyBR commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claimed in #3232 (comment).

What and why

FenceWaitDispatcher::run() (runtime/src/vulkan_backend.h) waits with vkWaitSemaphores(..., UINT64_MAX). Under GPU paravirtualization (measured in Windows Sandbox, vGPU on an RTX 5060 Ti, driver 617.42) that call is a kernel wait the OS can't interrupt. A process that exits while a wait is pending never finishes exiting, and TerminateProcess from outside can't end it either. d3d12_queue_wait_timeout does exactly this by design (_Exit(1) with a fence wait pending); in a serial ctest it stayed alive more than 17 minutes past its TIMEOUT 10.

This change caps each wait at 100 ms (kWaitSliceNs). A timeout returns to the existing loop, which already falls through on VK_TIMEOUT and re-arms the same wait. A completed fence still wakes the thread at once through the ANY wait, so this is not completion polling. The cost is at most 10 wake-ups a second, only while a wait is pending.

How it was narrowed down

Windows Sandbox, RTX 5060 Ti 617.42, main 1628210, the control run alone (d3d12_queue_wait_test --timeout-control) under a watchdog that waits 20 s, then Stop-Process, then 15 s more:

Variant Result
as main 2/2 never exit; after Stop-Process one thread remains in Wait/Executive
TerminateProcess(GetCurrentProcess(), 1) instead of _Exit(1) 2/2 never exit, same thread state, so it isn't DLL detach
100 ms slices 3/3 exit in about 1 s with code 1

Validation (this branch, same sandbox)

  • d3d12_queue_wait_timeout: passed in 1.06 s (on main it hangs). The control alone: 5/5 exit in 0.9 to 1.2 s with code 1. d3d12_queue_wait_test (positive): 5/5 pass.
  • ctest --test-dir runtime/build --output-on-failure: 128/129. The one failure, queue_proxy (line 1302, a shared fence's value read through OpenSharedHandle), fails the same way on main in this sandbox.
  • scripts/run_gpu_tests.py: 143/189 passed, 46 skipped; with LEONIDA_W64_EMULATE=1, 174/189 passed, 15 skipped. Same as main.
  • Not checked on bare metal.

Relation to TEST-586 (#2963, #2970): those raise the test's TIMEOUT to 20 s for slow device bring-up under parallel load. This fixes a process that never exits, and it changes a different file, so there is no conflict.

Tested on NVIDIA GeForce RTX 5060 Ti (Blackwell, subgroup 32), driver 617.42, Windows 11 Pro 26200, inside Windows Sandbox (vGPU, no network).

AI-assisted (Claude Code): the investigation, the change and the runs were automated; I reviewed the diff and the results.

🤖 Generated with Claude Code

Under GPU paravirtualization (Windows Sandbox, RTX 5060 Ti, driver 617.42) the dispatcher's
infinite vkWaitSemaphores is a kernel wait that cannot be interrupted. A process that exits with
a wait pending, as d3d12_queue_wait_timeout does by design, never finishes exiting, and
TerminateProcess from CTest cannot end it. Bounded slices let the thread return to user mode;
the loop re-arms the same wait and completions still wake it at once.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Doffi4

Doffi4 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Independent bare-metal test of 4a9c4124 on Windows 11 (26200), MSVC 19.44 x64 Release, with Khronos validation 1.4.357 enabled. The executable logged the selected device in every run.

GPU Positive cases Pending-fence timeout control
Radeon 780M (AMD 26.11.2) 3/3 completed, exit 0 3/3 printed the expected timeout and exited 1 in ~0.22 s
RTX 5060 Laptop (NVIDIA 621.01) 3/3 completed, exit 0 3/3 printed the expected timeout and exited 1 in ~0.66 s

The registered d3d12_queue_wait and d3d12_queue_wait_timeout CTests also passed on each GPU. No Vulkan validation errors in the direct runs. Serial PR-head verification only; I did not rerun the unbounded-wait baseline or the separate parallel stress workload reported in #3197. Synthetic tests only. AI-assisted testing and reporting.

@mokkymiah

Copy link
Copy Markdown
Contributor

Independent bare-metal run of 4a9c4124, merged cleanly onto main f847748c. Windows 11 x64, NVIDIA GeForce RTX 3070, driver 621.01, Vulkan 1.4.357, MSVC 19.44, Ninja RelWithDebInfo, LEONIDA_VK_VALIDATION=1. Synthetic tests only, no game data. AI-assisted.

Direct results

  • d3d12_queue_wait_test positive: 3/3, exit 0, 684-803 ms.
  • d3d12_queue_wait_test --timeout-control: 3/3, exit 1, 672-700 ms.
  • d3d12_multithread_test --repeat until-fail:5: pass in 290 ms.

The parallel stress Doffi4 did not rerun on #3197

Six concurrent d3d12_multithread_test plus two concurrent d3d12_queue_wait_test, all with validation: all eight printed their PASS/completion line and exited in ~1 s, no hang. A control run of the same eight processes on plain main f847748c also passed in ~2 s.

So this Ampere host does not reproduce the >100 s contention hang seen on the RTX 5060 in #3197, with or without the 100 ms slices. That makes this a no-regression data point, not a confirmation of the hang fix: the uninterruptible vkWaitSemaphores wait appears specific to that vGPU/Sandbox environment, as your report says.

@al3xar

al3xar commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 4a9c4124 on NVIDIA GeForce RTX 3060 (driver 621.24, Vulkan 1.4.357, Windows 11, MSVC 19.44, Vulkan SDK 1.4.363.0): pass.

  • vk_fence_dispatcher_sync_test.exe with LEONIDA_VK_VALIDATION=1: ok (exit 0, 0 validation errors).
  • d3d12_fence_events_test.exe with LEONIDA_VK_VALIDATION=1: vulkan / host default adapter / host WARP: fence events match the host runtime (exit 0, 0 validation errors).
  • ctest -R "^(vk_fence_dispatcher_sync|d3d12_fence_events)$" --output-on-failure: 2/2 Passed.

AI-assisted.

@CowBoYdu76

Copy link
Copy Markdown
Contributor

Tested 4a9c412 merged onto main f847748 (clean merge) on bare metal, RTX 4070 SUPER (NVIDIA 616.64) and Intel UHD 770 (101.7092), Windows 11 build 26300, MSVC 19.44, Vulkan SDK 1.4.363.0: no regression. This is not the paravirtualized setup the PR fixes, so it only checks that the 100 ms slices change nothing on a normal driver.

main f847748 this PR
d3d12_queue_wait_test, 4070 SUPER pass, 0 validation messages pass, 0 validation messages
d3d12_queue_wait_timeout (ctest), 4070 SUPER passed, 0.84 s passed, 0.66 s
d3d12_queue_wait_timeout (ctest), UHD 770 passed, 0.29 s passed, 0.28 s
full ctest, 4070 SUPER 140/140 140/140
full ctest, UHD 770 138/140 138/140, the same two (d3d12_descriptor, d3d12_subgroup, both on main, see #2948 and #2934)

So the timeout control exits promptly on both GPUs with the slices in place.

On the UHD 770 the positive d3d12_queue_wait_test returns 77 (skipped) on main and with this PR alike, so it doesn't exercise the dispatcher there. That is unrelated to this change: the UHD 770's Vulkan driver exposes a single graphics/compute/transfer queue and no dedicated compute or transfer family, so after the copy queue at line 47 takes the only lease, the compute queue at line 49 gets E_OUTOFMEMORY (no independent Vulkan queue available). I'm posting that separately in the coordination issue.

AI-assisted (Claude Code).

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.

6 participants