gpu(native): cap unbounded GPU work, so a garbage indirect record cannot hang the Mac's GPU #522
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 LakshanSivakumar/Native-Victory-macOS. Originally posted by AeroUp on 2026-11-28T00:15:14Z.
The run of 2026-11-27 18:25 (Series S, M3 Pro) hung the GPU: 13 AGX restarts, WindowServer reset, and the process stuck in kernel exit holding 13.7 GB wired. The failing command buffer's trace shows indirect draw records read as garbage, e.g.
[3190467240, 1051372204, 2139095039, 2139095039, 2139095039]: an indirect dispatch's groups are gated to 2^22, but an indirect draw's vertex/index and instance counts are not clamped at all, so Metal runs billions of vertices.Plan: clamp indirect and direct dispatch/draw counts to hard caps with one log line per kind; refuse (rather than emit) any translated loop that has no iteration counter; drop a new submission when the GPU has not finished one for 10 s instead of queueing behind a hung GPU; and end the process on a deadline (bounded GPU drain) on every exit path, including the title's exit and unhandled-exception path.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AeroUp on 2026-11-28T00:15:16Z.
/claim
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-28T00:15:30Z.
Claimed by @AeroUp. Open a draft pull request with
Refs #522in its description within 24 hours, or the claim expires.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-29T00:42:12Z.
The claim by @AeroUp has expired: no pull request referenced it within 24 hours. This issue is free to claim.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-29T08:21:31Z.
/claim
Taking the demonstrated hang mechanism first (one change per PR): clamp an indirect draw's vertex/index and instance counts to hard caps — the indirect dispatch's groups are already gated to 2^22, the draw's counts are not clamped at all, and Metal ran billions of vertices off a garbage record. One log line per kind when a clamp bites, as the issue's plan has it. The loop-refusal and the 10 s stall-drop/drain items stay in this issue as follow-ups.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-29T08:21:41Z.
Claimed by @AnastasisKon. Open a draft pull request with
Refs #522in its description within 24 hours, or the claim expires.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-29T08:22:25Z.
Correcting my own scope above: the demonstrated indirect-draw hang is already fixed on main —
3f860303(2026-11-27, metal: an indirect draw of more than 2^20 instances or 2^26 vertices draws nothing) extended the gate the same day as the run in this issue, after it. So the item-1 indirect part is done; I am not redoing it.Re-scoping my claim to the plan's third item: drop a new submission when the GPU has not finished one for 10 s instead of queueing behind a hung GPU (with one log line). The gate bounds what one garbage record can ask for, but any other hang — a Metal fault, a compiler-service crash mid-frame — still leaves every later submission queued behind it, which is what cost 13 AGX restarts and the WindowServer reset in this issue's run. The direct-count clamps and the loop-refusal and bounded-drain items stay open in this issue.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-29T08:29:10Z.
The third plan item landed on the fork's main as commit 90f72141 (metal: a submission is not queued behind a GPU taken as hung).
One deviation from the plan, deliberately: the drop threshold is LOST_ANYWAY (30 s), not the 10 s written here. Legitimate world submissions have run 6-21 s (the piece work in #80 measured that), so at 10 s the drop would cut into healthy work; 30 s is the bar the repo already uses to call a command buffer lost (recover_lost pays one at that age), so queued and paid now use the same rule. If a run ever shows a hang shorter than that doing damage, the number is one constant.
What it does: once the oldest in-flight submission has been unfinished for 30 s, the GPU is taken as hung and the latch keeps it — every later submission is paid on the CPU (fence signals and value writes through the existing Owed recovery, the queue's order event moved past it so nothing waits behind a value that never comes) and not queued. That bounds what a hang costs: no new wired memory behind a dead GPU, and the exit has nothing extra to drain. One error line, once, telling the user to restart. The hung submissions themselves are still paid by recover_lost under its existing rules.
Gate green in isolation, this time including victory-metal's own tests: cargo test -p victory-hle -p victory -p victory-shader -p victory-gpu -p victory-backend -p victory-metal -p xtask (--test-threads=1, with a new unit test on the decision: nothing in flight or a young flight is not hung, one LOST_ANYWAY-old flight is, a young one behind it does not help), the x86_64-apple-darwin suite for host_posix, clippy on windows-gnullvm, cargo xtask policy, all tools/macos/tests/*.sh.
Remaining in this issue: the direct draw/dispatch count clamps (the indirect ones are done —
3f860303gates indirect draws at 2^20 instances / 2^26 vertices), the refusal of translated loops without an iteration counter, and the bounded GPU drain on every exit path. Not claiming those; freeing the claim so they can be taken one by one.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-29T08:29:11Z.
/release
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-29T08:29:29Z.
Released. This issue is free to claim.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-29T08:36:30Z.
/claim
Taking the direct half of the first item: clamp a direct dispatch's group counts and a direct draw's vertex and instance counts to the same hard caps the gate already holds indirect ones to (2^22 groups; 2^20 instances, 2^26 vertices), with one log line per kind when a clamp bites. The loop-refusal and bounded-drain items stay open.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-29T08:36:40Z.
Claimed by @AnastasisKon. Open a draft pull request with
Refs #522in its description within 24 hours, or the claim expires.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-29T08:44:41Z.
The direct half of the first item landed on the fork's main as commit ad0e5c2d (gpu(native): a direct dispatch or draw past the gate's caps runs nothing).
A direct call's counts were not bounded at all: the gate holds indirect records to 2^22 groups, 2^20 instances and 2^26 vertices or indices in all, but a direct Dispatch/Draw/DispatchMesh could ask the GPU for the same unbounded work a garbage record no longer can. Direct calls past the same caps now run nothing, as an indirect record past them does — a console title's own counts never come near the caps (D3D12's per-dimension limits are far below), so the guard only ever answers garbage. The refusal is argument validation before the pipeline state, so an under-cap call still fails exactly as before for a missing pipeline; one warning line per kind, the first four.
Unit test: dispatches past the cap in the product and in one dimension, draws past the instance cap and the vertex/index products, a mesh dispatch past the group cap — all record no command; under the caps the calls still reach the pipeline check. Full gate green in isolation (native suite incl. victory-metal and victory-backend, the x86_64-apple-darwin host_posix suite, clippy on windows-gnullvm, cargo xtask policy, all tools/macos/tests/*.sh).
That closes the first item of the plan entirely (indirect half:
3f860303; direct half: ad0e5c2d; plus the hung-GPU drop: 90f72141). Remaining: the refusal of translated loops without an iteration counter, and the bounded GPU drain on every exit path. Freeing the claim for those.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-29T08:44:42Z.
/release
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-29T08:45:00Z.
Released. This issue is free to claim.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-29T08:47:56Z.
/claim
Taking the last item: a bounded GPU drain on every exit path — the run in this issue ended stuck in kernel exit holding 13.7 GB wired, so the drain a hung GPU never finishes needs a deadline after which the process ends anyway. The loop-refusal item stays open after it.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-29T08:48:08Z.
Claimed by @AnastasisKon. Open a draft pull request with
Refs #522in its description within 24 hours, or the claim expires.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-29T08:55:27Z.
The bounded drain landed on the fork's main as commit fff0009e (loader, app: a bounded GPU stop on every exit path).
The run in this issue ended stuck in kernel exit holding 13.7 GB wired, because the unhandled-exception path aborted straight into the kernel's teardown with the GPU wedged and the residency sets still held. Now every path that ends the process stops the GPU first, bounded:
stop_gpu itself was already right (wake the tracked events, wait bounded, pay what is left, empty the residency sets); this wires it to the exits that skipped it. Unit test (x86_64, where the seh dispatcher compiles): the installed stop runs before the abort, and without one an aborting path goes on as it did.
Full gate green in isolation: the native suite incl. victory-metal and victory-backend, the x86_64-apple-darwin suite (hle, loader — the new test — and victory), clippy on windows-gnullvm, cargo xtask policy, all tools/macos/tests/*.sh.
Three of this issue's four items are now done on the fork's main (indirect gate
3f860303, direct caps ad0e5c2d, hung-GPU drop 90f72141, bounded exits fff0009e). What remains is the refusal of translated loops without an iteration counter. Freeing the claim for it.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-29T08:55:28Z.
/release
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-29T08:55:46Z.
Released. This issue is free to claim.