Files
metal2vulkan/crates
Anees Iqbal 29550063fe Share one linked VkPipeline between render variants of the same link
What: where the device links its render pipelines from graphics pipeline libraries, the linked
VkPipeline is now the device's, held in a content-keyed map (pipeline/libraries.rs) beside the
four part libraries and found by exactly what its linking takes: the four parts' names and the
pipeline layout it is linked with. A variant claims the link on the creating or drawing thread as
it claims its libraries; the first caller links it (Library::made, as a library is made), and every
later variant of the same link takes it with no driver call. The link holds its libraries and its
layout share while it lives (Vulkan may read a pipeline's creation's objects as long as the
pipeline lives); each variant's RawPipeline and each kept pipeline hold the link, and only the map
destroys it, at a program's settle once nothing holds it or at the device's teardown, before the
libraries. A pipeline made whole (no libraries, MoltenVK) is unchanged: the variant's own.

New count WorkCounts::linked_pipelines_shared; a shared link counts in neither pipelines_linked
nor variant_pipelines_made. The conformance cost half reports it as a FOUND count, never gated,
in the translation region. api_signatures.tsv gains the field.

Why: the consumer measured a client creating about 8,500 render states at login, each with a
linked pipeline of its own. States alive together of one compiled pipeline already share their
variant and its pipelines (memo.rs), and a released one's come back from kept.rs; but states that
are compiled pipelines of their own whose stages come out as the same words linked the same
pipeline again, each its own. Now a repeated link costs a lookup.

Test: tests::linked_pipelines_shared makes 16 siblings of one pair that differ only in
maxFragmentCallStackDepth (each a compiled pipeline and variant of its own; the fixture's fragment
function recurses through no visible function, so the words are the first state's), draws with
each and checks every pixel, and where the device links from libraries asserts the siblings
linked nothing, made no library and no variant pipeline, and took at least 16 shared links. A
descriptor differing only in a buffer's mutability is not such a sibling: it is the same compiled
pipeline, whose live variant it shares whole.

Verified: on MoltenVK 1.4.2 (M3 Max), which makes its pipelines whole, the new test and the
touched suites (driver_pipeline_compile, render_sibling_work, kept, warm_record,
uniform_bind_offsets, the libraries unit tests): all passed; the siblings there made 16 variant
pipelines, 0 shared, so the siblings are variants of their own. cargo clippy -p
metal2vulkan-runtime --all-targets --all-features -D warnings with --cfg m2v_gpu; public rustdoc
clean, no new private intra-doc link diagnostic; the conformance cost tests (37 passed). The run on
a device that links from libraries is in the hand-over.

(cherry picked from commit 22b2fd234eb66bf71ebc2c6e6639c0488ff5149a)
(cherry picked from commit a49b1f7d832c1beeae1e511a8f57b00b2e1640fd)
2026-11-03 04:54:40 -08:00
..