Files
metal2vulkan/crates/metal2vulkan-validation/src
Anees Iqbal 45a2e23184 Runtime: a kernel keeps 64 variants, and lengths round up to 16 bytes
A kernel module's VkPipelines, one per threadgroup size, threadgroup memory
lengths, imageblock size and tiles, lived in 8 lock-free cells and then an
unbounded list. Each one lived until the content's last state went, and each
dispatch past the cells searched the whole list under the lock. One kernel
can reach 30,343 threadgroup sizes at 1,024 threads, 66 imageblock sizes, and
any length of each threadgroup argument the encoder sets.

How: the 8 cells stay. Past them a module lists at most 56, ordered by
dispatch, the least recently dispatched first. A make past 56 evicts the
least recently dispatched idle ones to the reaper, so 55 remain before the
new one is listed. Idle means the list holds the only count. A command buffer
holds each listed variant it dispatches from its first such dispatch until it
retires: one count per variant per command buffer, taken under the list's
lock. No hold is taken for a cell, or for a dispatch that reuses the encoder's
last pipeline. Where every listed variant is held, the make evicts none. So
the variants grow only by what work not yet retired holds, there is no
refusal and no wait, and a pipeline is destroyed only once every command
buffer that encoded it has retired. A variant evicted and dispatched again is
made again through the device's pipeline cache.

The lengths in the key and in the specialization constant are each rounded
up to a multiple of 16 bytes, the only lengths Metal takes. Lengths 17 and 32
run one variant. The threadgroup memory check rounded each region to 16
already.

New gauge kernel_variants: every kernel variant alive, the cells' included.
It is added to the signature table, the device teardown list, the replay's
named gauges and the harness's.

Tests (tests::kernel_variants): 17 and 32 bytes run one variant. 70 keys,
each in its own command buffer retired before the next, keep the first 8 and
the 56 dispatched last, and the gauge reads min(n, 64). One command buffer
runs 70 keys and holds all 70. After it retires, the next make keeps 64. A
200-iteration loop reads 64 at iterations 100 and 200. Every test reads 0 at
device drop. An evicted variant is made again, timed without the validation
layer.

Verified: see the lane's report (jobs named there).
2026-11-23 00:53:53 -08:00
..
…
…
…
…
…
…
…
…
…
…