From 201803fc48581fdf7682a725f5ac6ec2a04d29d5 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Mon, 26 Oct 2026 00:05:13 +0200 Subject: [PATCH] Compile a kernel once for the stage-input attributes it never reads The steps this packet landed as, in order: - Bless the surface and the API guide for the kernel's narrowed inputs - Re-pin the runtime sources at the landing tip Content: the tree of `development` at 3eefc94c48, unchanged. --- .../metal2vulkan-runtime/src/pipeline/mod.rs | 14 +- .../runtime-sources.sha256 | 2 +- crates/metal2vulkan/src/cache/mod.rs | 2 +- crates/metal2vulkan/src/pipeline/compile.rs | 61 +++++ .../metal2vulkan/src/pipeline/compile/api.rs | 37 +++ .../metal2vulkan/src/pipeline/descriptor.rs | 39 +++ .../src/tests/stage_in_unread_key.rs | 223 ++++++++++++++++-- crates/metal2vulkan/tests/api_signatures.tsv | 1 + docs/API.md | 7 +- 9 files changed, 356 insertions(+), 30 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/pipeline/mod.rs b/crates/metal2vulkan-runtime/src/pipeline/mod.rs index 03f8f7e09..e95ee61f8 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/mod.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/mod.rs @@ -1526,9 +1526,9 @@ impl Variant { /// /// The compile reads the kernel's specialized entry from the device's stage entries, as a /// render creation's stages do: a sibling pipeline of the same kernel at the same call-stack - /// depth compiles under its own lowering inputs, so no memo of compiled functions spares it, - /// but it decodes and specializes nothing an earlier sibling did - /// (`tests::stage_entries_shared`). + /// depth decodes and specializes nothing an earlier sibling did + /// (`tests::stage_entries_shared`), and where its lowering inputs come out the same the memo + /// of compiled functions spares it the translation too. fn compiled( sources: &Sources<'_>, function: &FunctionDescriptor, @@ -1537,12 +1537,16 @@ impl Variant { ) -> Result<(Remembered, Kernel), metal2vulkan::error::Error> { let compile = sources.device().compile_device(); let budget = sources.budget(); - let inputs = descriptor.inputs(key); - let function_key = compile.function_compile_key(function, &inputs); // The kernel's specialized entry is the device's, as a render stage's is: a sibling // pipeline of the same kernel at the same call-stack depth decodes and specializes // nothing an earlier one did (`pipeline/memo.rs`, `StageEntries`). let entries = sources.device().shared().shader_cache.memo.stage_entries(); + // The kernel compiles under the `[[stage_in]]` attributes its entry reads, which the + // shared entry states: a sibling state whose descriptor moves an attribute the kernel + // never reads asks for the function this one compiled, and the memo answers it. + let inputs = + compile.kernel_inputs_read(function, &descriptor.inputs(key), &budget, entries)?; + let function_key = compile.function_compile_key(function, &inputs); let compiled = sources.function(function, &inputs, (&function_key, Some(entries)), &budget)?; let compiled = descriptor.with_stage(StageSource::Compiled(compiled)); diff --git a/crates/metal2vulkan-validation/runtime-sources.sha256 b/crates/metal2vulkan-validation/runtime-sources.sha256 index 8b3a1b7e1..f48e0b603 100644 --- a/crates/metal2vulkan-validation/runtime-sources.sha256 +++ b/crates/metal2vulkan-validation/runtime-sources.sha256 @@ -1 +1 @@ -62489bb315e233df9e10ab597eab8683d0bed843c5fba8abfd3c9814cd097788 +8ee4fe7a9213f4d2756f630a27cf463a18d8c0e2a7c5d76017a9b8a587847070 diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index d34bf08a8..86a0bb0e1 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -60,7 +60,7 @@ mod tests; /// unchanged version, and its bless records the version. Independent of the crate's version and of /// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no /// history. -pub const SEMANTICS_VERSION: u32 = 1866; +pub const SEMANTICS_VERSION: u32 = 1867; /// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the /// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another diff --git a/crates/metal2vulkan/src/pipeline/compile.rs b/crates/metal2vulkan/src/pipeline/compile.rs index 9adf60ec0..6be8d8b8e 100644 --- a/crates/metal2vulkan/src/pipeline/compile.rs +++ b/crates/metal2vulkan/src/pipeline/compile.rs @@ -1765,6 +1765,67 @@ pub(crate) fn declared_attributes( out } +/// The Metal `[[stage_in]]` attribute indices the specialized kernel entry `spec` reads: its +/// `air.stage_in` parameters that survived function-constant specialization and that an +/// instruction uses, which are the parameters `lower::stage_io` plans and so the only attributes +/// the module fetches (`lower::stage_io::stage_in::param`, one `StageInFetch::of` a parameter). +/// The use is read as the lowering reads it (`lower::select`: an argument any instruction of the +/// entry's body names, a call's operand included), so the set is the lowering's own and not a +/// narrower reading of it. Empty for any other stage, which declares no such parameter. +pub(crate) fn stage_in_attributes(spec: &air::Entry) -> BTreeSet { + let mut out = BTreeSet::new(); + let Some(func) = spec.module.func(spec.func) else { + return out; + }; + let Some(body) = func.body.as_ref() else { + return out; + }; + let mut used = BTreeSet::new(); + for inst in body.insts.values() { + inst.kind.for_each_value(|v| { + if let Value::Arg(a) = v { + used.insert(a.raw()); + } + }); + } + for b in &spec.ep.params { + if let ParamRole::StageIn { location } = &b.role { + if let AbiInt::Const(index) = location.index { + if used.contains(&b.param) { + out.insert(index); + } + } + } + } + out +} + +/// `inputs` with a kernel's stage-input descriptor narrowed to the attributes the entry of stage +/// `fd` reads (`StageInputDescriptor::narrowed_to` of [`stage_in_attributes`]): the inputs a +/// compile of `fd` under `inputs` emits its module from, stated so that the key the compile is +/// keyed under names them and nothing else. It decodes and specializes only (the entry `entries` +/// holds, or one made there now), as a key before compiling does. +/// +/// `inputs` without a stage-input descriptor is its own answer, decoding nothing: a kernel that +/// states none, and every other stage, keep the inputs they were given. +pub(crate) fn kernel_inputs_read( + fd: &FunctionDescriptor, + inputs: &LowerInputs, + entries: &StageEntries, + m: &mut Meter, +) -> Result { + guarded(|| { + let Some(given) = inputs.stage_input.as_ref() else { + return Ok(inputs.clone()); + }; + let specialized = entries.specialized(fd, inputs.max_call_stack_depth.unwrap_or(1), m)?; + let read = stage_in_attributes(&specialized.spec); + let mut out = inputs.clone(); + out.stage_input = Some(given.narrowed_to(&read)); + Ok(out) + }) +} + /// The color attachments the specialized fragment entry `spec` reads (`[[color(n)]]`) whose /// pixel format in `colors` is `RGBA8Unorm_sRGB` or `BGRA8Unorm_sRGB` /// (`LoweringInputs::srgb_fetches`). Empty for any other stage. diff --git a/crates/metal2vulkan/src/pipeline/compile/api.rs b/crates/metal2vulkan/src/pipeline/compile/api.rs index 8d67cb7e1..aeecbdda1 100644 --- a/crates/metal2vulkan/src/pipeline/compile/api.rs +++ b/crates/metal2vulkan/src/pipeline/compile/api.rs @@ -224,6 +224,43 @@ impl Device { compile_stage_from(f, self.profile(), InputsFrom::Given(inp), entries, &mut m) } + /// `inp` with its stage-input descriptor narrowed to the `[[stage_in]]` attributes the kernel + /// `f` reads, which is the form a creation keys its kernel under and compiles it with. + /// + /// A kernel fetches one attribute at a time, from that attribute's own entries of the + /// descriptor alone, so an attribute no instruction of its entry reads reaches no instruction + /// of the module: a kernel that reads five attributes compiles to one module however a sixth + /// it never reads is stated. Narrowing the inputs is what gives it one key as well as one + /// module, so a consumer that keys compiled functions by + /// [`Device::function_compile_key`] under these inputs compiles the kernel once for the whole + /// family instead of once a state. The inputs it answers are the ones to give both + /// [`Device::function_compile_key`] and the compile + /// ([`Device::compile_function_from_entries`]), as a render creation gives + /// [`RenderPipelineKeys::vertex_inputs`] to both. + /// + /// This narrows the kernel's **compile**, not the descriptor: what a creation reads of the + /// stage-input descriptor past the fetch reads it whole, so + /// [`Device::compile_compute_pipeline`] still refuses an attribute whose buffer has no + /// layout, read or not, [`Device::compute_pipeline_key`] still states every field of it, and + /// [`ComputePipelineDescriptor::reflection`] still lists a buffer for every set attribute. + /// + /// It decodes and specializes the kernel's AIR under `b`, reading the stage's specialized + /// entry from `entries` (the one a key or check of the same creation made, else one made + /// there now), so a sweep of states over one kernel decodes once. Inputs without a + /// stage-input descriptor are their own answer, decoding nothing. + /// + /// Refused by the decode's and the specialization's own errors. + pub fn kernel_inputs_read( + &self, + f: &FunctionDescriptor, + inp: &LoweringInputs, + b: &Budget, + entries: &StageEntries, + ) -> Result { + let mut m = Meter::new(b); + crate::pipeline::compile::kernel_inputs_read(f, inp, entries, &mut m) + } + /// The key of the compute pipeline `d` (no decode). pub fn compute_pipeline_key(&self, d: &ComputePipelineDescriptor) -> crate::cache::PipelineKey { let stage = match &d.kernel { diff --git a/crates/metal2vulkan/src/pipeline/descriptor.rs b/crates/metal2vulkan/src/pipeline/descriptor.rs index a8c254ae5..352f3a81e 100644 --- a/crates/metal2vulkan/src/pipeline/descriptor.rs +++ b/crates/metal2vulkan/src/pipeline/descriptor.rs @@ -983,6 +983,45 @@ impl StageInputDescriptor { } out } + + /// This descriptor as the fetches of the attributes `read` names read it: those attributes and + /// the layouts they name, each verbatim, and the index type and index buffer index as they + /// stand; every other attribute, and every layout only such an attribute named, dropped. + /// + /// A kernel fetches one attribute at a time, from that attribute's own descriptor entries + /// alone (`StageInFetch::of`, which `lower::stage_io::stage_in::param` reaches for each + /// `[[stage_in]]` parameter an instruction uses), so an attribute `read` leaves out reaches + /// no instruction of the module: a compile under this descriptor emits what a compile under + /// the whole one emits, word for word, and the key it is compiled under states the whole + /// difference between two descriptors their fetches read apart. + /// + /// Everything the attributes `read` names fetch is kept as it stands, so every + /// [`StageInFetch::of`] of such an attribute answers what it answered: the canonical form of + /// a constant step, and of an index type no kept layout steps through, is + /// [`canonical`](Self::canonical)'s to write. + /// + /// This is not a check: an attribute `read` names that the descriptor lacks stays absent, and + /// the compile refuses it where Metal's pipeline creation stops + /// (`InvalidDescriptor(StageInputAttribute)`). Nor is it what a creation reads of the + /// descriptor past the fetch: its layout agreement (`check_layouts`), its reflection + /// ([`ComputePipelineDescriptor::reflection`](crate::pipeline::ComputePipelineDescriptor::reflection), + /// which lists a buffer for every set attribute, read or not) and the compute pipeline key + /// (`compute_fields`) each read the descriptor as given. + pub(crate) fn narrowed_to( + &self, + read: &std::collections::BTreeSet, + ) -> StageInputDescriptor { + let mut out = StageInputDescriptor::new(); + out.index_type = self.index_type; + out.index_buffer_index = self.index_buffer_index; + for (&index, a) in self.attributes.iter().filter(|(i, _)| read.contains(i)) { + out.attributes.insert(index, *a); + if let Some(l) = self.layouts.get(&a.buffer_index) { + out.layouts.insert(a.buffer_index, *l); + } + } + out + } } impl Default for StageInputDescriptor { diff --git a/crates/metal2vulkan/src/tests/stage_in_unread_key.rs b/crates/metal2vulkan/src/tests/stage_in_unread_key.rs index 334b14d72..87512e648 100644 --- a/crates/metal2vulkan/src/tests/stage_in_unread_key.rs +++ b/crates/metal2vulkan/src/tests/stage_in_unread_key.rs @@ -54,7 +54,7 @@ use crate::device::requirements::VkFeature; use crate::device::{Device, DeviceDescription, DevicePolicy}; use crate::library::Library; use crate::metal::{AttributeFormat, IndexType, StepFunction}; -use crate::pipeline::compile::{compile_stage, InputsFrom}; +use crate::pipeline::compile::{compile_stage, InputsFrom, StageEntries}; use crate::pipeline::descriptor::{ ComputePipelineDescriptor, StageInputAttributeDescriptor, StageInputDescriptor, StageInputLayoutDescriptor, StageSource, @@ -468,13 +468,28 @@ fn rows() -> Vec<(String, StageInputDescriptor)> { rows } -/// The lowering inputs of a row. +/// The lowering inputs of a row: the whole descriptor, as a creation states it before it learns +/// what the kernel reads. fn inputs(d: &StageInputDescriptor) -> LoweringInputs { let mut inputs = LoweringInputs::new(); inputs.stage_input = Some(d.clone()); inputs } +/// The lowering inputs a creation compiles the kernel of a row under: [`inputs`] narrowed to the +/// attributes the kernel reads (`Device::kernel_inputs_read`), through `entries`, so the sweep +/// decodes and specializes the one kernel once however many rows it reads. +fn read_inputs( + device: &Device, + kernel: &FunctionDescriptor, + entries: &StageEntries, + d: &StageInputDescriptor, +) -> LoweringInputs { + device + .kernel_inputs_read(kernel, &inputs(d), &Budget::standard(), entries) + .expect("the kernel's read attributes") +} + /// The sweep's rows are all different descriptors, so nothing below is a comparison of a /// descriptor with itself. /// @@ -538,52 +553,211 @@ fn an_unread_attribute_changes_no_word_of_the_module() { ); } -/// Every row of the sweep is a **function compile key and a compute pipeline key of its own**: a -/// kernel that reads five attributes is translated again, and its pipeline compiled again, for -/// every value of an attribute it never reads. +/// The whole sweep is **one function compile key**, and so one translation: a kernel that reads +/// five attributes is compiled once however the sixth it never reads is stated. /// -/// This is the measurement of the waste, not an endorsement of it. The module -/// [`an_unread_attribute_changes_no_word_of_the_module`] compiles is the same in all of these, so -/// every key past the first buys a translation of bytes the first already produced, and on a -/// driver that converts SPIR-V at pipeline creation each one buys a shader conversion too. The -/// count is asserted at the sweep's own length rather than left unwritten, because it is the -/// deterministic check behind the bug: a narrowing of the key fails here with its own number, and -/// so does a widening. +/// This is the measurement of the fix. `Device::kernel_inputs_read` narrows a creation's lowering +/// inputs to the attributes the kernel's entry reads, and a creation keys its kernel and compiles +/// it under those (`metal2vulkan-runtime`'s `Variant::compiled`), so the 36 rows ask for one +/// compiled function and the memo of compiled functions answers 35 of them. Before the narrowing +/// each row was a key of its own and each bought a translation of bytes the first already +/// produced; [`an_unread_attribute_changes_no_word_of_the_module`] is what says those were the +/// same bytes. +/// +/// The **compute pipeline key stays one a row**, which is deliberate and is not the waste: it +/// states the descriptor as a creation reads it past the fetch (its layout agreement, which +/// refuses an attribute whose buffer has no layout read or not, and the buffers its reflection +/// lists for every set attribute), and a creation of a key the memo lacks links and relocates a +/// module it already has rather than translating one. +/// +/// The counts are asserted at what they read, so neither a narrowing that went further nor one +/// that came back can land quietly. #[test] fn an_unread_attribute_keys_a_translation_of_its_own() { let Some(bitcode) = fixture() else { return }; let device = device(); let kernel = kernel(&bitcode); + let entries = StageEntries::new(); let rows = rows(); let mut function_keys: BTreeSet<[u8; 32]> = BTreeSet::new(); + let mut whole_keys: BTreeSet<[u8; 32]> = BTreeSet::new(); let mut pipeline_keys: BTreeSet<[u8; 32]> = BTreeSet::new(); for (_, d) in &rows { - function_keys.insert(*device.function_compile_key(&kernel, &inputs(d)).digest()); + let read = read_inputs(&device, &kernel, &entries, d); + function_keys.insert(*device.function_compile_key(&kernel, &read).digest()); + whole_keys.insert(*device.function_compile_key(&kernel, &inputs(d)).digest()); let mut descriptor = ComputePipelineDescriptor::new(StageSource::Function(kernel.clone())); descriptor.stage_input = Some(d.clone()); pipeline_keys.insert(*device.compute_pipeline_key(&descriptor).digest()); } + let (specialized, shared) = entries.counts(); eprintln!( - "{} rows: {} function compile key(s), {} compute pipeline key(s)", + "{} rows: {} function compile key(s) read, {} stated whole, {} compute pipeline key(s); \ + {specialized} entry specialized, {shared} shared", rows.len(), function_keys.len(), - pipeline_keys.len() + whole_keys.len(), + pipeline_keys.len(), ); assert_eq!( function_keys.len(), + 1, + "the sweep's {} rows are {} function compile keys, so {} of them buy a translation of \ + bytes another produced", rows.len(), - "the sweep's {} rows are {} function compile keys: the key is narrower or wider than the \ - whole descriptor, and the module docs' reading of it is stale either way", + function_keys.len(), + function_keys.len() - 1 + ); + assert_eq!( + whole_keys.len(), rows.len(), - function_keys.len() + "the descriptor stated whole is still {} keys: the narrowing is `kernel_inputs_read`'s \ + and not a change to what a key makes of the inputs it is given", + rows.len() ); assert_eq!( pipeline_keys.len(), rows.len(), - "the sweep's {} rows are {} compute pipeline keys: as above, for `compute_fields`", - rows.len(), - pipeline_keys.len() + "the compute pipeline key states the whole descriptor, as `compute_fields` writes it" ); + assert_eq!( + (specialized, shared), + (1, rows.len() as u64 - 1), + "the sweep decodes and specializes the one kernel once and shares it {} times", + rows.len() - 1 + ); +} + +/// Every row narrows to the read set alone, and the **canonical form** of every narrowed row is +/// one descriptor: the one key above is that, and not two descriptors a digest happened to agree +/// on. +/// +/// The narrowed descriptors themselves are not all equal, and must not be: the narrowing keeps +/// what it keeps verbatim, the index type and index buffer index among it, so that every +/// `StageInFetch::of` of a read attribute answers what it answered under the whole descriptor. +/// Writing those at Metal's defaults where no kept layout steps through the index buffer is +/// `StageInputDescriptor::canonical`'s to do, and the key hashes the canonical form +/// (`pipeline::compile::key::canonical_inputs`), so that is what this compares. +#[test] +fn every_row_narrows_to_the_read_set_alone() { + let Some(bitcode) = fixture() else { return }; + let device = device(); + let kernel = kernel(&bitcode); + let entries = StageEntries::new(); + let rows = rows(); + let mut held: Option<(String, StageInputDescriptor)> = None; + for (name, d) in &rows { + let read = read_inputs(&device, &kernel, &entries, d); + let narrowed = read.stage_input.clone().expect("a stage-input descriptor"); + assert_eq!( + narrowed.attributes.keys().copied().collect::>(), + vec![0, 1, 2, 3, 4], + "{name} narrows to attributes the kernel does not read, or drops one it does" + ); + assert_eq!( + narrowed.layouts.keys().copied().collect::>(), + vec![SOURCE], + "{name} keeps a layout no read attribute names, or drops the one they read" + ); + let canonical = narrowed.canonical(); + match &held { + None => held = Some((name.clone(), canonical)), + Some((first, first_canonical)) => assert_eq!( + &canonical, first_canonical, + "{name} narrows to a descriptor the baseline {first} does not fetch alike" + ), + } + } +} + +/// The module a row compiles to under the **narrowed** inputs is the module it compiles to under +/// the whole descriptor, word for word, over the whole sweep. +/// +/// This is the exactness of the narrowing itself, and the other half of +/// [`an_unread_attribute_changes_no_word_of_the_module`]: that one says the 36 descriptors compile +/// alike, and this one says compiling under the attributes the kernel reads compiles to the same +/// thing as compiling under all of them. A row whose words moved would be an input the narrowing +/// must not drop. +#[test] +fn narrowing_the_inputs_changes_no_word_of_the_module() { + let Some(bitcode) = fixture() else { return }; + let device = device(); + let kernel = kernel(&bitcode); + let entries = StageEntries::new(); + let compile = |inputs: &LoweringInputs, name: &str| -> Vec { + let mut meter = Meter::new(&Budget::standard()); + compile_stage( + &kernel.function, + &kernel.constants, + (&kernel.linked, &kernel.libraries), + device.profile(), + InputsFrom::Given(inputs), + &mut meter, + ) + .unwrap_or_else(|why| panic!("{name} compiles: {why:?}")) + .artifact() + .module + .words + .clone() + }; + for (name, d) in &rows() { + let whole = compile(&inputs(d), name); + let read = compile(&read_inputs(&device, &kernel, &entries, d), name); + assert_eq!( + read, whole, + "{name} compiled to another module under the attributes the kernel reads: an \ + attribute the narrowing drops reaches an instruction" + ); + } +} + +/// Every row's pipeline is **created from the kernel compiled under the narrowed inputs and the +/// descriptor as given**, which is what a creation does, and none of them refuses. +/// +/// This is the check a count cannot make. The narrowing takes inputs out of the kernel's compile, +/// and what a creation reads of the descriptor past the fetch still reads it whole: the pipeline +/// compares every fetch its artifact recorded against the descriptor it was given +/// (`check_stage_in`), and holds the descriptor's layouts to Metal's agreement +/// (`check_layouts`). A narrowing that moved a read attribute's fetch, or that let the +/// descriptor's own refusals go, would not change a key count — it would surface here, as a +/// refusal of a descriptor Metal accepts or an acceptance of one it stops. +/// +/// Each row's pipeline also keeps the key `Device::compute_pipeline_key` states for its +/// descriptor, so a consumer that looks one up before creating it finds what the creation made. +#[test] +fn a_narrowed_kernel_still_makes_every_row_s_pipeline() { + let Some(bitcode) = fixture() else { return }; + let device = device(); + let kernel = kernel(&bitcode); + let entries = StageEntries::new(); + let budget = Budget::standard(); + for (name, d) in &rows() { + let read = read_inputs(&device, &kernel, &entries, d); + let compiled = device + .compile_function(&kernel, &read, &budget) + .unwrap_or_else(|why| panic!("{name}'s kernel compiles: {why:?}")); + let mut descriptor = + ComputePipelineDescriptor::new(StageSource::Compiled(compiled.clone())); + descriptor.stage_input = Some(d.clone()); + let pipeline = device + .compile_compute_pipeline(&descriptor, &budget) + .unwrap_or_else(|why| { + panic!( + "{name}'s pipeline links the kernel compiled under the attributes it reads: \ + {why:?}" + ) + }); + assert_eq!( + &pipeline.key, + &device.compute_pipeline_key(&descriptor), + "{name}'s pipeline keeps a key its descriptor does not state" + ); + assert_eq!( + compiled.key(), + &device.function_compile_key(&kernel, &read), + "{name}'s kernel keeps a key the inputs it compiled under do not state" + ); + } } /// An attribute the kernel **does** read keys a translation of its own: moving one of the five, or @@ -599,9 +773,14 @@ fn a_read_attribute_is_part_of_the_key() { let Some(bitcode) = fixture() else { return }; let device = device(); let kernel = kernel(&bitcode); + let entries = StageEntries::new(); let plain = (IndexType::UInt32, INDEX_A); let base = descriptor(&[], &[], plain); - let key = |d: &StageInputDescriptor| *device.function_compile_key(&kernel, &inputs(d)).digest(); + let key = |d: &StageInputDescriptor| { + *device + .function_compile_key(&kernel, &read_inputs(&device, &kernel, &entries, d)) + .digest() + }; let mut moved_format = base.clone(); moved_format.attributes.insert( 0, diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index f53474ef4..7a8aaa39b 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -8702,6 +8702,7 @@ method metal2vulkan::device::Device::fit_render_variant pub fn fit_render_varian method metal2vulkan::device::Device::fit_tile_pipeline pub fn fit_tile_pipeline(&self, d: &TileRenderPipelineDescriptor, inputs: &LoweringInputs, b: &Budget, pipeline: ComputePipeline) -> Result method metal2vulkan::device::Device::function_compile_key pub fn function_compile_key(&self, f: &FunctionDescriptor, inp: &LoweringInputs) -> FunctionCompileKey method metal2vulkan::device::Device::generated_commands pub fn generated_commands(&self) -> Option<&GeneratedCommandsProperties> +method metal2vulkan::device::Device::kernel_inputs_read pub fn kernel_inputs_read(&self, f: &FunctionDescriptor, inp: &LoweringInputs, b: &Budget, entries: &StageEntries) -> Result method metal2vulkan::device::Device::mesh_descriptor_key pub fn mesh_descriptor_key(&self, d: &MeshPipelineDescriptor) -> crate::cache::PipelineKey method metal2vulkan::device::Device::metal_properties pub fn metal_properties(&self) -> &MetalDeviceProperties method metal2vulkan::device::Device::neutral_kinds pub fn neutral_kinds(&self) -> Vec diff --git a/docs/API.md b/docs/API.md index 7ef66e4f6..5dc0022ac 100644 --- a/docs/API.md +++ b/docs/API.md @@ -944,7 +944,12 @@ assert_eq!(linked, pipeline); `compile_function_with_report` also returns a `CompileReport` of what the compile cost. - A render pipeline's stages compile under inputs that a decode of its functions learns. `render_pipeline_key` returns `RenderPipelineKeys`: each stage's function key, and the inputs to - compile a missing stage under. Each pipeline kind's compile (`compile_render_variant`, + compile a missing stage under. So does a compute pipeline's kernel: + `kernel_inputs_read(&kernel, &inputs, &budget, &entries)` narrows the stage-input descriptor to + the attributes its entry reads, and the kernel keys and compiles under those, so states that + differ only in an attribute it never reads share one compiled function. What a creation reads of + the descriptor past the fetch -- its layout agreement, its reflection, and `compute_pipeline_key` + -- reads it whole. Each pipeline kind's compile (`compile_render_variant`, `compile_mesh_variant`, `compile_compute_pipeline`, `compile_tile_pipeline`) holds a pipeline of `Function` stages to the device's compiler word bound (`DeviceProfile::module_word_bound`, ANV's) itself; one linked from `Compiled` stages it cannot translate again. A caller who