Files
metal2vulkan/docs
Anees Iqbal 1a541744e1 Destroy an event's semaphore where its release goes again, and record NVIDIA's event costs
What: an event's release destroys its timeline semaphore on the releasing thread again, as at
4bbafa667d (event.rs is that commit's again); the device's free thread frees blocks alone. The
semaphore posting goes with its counter (WorkCounts::semaphore_destroys_posted; the API table
blessed: the field removed), its runtime test and its lane rows. docs/FAST-PATHS.md's known gaps
record what making and releasing an event costs on NVIDIA, and why the release is not posted.

Why: NVIDIA's driver runs a vkCreateSemaphore behind a vkDestroySemaphore another thread runs,
so a posted destroy moves its cost onto the program's next event and adds to it. Measured on the
RTX 5080 Laptop GPU with the bench's event modes (each row 1000 events unless said; before and
after interleaved within each hold; CPU package 83-103 C), p50 unless said:

  burst, 1000 made then released     inline: make 143-262 us, release 495-579 us
                                       (0.47-0.57 s a 1000 released)
                                     posted, bound 4096: release 0.2-0.5 us, but the makes
                                       while the destroys drained 1048-1676 us (1.10-1.66 s
                                       a 1000)
                                     posted, bound 64: release 0.5-1.2 us, p99 1.5-2.2 ms,
                                       0.51-0.66 s a 1000; makes unchanged
  steady, make one and release the   inline 203-238 us a pair; posted (64) 390-507 us
  one before, back to back
  steady, 2 ms apart (500)           inline 488-490 us a pair (event), 663-677 us (shared);
                                     posted 260-263 us and 417-421 us
  the driver's own cost              grows with the semaphores live: 98-119 us a make and a
                                     release with one or two live, against the burst's
                                       143-262 and 495-579 us with 1000 live

On the M3 Max (MoltenVK 1.4.2) a pair costs 2.6-2.8 us inline and 5.3-5.9 us posted back to
back, about 45 us either way 2 ms apart; Metal's own newEvent and newSharedEvent take 0.8-1.9
us there. The consumer's guests made no event in a boot of theirs, and their host makes a few a
second, so no shape of use has the posted destroy ahead, and the burst at a program's close,
which posting was for, gains nothing: the device's teardown drains what was posted.

Verified on the M3 Max (debug, --cfg m2v_gpu, under maclock and memcap): 90 runtime tests
(posted_frees, freed_memory, teardown_threads, memory, allocations, event, cpu_copy_layouts)
and 27 lane tests (posted_frees, shared_event, events, pool_churn, staging_batches) pass;
api_signatures and api_surface pass; clippy (plain and --cfg m2v_gpu, workspace, all targets,
all features) and the release check of the runtime's tests are clean. The inline rows above
are the RTX 5080's at 4bbafa667d's event path, which this restores.

(cherry picked from commit 1659544703425cd461106fba2cff7cfe73a02a8a)
2026-11-04 18:50:29 -08:00
..