Skip to content

D3D12.X: wait_for ignores stale signals on the reusable sparse fence event - #1419

Closed
gridoe wants to merge 1 commit into
xcl-dev:mainfrom
gridoe:sparse-wait-stale-event
Closed

gridoe wants to merge 1 commit into
xcl-dev:mainfrom
gridoe:sparse-wait-stale-event

Conversation

@gridoe

@gridoe gridoe commented Nov 24, 2026 •

Copy link
Copy Markdown

sparse::State::wait_for reuses a single auto-reset Win32 event (self.event) across waits on self.fence, calling SetEventOnCompletion(target, self.event) followed by one WaitForSingleObject(self.event, 5000). If an earlier wait times out at 5 s and its pending SetEventOnCompletion(old_target, self.event) completes afterwards, self.event stays signalled (or fires mid-wait during a later call). Every subsequent wait_for(newer_target) then returns in under 1 ms before self.fence actually reaches newer_target, letting begin_slot reset an in-flight command allocator and readback_after_execute copy from staging before the GPU copy finishes.

This change extracts a small wait_fence_until helper that calls ResetEvent(event) before SetEventOnCompletion and loops WaitForSingleObject against the remaining deadline until fence.GetCompletedValue() >= target.

What is in it

  • crates/xcl/src/hle/d3d12x/sparse.rs: add wait_fence_until, switch State::wait_for to call it, and add wait_fence_until_ignores_stale_event_signal covering both an already-signalled event and an earlier pending SetEventOnCompletion firing mid-wait.

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).
  • cargo +stable-x86_64-pc-windows-msvc build --workspace and cargo +stable-x86_64-pc-windows-msvc test --workspace -- --test-threads=4: 725 passed, 0 failed, 41 ignored (including hle::d3d12x::sparse::tests::wait_fence_until_ignores_stale_event_signal).
  • SKIPPED GPU/D3D12 tests on this adapter:
    • gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask (no wave64)
    • gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64)
    • test_title_draws_with_a_root_signature_under_the_debug_layer (no d3d12SDKLayers.dll)
    • uploads_start_from_each_subresources_state (no D3D12 debug layer (0x887A002D))
  • Retail title (<game folder>): 60 s regression run below; in longer bring-up runs past menus on this machine, once a single 5 s sparse wait timed out, wait_for previously logged 51 back-to-back ~1 ms timeouts before crashing in readback, and dropped to 0 after this fix.

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: 3861d2e2b561482933c657802cc5801b28bc60ba
gpu: NVIDIA GeForce RTX 3080
title: d2d324b7
seconds: 60
exit: 0x0
frames shown: 1585 (PresentX 1586)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17312 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 wait_for does not time out; the stale-event timeout 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 1 ms timeout cascade from logs, wrote the wait_fence_until helper, unit test, 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 3861d2e (on its base 9aec53d).

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: 725 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: wait_fence_until_ignores_stale_event_signal.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), full suite: one failure, 2 of 2 runs: readback_routing_tests::coherent_buffer_sanitizes_console_flags_and_state, at real.rs:5463, assert_ne!(VirtualFree(mem, 0, MEM_RELEASE), 0) (the release of the OpenExistingHeapFromAddress memory fails after the heap is dropped). 683 passed before cargo stopped.
  • I'm not sure this PR causes it, but the pattern points at it: a full Radeon run of main 930e8b4 right after passes (751 passed, 0 failed), and the test passed in all ~70 other full Radeon runs of other PRs I did today. Run on its own, it passes 5 of 5 on both this head and main. So it shows up only next to the other lib tests with this change in.

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.

anoyarou added a commit to anoyarou/xcl that referenced this pull request Nov 24, 2026
…d harden compute/sparse paths

- crates/xcl/src/hle/d3d12x/pso_async.rs (fixes 1 MiB thread stack overflow / deadlock seen alongside ivall#611):
  Add urgent_queue() spawning dedicated 64 MiB-stack xcl-pso-wait-* workers and offload unstarted jobs in resolve_wait_for(..., None) instead of executing job() inline on the title's 1 MiB stack threads, avoiding silent Wine thread deaths without skipping compute dispatches (ivall#675, ivall#891). Guard build() with std::panic::catch_unwind plus a Drop completion guard so panics always call complete(p, 0) and notify waiters.
- crates/xcl/src/hle/d3d12x/pso_async.rs & kernelx.rs (ivall#1288, ivall#505, ivall#232):
  Track active pipeline bind waits via HELD / title_held() and export kernelx::Sleep backed by title_sleep() so Sleep skips counting time spent blocked on background PSO compilation (XCL_SLEEP_HOLD=0 disables).
- crates/xcl/src/hle/d3d12x/bind.rs, device_x.rs & real.rs (ivall#1195):
  Track console compute PSOs (CONSOLE_COMPUTE) and Dispatch-capable command signatures (DISPATCH_SIGNATURES) so ExecuteIndirect skips dispatches against untranslated console compute stand-ins or fallbacks while still forwarding native PC compute pipelines.
- crates/xcl/src/hle/d3d12x/sparse.rs (ivall#1419, ivall#1277):
  Extract wait_fence_until() to ResetEvent before SetEventOnCompletion and re-check GetCompletedValue() until target or deadline so stale signals on the reusable auto-reset event cannot end waits early; bail cleanly from upload_dirty() if ring fence reclaim times out instead of holding STATE indefinitely.
- crates/xcl/src/gpu/recomp/emit.rs & tests.rs (ivall#1361):
  Split GFX10.30 SADDR == 0x7F (ST immediate-only 0u base) from SADDR == 0x7D (v[ADDR] base) in Em::scratch and update ENC_FLAT_SCRATCH VADDR test encodings to 0x7D.

Assisted-by: Antigravity (Gemini 4 Neon)
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. (One parallel run showed a single flaky failure; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

@xpatfussy69x

Copy link
Copy Markdown
Contributor

Test report for head 3861d2e as pushed (not merged onto current main) – NVIDIA, wave32.

Tested

  • NVIDIA GeForce RTX 3060 12 GB (Ampere, 32-lane waves only), driver 32.0.16.2124; AMD Ryzen 5 7500F; 32 GB RAM; Windows NT 10.0.26300; Rust 1.100.0 (stable-x86_64-pc-windows-msvc); debug; DXC 1.9.2609.5
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 725 passed, 0 failed, 41 ignored
  • SKIPPED GPU tests on this adapter: 2 (no wave64)
  • this PR's tests: wait_fence_until_ignores_stale_event_signal ran and passed
  • no XCL_SAMPLE_* data set (game-data tests not run)

Not tested

  • a smoke run on a title; AMD / native wave64; release build; the head merged onto current main; the D3D12 debug layer

AI use

  • Claude (Claude Opus 5.5) wrote the script that ran the suite on my PC, read the log and wrote and posted this report with my approval; the run is mine.

@ClosetPie107

Copy link
Copy Markdown

Linux / AMD RDNA4 (RADV) test report for head 3861d2e 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 53aac418), 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::sparse: 16 passed, 0 failed, 1 ignored (early_commit_timing), 0 skipped (2.31 s), including wait_fence_until_ignores_stale_event_signal on RX 9070 / RADV.

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.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

AMD RDNA3 (native wave64) test report for exact head 3861d2e2b561482933c657802cc5801b28bc60ba, as pushed on its base 9aec53d (not merged onto current main).

Tested

  • AMD Radeon RX 7800 XT (RDNA3, native wave64), driver 32.0.31035.1003; Windows 11 Pro 10.0.26200; Rust 1.100.0 (stable-x86_64-pc-windows-msvc); debug; DXC 1.9.0.5512 (dxcompiler.dll)
  • cargo build --workspace: ok
  • Targeted: wait_fence_until_ignores_stale_event_signal: 1 passed; sparse filter: 17 passed, 0 failed, 1 ignored
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 725 passed, 0 failed, 41 ignored (summed over all test binaries)
  • SKIPPED lines: none in the output

Not tested

  • No game title, no scripts/smoke.ps1 regression run (synthetic GPU/unit tests only)
  • Not merged onto current main; other GPUs (NVIDIA / Intel / RDNA2 / RDNA4)
  • Whether the new test fails without the fix (I did not revert it)

AI use: Claude Code (Claude Sonnet 5.5) ran the build and tests and wrote this report; the numbers are from the runs above.

raylitebull added a commit that referenced this pull request Nov 25, 2026
Fix three descriptor-heap and view bugs in console_list.rs (#2461):
- Call ensure_dispatch_heaps before SetComputeRootSignature so SetDescriptorHeaps never invalidates bound root-signature state (D3D12 #1419).
- Bind the shared view heap in ensure_dispatch_heaps unconditionally when present (not only under XCL_HEAP_WINDOWS) so ResourceDescriptorHeap texture/UAV indexing always sees it, and guard zero window VAs before SetComputeRootUnorderedAccessView.
- Prefer c.pc_gpu_uav when both CPU and GPU ClearUAV slots are hosted in GLOBAL so inline RAM copies (CopyDescriptorsSimple) never clear with an uninitialized g.pc_gpu_uav handle.

Includes unit test clear_uav_prefers_cpu_slot_shared_gpu_handle_for_inline_copies.

Assisted-by: Antigravity (Gemini 4 Neon High)
KOLESNiii pushed a commit to KOLESNiii/xcl that referenced this pull request Nov 26, 2026
…event

(cherry picked from commit 3861d2e, xcl-dev#1419; on top of xcl-dev#1277,
wait_for_ms passes its own timeout to wait_fence_until and keeps returning whether the fence
was reached)
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 3861d2e

Main already fixes this: commit b5e8baf (merged with #3203) rewrote State::wait_for as wait_for_ms, which re-arms SetEventOnCompletion and waits again until fence_completed >= target or the timeout, for the same reason (a timed-out wait's registration firing the shared event later).
The large amd-dev PRs that share these lines (#2912, #2981, ...) carry this commit as part of their base; they are not separate fixes.
Recommendation: close (superseded by main commit b5e8baf).

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

@throny

throny commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Closing as superseded: this change is already on main (b5e8baf). main sparse.rs State::wait_for_ms loops SetEventOnCompletion/WaitForSingleObject until fence_completed >= target or timeout (b5e8baf), so a stale event signal no longer ends the wait; same fix as the PR

Two independent checks found this: Foniass's close list on #1607 and ours against current main. If something here is still missing on main, say so and reopen it, or ask and I will.

AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.

@throny throny added the duplicate This issue or pull request already exists label Dec 1, 2026
@throny throny closed this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists 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