metal: per-encoder residency (VICTORY_METAL_RESIDENCY_SETS=0) names all 30k+ heap allocations one-by-one with Read|Write on every pass #382
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 Sheffy007 on 2026-11-27T15:27:38Z.
Refs #79, #8, #258
Problem
When
MTLResidencySetis off (VICTORY_METAL_RESIDENCY_SETS=0, and the default on 16–24 GB Macs), world frames spend 12 to 24 s per frame in per-encoderuseResourceoverhead even though total GPU shader execution is ~1.6 s over 120+ s (#79):crates/victory-metal/src/gfx.rsuse_heap_encoder): Every compute and render encoder unconditionally walksHeap::alloc_countsto name all ~30,000–68,000 heap allocations, even when the pass's translated shaders do not indexResourceDescriptorHeapdynamically (!heap) and only access a few fixed-offsetRoot::Tableentries (or no resource-heap entries at all). In #79's measurement, ~29,600 of ~30,300 heap textures are never in any bound table.useResourcecalls over aHashMap:allocations.values().for_each(|(_, r)| use_res(r))issues 30,000–68,000 separate Objective-CuseResource:calls per encoder instead of submitting cached contiguous slices via Metal's batchuseResources:count:usage:.MTLResourceUsage::Read | MTLResourceUsage::Writeonheap.bufand read-only textures:bind_root_computeandbind_root_rendermark&heap.bufand all ~30,000 read-only sampled textures (!MTLTextureUsage::ShaderWrite) asWriteon every pass, forcingIOGPUFamilyhazard tracking (when!set_on_queue) to serialize false write-after-write dependencies across the entire heap between encoders.Plan
createHandleFromHeap/annotateHandleanalysis inBinding::of(crates/victory-gpu/src/native/list.rs): Inspect the emitted DXIL bitcode alongsideHostShader::user_data(keeping warm shader caches valid without touchingvictory-shader) to classify each stage's resource-heap accesses as either exact bounded entries (Table(slot, offset, writes), pool-offsetPairs(writes),Const(index, writes), or none) orFullHeap { writes }(conservative fallback for bindlessResourceDescriptorHeap, dynamic/per-lane table offsets, and raw untranslated DXIL).HeapAccessonDispatch/Draw(crates/victory-backend,crates/victory-gpu/src/native/host.rs): Resolve each command's bounded heap entry ranges (orFullHeap { writes }) against the bound tables and view pairs.useResourceswith accurateReadvsRead | Writeusage (crates/victory-metal/src/gfx.rs):Heapallocations into cached contiguousread_onlyvsshader_writable(MTLBufferorMTLTextureUsage::ShaderWrite) slices forFullHeappasses, naming&heap.bufand read-only textures asReadand writable allocations asRead | Writeonly when an active command in the encoder can write to the heap.Heap::refsallocations via batcheduseResources.MTLResidencySetmode (residency_sets == true) untouched.with_residency_sets(false)covering bounded table passes over heaps populated with thousands of unrelated textures, read-after-write UAV hazard ordering across passes,Lower::memory/root_viewspair ranges,TypeTextureBufferviews, dynamic/bindlessFullHeapshaders, and stage scoping.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T15:27:39Z.
/claim
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-27T15:27:50Z.
Claimed by @Sheffy007. Open a draft pull request with
Refs #382in its description within 24 hours, or the claim expires.