metal: detach replaced and dropped heap allocations from MTLResidencySet #32
No reviewers
Labels
No labels
accessibility
bug
claimed
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
tester report
urgent
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LakshanSivakumar--Native-Victory-macOS!32
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/32/head"
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?
@claytonblythe on GitHub · 2026-11-26 10:46 UTC · original
claytonblythe:fix/metal-residency-set-lifecycle→main· +76 −5 · 2 files · 2 commits · merged 2026-11-26 10:59 UTCSummary
During a long headed Story Mode streaming run on macOS 26 (Darwin 25.3.0, Apple M4), the host hit an Apple Silicon
IOGPUkernel panic:IOGPUGroupMemorybacksMTLResidencySet. Inspectingcrates/victory-metal/src/gfx.rsshows two residency-set lifecycle bugs onHeap:Metal::heap_entryoverwroteheap.refs[index](dropping the oldMTLResource) without ever callingset.removeAllocation+set.commit(), and calledset.addAllocationredundantly on every write even when the same resource was already in the set.Heaphad noDropimplementation, so Rust droppedbufandrefsin field order before droppingset, leaving dangling allocations in theMTLResidencySet(which does not retain its allocations).This fix:
alloc_counts) onHeapso each allocation is added toheap.setonce on0 -> 1and detached (removeAllocation+commit) when its last descriptor slot is overwritten or cleared, before the oldResis dropped.Drop for Heapto callset.removeAllAllocations()andset.commit()beforebufandrefsare dropped.heap_overwrite_detaches_replaced_residency_allocationsincrates/victory-metal/tests/resources.rsexercising multi-slot sharing, overwrite, and drop in bothMTLResidencySetanduseResourcemodes.Verification
cargo test -p victory-metal --target x86_64-apple-darwin --test resources heap_overwrite_detaches_replaced_residency_allocations— passed.cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings— 0 warnings.cargo xtask policy— 363 files ok.@LakshanSivakumar on GitHub · 2026-11-26 10:56 UTC · original · approved these changes
Reviewed and tested merged with current main: victory-metal (incl. the new test), victory-gpu/hle/victory/xtask and Windows clippy all pass. Good find on the residency set not retaining allocations.
Follow-ups, not blocking:
set.commit()immediately. During heavy streaming that can mean many commits per frame. Consider batching the removals (mark dirty, commit once before the next submit) if it shows up in profiles.victory-metal'ssrv_and_uav_through_a_descriptor_tablefails on main under x86_64 Rosetta (tests/common/mod.rs:48, write past region.len). It looks like the same >=16 KiB page-size sizing issue you fixed for the gpu tests in #23.