Skip to content

[upstream #996] D3D12.X: timestamps are the CPU's clock on a host without GPU timestamps - #127

Closed
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/996
Closed

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/996

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

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. A title's Write64BitValueBottomOfPipeX / Write64BitValueTopOfPipeX timestamp therefore stays 0 for ever: timestamps_outside_unified_memory_land_after_the_queue fails 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 one GetTimestampFrequency per 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 test a_60_hz_timestamp_frequency_is_no_gpu_clock.
  • hle/d3d12x/device_x.rs: create_command_queue_x asks a direct / compute queue its timestamp frequency.
  • hle/d3d12x/list_x.rs: with cpu_clock(), timestamp writes the clock's value through write, as any other Write64BitValue*. 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 the cpu_writes worker after the queue's fence, as every other value written there does.
  • hle/d3d12x/real.rs: with cpu_clock(), queue GetTimestampFrequency answers the clock's frequency and GetClockCalibration its 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_writes worker, so the gap @Lucasyudi described in #258 (a title's own Signal and 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

  • MacBook Pro M5 Pro, macOS 27.2.1, Rosetta 2; CrossOver 26.3 (Wine 11.0), Windows 10 bottle, D3DMetal; DXC 1.9.2609. Cross-built for x86_64-pc-windows-msvc with clang-cl / lld-link 23.1.6 and an xwin SDK 10.0.26100, Rust 1.100.0, debug. Test binaries run under Wine. main is 9aec53d, the head is f242ea8.
  • Without XCL, a D3D12 program on this host (EndQuery + ResolveQueryData of three timestamps into a readback buffer, fence reached): GetTimestampFrequency S_OK, 60; all three slots 0.
  • xcl-<hash>.exe cpu_writes:: timestamps_outside_unified_memory --test-threads=1, 3 runs each: main 2 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 on main too (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): main 288 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 xcl-dev/xcl#890).
  • The test title (tests/e2e.rs): main dies 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 xcl-dev/xcl#750). On a local stack of mac-on-main-wip (db065d8) + D3D12.X: a stage the PC cannot run goes to the fallback without the driver xcl-dev/xcl#750's diff + this change (ported by hand, the branch's cpu_writes.rs differs): "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 xcl-dev/xcl#750's description has the same).

Tested by others

Regression run

  • Not run yet (no retail title on this machine yet). An xcl-smoke pair is needed before this leaves draft.

Not tested

  • Windows: I have no Windows machine. Two testers ran the suite there, linked under Tested by others: the new path stays off on an AMD card and the suite passes on an NVIDIA one.
  • Whether a title's own wait can overtake a timestamp written outside unified memory (the cpu_writes ordering above): timestamps_outside_unified_memory_land_after_the_queue polls until the value is there, so it cannot see that.
  • A title that makes its own EndQuery / ResolveQueryData timestamp queries on the PC queue is not intercepted and still reads 0 on such a host (noted by @mikebuckets171).
  • The GPU tests and the whole suite (cargo test --workspace does not finish on this host, see [upstream #1898] Direct DXIL: truncate s instead of returning native on special values in round_exact #258).
  • Any retail title; a title's GetTimestampFrequency / GetClockCalibration calls (the test title makes neither).
  • In 4 of 5 runs of the local stack the title's "files: delete hides the file without touching the original" check failed; I have not checked whether that comes from running repeatedly on one data folder.

AI use

  • Claude Code with Claude Fable 5.2: found the cause, wrote the probe, the change, the test and this description, and ran the tests above on my machine.

🤖 Generated with Claude Code


Mirror of xcl-dev#996 (auto-synced, do not edit).

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>
ufoptg pushed a commit that referenced this pull request Nov 24, 2026
…ites

`pc_resource_desc` takes ALLOW_UNORDERED_ACCESS from a depth buffer the
console also lets shaders write (the PC refuses ALLOW_DEPTH_STENCIL with
ALLOW_UNORDERED_ACCESS). Only CreatePlacedResourceX (#44) moved such a
resource's initial state off UNORDERED_ACCESS as well (to DEPTH_WRITE).
The other paths that create a resource of the converted description
only masked the state with PC_RESOURCE_STATES: the committed fallback of
CreateCommittedResource (#27 / #76 / #127, reached without unified
memory or when its coherent window is full), the PC-way retry and the
committed fallback of CreatePlacedResource (#29), and its memory-of-its-
own path for textures larger on the PC. A console texture with flags
DEPTH_STENCIL | UNORDERED_ACCESS created in UNORDERED_ACCESS was then
asked for in a state D3D12 refuses for a resource without the UAV flag
(E_INVALIDARG; the #29 own-memory path fell back to COMMON).

`device_x::pc_initial_state` does both steps; #44 uses it with no change
in behaviour, and the four other sites use it with the console flags
(or the PC description's, which keep ALLOW_DEPTH_STENCIL).

Tests: a unit test of the helper; a GPU test placing a 256x256 D16
depth+UAV texture in UNORDERED_ACCESS as XCL now does (not run here).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#996 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/996 branch November 25, 2026 00:09
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.

2 participants