D3D12.X: resolve GPU timestamps targeting memory outside unified memory #330
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!330
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/330/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?
@XaviFortes on GitHub · 2026-11-23 23:31 UTC · original
XaviFortes:d3d12x-non-uma-timestamps→main· +253 −25 · 2 files · 1 commits · merged 2026-11-24 00:03 UTCWrite64BitValueBottomOfPipeXandWrite64BitValueTopOfPipeXwith timestamp flags (BOTTOM_TIMESTAMPS/TOP_TIMESTAMPS) previously dropped any timestamp targeting memory outside unified memory (0x... is not 8-byte aligned in unified memory – not done), even though non-timestamp writes already fall back tocpu_writesafter the queue fence completes. On a retail title's first run (beforeuma_coherent.txtgrows the coherent window), its timestamp buffers land in plainVirtualAllocmemory and every GPU timestamp is lost.This resolves non-UMA GPU timestamp queries into a lazily allocated, persistently mapped
READBACKbuffer per device (4096slots, 32 KiB) and copies the resolved 64-bit GPU tick atomically to the title's address incpu_writesonce the submission's queue fence completes. It also separates the 8-byte alignment check from the unified-memory check so warnings report the actual reason.What is in it
crates/xcl/src/hle/d3d12x/cpu_writes.rs: replace the(usize, Vec<u32>)alias with aWriteenum (ImmediateandReadbackU64) and atomic 64-bit stores for readback slots; addreadback_u64_lands_after_the_queueunit test.crates/xcl/src/hle/d3d12x/list_x.rs: extendTIMESTAMPSwith a lazy per-deviceREADBACKbuffer (TimestampPool) for non-UMA timestamp targets, separate alignment vs. UMA validation, and addtimestamps_outside_unified_memory_land_after_the_queueGPU test.Tested
rustc 1.98.1, debug (tests) and release (smoke).cargo build --workspace && cargo test --workspace -- --test-threads=4: 654 passed, 0 failed, 40 ignored, 0SKIPPEDGPU tests.hle::d3d12x::cpu_writes::tests::readback_u64_lands_after_the_queueandhle::d3d12x::list_x::tests::timestamps_outside_unified_memory_land_after_the_queuepass on the RX 7900 XT (both verify non-UMA GPU timestamp / readback delivery after queue completion and rejection of unaligned/unwritable targets).Regression run
Not tested
timestamps_outside_unified_memory_land_after_the_queue) andreadback_u64_lands_after_the_queue.AI use
@mastrr9 on GitHub · 2026-11-23 23:38 UTC · original
Static code audit of
85d85b5(not tested on Windows; no game files):Overlap with earlier PR #311
This solves the same non-UMA GPU timestamp issue in
cpu_writes.rsandlist_x.rsas earlier open PR #311 (600f092, which also adds an end-to-endtesttitlecheck and has an active thread on coordinatingWritewith #317).That said, this PR handles three details cleaner than #311's current head:
AtomicU64::store(..., Release)inwrite_u64_now(avoiding the torn 2×32-bit write race reproduced on #311)._buf: ID3D12Resourcealive insideWrite::ReadbackU64.listis tracked inLISTSbefore emittingEndQuery/ResolveQueryData.Issues found in
85d85b5write_u64_now(cpu_writes.rs:79):m.Protect & (PAGE_READWRITE | PAGE_EXECUTE_READWRITE) == 0does not excludePAGE_GUARD(0x100), so a guarded RW page passes the check and faults on the worker thread; also preferva.checked_add(8)overva + 8.readback_u64_lands_after_the_queue(cpu_writes.rs:107-111): Calls.unwrap()/.expect()when creating the DXGI factory / WARP device instead of callingskip_test("no GPU")aslist_x.rs:303does andCONTRIBUTING.mdasks for GPU tests.AI usesection: Does not name the AI tool/model if an AI tool was used (or statenone).NEXT_TIMESTAMPring has no fence-completion guard if >4096 non-UMA timestamps are recorded before the worker drains earlier submissions.AI use: static code audit of
85d85b5(and comparison with #311600f092) with Antigravity (Gemini 4 Neon).@regiumlepidi on GitHub · 2026-11-23 23:45 UTC · original
An NVIDIA run, which the description lists under Not tested:
85d85b5merged onto currentmaindb1ddb2(clean merge): pass.Tested
XCL_ADAPTER=radeon(the Ryzen 7 9800X3D's RDNA2 iGPU, driver 32.0.21030.2001).\scripts\test.ps1(cargo test --workspace -- --test-threads=4), noXCL_SAMPLE_*setXCL_ADAPTER=radeonmaindb1ddb285d85b5ondb1ddb2D3D12CreateDevice(None, …), so they ran on the RTX 5070 Ti in both columns;XCL_ADAPTERonly moves the recompiler's GPU tests.--exact):readback_u64_lands_after_the_queue0 of 30 failed,writes_land_after_the_queue0 of 30 failed. The readback value lands as oneAtomicU64store and the test waits for the whole value, so it does not have the torn-read race described on #311, where the same kind of test run alone fails every time on this machine.Not tested
scripts/smoke.ps1on a real title (I have none).This PR, #311 and #317 all reshape
cpu_writes::Writeand will conflict in that file.AI use: Claude Code with Claude Opus 5.5 ran the build and tests and wrote this comment; the numbers come from those runs.
@XaviFortes on GitHub · 2026-11-23 23:55 UTC · original
Thanks for the audit! Fixed those in
4403887:write_u64_nownow excludesPAGE_GUARDand useschecked_add(8)readback_u64_lands_after_the_queuecallsskip_test("no GPU")instead of unwrapping4403887Didn't catch #311 before opening this — I'll leave it open if the atomic 64-bit write /
_buf/LISTScheck is useful.@ivall on GitHub · 2026-11-24 00:03 UTC · original
Merged (
a6f5f7a). Checked on an RX 9070 (RDNA4) on maina6f5f7a, together with #335, #322, #331, #330, #338, #318 and #332:cargo test --workspace -- --test-threads=4- 636 unit tests passed, 0 failed; the retail game reaches its menu and draws it (frame dump) and goes on past it. This also supersedes #311 (the same timestamps, but written there as two 32-bit stores).@PHeitor1 on GitHub · 2026-11-24 00:13 UTC · original
Tested
4403887merged 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: 672 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).