[bug] Metal residency sets keep all of title memory + host textures resident, then command buffers time out after the world load #79
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-26T13:43:58Z.
Labels:
bug,urgent— written here because this account has no label permission on the repository.Summary
On the native macOS host, heap residency goes through one
MTLResidencySetper heap. A set never forgets an allocation, so after the world load the set holds all of title memory (about 6.7 GB on a Series S profile) plus every texture copy the host made, resident for the whole process. On this Mac that ends inkIOGPUCommandBufferCallbackErrorTimeout(and, with ~5 GB of host texture copies,kIOGPUCommandBufferCallbackErrorOutOfMemory), then the known0xc0000005 at image+0x55e56f8.Switching the default to per-encoder
useResource(the existing fallback) fixed it here: frames pass 4200 where they used to stop at ~1950, and the boot logo and story loading art render correctly.Evidence (M3 Pro, 18 GB, macOS 27.2.1, Series S profile, 1920x1080 layer)
The process is x86_64 because it executes 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 of API calls). The DXIL converter is D3DMetal's
libmetalirconverterbecause Apple's Metal Shader Converter is not installed on this machine.With sets (before):
With sets off:
Proposal
PR #76 flips the default to per-encoder
useResourceand keeps the set path behindVICTORY_METAL_RESIDENCY_SETS=1. The better long-term fix is to prune the set (remove a replaced entry's old allocation, remove targets), whichdocs/metal-backend.mdlists as not done.Not claimed
The 4K world's first frames still stall about 20 s and the title's own watchdog then takes the process down (the crash log says
Unsignaled CrossQueueBarrierin some runs and nothing in others). This issue is only the residency/OOM/timeout chain.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T15:56:44Z.
Status: PR #76 (per-encoder residency by default) is open with changes requested, not merged. Needed: updated #76, then a run on a 16 GB Mac (see #8) to confirm the command-buffer timeouts go away.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T22:52:57Z.
Update: the heap residency set is on main (
3009640b), and since0133b82ereleased textures leave it. It's on by default on 32 GB and up. 16–24 GB testers: please tryVICTORY_METAL_RESIDENCY_SETS=heapon current main and report theheap_set_mblines and any command-buffer errors.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sandile-0511 on 2026-11-27T05:40:13Z.
A data point from a 24 GB Mac, since the README asks for one:
VICTORY_METAL_RESIDENCY_SETS=heapgets this machine past the title's 30 s watchdog at the first world frame, which the default (per-encoderuseResource) does not. It is not clean: one of three runs had four out-of-memory command buffers.Machine: MacBook Pro, Apple M5 (base), 24 GB, macOS 26.5.1, Series S profile (
title_memory_mib=7776,recommended_working_set_mib=18186). Commit76c001aunless noted. Warm shader cache in every run below.Default: per-encoder
useResourceVICTORY_HOLD_BYTE: the watchdog fault (image+0x23cf683, thenimage+0x55e56f8) 31 s after the first world frame.VICTORY_HOLD_BYTE=1471b6330:1: 9 frames in the 123 s after the world frame. WithVICTORY_TRACE_GPU_FAILS=1, 93slow command bufferlines after the world frame (the 100-line cap nearly reached), the longest with 5.1 s between GPU start and end.VICTORY_SHADER_LOOP_LIMIT(64, diagnostics build) changed nothing either. This matches the note indocs/native-host.mdabout the kernel's time per pass for theuseResourcelist.VICTORY_METAL_RESIDENCY_SETS=heapslow command bufferlineskIOGPUCommandBufferCallbackErrorOutOfMemory2a3b03d+ #260)heap_set_mb=17862 heap_allocations=68040.a command buffer failed; paid 0 fence signals and N value writes on the CPU(N = 4, 8, 20, 8), and the title went on. No timeout errors.Memory
Sampled once during a default run and once during run 1: about 21.7 GB wired in both, 5% free, swap 7.0 to 7.4 GB of 8.2 GB in use, with the kernel compressing and decompressing about 3 GB a second in the default run. So this Mac is at its limit in either mode; the sets remove the per-pass cost but not the pressure.
What I did not check
I can attach logs from any of these runs, or rerun with other switches, if that helps.
AI-assisted: runs and log summary done with Claude Code on my own machine; I reviewed the text.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T06:46:15Z.
Some data for this issue, from an Apple M5 Pro with 48 GB, Series S, windowed, on main
2a3b03d1.48 GB isn't spared. In every world run the Mac reaches its memory limit:
kern.memorystatus_leveldown to 6–8%;heap_set_mb17.3–18.7 GB.Under extra load (target tracing), 2 of 3 runs hit a command buffer that never completes, with the "this is what running out of memory looks like" message. The stuck buffers of the two traced hangs share no shader. Kernel time is far above GPU time in the slow buffers just before (e.g. 1.37 s total, 0.013 s GPU, 0.475 s kernel), which is the same pattern as the 24 GB measurements above. The latest 5 untraced runs all lived to 300 s.
VICTORY_METAL_RESIDENCY_SETS=1survived 3 of 3 runs. But the frame rate after the world was 5x lower (~0.3 fps vs ~1.6) and the memory pressure was unchanged, so it isn't a fix.Is evicting idle heap-set allocations a lever? No. A local diagnostic counted each underlying allocation in the heap sets once, with the last time a bound table named it, over a warm 300 s run (world frames 2176–2496):
So time-based eviction would save nothing in the world. The never-named textures are most likely the materials shaders reach by indexing the heap themselves, which the host doesn't see, so evicting them would break bindless reads. The remaining levers look like:
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T06:48:19Z.
Thank you for the careful runs. This is the first data point I have for a 24 GB Mac with the heap residency set, and the table is clear about what each run did and did not show.
Yes please, attach the log of run 2. I would like to see the lines before the first failed command buffer and the counter lines around it. I have not checked whether those failures are tied to the world load or only to later frames.
I have also not checked a 16 or 18 GB Mac. If someone has one, a run with
VICTORY_METAL_RESIDENCY_SETS=heapand the same counters would help.Your pull request #260 gets its own review.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sandile-0511 on 2026-11-27T07:46:54Z.
The log of run 2 is here: https://gist.github.com/Sandile-0511/fca19a0bc62954beec486f1e3dcb380f. Colour codes are removed, and my home path and the Mac's network name are replaced (
~,REDACTED-HOST); nothing else is changed. It is76c001a,VICTORY_METAL_RESIDENCY_SETS=heap, no other switch.Where to look:
a command buffer failed; paid 0 fence signals and N value writes on the CPU.native draws so farcounter line between the world frame and the failures: the world advanced 28 frames in those 152 s, fewer than the 64 a counter line takes.a descriptor was not mirrored ... is not in a mapped pool, among them0x247e0000+0xae00000and0xd08d40000+0x3200000: the two sizes #258 is about.So in this run the failures come well after the world load, not at it. I have not looked at what the failing buffers held; the run had no
VICTORY_TRACE_GPU_FAILS.AI-assisted: log summary done with Claude Code on my own machine; I reviewed the text.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T08:08:01Z.
Thank you. This is the most useful memory data I have: a 48 GB Mac is not spared, and the table shows why time-based eviction would save nothing, because the 8.3 GB the world never names through a bound table is most likely what the shaders reach by indexing the heap themselves.
So the two levers you name are the ones left: not keeping each sampled texture twice, and a switch that drops the top mips. I agree the first is a large change, and I will not start it without a measurement of how much of the 9.2 GB is the second copy.
One request. Could the diagnostic that counts each allocation once, with the last time a bound table named it, go in as a pull request behind a switch, off by default? Then others can send the same table from 16 and 24 GB Macs, which is what we lack.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T08:08:03Z.
Thank you for the log, for removing the colour codes and the host name, and for the line numbers.
What I take from your reading: the failures come about 100 seconds after the world load, not at it, and the world moved only 28 frames in 152 seconds, so the Mac was already starved before the first failed command buffer. I have not read the log myself yet; I am relying on your reading.
The two sizes before the first failure are the two in #258:
0xae00000is the 174 MiB view and0x3200000is 50 MiB, which matches entry 9936. If #267 and #264 land, those lines may change; I have not checked.If you run it once more, please add
VICTORY_TRACE_GPU_FAILS=1so we see what the failing buffers held. The 16 and 18 GB Macs are still missing.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T09:04:35Z.
Yes. The diagnostic will come as a pull request behind a switch (
VICTORY_TRACE_HEAP_SET=<frames>, off by default, documented, with its Metal test), so 16 and 24 GB Macs can send the same table. For each heap set, it counts every underlying allocation once and splits textures from buffers, with the last time a bound table named each one.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Tarraga on 2026-11-27T09:16:08Z.
/claim the command-buffer time-out piece only: a submission's passes go in command buffers of at most N passes (
VICTORY_PASSES_PER_BUFFER), each piece with the heaps' residency sets attached again. Not the residency pruning or the memory side.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-27T09:16:20Z.
Claimed by @Tarraga. Open a draft pull request with
Refs #79in its description within 24 hours, or the claim expires.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by alexballvideos-netizen on 2026-11-27T13:48:59Z.
A data point from a 36 GB Mac on the Series X profile: wired memory climbs to the Metal recommended working set, then command buffers time out.
Setup. M3 Max, 36 GB, macOS 27.2.1, main
86786a72,run-native.sh --seconds 300, windowed. Defaults throughout: console Series X (title_memory_mib=13824), residencymode="a set per heap" memory_gb=36 switch="unset". Warm shader cache. Only the game and one other app were open. System memory was sampled every 5 s (vm_stat,memory_pressure,kern.memorystatus_vm_pressure_level, the process RSS).kIOGPUCommandBufferCallbackErrorTimeout(20 in all)image+0x55e56f8, end of runrecommended_working_set_mib=28753(28.1 GB). Peak wired, 28.25 GB, was at that limit when the time-outs ended the run.heap_set_mbon the frame lines was 24,944.5 command buffers were never reported on by the GPU (the first unreported for 22.1s).Even with 36 GB and the heap sets on by default, the world reaches the working-set limit within about 1.5 minutes. Then the GPU stops reporting and the title dies. This matches the description here: the sets hold the world's heap resident, about 25 GB on its own.
Happy to repeat with
VICTORY_METAL_RESIDENCY_SETS=0or--console series-sfor comparison if that helps. Counts only.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T14:10:02Z.
Numbers from tonight on my Mac (recommended working set 38,338 MiB, "a set per heap", heap set about 19,000 MB, Series S, headless unless said):
b639c175b639c17560baf130+ pixel input enablesb639c175VICTORY_PASSES_PER_BUFFER=102ecf394VICTORY_METAL_RESIDENCY_SETS=0aa43c491, windowedgpu 0.002s) while the buffer takes 1.1 to 1.8 s, and many of them have 0 passes. So the queue stalls; it is not one shader running long. Translated loops are capped anyway.I am looking at a middle design (keep resident only what a buffer's passes name, or cap the host copies). If anyone has a run with
VICTORY_METAL_RESIDENCY_SETS=0that is NOT slow, please post the Mac and the fps.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T14:28:37Z.
A measured cause for the stall that ends world runs (2–4 min), on main
905e7aad: M5 Pro 48 GB, Series S, 5 headless runs, with the GPU memory released after each one.IOGPUFamily Cmd queue sleep port_name … value … timed out!. The buffer that times out is the next one in the queue, waiting on the ordering (or piece) event of the buffer before it. That earlier buffer never completes ("never reported on").VICTORY_TRACE_GPU_FAILS. Compute0af6bb55…gets [510, 1182027346, 1314076063] groups. Word 0 looks sane and GPU-written; words 1 and 2 are stale float bits. Two other records of the same pass sit 4 bytes apart.docs/native-host.mdmarks as a guess ("three group counts"). If its record holds one word, y and z are noise.VICTORY_PASSES_PER_BUFFER=1hits the same stall at +110–190 s.We're checking the signature now, and a fix with a test will follow. That's why the queue stops, and probably why the kernel kept GPU memory and froze WindowServer on our Mac several times today.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by alexballvideos-netizen on 2026-11-27T14:37:11Z.
VICTORY_METAL_RESIDENCY_SETS=0on the M3 Max, 36 GB, Series X: stable, but slow, and slower than on your Mac.Setup.
a3b26747(main728845d1plus #373, a shader-only change), macOS 27.2.1,--console series-x, headless, 300 s, warm cache. Host line:mode="useResource per encoder" memory_gb=36 switch="0". System memory sampled every 5 s.mesh>0) from frame ~1472 at +84 s.kIOGPUCommandBufferCallbackErrorTimeout, no crash, ran to the timer.So it isn't a "not slow" run: on this Mac, per-encoder naming costs 20 to 24 s a world frame, against your 12 to 14. It does confirm the trade-off: no queue stall and no memory pressure without the sets. Counts only.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T15:05:01Z.
An update to my comment above, correcting the suspect. The console signature "type 105" is not the cause: its records do hold [x,1,1]. The record the GPU reads as [510, 1182027346, 1314076063] is a standard 12-byte dispatch record, and its y and z are never written.
The fix being tested: an indirect dispatch record with more than 65,535 groups in any dimension (the D3D12 limit) launches nothing, and is logged. Without it, 5 of 5 world runs froze at +110–190 s. With it, 4 runs went 170–300 s with no GPU error. A fifth froze at +126 s with sane counts, which points to a second cause, still being checked: a compute retry loop around
buffer_atomic_cmpswapthat may never exit. A PR with a Metal test will follow.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T15:05:14Z.
Two world-entry runs from an M5 Max, 36 GB, macOS 26.5 (
--console series-s, main728845d1plus #335, #341, #342 and #358), A/B on the residency mode:VICTORY_METAL_RESIDENCY_SETS0(per encoder)a set per heap(the 36 GB default)kIOGPUCommandBufferCallbackErrorHang(code 3), then…InnocentVictimFree system memory was about 20–25% during the world in both. Earlier today a heap-set run reached the world and then hit
kIOGPUCommandBufferCallbackErrorTimeoutat about 180 s, and it also stranded about 20 GB. So on this Mac the per-heap sets hang or time out around the world load, while per-encoder residency survives but is far too slow.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by maaalrey on 2026-11-27T20:52:01Z.
A data point from an M4 Max, 128 GB, macOS 27.2.1: after a run of stops at the first Metal error, the GPU stayed hung for WindowServer with no game running, until a restart. Windowed, default per-heap residency sets (
memory_gb=128).My runner stops the game at the first
IOGPUMetalErrorin the system log: SIGTERM, then SIGKILL 3 s later. Over 99 minutes it did that eight times, always in a world run. About a dozen other runs in between ended another way: most on my timer (also a SIGTERM, in the world, with no Metal error and no trouble afterwards), two at the title's own fault.86786a760baf130c1b9587b639c175b639c175,VICTORY_PASSES_PER_BUFFER=1In the first seven, the game's own log has one
work held for a wait that does not holdwarning and no failed command buffer; the error was only in the system log. The eighth has 25command buffer failedlines withkIOGPUCommandBufferCallbackErrorTimeout.37 s after the eighth stop the watchdog killed WindowServer ("40 seconds since last successful checkin"). A WindowServer report was then written about every 50 s for 20 minutes, and hang reports at intervals for hours, until the Mac was restarted. No game process was running in that time.
So after the eighth the GPU was unusable for every later client. The time-out came before my stop, so I cannot tell which of the two did it. The first seven left no sign I noticed.