native: a byte budget on host texture copies (evict unused ones under memory pressure) #294
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 m0rff on 2026-11-27T09:10:19Z.
Piece of #8 (16–24 GB Macs run out of GPU memory), proposed in #110.
What is wrong. On the native host a host texture copy is made when a view first names a texture (
Title::realize, called fromglue::mirrorfor every device-written view, staging heaps included) and kept until the title releases the resource, or, for a placed texture, until another texture takes its address or its pool is released. Nothing bounds their total. On electrifie's M4 16 GB run in #8 the host made ~13,000 new copies during the first load while the footprint grew ~7.6 GB, and Metal then failed ordinary command buffers withkIOGPUCommandBufferCallbackErrorOutOfMemory. #252 (hot-texture expiry) and2d4cd0a1(sync off the lock) change probing and sync cost, not how many copies live.Plan.
recommendedMaxWorkingSetSizeminus the title's memory (both logged at startup since #149), with a floor;VICTORY_METAL_TEXTURE_BUDGET_MBoverrides it.VICTORY_METAL_RESIDENCY_SETS=heap(the last reference leaving takes it out of the set).Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by m0rff on 2026-11-27T09:10:24Z.
/claim
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-27T09:10:36Z.
Claimed by @m0rff. Open a draft pull request with
Refs #294in its description within 24 hours, or the claim expires.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Hayyan612 on 2026-11-27T15:37:19Z.
@m0rff, an idea that might fit alongside the byte budget, before anyone builds it. Not claiming anything.
Every host texture copy can be rebuilt from title memory, since that's what texture sync does on a change. So instead of only evicting copies over budget, idle copies could be marked purgeable (
setPurgeableState(.volatile)): macOS/iOS then reclaims them under real memory pressure, rather than the process hittingOutOfMemoryor being killed, and leaves them alone when there's room. On next use,setPurgeableState(.nonVolatile)returns the previous state; if it was.empty, the copy is detiled again from title memory, as after a change.How it might combine with #301: the budget decides when a copy is idle enough; purgeable decides whether the OS needs the memory back, so an idle copy that fits stays warm instead of being re-detiled.
Open questions:
MTLHeap? Purgeable state is per heap for placed resources, so it would only suit standalone copies.Happy to build and test it (state transitions, and the rebuild path with a simulated purge) if it fits your design, or leave it to you.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by m0rff on 2026-11-27T15:40:43Z.
@Hayyan612 thanks. One limit to check before building: shaders index heaps themselves (#79), so the host can't tell when a copy that a heap entry shows is read, and it could not safely be volatile. That leaves the copies no entry shows and no list holds, the same set #301 may give up, and testers' 24 GB runs found little in it (about 310 MiB over a run). The larger cost there is copies overlapping one range (#356, draft #359). I won't build purgeable copies in #301. If you want to try it, open your own issue and measure how much would qualify first.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Hayyan612 on 2026-11-27T15:44:28Z.
Thanks @m0rff, that settles it: if heap-indexed copies can't be volatile, ~310 MiB isn't worth the complexity, and #356/#359 is the bigger win. I'll leave it unless a measurement shows otherwise.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by m0rff on 2026-11-27T22:46:09Z.
Done on main through #359 (
582670f1), with the budget off by default. The overlap work continues on #356.