D3D12.X: GPU timestamps into the title's own memory land after the GPU #311
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!311
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/311/head"
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?
@emirduran707 on GitHub · 2026-11-23 23:07 UTC · original
emirduran707:timestamps-outside-uma→main· +181 −41 · 3 files · 1 commits · closed without mergingWrite64BitValueBottomOfPipeX/Write64BitValueTopOfPipeXwith a timestamp flag were dropped when the address was outside the unified memory windows, although the same calls with a value already reach such memory throughcpu_writes. The warning said0x…698 is not 8-byte aligned in unified memoryfor 8-byte-aligned addresses, because one message covered both cases.A retail title asks for such timestamps from its first frames. It hits this on a first run, while the coherent window is 512 MB (#284); with a learned window the addresses are inside it.
XCL_COHERENT_MB=512reproduces it on any run.What is in it
hle/d3d12x/cpu_writes.rs: a deferred write is either dwords (as before) or the 8 bytes the GPU resolved into a mapped readback buffer; the worker copies those to the address once the queue's fence is there, as one 8-byte store (a title polling it never sees half a value).hle/d3d12x/list_x.rs:timestamp()resolves a timestamp for the title's own writable memory into a per-device readback buffer (one 8-byte slot per query of the existing timestamp heap) and queues the copy; unified memory goes as before. Unaligned addresses and memory that is neither unified nor writable get their own warnings.cpu_writes::resolved_values_land_after_the_queue; the test title's console list check writes a timestamp into its heap (it failed on main withno GPU timestamp in the title's own memory). Bothcpu_writestests wait for the whole value (review below).Tested
x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug for the suite, release for the runs.cargo test --workspace -- --test-threads=4ate39bbfb: 667 passed, 0 failed, 41 ignored; noSKIPPEDlines.scripts/smoke.ps1(60 s) withXCL_COHERENT_MB=512set, maindb1ddb2vs this PR: main logsWrite64BitValueBottomOfPipeX: … not 8-byte aligned in unified memory – not done4 times (the warning's cap); this PR logs none andbottom-of-pipe writes outside unified memory are done by the CPU after the GPU (2 in the first submission). Frames 561 vs 694, peak commit 15 458 vs 15 483 MB, no crash or device removal in either. I did not see a visible change from the timestamps.cpu_writestest run alone, 10 times, passes on this machine before and after; with a 20 ms sleep after each dword store (local experiment, not committed) both fail 5 of 5 before the fix and 0 of 5 after.Regression run
The
gpu:line names a virtual display adapter of this machine (what #281 / #282 / #285 fix); XCL's log namesbackend 'real' – AMD Radeon RX 9060 XT (16188 MiB VRAM)in both runs.main:
PR:
Not tested
Write64BitValueTopOfPipeXtimestamps into the title's own memory on a retail title (same code path; the test title covers the bottom-of-pipe one).AI use
@regiumlepidi on GitHub · 2026-11-23 23:31 UTC · original
A race in the
cpu_writestests that this PR makes easy to hit, and that touches the timestamps themselves.write_nowstores the dwords one at a time (cpu_writes.rs,for (i, &w) in words.iter().enumerate() { … store(w, Release) }), so aValue::Resolvedtimestamp reaches the title as two 32-bit stores, low half first. Both tests wait only for the first store:writes_land_after_the_queuefor word 0 == 7,resolved_values_land_after_the_queueforcell != 0, i.e. the low half, and then compare the whole value.Tested on
600f092, RTX 5070 Ti (driver 617.42), Ryzen 7 9800X3D, Windows 11 Pro 25H2, rustc 1.100.0 MSVC, debug:writes_land_after_the_queueresolved_values_land_after_the_queuecargo test -p xcl --lib -- --exact <test>, this PRmain4017f8fwrite_now(local experiment only)left: [7, 0]left: 3642888684, right: 252750991852.\scripts\test.ps1, this PRAlone, the resolved test fails with only the low half, e.g.
left: 1473621646, right: 254876692110(the difference is 59 × 2³²). So with the suite's timing both pass, as in your run; run alone they fail every time on this machine. (writes_land_after_the_queueprintingleft: [7, 9] right: [7, 9]is the same race: the comparison saw[7, 0], and the second store landed before the message was formatted.)Outside the tests this means a title polling a 64-bit timestamp can read the new low half with the old high half.
Suggestions (either is enough for the tests; the second also covers the title):
while words() != [7, 9]withwords = || [0, 1].map(|i| (*((va + 4 * i) as *const AtomicU32)).load(Acquire)), andwhile cell.load(Acquire) != std::ptr::read_volatile(p as *const u64)for the resolved one. Onmainwith the 20 ms experiment, that change towrites_land_after_the_queuepasses 5 of 5 (and 300 of 300 without it);AtomicU64::store), which is what #317 does for itsWrite::U64/OsTimestamp. The two PRs reshapeWritedifferently and will conflict in this file.Not tested: a retail title; AMD for the failure (these tests use the default adapter, so the RX 9060 XT / Ryzen 5 5600 timing may simply never lose the race).
AI use: Claude Code with Claude Opus 5.5 found the race, ran these tests and wrote this comment; the numbers come from those runs.
@emirduran707 on GitHub · 2026-11-23 23:49 UTC · original
Thanks, you were right on both counts. Fixed in
e39bbfb(squashed, rebased ondb1ddb2):AtomicU64store when the address is 8-byte aligned (it always is:timestamp()refuses unaligned ones); the two-dword path is only the fallback.writes_land_after_the_queuefor[7, 9]read as two atomic loads,resolved_values_land_after_the_queuefor the resolved value itself.writable()and the worker share onecan_write_nowcheck instead of two copies of it.On the RX 9060 XT the race never shows on its own (each test alone, 10 runs: 0 failures before and after, as you expected for AMD). With your experiment (a 20 ms sleep after each dword store, local only): 5 of 5 failures for each test on 135195f, 0 of 5 on
e39bbfb. Suite ate39bbfb: 667 passed, 0 failed, 41 ignored, noSKIPPED; new smoke blocks are in the description.On #317: it reshapes
Writetoo, so whichever lands second will need a rebase; this PR keeps the GPU-timestamp flags as they are onmainand only adds the readback path, so the OS-QPC split there can sit on top of it.AI use: Claude Code with Claude Opus 5.5 made the fix, ran these tests and wrote this reply.
@ivall on GitHub · 2026-11-24 00:04 UTC · original
Closing as superseded by #330 (merged in
a6f5f7a): the same timestamps outside unified memory, with the resolved 64-bit value written as one atomic store (the two 32-bit stores here were the race regiumlepidi measured). Thanks!@PHeitor1 on GitHub · 2026-11-24 00:13 UTC · original
Tested
e39bbfbmerged ontomain3516080.RTX 5060 Ti 8 GB (Blackwell, 32-lane waves), NVIDIA 621.24, Ryzen 5 5600X, Windows 11 Pro 26300 (native, Graphics Tools + XGameRuntime installed, so the debug-layer tests run), rustc 1.100.0 MSVC, debug,
cargo test --workspace --no-fail-fast -- --test-threads=4, noXCL_SAMPLE_*.Pass: 671 passed, 0 failed, 41 ignored. SKIPPED: only the 2
no wave64tests (gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware). Build clean.Run and written with Claude Code (Claude Opus 5.5).
Pull request closed