Skip to content

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

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

Michael-Glaser wants to merge 1 commit into
ivall: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.

…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 and did not exclude PAGE_GUARD in write_now / writable.

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, 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 adddae9 to d87aa07 Compare November 24, 2026 00:16
@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.

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.

2 participants