metal, app: wake and drain the GPU's work before exiting on a signal (#357) #358

Open
derz92 wants to merge 2 commits from upstream-pr/358 into main
derz92 commented 2026-11-27 13:58:25 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T13:58:25Z.


What this changes

Refs #357.

SIGTERM, SIGINT and SIGHUP now stop the GPU's work before the process exits, instead of the process dying with command buffers asleep in the kernel:

  • victory_metal::gfx::track_event: the backend remembers, weakly, every shared event it makes: queue order events (create_queue), title fences (create_fence) and piece events (submit_passes with VICTORY_PASSES_PER_BUFFER).
  • victory_metal::gfx::stop_gpu(wait) (re-exported as victory_gpu::stop_gpu):
    • raises each live tracked event to a value above anything awaited (1 << 62), so no command buffer stays asleep on an event nobody will signal;
    • waits up to wait for the command buffers in flight (the existing flights() list) to be reported complete;
    • pays on the CPU, through Owed::recover, whatever is still left;
    • returns (in_flight, left).
  • apps/victory (macOS): main blocks the three signals before any other thread starts, and a thread of its own takes them with sigwait. It logs the stop, calls stop_gpu(3 s), logs the result and exits with 128 + signal. The stop runs as ordinary code, not in a signal handler.

docs/native-host.md has the finding and the change, next to the existing note on Metal's 5 s event-wait limit.

How it was tested

  • cargo test -p victory-metal --lib (arm64): 37 passed. New: a_stop_wakes_command_buffers_waiting_on_events_nobody_signals. A command buffer waits on a fence nobody signals. After waking that fence and the queue's order event, it completes on the GPU within the deadline: its own fence signal is reached, nothing is left to pay, and both events were tracked when made. With nothing woken (checked by running the test with an empty event list), it is still in flight at the deadline (left 1).
  • Game run: Apple M5 Max, macOS 26.5, --console series-s. A watcher's SIGTERM during loading gave stopping: waking and draining the GPU's queued work first signal=15 and then stopped the GPU's work; exiting in_flight=0 left=0, and the process exited at once, without the SIGKILL that follows 15 s later. The GPU driver's "In use system memory" was 1819 MB before the run and 1810 MB after.
  • Caveat: no command buffer happened to be in flight at that stop. The stuck-wait case is covered by the unit test, not by a game run. I haven't yet reproduced the ~20 GB strand on purpose (a 1 GB standalone repro never strands anything, see #357), so I can't yet say this prevents it. It removes the state the kernel log showed at teardown.
  • cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory: all pass except host_posix::ucrt::tests::dlls_that_are_not_the_c_runtime_are_left_alone, which fails the same way on main.
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo xtask policy

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none: host shutdown)
  • New diagnostics are behind a VICTORY_* variable and documented (no new diagnostics; the stop logs two lines when a signal arrives)
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5527852122 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/358). Originally posted by [derz92](https://github.com/derz92) on 2026-11-27T13:58:25Z. --- ## What this changes Refs #357. SIGTERM, SIGINT and SIGHUP now stop the GPU's work before the process exits, instead of the process dying with command buffers asleep in the kernel: - **`victory_metal::gfx::track_event`:** the backend remembers, weakly, every shared event it makes: queue order events (`create_queue`), title fences (`create_fence`) and piece events (`submit_passes` with `VICTORY_PASSES_PER_BUFFER`). - **`victory_metal::gfx::stop_gpu(wait)`** (re-exported as `victory_gpu::stop_gpu`): - raises each live tracked event to a value above anything awaited (1 << 62), so no command buffer stays asleep on an event nobody will signal; - waits up to `wait` for the command buffers in flight (the existing `flights()` list) to be reported complete; - pays on the CPU, through `Owed::recover`, whatever is still left; - returns `(in_flight, left)`. - **`apps/victory`** (macOS): `main` blocks the three signals before any other thread starts, and a thread of its own takes them with `sigwait`. It logs the stop, calls `stop_gpu(3 s)`, logs the result and exits with `128 + signal`. The stop runs as ordinary code, not in a signal handler. docs/native-host.md has the finding and the change, next to the existing note on Metal's 5 s event-wait limit. ## How it was tested - [x] `cargo test -p victory-metal --lib` (arm64): 37 passed. New: `a_stop_wakes_command_buffers_waiting_on_events_nobody_signals`. A command buffer waits on a fence nobody signals. After waking that fence and the queue's order event, it completes on the GPU within the deadline: its own fence signal is reached, nothing is left to pay, and both events were tracked when made. With nothing woken (checked by running the test with an empty event list), it is still in flight at the deadline (`left` 1). - [x] **Game run:** Apple M5 Max, macOS 26.5, `--console series-s`. A watcher's SIGTERM during loading gave `stopping: waking and draining the GPU's queued work first signal=15` and then `stopped the GPU's work; exiting in_flight=0 left=0`, and the process exited at once, without the SIGKILL that follows 15 s later. The GPU driver's "In use system memory" was 1819 MB before the run and 1810 MB after. - **Caveat:** no command buffer happened to be in flight at that stop. The stuck-wait case is covered by the unit test, not by a game run. I haven't yet reproduced the ~20 GB strand on purpose (a 1 GB standalone repro never strands anything, see #357), so I can't yet say this prevents it. It removes the state the kernel log showed at teardown. - [x] `cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory`: all pass except `host_posix::ucrt::tests::dlls_that_are_not_the_c_runtime_are_left_alone`, which fails the same way on main. - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` - [x] `cargo xtask policy` ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none: host shutdown) - [x] New diagnostics are behind a `VICTORY_*` variable and documented (no new diagnostics; the stop logs two lines when a signal arrives)
derz92 commented 2026-11-27 15:02:14 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T15:02:14Z.


A game-run data point for the case the PR is for: a stop with work in flight.

Apple M5 Max, macOS 26.5, --console series-s, VICTORY_METAL_RESIDENCY_SETS=0, this branch on main 728845d1 (with #335, #341, #342). A world run stopped by a watcher's SIGTERM after 240 s in the world (about one frame every 13 s at that point) logged:

stopping: waking and draining the GPU's queued work first signal=15
stopped the GPU's work; exiting in_flight=8 left=0

So 8 command buffers were in flight when the signal came, all completed on the GPU within the 3 s, nothing had to be paid on the CPU, and the process exited by itself before the watcher's SIGKILL (15 s later). The GPU driver's "In use system memory" was 1854 MB before the run and 1165 MB after.

That run didn't hit a GPU time-out, so it still doesn't reproduce the stranded-memory case from #357. It does show the stop working with real work in flight.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7221543027 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/358#issuecomment-7221543027). Originally posted by [derz92](https://github.com/derz92) on 2026-11-27T15:02:14Z. --- A game-run data point for the case the PR is for: a stop with work in flight. Apple M5 Max, macOS 26.5, `--console series-s`, `VICTORY_METAL_RESIDENCY_SETS=0`, this branch on main 728845d1 (with #335, #341, #342). A world run stopped by a watcher's SIGTERM after 240 s in the world (about one frame every 13 s at that point) logged: ``` stopping: waking and draining the GPU's queued work first signal=15 stopped the GPU's work; exiting in_flight=8 left=0 ``` So 8 command buffers were in flight when the signal came, all completed on the GPU within the 3 s, nothing had to be paid on the CPU, and the process exited by itself before the watcher's SIGKILL (15 s later). The GPU driver's "In use system memory" was 1854 MB before the run and 1165 MB after. That run didn't hit a GPU time-out, so it still doesn't reproduce the stranded-memory case from #357. It does show the stop working with real work in flight.
derz92 commented 2026-11-27 15:05:12 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T15:05:12Z.


A correction to the scope of this PR, from the next run.

Same Mac and branch, this time with the default residency mode for 36 GB (mode="a set per heap", switch="unset"). At world entry, about 89 s in, Metal reported a real GPU hang, kIOGPUCommandBufferCallbackErrorHang (code 3), followed by kIOGPUCommandBufferCallbackErrorInnocentVictim. The watcher sent SIGTERM at once. The stop logged in_flight=4 left=4: the hung GPU never completed those four, so they were paid on the CPU. After exit the GPU driver held 19,724 MB "In use system memory" (1,219 MB before the run), and it isn't coming back without a reboot.

So this change does not prevent the strand when the GPU itself hangs. Raising the events can wake command buffers that are waiting, not ones the GPU is stuck executing. It still makes a stop with waiting work clean (the earlier run: in_flight=8 left=0, memory returned), but it can't replace avoiding the hang. I'll update #357 to say so. I'm keeping the PR open as a partial mitigation unless you'd rather not take it on those terms.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7221605498 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/358#issuecomment-7221605498). Originally posted by [derz92](https://github.com/derz92) on 2026-11-27T15:05:12Z. --- A correction to the scope of this PR, from the next run. Same Mac and branch, this time with the default residency mode for 36 GB (`mode="a set per heap"`, `switch="unset"`). At world entry, about 89 s in, Metal reported a real GPU hang, `kIOGPUCommandBufferCallbackErrorHang` (code 3), followed by `kIOGPUCommandBufferCallbackErrorInnocentVictim`. The watcher sent SIGTERM at once. The stop logged `in_flight=4 left=4`: the hung GPU never completed those four, so they were paid on the CPU. After exit the GPU driver held **19,724 MB "In use system memory"** (1,219 MB before the run), and it isn't coming back without a reboot. So **this change does not prevent the strand when the GPU itself hangs.** Raising the events can wake command buffers that are waiting, not ones the GPU is stuck executing. It still makes a stop with waiting work clean (the earlier run: `in_flight=8 left=0`, memory returned), but it can't replace avoiding the hang. I'll update #357 to say so. I'm keeping the PR open as a partial mitigation unless you'd rather not take it on those terms.
derz92 commented 2026-11-27 15:32:12 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T15:32:12Z.


Pushed a second commit (rebased onto main 728845d1): a stop now also empties the residency sets before the process exits.

Why: process exit skips Heap's Drop, so the heaps' residency sets (and the pool's) were still committed, with everything in them, when the process went. In the run that hung the GPU, those sets held about 16 GB, and 19.7 GB stayed "in use" on the driver after exit. The backend now tracks its residency sets weakly (track_residency_set, at create_heap and the pool set), and stop_gpu, after the drain, calls removeAllAllocations and commit on each. It logs stop: residency sets emptied sets=<n> mb=<held>. New test: a_stop_empties_the_residency_sets. docs/native-host.md is updated.

Game run (M5 Max, macOS 26.5, VICTORY_METAL_RESIDENCY_SETS=heap, Series S): about 4 minutes in the world at about 1–2 fps, no GPU errors, stopped by a watcher's SIGTERM:

stopping: waking and draining the GPU's queued work first signal=15
stop: residency sets emptied sets=4 mb=17519
stopped the GPU's work; exiting in_flight=3 left=0

The driver's "In use system memory" was 1447 MB before the run and 699 MB after.

Caveat, as before: this run didn't hang the GPU, so it doesn't yet show the release preventing the strand after a hang. I'll keep running world tests in heap mode, and I'll post here when one hangs, whichever way it goes.

Checks: cargo test -p victory-metal --lib 39 passed; Windows clippy gate clean; cargo xtask policy ok; x86_64 HLE/loader/app tests pass except the ucrt test that fails on main too.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7222176367 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/358#issuecomment-7222176367). Originally posted by [derz92](https://github.com/derz92) on 2026-11-27T15:32:12Z. --- Pushed a second commit (rebased onto main 728845d1): **a stop now also empties the residency sets** before the process exits. **Why:** process exit skips `Heap`'s `Drop`, so the heaps' residency sets (and the pool's) were still committed, with everything in them, when the process went. In the run that hung the GPU, those sets held about 16 GB, and 19.7 GB stayed "in use" on the driver after exit. The backend now tracks its residency sets weakly (`track_residency_set`, at `create_heap` and the pool set), and `stop_gpu`, after the drain, calls `removeAllAllocations` and `commit` on each. It logs `stop: residency sets emptied sets=<n> mb=<held>`. New test: `a_stop_empties_the_residency_sets`. docs/native-host.md is updated. **Game run** (M5 Max, macOS 26.5, `VICTORY_METAL_RESIDENCY_SETS=heap`, Series S): about 4 minutes in the world at about 1–2 fps, no GPU errors, stopped by a watcher's SIGTERM: ``` stopping: waking and draining the GPU's queued work first signal=15 stop: residency sets emptied sets=4 mb=17519 stopped the GPU's work; exiting in_flight=3 left=0 ``` The driver's "In use system memory" was 1447 MB before the run and **699 MB after**. **Caveat, as before:** this run didn't hang the GPU, so it doesn't yet show the release preventing the strand *after a hang*. I'll keep running world tests in heap mode, and I'll post here when one hangs, whichever way it goes. Checks: `cargo test -p victory-metal --lib` 39 passed; Windows clippy gate clean; `cargo xtask policy` ok; x86_64 HLE/loader/app tests pass except the `ucrt` test that fails on main too.
Olima34 commented 2026-11-27 15:37:31 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T15:37:31Z.


@derz92 nice result: sets=4 mb=17519 emptied, and the driver back to 699 MB after exit, is the first stop we've seen give the memory back with the heap sets on. Three things that may help:

  1. Your world-entry hang is probably the same as ours. The command buffer that never ends here holds an ExecuteIndirect dispatch whose record reads as absurd group counts, e.g. [510, 1182027346, 1314076063]. Its writer, compute eee76bf6265f33bb, is refused, so it never stores the record's [0, 1, 1], and the record keeps stale memory. The maintainer sees the same: a step under 1 ms running 25 s on garbage counts. #383 is a guard: a record above 2^22 groups runs nothing. With it, 5 of 6 world runs here went 170–300 s with no GPU error, against 5 of 5 freezing without it. Could you run heap mode with #358 + #383 together? If the Hangs stop, that's the two halves: no hang, and a clean stop if one happens anyway. We're translating eee76bf6 itself now, which is the real fix.
  2. The exit our runs took wasn't a signal. It was the title's own watchdog fault (unhandled exception … image+0x55e56f8, exit 134) after the time-outs. If stop_gpu and the residency-set release only run on SIGTERM, SIGINT and SIGHUP, that path still strands memory. Hooking the same stop into the unhandled-exception or abort path would cover it.
  3. A cost we measured, in case it's useful for #79: each command buffer that attaches the heaps' residency sets costs about 0.35 s of kernel time. That's about the world's 1.3 fps here.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7222284790 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/358#issuecomment-7222284790). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T15:37:31Z. --- @derz92 nice result: `sets=4 mb=17519` emptied, and the driver back to 699 MB after exit, is the first stop we've seen give the memory back with the heap sets on. Three things that may help: 1. **Your world-entry hang is probably the same as ours.** The command buffer that never ends here holds an ExecuteIndirect dispatch whose record reads as absurd group counts, e.g. [510, 1182027346, 1314076063]. Its writer, compute `eee76bf6265f33bb`, is refused, so it never stores the record's [0, 1, 1], and the record keeps stale memory. The maintainer sees the same: a step under 1 ms running 25 s on garbage counts. #383 is a guard: a record above 2^22 groups runs nothing. With it, 5 of 6 world runs here went 170–300 s with no GPU error, against 5 of 5 freezing without it. Could you run heap mode with #358 + #383 together? If the `Hang`s stop, that's the two halves: no hang, and a clean stop if one happens anyway. We're translating `eee76bf6` itself now, which is the real fix. 2. **The exit our runs took wasn't a signal.** It was the title's own watchdog fault (`unhandled exception … image+0x55e56f8`, exit 134) after the time-outs. If `stop_gpu` and the residency-set release only run on SIGTERM, SIGINT and SIGHUP, that path still strands memory. Hooking the same stop into the unhandled-exception or abort path would cover it. 3. **A cost we measured, in case it's useful for #79:** each command buffer that attaches the heaps' residency sets costs about 0.35 s of kernel time. That's about the world's 1.3 fps here.
derz92 commented 2026-11-27 15:55:36 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T15:55:36Z.


@Olima34 here's the run you asked for: heap mode with #358 + #383 together.

M5 Max, 36 GB, macOS 26.5, --console series-s, VICTORY_METAL_RESIDENCY_SETS=heap, VICTORY_TRACE_GPU_FAILS=1, main 728845d1 + #335 #341 #342 + this branch (now also with the fatal-fault hook, below) + #383, plus a local translator change. Cold shader cache.

  • No GPU errors at all: 0 failed command buffers, no Hang or Timeout through the story load and into the world (frame 2176). My own watcher stopped it at 165 s, on a GPU-memory cap I'd set too low for heap mode (22 GB; the sets alone hold ~17 GB).
  • The stop gave it all back: residency sets emptied sets=4 mb=17379, in_flight=0 left=0. "In use system memory" was 1267 MB before and 1992 MB 5 s after exit, then 2.1 GB, not stranded.
  • With the same build without #383, one of two heap-mode runs hung at world entry (…ErrorHang). One run isn't proof, but it fits your 5 of 6.

On your point 2: done. The loader now runs a hook once before the unhandled-exception filter (victory_loader::native::seh::set_fatal_hook), and the app sets it to the same stop_gpu. So the title's watchdog fault drains and empties the sets too. Test the_fatal_hook_runs_once, Windows clippy clean, docs updated. Pushing it to this branch.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7222647572 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/358#issuecomment-7222647572). Originally posted by [derz92](https://github.com/derz92) on 2026-11-27T15:55:36Z. --- @Olima34 here's the run you asked for: heap mode with #358 + #383 together. M5 Max, 36 GB, macOS 26.5, `--console series-s`, `VICTORY_METAL_RESIDENCY_SETS=heap`, `VICTORY_TRACE_GPU_FAILS=1`, main 728845d1 + #335 #341 #342 + this branch (now also with the fatal-fault hook, below) + #383, plus a local translator change. Cold shader cache. - **No GPU errors at all:** 0 failed command buffers, no `Hang` or `Timeout` through the story load and into the world (frame 2176). My own watcher stopped it at 165 s, on a GPU-memory cap I'd set too low for heap mode (22 GB; the sets alone hold ~17 GB). - **The stop gave it all back:** `residency sets emptied sets=4 mb=17379`, `in_flight=0 left=0`. "In use system memory" was 1267 MB before and 1992 MB 5 s after exit, then 2.1 GB, not stranded. - With the same build without #383, one of two heap-mode runs hung at world entry (`…ErrorHang`). One run isn't proof, but it fits your 5 of 6. On your point 2: done. The loader now runs a hook once before the unhandled-exception filter (`victory_loader::native::seh::set_fatal_hook`), and the app sets it to the same `stop_gpu`. So the title's watchdog fault drains and empties the sets too. Test `the_fatal_hook_runs_once`, Windows clippy clean, docs updated. Pushing it to this branch.
Olima34 commented 2026-11-27 16:13:52 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T16:13:52Z.


Thanks @derz92, that's the combined evidence we needed:

  • With #358 + #383 in heap mode: no GPU error into the world, and the sets emptied at stop (17,379 MB), with nothing stranded.
  • Without #383: one of two runs hung at world entry, which matches 5 of 6 here.

The fatal-fault hook covers the exit our runs took. @LakshanSivakumar, from our side these two read as a pair for #79/#357: #383 stops the stale-count hang, and #358 makes any stop, including the title's watchdog fault, give the GPU memory back.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223012508 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/358#issuecomment-7223012508). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T16:13:52Z. --- Thanks @derz92, that's the combined evidence we needed: - With #358 + #383 in heap mode: no GPU error into the world, and the sets emptied at stop (17,379 MB), with nothing stranded. - Without #383: one of two runs hung at world entry, which matches 5 of 6 here. The fatal-fault hook covers the exit our runs took. @LakshanSivakumar, from our side these two read as a pair for #79/#357: #383 stops the stale-count hang, and #358 makes any stop, including the title's watchdog fault, give the GPU memory back.
LakshanSivakumar commented 2026-11-27 16:15:39 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:15:39Z.


Your earlier head (9830ce50) is merged in 4cf84c83. I added one fix on top: after the first signal the stop thread unblocks SIGINT/SIGTERM/SIGHUP, so a second Ctrl-C ends the process if the drain or the exit hangs, and they are unblocked again if the thread cannot be started (9d775ebe). Tests, clippy, policy, release build and a 170 s headless game run passed on that tree. Leaving this open for your new commit 41670d8d (stop on a fatal fault): it runs the GPU stop inside the exception path on the faulting thread, and I have not reviewed or run that yet.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223048918 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/358#issuecomment-7223048918). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T16:15:39Z. --- Your earlier head (9830ce50) is merged in 4cf84c83. I added one fix on top: after the first signal the stop thread unblocks SIGINT/SIGTERM/SIGHUP, so a second Ctrl-C ends the process if the drain or the exit hangs, and they are unblocked again if the thread cannot be started (9d775ebe). Tests, clippy, policy, release build and a 170 s headless game run passed on that tree. Leaving this open for your new commit 41670d8d (stop on a fatal fault): it runs the GPU stop inside the exception path on the faulting thread, and I have not reviewed or run that yet.
Olima34 commented 2026-11-27 16:19:34 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T16:19:34Z.


A correction to my point 3 above. The ~0.35 s of kernel time is not a per-buffer cost, and not the frame-rate ceiling. In a traced 300 s run, only 7 command buffers had 50 ms or more of kernel time (0.31–0.36 s each). They came in 3 episodes about 25 s apart, across 3 queues at once, and each episode held the queues for 1.5–3.3 s with GPU time near 0.

An isolated Metal test shows that an unchanged set of 30,000 textures, or 8 GiB of wrapped memory, costs 0.03 ms per buffer. So an episode looks more like the whole set being re-wired (about 20 GiB) than like attach cost. Its trigger isn't identified yet. It matters for the 5 s limit (#79) rather than for fps.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223125974 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/358#issuecomment-7223125974). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T16:19:34Z. --- A correction to my point 3 above. The ~0.35 s of kernel time is **not** a per-buffer cost, and not the frame-rate ceiling. In a traced 300 s run, only 7 command buffers had 50 ms or more of kernel time (0.31–0.36 s each). They came in 3 episodes about 25 s apart, across 3 queues at once, and each episode held the queues for 1.5–3.3 s with GPU time near 0. An isolated Metal test shows that an unchanged set of 30,000 textures, or 8 GiB of wrapped memory, costs 0.03 ms per buffer. So an episode looks more like the whole set being re-wired (about 20 GiB) than like attach cost. Its trigger isn't identified yet. It matters for the 5 s limit (#79) rather than for fps.
derz92 commented 2026-11-27 19:54:23 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T19:54:23Z.


Rebased onto b998bb65, which already has your second-signal fix (9d775ebe). What's left here is the one commit for stopping on a fatal fault. The conflict in main.rs was only the new spawned handle: the hook is now set before the stop thread starts, and your unblock-on-failure path is untouched. Checks on this tree: victory and victory-loader tests pass (including the_fatal_hook_runs_once), Windows clippy is clean, and policy is ok. The game run that took this path (title watchdog fault → in_flight=8 left=0, sets emptied, driver memory back) is in my comment above.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7226984811 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/358#issuecomment-7226984811). Originally posted by [derz92](https://github.com/derz92) on 2026-11-27T19:54:23Z. --- Rebased onto b998bb65, which already has your second-signal fix (9d775ebe). What's left here is the one commit for stopping on a fatal fault. The conflict in `main.rs` was only the new `spawned` handle: the hook is now set before the stop thread starts, and your unblock-on-failure path is untouched. Checks on this tree: victory and victory-loader tests pass (including `the_fatal_hook_runs_once`), Windows clippy is clean, and policy is ok. The game run that took this path (title watchdog fault → `in_flight=8 left=0`, sets emptied, driver memory back) is in my comment above.
derz92 commented 2026-11-27 23:41:53 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T23:41:53Z.


Rebased onto 86cefd22. The only conflicts were the docs paragraph (your 20 s wait for command buffers still in flight is kept, plus one sentence for the fatal-fault stop) and stop_gpu's new longest argument. The fatal hook now passes the same 3 s / 20 s as the signal path, so both stops wait the same way. I flag it because it means the faulting thread can wait up to 20 s inside the exception path before the unhandled filter runs. If that's too long there, I can pass a shorter limit for the fatal case. Checks: victory and victory-loader tests pass (including the_fatal_hook_runs_once), Windows clippy clean, policy ok.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7230339486 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/358#issuecomment-7230339486). Originally posted by [derz92](https://github.com/derz92) on 2026-11-27T23:41:53Z. --- Rebased onto 86cefd22. The only conflicts were the docs paragraph (your 20 s wait for command buffers still in flight is kept, plus one sentence for the fatal-fault stop) and `stop_gpu`'s new `longest` argument. The fatal hook now passes the same 3 s / 20 s as the signal path, so both stops wait the same way. I flag it because it means the faulting thread can wait up to 20 s inside the exception path before the unhandled filter runs. If that's too long there, I can pass a shorter limit for the fatal case. Checks: victory and victory-loader tests pass (including `the_fatal_hook_runs_once`), Windows clippy clean, policy ok.
Olima34 commented 2026-11-28 00:38:15 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-28T00:38:15Z.

Review: CHANGES_REQUESTED


Thanks @derz92, and for the runs behind it. We read the whole diff of 3ad63471 while helping the maintainer clear the queue. Stopping the GPU on a fatal fault makes sense, but one thing needs changing before it merges, plus a small docs fix:

  1. The hook runs before the title's filter has decided to end the process (dispatch.rs, unhandled). If the filter returns EXCEPTION_CONTINUE_EXECUTION, unhandled resumes the title, but stop_gpu has already raised every event past its awaited value and emptied every residency set. The title then goes on submitting work against heaps that are no longer resident, and fences that are already past their values. Please run the hook only on the paths that end the process: the EXCEPTION_EXECUTE_HANDLER branch before std::process::exit, and before the final abort. If you also want to cover a filter that ends the process itself, the title's own exit/terminate path is the place for that, not before the filter. A test that a filter returning EXCEPTION_CONTINUE_EXECUTION does not run the hook would pin it.
  2. On your question about the 20 s wait: once the hook only runs when the process is ending anyway, waiting as long as the signal path does seems fine to us. The maintainer may still prefer a shorter limit for the fault case, so it's his call.
  3. docs/native-host.md: the same bullet still says "a run that ended on the title's own fault after its time-outs got its memory back", and the new sentence says runs that ended that way "also stranded memory". Please reword the older sentence so the two agree, for example by saying which runs got their memory back and which didn't.

CI is green on this head. We didn't do a game run (the maintainer asked us to work on GitHub only).

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6094676504 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/358#pullrequestreview-6094676504). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-28T00:38:15Z. **Review:** CHANGES_REQUESTED --- Thanks @derz92, and for the runs behind it. We read the whole diff of 3ad63471 while helping the maintainer clear the queue. Stopping the GPU on a fatal fault makes sense, but one thing needs changing before it merges, plus a small docs fix: 1. **The hook runs before the title's filter has decided to end the process** (`dispatch.rs`, `unhandled`). If the filter returns `EXCEPTION_CONTINUE_EXECUTION`, `unhandled` resumes the title, but `stop_gpu` has already raised every event past its awaited value and emptied every residency set. The title then goes on submitting work against heaps that are no longer resident, and fences that are already past their values. Please run the hook only on the paths that end the process: the `EXCEPTION_EXECUTE_HANDLER` branch before `std::process::exit`, and before the final `abort`. If you also want to cover a filter that ends the process itself, the title's own exit/terminate path is the place for that, not before the filter. A test that a filter returning `EXCEPTION_CONTINUE_EXECUTION` does not run the hook would pin it. 2. **On your question about the 20 s wait:** once the hook only runs when the process is ending anyway, waiting as long as the signal path does seems fine to us. The maintainer may still prefer a shorter limit for the fault case, so it's his call. 3. **docs/native-host.md:** the same bullet still says "a run that ended on the title's own fault after its time-outs got its memory back", and the new sentence says runs that ended that way "also stranded memory". Please reword the older sentence so the two agree, for example by saying which runs got their memory back and which didn't. CI is green on this head. We didn't do a game run (the maintainer asked us to work on GitHub only).
derz92 commented 2026-11-28 00:42:02 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-28T00:42:02Z.


@Olima34, thanks, you're right on all three. Fixed in the new head commit:

  1. The hook now runs only when the process ends. unhandled asks the filter first. A new after_filter(answer, ending) turns its answer into Resume, Exit or Abort, and runs the hook only for Exit (before std::process::exit) and Abort (before the final abort), never for EXCEPTION_CONTINUE_EXECUTION. The new test the_fatal_hook_runs_only_when_the_filter_ends_the_process pins it: a resuming filter doesn't run the hook, and execute-handler, any other answer and no filter each run it once. I left a filter that ends the process itself (through the title's own exit) to the existing signal and exit paths, as you suggest.
  2. The 20 s wait: unchanged, the same 3 s / 20 s as the signal path. If the maintainer wants a shorter limit for the fault case, it's a one-line change.
  3. docs/native-host.md: the older sentence now says only one run that ended on the title's own fault got its memory back, and that others didn't. The new sentence says when the hook runs (after the filter, on exit or abort, not on resume) and names both tests.

Checks on this head: victory and victory-loader tests pass, Windows clippy clean, policy ok.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7231124116 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/358#issuecomment-7231124116). Originally posted by [derz92](https://github.com/derz92) on 2026-11-28T00:42:02Z. --- @Olima34, thanks, you're right on all three. Fixed in the new head commit: 1. **The hook now runs only when the process ends.** `unhandled` asks the filter first. A new `after_filter(answer, ending)` turns its answer into `Resume`, `Exit` or `Abort`, and runs the hook only for `Exit` (before `std::process::exit`) and `Abort` (before the final `abort`), never for `EXCEPTION_CONTINUE_EXECUTION`. The new test `the_fatal_hook_runs_only_when_the_filter_ends_the_process` pins it: a resuming filter doesn't run the hook, and execute-handler, any other answer and no filter each run it once. I left a filter that ends the process itself (through the title's own exit) to the existing signal and exit paths, as you suggest. 2. **The 20 s wait:** unchanged, the same 3 s / 20 s as the signal path. If the maintainer wants a shorter limit for the fault case, it's a one-line change. 3. **docs/native-host.md:** the older sentence now says only *one* run that ended on the title's own fault got its memory back, and that others didn't. The new sentence says when the hook runs (after the filter, on exit or abort, not on resume) and names both tests. Checks on this head: victory and victory-loader tests pass, Windows clippy clean, policy ok.
Olima34 commented 2026-11-28 00:46:57 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-28T00:46:57Z.


The maintainer is handling this one himself; please follow his lead rather than my review.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7231187122 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/358#issuecomment-7231187122). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-28T00:46:57Z. --- The maintainer is handling this one himself; please follow his lead rather than my review.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/358:upstream-pr/358'
git switch 'upstream-pr/358'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/358'
git switch 'upstream-pr/358'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/358'
git switch 'upstream-pr/358'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/358'
git switch 'main'
git merge --squash 'upstream-pr/358'
git switch 'main'
git merge --ff-only 'upstream-pr/358'
git switch 'main'
git merge 'upstream-pr/358'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS!358
No description provided.