metal: tables residency per encoder by default (a set kept all of title memory resident) #76

Merged
AeroUp merged 3 commits from upstream-pr/76 into main 2026-11-26 17:08:16 +00:00
AeroUp commented 2026-11-26 13:42:02 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AeroUp on 2026-11-26T13:42:02Z.


What

Heap residency currently goes through one MTLResidencySet per heap (addAllocation on every write_*, useResidencySet on every command buffer). A set never forgets an allocation, and the title names thousands of textures and buffers in its descriptor heaps, so the set held all of title memory plus every host texture copy resident for the whole process. On my Mac that is what turned into kIOGPUCommandBufferCallbackErrorTimeout after the world load (and, with the host's texture copies, kIOGPUCommandBufferCallbackErrorOutOfMemory), followed by the known 0xc0000005 at image+0x55e56f8.

This flips the default to per-encoder useResource (the existing fallback path) and keeps the set path behind VICTORY_METAL_RESIDENCY_SETS=1.

Measured (M3 Pro, 18 GB, macOS 27.2.1, Series S profile, 1920x1080 layer)

The process is x86_64 because it runs the game's x86_64 code in-process; Rosetta translates the CPU side only and the Metal backend is native (no D3D12 or Wine translation). The DXIL converter is D3DMetal's libmetalirconverter because Apple's Metal Shader Converter is not installed on this machine.

sets on (before) sets off (after)
menus ~24 fps, GPU 3 ms 30 fps (the title's own cap), GPU 2.5 ms
story loading art — 8–17 fps, 37–55 ms GPU, 4K
frames timeout ~frame 1950, then 0xc0000005 past 4200+, boot logo and loading art correct
Metal memory 12+ GB and OOM ~9.4 GB

The 4K world's first frames still stall (~20 s) and the title's own watchdog then ends the process; that is a separate problem and this change does not claim to fix it.

Testing

  • cargo build --release --target x86_64-apple-darwin (Metal backend, the host build) clean.
  • The heap tests in crates/victory-metal/tests run in both modes (common::backends()) and pass.
  • Ran the game with the change: boot logo, story loading art (Jason/Lucia) at 1920x1080, 30 fps menus.

Notes

If you would rather keep sets on for speed on bigger machines, an alternative is to prune the set (remove replaced entries and targets) — that is the "not done" in docs/metal-backend.md. Until that exists, this default avoids a failure mode that looks like a hung GPU.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6627932005 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/76). Originally posted by [AeroUp](https://github.com/AeroUp) on 2026-11-26T13:42:02Z. --- ## What Heap residency currently goes through one `MTLResidencySet` per heap (`addAllocation` on every `write_*`, `useResidencySet` on every command buffer). A set never forgets an allocation, and the title names thousands of textures and buffers in its descriptor heaps, so the set held **all of title memory plus every host texture copy resident for the whole process**. On my Mac that is what turned into `kIOGPUCommandBufferCallbackErrorTimeout` after the world load (and, with the host's texture copies, `kIOGPUCommandBufferCallbackErrorOutOfMemory`), followed by the known `0xc0000005 at image+0x55e56f8`. This flips the default to per-encoder `useResource` (the existing fallback path) and keeps the set path behind `VICTORY_METAL_RESIDENCY_SETS=1`. ## Measured (M3 Pro, 18 GB, macOS 27.2.1, Series S profile, 1920x1080 layer) The process is x86_64 because it runs the game's x86_64 code in-process; Rosetta translates the CPU side only and the Metal backend is native (no D3D12 or Wine translation). The DXIL converter is D3DMetal's `libmetalirconverter` because Apple's Metal Shader Converter is not installed on this machine. | | sets on (before) | sets off (after) | |---|---|---| | menus | ~24 fps, GPU 3 ms | **30 fps** (the title's own cap), GPU 2.5 ms | | story loading art | — | **8–17 fps**, 37–55 ms GPU, 4K | | frames | timeout ~frame 1950, then 0xc0000005 | past **4200+**, boot logo and loading art correct | | Metal memory | 12+ GB and OOM | ~9.4 GB | The 4K world's first frames still stall (~20 s) and the title's own watchdog then ends the process; that is a separate problem and this change does not claim to fix it. ## Testing - `cargo build --release --target x86_64-apple-darwin` (Metal backend, the host build) clean. - The heap tests in `crates/victory-metal/tests` run in both modes (`common::backends()`) and pass. - Ran the game with the change: boot logo, story loading art (Jason/Lucia) at 1920x1080, 30 fps menus. ## Notes If you would rather keep sets on for speed on bigger machines, an alternative is to prune the set (remove replaced entries and targets) — that is the "not done" in `docs/metal-backend.md`. Until that exists, this default avoids a failure mode that looks like a hung GPU.
LakshanSivakumar commented 2026-11-26 14:54:56 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T14:54:56Z.

Review: CHANGES_REQUESTED


Thanks. Since this flips the default to per-encoder residency, please update docs/native-host.md (~448), which still names VICTORY_METAL_NO_RESIDENCY_SETS, and document the new VICTORY_METAL_RESIDENCY_SETS switch there.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6076252753 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/76#pullrequestreview-6076252753). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T14:54:56Z. **Review:** CHANGES_REQUESTED --- Thanks. Since this flips the default to per-encoder residency, please update docs/native-host.md (~448), which still names VICTORY_METAL_NO_RESIDENCY_SETS, and document the new VICTORY_METAL_RESIDENCY_SETS switch there.
AeroUp commented 2026-11-26 16:12:44 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AeroUp on 2026-11-26T16:12:44Z.


Done in 563de87: docs/native-host.md no longer names VICTORY_METAL_NO_RESIDENCY_SETS; the ruled-out note now names VICTORY_METAL_RESIDENCY_SETS=1, and a short paragraph there says which path is the default and why (a set never forgets an allocation, so it holds all of title memory plus the host's texture copies, which ends in kIOGPUCommandBufferCallbackErrorTimeout). Pruning the set is listed as not done, as in docs/metal-backend.md.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7197335407 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/76#issuecomment-7197335407). Originally posted by [AeroUp](https://github.com/AeroUp) on 2026-11-26T16:12:44Z. --- Done in 563de87: `docs/native-host.md` no longer names `VICTORY_METAL_NO_RESIDENCY_SETS`; the ruled-out note now names `VICTORY_METAL_RESIDENCY_SETS=1`, and a short paragraph there says which path is the default and why (a set never forgets an allocation, so it holds all of title memory plus the host's texture copies, which ends in `kIOGPUCommandBufferCallbackErrorTimeout`). Pruning the set is listed as not done, as in `docs/metal-backend.md`.
LakshanSivakumar commented 2026-11-26 16:37:58 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T16:37:58Z.

Review: DISMISSED


Docs now name VICTORY_METAL_RESIDENCY_SETS and the new default. Merged onto main, victory-metal and the native tests pass, clippy and policy are clean, CI is green.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6077667645 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/76#pullrequestreview-6077667645). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T16:37:58Z. **Review:** DISMISSED --- Docs now name VICTORY_METAL_RESIDENCY_SETS and the new default. Merged onto main, victory-metal and the native tests pass, clippy and policy are clean, CI is green.
LakshanSivakumar commented 2026-11-26 16:38:52 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T16:38:52Z.


Approved, but main has moved and this now conflicts (docs/native-host.md). Please merge main into the branch and I will merge it right after.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7197917474 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/76#issuecomment-7197917474). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T16:38:52Z. --- Approved, but main has moved and this now conflicts (docs/native-host.md). Please merge main into the branch and I will merge it right after.
AeroUp commented 2026-11-26 16:48:06 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AeroUp on 2026-11-26T16:48:06Z.


Merged upstream/main into the branch. One conflict in docs/native-host.md, resolved by keeping both sides: upstream's new "views of memory in no pool" bullet and this PR's residency paragraph using VICTORY_METAL_RESIDENCY_SETS=1. Release build of victory-metal for x86_64-apple-darwin is clean.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7198112432 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/76#issuecomment-7198112432). Originally posted by [AeroUp](https://github.com/AeroUp) on 2026-11-26T16:48:06Z. --- Merged `upstream/main` into the branch. One conflict in `docs/native-host.md`, resolved by keeping both sides: upstream's new "views of memory in no pool" bullet and this PR's residency paragraph using `VICTORY_METAL_RESIDENCY_SETS=1`. Release build of `victory-metal` for `x86_64-apple-darwin` is clean.
LakshanSivakumar commented 2026-11-26 17:08:38 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T17:08:38Z.


Merged in 8c47ddd. The docs now name VICTORY_METAL_RESIDENCY_SETS, and your merge of main resolved the conflict. Thanks!

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7198562134 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/76#issuecomment-7198562134). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T17:08:38Z. --- Merged in 8c47ddd. The docs now name `VICTORY_METAL_RESIDENCY_SETS`, and your merge of main resolved the conflict. Thanks!
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!76
No description provided.