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)
99 lines
4.6 KiB
Rust
99 lines
4.6 KiB
Rust
//! Render states whose whole key is equal, each a variant of its own, share one linked
|
|
//! `VkPipeline`: the device's, found by exactly what its linking takes, its four libraries and its
|
|
//! pipeline layout (`pipeline/libraries.rs`, `WorkCounts::linked_pipelines_shared`).
|
|
//!
|
|
//! The siblings here are descriptors of one vertex-and-fragment pair that differ only in
|
|
//! `maxFragmentCallStackDepth`, which sizes the call stack of a fragment function's recursion
|
|
//! through visible functions: each compiles its fragment function under a depth of its own, and
|
|
//! so is a compiled pipeline and a variant of its own, while the fixture's fragment function calls
|
|
//! no visible function, so every sibling's stages come out as the first creation's words, and
|
|
//! every part of its pipelines, every library and every link, is the first creation's. Each
|
|
//! sibling's creation takes the first creation's linked pipelines with no driver call, and each
|
|
//! sibling draws with them the pixels the fixture's constants give.
|
|
//!
|
|
//! A descriptor that differs only in what no compile reads (a buffer's mutability) is not a
|
|
//! sibling of this kind: it is the first creation's compiled pipeline, whose live variant it
|
|
//! shares whole (`memo.rs`).
|
|
//!
|
|
//! On a device that makes its render pipelines whole (no `VK_EXT_graphics_pipeline_library` with
|
|
//! fast linking: MoltenVK) nothing is linked, so nothing is shared; the run says so and checks
|
|
//! the draws alone.
|
|
//!
|
|
//! A device test: compiled only under the GPU safety cfgs (`m2v_gpu`, `m2v_cpu_icd`), on the kind
|
|
//! of device the cfg selects. The functions are the owned fixture
|
|
//! `validation/fixtures/public/engine/ubo_bind_offsets.ll`'s (`llvm-as`).
|
|
|
|
use super::blit_holds::{device, Scratch};
|
|
use super::descriptor_key_once::descriptor;
|
|
use super::uniform_bind_offsets::{draw, idle, Bound};
|
|
use crate::{PipelineOptions, WorkCounts};
|
|
use std::time::Instant;
|
|
|
|
/// The siblings made after the first state.
|
|
const RUN: u32 = 16;
|
|
|
|
/// The draw each state makes: the fragment's constants at byte 0 and the vertex's at byte 256 of
|
|
/// the constants buffer, offsets every device's uniform alignment divides.
|
|
const CASE: Bound = Bound::Buffer(0, 256);
|
|
|
|
#[test]
|
|
fn render_states_of_one_whole_key_share_one_linked_pipeline() {
|
|
let scratch = Scratch::new("linked-pipelines-shared");
|
|
let device = device(&scratch.0);
|
|
let queue = device.new_command_queue().unwrap();
|
|
let base = descriptor(&device);
|
|
let options = PipelineOptions::default();
|
|
let first = device.new_render_pipeline_state(&base, &options).unwrap();
|
|
draw(&device, &queue, &first, &[CASE]);
|
|
let before = idle(&device);
|
|
let mut siblings = Vec::with_capacity(RUN as usize);
|
|
let mut times = Vec::with_capacity(RUN as usize);
|
|
for i in 0..RUN {
|
|
let mut d = base.clone();
|
|
// Past Metal's default, 1, each a depth of its own.
|
|
d.max_fragment_call_stack_depth = 2 + i;
|
|
let started = Instant::now();
|
|
siblings.push(device.new_render_pipeline_state(&d, &options).unwrap());
|
|
times.push(started.elapsed().as_secs_f64() * 1e3);
|
|
}
|
|
for sibling in &siblings {
|
|
draw(&device, &queue, sibling, &[CASE]);
|
|
}
|
|
let after = idle(&device);
|
|
let made = |of: fn(&WorkCounts) -> u64| of(&after) - of(&before);
|
|
let (linked, shared) = (
|
|
made(|c| c.pipelines_linked),
|
|
made(|c| c.linked_pipelines_shared),
|
|
);
|
|
let libraries = made(|c| c.pipeline_libraries_made);
|
|
let pipelines = made(|c| c.variant_pipelines_made);
|
|
times.sort_by(f64::total_cmp);
|
|
println!(
|
|
"LINKED-PIPELINES-SHARED: {RUN} siblings: {linked} linked, {shared} shared, {libraries} \
|
|
libraries made, {pipelines} variant pipelines made; creation median {:.3} ms, max {:.3} ms",
|
|
times[times.len() / 2],
|
|
times[times.len() - 1],
|
|
);
|
|
if device.shared().libraries.is_none() {
|
|
assert_eq!(
|
|
shared, 0,
|
|
"a device that makes its render pipelines whole links none, so shares none"
|
|
);
|
|
return;
|
|
}
|
|
// Each sibling is a variant of its own: it made no library and linked nothing, and took at
|
|
// least one linked pipeline, its creation's, from the first state.
|
|
assert_eq!(
|
|
(linked, libraries, pipelines),
|
|
(0, 0, 0),
|
|
"every one of {RUN} siblings of one whole key must take the first state's linked \
|
|
pipelines and libraries: {linked} linked, {libraries} libraries and {pipelines} variant \
|
|
pipelines made, {shared} shared"
|
|
);
|
|
assert!(
|
|
shared >= u64::from(RUN),
|
|
"every one of {RUN} siblings must take at least its creation's linked pipeline from the \
|
|
first state: {shared} taken"
|
|
);
|
|
}
|