Skip to content

Runtime: validate Vulkan clock calibration against Win32 QPC - #1278

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Zebraine:codex/wine-qpc-clock-calibration
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Zebraine:codex/wine-qpc-clock-calibration

Conversation

@Zebraine

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: Wine clock calibration follow-up in #1218.

What and why

d3d12_fence_timing fails under Wine when vkGetCalibratedTimestampsKHR succeeds but returns a CPU timestamp outside the Win32 QueryPerformanceCounter (QPC) interval around the call. On this Linux setup, Wine 11.22 maps Vulkan's QPC domain to CLOCK_MONOTONIC_RAW and converts the units to 100 ns ticks, while Wine's Win32 QPC uses CLOCK_BOOTTIME. A standalone Vulkan probe measured an offset of about 85 ms on this host.

Check the Vulkan CPU timestamp against QPC before accepting the calibrated pair. If it falls outside the interval, use the existing submitted GPU timestamp query to obtain a fresh GPU/CPU pair. The fast path still serves valid calibrated samples. The test now checks the QPC interval around both calls. This follows up on the merged D3D-30 implementation in #423.

Tested

CachyOS x86_64 (kernel 7.3.4-1-cachyos-bore), Wine 11.22, AMD Radeon RX 7700 XT (RADV NAVI32, Mesa 26.3.1-arch3.5), clang-cl 23.1.5, xwin 0.10.0, Windows SDK 10.0.26100. No game files were used.

Full test via CTest and Wine Result
Upstream e7584c52 Failed at before <= cpu0 && cpu0 <= after with calibrated timestamps available.
Patched 158e3e94 1/1 passed. Both QPC interval checks passed, including on the device that advertises calibrated timestamps. The explicit submitted-query fallback also passed. The measured CPU/GPU interval difference was 46.4 us on the device advertising calibrated timestamps and 0.6 us on the explicit fallback.

To reproduce, run the commands below from the repository root on the base and on this branch, using a separate build directory for each. This assumes xwin, clang-cl/lld-link, Ninja, Wine, and Vulkan headers are installed.

xwin --accept-license --sdk-version 10.0.26100 splat \
  --use-winsysroot-style --preserve-ms-arch-notation --output /tmp/leonida-xwin-sdk
cmake -S runtime -B /tmp/leonida-win-timing -G Ninja \
  --toolchain "$PWD/runtime/cmake/clang-cl-xwin.cmake" \
  -DXWIN_DIR=/tmp/leonida-xwin-sdk -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build /tmp/leonida-win-timing --target d3d12_fence_timing_test
WINEPREFIX=/tmp/leonida-timing-prefix WINEDLLOVERRIDES='mscoree,mshtml=' \
  LEONIDA_VK_DEVICE='RX 7700 XT' \
  ctest --test-dir /tmp/leonida-win-timing -R '^d3d12_fence_timing$' --no-tests=error -V

AI-assisted (Codex).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (N/A, runtime change.)

@whattheflop whattheflop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted independent native Windows verification of 158e3e94557f0843f2e8b16ecb113dec91251036 and its direct parent e7584c5207e44ed51472e6aa05c781f39ea975f6.

Windows 11 Pro x64 (build 26200), CMake 4.4.4, Ninja 1.13.2, MSVC 19.38.33145, Windows SDK 10.0.26100, uv-managed CPython 3.12.13. I built only d3d12_fence_timing_test in RelWithDebInfo and ran ctest -R '^d3d12_fence_timing$' --no-tests=error -V once per revision and GPU. I pinned one native ICD per run with VK_DRIVER_FILES and pointed VK_IMPLICIT_LAYER_PATH to an empty directory. The loader showed Khronos validation (SDK 1.4.363.0) on both Vulkan instances in each run. No validation errors were reported. No game files were used.

Stock runs (4/4 passed, zero skips). Cells show GPU / CPU interval in seconds and the absolute difference printed by the test.

GPU and Windows driver Revision Explicit submitted fallback Standalone queue
RTX 3080 (32.0.16.1664) Parent 0.050410 / 0.050729 (318.2 µs) 0.050158 / 0.050160 (1.8 µs)
RTX 3080 (32.0.16.1664) PR head 0.050941 / 0.051006 (65.5 µs) 0.050300 / 0.050302 (1.9 µs)
AMD Radeon(TM) Graphics (32.0.21030.2001) Parent 0.052603 / 0.052216 (387.0 µs) 0.053554 / 0.053551 (3.0 µs)
AMD Radeon(TM) Graphics (32.0.21030.2001) PR head 0.060177 / 0.059832 (344.9 µs) 0.051169 / 0.051167 (2.6 µs)

Both drivers advertised calibrated timestamps and both standalone queues had the calibrated function available. The stock head passed the Win32 QPC bracket assertions for both calls on each queue (the parent asserts the first call only). The stock queue label reports capability; the choice to return a calibrated sample is made per call.

Separate diagnostic runs (2/2 passed). In a disposable build of the head, I logged the Vulkan result and the QPC bracket decision after the inner QPC readings, plus entry to the submitted fallback. Each GPU returned VK_SUCCESS and accepted both standalone samples (4/4 total). Each explicit fallback queue took the submitted-query path twice with the calibrated function absent (4/4 total). The instrumented samples came from the ordinary test inputs. The out-of-range Wine case did not occur on these Windows runs.

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51): pass. ctest: 61/61 on the RTX 4080 SUPER, including d3d12_fence_timing with the QPC calibration check. On the Intel UHD 770, d3d12_fence_timing also passes, at 57/61. The Intel failures are known Intel issues, not from this PR: d3d12_vulkan_device (#962), d3d12_descriptor (min-LOD), d3d12_copy_xfmt, and vk_binary_occlusion (also on main; reported separately).

@ItsNotRexed
ItsNotRexed merged commit 1ecfd55 into ItsNotRexed:main Nov 22, 2026
@Ryderadzeee

Copy link
Copy Markdown
Contributor

Post-merge hardware verification from a run on PR head 158e3e94. AMD Radeon RX 9070 XT, driver 32.0.32029.2010, Windows 11 build 26300.10075, MSVC 19.51.36256, RelWithDebInfo. AI-assisted testing.

ctest --test-dir runtime/build -C RelWithDebInfo -R '^d3d12_fence_timing$' --no-tests=error --repeat until-fail:10 --output-on-failure passed 10 consecutive runs with LEONIDA_VK_DEVICE='RX 9070 XT'. A verbose run confirmed that the GPU exposed calibrated timestamps and the queue used them. The test also exercised the submitted-query fallback on the device created without the extension. Both paths passed the Win32 QPC interval checks.

The run used synthetic inputs with Vulkan validation layers disabled.

@ianneobot-cyber

Copy link
Copy Markdown

Tested 158e3e9 on Windows 11 (native, MSVC 17.14, Vulkan SDK 1.4.363): pass

  • d3d12_fence_timing, 3 runs each: pass on NVIDIA RTX 3070 Ti Laptop (621.14) and AMD Radeon integrated (2.0.262). Calibrated path: 0.4–0.8 us apart on NVIDIA, ~110 us on the AMD iGPU (same as main e7584c5); fallback 27–35 us / 640–910 us.
  • Full ctest on NVIDIA: 60/61 on both main and this branch; the one failure is d3d12_sampler2, already reported in Coordinating who works on what (5) (moved to #1380) #1218.

Review: looks correct. Two nits: under Wine every call now pays the submitted-query round trip because the mismatch isn't latched, so disabling the calibrated path after the first out-of-range sample (with a one-time log) would avoid that; and uses_calibrated_timestamps() stays true in that case, so the test's "used by the queue" line is misleading under Wine.

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