Skip to content

vk_presenter_sync: a watchdog and a ctest timeout, so a stalled step 3 says where and ends (TEST-840) - #3815

Open
Sc4ros wants to merge 2 commits into
ItsNotRexed:mainfrom
Sc4ros:test-840-presenter-sync
Open

Sc4ros wants to merge 2 commits into
ItsNotRexed:mainfrom
Sc4ros:test-840-presenter-sync

Conversation

@Sc4ros

@Sc4ros Sc4ros commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claim: #3796 (comment) (TEST-840, the first half: "give it a timeout")

AI-assisted (Claude Code). Tested on Windows 11 build 26300, MSVC 19.44, AMD Radeon RX 9060 XT (driver 32.0.32029.2010 = AMD 26.11.2, Vulkan 1.4.359). No game files.

What this does, and what it does not

TEST-840: on a Radeon 780M under AMD 26.11.2, vk_presenter_sync hangs about half the time in step 3, at full CPU, and ctest had no timeout on the target, so one run stalled the suite (finding by @damagdpixl on #3574).

It does not fix the race. I could not reproduce it on an RDNA4 dGPU with the same driver family: 12 sequential runs and 24 runs in 4 parallel processes (36 in all) all passed in about 0.5 s, so I have no stall to look at. The item says "an RDNA3 iGPU reproduces it"; whoever has one is better placed to find the race, and this PR gives them the data to start from.

Change

  • runtime/test/vk_presenter_sync_test.cpp: step 3 has a watchdog thread. If the step has not finished after LEONIDA_PRESENTER_SYNC_WATCHDOG_S seconds (default 60; a normal run takes about half a second) it prints presenter sync: step 3 did not finish in N s: K of 40 presents done, R worker rounds, worker failed: 0/1 and exits with 3, instead of spinning until killed. The two counters say whether the stall is in present() (K stops below 40) or in the worker's queue.execute() loop (R stops growing between two reports).
  • runtime/CMakeLists.txt: vk_presenter_sync gets TIMEOUT 180 as the backstop (the reporter measured one passing ctest run at 49 s on another driver, so it is not set tight).
  • vk_presenter_sync_watchdog tests the watchdog itself: LEONIDA_PRESENTER_SYNC_STALL=1 makes step 3 sleep, and the test must print the line above within 2 s (PASS_REGULAR_EXPRESSION). Without the change to the test source it fails (Required regular expression not found), because the old test ignores the variable and finishes normally.

Tested

  • ctest -R vk_presenter_sync: vk_presenter_sync 0.4 s and vk_presenter_sync_watchdog 2.4 s, 2/2 pass. The watchdog run printed step 3 did not finish in 2 s: 0 of 40 presents done, 37339 worker rounds, worker failed: 0.
  • The old test source with the new CMake: vk_presenter_sync_watchdog fails as described above.
  • Build: no new warnings from the test (it reads the variables with GetEnvironmentVariableA, as other tests do).

🤖 Generated with Claude Code

…3 says where and ends (TEST-840)

On an AMD Windows 26.11.2 iGPU about half the runs of vk_presenter_sync never left step 3 (concurrent present +
queue.execute + tracker mutations), spinning at full CPU, and ctest had no timeout on the target, so one run stalled the
whole suite. This does not fix the race; it makes the stall visible and bounded:

- Step 3 has a watchdog thread. If the step has not finished after LEONIDA_PRESENTER_SYNC_WATCHDOG_S seconds (default 60)
  the test prints how many of the 40 presents are done and how many rounds the worker ran, and exits with 3.
- vk_presenter_sync gets TIMEOUT 180 in ctest as the backstop.
- vk_presenter_sync_watchdog tests the watchdog: LEONIDA_PRESENTER_SYNC_STALL=1 makes step 3 stall on purpose and the test
  must report it within 2 s (it fails against the old test source).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@CowBoYdu76

Copy link
Copy Markdown
Contributor

Tested 5aef9eb (based on main f847748) on Windows 11 build 26300, MSVC 19.44, Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0: pass. No stall on NVIDIA or Intel, which adds two vendors next to your RDNA4 runs.

main f847748 this PR
RTX 4070 SUPER (NVIDIA 616.64), 20 sequential vk_presenter_sync_test runs 20/20 exit 0, 0.48 to 0.53 s 20/20 exit 0, 0.46 to 0.53 s
Intel UHD 770 (101.7092), the same 20/20 exit 0, 0.43 to 0.47 s 20/20 exit 0, 0.40 to 0.47 s
ctest -R vk_presenter_sync, 4070 SUPER 2/2: vk_presenter_sync 0.49 s; vk_presenter_sync_watchdog 2.43 s, printing step 3 did not finish in 2 s: 0 of 40 presents done, 119544 worker rounds, worker failed: 0
ctest -R vk_presenter_sync, UHD 770 2/2: 0.43 s; watchdog 2.65 s, 0 of 40 presents done, 43651 worker rounds

The watchdog line gives both counters as described, so a stall on the 780M should show which side stopped.

AI-assisted (Claude Code). No game files.

@kovaaper

Copy link
Copy Markdown
Contributor

Independent TEST-840 check on PR head 5aef9eb: Windows, MSVC 19.44, Ninja RelWithDebInfo, NVIDIA GeForce RTX 3060 (driver 621.01). Built vk_presenter_sync_test from a separate worktree with no game files. ctest -R ^vk_presenter_sync passed 2/2: normal test 0.87 s; injected stall reported step 3 did not finish in 2 s: 0 of 40 presents done, 38791 worker rounds, worker failed: 0 and completed in 2.66 s. Ten additional sequential normal runs passed 10/10 (0.71–0.80 s). This confirms the watchdog path on this NVIDIA setup; it does not reproduce or resolve the reported AMD iGPU race. AI-assisted (Codex).

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head merged with main 4c52ce2, MSVC 14.51):

  • RTX 4080 SUPER: vk_presenter_sync passes (0.7 s) and vk_presenter_sync_watchdog passes (2.5 s: the stalled step 3 is reported and the test exits well inside its 60 s timeout).
  • Intel UHD 770 (VK_LOADER_DRIVERS_DISABLE=*nv*): both pass, 0.5 s and 2.5 s.
  • Negative control: with vk_presenter_sync_test.cpp reverted to main, vk_presenter_sync still passes and vk_presenter_sync_watchdog fails on both GPUs (the required step 3 did not finish in 2 s: N of 40 presents done line is not printed), so the new test does exercise the watchdog.

Only these two tests were built and run, not the full ctest. No concerns.

@AC-Storm-YT

Copy link
Copy Markdown
Contributor

Tested 5aef9eb on Windows 11, Visual Studio 2026, RelWithDebInfo, AMD Windows 26.11.2: pass on two AMD GPUs.

  • AMD Radeon RX 9070 XT (RDNA4, driver 32.0.32029.2010): ctest -R vk_presenter_sync --repeat until-fail:10 passes both vk_presenter_sync and vk_presenter_sync_watchdog, and vk_presenter_sync alone passes 20/20.
  • Ryzen 7 9800X3D iGPU (RDNA2, driver 32.0.21045.29003): the same, 10/10 for both and 20/20 alone.
  • ctest --show-only=json-v1: vk_presenter_sync has TIMEOUT=180, and vk_presenter_sync_watchdog has TIMEOUT=60 and its pass regex.
  • Forcing a stall with LEONIDA_PRESENTER_SYNC_STALL=1 and LEONIDA_PRESENTER_SYNC_WATCHDOG_S=2 on the 9070 XT prints step 3 did not finish in 2 s: 0 of 40 presents done, 52449 worker rounds, worker failed: 0 and exits 3.

The hang itself didn't reproduce here either, on the same 26.11.2 driver: 50/50 runs of main's vk_presenter_sync_test pass on each GPU (slowest 2.1 s on the iGPU, 1.3 s on the 9070 XT). With your 9060 XT result, that rules out the driver alone on RDNA2 and RDNA4, which fits it needing the RDNA3 iGPU.

@ricardotanaka

Copy link
Copy Markdown

TEST-840 reproduces on an RDNA3 dGPU with this PR's watchdog: AMD Radeon RX 7600 (Navi 33, discrete), AMD driver 26.11.2 (LLPC, Vulkan 1.4.359), Windows 11 Pro 26200.9457, MSVC 19.44.35230, Ninja RelWithDebInfo. 5aef9ebd merged onto main f847748c; vk_presenter_sync_test.exe run directly, LEONIDA_PRESENTER_SYNC_WATCHDOG_S=20, VK_LOADER_LAYERS_DISABLE=~implicit~, no overlays.

runs stalls in step 3
sequential 40 0 (367 to 422 ms each)
4 processes in parallel, 6 runs each 24 8 (exit 3)

Watchdog lines of the 8 stalls, all worker failed: 0:

presents done (of 40) worker rounds
0 12174
0 6337
0 9539
0 8615
13 9399
15 12586
21 9752
30 9890

So on this card it is not iGPU-only, and it needs concurrency: no sequential run stalled, while a third of the parallel ones did. present() stops at different counts (0 to 30) while the worker keeps looping. Each run reports once and exits, so I can't say whether the rounds were still growing at that point. The stalled runs took 46 to 59 s from start to exit, against 0.5 to 3.5 s for the parallel runs that passed.

Also: ctest -R vk_presenter_sync 2/2 (the watchdog test prints 0 of 40 presents done, 36034 worker rounds), the same with LEONIDA_VK_VALIDATION=1, and full ctest 141/141.

I can rerun with other settings on this card if that helps whoever takes the race (VK_LOADER_DEBUG, a longer watchdog, a different process count). No game files. AI-assisted (Claude Code).

@Parakeet-Wheat

Copy link
Copy Markdown
Contributor

Tested 5aef9eb on Windows 11 26300, MSVC (VS 2022), Windows SDK 10.0.26100, RTX 3070 (610.88): pass. Full ctest was 141/141, and vk_presenter_sync_test with validation on passed 30 of 30 runs. That's the same as the other NVIDIA results. What follows is new.

Control: a stall on the worker side. The watchdog test and @ricardotanaka's stalls both stop in present(). To check that the report also points to the other side, I made the worker sleep locally at round 50 and ran with the default watchdog. After 60 s it printed step 3 did not finish in 60 s: 40 of 40 presents done, 50 worker rounds, worker failed: 0 and exited 3. So "all presents done, rounds frozen" is reported as clearly as "presents stopped".

Two small suggestions, based on @ricardotanaka's RX 7600 data:

  • A second read of the rounds. They note that each run reports once, so they can't tell whether the worker was still looping. Reading worker_rounds again about a second after the first print, and printing both before exiting, would answer that in one run.
  • Exiting without DLL detach. With LEONIDA_PRESENTER_SYNC_WATCHDOG_S=20, their stalled runs took 46 to 59 s from start to exit, against 0.5 to 3.5 s for the passing parallel runs. In the MSVC UCRT, std::_Exit ends in ExitProcess, which still runs every DLL's DLL_PROCESS_DETACH, the driver's included, after the other threads are gone. If the driver is the thing that's stuck, that is a place for the extra time to go. I can't verify that, since nothing stalls here: the whole 2 s watchdog test takes 2.7 s on this card. After the fflush, TerminateProcess(GetCurrentProcess(), 3) would skip the detach. Printing a timestamp next to the line would show whether the time goes before the report or after it.

AI-assisted (Claude Code).

@ismailchaka1

Copy link
Copy Markdown
Contributor

Tested 5aef9ebd on NVIDIA GeForce RTX 4070 SUPER, driver 32.0.16.1088, Windows 11, MSVC 2022 (Ninja, RelWithDebInfo), LEONIDA_VK_VALIDATION=1: pass.

  • ctest: 141/141 passed, including vk_presenter_sync and vk_presenter_sync_watchdog.
  • d3d12_vulkan_device_test, d3d12_descriptor_test, d3d12_present_test, d3d12_compute_test, d3d12_draw_test, d3d12_method_variants_test and d3d12_sampler2_test pass with 0 validation errors.
  • d3d12_clear_test exits 1 on depth format 55 case 1 byte 12: Vulkan ff, WARP 00. Current main (aa2988c) fails the same byte on the same GPU, so it doesn't come from this PR.
  • The build's four warnings (C4996 in d3d12_bundle_test.cpp and d3d12_first_light_test.cpp, C4456 in d3d12_compute_test.cpp and xgameruntime_test.cpp) are in files this PR doesn't touch.

PR head as-is, no game files. AI-assisted.

@LucasDonin

Copy link
Copy Markdown

Tested 5aef9ebd (head as is, base f847748c) on an NVIDIA GeForce GTX 1660 (Turing TU116), driver 610.88, Windows 11, MSVC 19.44 (VS 2022 Build Tools, Ninja, RelWithDebInfo), LEONIDA_VK_VALIDATION=1: pass.

AI-assisted run (Claude). No game files involved.

@ricardotanaka

Copy link
Copy Markdown

@Parakeet-Wheat, timing on the same RX 7600 (AMD 26.11.2, Windows 11 26200.9457): the extra time is after the report, at exit.

This round: 5aef9ebd merged onto main aa2988cc, 4 processes in parallel × 6 runs, LEONIDA_PRESENTER_SYNC_WATCHDOG_S=20, each process's output read line by line with a timer from process start. 20 of 24 runs stalled this time (8 of 24 in my first round on f847748c).

  • The watchdog line appears at 20.4 to 22.6 s after start, i.e. the 20 s watchdog plus ~0.5–2.5 s of startup.
  • The process then exits 34 to 40 s later (totals 55.6 to 61.0 s), with nothing more printed.
  • The 4 passing runs took 0.6 to 2.7 s in all.
  • Presents done at the report: 0 of 40 in 17 stalls, 10 or 11 in the other 3; worker rounds 7,891 to 10,038; worker failed: 0 every time.

One caveat: stdout is a pipe here, so the test's earlier lines only arrive with the watchdog's fflush (they all show the same time). The watchdog line's time is reliable, the others aren't.

So the 35–40 s go after std::_Exit, which fits your DLL-detach reading. I haven't tried TerminateProcess or a second read of the rounds, since both need a source change; if the PR adds them, I'll rerun the same 24 here. No game files. AI-assisted (Claude Code).

@zzEmmazz

Copy link
Copy Markdown
Contributor

Tested 5aef9ebd, applied alone on main f847748c: pass.

Windows 11 (26200), MSVC 14.50 (VS 2026), Ninja RelWithDebInfo. Two GPUs: Ryzen 7 9700X iGPU (RDNA2, AMD 32.0.21042.62) and RTX 3070 (NVIDIA 610.74), picked with LEONIDA_VK_DEVICE.

  • CMake change alone with the old test source: vk_presenter_sync_watchdog fails on both GPUs with Required regular expression not found. Regex=[step 3 did not finish in 2 s: [0-9]+ of 40 presents done]; vk_presenter_sync passes.
  • Whole PR, ctest -R "^vk_presenter_sync" --repeat until-fail:10: both tests pass all 10 rounds on each GPU (Radeon 76 s in total, RTX 3070 67 s). The test builds with no warning.
  • The watchdog run directly (LEONIDA_PRESENTER_SYNC_STALL=1, LEONIDA_PRESENTER_SYNC_WATCHDOG_S=2): exit code 3 and presenter sync: step 3 did not finish in 2 s: 0 of 40 presents done, 77418 worker rounds, worker failed: 0 on the Radeon, the same line with 62348 rounds on the RTX 3070.
  • The TEST-840 stall itself did not show here: 10 normal runs of step 3 on the AMD iGPU (RDNA2, driver 32.0.21042.62, not the 26.11.2 driver of the report) all finished. A single vk_presenter_sync run took 6.2 s on the Radeon and 1.2 s on the RTX 3070 (other GPU jobs were running on this PC at the time).

Not checked: a real stall (none occurred), so the two counters were only seen in the forced-stall run; the whole ctest run.

AI-assisted; measured on my PC.

@crastinator

Copy link
Copy Markdown
Contributor

Tested 5aef9eb merged into main aa2988cc (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • Whole run_gpu_tests.py: 196/210 native, 196/210 with LEONIDA_W64_EMULATE=1 (the skips are the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 47/47.

No game files. AI-assisted (Claude Code).

@tupacfan04

Copy link
Copy Markdown
Contributor

Static review (no Vulkan build/GPU here): the TIMEOUT 180 is registered at runtime/CMakeLists.txt:956, and the watchdog test is at :958-961 (TIMEOUT 60, STALL=1, 2 s, PASS_REGULAR_EXPRESSION). The mutation check is real - the old source ignores STALL, prints no line, and the regex fails.

The watchdog (runtime/test/vk_presenter_sync_test.cpp:339-347) reports the step, presents_done, worker_rounds and worker_failed before _Exit(3), and the counters at :367,378 distinguish a hang in present() from one in queue.execute()/join.

Nits: env_value silently ignores values of 32+ characters (:52-54), and the body says worker failed: 0/1 while the code prints one integer (:342-343).

Approve. AI-assisted review, no game files, no GPU.

…atchdog with TerminateProcess (review)

- After the watchdog line the test waits one second and prints the presents done and the worker rounds again, saying
  whether the worker is still looping, so one stalled run tells present() from the worker side.
- The test ends with TerminateProcess(GetCurrentProcess(), 3) instead of std::_Exit(3): _Exit ends in ExitProcess,
  which runs every DLL's DLL_PROCESS_DETACH, the driver's included, and stalled runs on an RX 7600 took 35 to 40 s more
  to exit after the report. The exit code stays 3 and the watchdog test still matches the same line.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Sc4ros

Sc4ros commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @ricardotanaka for the RX 7600 numbers (the race is real on an RDNA3 dGPU, and only under concurrency) and @Parakeet-Wheat for the two suggestions; both are in, pushed 9e9f97e:

  1. A second read. After the watchdog line the test waits one second and prints one second later: N presents done, R worker rounds (the worker is still looping | the worker has stopped too), so a single stalled run says whether the stall is in present() (presents stuck, rounds growing) or on the worker side (rounds frozen).
  2. No DLL detach. The test now ends with TerminateProcess(GetCurrentProcess(), 3) instead of std::_Exit(3), so ExitProcess does not run every DLL's DLL_PROCESS_DETACH (the driver's included) after the report. The exit code stays 3.

Tested on Windows 11 build 26300, MSVC 19.44, AMD RX 9060 XT (driver 32.0.32029.2010): ctest -R vk_presenter_sync 2/2 (the watchdog test 3.6 s, because of the extra second), a stalled run with a 2 s watchdog printed both lines (0 presents done, 94003 worker rounds, then 141308 worker rounds (the worker is still looping)) and exited with 3 after 3.6 s in all, and 12 normal runs exited 0. I did not reproduce the stall itself here (my first 36 runs, 24 of them in parallel, all passed; I have not retried with more processes).

@ricardotanaka, if you rerun your 24 with this head, the exit time after the report is what to look at.

AI-assisted (Claude Code). No game files.

@Parakeet-Wheat

Copy link
Copy Markdown
Contributor

Retested 9e9f97e on the same RTX 3070 (610.88, Windows 11 26300, MSVC VS 2022): pass. Full ctest is 141/141 (vk_presenter_sync and vk_presenter_sync_watchdog included), and vk_presenter_sync_test passes with 0 validation errors.

Worker-side stall control, rerun on this head (worker sleeps at round 50, default 60 s watchdog):

presenter sync: step 3 did not finish in 60 s: 40 of 40 presents done, 50 worker rounds, worker failed: 0
presenter sync: one second later: 40 presents done, 50 worker rounds (the worker has stopped too)

Exit code 3. The run took about 62.5 s from start to its last output, which is the 60 s watchdog, the 1 s second read and start-up. So the new line names the stalled side correctly in the case your own run didn't cover (yours was the present() side, still looping), and the exit comes straight after the report. Thanks for taking both suggestions.

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.