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

Open
github-bot wants to merge 1 commit from github-bot/gh-1419 into main AGit
Owner

@⁠gridoe on GitHub · 2026-11-24 15:47 UTC · original
gridoe:sparse-wait-stale-event → main · +78 −6 · 1 files · 1 commits · open

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.
**@⁠gridoe** on GitHub · 2026-11-24 15:47 UTC · [original](https://github.com/xcl-dev/xcl/pull/1419) `gridoe:sparse-wait-stale-event` → `main` · +78 −6 · 1 files · 1 commits · open `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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:53:17 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 15:57 UTC · original · edited 2026-11-24 16:07 UTC

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.
**@⁠futurepro62** on GitHub · 2026-11-24 15:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/1419#issuecomment-7136880318) · edited 2026-11-24 16:07 UTC 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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 17:13 UTC · original

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!

**@⁠DavidM1911** on GitHub · 2026-11-24 17:13 UTC · [original](https://github.com/xcl-dev/xcl/pull/1419#issuecomment-7138865894) 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!
Author
Owner

@⁠xpatfussy69x on GitHub · 2026-11-25 11:41 UTC · original

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.
**@⁠xpatfussy69x** on GitHub · 2026-11-25 11:41 UTC · [original](https://github.com/xcl-dev/xcl/pull/1419#issuecomment-7161381344) 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.
Author
Owner

@⁠ClosetPie107 on GitHub · 2026-11-25 12:19 UTC · original

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.

**@⁠ClosetPie107** on GitHub · 2026-11-25 12:19 UTC · [original](https://github.com/xcl-dev/xcl/pull/1419#issuecomment-7162223798) 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.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 13:19 UTC · original

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.

**@⁠oni-swr** on GitHub · 2026-11-25 13:19 UTC · [original](https://github.com/xcl-dev/xcl/pull/1419#issuecomment-7163606431) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1419/head:github-bot/gh-1419'
git switch 'github-bot/gh-1419'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1419'
git switch 'github-bot/gh-1419'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1419'
git switch 'github-bot/gh-1419'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1419'
git switch 'main'
git merge --squash 'github-bot/gh-1419'
git switch 'main'
git merge --ff-only 'github-bot/gh-1419'
git switch 'main'
git merge 'github-bot/gh-1419'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.