Files
metal2vulkan/crates/metal2vulkan-runtime/src/two_planes
Anees Iqbal 31a8967645 Retains hold shared objects by reference, once each, and drop the holds residency and blit_at made
Every resource an encoder made resident was boxed into its retains, though its residency holds it
and its encoder's record holds the residency until the command buffer completes; blit commands
boxed the buffers blit_at had already held by reference; and each dispatch boxed its pipeline
state, variant objects, pipelines and samplers again.

- encoder.rs: made_resident no longer retains (the residency holds the resource; the record
  holds the residency until completion, as command_buffer's own sync_heaps already relied on).
  Compute's sync_heaps and carry_residency likewise; Residency::carry returns nothing.
- retained.rs: a shared hold looks among the last 8 shared objects the encoder held and holds
  none again (the encoder holds it until completion, so no other object has its address
  meanwhile); each object still goes where its earliest hold goes.
- compute.rs: a dispatch holds its pipeline state (ComputePipelineState::held), variant objects,
  pipelines, samplers and flat-call buffer by reference; a memo hit borrows the made pipelines
  instead of cloning the list, and sets the memo's made list only where it is empty.
- blit.rs, blit_fill.rs, blit_texture.rs, two_planes/buffer_rows.rs: the retains of buffers
  blit_at held go; staging buffers and textures are held by reference.

Everything is still held until the command buffer completes. The same commands, barriers and
notices.

Checks: tests::retained::an_object_held_lately_is_held_once_until_the_holds_go (fails without the
recent-holds look: 12 holds for 3); the runtime GPU suite's encoder_holds and blit_holds legs,
which drop every object after the commit and check it lives until completion, pass.

Release, M3 Max, MoltenVK 1.4.2, host_ab percall (allocations deterministic; times interleaved
twice, ns per call):

| call | allocs before | allocs after | ns before | ns after |
|---|---:|---:|---:|---:|
| use_resources_read_256 | 277 | 16 | 10542-10583 | 7333-8208 |
| use_resources_read_1 | 6 | 3 | | |
| use_resource_read_write | 5 | 2 | | |
| use_heap | 8 | 5 | | |
| dispatch | 14.16 | 8.15 | 831-839 | 759-762 |
| copy_buffer_1k | 2.08 | 0.06 | 303-312 | 277-289 |
| fill_buffer_256 | 4.06 | 3.04 | 272-278 | 256-259 |
| copy_buffer_to_texture | 8.63 | 6.56 | | |

host_ab calls allocations: many_dispatch 46 -> 41, many_dispatch_resident 47 -> 44,
wide_dispatch 32.6 -> 27.5, many_blit_copy 11 -> 9, wide_blit_copy 2.5 -> 0.5; their times
within run-to-run noise (five interleaved rounds).

Verified on MoltenVK: the runtime GPU suite 1505/1505; the validation runtime lanes 533/535, the
two failures failing the same at the base.

(cherry picked from commit 3fc8182b1768af73cde54d2e9d717fa200f84593)
(cherry picked from commit 16d063c2ee9a70fd9dcc51d8b03abe8f69a07859)
(cherry picked from commit 5c880c7a5e082a417000448098c5ea5348a838d7)
(cherry picked from commit 367a4572f3c1cc951e0d2fb9f31a2f65af830f62)
2026-11-03 01:40:27 -08:00
..