d3d12: allow queue submissions during fallback clock calibration #1720

Merged
PyZikYG merged 1 commit from upstream-pr/1720 into main 2026-11-28 09:53:04 +00:00
PyZikYG commented 2026-11-25 09:34:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PyZikYG on 2026-11-25T09:34:04Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5488729444 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1720). Originally posted by [PyZikYG](https://github.com/PyZikYG) on 2026-11-25T09:34:04Z. --- Claimed as [D3D-CLOCK-CALIBRATION-SUBMIT](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7158386667). ### 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.
kawaii-shakal commented 2026-11-25 09:45:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kawaii-shakal on 2026-11-25T09:45:26Z.

Review: COMMENTED


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6055208409 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1720#pullrequestreview-6055208409). Originally posted by [kawaii-shakal](https://github.com/kawaii-shakal) on 2026-11-25T09:45:26Z. **Review:** COMMENTED --- 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).
potatoe0100 commented 2026-11-25 11:46:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by potatoe0100 on 2026-11-25T11:46:11Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7161475691 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1720#issuecomment-7161475691). Originally posted by [potatoe0100](https://github.com/potatoe0100) on 2026-11-25T11:46:11Z. --- 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).
adrianmjim commented 2026-11-25 12:00:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by adrianmjim on 2026-11-25T12:00:49Z.


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.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7161802877 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1720#issuecomment-7161802877). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-25T12:00:49Z. --- 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.
MoonEyes commented 2026-11-28 09:52:53 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T09:52:53Z.


Red/green: the PR's test fails on main and passes with this PR (checked by OreoFR).
Runtime batch of 20 PRs tested by OreoFR (full build, ctest without the game, Python suite, translator): same results as main 09c153948, RTX 4070 Laptop / Windows 11.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237527255 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1720#issuecomment-7237527255). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T09:52:53Z. --- Red/green: the PR's test fails on main and passes with this PR (checked by OreoFR). Runtime batch of 20 PRs tested by OreoFR (full build, ctest without the game, Python suite, translator): same results as main 09c153948, RTX 4070 Laptop / Windows 11. AI-assisted (Claude Code, Claude Opus 5.5)
OreoFR commented 2026-11-28 21:53:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:53:32Z.


Verified by OreoFR

  • Base: main 09c153948 + PR head c6817c3d5; integration package 1 of 6 (20 PRs, merged without conflict)
  • Test: full runtime build; ctest -j 6 without the 28 tests that launch gta6rt; full Python suite; translator suite
  • Red on main: n/a (integration test; main baseline: xbox_present and d3d12_set_descriptor_heaps)
  • Green with the PR: ctest: only xbox_present and d3d12_set_descriptor_heaps fail, as on main; Python: the same 7 failing files as main, the PRs' 11 test files pass; translator: 0 failures
  • Verdict: CLEAN PACKAGE (no new failure vs main)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246348559 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1720#issuecomment-7246348559). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T21:53:32Z. --- **Verified by OreoFR** - Base: main `09c153948` + PR head `c6817c3d5`; integration package 1 of 6 (20 PRs, merged without conflict) - Test: full runtime build; ctest -j 6 without the 28 tests that launch gta6rt; full Python suite; translator suite - Red on main: n/a (integration test; main baseline: xbox_present and d3d12_set_descriptor_heaps) - Green with the PR: ctest: only xbox_present and d3d12_set_descriptor_heaps fail, as on main; Python: the same 7 failing files as main, the PRs' 11 test files pass; translator: 0 failures - Verdict: CLEAN PACKAGE (no new failure vs main) - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!1720
No description provided.