Repository navigation
Conversation
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 <noreply@anthropic.com>
|
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 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. |
|
Test report for #996 at This covers the first point under Not tested: whether the new path is taken on Windows. Tested
Not tested
AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report. |
|
@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 On 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. |
|
Passes on a second Apple silicon host, on the Host: MacBook Pro M5 Pro (48 GB), macOS 27.2.1, CrossOver 26 with D3DMetal, Rosetta 2, Rust 1.100.0,
Which trigger fired, and why that matters. It is the "resolved to 0 on a queue that reached its fence" one, not the frequency gate. 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 One number that argues for your What this change does not reach, as far as I can read the diff (not tested against a title). 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. |
|
@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 @Lucasyudi so the picture for your decision: this PR supplies the value and the frequency / calibration answers; your |
|
Independent verification, merged onto current Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug.
AI use: test runs by Devin (Cognition, SWE-2); no code changes. |
Apple'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 XAudio2: GetState names the oldest queued buffer when the host gives none #890).tests/e2e.rs):maindies on this host before its timestamp check (the fallback PSO, D3D12.X: a stage the PC cannot run goes to the fallback without the driver #750). On a local stack ofmac-on-main-wip(db065d8) + D3D12.X: a stage the PC cannot run goes to the fallback without the driver #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" (D3D12.X: a stage the PC cannot run goes to the fallback without the driver #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). D3D12.X: timestamps are the CPU's clock on a host without GPU timestamps #996 (comment)f242ea8: 725 passed, 0 failed, 41 ignored; "no GPU timestamps on this host" appears 0 times in the tests' and the test title's logs. D3D12.X: timestamps are the CPU's clock on a host without GPU timestamps #996 (comment)gnullvmrelease build: the timestamp test fails on02bfd1dand passes onf242ea8; the trigger there is the resolved-to-0 one. D3D12.X: timestamps are the CPU's clock on a host without GPU timestamps #996 (comment)Regression 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, macOS (Apple Silicon, CrossOver + D3DMetal): the newer retail game reaches its first-run menus at 30 fps #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 macOS (Apple Silicon, CrossOver + D3DMetal): the newer retail game reaches its first-run menus at 30 fps #258).GetTimestampFrequency/GetClockCalibrationcalls (the test title makes neither).AI use
🤖 Generated with Claude Code