gpu: a compiler crash spends the rest of the frame's pipeline budget #318

Manually merged
github merged 2 commits from github-bot/gh-318 into main 2026-11-27 13:38:56 +00:00 AGit
Owner

@⁠ShadyUnderLight on GitHub · 2026-11-27 11:15 UTC · original
ShadyUnderLight:fix/compile-crash-spends-frame-budget → main · +196 −6 · 7 files · 2 commits · closed without merging

Refs #181

What and why

Issue #181: Metal's compiler service crashes on a few world pipelines, and each crash costs the frame about 0.85 s while Metal retries. #263 fixes the cause for the mesh and pixel pairs it dumped (invalid IR from the export order). This is the safety net the issue asks for on top of that fix: a crash must not be paid for again and again inside one frame.

Measured on one run of main (commit 38786fd, macOS 27.2.1, M5 Max, series-x, cold crash cache): nine XPC_ERROR_CONNECTION_INTERRUPTED refusals all landed in frame~2259, from 05:19:27.027 to 05:19:34.304 — 7.3 s of one frame, about 0.85 s each, all of it spent waiting for compiles that died. The frame cannot advance meanwhile, and the title's own watchdog is 30 s.

What changed

  • victory_metal::is_compiler_crash is public. It is the predicate the crash cache already used (XPC_ERROR_CONNECTION_INTERRUPTED, Compiler encountered an internal error): Metal's compiler dying on the pipeline, not a shader the host cannot run.
  • prewarm::FrameBudget gains spend() and spent_by_crash(). A frame can now be spent before its 10 s of wall time: left() is zero for the rest of it, and the next frame starts whole.
  • glue::compile_failed(name, error): when a compile ends in a compiler crash it spends the rest of the frame's budget and warns once a frame (a compile crashed Metal's compiler; no new pipelines this frame).
  • glue::compile_wait: a frame that a crash spent returns zero — it does not hand out the 20 ms ARCHIVED window that a frame merely past its time still gets. The compiler service is usually down for the rest of such a frame, and that window let 12 pipelines of one frame be refused within 0.22 s, each cached as refused and remembered by remember_crash as a crash of its own.
  • Both Err arms of Title::make_render and Title::make_compute call it.
  • docs/native-host.md: the compiler-crash section says so, with the numbers.

Nothing else changes: FIRST_BIND_BUDGET (10 s), COMPILE_DEADLINE (60 s) and the wait that a frame past its time gets are untouched, and a pipeline whose compile failed with a host error is refused exactly as before.

Tests

  • prewarm::tests::a_spent_frame_starts_the_next_one_whole: a crash-spent frame reports zero for the rest of it and spent_by_crash(); a frame merely past its time does not; the next frame clears both.
  • native::glue::a_compiler_crash_spends_the_frame_budget: the real XPC text spends the frame; a non-crash refusal (a target format the host does not know) does not.

Both fail without the change: the spend was removed and then the classification was removed, each time the relevant assertion failed, then both were restored.

Verification on a real run

Same machine, headless, series-x, cold crash cache, 230 s:

  • Before (38786fd): 9 crashes in one frame over 7.304 s, as above.
  • After (this branch): the first crash of frame 2347 (vertex a1785729710c22b3 pixel 80b896aafd2ec5f4, after a 677 ms mesh compile) spends the budget, and the frame's next pipelines are put off within 22 ms (put_off=1, 2, 4 in the log). The 16 frames that logged the warning had no second paid crash. Refusals that follow a crash in the same frame, once the service is down, come back instantly (11 of them in 47 ms) instead of waiting about 0.85 s each.

That run also ended with no GPU error and no watchdog line, but it was killed by the timer at 230 s and reached frame 2103 against 2334 in the run it is compared with, so I am not claiming that as an effect of this change.

cargo test -p victory-gpu -p victory-metal -p victory-shader (native arm64): 321 / 33 / 12 / 14 / 332 passed, 0 failed. cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings: clean. cargo xtask policy: 371 files ok. main at ce2b7860 is merged in, and the checks above are on the merged tree.

Not addressed

  • A single crash still costs the frame what Metal spends on it, up to what is left of the frame's budget (about 10 s on macOS 15). Bounding the first crash of a frame would need a per-pipeline cap, which is a different trade: it would also put off slow compiles that would have landed.
  • Pipelines attempted while the service is down are still refused and recorded by remember_crash as if they had crashed on their own. That is existing behaviour on main; this change only reduces how many are attempted. Skipping the record when the frame was already spent by a crash would be a separate change.
  • Crash-affected frames put more pipelines off (8192 in this run against 2048 in the compared one). They are made on later frames, as the put-off path already does.
**@⁠ShadyUnderLight** on GitHub · 2026-11-27 11:15 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/318) `ShadyUnderLight:fix/compile-crash-spends-frame-budget` → `main` · +196 −6 · 7 files · 2 commits · closed without merging Refs #181 ## What and why Issue #181: Metal's compiler service crashes on a few world pipelines, and each crash costs the frame about 0.85 s while Metal retries. #263 fixes the cause for the mesh and pixel pairs it dumped (invalid IR from the export order). This is the safety net the issue asks for on top of that fix: a crash must not be paid for again and again inside one frame. Measured on one run of `main` (commit 38786fd, macOS 27.2.1, M5 Max, series-x, cold crash cache): nine `XPC_ERROR_CONNECTION_INTERRUPTED` refusals all landed in `frame~2259`, from 05:19:27.027 to 05:19:34.304 — 7.3 s of one frame, about 0.85 s each, all of it spent waiting for compiles that died. The frame cannot advance meanwhile, and the title's own watchdog is 30 s. ## What changed - `victory_metal::is_compiler_crash` is public. It is the predicate the crash cache already used (`XPC_ERROR_CONNECTION_INTERRUPTED`, `Compiler encountered an internal error`): Metal's compiler dying on the pipeline, not a shader the host cannot run. - `prewarm::FrameBudget` gains `spend()` and `spent_by_crash()`. A frame can now be spent before its 10 s of wall time: `left()` is zero for the rest of it, and the next frame starts whole. - `glue::compile_failed(name, error)`: when a compile ends in a compiler crash it spends the rest of the frame's budget and warns once a frame (`a compile crashed Metal's compiler; no new pipelines this frame`). - `glue::compile_wait`: a frame that a crash spent returns zero — it does not hand out the 20 ms `ARCHIVED` window that a frame merely past its time still gets. The compiler service is usually down for the rest of such a frame, and that window let 12 pipelines of one frame be refused within 0.22 s, each cached as refused and remembered by `remember_crash` as a crash of its own. - Both `Err` arms of `Title::make_render` and `Title::make_compute` call it. - `docs/native-host.md`: the compiler-crash section says so, with the numbers. Nothing else changes: `FIRST_BIND_BUDGET` (10 s), `COMPILE_DEADLINE` (60 s) and the wait that a frame past its time gets are untouched, and a pipeline whose compile failed with a host error is refused exactly as before. ## Tests - `prewarm::tests::a_spent_frame_starts_the_next_one_whole`: a crash-spent frame reports zero for the rest of it and `spent_by_crash()`; a frame merely past its time does not; the next frame clears both. - `native::glue::a_compiler_crash_spends_the_frame_budget`: the real XPC text spends the frame; a non-crash refusal (`a target format the host does not know`) does not. Both fail without the change: the spend was removed and then the classification was removed, each time the relevant assertion failed, then both were restored. ## Verification on a real run Same machine, headless, `series-x`, cold crash cache, 230 s: - Before (38786fd): 9 crashes in one frame over 7.304 s, as above. - After (this branch): the first crash of `frame 2347` (`vertex a1785729710c22b3 pixel 80b896aafd2ec5f4`, after a 677 ms mesh compile) spends the budget, and the frame's next pipelines are put off within 22 ms (`put_off=1`, `2`, `4` in the log). The 16 frames that logged the warning had no second paid crash. Refusals that follow a crash in the same frame, once the service is down, come back instantly (11 of them in 47 ms) instead of waiting about 0.85 s each. That run also ended with no GPU error and no watchdog line, but it was killed by the timer at 230 s and reached frame 2103 against 2334 in the run it is compared with, so I am not claiming that as an effect of this change. `cargo test -p victory-gpu -p victory-metal -p victory-shader` (native arm64): 321 / 33 / 12 / 14 / 332 passed, 0 failed. `cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings`: clean. `cargo xtask policy`: 371 files ok. `main` at `ce2b7860` is merged in, and the checks above are on the merged tree. ## Not addressed - A single crash still costs the frame what Metal spends on it, up to what is left of the frame's budget (about 10 s on macOS 15). Bounding the first crash of a frame would need a per-pipeline cap, which is a different trade: it would also put off slow compiles that would have landed. - Pipelines attempted while the service is down are still refused and recorded by `remember_crash` as if they had crashed on their own. That is existing behaviour on `main`; this change only reduces how many are attempted. Skipping the record when the frame was already spent by a crash would be a separate change. - Crash-affected frames put more pipelines off (8192 in this run against 2048 in the compared one). They are made on later frames, as the put-off path already does.
Before (commit 38786fd): 9 XPC_ERROR_CONNECTION_INTERRUPTED crashes in one
frame (frame~2259) between 05:19:27.027 and 05:19:34.304 -- 7.3 s of that
frame waiting for compiles that all died, about 0.85 s each.

After (this commit, cold crash cache): the first crash of frame~2347 (vertex
a1785729710c22b3 pixel 80b896aafd2ec5f4, after a 677 ms mesh compile) spends
the frame's budget, and the same frame's next pipelines are put off within
22 ms (put_off 1, 2, 4). The 15 frames that logged the warning paid no second
crash.

After the first crash in a frame the budget is zero, and a frame a crash spent
is handed no new pipeline at all: glue::compile_wait gives it not even the
20 ms window a pipeline the archive holds takes. Without that, a frame whose
compiler service was already down still tried 12 more pipelines in 0.22 s;
each failed at once and was refused and remembered as a crash of its own,
although the service being down was not the pipeline's fault. They are retried
on later frames, where the crash cache refuses the bad ones instantly.

victory_metal::is_compiler_crash (now public) names the errors that are
Metal's compiler dying rather than a shader the host cannot run; a compile
that ends in one spends the frame's budget (glue::compile_failed, called from
both of Title's make_* Err arms) and warns once a frame.

Not addressed: the crash itself still costs the frame what Metal spent on it
(677 ms in that run; up to the frame's remaining budget, about 10 s on
macOS 15), and the root cause -- the invalid IR from export ordering
(PR #263) -- is untouched.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 11:17:43 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 11:54 UTC · original

Thank you for taking the second half of #181 and for writing down what the change does not fix.

Two questions before it leaves draft.

  1. After a crash the rest of the frame's new pipelines are put off, including ones that would have compiled. If a pipeline that crashes is needed in every frame, do the others ever get their turn? Please show the number of pipelines put off and made, by frame, over a longer run on current main (with #263 if you can).
  2. Your run used an older main. Please repeat it on ce2b7860 and post the same two numbers (crashes in one frame and time spent).

I have not run it. Counts and ids only, as before.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 11:54 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/318#issuecomment-7217608210) Thank you for taking the second half of #181 and for writing down what the change does not fix. Two questions before it leaves draft. 1. After a crash the rest of the frame's new pipelines are put off, including ones that would have compiled. If a pipeline that crashes is needed in every frame, do the others ever get their turn? Please show the number of pipelines put off and made, by frame, over a longer run on current main (with #263 if you can). 2. Your run used an older main. Please repeat it on `ce2b7860` and post the same two numbers (crashes in one frame and time spent). I have not run it. Counts and ids only, as before.
github manually merged commit 5cdb9e056b into main 2026-11-27 13:38:56 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 13:36 UTC · original

This is on main as of b639c175, merged from the head before your latest push, so GitHub still shows the PR open. Your commits are in the history under your name. Checked as part of a batch of nine PRs on main 60baf130: tests, Windows clippy, policy, a full-corpus comparison and one world run (240 s, no crash, no GPU errors, scene colour lit).

If your new head has changes beyond a rebase, please rebase it onto main so only those remain; otherwise please close this. Thank you.

On my question about whether other pipelines ever get their turn: a remembered crash is refused with a message that is not counted as a crash, so it does not take the frame's budget again. That answers it.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 13:36 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/318#issuecomment-7219707619) This is on main as of b639c175, merged from the head before your latest push, so GitHub still shows the PR open. Your commits are in the history under your name. Checked as part of a batch of nine PRs on main 60baf130: tests, Windows clippy, policy, a full-corpus comparison and one world run (240 s, no crash, no GPU errors, scene colour lit). If your new head has changes beyond a rebase, please rebase it onto main so only those remain; otherwise please close this. Thank you. On my question about whether other pipelines ever get their turn: a remembered crash is refused with a message that is not counted as a crash, so it does not take the frame's budget again. That answers it.
Author
Owner

@⁠ShadyUnderLight on GitHub · 2026-11-27 13:43 UTC · original

Thank you — I see 3a03e6ed in main (merged as 5cdb9e05), so the fix is in and there is nothing left to review here.

The only thing in this head beyond that merge is the diagnostic line I added while working on your put-off/made question: the frame log had no pipeline counters. I have split that out as its own change against current main: #353. Nothing else remains, so I am closing this one.

On the remembered crash: agreed, and thank you for checking it. That refusal comes from the crash memory, its message is not one of the two a crash is recognised by, so it does not spend the frame budget again and the frame.s other pipelines get their turn.

**@⁠ShadyUnderLight** on GitHub · 2026-11-27 13:43 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/318#issuecomment-7219864380) Thank you — I see `3a03e6ed` in `main` (merged as `5cdb9e05`), so the fix is in and there is nothing left to review here. The only thing in this head beyond that merge is the diagnostic line I added while working on your put-off/made question: the frame log had no pipeline counters. I have split that out as its own change against current `main`: #353. Nothing else remains, so I am closing this one. On the remembered crash: agreed, and thank you for checking it. That refusal comes from the crash memory, its message is not one of the two a crash is recognised by, so it does not spend the frame budget again and the frame.s other pipelines get their turn.
This discussion has been locked. Commenting is limited to contributors.
No description provided.