metal, gpu: recover swept queue followers and isolate piece fences on GPU timeout #551
No reviewers
Labels
No labels
accessibility
bug
claimed
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
tester report
urgent
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LakshanSivakumar--Native-Victory-macOS!551
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-547"
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?
@Sheffy007 on GitHub · 2026-11-28 02:57 UTC · original
Sheffy007:fix/gpu-timeout-cascade-recovery→main· +272 −75 · 5 files · 1 commits · openSummary
Addresses the GPU timeout / residency-order cascade analyzed in #408 (and #525):
MTLFence& failednext_piecesignal refund (crates/victory-metal/src/gfx.rs): Give each split-submission piece (VICTORY_PASSES_PER_BUFFER) its own intra-pieceMTLFence(Order) while keeping inter-piece ordering onpiece_event(MTLSharedEvent), so a timed-out earlier piece never leaves the next piece wedged on an unsignalled GPU-onlyMTLFence. Ifnext_piecefails afterqueue.3was incremented, attach(queue.2, queue.3)and the submission's fence signals to the last committed piece's completion refund (attach_refund_and_events).crates/victory-metal/src/gfx.rs,crates/victory-gpu/src/native/glue.rs):HAD_FAILUREonlanded(..., true)soglue::refreshchecksrecover_lost()immediately (and every 200 ms rather than behind the 5 s warning log throttle) and callst.pump()as soon as lost work is recovered.serial < failed_serial) on a failed FIFO queue after0.5 s, sibling followers already committed on that queue when the failure/reset hit (since <= failed_at) after3 s(leaving fresh post-failure work untouched), and any unreported buffer on any queue after15 s— well ahead of the title's 30 s fatal watchdog (0x1423cf683->0x1455e56f8).order_state()queues in"work held for a wait that does not hold"warnings even whenVICTORY_TRACE_GPU_FAILSis unset.crates/victory-gpu/src/native/host.rs): Whensubmit_passesfails with!f.committed, raise the submission's fence signals (when ahead ofcompleted) after paying CPU fills and issuing a release fence.Verification
cargo xtask policycargo test --locked -p victory-metal --lib -- owed_testscargo test --locked -p victory-gpu --lib -- vertex_testscargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warningscargo clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-gnullvm -- -D warningsCloses #408
Refs #80, #525
cc @Olima34 @wz11wz
@Olima34 on GitHub · 2026-11-28 03:54 UTC · original · requested changes
Thanks @Sheffy007. Giving each piece its own
MTLFenceand refunding the order event and fence signals whennext_piecefails both read right to us, andpay_refundkeeps the take-under-lock rule the maintainer just landed. We read the whole diff ofba6821eawhile helping the maintainer clear the queue. The part we can't take without evidence is the new recovery horizons inrecover_lost_after:LOST_ANYWAY30 s → 15 s. docs/native-host.md on main records long command buffers that did complete: "a single 30 s dispatch completed" (the Metal event-wait finding), and "a pass of res5 ran 25 s and completed" (the stop paragraph, #360). Under the new rule, a buffer like that has its fence signals and value writes paid from the CPU at 15 s while it is still running. The title then goes on and reads results the GPU hasn't written yet, and the GPU's late writes land over newer values. Cold-cache world frames are where such buffers happen.LOST_WITH_A_FAILURE(3 s,f.since <= at). This treats every buffer already committed on the queue when one failed as swept, including one that is simply still running after the failed one. The same problem as 1 then applies at 3 s. If Metal's reset really sweeps followers without reporting them, a traced run should show it: buffers committed before the failure, never reported completed or failed, for minutes. Please post theVICTORY_TRACE_GPU_FAILS=1lines from such a run. The rule could also be narrowed to buffers whose status Metal shows as not completed after the failure, rather than by age alone.LOST_BEHIND_A_FAILURE5 s → 0.5 s. It's the same FIFO argument as before, but at 0.5 s an older buffer that is merely slow gets paid too. What did you see that makes 5 s too long, ahead of the 30 s watchdog?The "Guess:" note in the code is the right place for this, and docs/native-host.md should say the same. What's missing is a run showing the new horizons recover a real cascade without paying work that would have finished. Two before/after headless world runs with
VICTORY_TRACE_GPU_FAILS=1, compared withtools/macos/run-summary.sh --compare, would settle it. If the faster pump (take_had_failure), the per-piece fences and the refunded events can stand on their own, splitting them from the horizon change would let those merge first.CI is green on this head. No game run on our side.
@wz11wz on GitHub · 2026-11-28 05:12 UTC · original
This matches what we measured in #408 — strong LGTM on the mechanism, with two additions from our data.
Confirming evidence (240s headless repro runs,
VICTORY_TRACE_GPU_FAILS=1):kIOGPUCommandBufferCallbackErrorTimeoutin the same instant, including a 0-pass signal-only buffer — followers on the swept queue then hang atwaits=0(the residency-order wait is not counted in the label'swaits), and four other queues stall on one fence each missing exactly one signal.0x1455e56f8via0x1423cf683— same chain your recovery targets.victory-gpu/src/native/suspect_tests.rs), and IR analysis shows none of them contains a loop. The freeze-window kernels (12 containers viavictory-shader --example dump_dxil) are all bounded too — the two Scheduled-stuck command buffers' full dispatch lists are in the report.1. The order counter race is still in this PR.
queue.3is aCell<u64>:let n = queue.3.get(); queue.3.set(n + 1);is a lost-update window if the title callsExecuteCommandListson one queue from two threads (legal in D3D12), and the newtail_events.push((queue.2.clone(), queue.3.get()))re-reads it again — under concurrency that signals a slot another submission was waiting on, breaking the serialization this whole design relies on (two command buffers running concurrently = buffer races the residency ordering exists to prevent). We run an atomicfetch_addwith each submission signalling its ownn + 1(captured at encode time, also used forOwed) — happy to split that out as a PR if you'd rather keep this one focused.2. One crash shape this PR doesn't cover yet: with
VICTORY_METAL_RESIDENCY_SETS=0(no order-event chain at all) we still got the same0xc0000005 at image+0x55e56f8crash at t≈168 — with zero GPU Timeout kills and the GPU alive but slow (fence lag ≈ 9, counters moving). Nothing failed, soHAD_FAILURE/recover_lostnever fires, and the title's watchdog still tripped on lagging fences. That shape points at throughput collapse in the Prestream zone rather than a stuck sweep — recovery alone won't stop it; the budget problem (a world submission exceeding the ~5s device watchdog under ordered residency) remains. Worth keeping in scope before closing #408.Verification tooling: our cascade repro (
a_never_finishing_dispatch_cascades_to_waits_zero_followers: spin-kernel root → trivial follower, asserts the follower hangs) plus the suspect-dispatch tests are invictory-gpu/src/native/suspect_tests.rs— they should pass identically before/after this PR and directly exercise the swept-follower path yourrecovernow covers.@wz11wz on GitHub · 2026-11-28 06:44 UTC · original
Measured data on the
LOST_ANYWAYthreshold — 15s misfires on legitimate frames, and lag accumulation caps what any recovery threshold can buy.We kept your branch (plus an unrelated order-counter atomicity fix) and ran the same 300s headless repro with
VICTORY_METALFX=1, ordered residency (mode="a set per heap"),VICTORY_TRACE_GPU_FAILS=1:LOST_ANYWAYThe 15s threshold pays running command buffers. The world-frame submission
#9443(171 passes, 362 draws + indirect compute) was committed at t=170.56, andrecover_lost_afterfired at 05:31:44 — its first unreported was 15.2s old — while#9443was still executing. It completed at 05:31:52 withfailed=False(took 22.752s, gpu 18.421s): the CPU-paid signals/events landed 7.5s before the GPU's real ones, and the GPU's late writes fell on top of paid values. Three more recovery bursts followed (3/3/4/2). With the threshold at 30s the same frame completes unmolested (one recovery, for a different buffer).But 30s does not stop the crash — lag accumulates. Single-frame GPU time (18.4s) is under the title's ~30s tolerance, yet frames queue back to back: frame N takes 18s, frame N+1 queues behind it, so frame N+1's fences lag ~36s — past the title's watchdog — and it crashes at the same
0x1455e56f8. That's why every threshold fix only moved the crash later (t≈136 → 246 → 254) without removing it.Recommendations:
LOST_ANYWAYto 30s (the measured legitimate-frame ceiling is 18.4s; 15s pays healthy work every world frame, which is worse than not paying — the GPU's late writes land on top of paid values).victory-gpu/src/native/suspect_tests.rs) upstreamed as the regression harness for whichever direction lands.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.