d3d12-gpu: stabilize global stall routing test under parallel diagnostics runs #2884
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2884"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-12-01T14:16:09Z.
Claim:
D3D12-TIMELINE-STALL-TEST-PARALLEL(https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7313717013)Fixes the
--features diagnosticsparallel test flake ind3d12/crates/leonida-gpu/src/timeline/record.rs(global_stall_routing_retains_spans_waits_wakes_and_sent_fences_without_stacks, reported by@enlight3din #2854).Root cause
Under parallel
cargo test -p leonida-gpu --lib --features diagnostics,global_stall_routing_retains_spans_waits_wakes_and_sent_fences_without_stacksshares the process-wide 65,536-entryROLLINGring buffer with all other test threads. Previously, it emitted"synthetic stall span"first and then spawned a worker thread and synchronized aCondvar+Barrierwait/wake before callingfinalize_stall. While the thread-spawn + condvar step ran, concurrent tests floodedROLLINGand evicted the earlier"synthetic stall span"from the ring before freeze (as@KelboLiveconfirmed by instrumenting the base: the span landed inROLLINGwithpresent=true, then vanished by freeze withoverwritten=339,176).Separately,
emit_global_without_contentionpolled the process-wideROLLING.dropped_contentioncounter and silently gave up after 64 retries instead of checking that the test's own event was actually retained inROLLING.Change
global_stall_routing_retains_spans_waits_wakes_and_sent_fences_without_stacksso the thread-spawn + condvar wait/wake runs before emitting"synthetic stall span",Sent, and the fence-linkedWait, shrinking the window during which concurrent tests can evict those events before freeze.#[cfg(test)] RollingBuffer::has_event(&self, pred)ind3d12/crates/leonida-gpu/src/timeline/record.rs.emit_global_without_contentionwithemit_global_until(pred, emit), which verifies the specific synthetic event is present inROLLING(panicking loudly after 64 attempts rather than silently giving up). Applied to bothglobal_stall_routing_retains_spans_waits_wakes_and_sent_fences_without_stacksandstep_stall_present_writes_on_background_thread_and_preserves_reentrancy_safety.Note: this does not eliminate concurrent test traffic into the shared
ROLLINGring itself; it removes the thread-spawn eviction gap and turns any emit-time drop into an explicit failure.Verification
mainb3910e5e3, 10 parallel runs ofcargo 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_stackspanicked atrecord.rs:2325:9(1/10runs here;7/10--8/10on@enlight3d's machine;18/20on@KelboLive's machine).timeline::(timeline::record::tests::*passed 20/20;0/20on@KelboLive's machine as well).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
Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-01T14:27:50Z.
Independent parallel diagnostics runs at
4b52062dmerged ontob3910e5e, with fresh Win64 MSVC-target builds and Wine 11.22. I ran the 11timeline::record::testswith 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::recordtest failed in those nine runs. The wider runs stayed red for failures also observed onmain(including a separatetimeline::reporttest). 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).
Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T16:44:49Z.
Review: COMMENTED
Verified empirically, and the fix works: the target test fails 18/20 full-suite diagnostics runs on base
b3910e5e3and 0/20 with this branch, and the merged tree passes. CI green, merge clean, andrecord.rshas 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
ROLLINGright afteremit_global_without_contentionreturns (present=true, overwritten=0), and it only vanishes by freeze withoverwritten=339,176and the ring full at 65,536 — so it is eviction by other tests' events, not a push that never landed. The newhas_eventcheck (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 andfreeze(). The underlying shared-ring flooding is not addressed.Two suggestions that would keep this class visible instead of latent:
data.meta.overwritten == 0(or gate the foreign producers) so a future flood fails loudly rather than relying on the timing window;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 truepasses 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!atrecord.rs:2283adds 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".
Imported from ubiquitarianism/leonida. Originally posted by Neutron-0 on 2026-12-01T17:46:59Z.
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-gputest 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:b3910e5e34b52062d5global_stall_routing_retains_spans_waits_wakes_and_sent_fences_without_stacksdid 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 onmainad7c62edb) 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:
That is the pool race #2854 fixes (
Reclaim::releaseleaving the released resource's raw pointer inRECENT/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_contentionpolled the process-wideROLLING.dropped_contentioncounter 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 ondata.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_untilretries 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_drawstest, which the repository's own commands skip on a software adapter.Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-12-01T20:49:04Z.
@KelboLive Thanks for instrumenting the base and catching the actual failure mechanism -- eviction from
ROLLINGduring the thread-spawn + condvar step rather than a lost push. I've updated the PR description to state the root cause accurately (eviction by other tests' events into the shared 65,536-entry ring, plus thehas_eventpanic guard) and explicitly note that shared-ring flooding itself is not eliminated here. Keeping the code untouched so CI and your /@Neutron-0's verification runs stay valid on4b52062d5.@Neutron-0 Thanks for running the 10+10 parallel check as well (and confirming the separate
alias_cast_testshit belongs to #2854).Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-12-01T22:35:45Z.
Merging (added to the merge queue). Head
4b52062d5merges cleanly with mainc4ca57615. Claim: D3D12-TIMELINE-STALL-TEST-PARALLEL (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7313717013). Red/green: KelboLive (the test fails 18/20 diagnostics runs on base, 0/20 with this), Neutron-0 (Windows 11, 10 runs each side). I ran: #2858, #2882, #2788, #2876 and #2884 merged together onto mainc4ca57615: cargo tests leonida-shader 420 passed / 0 failed, leonida-loader 85/0, leonida-gpu 644/0. In-game run: RTX 4070 Laptop 8 GB, NVIDIA 621.40, -SeriesS -NoDlss -NoFrameGen, a cold start to the world (135 s) then a 330 s warm walking run: median 35.4 ms (28.2 fps), private memory max 24.4 GB, 0 device lost. CI: green on head and main; the queue runs the full CI on the group before merging. AI-assisted: Claude Code (oreofr-agent), merge approved in writing by OreoFR.Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-02T00:11:55Z.
VERIFY-2884 — Linux, Fedora 45, Rust 1.98.1 (the pinned toolchain), Wine 11.21, no GPU device, no game files
Verdict: PASS on what I could check. The change makes a test that was flaky under parallel runs deterministic, and nothing that passed before fails now. The flakiness itself does not reproduce on this machine, so I could not watch the test go from red to green.
Head
4b52062d, base the currentmain, merge baseb3910e5e, 1 file, +70/−42:d3d12/crates/leonida-gpu/src/timeline/record.rs.1. What it changes
ROLLINGis a global ring the timeline writes into;try_pushdrops rather than blocks when another thread holds the ring's lock. The global-stall routing test writes a synthetic span through that global producer, and undercargo test's parallel threads an unrelated test thread can holdROLLING.innerat that moment — so the producer call is dropped and the test fails even though the code is right. The test's own comment said so:The change replaces "retry when the contention counter advances" with "retry until the producer call actually took":
and the assertion it guards becomes "the synthetic wake/wait events were not retained in
ROLLING" — the test now waits for the events to be there rather than assuming one call was enough.2. What the tests do here
leonida-gpudoes not build on Linux (upstream: "The crates are Windows-only today … Linux follows #2577"), so I cross-compiled it forx86_64-pc-windows-gnuand ran the tests under Wine 11.21:watch::many_askers_tests::holes_are_known_until_the_runtime_tells,watch::many_askers_tests::no_mapping_is_lost_between_askersandwatch::tests::what_is_left_alone_is_no_known_holeThe test count is the same on both sides because the change modifies an existing test (
timeline::record::tests::global_stall_routing_retains_spans_waits_wakes_and_sent_fences_without_stacks) rather than adding one.3. Why there is no red→green to see
The modified test passes on the merge base as well: the contention the retry answers to needs another test thread to hold
ROLLING.innerat that exact moment, and on this machine (8 cores, Wine's own timing) it does not happen. So the base's copy of the test passes, the head's copy passes, and the difference the pull request makes — a test that fails sometimes becoming one that never does — is not observable here.That is the opposite of a defect: the change removes a flake that the upstream's 16-core Windows CI sees. I could not reproduce the flake to measure how often it fires.
4. What I did not check
emit_global_untilwaits for the events to appear; if the producer keeps losing the race the test would spin. I did not read its bound.timeline/record.rs; I read the test-related part and thehas_event/emit_global_untilhelpers, not every line of the production change.AI-assisted: MiniMax M3.1 Flash.