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

Manually merged
github merged 1 commit from gh-pr/330/head into gh-pr/330/base 2026-11-26 04:20:12 +00:00
Owner

@⁠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 UTC

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: ea3b5e4d
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: ea3b5e4d
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: ea3b5e4d
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** on GitHub · 2026-11-23 23:31 UTC · [original](https://github.com/xcl-dev/xcl/pull/330) `XaviFortes:d3d12x-non-uma-timestamps` → `main` · +253 −25 · 2 files · 1 commits · merged 2026-11-24 00:03 UTC `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: ea3b5e4d 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: ea3b5e4d 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: ea3b5e4d 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.
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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:20:11 +00:00
github manually merged commit 44038872d9 into gh-pr/330/base 2026-11-26 04:20:12 +00:00
Author
Owner

@⁠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.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:

  • Uses a single AtomicU64::store(..., Release) in write_u64_now (avoiding the torn 2×32-bit write race reproduced on #311).
  • Keeps _buf: ID3D12Resource alive inside Write::ReadbackU64.
  • Checks that list is tracked in LISTS before emitting EndQuery / ResolveQueryData.

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 #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).

**@⁠mastrr9** on GitHub · 2026-11-23 23:38 UTC · [original](https://github.com/xcl-dev/xcl/pull/330#issuecomment-7117196397) 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: - Uses a single `AtomicU64::store(..., Release)` in `write_u64_now` (avoiding the torn 2×32-bit write race reproduced on #311). - Keeps `_buf: ID3D12Resource` alive inside `Write::ReadbackU64`. - Checks that `list` is tracked in `LISTS` before emitting `EndQuery` / `ResolveQueryData`. ### 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 #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).*
Author
Owner

@⁠regiumlepidi on GitHub · 2026-11-23 23:45 UTC · original

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 #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.

**@⁠regiumlepidi** on GitHub · 2026-11-23 23:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/330#issuecomment-7117322055) 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 #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.
Author
Owner

@⁠XaviFortes on GitHub · 2026-11-23 23:55 UTC · original

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.

**@⁠XaviFortes** on GitHub · 2026-11-23 23:55 UTC · [original](https://github.com/xcl-dev/xcl/pull/330#issuecomment-7117518139) 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.
Author
Owner

@⁠ivall on GitHub · 2026-11-24 00:03 UTC · original

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).

**@⁠ivall** on GitHub · 2026-11-24 00:03 UTC · [original](https://github.com/xcl-dev/xcl/pull/330#issuecomment-7117662206) 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).
Author
Owner

@⁠PHeitor1 on GitHub · 2026-11-24 00:13 UTC · original

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).

**@⁠PHeitor1** on GitHub · 2026-11-24 00:13 UTC · [original](https://github.com/xcl-dev/xcl/pull/330#issuecomment-7117845634) 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)._
This discussion has been locked. Commenting is limited to contributors.
No description provided.