Files
metal2vulkan/crates
Anees Iqbal 1c0833c2dd RUNTIME 2434: A settle of the device's maps looks only at the objects released since the last
Every compute or render state creation whose variant is not live
(VariantObjects::kept_or_create) settled the device's content-keyed maps:
the linked pipelines, the four graphics pipeline library parts, the shader
modules, the pipeline layouts and the sampler sets. Each settle walked
every entry with Arc::get_mut (a compare-exchange on each entry's weak
count) under the map's lock, so a creation cost O(objects the device
holds), a run of creations O(N^2), and creating threads queued behind each
other's walks. A guest benchmark's 7,981 compute makes spent 19.4% of their
on-CPU time in settle_device_maps and 6 + 3 ms asleep on those locks; the
new COMPUTE-CREATE-SCALING bench shows the slope (XTX, 4 threads: p50 10.7
us at 64 modules, 80.3 us at 4,160).

Now holders take a Share<T> from the map instead of a bare Arc<T>: the
object counts its shares, and the drop that leaves it with none queues its
insertion number on the map's release queue (a leaf mutex, each number
once until a settle takes it). ContentKeyed::settle drains only that queue
and destroys each queued object that still has no share, read under the
queue's lock and the map's (a lookup, the only way to take a share anew,
holds the map's lock; a later last drop queues the object again). The
objects destroyed, their order (insertion) and the calls that destroy them
are today's: the walk found exactly the objects whose shares had all gone.
No switch, no deferral, every map bound as before. The render libraries'
maps (Libraries::settle, the links and the four parts) are ContentKeyed
maps too, so a compute creation no longer walks them either.

Holders changed from Arc to Share: StageObject.module, VariantObjects and
KeptObjects samplers and layout, SharedLayout's sampler set, Link's parts
and layout, Linked. A layout's empty sampler set is Share::unmapped.

Tests (content_keyed, no device):
- a_settle_looks_only_at_what_was_released: 10,000 held, one released, the
  settle looks at 1 object (0 with none released); the old walk looked at
  10,000 each time.
- a_share_taken_again_before_the_settle_keeps_the_object, and the same on
  another thread: a share taken between the last drop and the settle keeps
  the object; released and taken again, it is queued once.
- settles_racing_shares_destroy_nothing_held: 4 threads take and drop
  shares while another settles; nothing destroyed while held, each object
  destroyed once.
- a_share_dropped_after_its_map_leaves_nothing: a share that outlives the
  map's teardown drain goes without panicking and frees its object and the
  queue.

Also: the COMPUTE-CREATE-SCALING and COMPUTE-CREATE-KEYS benches (ignored) and their profile
targets; the content-keyed map tests start their threads through exit_guard::spawn.

Verified (pipesettle): lavapipe gem10 m3-max-35753 (debug, m2v_cpu_icd) 142/142 (pipeline::*,
kept_variants, sampler_sets, linked_pipelines_shared, render_stage_digests, kept_across_calls,
core_image_libraries, exit_guard); msi 35734 clippy -D warnings 0 and 67 pipeline:: tests; gpucfg
build 35754. XTX release bench 35765 (not exclusive, same neighbour both runs), p50 us per creation
at 64 / 1088 / 4160 modules: T=1 5.9/9.3/21.8 -> 5.4/5.2/5.2; T=4 7.6/23.4/76.2 -> 6.8/7.0/6.6.
PHOENIX suites (35772) and clippy x3 + rustdoc at the tip follow.
2026-11-16 01:26:02 -08:00
..