Skip to content

D3D12.X: track Write64 fence highs and keep the sync watchdog awake after CPU releases - #1429

Open
gridoe wants to merge 1 commit into
xcl-dev:mainfrom
gridoe:sync-watchdog-rewind-guard
Open

gridoe wants to merge 1 commit into
xcl-dev:mainfrom
gridoe:sync-watchdog-rewind-guard

Conversation

@gridoe

@gridoe gridoe commented Nov 24, 2026 •

Copy link
Copy Markdown

On native Windows D3D12, an older in-flight GPU queue.Signal(&fence, v - 1) on a slower queue can retire after a higher GPU completion or a CPU fence.Signal(v) (from a cycle-break or watchdog release) and rewind ID3D12Fence::GetCompletedValue() backwards. Two gaps in list_x.rs let those rewinds stick and stall later queue.Wait calls:

  1. prune_completed_waits did not track the highest observed GetCompletedValue() on a SyncCell or restore a fence that dropped below cpu_signaled_max.max(highest_completed).
  2. When a CPU cycle-break or watchdog release cleared the last pending wait, ARMED_GPU_WAITS dropped to 0 and xcl-sync-watchdog went straight back to cv.wait, so an older in-flight GPU Signal retiring milliseconds later rewound the fence with nothing awake to restore it.

This change records SyncCell::highest_completed, restores rewound fences in prune_completed_waits, and adds a short REWIND_GUARD_UNTIL window (10 s, polling at 20 ms while ARMED_GPU_WAITS == 0) armed whenever a CPU release or rewind repair occurs so xcl-sync-watchdog catches post-release GPU rewinds.

What is in it

  • crates/xcl/src/hle/d3d12x/list_x.rs: track SyncCell::highest_completed, detect/restore fence rewinds in prune_completed_waits, add REWIND_GUARD_UNTIL / arm_rewind_guard / rewind_guard_active for xcl-sync-watchdog, and add sync_watchdog_and_prune_repair_fence_rewind_with_zero_armed_waits.

Tested

  • Hardware / OS / toolchain: NVIDIA GeForce RTX 3080 (10053 MiB VRAM, driver 617.42, wave32), AMD Ryzen 7 5700X3D (16 logical CPUs), 32 GB RAM, Windows 11 IoT Enterprise LTSC 2024 26H2 (Build 26300.9974), DXC 1.9.2602.17, rustc 1.99.1 (58cf8f9c3 2026-10-13) (stable-x86_64-pc-windows-msvc), debug (tests) and release (smoke).
  • Rebased onto main (9633138) as dd5ea20: cargo +stable-x86_64-pc-windows-msvc test -p xcl --lib hle::d3d12x::list_x::tests — 35 passed, 0 failed (including sync_watchdog_and_prune_repair_fence_rewind_with_zero_armed_waits); cargo +stable-x86_64-pc-windows-msvc build --release -p xcl clean.
  • Original head 3ea5ef4: cargo +stable-x86_64-pc-windows-msvc test --workspace -- --test-threads=4: 752 passed, 0 failed, 41 ignored (SKIPPED on this adapter: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, test_title_draws_with_a_root_signature_under_the_debug_layer, uploads_start_from_each_subresources_state).
  • Retail title (<game folder>): 60 s regression run below; in longer bring-up runs past the opening title card on this machine, multi-queue Write64 rewinds (0x6df -> 0x6de, 0x6e1 -> 0x6e0, 0x795 -> 0x794) were caught and repaired, cutting GPU queue.Wait timeouts from 166 to 0 in the compared run.

Regression run

main:

xcl-smoke v1
commit: 9aec53df7004bd9018ef3df67532f85d66ee261c
gpu: NVIDIA GeForce RTX 3080
title: d2d324b7
seconds: 60
exit: 0x0
frames shown: 1581 (PresentX 1581)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17039 MB

PR:

xcl-smoke v1
commit: b14487f442d91f33e8640bddfc91fe1eb1261773
gpu: NVIDIA GeForce RTX 3080
title: d2d324b7
seconds: 60
exit: 0x0
frames shown: 1441 (PresentX 1441)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15182 MB

Not tested

  • AMD / Intel GPUs, native wave64 hardware, D3D12 debug layer (d3d12SDKLayers.dll not installed), Wine / vkd3d-proton.
  • Other retail titles and sample-data tests requiring XCL_SAMPLE_* env vars.
  • The 60 s smoke run stays on the menu where multi-queue Write64 rewinds do not occur; the zero-armed-waits rewind repair path is covered directly by the unit test and by longer local bring-up runs.

AI use

  • Antigravity with Gemini 4 Neon: helped diagnose the post-release rewind from logs/minidumps, wrote the fix, unit test, rebase resolution, and PR description; all builds, tests, and smoke runs were executed locally on the hardware listed above.

@futurepro62

futurepro62 commented Nov 24, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 3ea5ef4 (on its base 930e8b4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 752 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: sync_watchdog_and_prune_repair_fence_rewind_with_zero_armed_waits.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 752 passed, 0 failed, 41 ignored, no skips.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…#1395 in-place vtables

Integrates 16 upstream PRs (xcl-dev#1380, xcl-dev#1383, xcl-dev#1384, xcl-dev#1395, xcl-dev#1398, xcl-dev#1400,
xcl-dev#1404, xcl-dev#1405, xcl-dev#1419, xcl-dev#1420, xcl-dev#1421, xcl-dev#1423, xcl-dev#1424, xcl-dev#1427, xcl-dev#1428, xcl-dev#1429)
on top of the Linux/Proton fork, plus three Proton/vkd3d-proton fixes
caught during verification:
- Recompiler (xcl-dev#1428): flatten IO_GROUP_LIMIT early-return in compute
  shaders so vkd3d-proton v3.1 dxil-spirv accepts the emitted CFG.
- D3D12.X (xcl-dev#1395 + xcl-dev#867): skip UnadoptGuard on in-place-patched vtables
  and restore native vtables in runner::submit_list when a prior test
  adopted the singleton ID3D12Device.
- Tests: match Wine centered default in window_position_modes.

Verified under GE-Proton11-14 (RX 9060 XT / RADV):
- gpu_sparse_vram_descriptors_buffers_and_xmem + gpu_valu_float_and_int
  + window_position_modes: 3 passed, 0 failed
- Broad sweep (present, real, sparse, clamp, dstorage, gpu_valu,
  gpu_typed_buffer): 82 passed, 0 failed, 1 ignored, 0 skipped
- 2.5 min retail title run (XCL_MEM_LIMIT=12G): 3,000+ frames at 30.0
  fps, 6.0-6.1 GB flat committed RAM, 6.4 GB local VRAM, 0 DS failures.
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

@gut0to gut0to left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted review; I checked the guard lifetime against the D3D12 queue ordering described in the PR.

static QUEUE_IDS: Mutex<Vec<usize>> = Mutex::new(Vec::new());

fn arm_rewind_guard() {
let until = Instant::now() + Duration::from_secs(10);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rewind guard expires after 10 seconds, but a queued ID3D12CommandQueue::Signal has no completion deadline: it can remain behind stalled or long-running work and retire after this window. Once the guard expires with no armed waits, the watchdog returns to cv.wait, so that late lower signal can rewind the fence without repair until some later event happens to wake the watchdog. Could the guard remain active while older signals are in flight, or otherwise track their completion rather than use a fixed timeout? AI-assisted review; I verified the fixed window and idle branch.

@gridoe

gridoe commented Nov 25, 2026

Copy link
Copy Markdown
Author

Rebased onto current main (9633138) as dd5ea20, resolving the two additive conflicts in crates/xcl/src/hle/d3d12x/list_x.rs alongside #1926, #2078, and #2163.

Tested

  • Hardware / OS / toolchain: NVIDIA GeForce RTX 3080 (driver 617.42, wave32), AMD Ryzen 7 5700X3D, Windows 11 IoT Enterprise LTSC 2024 26H2 (Build 26300.9974), rustc 1.99.1 (stable-x86_64-pc-windows-msvc).
  • cargo +stable-x86_64-pc-windows-msvc test -p xcl --lib hle::d3d12x::list_x::tests — 35 passed, 0 failed (including sync_watchdog_and_prune_repair_fence_rewind_with_zero_armed_waits, sync_watchdog_pair_is_set_before_the_thread_starts, and cpu_cycle_break_publishes_value_to_title_memory_and_keeps_it_monotonic).
  • cargo +stable-x86_64-pc-windows-msvc test -p xcl --lib -- --test-threads=4 — 1,173 passed, 2 unrelated pre-existing failures on main 9633138 (gpu::recomp::pso::shader_cache_tests::rerouted_disk_entries_follow_the_direct_translator and hle::d3d12x::device_x::tests::pc_resource_desc_strips_uav_on_unsupported_formats_and_msaa), 26 ignored.

AI use: Rebase conflict resolution and test verification assisted by Antigravity with Gemini 4 Neon.

@ClosetPie107

ClosetPie107 commented Nov 25, 2026 •

Copy link
Copy Markdown

Update for head b14487f4 (earlier results for dd5ea20 below)

Same RX 9070 / RADV / Proton Experimental machine, patched vkd3d-proton (master ec207194 without the allocator / command-list lpVtbl checks), Rust 1.96.0, x86_64-pc-windows-gnu. Head merged onto main 83b00818, test commit ff73a5f9.

Tests (debug, XCL_REQUIRE_GPU=wave64, --test-threads=1)

  • hle::d3d12x::list_x::: 41 passed, 0 failed (main: 40 passed, 0 failed), including sync_watchdog_and_prune_repair_fence_rewind_with_zero_armed_waits
  • cargo test --workspace --no-fail-fast -- --test-threads=4, lib binary: 1322 passed, 8 failed, 27 ignored (main the same run: 1320 passed, 9 failed, 27 ignored). The failures are all among main's.

Retail title, 300 s (release, every run from a copy of the same warm-cache snapshot; XCL_DIRECT_DXIL=1 XCL_PREPARE=1 XCL_PSO_PRELOAD=1 XCL_PSO_WAIT_MS=50 XCL_TEXTURE_LEVEL_PAGES=1 XCL_COHERENT_MB=1024 VKD3D_CONFIG=ignore_shared_fence, A pressed every 10 s)

  • 3 runs: 2 clean (exit 0, 2,018 and 1,875 presents). 1 ended with 0xc0000005 in the title (game_scarlett_master.exe+0x23cf683, a write at address 0) at 305.7 s, after the 300 s, while the title was being stopped; it had 2,046 presents. main, 4 runs: all clean, 1,892–2,122. It is not this PR's: the same crash (same offset, a write at address 0) happened in 16 earlier runs on this machine on trees without this PR (11-24 and 11-26, at ~110–130 s), and on [OFFICIAL] Swarm: ports from other GPL-3.0 projects into XCL #3011 a skip file of the title's ray-tracing programs is reported to remove it.

Not tested

  • Native Windows, NVIDIA/Intel
  • A fence rewind on this machine (the log shows none)

AI use

  • Claude Code (Claude Opus 5.5) wrote the test scripts, ran the tests and runs on this machine and wrote this update.

Linux / AMD RDNA4 (RADV) test report for head dd5ea20 merged locally onto main 1a0bbe3 (clean merge).

Environment

  • AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1, native wave64), Ryzen 5 9600X, 30 GiB RAM, CachyOS
  • Proton Experimental (experimental-11.0-20261112), vkd3d-proton v3.1 (#257 + dxil-spirv master 694cc674), DXVK v3.1.1-209, DXC 1.9.2609.5, x86_64-pc-windows-gnu cross-compile

Tested (debug test binary under Wine, XCL_ADAPTER=9070 XCL_REQUIRE_GPU=wave64, --test-threads=1 --nocapture)

  • hle::d3d12x::list_x: 35 passed, 0 failed, 0 ignored, 0 skipped (0.34 s), including sync_watchdog_and_prune_repair_fence_rewind_with_zero_armed_waits.
  • hle::d3d12x::real: 56 passed, 0 failed, 0 ignored, 0 skipped.

Not tested: full workspace suite, retail title run, native Windows.

AI use: T3 Code / Antigravity (Gemini 4 Neon) merged, built, ran the tests on this machine, and drafted this report.

@gridoe
gridoe force-pushed the sync-watchdog-rewind-guard branch from dd5ea20 to b14487f Compare November 25, 2026 17:39
@gridoe

gridoe commented Nov 25, 2026

Copy link
Copy Markdown
Author

Rebased onto current main (68a284a) as b14487f, resolving the additive test conflict at the end of crates/xcl/src/hle/d3d12x/list_x.rs.

Tested

  • Hardware / OS / toolchain: NVIDIA GeForce RTX 3080 (driver 617.42, wave32), AMD Ryzen 7 5700X3D, Windows 11 IoT Enterprise LTSC 2024 26H2 (Build 26300.9974), rustc 1.99.1 (stable-x86_64-pc-windows-msvc).
  • cargo +stable-x86_64-pc-windows-msvc test -p xcl --lib hle::d3d12x::list_x::tests — 37 passed, 0 failed (0.63 s), including sync_watchdog_and_prune_repair_fence_rewind_with_zero_armed_waits, sync_watchdog_pair_is_set_before_the_thread_starts, and cpu_cycle_break_publishes_value_to_title_memory_and_keeps_it_monotonic.

AI use: Rebase conflict resolution and test verification assisted by Antigravity with Gemini 4 Neon.

@DavidM1911

Copy link
Copy Markdown
Contributor

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

@pickles976

Copy link
Copy Markdown

Wine/NVIDIA verification of exact head b14487f442d91f33e8640bddfc91fe1eb1261773:

  • Linux 6.17, Wine 11.0, RTX 4060 Laptop GPU / NVIDIA 590.48.1, Rust 1.98.1, x86_64-pc-windows-msvc, DXVK_CONFIG='dxgi.hideNvidiaGpu = False'.
  • Diagnostic vkd3d-proton 3.2.0 build 2576c0b4adfae4a+ (two local console-vtable assertion relaxations used throughout this lab; not stock-vkd3d certification).
  • Fresh intended-worktree compilation confirmed: Compiling xcl v0.1.0 (.../xcl-pr1429/crates/xcl).
  • Command: cargo test --locked --target x86_64-pc-windows-msvc -p xcl --lib sync_watchdog_and_prune_repair_fence_rewind_with_zero_armed_waits -- --nocapture --test-threads=1 through the Wine wrapper, with a 9 GiB memory / 512 MiB swap scope.
  • Result: 1 passed, 0 failed, 0 ignored in 0.76 s. The physical NVIDIA adapter opened. The log observed and repaired both synthetic rewinds: 0x7 -> 0x4 and 0xa -> 0x9.

This closes the PR's listed Wine/vkd3d test gap for the focused rewind fixture only. No title was launched, and this does not establish correction of our separately observed Game-Init cpu_writes legacy fallback (fence at 0, wanted 1).

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head b14487f

No open or merged PR makes the same change: #906 handles rewinds of the fence_x.rs completed-value mirrors, and #2499 (merged) only fixed the watchdog's lost wake-up; neither tracks a highest_completed floor per Write64 cell or keeps the watchdog polling after a CPU release.
The PR conflicts with main: wake_sync_watchdog now sleeps through sync_watchdog_sleep_if_idle (#2499), so the REWIND_GUARD_UNTIL check has to move into that helper's idle condition when rebasing.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants