D3D12.X: timestamps are the CPU's clock on a host without GPU timestamps #996
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!996
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-996"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@shortside on GitHub · 2026-11-24 10:06 UTC · original
shortside:d3d12x/host-without-gpu-timestamps→main· +100 −5 · 4 files · 1 commits · openApple's D3DMetal (macOS under CrossOver) has no GPU timestamps: a queue's
GetTimestampFrequencygives 60 and everyD3D12_QUERY_TYPE_TIMESTAMPresolves to 0. A title'sWrite64BitValueBottomOfPipeX/Write64BitValueTopOfPipeXtimestamp therefore stays 0 for ever:timestamps_outside_unified_memory_land_after_the_queuefails there ("never landed (top=0, bottom=0)"), and so does the test title's "no GPU timestamp" check. Part of #258.On such a host XCL's timestamps become the CPU's clock (
QueryPerformanceCounter). A host with GPU timestamps is asked oneGetTimestampFrequencyper title queue and nothing else changes for it.Related: #317 (draft) touches the same functions for a different thing, the console's OS-clock timestamp flags. This PR does not change which flags mean what.
What is in it (one commit, +100 / -5)
hle/d3d12x/cpu_writes.rs:cpu_clock()and what turns it on: a title queue whose timestamp frequency is below 1000 ticks a second (note_host_timestamp_frequency), or a timestamp query that resolved to 0 on a queue that reached its fence (that write gets the clock's value too). Unit testa_60_hz_timestamp_frequency_is_no_gpu_clock.hle/d3d12x/device_x.rs:create_command_queue_xasks a direct / compute queue its timestamp frequency.hle/d3d12x/list_x.rs: withcpu_clock(),timestampwrites the clock's value throughwrite, as any otherWrite64BitValue*. A target in unified memory gets it from the GPU, in the list's order (WriteBufferImmediate, marker in for top of pipe, marker out for bottom). A target outside unified memory gets it from thecpu_writesworker after the queue's fence, as every other value written there does.hle/d3d12x/real.rs: withcpu_clock(), queueGetTimestampFrequencyanswers the clock's frequency andGetClockCalibrationits value for both.What it is not: the value is the clock when the timestamp was recorded, not when the GPU got there, so GPU times measured between two timestamps come out too short (top and bottom of one submission differ only by the CPU time between the two calls). It also changes the value, not the ordering: outside unified memory the write still comes from the
cpu_writesworker, so the gap @Lucasyudi described in #258 (a title's ownSignaland wait can overtake the worker's write) is as open as before, for timestamps as for any other value. An earlier version wrote every clock value from that worker; the test title, whose timestamp is in unified memory, read 0 right after its own fence, which is why those go through the list.Tested
x86_64-pc-windows-msvcwith clang-cl / lld-link 23.1.6 and an xwin SDK 10.0.26100, Rust 1.100.0, debug. Test binaries run under Wine.mainis9aec53d, the head isf242ea8.EndQuery+ResolveQueryDataof three timestamps into a readback buffer, fence reached):GetTimestampFrequencyS_OK, 60; all three slots 0.xcl-<hash>.exe cpu_writes:: timestamps_outside_unified_memory --test-threads=1, 3 runs each:main2 passed, 1 failed (timestamps_outside_unified_memory_land_after_the_queue) every run; head 4 passed, 0 failed every run (the log shows "no GPU timestamps on this host (a timestamp query resolved to 0)").hle:: --skip ::gpu_ --test-threads=1, skipping the 3 tests that crash this host onmaintoo (create_list_reset_and_clear_state_track_initial_pso_on_d3d12,placed_title_textures_share_vram_and_preserve_pixels,d32s8_targets_take_their_own_size_of_video_memory):main288 passed, 4 failed, 2 ignored; head 290 passed, 3 failed, 2 ignored. The only test that changed is the timestamp one; the other 3 failures are the same on both (write_buffer_immediate_on_open_existing_heap_visible_to_cpu,mapped_frame_dump_distinguishes_dark_bright_and_undecoded_content,xma2_source_voice_decodes_and_manages_lifetime, the last one is #890).tests/e2e.rs):maindies on this host before its timestamp check (the fallback PSO, #750). On a local stack ofmac-on-main-wip(db065d8) + #750's diff + this change (ported by hand, the branch'scpu_writes.rsdiffers): "D3D12.X: console command list memory methods (writes, timestamp, fill, copy, KickoffX, Wait32/64)" passes in 3 of 3 runs, 47 PASS, and the log shows "no GPU timestamps on this host (the queue's timestamp frequency is 60)". Without this change that stack fails the check with "no GPU timestamp" (#750's description has the same).Tested by others
cargo test --workspace -- --test-threads=4with this patch onmain02bfd1d: 728 passed, 0 failed, 41 ignored (baseline 727). https://github.com/ivall/xcl/pull/996#issuecomment-7128493129f242ea8: 725 passed, 0 failed, 41 ignored; "no GPU timestamps on this host" appears 0 times in the tests' and the test title's logs. https://github.com/ivall/xcl/pull/996#issuecomment-7128968340gnullvmrelease build: the timestamp test fails on02bfd1dand passes onf242ea8; the trigger there is the resolved-to-0 one. https://github.com/ivall/xcl/pull/996#issuecomment-7129316849Regression run
scripts/smoke.ps1 -Seconds 60under PowerShell 7 on macOS, the retail title, release builds cross-built forx86_64-pc-windows-msvc, each from a clean tree of the commit, each on a fresh data root, one after the other. The script startsxcl.exethrough a small wrapper that runs it under Wine and rewrites only theLog:/Report:lines to macOS paths;XCL_DXC_THREADS=4for both runs. The blocks are as printed.maindoes not draw (OpenExistingHeapFromAddress … Not implemented, #258), so both runs sit at 0 frames for the 60 s and end cleanly; the device is made, but XCL's log shows no command queue and no timestamp before that point, so the change is not reached. It is a check that nothing is worse (no crash, no device removal, the same frames), not a run of the change.gpu:is D3DMetal's adapter name, andpeak commitreads 0 MB under Wine, so the commit limit cannot be compared here. A Windows pair would say more.main:this PR:
Not tested
cpu_writesordering above):timestamps_outside_unified_memory_land_after_the_queuepolls until the value is there, so it cannot see that.EndQuery/ResolveQueryDatatimestamp queries on the PC queue is not intercepted and still reads 0 on such a host (noted by @mikebuckets171).cargo test --workspacedoes not finish on this host, see #258).GetTimestampFrequency/GetClockCalibrationcalls (the test title makes neither).AI use
🤖 Generated with Claude Code
Apple's D3DMetal (macOS under CrossOver) has no GPU timestamps: a queue's GetTimestampFrequency gives 60 and every D3D12_QUERY_TYPE_TIMESTAMP resolves to 0 (measured with a D3D12 program without XCL: three queries, fence reached, all three 0). A title's Write64BitValue{Top,Bottom}OfPipeX timestamp therefore stayed 0 for ever: timestamps_outside_unified_memory_land_after_the_queue fails there with "never landed (top=0, bottom=0)", and the test title's "no GPU timestamp". A title queue is asked its timestamp frequency when it is created; below 1000 ticks a second that is no GPU clock, and XCL's timestamps become the CPU's clock (QueryPerformanceCounter). A timestamp query that resolved to 0 on a queue that got there turns it on as well. From then on a timestamp is the clock's value when it was recorded, written through the path every other Write64BitValue takes (so it lands in the GPU's order), and the queue's GetTimestampFrequency / GetClockCalibration answer with the same clock. A host with GPU timestamps is asked one frequency per queue and nothing else changes. Co-Authored-By: Claude Fable 5.2 <[email protected]>@dcastell1 on GitHub · 2026-11-24 10:13 UTC · original
Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on
main@02bfd1d(baseline 727 passed, 0 failed, 41 ignored on this box):One more passing test than the baseline: the CPU-clock timestamp path on a host without GPU timestamps is covered and green.
Tree restored afterwards (full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.
@DTsordas on GitHub · 2026-11-24 10:34 UTC · original
Test report for #996 at
f242ea8: Windows, AMD RDNA4. The CPU-clock path stays off on a host with GPU timestamps.This covers the first point under Not tested: whether the new path is taken on Windows.
Tested
cargo test --workspace --no-fail-fast -- --test-threads=4atf242ea8: 725 passed, 0 failed, 41 ignored, 0 SKIPPED. Among them:a_60_hz_timestamp_frequency_is_no_gpu_clock,readback_u64_lands_after_the_queueandtimestamps_outside_unified_memory_land_after_the_queue.cpu_writes/list_xtimestamp tests and--test e2e, with--nocapture: "no GPU timestamps on this host" appears 0 times in their output. It also appears 0 times in the test title's own log (target\tmp\e2e\data\XCL.TestTitle\logs\xcl.log, backend "AMD Radeon RX 9060 XT"). The title's "D3D12.X: console command list memory methods (writes, timestamp, fill, copy, KickoffX, Wait32/64)" check passes with the GPU's own timestamps.Not tested
GetTimestampFrequency/GetClockCalibrationcalls, on Windows; noxcl-smokeblocks from here.AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
@shortside on GitHub · 2026-11-24 10:39 UTC · original
@Lucasyudi I only saw your timestamp plan in #258 (04:50 and 04:59) after opening this. I had searched issues and PRs, not the comments of that thread. You said it first, so this is your call.
This PR ends up at the same detection as yours (a 60 Hz queue) and the same answers for
GetTimestampFrequency/GetClockCalibration. It differs in how the value gets written. I hit the race you describe too: my first version wrote the clock from thecpu_writesworker, and the test title read 0 at+0x10right after its own fence. Here the timestamp instead goes throughwrite, like any otherWrite64BitValue*: the clock value is taken when the timestamp is recorded and the GPU writes it in list order, so nothing waits on the worker. The cost is that it is the record time, not the time the GPU got there. It is not stacked on #317.On
mac-on-main-wip(db065d8) + #750 + this, the title's "console command list memory methods" check passes 3 of 3 here (M5 Pro, CrossOver 26.3).Whichever you prefer: take this approach into yours and I close this one, or keep this one and I add whatever your version has that this lacks (your three unit tests, the 1 MHz threshold instead of my 1 kHz). I won't take it out of draft before you answer.
@mikebuckets171 on GitHub · 2026-11-24 10:50 UTC · original
Passes on a second Apple silicon host, on the
gnullvmroute - and here the trigger that fires is the second one you built in.Host: MacBook Pro M5 Pro (48 GB), macOS 27.2.1, CrossOver 26 with D3DMetal, Rosetta 2, Rust 1.100.0,
x86_64-pc-windows-gnullvmwith LLVM-MinGW 20261117 (clang 23.1.6),--release --locked, test binaries under Wine, one test per process (--exact <full test path> --nocapture --test-threads=1).hle::d3d12x::list_x::tests::timestamps_outside_unified_memory_land_after_the_queue:base
02bfd1d: FAILED -panicked at crates/xcl/src/hle/d3d12x/list_x.rs:4981: non-UMA GPU timestamp never landed (top=0, bottom=0), exit0x65, after 5.34 s of polling. Same symptom the description reports.head
f242ea8: ok. 1 passed; 0 failed in 0.44 s, exit0x0, withWhich trigger fired, and why that matters. It is the "resolved to 0 on a queue that reached its fence" one, not the frequency gate.
note_host_timestamp_frequencyis wired intocreate_command_queue_x, and a lib test that builds its own device never goes through that wrapper - so on this host the fallback is not a rare second line of defence, it is the one that actually carries the library tests. Both paths exist for a title; for these tests only the fallback can fire, and it does, reliably, on the first timestamp write.Correcting one thing I posted earlier on #258, because it changes what your fix has to cover. I wrote that this host "has no readback heap at all" and that XCL's
D3D12_HEAP_TYPE_READBACKbuffer cannot be created here. That was wrong: the heap type is refused only in the initial states I first tried (GENERIC_READ,RESOLVE_DEST). InCOPY_DESTit is created fine, at 64 bytes and at 32768 bytes (TIMESTAMP_SLOTS * 8, the sizelist_x.rs:2118asks for),Mapwith no range andMapwith a read range both S_OK - which is exactly the shaperunner.rs:1442andlist_x.rs:2127ask for. So on this host the readback plumbing of the timestamp path works, and what fails is the content:EndQuery/ClearRenderTargetView/EndQuery,ResolveQueryDatainto that READBACK +COPY_DESTbuffer, fence signalled,Map(0, 0..16)S_OK → stamps 0 and 0. That makes your change the right one rather than a workaround for a missing buffer type: the query heap and the readback buffer are both there, they just never get a number in them.One number that argues for your
real.rshalf specifically. A plain D3D12 program on this host (no XCL) getsGetTimestampFrequencyS_OK = 60, andGetClockCalibrationS_OK with its GPU value equal to the CPU value (or 41-42 ticks below it) and advancing with wall time at ~10^6-10^7 ticks per run - i.e. the "GPU" clock it reports is already the host QPC at ~1 GHz. A title that reads both is given 60 ticks/second and a ~1 GHz-scaled value at the same time, so the error before this change is a factor of ~16.7 million, not just a zero. Making both answer from the clock is what removes that.What this change does not reach, as far as I can read the diff (not tested against a title).
timestamp()returns early with the clock whencpu_clock()is set, andreal.rsanswersGetTimestampFrequency/GetClockCalibrationfrom the clock, so XCL's ownWrite64BitValue*OfPipeXtimestamps and the port's frequency answers are covered. A title that callsBeginQuery/EndQuery/ResolveQueryData/Mapitself through the real queue is not intercepted by this change, and on this host such a query resolves to 0 - the test title makes neither call, so nothing here shows whether a real title does that. Flagging it because it is the remaining route to a 0, not because the PR should necessarily cover it.Host: macOS 27.2.1 (Apple silicon, M5 Pro), CrossOver 26, D3DMetal; local inference unloaded and the bottle's wineserver stopped for each run; the plain-D3D12 probe is a ~250-line PE with no XCL in it and reads no files. AI use: GPT-6 Luna built both trees, ran the test and the probe, and drafted this comment; the codes and timings are from those runs.
@shortside on GitHub · 2026-11-24 11:06 UTC · original
@mikebuckets171 your reading is right, thanks. In unified memory the value is written by the GPU in list order; outside it, it goes through the
cpu_writesworker like every other value there, so the ordering gap @Lucasyudi described is untouched by this PR. My note above ("nothing waits on the worker") and the description said that too broadly. I have corrected the description and added both of your points under Not tested (the ordering outside unified memory, and a title's own timestamp queries).@Lucasyudi so the picture for your decision: this PR supplies the value and the frequency / calibration answers; your
q.Waitidea forcpu_writes::afteris a separate fix that both approaches would need.@DavidM1911 on GitHub · 2026-11-24 11:36 UTC · original
Independent verification, merged onto current
main384f7f7locally (clean merge).Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug.
cargo test -p xcl --lib timestamp: 2 passed, 0 failed —a_60_hz_timestamp_frequency_is_no_gpu_clockcovers the new CPU-clock fallback path, andtimestamps_outside_unified_memory_land_after_the_queuestill passes with the list_x changes.AI use: test runs by Devin (Cognition, SWE-2); no code changes.
@JJAutoCompare on GitHub · 2026-11-25 05:31 UTC · original
Empirical test report (
f242ea82)Hardware / environment
rustc 1.100.0 (0ef1bc386 2026-11-09). DXC reporteddxcompiler.dll: 1.9(5512-01b62ad4)(1.9.2609.5) - 1.9.2609.5 (01b62ad47). Cargo used the unoptimized test profile with incremental compilation and debug info disabled.Commands and results
cargo test --workspace --no-runexited 0 and built the workspace test executables.cargo test -p xcl --lib hle::d3d12x::cpu_writes::tests::a_60_hz_timestamp_frequency_is_no_gpu_clock -- --exactexited 0 with 1 passed, 0 failed, 0 ignored, 0 skipped, and 704 filtered out. Ran outsideInvoke-ArcTest.ps1withXCL_ADAPTER=NONE_CPU_ONLYandRUST_TEST_NOCAPTURE=1.f242ea8285368db7aba158f0966a0ece9376cc6c.Observed behavior
The fixture classified 0 and 60 Hz as unavailable GPU timestamp frequencies and classified 1 MHz, 25 MHz, and 1 GHz as GPU clock frequencies. On this Windows host the reported performance-counter frequency cleared the fallback threshold, and consecutive counter reads were nonzero and nondecreasing.
Not tested
The full GPU workspace suite and game smoke runs on main and the PR head were omitted. The focused fixture leaves D3D12 queue integration untested, including zero GPU timestamp readback, ordered timestamp writes, clock calibration, and behavior on D3DMetal under CrossOver.
AI use
Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against
pr996-focused.logand published.@DavidM1911 on GitHub · 2026-11-26 03:32 UTC · original
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.