Skip to content

D3D12.X: resolve GPU timestamps targeting memory outside unified memory - #330

Merged
ivall merged 1 commit into
ivall:mainfrom
XaviFortes:d3d12x-non-uma-timestamps
Nov 24, 2026
Merged

ivall merged 1 commit into
ivall:mainfrom
XaviFortes:d3d12x-non-uma-timestamps

Conversation

@XaviFortes

@XaviFortes XaviFortes commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Write64BitValueBottomOfPipeX and Write64BitValueTopOfPipeX with 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 to cpu_writes after the queue fence completes. On a retail title's first run (before uma_coherent.txt grows the coherent window), its timestamp buffers land in plain VirtualAlloc memory and every GPU timestamp is lost.

This resolves non-UMA GPU timestamp queries into a lazily allocated, persistently mapped READBACK buffer per device (4096 slots, 32 KiB) and copies the resolved 64-bit GPU tick atomically to the title's address in cpu_writes once 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 a Write enum (Immediate and ReadbackU64) and atomic 64-bit stores for readback slots; add readback_u64_lands_after_the_queue unit test.
  • crates/xcl/src/hle/d3d12x/list_x.rs: extend TIMESTAMPS with a lazy per-device READBACK buffer (TimestampPool) for non-UMA timestamp targets, separate alignment vs. UMA validation, and add timestamps_outside_unified_memory_land_after_the_queue GPU test.

Tested

  • Hardware / OS / toolchain: AMD Radeon RX 7900 XT (20420 MiB VRAM), AMD64 Family 25 Model 33 Stepping 2 (Zen 3), Windows 11 (10.0.26200.0), DXC 1.8.2502.11, rustc 1.98.1, debug (tests) and release (smoke).
  • cargo build --workspace && cargo test --workspace -- --test-threads=4: 654 passed, 0 failed, 40 ignored, 0 SKIPPED GPU tests.
  • New tests: hle::d3d12x::cpu_writes::tests::readback_u64_lands_after_the_queue and hle::d3d12x::list_x::tests::timestamps_outside_unified_memory_land_after_the_queue pass on the RX 7900 XT (both verify non-UMA GPU timestamp / readback delivery after queue completion and rejection of unaligned/unwritable targets).
  • Retail title smoke run: 60 s run completes with 0 crashes and 0 device removals.

Regression run

xcl-smoke v1
commit: 4017f8ff8faaae6007fd83910d230a027dd85a33
gpu: AMD Radeon RX 7900 XT
title: GTA VI
seconds: 60
exit: 0x0
frames shown: 1195 (PresentX 1196)
presents per 2 s (last 3): 56 54 57
device removals: 0
crashes: 0
peak commit: 14950 MB
xcl-smoke v1
commit: 85d85b5d89de122c47cb9522fe191332f3129558
gpu: AMD Radeon RX 7900 XT
title: GTA VI
seconds: 60
exit: 0x0
frames shown: 1062 (PresentX 1062)
presents per 2 s (last 3): 53 51 53
device removals: 0
crashes: 0
peak commit: 14938 MB
xcl-smoke v1
commit: 44038872d944edb111772d0685f86d8de8808828
gpu: AMD Radeon RX 7900 XT
title: GTA VI
seconds: 60
exit: 0x0
frames shown: 1204 (PresentX 1204)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14925 MB

Not tested

  • NVIDIA / Intel GPUs and wave32-only adapters.
  • Other retail titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant).
  • The 60 s regression run above had the 4095 MB coherent window active so the title's timestamps landed in UMA during that run; the non-UMA readback path itself was exercised by the new GPU test (timestamps_outside_unified_memory_land_after_the_queue) and readback_u64_lands_after_the_queue.

AI use

  • Diagnosed the issue from the runtime logs, tests; all builds, tests, and smoke runs were executed locally on the hardware listed above.

@XaviFortes
XaviFortes marked this pull request as draft November 23, 2026 23:33
@XaviFortes
XaviFortes marked this pull request as ready for review November 23, 2026 23:35
@ethandepstein-del

Copy link
Copy Markdown

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.rs and list_x.rs as earlier open PR #311 (600f092, which also adds an end-to-end testtitle check and has an active thread on coordinating Write with #317).

That said, this PR handles three details cleaner than #311's current head:

Issues found in 85d85b5

  1. write_u64_now (cpu_writes.rs:79): m.Protect & (PAGE_READWRITE | PAGE_EXECUTE_READWRITE) == 0 does not exclude PAGE_GUARD (0x100), so a guarded RW page passes the check and faults on the worker thread; also prefer va.checked_add(8) over va + 8.
  2. readback_u64_lands_after_the_queue (cpu_writes.rs:107-111): Calls .unwrap()/.expect() when creating the DXGI factory / WARP device instead of calling skip_test("no GPU") as list_x.rs:303 does and CONTRIBUTING.md asks for GPU tests.
  3. AI use section: Does not name the AI tool/model if an AI tool was used (or state none).
  4. Shared with D3D12.X: GPU timestamps into the title's own memory land after the GPU #311 (minor): The 4096-slot NEXT_TIMESTAMP ring 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 #311 600f092) with Antigravity (Gemini 4 Neon).

Write64BitValueBottomOfPipeX and Write64BitValueTopOfPipeX with timestamp flags previously rejected any target address outside unified memory (for example, a title's own VirtualAlloc memory on a first run before the coherent window grows), even though non-timestamp writes already fall back to cpu_writes after the queue fence completes.

Resolve non-UMA timestamp queries into a lazily allocated, persistently mapped READBACK buffer per device (4096 slots, 32 KiB) and copy the 64-bit GPU tick atomically to the title's address in the cpu_writes worker once the submission's fence completes. Also separate the 8-byte alignment check from the unified-memory check so warnings report the actual reason.

Assisted-by: Antigravity (Gemini 4 Neon)
@regiumlepidi

Copy link
Copy Markdown

An NVIDIA run, which the description lists under Not tested: 85d85b5 merged onto current main db1ddb2 (clean merge): pass.

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves), driver 617.42 (32.0.16.1742); also with XCL_ADAPTER=radeon (the Ryzen 7 9800X3D's RDNA2 iGPU, driver 32.0.21030.2001)
  • Ryzen 7 9800X3D, 48 GB, Windows 11 Pro 25H2, rustc 1.100.0 MSVC, DXC from Windows SDK 10.0.26100, debug
  • .\scripts\test.ps1 (cargo test --workspace -- --test-threads=4), no XCL_SAMPLE_* set
Build default adapter (RTX 5070 Ti) XCL_ADAPTER=radeon
main db1ddb2 666 passed, 0 failed, 41 ignored 666 passed, 0 failed, 41 ignored
85d85b5 on db1ddb2 668 passed, 0 failed, 41 ignored 668 passed, 0 failed, 41 ignored
  • The two new tests create their device with D3D12CreateDevice(None, …), so they ran on the RTX 5070 Ti in both columns; XCL_ADAPTER only moves the recompiler's GPU tests.
  • Run alone 30 times each (--exact): readback_u64_lands_after_the_queue 0 of 30 failed, writes_land_after_the_queue 0 of 30 failed. The readback value lands as one AtomicU64 store and the test waits for the whole value, so it does not have the torn-read race described on D3D12.X: GPU timestamps into the title's own memory land after the GPU #311, where the same kind of test run alone fails every time on this machine.

Not tested

  • scripts/smoke.ps1 on a real title (I have none).
  • Intel.

This PR, #311 and #317 all reshape cpu_writes::Write and 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
XaviFortes force-pushed the d3d12x-non-uma-timestamps branch from 85d85b5 to 4403887 Compare November 23, 2026 23:50
@XaviFortes

Copy link
Copy Markdown
Contributor Author

Thanks for the audit! Fixed those in 4403887:

  • write_u64_now now excludes PAGE_GUARD and uses checked_add(8)
  • readback_u64_lands_after_the_queue calls skip_test("no GPU") instead of unwrapping
  • Updated the PR description with a fresh smoke run on 4403887

Didn't catch #311 before opening this — I'll leave it open if the atomic 64-bit write / _buf / LISTS check is useful.

@ivall

ivall commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Merged (a6f5f7a). Checked on an RX 9070 (RDNA4) on main a6f5f7a, 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

PHeitor1 commented Nov 24, 2026 •

Copy link
Copy Markdown

Tested 4403887 merged onto main 3516080.

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, no XCL_SAMPLE_*.

Pass: 672 passed, 0 failed, 41 ignored. SKIPPED: only the 2 no wave64 tests (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).

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.

5 participants