d3d12: allow queue submissions during fallback clock calibration #1720

Open
github-bot wants to merge 1 commit from github-bot/gh-1720 into main AGit
Owner

@⁠PyZikYG on GitHub · 2026-11-25 09:34 UTC · original
PyZikYG:d3d12-calibration-queue-progress → main · +165 −26 · 3 files · 1 commits · open

Claimed as D3D-CLOCK-CALIBRATION-SUBMIT.

Summary

Fallback GetClockCalibration used to hold the device-wide Vulkan submission lock across queue-idle waits. A slow calibration could block submissions from every D3D12 queue on the device.

Drain prior work with an empty submission and wait for that marker and the timestamp sample on a private timeline outside the submission lock. The timestamp submission remains bracketed by QPC reads. If a host wait fails, the next call retires the outstanding sample before reusing the command buffer.

Verification

Checked clock pairing, queue submissions while a calibration wait is paused, and retry after an injected host wait failure. Also ran the fence event coverage.

AI-assisted: yes.

**@⁠PyZikYG** on GitHub · 2026-11-25 09:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1720) `PyZikYG:d3d12-calibration-queue-progress` → `main` · +165 −26 · 3 files · 1 commits · open Claimed as [D3D-CLOCK-CALIBRATION-SUBMIT](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608). ### Summary Fallback `GetClockCalibration` used to hold the device-wide Vulkan submission lock across queue-idle waits. A slow calibration could block submissions from every D3D12 queue on the device. Drain prior work with an empty submission and wait for that marker and the timestamp sample on a private timeline outside the submission lock. The timestamp submission remains bracketed by QPC reads. If a host wait fails, the next call retires the outstanding sample before reusing the command buffer. ### Verification Checked clock pairing, queue submissions while a calibration wait is paused, and retry after an injected host wait failure. Also ran the fence event coverage. AI-assisted: yes.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:02:23 +00:00
Author
Owner

@⁠kawaii-shakal on GitHub · 2026-11-25 09:45 UTC · original · reviewed

Review (read-only, not run). Taking the waits out of the submit lock is the right fix, and the teardown and retry handling look correct. One accuracy point:

The calibration bracket is no longer exclusive. The old code held submit_mutex() from vkQueueWaitIdle through the timestamp submit and its wait, so the queue was idle and the GPU stamp ran right after before. Now:

  1. the drain marker is waited for outside the lock;
  2. before is read and the stamp submitted under the lock;
  3. the stamp is waited for outside it.

Between 1 and 2, another D3D12 queue that maps to the same VkQueue can submit work. The TOP_OF_PIPE timestamp then runs only after that work starts, and before is no longer close to it. The midpoint (before + after) / 2 can then be off by up to the duration of the interleaved work, not the tens of microseconds the doc text promises. The test does not see this because nothing else is submitted between the drain and the stamp.

Cheap options:

  • report or retry when after - before exceeds a bound (for example retry up to N times and keep the narrowest bracket), and say in docs/d3d12_vulkan.md that the fallback's error is bounded by that;
  • or hold submit_mutex() only from the drain wait's completion to the stamp submit. That is a short window and no GPU wait.

Minor: calibration_driver::fail_wait_number = 2 depends on the exact number of vkWaitSemaphores calls per calibration (the drain, then the stamp). A comment saying so would help the next person who changes the sequence.

AI-assisted review (Claude Code, Claude Opus 5.5).

**@⁠kawaii-shakal** on GitHub · 2026-11-25 09:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1720#pullrequestreview-6055208409) · **reviewed** Review (read-only, not run). Taking the waits out of the submit lock is the right fix, and the teardown and retry handling look correct. One accuracy point: **The calibration bracket is no longer exclusive.** The old code held `submit_mutex()` from `vkQueueWaitIdle` through the timestamp submit and its wait, so the queue was idle and the GPU stamp ran right after `before`. Now: 1. the drain marker is waited for outside the lock; 2. `before` is read and the stamp submitted under the lock; 3. the stamp is waited for outside it. Between 1 and 2, another D3D12 queue that maps to the same `VkQueue` can submit work. The `TOP_OF_PIPE` timestamp then runs only after that work starts, and `before` is no longer close to it. The midpoint `(before + after) / 2` can then be off by up to the duration of the interleaved work, not the tens of microseconds the doc text promises. The test does not see this because nothing else is submitted between the drain and the stamp. Cheap options: - report or retry when `after - before` exceeds a bound (for example retry up to N times and keep the narrowest bracket), and say in `docs/d3d12_vulkan.md` that the fallback's error is bounded by that; - or hold `submit_mutex()` only from the drain wait's completion to the stamp submit. That is a short window and no GPU wait. Minor: `calibration_driver::fail_wait_number = 2` depends on the exact number of `vkWaitSemaphores` calls per calibration (the drain, then the stamp). A comment saying so would help the next person who changes the sequence. AI-assisted review (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠potatoe0100 on GitHub · 2026-11-25 11:46 UTC · original

Tested c6817c3d5 merged onto main bcaa13dad (clean), native Windows 11 Pro 26H2 (build 26300), NVIDIA GeForce RTX 4060, driver 621.14, VS 2022 RelWithDebInfo + Ninja.

  • d3d12_fence_timing passes. Full ctest -j 6: 409 of 409 passed, same as main. run_gpu_tests.py: 209/263, identical to main.

AI-assisted testing (non-developer tester).

**@⁠potatoe0100** on GitHub · 2026-11-25 11:46 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1720#issuecomment-7161475691) Tested `c6817c3d5` merged onto `main` `bcaa13dad` (clean), native Windows 11 Pro 26H2 (build 26300), NVIDIA GeForce RTX 4060, driver 621.14, VS 2022 RelWithDebInfo + Ninja. - `d3d12_fence_timing` passes. Full `ctest -j 6`: 409 of 409 passed, same as `main`. `run_gpu_tests.py`: 209/263, identical to `main`. AI-assisted testing (non-developer tester).
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-25 12:00 UTC · original

Tested c6817c3d5 applied onto main 42537e7b6 on AMD: Radeon RX 7900 XT, driver 32.0.32029.2010 (26.11.2), Windows 11 build 26300, VS 2022 RelWithDebInfo. This driver has calibrated timestamps, so the test exercises both the calibration-capable queue and the fallback. No game files.

  • d3d12_fence_timing: passes 30 of 30 with --repeat until-fail:30, and 5 of 5 with LEONIDA_VK_VALIDATION=1 (no messages).
  • Fallback accuracy at idle, from the test's own lines, 3 runs each:
fallback (submitted timestamp query) calibration-capable queue
main 42537e7b6 25.0, 42.8, 86.7 µs apart 8.2, 6.7, 3.7 µs
this PR 69.2, 38.4, 55.3 µs apart 4.9, 7.7, 4.6 µs

So at idle the fallback is in the same range as before on this card. The run-to-run spread is larger than any difference between the two. I didn't measure it under concurrent submissions. That is where waiting outside the submission lock could widen the gap: work another thread queues on the same VkQueue after the marker drains runs ahead of the timestamp write.

  • Whole ctest -j 6: 398 of 402 pass or skip. The failures are d3d12_texture_tiles, d3d12_clear and d3d12_geometry_views, the same as on main. d3d12_indirect_rt failed once under -j 6 and passes 3 of 3 alone; it has done that on other trees here too.
**@⁠adrianmjim** on GitHub · 2026-11-25 12:00 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1720#issuecomment-7161802877) Tested `c6817c3d5` applied onto `main` `42537e7b6` on AMD: Radeon RX 7900 XT, driver 32.0.32029.2010 (26.11.2), Windows 11 build 26300, VS 2022 RelWithDebInfo. This driver has calibrated timestamps, so the test exercises both the calibration-capable queue and the fallback. No game files. - `d3d12_fence_timing`: passes 30 of 30 with `--repeat until-fail:30`, and 5 of 5 with `LEONIDA_VK_VALIDATION=1` (no messages). - **Fallback accuracy at idle**, from the test's own lines, 3 runs each: | | fallback (submitted timestamp query) | calibration-capable queue | |---|---|---| | `main` `42537e7b6` | 25.0, 42.8, 86.7 µs apart | 8.2, 6.7, 3.7 µs | | this PR | 69.2, 38.4, 55.3 µs apart | 4.9, 7.7, 4.6 µs | So at idle the fallback is in the same range as before on this card. The run-to-run spread is larger than any difference between the two. I didn't measure it under concurrent submissions. That is where waiting outside the submission lock could widen the gap: work another thread queues on the same VkQueue after the marker drains runs ahead of the timestamp write. - **Whole `ctest -j 6`:** 398 of 402 pass or skip. The failures are `d3d12_texture_tiles`, `d3d12_clear` and `d3d12_geometry_views`, the same as on `main`. `d3d12_indirect_rt` failed once under `-j 6` and passes 3 of 3 alone; it has done that on other trees here too.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1720/head:github-bot/gh-1720'
git switch 'github-bot/gh-1720'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1720'
git switch 'github-bot/gh-1720'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1720'
git switch 'github-bot/gh-1720'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1720'
git switch 'main'
git merge --squash 'github-bot/gh-1720'
git switch 'main'
git merge --ff-only 'github-bot/gh-1720'
git switch 'main'
git merge 'github-bot/gh-1720'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.