Skip to content

D3D12.X: honour OS QPC timestamp flags and atomic 64-bit CPU writes (#103) - #317

Open
Michael-Glaser wants to merge 1 commit into
xcl-dev:mainfrom
Michael-Glaser:fix/d3d12x-os-qpc-timestamps
Open

Michael-Glaser wants to merge 1 commit into
xcl-dev:mainfrom
Michael-Glaser:fix/d3d12x-os-qpc-timestamps

Conversation

@Michael-Glaser

Copy link
Copy Markdown

Part of #103. Write64BitValueBottomOfPipeX (0x2) and Write64BitValueTopOfPipeX (0x8) routed OS QPC timestamps to GPU timestamp queries; cpu_writes also split 64-bit stores into two 32-bit writes and did not reject PAGE_GUARD.

What is in it

  • crates/xcl/src/hle/d3d12x/{cpu_writes.rs, list_x.rs, real.rs}: split GPU vs OS timestamp flags (classify_write64), stamp top/bottom OS QPC timestamps via cpu_writes with AtomicU64, reject PAGE_GUARD, and add unit tests.

Tested

  • Cross-checked on macOS (aarch64-apple-darwin, Rust 1.100.0): cargo check --offline --target x86_64-pc-windows-msvc --workspace --tests (0 errors, 0 new warnings).

Not tested

  • Not built or executed on Windows; cargo test, GPU tests, and scripts/smoke.ps1 not run yet.

AI use

  • Antigravity with Gemini 4 Neon (audit, fix, unit tests, description).

@regiumlepidi

Copy link
Copy Markdown

A Windows run for this draft, since the description has none yet: adddae9 merged onto current main 85bdf21 (clean merge, real.rs auto-merged): builds and passes on both adapters.

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB, driver 617.42 (32.0.16.1742), and AMD Radeon(TM) Graphics (Ryzen 7 9800X3D iGPU, RDNA2), driver 32.0.21030.2001, selected with XCL_ADAPTER=radeon
  • 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 RTX 5070 Ti RDNA2 iGPU
main 85bdf21 665 passed, 0 failed, 41 ignored 665 passed, 0 failed, 41 ignored
adddae9 on 85bdf21 667 passed, 0 failed, 41 ignored 667 passed, 0 failed, 41 ignored

GPU tests skipped: the usual 2 (no wave64) on NVIDIA, none on the iGPU.

The cpu_writes tests run alone, 50 times each (--exact): writes_land_after_the_queue 0 of 50 failed, os_timestamp_writes_qpc_and_writable_rejects_page_guard 0 of 50 failed. That matters here because on main / #311 the same test waits only for the first of two dword stores; on #311 run alone it fails every time on this machine (details in #311). With this PR's single AtomicU64 store the race is gone.

Not tested

  • scripts/smoke.ps1 on a real title (I have none), so nothing on the QPC-flag path at run time.
  • Whether a title writes a 64-bit value to an address that is not 8-byte aligned, which write_now now skips.

AI use: Claude Code with Claude Opus 5.5 ran the build and tests and wrote this comment; the numbers come from those runs.

@Michael-Glaser

Copy link
Copy Markdown
Author

Thanks @regiumlepidi! Rebased onto main (a6f5f7a, commit d87aa07), keeping 4403887's ReadbackU64 GPU timestamp path intact alongside the OS QPC timestamp flags and AtomicU64 / PAGE_GUARD fixes.

@WebIdentity1

WebIdentity1 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Independent Windows validation of current head d87aa071287e4a8cd5f4a068d3b791e01c7052c7, cleanly integrated with main 508a0c74d7c0625d6d2de8d24494e69dc2e1926f (tree 7126b9600b4ebdf0274f934956032f24d92aa83a; no additional runtime changes).

Tested

  • Windows 10 Home 19045, Ryzen 7 7800X3D, RTX 3090 driver 591.74 and AMD Radeon integrated graphics driver 32.0.21030.2001. Rust 1.98.1 MSVC, debug build, SDK DXC 1.8.2502.11, public Agility 1.620.2.
  • cargo build --locked --workspace: exit 0. Interactive desktop session, then cargo test --locked --workspace --no-fail-fast -- --test-threads=4 --show-output: 681 passed / 1 failed / 41 ignored across workspace targets. The sole failure is gpu_clamp_and_omod_per_instruction, also present on the same main baseline (679 passed / 1 failed / 41 ignored); Recompiler: complete remaining RDNA2 integer CLAMP=1 saturation (#105) #202 addresses it. The CPU-write fixtures passed in this run. This is not a clean-suite claim or proof that intermittent failures are eliminated.
  • Focused command: cargo test --locked -p xcl --lib -- cpu_writes::tests:: timestamps_outside_unified_memory_land_after_the_queue write64_os_timestamp_flags_route_to_qpc_instead_of_gpu_timestamps --nocapture --test-threads=1: 5 passed / 0 failed / 0 ignored, 658 filtered out, no skips. Covers QPC/PAGE_GUARD, atomic writes, preserved ReadbackU64, command-list timestamp readback, and flag routing.
  • Adapter caveat: these fixtures call D3D12CreateDevice(None) and do not honor XCL_ADAPTER. A separate test-only diagnostic overlay queried the actual device LUID: all four GPU fixtures used AMD integrated graphics and passed (5/0/0 including the CPU-only flag test). A second local test-only overlay selected and asserted RTX 3090 for those four devices: 5/0/0, no skips. No runtime code changed in either diagnostic run; these overlays are not part of the reported full-suite tree.
  • Full-suite explicit skips: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no wave64 on selected NVIDIA adapter); test_title_draws_with_a_root_signature_under_the_debug_layer and uploads_start_from_each_subresources_state (missing D3D12 debug layer). These early returns are included in Rust's pass counts, not coverage. Sample-data tests had no XCL_SAMPLE_* inputs; system XGameRuntime comparison also skipped without its DLL.

Not tested
Retail-title smoke/regression runs, gameplay, console hardware, and sustained stress. Full-suite fixtures use mixed adapters; this is not a claim that every fixture ran on NVIDIA. Local source snapshots, integration patch, diagnostic overlays, hashes and logs retained. This complements the earlier adddae9 report; it does not replace the required retail evidence.

AI use
Codex (GPT-6) inspected the integration, prepared test-only adapter diagnostics, executed the native Windows runs and prepared this report.

Integration follow-up: tested together with #562 on current main 9ce2070. Six focused tests pass on verified AMD and RTX3090 devices; the shared-worker negative control fails queue independence on both without device removal. Serial workspace: main 683/1/41, integration 686/1/41, same CLAMP failure. Report and tested resolution branch. This is a separately modified integration, not a replacement for the exact-head results above; parallel isolation and retail smoke remain unverified.

@iggyvilla

Copy link
Copy Markdown
Collaborator

A run-time data point on the path this PR changes, from a retail title on main 9ce2070. We did not run this PR.

Measured

  • The title calls Write64BitValueBottomOfPipeX with a timestamp flag into its own memory, outside unified memory. On a cold address space (game files on a hard drive, after the account prompt) the cpu_writes::writable check in timestamp() (list_x.rs:1169) was 18.5 % of the render thread's samples, all of it in NtQueryVirtualMemory. Each timestamp makes one VirtualQuery there.
  • That thread was at a full core and 24 fps (20 s, 4,422 samples). The rest of its time was the same kind of check on vertex and index buffer binds (details in D3D12.X: the write-watch look scans 1.5 GiB before every submit while 4 pages are written (measurement and plan) #582).

What it means for this PR (read from the diff, not measured)

  • os_timestamp calls writable for every OS timestamp, also when the destination is in unified memory. timestamp() on main checks uma_window_buffer first and skips VirtualQuery for those addresses.
  • Each OS timestamp then makes a second VirtualQuery when it is written (write_now). For top-of-pipe timestamps that runs in cpu_writes_before, on the thread that submits.
  • We do not know whether this title sets bit 0 (GPU) or bit 1 (OS) of the flags. If it sets bit 1, the PR moves the 18.5 % to os_timestamp and adds a second walk per timestamp. Checking uma_window_buffer first, as timestamp() does, would at least keep unified-memory destinations off that path.

Tested

  • AMD Radeon RX 6650 XT 8 GB (driver 32.0.21045.29003), Ryzen 7 5700X, 32 GB, Windows 11 26H2 (26300), release build of 9ce2070 with local counters in title_textures.rs (not in any PR), XCL_NETWORK=0. Profile with a stack sampler of our own, symbols from the build's PDB.

Not tested

  • This PR's head (d87aa07), at build time or at run time. Which timestamp flag the title uses. NVIDIA.

AI use

  • Claude Code agents (Claude Opus 5.5) ran the measurement and wrote this comment.

…vall#103)

Write64BitValueBottomOfPipeX (flags 0x2) and Write64BitValueTopOfPipeX (flags 0x8) routed OS QPC timestamp requests to GPU timestamp queries (wrong clock domain/frequency and dropped on copy lists). cpu_writes also split immediate 64-bit stores into two 32-bit AtomicU32 stores, did not exclude PAGE_GUARD, and called VirtualQuery even for committed coherent UMA addresses.

Split GPU vs OS timestamp flag bits explicitly (classify_write64), keep the existing GPU readback path for GPU timestamps, write top-of-pipe OS QPC timestamps right before ExecuteCommandLists / KickoffX and bottom-of-pipe OS QPC timestamps via cpu_writes after GPU fence completion, store 64-bit values atomically via AtomicU64, fast-path committed coherent UMA windows via Uma::in_committed_window to avoid VirtualQuery, and reject PAGE_GUARD / overflowing ranges in cpu_writes.

Assisted-by: Antigravity (Gemini 4 Neon)
@Michael-Glaser
Michael-Glaser force-pushed the fix/d3d12x-os-qpc-timestamps branch from d87aa07 to f6d072d Compare November 24, 2026 13:50
@Michael-Glaser

Copy link
Copy Markdown
Author

Thanks @WebIdentity1 and @iggyvilla! Rebased onto main (47efa2e, commit f6d072d) to resolve the merge conflict with the wait64 mid-list split changes, preserving the LATE timeout log and split-segment state clearing.

Also addressed @iggyvilla's VirtualQuery profiling point: both cpu_writes::writable and cpu_writes::write_now now fast-path committed coherent UMA windows via Uma::in_committed_window, keeping UMA OS timestamps off VirtualQuery completely (and os_timestamp no longer adds CPU-written destinations to GPU sparse_writes). Cross-checked on macOS against x86_64-pc-windows-msvc (--workspace --tests); Windows runtime not re-run locally.

@CuteBooty

Copy link
Copy Markdown

Regression run on a retail title for f6d072d: pass (no device removal, no crash, frames and peak commit within the check's limits).

Tested

  • RTX 3070 8 GB (32-lane waves), NVIDIA 621.24; Ryzen 5 3600, 32 GB; Windows 11 Pro 26200; rustc 1.100.0 MSVC; release build.
  • scripts\smoke.ps1 -Game <folder> -Seconds 60, no input, on this PR's head as it is and on main 47efa2e, the commit it branches from, each from a clean checkout. Each build ran twice back to back; the blocks are the second runs. The main block is shared with my reports on other PRs of the same base.

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 3070
title: game
seconds: 60
exit: 0x0
frames shown: 1446 (PresentX 1446)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19285 MB

this PR:

xcl-smoke v1
commit: f6d072da67b2f6b1ca67ffaa30ea47e3a60e728b
gpu: NVIDIA GeForce RTX 3070
title: game
seconds: 60
exit: 0x0
frames shown: 1512 (PresentX 1512)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19432 MB

Not tested

  • Whether the 60 s reach the code this PR changes, the world load, the test suite, current main merged in, AMD and Intel GPUs.

AI use

  • Claude Code (Claude Opus 5.5) made the runs with me present and wrote this from the script's output.

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