Skip to content

[upstream #1044] D3D12.X: read back sparse-window Wait64BitValueX counters during CPU waits - #104

Closed
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1044
Closed

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1044

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

When a Wait32/64BitValueX falls back to CPU polling (PendingWait::wait_until_satisfied) for a counter inside a sparse VRAM window, CPU memory only holds the last uploaded/copied-back value while GPU writes live in sparse VRAM. This reads back [va, va + width) from sparse VRAM (sparse::readback_now) before spinning and at 10 ms intervals during the sleep loop (plus a final readback on timeout). Addresses item #2 measured in #505 (and keeps coherent-window / heap addresses lock-free on the fast path via uma::is_sparse). Part of xcl-dev#505.

What is in it

  • crates/xcl/src/hle/d3d12x/sparse.rs:
    • sparse::contains(va): checks gpu::uma::get().is_some_and(|u| u.is_sparse(va)) before taking STATE to verify an active sparse window covers va.
  • crates/xcl/src/hle/d3d12x/list_x.rs:
    • PendingWait::wait_until_satisfied / wait_until_satisfied_with: preserves the zero-overhead fast path when CPU memory already satisfies the wait; for unsatisfied sparse-window addresses, runs sparse::readback_now(va, width) before spinning, throttled at 10 ms intervals while polling, and once on timeout expiry.
    • Unit test pending_wait_sparse_readback_pulls_gpu_writes_and_skips_coherent verifying coherent waits never call readback and sparse waits pull delayed writes cleanly.
    • GPU test pending_wait_reads_back_gpu_write_in_sparse_window verifying a real CopyBufferRegion into a sparse window buffer (invisible to CPU-only polling) is read back and satisfies PendingWait::wait_until_satisfied.

Tested

  • GPU: NVIDIA GeForce RTX 3060 Ti (8024 MiB VRAM, driver 32.0.16.1088, 32-lane waves); CPU: Intel Core i5-12400F; 16 GB RAM; Windows 11 Pro Build 22631; Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug (scripts/test.ps1) and release (cargo build --release -p xcl).
  • cargo test --workspace -- --test-threads=4 (scripts/test.ps1): 729 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 (no wave64: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware)).
  • cargo test -p xcl --lib pending_wait_ -- --test-threads=4: 3 passed, 0 failed (run 3 consecutive times with 0 flakes). In pending_wait_reads_back_gpu_write_in_sparse_window, CPU-only polling (wait_until_satisfied_with(..., false, ...)) fails on the real GPU sparse-VRAM write before wait_until_satisfied passes with sparse readback enabled.

Regression run
main:

xcl-smoke v1
commit: 6efdabcdaac93ce5cc123a85e85deba5d49cb294
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1508 (PresentX 1509)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 10406 MB

PR:

xcl-smoke v1
commit: 8fd59213003554c868d6b8729ecdb1fb7d09a77c
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1554 (PresentX 1554)
presents per 2 s (last 3): 61 59 61
device removals: 0
crashes: 0
peak commit: 10404 MB

Not tested

  • AMD GPUs / wave64 paths and Linux / Wine + vkd3d-proton.
  • A retail title phase where a CPU-fallback Wait64BitValueX counter explicitly lands in a sparse window on main (not yet triggered during our 60 s retail smoke run).

AI use

  • Antigravity (Google DeepMind; exact model identifier not exposed in environment) analyzed #505 and the D3D12.X sync/sparse implementation, wrote the fix and tests, and ran the test suite and retail smoke runs.

Mirror of xcl-dev#1044 (auto-synced, do not edit).

@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#1044 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/1044 branch November 25, 2026 00:10
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