Skip to content

d3d12-gpu: stabilize global stall routing test under parallel diagnostics runs - #2884

Open
lixonik wants to merge 1 commit into
ProjectLeonida:mainfrom
lixonik:fix/timeline-stall-test-parallel-flake
Open

lixonik wants to merge 1 commit into
ProjectLeonida:mainfrom
lixonik:fix/timeline-stall-test-parallel-flake

Conversation

@lixonik

@lixonik lixonik commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Claim: D3D12-TIMELINE-STALL-TEST-PARALLEL (#2570 (comment))

Fixes the --features diagnostics parallel test flake in d3d12/crates/leonida-gpu/src/timeline/record.rs (global_stall_routing_retains_spans_waits_wakes_and_sent_fences_without_stacks, reported by @enlight3d in #2854).

Root cause

Under parallel cargo test -p leonida-gpu --lib --features diagnostics, emit_global_without_contention checked whether the process-wide ROLLING.dropped_contention counter changed across the closure. When another test thread concurrently triggered or avoided contention while this test emitted its synthetic Span, Wake, Sent, or Wait, emit_global_without_contention could return without the test's own synthetic event actually landing in ROLLING, causing data.events.iter().any(...) to panic after finalize_stall.

Change

  • Added #[cfg(test)] RollingBuffer::has_event(&self, pred) in d3d12/crates/leonida-gpu/src/timeline/record.rs.
  • Replaced emit_global_without_contention with emit_global_until(pred, emit), which retries until this test's specific synthetic event is retained in ROLLING (up to 64 attempts, panicking otherwise), and updated both global-routing tests (global_stall_routing_retains_spans_waits_wakes_and_sent_fences_without_stacks and step_stall_present_writes_on_background_thread_and_preserves_reentrancy_safety).

Verification

  • Before (on main b3910e5e3, 10 parallel runs of cargo test --locked -p leonida-gpu --lib --features diagnostics -- --skip depth_bounds_pipeline_loads_and_filters_draws): global_stall_routing_retains_spans_waits_wakes_and_sent_fences_without_stacks panicked at record.rs:2325:9 (1/10 runs here; 7/10--8/10 on @enlight3d's machine).
  • After (20 consecutive parallel runs of the same command): 0 / 20 failures in timeline:: (timeline::record::tests::* passed 20/20; the 3/20 failures in descriptor::tests / watch::tests are the separate pre-existing races fixed in d3d12-gpu: fix parallel unit test races in watch, descriptor, and pool #2854).

GPUs tested: NVIDIA GeForce RTX 5070 12 GB (driver 621.40, Windows 10 Pro 22H2 build 19045, Ryzen 9 5950X 16C/32T)

AI-assisted: Antigravity

@merzleckeier

Copy link
Copy Markdown
Contributor

Independent parallel diagnostics runs at 4b52062d merged onto b3910e5e, with fresh Win64 MSVC-target builds and Wine 11.22. I ran the 11 timeline::record::tests with eight test threads four times per tree on each of RTX 4070 SUPER (620.73.04) and Radeon Raphael (RADV 26.3.1). All eight targeted runs passed per tree.

I also ran the full GPU crate selection on RTX 4070 SUPER three times per tree and three more with #2854 applied. No timeline::record test failed in those nine runs. The wider runs stayed red for failures also observed on main (including a separate timeline::report test). The original stall-routing flake did not reproduce on this Wine setup, so this is integration coverage for the changed tests and #2854 together.

MEASURED with synthetic tests, no game files. AI-assisted (Codex).

@KelboLive KelboLive 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.

Verified empirically, and the fix works: the target test fails 18/20 full-suite diagnostics runs on base b3910e5e3 and 0/20 with this branch, and the merged tree passes. CI green, merge clean, and record.rs has not moved between the branch base and current main.

But the stated root cause does not match the failure. Instrumenting base shows the span is in ROLLING right after emit_global_without_contention returns (present=true, overwritten=0), and it only vanishes by freeze with overwritten=339,176 and the ring full at 65,536 — so it is eviction by other tests' events, not a push that never landed. The new has_event check (record.rs:674-676) is a real improvement (silent give-up becomes a panic), but it proves presence only at emit time; the same eviction can still wipe the event between the last check and freeze(). The underlying shared-ring flooding is not addressed.

Two suggestions that would keep this class visible instead of latent:

  • assert on data.meta.overwritten == 0 (or gate the foreign producers) so a future flood fails loudly rather than relying on the timing window;
  • make the wait predicate object-specific — Kind::Wait && e.b == 0 (record.rs:2282) matches any concurrent non-card wait, so the test can be satisfied by someone else's wait.

Mutation note: replacing the retention guard with if true passes the stock test 8/8, so the new guard is only covered when contention actually hits — the temporary 2 ms ring hold I used is the only way I got it red. That is acceptable for a flake fix, but it means the guard is not a regression test on its own.

Nit: the over-long assert! at record.rs:2283 adds a 15th rustfmt diff to a file that already has 14; fmt is report-only here, so cosmetic.

Verdict: approve with the root-cause correction — no runtime risk, and the flake is gone empirically — but the narrative should say "evicted by other tests", not "the push was lost".

@Neutron-0

Copy link
Copy Markdown

Verified on Windows 11, Rust 1.98.1, no GPU and no game files.

The change is right in shape, and the flake it fixes did not reproduce on this machine. The whole leonida-gpu test binary was run in parallel, ten times on each side, with the shape the report uses (cargo test -p leonida-gpu --lib --features diagnostics -- --skip depth_bounds_pipeline_loads_and_filters_draws), so that the other test threads are there to contend:

runs the test this pull request fixes
the base b3910e5e3 10 0 failures
the head 4b52062d5 10 0 failures

global_stall_routing_retains_spans_waits_wakes_and_sent_fences_without_stacks did not fail on either side in twenty runs, so on this machine the change is neither needed nor harmful - it is simply not the thing that reproduces here. The report's own measurement (1 of 10 runs on main ad7c62edb) is a different commit and a different machine, and a race that fires in 1 run out of 10 is not going to fire in every set of ten.

One failure was seen, in a different test, and it belongs to #2854. On run 8 of the head:

texture::alias_cast_tests::committed_and_placed_r32_uint_textures_cast_to_r9g9b9e5_under_legacy_barriers
thread ... panicked at crates\leonida-gpu\src\texture.rs:5664:17

That is the pool race #2854 fixes (Reclaim::release leaving the released resource's raw pointer in RECENT/UNSEEN, so a reused pointer is reported as fresh), and #2854 is still open. It is worth knowing that the parallel run of this crate is not yet clean even with this pull request: #2884 and #2854 fix different races in the same test binary, and both are needed for a green parallel run.

What the change does, and it matches the report. emit_global_without_contention polled the process-wide ROLLING.dropped_contention counter to decide whether its own synthetic event had landed; another test thread advancing that counter made the helper give up before the event was in the buffer, and the test then failed on data.events.iter().any(...). The replacement asks the buffer itself (RollingBuffer::has_event) whether the event is there, and retries until it is. That is the right fix: the counter was a proxy for a question the buffer can answer directly, and the proxy was shared with every other thread in the process.

One note on the helper's shape. emit_global_until retries until the event is present, so a genuine failure inside the emitter - an event that is never retained because the buffer is full - would now be retried until the test times out rather than failing on the first attempt. The loop is bounded by the test harness's timeout, so it fails, but with a timeout panic instead of the assertion that says what went wrong. Checking the buffer for the event and the buffer's capacity (or a retry limit) would keep the failure readable. Not blocking.

Not checked: the GPU crates' behaviour under a real adapter (no GPU device here); the depth_bounds_pipeline_loads_and_filters_draws test, which the repository's own commands skip on a software adapter.

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.

4 participants