diff --git a/crates/metal2vulkan-runtime/src/pipeline/render.rs b/crates/metal2vulkan-runtime/src/pipeline/render.rs index 21f8fc2c3..c5a9cc4b2 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/render.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/render.rs @@ -936,9 +936,21 @@ impl RenderPipelineState { /// Only the slot is answered. A function may also reach textures through an argument buffer, /// a heap or a resource ID, which no slot's answer covers; /// [`vertex_writes_textures`](Self::vertex_writes_textures) and its siblings cover those - /// too. Refused as the reflection is (`Unsupported` with `Feature::Reflection` for an - /// argument of any kind whose answer Metal's has not been measured for, `Compile` for the - /// decode's errors). The refusal is kept and returned on every later call. + /// too. + /// + /// The answers come from the pipeline's slot writes + /// (`metal2vulkan::reflection::SlotWrite`), not from its reflection: a reflection must give + /// Metal's `MTLType` for every binding and refuses the whole function where Metal's answer + /// for one argument's *type* has not been measured, which refused every slot of the state, + /// read-only ones included. A state that compiles answers here. + /// + /// Refused for one slot alone (`Unsupported` with `Feature::Reflection`) where an argument + /// that may cover it leaves it undetermined: a slot only a function constant states, a + /// payload in a stage Metal's access for one is unmeasured in, or an argument whose role only + /// an argument-buffer member takes. Every other slot still answers, and a slot a determined + /// argument covers answers whatever else the state holds. The decode's own errors are + /// `Compile`. No refusal is remembered: only a successful set of answers is kept, so a later + /// call is answered again rather than handed the first failure. pub fn texture_access( &self, stages: RenderStages, @@ -948,7 +960,7 @@ impl RenderPipelineState { Kind::Graphics(state) => state.texture_accesses()?, Kind::Tile(state) => state.texture_accesses()?, }; - Ok(accesses.at(stages, index)) + accesses.at(stages, index) } /// The pipeline's reflection, as its creation's out-parameter answers it where the options @@ -1710,10 +1722,20 @@ impl GraphicsState { self.0.drawn.as_ref().unwrap_or(&self.0.descriptor) } - /// Its functions' texture slots and their accesses, from its reflection - /// ([`reflection`](Self::reflection)) the first time. + /// Its functions' texture slots and their accesses, from its slot writes the first time. + /// + /// Not from its reflection: that refuses the whole state where Metal's answer for one + /// argument's type has not been measured, which took every slot's access with it + /// (`pipeline::texture_access`). The slot writes read the functions' roles, declared accesses + /// and slots alone, so a state that compiles answers. fn texture_accesses(&self) -> Result<&TextureAccesses, Error> { - TextureAccesses::remembered(&self.0.texture_accesses, |budget| self.reflection(budget)) + TextureAccesses::remembered(&self.0.texture_accesses, |budget| { + match self.descriptor() { + StateDescriptor::Vertex(descriptor) => descriptor.slot_writes(budget), + StateDescriptor::Mesh(descriptor) => descriptor.slot_writes(budget), + } + .map_err(device_error) + }) } /// The pipeline's reflection ([`RenderPipelineState::compiled_reflection`]) of the descriptor diff --git a/crates/metal2vulkan-runtime/src/pipeline/texture_access.rs b/crates/metal2vulkan-runtime/src/pipeline/texture_access.rs index 14d874917..71892018a 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/texture_access.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/texture_access.rs @@ -1,48 +1,98 @@ //! The texture slots of a render pipeline state's functions, and how each function accesses them -//! ([`RenderPipelineState::texture_access`](crate::RenderPipelineState::texture_access)). The -//! answers come from the pipeline's reflection, which the `reflection:` out-parameter of -//! Metal's creation calls gives too. They are read from the state's reflection -//! (`RenderPipelineState::compiled_reflection`) the first time someone asks, and kept while the -//! state lives. +//! ([`RenderPipelineState::texture_access`](crate::RenderPipelineState::texture_access)). +//! +//! The answers come from the pipeline's slot writes +//! (`metal2vulkan::reflection::SlotWrite`): each argument's role, declared access and slot, with +//! no type description derived. The same values are in the pipeline's reflection as +//! `Binding::access`, but a reflection must also give Metal's `MTLType` for every binding and +//! refuses the whole function where Metal's answer for one argument's *type* has not been +//! measured. Reading these answers from the reflection made one such argument refuse every slot +//! of the state, read-only ones included, and a caller that cannot tell a read-only slot from a +//! writable one has to treat every bound texture as written. +//! +//! Two properties follow, and both matter to a caller that must be safe: +//! +//! - **A state that compiles answers.** The slot writes refuse nothing a compile accepted. +//! - **No refusal is remembered.** Only a successful set of answers is kept +//! ([`TextureAccessMemo`]); a slot left undetermined is worked out again from that set on every +//! call, and a failure to get the answers at all is not stored, so a later call tries again. +//! The memo used to hold a `Result` and hand back the same refusal for the life of the state. +//! +//! A slot whose answer one argument alone leaves undetermined is refused as that slot, naming the +//! gap; every other slot of the state still answers. use crate::error::Error; +use metal2vulkan::error::{DiagName, Feature, Unsupported}; use metal2vulkan::metal::{BindingAccess, BindingType, RenderStages}; -use metal2vulkan::reflection::{Binding, RenderPipelineReflection}; +use metal2vulkan::reflection::{SlotWritability, SlotWrite, SlotWrites}; use metal2vulkan::Budget; use std::ops::Range; use std::sync::OnceLock; -/// The texture arguments a render pipeline state's functions reference. Each entry has its -/// stage, the slots it covers (each element's slot, for an array) and its declared access. -#[derive(Debug, PartialEq, Eq)] -pub(crate) struct TextureAccesses(Vec<(RenderStages, Range, BindingAccess)>); +/// What one texture argument of a stage answers: the slots it covers and its declared access, or +/// the gap that left it undetermined. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Answer { + /// The argument's declared access, as Metal answers it. + Access(BindingAccess), + /// Undetermined for the reason named; the slots it covers answer no access. + Gap(metal2vulkan::reflection::SlotWriteGap), +} -/// A state's [`TextureAccesses`], read when first asked. A refused reflection is kept as its -/// error. -pub(crate) type TextureAccessMemo = OnceLock>; +/// The texture arguments a render pipeline state's functions reference. Each entry has its +/// stage, the slots it covers (each element's slot, for an array) and its answer. +#[derive(Debug, PartialEq, Eq)] +pub(crate) struct TextureAccesses(Vec<(RenderStages, Range, Answer)>); + +/// A state's [`TextureAccesses`], worked out when first asked and kept while the state lives. +/// +/// It holds a successful set of answers alone. A call that cannot get them stores nothing, so a +/// refusal is never handed back for the life of the state (which is what a `Result` here did). +pub(crate) type TextureAccessMemo = OnceLock; + +/// The widest span a slot can be asked about, for an argument whose own span is not stated: it may +/// cover any slot, so it must not let one read as unbound. +const EVERY_SLOT: Range = 0..u64::MAX; impl TextureAccesses { - /// The referenced texture arguments of `reflection`'s stages. - pub(crate) fn of(reflection: &RenderPipelineReflection) -> TextureAccesses { - let stages: [(RenderStages, &[Binding]); 5] = [ - (RenderStages::VERTEX, reflection.vertex_bindings()), - (RenderStages::FRAGMENT, reflection.fragment_bindings()), - (RenderStages::TILE, reflection.tile_bindings()), - (RenderStages::OBJECT, reflection.object_bindings()), - (RenderStages::MESH, reflection.mesh_bindings()), + /// The referenced texture arguments of `writes`'s stages. + /// + /// An argument of another binding type is left out, and so is one the function never + /// references: Metal's reflection lists that one with `isUsed` false, and the function + /// neither reads nor writes it. An argument whose role determines no binding type at all, or + /// whose slots only a function constant states, may be a texture at any slot, so it is kept + /// over every slot as a gap. + fn of(writes: &SlotWrites) -> TextureAccesses { + let stages: [(RenderStages, &[SlotWrite]); 5] = [ + (RenderStages::VERTEX, writes.vertex_slots()), + (RenderStages::FRAGMENT, writes.fragment_slots()), + (RenderStages::TILE, writes.tile_slots()), + (RenderStages::OBJECT, writes.object_slots()), + (RenderStages::MESH, writes.mesh_slots()), ]; let mut accesses = Vec::new(); - for (stage, bindings) in stages { - for binding in bindings { - let Some(texture) = binding.texture() else { - continue; - }; - if binding.binding_type() != BindingType::Texture || !binding.is_used() { + for (stage, slots) in stages { + for slot in slots { + if slot.binding_type.is_some_and(|t| t != BindingType::Texture) { continue; } - let first = u64::from(binding.index()); - let slots = first..first + u64::from(texture.array_length().max(1)); - accesses.push((stage, slots, binding.access())); + let answer = match (slot.writes, slot.access) { + (SlotWritability::Unknown(gap), _) => Answer::Gap(gap), + (_, Some(access)) => Answer::Access(access), + // A determined writability always carries its declared access. + (_, None) => continue, + }; + let span = match (slot.index, slot.count, answer) { + (Some(first), Some(count), _) => { + let first = u64::from(first); + first..first + u64::from(count.max(1)) + } + _ => EVERY_SLOT, + }; + if matches!(answer, Answer::Access(_)) && !slot.used { + continue; + } + accesses.push((stage, span, answer)); } } TextureAccesses(accesses) @@ -50,31 +100,72 @@ impl TextureAccesses { /// The accesses of the referenced texture arguments of `stages` that cover slot `index`, /// joined into one; `None` where none covers it. - pub(crate) fn at(&self, stages: RenderStages, index: u64) -> Option { - self.0 - .iter() - .filter(|(stage, slots, _)| stages.contains(*stage) && slots.contains(&index)) - .map(|&(_, _, access)| access) - .reduce(|a, b| if a == b { a } else { BindingAccess::ReadWrite }) + /// + /// Refused where an argument that may cover the slot is undetermined and none that covers it + /// answers: that slot alone, naming the gap. Where a determined argument covers it, that + /// answer stands, so one undetermined argument does not take the rest of the state with it. + pub(crate) fn at( + &self, + stages: RenderStages, + index: u64, + ) -> Result, Error> { + let covering = || { + self.0 + .iter() + .filter(move |(stage, slots, _)| stages.contains(*stage) && slots.contains(&index)) + }; + let joined = covering() + .filter_map(|(_, _, answer)| match answer { + Answer::Access(access) => Some(*access), + Answer::Gap(_) => None, + }) + .reduce(|a, b| if a == b { a } else { BindingAccess::ReadWrite }); + if let Some(access) = joined { + return Ok(Some(access)); + } + match covering().find_map(|(_, _, answer)| match answer { + Answer::Gap(gap) => Some(*gap), + Answer::Access(_) => None, + }) { + Some(gap) => Err(Error::Unsupported( + Unsupported::not_implemented(Feature::Reflection) + .naming(DiagName::new(gap_name(gap))), + )), + None => Ok(None), + } } - /// `memo`'s accesses, from `reflect`'s reflection (under the standard budget) the first time. + /// `memo`'s accesses, from `slot_writes`'s answers (under the standard budget) the first time. + /// A failure to get them is returned and not stored. pub(crate) fn remembered( memo: &TextureAccessMemo, - reflect: impl FnOnce(&Budget) -> Result, + slot_writes: impl FnOnce(&Budget) -> Result, ) -> Result<&TextureAccesses, Error> { - memo.get_or_init(|| { - reflect(&Budget::standard()).map(|reflection| TextureAccesses::of(&reflection)) - }) - .as_ref() - .map_err(Clone::clone) + if let Some(accesses) = memo.get() { + return Ok(accesses); + } + let answers = TextureAccesses::of(&slot_writes(&Budget::standard())?); + // Another thread racing here computed the same answers, so either value will do. + Ok(memo.get_or_init(|| answers)) + } +} + +/// The name a refused slot's gap is reported under. +fn gap_name(gap: metal2vulkan::reflection::SlotWriteGap) -> &'static str { + use metal2vulkan::reflection::SlotWriteGap as G; + match gap { + G::UnresolvedIndex => "a texture slot only a function constant states", + G::UnmeasuredPayloadStage => "a payload in a stage Metal's access is unmeasured for", + G::MemberRole => "an argument whose role only an argument-buffer member takes", + _ => "an undetermined texture slot", } } #[cfg(test)] mod tests { - use super::TextureAccesses; + use super::{Answer, TextureAccesses}; use metal2vulkan::metal::{BindingAccess, RenderStages}; + use metal2vulkan::reflection::SlotWriteGap; /// A slot's answer is the access of the referenced texture argument covering it in the /// stages asked, an array's at each element's slot; stages that agree keep their access, @@ -85,10 +176,10 @@ mod tests { use BindingAccess::{ReadOnly, ReadWrite, WriteOnly}; let (vertex, fragment) = (RenderStages::VERTEX, RenderStages::FRAGMENT); let accesses = TextureAccesses(vec![ - (vertex, 0..1, ReadOnly), - (vertex, 1..2, ReadOnly), - (fragment, 0..1, ReadOnly), - (fragment, 1..3, WriteOnly), + (vertex, 0..1, Answer::Access(ReadOnly)), + (vertex, 1..2, Answer::Access(ReadOnly)), + (fragment, 0..1, Answer::Access(ReadOnly)), + (fragment, 1..3, Answer::Access(WriteOnly)), ]); let both = vertex.union(fragment); for (stages, index, want) in [ @@ -101,7 +192,47 @@ mod tests { (RenderStages::TILE, 0, None), (RenderStages::empty(), 0, None), ] { - assert_eq!(accesses.at(stages, index), want, "{stages:?} {index}"); + assert_eq!( + accesses.at(stages, index).expect("answered"), + want, + "{stages:?} {index}" + ); } } + + /// An undetermined argument refuses the slots it may cover and no others: the slots a + /// determined argument covers keep their answers, and so does every stage it is not in. That + /// is the whole point of answering per slot -- one gap must not take the state with it. + #[test] + fn an_undetermined_argument_refuses_its_own_slots_alone() { + let (vertex, fragment) = (RenderStages::VERTEX, RenderStages::FRAGMENT); + let accesses = TextureAccesses(vec![ + (vertex, 0..1, Answer::Access(BindingAccess::ReadOnly)), + (vertex, 4..5, Answer::Gap(SlotWriteGap::UnresolvedIndex)), + (fragment, 0..2, Answer::Access(BindingAccess::WriteOnly)), + ]); + // The determined slots answer. + assert_eq!( + accesses.at(vertex, 0).expect("answered"), + Some(BindingAccess::ReadOnly) + ); + assert_eq!( + accesses.at(fragment, 1).expect("answered"), + Some(BindingAccess::WriteOnly) + ); + // A slot nothing covers is still unbound, not refused. + assert_eq!(accesses.at(vertex, 9).expect("answered"), None); + // The undetermined slot is refused, and it alone. + assert!(accesses.at(vertex, 4).is_err()); + assert!(accesses.at(fragment, 4).expect("answered").is_none()); + // A determined argument covering the same slot wins: nothing is lost to the gap. + let both = TextureAccesses(vec![ + (vertex, 4..5, Answer::Gap(SlotWriteGap::UnresolvedIndex)), + (vertex, 4..5, Answer::Access(BindingAccess::ReadOnly)), + ]); + assert_eq!( + both.at(vertex, 4).expect("answered"), + Some(BindingAccess::ReadOnly) + ); + } } diff --git a/crates/metal2vulkan-runtime/src/pipeline/tile.rs b/crates/metal2vulkan-runtime/src/pipeline/tile.rs index dd4b57dce..d06c27b6e 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/tile.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/tile.rs @@ -146,11 +146,15 @@ impl TileState { &self.0.descriptor } - /// The tile function's texture slots and their accesses, from the pipeline's reflection - /// (`ComputePipelineState::tile_reflection`, what its compile kept) the first time. + /// The tile function's texture slots and their accesses, from the pipeline's slot writes the + /// first time. They read the tile function's roles, declared accesses and slots, so an + /// argument whose type a reflection cannot describe does not refuse them + /// (`pipeline::texture_access`). pub(crate) fn texture_accesses(&self) -> Result<&TextureAccesses, Error> { TextureAccesses::remembered(&self.0.texture_accesses, |budget| { - self.kernel().tile_reflection(budget) + self.descriptor() + .slot_writes(budget) + .map_err(crate::device::device_error) }) } diff --git a/crates/metal2vulkan-validation/runtime-sources.sha256 b/crates/metal2vulkan-validation/runtime-sources.sha256 index 153be6259..7b66d2307 100644 --- a/crates/metal2vulkan-validation/runtime-sources.sha256 +++ b/crates/metal2vulkan-validation/runtime-sources.sha256 @@ -1 +1 @@ -304014cb15e417ae733affbd4bf32bcb35efe744f463e42f6f98d1fb7a5ebea5 +2f8e9eeabe937aa092359fee957acc18c805cad97e86115d5e716bb0c03efdb1 diff --git a/crates/metal2vulkan/src/cache/codec.rs b/crates/metal2vulkan/src/cache/codec.rs index 554c80503..671c01cc3 100644 --- a/crates/metal2vulkan/src/cache/codec.rs +++ b/crates/metal2vulkan/src/cache/codec.rs @@ -72,8 +72,8 @@ use crate::pipeline::vertex::{ use crate::reflection::{ ArrayType, Binding as ReflectionBinding, BindingKind, BufferBinding, DirectArgumentUse, LinkedUseAnswers, LinkedUseGap, ObjectPayloadBinding, PointerType, RenderPipelineReflection, - StageReflection, StructMember, StructType, TextureBinding, TextureReferenceType, - ThreadgroupBinding, TypeDetail, UnwrittenFragmentInputs, + SlotWritability, SlotWrite, SlotWriteGap, StageReflection, StructMember, StructType, + TextureBinding, TextureReferenceType, ThreadgroupBinding, TypeDetail, UnwrittenFragmentInputs, }; use crate::spirv::serialize::RelocatableModule; use crate::vk; @@ -1253,9 +1253,10 @@ codec_struct! { RelocatableModule { words, relocs, requirements } FunctionArtifact { key, module, interface, facts, subgroup, reconvergence, precision, strategies, blob, - requirements, variant_bits, profile, kernel, reflection, specialized, + requirements, variant_bits, profile, kernel, reflection, slot_writes, specialized, } StageReflection { bindings, attributes } + SlotWrite { name, parameter, binding_type, index, count, used, access, writes } RenderPipelineReflection { vertex, fragment, tile, object, mesh } LinkedUseAnswers { vertex_returns_value, fragment_writes_depth_unattached, stages_using_direct_arguments, @@ -1349,6 +1350,8 @@ codec_struct! { codec_enum! { Reconvergence { Guaranteed, ImplementationDefined } LinkedUseGap { EndlessLoop, StackMemory, GatedOffMeshBuiltin, UnmeasuredColorWrite } + SlotWritability { Never, Maybe, Unknown(f0) } + SlotWriteGap { UnresolvedIndex, UnmeasuredPayloadStage, MemberRole } ImageblockMechanism { StorageImageInterlock } StorageAttachmentView { Attachment, SamplePlanes { layers } } StandInView { Image, SamplePlanes { layers } } diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 882c75772..8d4f85a18 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 = 1824; +pub const SEMANTICS_VERSION: u32 = 1825; /// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the /// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another @@ -70,7 +70,7 @@ pub const SEMANTICS_VERSION: u32 = 1824; /// re-typed in an encoded type, its `codec` body or its `envelope`. A variant removed while its tag /// stays unused needs no bump: an entry holding it fails to decode, which is a miss. The commit that /// bumps it says what changed; this comment keeps no history. -pub const ARTIFACT_FORMAT_VERSION: u32 = 446; +pub const ARTIFACT_FORMAT_VERSION: u32 = 447; /// The version of what this crate's runtime does with a compiled pipeline: instantiating a binding /// plan (`BindingPlan::instantiate_*`: descriptor ranges, push bytes, root, argument, and handle @@ -93,7 +93,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 446; /// changes no behaviour, and then updates that hash alone with the commit saying why, or changes /// behaviour and also bumps this version. The commit that bumps it says what changed; this comment /// keeps no history. -pub const RUNTIME_VERSION: u32 = 1528; +pub const RUNTIME_VERSION: u32 = 1530; /// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex, /// of the manifest, the build script, and exactly the files the crate roots' module tree compiles diff --git a/crates/metal2vulkan/src/library/compiled.rs b/crates/metal2vulkan/src/library/compiled.rs index 9ba2a1621..25a91639b 100644 --- a/crates/metal2vulkan/src/library/compiled.rs +++ b/crates/metal2vulkan/src/library/compiled.rs @@ -208,6 +208,13 @@ pub struct FunctionArtifact { /// compiled function answers its reflection without its AIR. `None` where a binding's answer /// is unmeasured (the reflection refuses it). pub(crate) reflection: Option, + /// What the stage may store through each slot its arguments bind, from the entry the function + /// compiled (`reflection::entry_slot_writes` over it), so a pipeline of the compiled function + /// answers it without its AIR. Never absent: the answer reads each parameter's role, declared + /// access and slot alone and derives no type description, so no unmeasured argument type can + /// take it away, and a per-slot gap is one undetermined answer among the others + /// (`SlotWritability::Unknown`). + pub(crate) slot_writes: Vec, /// The notes of `precision` that hold only under some specializations, with their /// conditions: what its linked stage states as `StageModule::specialized_notes`. pub specialized: Vec, diff --git a/crates/metal2vulkan/src/pipeline/compile.rs b/crates/metal2vulkan/src/pipeline/compile.rs index c0f5a4d0c..23a74814b 100644 --- a/crates/metal2vulkan/src/pipeline/compile.rs +++ b/crates/metal2vulkan/src/pipeline/compile.rs @@ -669,6 +669,53 @@ pub(crate) fn stage_reflection( }) } +/// What stage `fd`, its calls nesting `depth` deep through visible functions, may store through +/// each slot its arguments bind: of the entry [`stage_reflection`] reads, its parameters' roles, +/// declared accesses and slots alone (`reflection::entry_slot_writes`). It derives no type +/// description, so an argument whose reflection Metal's answer has not been measured for does not +/// refuse it: only the decode and the specialization can. +pub(crate) fn stage_slot_writes( + fd: &FunctionDescriptor, + depth: u32, + m: &mut Meter, +) -> Result, Error> { + let mut inputs = LowerInputs::new(); + inputs.max_call_stack_depth = call_stack_input(depth); + guarded(|| { + with_request( + &fd.function, + &fd.constants, + (&fd.linked, &fd.libraries), + InputsFrom::Given(&inputs), + |r| { + let mut decoded = air::decode(r.bitcode, m)?; + if let Some(c) = r.container { + decoded.abi.check_container(&decoded.module, c, m)?; + } + let mut req = spec_request(&decoded, r.entry, r.consts)?; + req.call_stack_depth = r.inputs.call_stack_depth(); + let ep = air::canon::select(&decoded.module, &decoded.abi, &req.entry)?; + if !reflection::needs_resolution(ep, &decoded.abi.structs) + && !reflection::specialization_decides_reads(&decoded.abi) + { + return Ok(reflection::entry_slot_writes(ep)); + } + let before = reflection::UnspecializedReads::of(&decoded.module, &decoded.abi, ep); + let spec = specialize_request(decoded, &req, r, m)?; + match reflection::specialized_reads(&spec, &before) { + Ok(read) => Ok(reflection::entry_slot_writes(&read)), + // Refused over control-point inputs a function constant gates, which bind no + // argument-table slot (`kept_reflection` says what that costs). + Err(Error::Unsupported(u)) if u.feature == Feature::Reflection => { + Ok(reflection::entry_slot_writes(&spec.ep)) + } + Err(error) => Err(error), + } + }, + ) + }) +} + /// Whether stage `fd`, its calls nesting `depth` deep through visible functions, uses a direct /// texture or sampler argument (`[[texture(n)]]`, `[[sampler(n)]]`, a texture array among them) /// that a pipeline's reflection lists as used: of the entry [`stage_reflection`] reads, its @@ -2226,7 +2273,12 @@ fn compile_kept( ) }); let (numbered_samplers, numbering_differs) = numbered::samplers(&spec, unmeasured); - let reflection = kept_reflection(&spec, &before)?; + // The slot writes are kept whatever the reflection could describe, so a pipeline of this + // function always answers what it may store through each of its slots. + let KeptAnswers { + reflection, + slot_writes, + } = kept_reflection(&spec, &before)?; // Decoded AIR is not needed past emission. drop(spec); // The function's own side effects; the `ExecutionStatus` buffer's words (the resident-miss @@ -2526,33 +2578,63 @@ fn compile_kept( profile: p.fingerprint(), kernel, reflection, + slot_writes, specialized, }); Ok((artifact, plan, kept)) } /// What a pipeline's reflection states for the compiled entry `spec`, kept in its artifact for a -/// `StageSource::Compiled` stage: its bindings as the pipeline channel answers them and the -/// attributes it reads, as [`stage_reflection`] answers from the same specialized entry and what -/// its code read before specialization (`before`); `None` where a binding's answer is unmeasured -/// (`Feature::Reflection`). +/// `StageSource::Compiled` stage, and what the stage may store through each slot its arguments +/// bind, both from the same specialized entry and what its code read before specialization +/// (`before`), as [`stage_reflection`] and [`stage_slot_writes`] answer them from a function. +/// +/// The reflection is `None` where a binding's answer is unmeasured (`Feature::Reflection`). The +/// slot writes are always kept: they read the entry's roles, declared accesses and slots alone. fn kept_reflection( spec: &air::Entry, before: &reflection::UnspecializedReads, -) -> Result, Error> { - let answer = reflection::specialized_reads(spec, before).and_then(|read| { +) -> Result { + let read = match reflection::specialized_reads(spec, before) { + Ok(read) => read, + // Refused over control-point inputs a function constant gates. Those bind no + // argument-table slot, so the entry's own parameters still state every slot's access; + // what the specialized read would have added is which arguments the constants leave + // unread. + Err(Error::Unsupported(u)) if u.feature == Feature::Reflection => { + return Ok(KeptAnswers { + reflection: None, + slot_writes: reflection::entry_slot_writes(&spec.ep), + }) + } + Err(error) => return Err(error), + }; + let slot_writes = reflection::entry_slot_writes(&read); + let answer = (|| { Ok(reflection::StageReflection { bindings: reflection::bindings(&read, &spec.structs, reflection::Channel::Pipeline)?, attributes: reflection::read_attributes(&read)?, }) - }); + })(); match answer { - Ok(stage) => Ok(Some(stage)), - Err(Error::Unsupported(u)) if u.feature == Feature::Reflection => Ok(None), + Ok(stage) => Ok(KeptAnswers { + reflection: Some(stage), + slot_writes, + }), + Err(Error::Unsupported(u)) if u.feature == Feature::Reflection => Ok(KeptAnswers { + reflection: None, + slot_writes, + }), Err(error) => Err(error), } } +/// What [`kept_reflection`] keeps of one compiled entry for its artifact. +struct KeptAnswers { + reflection: Option, + slot_writes: Vec, +} + fn census(plan: &Plan) -> StrategyCensus { let mut c = StrategyCensus::default(); for (name, (uses, words)) in plan.census() { diff --git a/crates/metal2vulkan/src/pipeline/compile/tests.rs b/crates/metal2vulkan/src/pipeline/compile/tests.rs index 4e83520af..d018cfff5 100644 --- a/crates/metal2vulkan/src/pipeline/compile/tests.rs +++ b/crates/metal2vulkan/src/pipeline/compile/tests.rs @@ -324,6 +324,50 @@ fn a_compute_pipeline_compiles_from_a_function() { } } +/// A `Compiled` stage answers what it may store through each of its slots from what its compile +/// kept, with no decode, and its answer is the `Function` path's: the two read the same entry's +/// roles, declared accesses and slots. It is the answer a consumer needs for a state it already +/// made, and a compile keeps it whatever a reflection of the same entry could describe. +#[test] +fn a_compiled_stage_answers_its_slot_writes_without_decoding() { + let Some(bc) = fixture("store_const") else { + return; + }; + let dev = device("moltenvk-m3"); + let f = Library::from_air(&bc) + .expect("library") + .function("store_const") + .expect("function"); + let fd = FunctionDescriptor::new(f.clone()); + let inp = LoweringInputs::new(); + let compiled = dev + .compile_function(&fd, &inp, &Budget::standard()) + .expect("compile"); + + let from_function = ComputePipelineDescriptor::new(StageSource::Function(fd)) + .slot_writes(&Budget::default()) + .expect("the function path answers"); + let from_compiled = ComputePipelineDescriptor::new(StageSource::Compiled(compiled)) + .slot_writes(&Budget::default()) + .expect("the compiled path answers"); + assert_eq!(from_compiled, from_function); + + // `device uint *out [[buffer(0)]]`: read-write, as Metal answers a device buffer. + let slots = from_compiled.kernel_slots(); + assert_eq!(slots.len(), 1); + assert_eq!(slots[0].name, "out"); + assert_eq!(slots[0].index, Some(0)); + assert_eq!( + crate::reflection::SlotWrite::may_write(slots, metal::BindingType::Buffer, 0), + crate::reflection::SlotWritability::Maybe + ); + // No argument binds buffer 1, so nothing stores through it. + assert_eq!( + crate::reflection::SlotWrite::may_write(slots, metal::BindingType::Buffer, 1), + crate::reflection::SlotWritability::Never + ); +} + /// A `Compiled` stage is link and relocate only. The pipeline meter does no work (no decode, no /// lowering), and the result equals the `Function` path's. #[test] diff --git a/crates/metal2vulkan/src/pipeline/link/tests.rs b/crates/metal2vulkan/src/pipeline/link/tests.rs index d175122ba..cd6e4feba 100644 --- a/crates/metal2vulkan/src/pipeline/link/tests.rs +++ b/crates/metal2vulkan/src/pipeline/link/tests.rs @@ -155,6 +155,7 @@ pub(super) fn artifact( profile: [0; 32], kernel: Default::default(), reflection: None, + slot_writes: Vec::new(), specialized: Vec::new(), } } diff --git a/crates/metal2vulkan/src/reflection/mod.rs b/crates/metal2vulkan/src/reflection/mod.rs index 9bcae1e60..35a807ad2 100644 --- a/crates/metal2vulkan/src/reflection/mod.rs +++ b/crates/metal2vulkan/src/reflection/mod.rs @@ -80,11 +80,16 @@ pub(crate) use linked::dropped_fragment_inputs; pub use linked::{DirectArgumentUse, LinkedUseAnswers, LinkedUseGap, UnwrittenFragmentInputs}; mod live; mod types; +mod writes; +pub(crate) use writes::entry_slot_writes; +pub use writes::{SlotWritability, SlotWrite, SlotWriteGap, SlotWrites}; #[cfg(test)] mod linked_tests; #[cfg(test)] mod tests; +#[cfg(test)] +mod writes_tests; pub(crate) use derive::{ bindings, needs_resolution, read_attributes, specialization_decides_reads, specialized_reads, @@ -252,6 +257,21 @@ fn stage(source: &StageSource, depth: u32, m: &mut Meter) -> Result Result, Error> { + match source { + StageSource::Function(fd) => crate::pipeline::compile::stage_slot_writes(fd, depth, m), + StageSource::Compiled(c) => Ok(c.artifact().slot_writes.clone()), + } +} + /// Whether stage `source`, its calls nesting `depth` deep, uses a direct texture or sampler /// argument that its reflection lists as used: decided from the arguments' roles and use alone /// (`compile::stage_uses_direct_arguments`), so an argument whose reflection Metal's answer has @@ -371,6 +391,27 @@ impl ComputePipelineDescriptor { let mut m = Meter::new(budget); stage_direct(&self.kernel, self.max_call_stack_depth, &mut m) } + + /// What the kernel may store through each slot its arguments bind + /// ([`writes`](crate::reflection::SlotWrite), whose rules are + /// [`reflection`](crate::reflection)'s), of the entry its constants specialize where they + /// decide a slot: the answers in [`SlotWrites::kernel_slots`]. The stage input descriptor's + /// buffers are not among them, since they bind no argument of the kernel. It decodes the + /// kernel's AIR under `budget`; a kernel the compile layer already compiled answers what its + /// compile kept, decoding nothing. + /// + /// Unlike [`reflection`](Self::reflection) it derives no type description, so an argument + /// whose *type* Metal's answer has not been measured for does not refuse it: a kernel that + /// compiles answers, and an argument whose own slot or access is undetermined is one + /// [`SlotWritability::Unknown`] answer among determined ones. Refused only by the decode's + /// and specialization's own errors. + pub fn slot_writes(&self, budget: &crate::Budget) -> Result { + let mut m = Meter::new(budget); + Ok(SlotWrites { + kernel: stage_writes(&self.kernel, self.max_call_stack_depth, &mut m)?, + ..SlotWrites::default() + }) + } } impl RenderPipelineDescriptor { @@ -409,6 +450,29 @@ impl RenderPipelineDescriptor { ..RenderPipelineReflection::default() }) } + + /// What each stage of the drawing pipeline this descriptor describes may store through each + /// slot its arguments bind ([`ComputePipelineDescriptor::slot_writes`]'s answer per stage): + /// [`SlotWrites::vertex_slots`] and [`SlotWrites::fragment_slots`]. The vertex descriptor's + /// buffers are not among the vertex answers, since they bind no argument of the function. + /// + /// This is the question [`reflection`](Self::reflection) also answers, in + /// [`Binding::access`], without the type description that makes a reflection refuse a + /// function whose argument types Metal's answer has not been measured for. A state that + /// compiles answers here. Refused only by the decode's and specialization's own errors. + pub fn slot_writes(&self, budget: &crate::Budget) -> Result { + let mut m = Meter::new(budget); + let vertex = stage_writes(&self.vertex, self.max_vertex_call_stack_depth, &mut m)?; + let fragment = match &self.fragment { + Some(f) => stage_writes(f, self.max_fragment_call_stack_depth, &mut m)?, + None => Vec::new(), + }; + Ok(SlotWrites { + vertex, + fragment, + ..SlotWrites::default() + }) + } } impl MeshPipelineDescriptor { @@ -438,6 +502,31 @@ impl MeshPipelineDescriptor { ..RenderPipelineReflection::default() }) } + + /// What each stage of the mesh pipeline this descriptor describes may store through each slot + /// its arguments bind ([`ComputePipelineDescriptor::slot_writes`]'s answer per stage): + /// [`SlotWrites::object_slots`], [`SlotWrites::mesh_slots`] and + /// [`SlotWrites::fragment_slots`], an object or mesh function's payload among them. Each + /// stage's calls nest Metal's default depth of 1, as `Device::compile_mesh_pipeline` compiles + /// it. Refused only by the decode's and specialization's own errors. + pub fn slot_writes(&self, budget: &crate::Budget) -> Result { + let mut m = Meter::new(budget); + let object = match &self.object { + Some(o) => stage_writes(o, 1, &mut m)?, + None => Vec::new(), + }; + let mesh = stage_writes(&self.mesh, 1, &mut m)?; + let fragment = match &self.fragment { + Some(f) => stage_writes(f, 1, &mut m)?, + None => Vec::new(), + }; + Ok(SlotWrites { + fragment, + object, + mesh, + ..SlotWrites::default() + }) + } } impl TileRenderPipelineDescriptor { @@ -454,6 +543,18 @@ impl TileRenderPipelineDescriptor { ..RenderPipelineReflection::default() }) } + + /// What the tile function of the pipeline this descriptor describes may store through each + /// slot its arguments bind ([`ComputePipelineDescriptor::slot_writes`]'s answer for the tile + /// stage): [`SlotWrites::tile_slots`], a tile function's implicit imageblock among them. + /// Refused only by the decode's and specialization's own errors. + pub fn slot_writes(&self, budget: &crate::Budget) -> Result { + let mut m = Meter::new(budget); + Ok(SlotWrites { + tile: stage_writes(&self.tile, self.max_call_stack_depth, &mut m)?, + ..SlotWrites::default() + }) + } } /// `id`: one argument a function or pipeline binds, with the fields of the kind it diff --git a/crates/metal2vulkan/src/reflection/writes.rs b/crates/metal2vulkan/src/reflection/writes.rs new file mode 100644 index 000000000..02910cb41 --- /dev/null +++ b/crates/metal2vulkan/src/reflection/writes.rs @@ -0,0 +1,439 @@ +//! Whether a function may store through the object bound at one of its argument-table slots. +//! +//! The question a consumer asks of a state it is about to bind resources to: *may this function +//! write the object at this slot?* A slot the function cannot store through holds a resource no +//! draw or dispatch of the state can dirty, so a read-only buffer may sit there. +//! +//! It is answered from the entry's AIR metadata ABI alone: each parameter's role, the access its +//! declaration states (`air.read`, `air.write`, `air.read_write`, `air.sample`) and the slot it +//! binds (`air.location_index`). The declared access is the whole of it; the address space beside +//! it (`air.address_space`) is not read, and needs not be, since Apple's compiler writes +//! `air.read` for a `constant` or `const device` buffer and `air.read_write` for a `device` one. +//! +//! It is the same field the reflection derives [`Binding::access`](super::Binding::access) from, +//! so the two answers agree by construction, and +//! `writes_tests::every_fixture_kernel_answers_and_agrees_with_its_reflection` holds them +//! together over the recorded fixtures. The values are Metal's `MTLBinding.access` (the +//! measurements are +//! [`reflection`](super)'s): a `device` buffer is read-write whether the function reads it, writes +//! it or both; a `constant` or `const device` buffer is read-only; a texture read or sampled is +//! read-only, one written write-only, one `read_write` read-write; samplers, function tables, +//! acceleration structures and imageblocks are read-only; threadgroup memory is read-write; an +//! object function's payload is read-write and a mesh function's read-only. +//! +//! It derives **no type description**: not a pointee's data type, struct members, array strides, +//! sizes or alignments. That is the whole difference from a reflection, and the reason this +//! question is answerable where a reflection is refused. A reflection must give Metal's +//! `MTLType` for every binding, and refuses the function where Metal's answer for one argument's +//! *type* has not been measured (an argument buffer's member the AIR gives no argument index, a +//! pipeline's stride for an array of structs holding a struct, a type name the data-type table +//! does not know). None of those describe an access, so none of them need stop this answer: a +//! function whose reflection is refused still states, for every argument, what it may do to it. +//! +//! So a state that compiles always answers, and the answer is per slot: an argument whose own +//! access or slot cannot be determined is one [`SlotWrite`], naming the parameter and the +//! [`SlotWriteGap`] that left it undetermined, and the other arguments keep their answers. No +//! uncertainty is spread over the rest of the state, and an undetermined slot never reads as +//! writable nor as not writable: [`SlotWrite::may_write`] answers +//! [`SlotWritability::Unknown`] for it. + +use crate::air::abi::{ + AbiInt, AccelerationStructureKind, Access, EntryPoint, ImageblockKind, ParamBinding, ParamRole, + Slot, Stage, +}; +use crate::metal::{BindingAccess, BindingType}; + +/// Whether a function may store through the object bound at one argument-table slot. +#[non_exhaustive] +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub enum SlotWritability { + /// The function cannot store through the slot: its declaration is read-only, so no store it + /// performs can land on the object bound there (a `constant` or `const device` buffer, a + /// texture declared `access::read` or `access::sample`, a sampler, a visible-function or + /// intersection-function table, an acceleration structure, an imageblock, or a mesh + /// function's payload). + Never, + /// The function may store through the slot: its declaration is write-only or read-write (a + /// `device` buffer, which Metal answers read-write whether the function reads it, writes it + /// or neither, a texture declared `access::write` or `access::read_write`, threadgroup + /// memory, or an object function's payload). + Maybe, + /// Undetermined for this slot alone, for the reason named. It is neither [`Never`] nor + /// [`Maybe`]: a caller that must be safe treats it as writable, and one that reports gaps + /// reports this one. + /// + /// [`Never`]: SlotWritability::Never + /// [`Maybe`]: SlotWritability::Maybe + Unknown(SlotWriteGap), +} + +impl SlotWritability { + /// Whether the answer is [`SlotWritability::Never`]: the one answer that lets a caller bind a + /// resource it must not let the state write. + pub fn is_never(self) -> bool { + matches!(self, SlotWritability::Never) + } + + /// The gap that left the answer undetermined; `None` for a determined one. + pub fn gap(self) -> Option { + match self { + SlotWritability::Unknown(gap) => Some(gap), + SlotWritability::Never | SlotWritability::Maybe => None, + } + } +} + +/// Why one slot's writability is undetermined. +#[non_exhaustive] +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub enum SlotWriteGap { + /// Only a function constant states the argument's slot or the length of its span + /// (`air.location_index` naming a global, `[[buffer(base + 2)]]`), and the values the entry + /// was specialized with did not fold it to a literal. Which slots the argument binds is + /// therefore not known, so every slot of its binding type answers `Unknown` rather than let + /// one read as `Never` that the argument may cover. + UnresolvedIndex, + /// A `[[payload]]` argument of a stage that is neither an object nor a mesh function. Metal's + /// access for one has been measured in those two stages alone (read-write in the object + /// function that fills it, read-only in the mesh function that reads it). + UnmeasuredPayloadStage, + /// The argument's role is one only an argument-buffer member takes: an inline constant, an + /// indirect command buffer, a render or compute pipeline state, or a depth-stencil state. A + /// top-level parameter of such a role is a shape no measurement covers, so what Metal binds + /// it to and what it answers for it are both unknown. + MemberRole, +} + +/// What a function may do to the object bound at one of its argument-table slots: one per +/// argument that binds a slot, in the order the function declares its arguments, as +/// [`RenderPipelineDescriptor::slot_writes`] and its compute, mesh and tile forms answer. +/// +/// [`RenderPipelineDescriptor::slot_writes`]: crate::pipeline::RenderPipelineDescriptor::slot_writes +#[non_exhaustive] +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct SlotWrite { + /// The argument's name (`air.arg_name`), as its reflection names it; empty for an argument + /// the metadata leaves unnamed. + pub name: String, + /// The argument's parameter index in the entry's signature, which names it whatever else + /// about it is undetermined. + pub parameter: u32, + /// The kind of binding the argument is, as [`Binding::binding_type`](super::Binding::binding_type) + /// answers it; `None` where the role determines none ([`SlotWriteGap::MemberRole`]). + pub binding_type: Option, + /// The argument-table index the argument binds (`air.location_index`), `u32::MAX` for a + /// payload and 0 for an imageblock, as Metal answers; `None` where only a function constant + /// states it ([`SlotWriteGap::UnresolvedIndex`]). + pub index: Option, + /// The number of consecutive slots the argument binds from [`index`](Self::index), 1 for a + /// single argument and `N` for an `array` of textures or samplers; `None` where only a + /// function constant states it. + pub count: Option, + /// Whether the function references the argument (`air.arg_unused` unset), as + /// [`Binding::is_used`](super::Binding::is_used) answers it. An unused argument still binds + /// its slot, and its declaration still states what a store through it could do, so it is + /// answered like any other. + pub used: bool, + /// The argument's declared access, exactly as [`Binding::access`](super::Binding::access) + /// answers it for the same argument (Metal's `MTLBindingAccess`); `None` where the + /// declaration states none, which is where [`writes`](Self::writes) is + /// [`SlotWritability::Unknown`] for a reason other than the slot + /// ([`SlotWriteGap::UnmeasuredPayloadStage`], [`SlotWriteGap::MemberRole`]). + /// + /// It is stated even where the slots the argument binds are not + /// ([`SlotWriteGap::UnresolvedIndex`]): what the function may do to the argument is known, + /// and only which slots it applies to is not. + pub access: Option, + /// What the function may do to the object bound at the slot. + pub writes: SlotWritability, +} + +impl SlotWrite { + /// Whether a function whose arguments answer `slots` may store through the object bound at + /// `binding_type` slot `index`. + /// + /// [`SlotWritability::Maybe`] where an argument that covers the slot may be stored through, + /// [`SlotWritability::Unknown`] where none may but one is undetermined or binds a slot the + /// entry does not state, and [`SlotWritability::Never`] otherwise, a slot no argument covers + /// included (nothing binds it, so nothing stores through it). + /// + /// An argument whose slot is undetermined ([`SlotWriteGap::UnresolvedIndex`]) may be the one + /// at `index`, so it leaves every slot of its binding type `Unknown` rather than letting one + /// read as `Never`. + pub fn may_write( + slots: &[SlotWrite], + binding_type: BindingType, + index: u32, + ) -> SlotWritability { + let mut gap = None; + for s in slots { + // An argument of another binding type covers no slot of this one. One whose role + // determines no binding type at all (`MemberRole`) is not ruled out: what Metal + // binds it to is unknown, so it may be this slot. + if s.binding_type.is_some_and(|t| t != binding_type) { + continue; + } + let covers = match (s.index, s.count, s.binding_type) { + (Some(first), Some(count), Some(_)) => { + index >= first && index - first < count.max(1) + } + // A slot or span the metadata leaves open may be the one asked for. + _ => true, + }; + if !covers { + continue; + } + match s.writes { + SlotWritability::Maybe => return SlotWritability::Maybe, + SlotWritability::Unknown(g) => gap = gap.or(Some(g)), + SlotWritability::Never => {} + } + } + match gap { + Some(gap) => SlotWritability::Unknown(gap), + None => SlotWritability::Never, + } + } +} + +/// The slots of each stage of one pipeline, as the pipeline descriptors' `slot_writes` answer: +/// a stage the pipeline does not have has none. +#[non_exhaustive] +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct SlotWrites { + pub(crate) kernel: Vec, + pub(crate) vertex: Vec, + pub(crate) fragment: Vec, + pub(crate) tile: Vec, + pub(crate) object: Vec, + pub(crate) mesh: Vec, +} + +impl SlotWrites { + /// The kernel's arguments; none for a pipeline without a compute stage. + pub fn kernel_slots(&self) -> &[SlotWrite] { + &self.kernel + } + + /// The vertex function's arguments; none for a pipeline without a vertex stage. A vertex + /// descriptor's buffers are not among them: they bind no argument of the function, and a + /// pipeline never stores through one. + pub fn vertex_slots(&self) -> &[SlotWrite] { + &self.vertex + } + + /// The fragment function's arguments; none for a pipeline without a fragment stage. + pub fn fragment_slots(&self) -> &[SlotWrite] { + &self.fragment + } + + /// The tile function's arguments; none for a pipeline without a tile stage. + pub fn tile_slots(&self) -> &[SlotWrite] { + &self.tile + } + + /// The object function's arguments; none for a pipeline without an object stage. + pub fn object_slots(&self) -> &[SlotWrite] { + &self.object + } + + /// The mesh function's arguments; none for a pipeline without a mesh stage. + pub fn mesh_slots(&self) -> &[SlotWrite] { + &self.mesh + } + + /// Every stage's answers, in the order the stages are listed above. + pub fn stages(&self) -> [&[SlotWrite]; 6] { + [ + &self.kernel, + &self.vertex, + &self.fragment, + &self.tile, + &self.object, + &self.mesh, + ] + } +} + +/// `MTLBindingAccess` of a declared access, as `derive::binding_access` answers it for the same +/// argument's reflection. +fn declared(access: Access) -> BindingAccess { + match access { + Access::Read | Access::Sample => BindingAccess::ReadOnly, + Access::Write => BindingAccess::WriteOnly, + Access::ReadWrite => BindingAccess::ReadWrite, + } +} + +/// Whether a store may land through a binding of declared access `access`. +fn writability(access: BindingAccess) -> SlotWritability { + match access { + BindingAccess::ReadOnly => SlotWritability::Never, + BindingAccess::WriteOnly | BindingAccess::ReadWrite => SlotWritability::Maybe, + } +} + +/// An index or count the metadata states, `None` for one only a function constant gives. +fn stated(v: AbiInt) -> Option { + match v { + AbiInt::Const(x) => Some(x), + AbiInt::Global(_) => None, + } +} + +/// What entry `ep` may do to each slot its arguments bind, in declaration order: the arguments +/// that bind an argument-table slot, builtins and stage inputs left out as a reflection leaves +/// them out. Infallible by construction, since it reads each parameter's role, declared access +/// and slot alone and derives no type description. +pub(crate) fn entry_slot_writes(ep: &EntryPoint) -> Vec { + let mut out = Vec::new(); + for p in &ep.params { + if let Some(w) = slot_write(ep, p) { + out.push(w); + } + } + out +} + +/// The answer for parameter `p` of `ep`; `None` for a parameter that binds no argument-table slot. +fn slot_write(ep: &EntryPoint, p: &ParamBinding) -> Option { + // An index and count a slot states, with the span of a single argument where the metadata + // gives no count. + let at = |slot: Slot| (stated(slot.index), stated(slot.count).map(|c| c.max(1))); + let (binding_type, index, count, access) = match &p.role { + ParamRole::Buffer(b) | ParamRole::ArgumentBuffer(b) => { + let (index, count) = at(b.location); + ( + Some(BindingType::Buffer), + index, + count, + Ok(declared(b.access)), + ) + } + ParamRole::Threadgroup(b) => { + let (index, count) = at(b.location); + ( + Some(BindingType::ThreadgroupMemory), + index, + count, + Ok(declared(b.access)), + ) + } + ParamRole::Texture(t) => { + let (index, count) = at(t.location); + ( + Some(BindingType::Texture), + index, + count, + Ok(declared(t.access)), + ) + } + ParamRole::Sampler { location } => { + let (index, count) = at(*location); + ( + Some(BindingType::Sampler), + index, + count, + Ok(BindingAccess::ReadOnly), + ) + } + ParamRole::FunctionTable(o) => { + let (index, count) = at(o.location); + ( + Some(BindingType::VisibleFunctionTable), + index, + count, + Ok(BindingAccess::ReadOnly), + ) + } + ParamRole::IntersectionTable(o) => { + let (index, count) = at(o.location); + ( + Some(BindingType::IntersectionFunctionTable), + index, + count, + Ok(BindingAccess::ReadOnly), + ) + } + ParamRole::AccelerationStructure { kind, arg } => { + let (index, count) = at(arg.location); + let binding_type = match kind { + AccelerationStructureKind::Instance => BindingType::InstanceAccelerationStructure, + AccelerationStructureKind::Primitive => BindingType::PrimitiveAccelerationStructure, + }; + ( + Some(binding_type), + index, + count, + Ok(BindingAccess::ReadOnly), + ) + } + // An imageblock binds index 0 and is read-only, whichever the function does with it, as + // Metal answers. + ParamRole::Imageblock(ib) => { + let binding_type = match ib.kind { + ImageblockKind::Implicit | ImageblockKind::Explicit => BindingType::Imageblock, + ImageblockKind::Data => BindingType::ImageblockData, + }; + ( + Some(binding_type), + Some(0), + Some(1), + Ok(BindingAccess::ReadOnly), + ) + } + // An object function fills its payload and a mesh function reads it; Metal's access for + // one in any other stage is unmeasured. + ParamRole::Payload { .. } => { + let access = match ep.stage { + Stage::Object { .. } => Ok(BindingAccess::ReadWrite), + Stage::Mesh { .. } => Ok(BindingAccess::ReadOnly), + Stage::Kernel { .. } | Stage::Vertex { .. } | Stage::Fragment { .. } => { + Err(SlotWriteGap::UnmeasuredPayloadStage) + } + }; + ( + Some(BindingType::ObjectPayload), + Some(u32::MAX), + Some(1), + access, + ) + } + // Builtins, stage inputs, the mesh grid and the mesh output bind no argument-table slot. + ParamRole::Builtin(_) + | ParamRole::StageIn { .. } + | ParamRole::VertexInput { .. } + | ParamRole::FragmentInput(_) + | ParamRole::ColorInput { .. } + | ParamRole::PatchInput(_) + | ParamRole::MeshGridProperties + | ParamRole::Mesh(_) => return None, + // Roles of argument-buffer members only. + ParamRole::IndirectConstant { .. } + | ParamRole::CommandBuffer(_) + | ParamRole::ComputePipelineState(_) + | ParamRole::RenderPipelineState(_) + | ParamRole::DepthStencilState(_) => (None, None, None, Err(SlotWriteGap::MemberRole)), + }; + // The declaration states the access; a slot or span only a function constant states leaves + // which slots that access applies to unknown. + let writes = match (access, index, count) { + (Err(gap), _, _) => SlotWritability::Unknown(gap), + (Ok(access), Some(_), Some(_)) => writability(access), + (Ok(_), _, _) => SlotWritability::Unknown(SlotWriteGap::UnresolvedIndex), + }; + Some(SlotWrite { + name: p.name.as_ref().map(ToString::to_string).unwrap_or_default(), + parameter: p.param, + binding_type, + index, + count, + used: !p.unused, + access: access.ok(), + writes, + }) +} diff --git a/crates/metal2vulkan/src/reflection/writes_tests.rs b/crates/metal2vulkan/src/reflection/writes_tests.rs new file mode 100644 index 000000000..7c1347588 --- /dev/null +++ b/crates/metal2vulkan/src/reflection/writes_tests.rs @@ -0,0 +1,393 @@ +//! A state whose reflection is refused still answers what it may store through each slot. +//! +//! The shape here is the one a consumer's workload failed on: a kernel whose arguments include +//! one whose *type* the reflection cannot describe (a struct pointee the AIR gives no +//! `air.struct_type_info` and whose `air.arg_type_name` is not a name the MSL data-type grammar +//! covers). Deriving the type description refuses the whole entry's bindings, so `reflection` +//! answers nothing about any slot, including the read-only ones; the writability question derives +//! no type description and answers each slot. + +use super::{SlotWritability, SlotWrite, SlotWriteGap}; +use crate::budget::Budget; +use crate::error::{Error, Feature}; +use crate::library::Library; +use crate::metal::{BindingAccess, BindingType}; +use crate::pipeline::{ComputePipelineDescriptor, FunctionDescriptor, StageSource}; + +/// A kernel whose four bindings are, in declaration order: +/// +/// - `buffer(0)`, `constant` and `air.read`: a struct pointee with no `air.struct_type_info`, so +/// its `air.arg_type_name` (`Uniforms`) is the only thing stating its type, and the data-type +/// grammar does not name it. The reflection of the entry is refused here. +/// - `buffer(1)`, `device` and `air.read_write`: a plain `float` pointee. +/// - `texture(0)` declared `access::read`. +/// - `texture(1)` declared `access::write`. +/// +/// The two read-only bindings are the ones a consumer must be able to tell apart from the +/// writable ones: a read-only vertex or index buffer may sit at `buffer(0)`. +fn module() -> String { + r#"target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32" +target triple = "air64_v28-apple-macosx26.0.0" + +%struct.Uniforms = type { float, float } + +define void @shade(ptr addrspace(2) noundef %0, ptr addrspace(1) noundef %1, ptr addrspace(1) noundef %2, ptr addrspace(1) noundef %3, <3 x i32> noundef %4) { + %6 = load float, ptr addrspace(2) %0, align 4 + store float %6, ptr addrspace(1) %1, align 4 + ret void +} + +!air.kernel = !{!0} +!air.version = !{!20} +!air.language_version = !{!21} + +!0 = !{ptr @shade, !1, !2} +!1 = !{} +!2 = !{!3, !4, !5, !6, !7} +!3 = !{i32 0, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 8, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"Uniforms", !"air.arg_name", !"uniforms"} +!4 = !{i32 1, !"air.buffer", !"air.location_index", i32 1, i32 1, !"air.read_write", !"air.address_space", i32 1, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"out"} +!5 = !{i32 2, !"air.texture", !"air.location_index", i32 0, i32 1, !"air.read", !"air.arg_type_name", !"texture2d", !"air.arg_name", !"source"} +!6 = !{i32 3, !"air.texture", !"air.location_index", i32 1, i32 1, !"air.write", !"air.arg_type_name", !"texture2d", !"air.arg_name", !"destination"} +!7 = !{i32 4, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint3", !"air.arg_name", !"tid"} +!20 = !{i32 2, i32 8, i32 0} +!21 = !{!"Metal", i32 4, i32 0, i32 0} +"# + .to_owned() +} + +/// The kernel of [`module`] as a compute pipeline descriptor; `None` where `llvm-as` is missing. +fn kernel() -> Option { + let bitcode = match metal2vulkan_devtools::llvm_assemble_text(&module()) { + Ok(bitcode) => bitcode, + Err(metal2vulkan_devtools::AssembleError::Missing(why)) => { + eprintln!("SKIPPED: {why}"); + return None; + } + Err(metal2vulkan_devtools::AssembleError::Rejected(why)) => { + panic!("llvm-as rejected the module: {why}") + } + }; + let library = Library::from_air(&bitcode).expect("the module decodes"); + let f = library.function("shade").expect("the kernel"); + Some(ComputePipelineDescriptor::new(StageSource::Function( + FunctionDescriptor::new(f), + ))) +} + +/// The reflection of the kernel is refused, naming the argument whose type it cannot describe, so +/// it answers nothing about any slot: the shape a consumer's session died on, kept as the reason +/// the writability question exists apart from it. +#[test] +fn a_reflection_is_refused_for_an_argument_type_it_cannot_describe() { + let Some(kernel) = kernel() else { return }; + match kernel.reflection(&Budget::standard()) { + Err(Error::Unsupported(u)) => { + assert_eq!(u.feature, Feature::Reflection); + assert_eq!( + u.symbol.as_ref().map(ToString::to_string).as_deref(), + Some("Uniforms"), + "the refusal names the argument's type" + ); + } + other => panic!("the reflection was not refused: {other:?}"), + } +} + +/// The same kernel answers what it may store through each of its slots: the `constant` buffer and +/// the `access::read` texture cannot be written, the `device` buffer and the `access::write` +/// texture may be. Every binding is answered, the one whose type refused the reflection included, +/// and no answer is `Unknown`. +#[test] +fn a_state_whose_reflection_is_refused_still_answers_its_slot_writes() { + let Some(kernel) = kernel() else { return }; + let writes = kernel + .slot_writes(&Budget::standard()) + .expect("the slot writes are answered where the reflection is refused"); + let slots = writes.kernel_slots(); + let seen: Vec<_> = slots + .iter() + .map(|s| (s.name.as_str(), s.binding_type, s.index, s.writes)) + .collect(); + assert_eq!( + seen, + [ + ( + "uniforms", + Some(BindingType::Buffer), + Some(0), + SlotWritability::Never + ), + ( + "out", + Some(BindingType::Buffer), + Some(1), + SlotWritability::Maybe + ), + ( + "source", + Some(BindingType::Texture), + Some(0), + SlotWritability::Never + ), + ( + "destination", + Some(BindingType::Texture), + Some(1), + SlotWritability::Maybe + ), + ] + ); + // The builtin binds no slot. + assert_eq!(slots.len(), 4); + assert!(slots.iter().all(|s| s.writes.gap().is_none())); + assert!(slots.iter().all(|s| s.used)); +} + +/// The per-slot question a consumer asks: the read-only slots answer `Never`, which is what lets +/// a read-only buffer sit at one. A blanket "every slot may be written" answer fails here. +#[test] +fn the_slot_question_separates_the_read_only_slots_from_the_writable_ones() { + let Some(kernel) = kernel() else { return }; + let writes = kernel.slot_writes(&Budget::standard()).expect("answered"); + let at = |binding_type, index| SlotWrite::may_write(writes.kernel_slots(), binding_type, index); + assert_eq!(at(BindingType::Buffer, 0), SlotWritability::Never); + assert_eq!(at(BindingType::Buffer, 1), SlotWritability::Maybe); + assert_eq!(at(BindingType::Texture, 0), SlotWritability::Never); + assert_eq!(at(BindingType::Texture, 1), SlotWritability::Maybe); + // A slot no argument binds is one nothing stores through. + assert_eq!(at(BindingType::Buffer, 7), SlotWritability::Never); + assert_eq!(at(BindingType::Sampler, 0), SlotWritability::Never); +} + +/// An argument of undetermined writability is one answer among determined ones, and it never +/// reads as writable nor as not writable: the slots it may cover answer `Unknown` with its gap, +/// and the other slots keep their own answers. +#[test] +fn an_undetermined_slot_stays_undetermined_and_leaves_the_others_alone() { + let answer = |name: &str, binding_type, index, count, access, writes| SlotWrite { + name: name.to_owned(), + parameter: 0, + binding_type, + index, + count, + used: true, + access, + writes, + }; + let slots = [ + answer( + "read_only", + Some(BindingType::Buffer), + Some(0), + Some(1), + Some(BindingAccess::ReadOnly), + SlotWritability::Never, + ), + // A slot only a function constant states: the declared access is known (read-write), but + // which buffer slot it applies to is not. + answer( + "computed", + Some(BindingType::Buffer), + None, + None, + Some(BindingAccess::ReadWrite), + SlotWritability::Unknown(SlotWriteGap::UnresolvedIndex), + ), + answer( + "sampled", + Some(BindingType::Texture), + Some(3), + Some(1), + Some(BindingAccess::ReadOnly), + SlotWritability::Never, + ), + ]; + let at = |binding_type, index| SlotWrite::may_write(&slots, binding_type, index); + // Every buffer slot is undetermined, the one a determined answer calls read-only included: + // the argument of unknown slot may be that very slot. + for index in [0, 1, 30] { + assert_eq!( + at(BindingType::Buffer, index), + SlotWritability::Unknown(SlotWriteGap::UnresolvedIndex), + "buffer {index}" + ); + } + // The uncertainty stays with the buffer slots: a texture slot keeps its own answer. + assert_eq!(at(BindingType::Texture, 3), SlotWritability::Never); + assert_eq!(at(BindingType::Texture, 0), SlotWritability::Never); +} + +/// A texture `array, N>` binds `N` consecutive slots from its index, and only +/// those: a writable array leaves the slots past its span alone. +#[test] +fn an_argument_array_covers_its_own_span_alone() { + let slots = [SlotWrite { + name: "images".to_owned(), + parameter: 0, + binding_type: Some(BindingType::Texture), + index: Some(2), + count: Some(3), + used: true, + access: Some(BindingAccess::ReadWrite), + writes: SlotWritability::Maybe, + }]; + let at = |index| SlotWrite::may_write(&slots, BindingType::Texture, index); + assert_eq!(at(1), SlotWritability::Never); + for index in 2..5 { + assert_eq!(at(index), SlotWritability::Maybe, "texture {index}"); + } + assert_eq!(at(5), SlotWritability::Never); +} + +/// Over every kernel of the public reflection fixtures: the answer is never refused, and wherever +/// the pipeline's reflection is not refused the two agree, slot for slot, on what may be stored +/// through it. The reflection derives a type description and this does not, so the fixtures whose +/// argument shapes refuse a reflection are the point: they still answer here. +/// +/// It is the broad form of the claim the whole module exists for -- a state that compiles answers +/// -- and the cross-check that the two derivations cannot drift apart, since `Binding::access` is +/// held to Metal's recorded answers by `library_reflection_matches_metal` and the pipeline cases. +#[test] +fn every_fixture_kernel_answers_and_agrees_with_its_reflection() { + let stems = [ + "argument_buffers", + "buffers", + "encoder_arrays", + "encoder_reads", + "encoder_types", + "encoders", + "leftovers", + "specialized_reads", + "tables", + "tables_in_arguments", + "texture_accesses", + "textures", + "tile", + ]; + let mut answered = 0; + let mut compared = 0; + let mut refused_reflections = 0; + let mut unspecialized = 0; + // The recorded fixtures, then the synthetic kernel whose argument type refuses a reflection: + // the fixtures state the agreement over shapes Metal's answers are recorded for, and the + // synthetic one makes the refused leg run, since no recorded fixture kernel refuses. + for stem in stems.iter().copied().chain(["(synthetic)"]) { + let bitcode = if stem == "(synthetic)" { + match metal2vulkan_devtools::llvm_assemble_text(&module()) { + Ok(b) => b, + Err(metal2vulkan_devtools::AssembleError::Missing(why)) => { + eprintln!("SKIPPED: {why}"); + return; + } + Err(metal2vulkan_devtools::AssembleError::Rejected(why)) => { + panic!("llvm-as rejected the synthetic module: {why}") + } + } + } else { + let path = + crate::pipeline::testing::fixtures_dir().join(format!("reflection/{stem}.ll")); + match crate::pipeline::testing::llvm_assemble(&path) { + Ok(b) => b, + Err(crate::pipeline::testing::AssembleError::Missing(why)) => { + eprintln!("SKIPPED: {why}"); + return; + } + Err(crate::pipeline::testing::AssembleError::Rejected(why)) => { + panic!("llvm-as rejected {stem}.ll: {why}") + } + } + }; + let library = Library::from_air(&bitcode).unwrap_or_else(|e| panic!("{stem}: {e:?}")); + let names: Vec = library + .functions() + .filter(|info| info.stage == crate::library::FunctionStage::Kernel) + .map(|info| info.name.to_owned()) + .collect(); + for name in names { + let f = library + .function(&name) + .unwrap_or_else(|e| panic!("{stem} {name}: {e:?}")); + let at = format!("{stem} {name}"); + let kernel = + ComputePipelineDescriptor::new(StageSource::Function(FunctionDescriptor::new(f))); + let writes = match kernel.slot_writes(&Budget::standard()) { + Ok(writes) => writes, + // A function whose constants no caller gave a required value for: no pipeline of + // it compiles, and the reflection refuses it too. What must never happen is a + // refusal over a reflection gap, which is what this asserts. + Err(error) => { + assert!( + !matches!(&error, Error::Unsupported(u) if u.feature == Feature::Reflection), + "{at}: refused as a reflection gap: {error:?}" + ); + assert!( + kernel.reflection(&Budget::standard()).is_err(), + "{at}: refused where the reflection answers: {error:?}" + ); + unspecialized += 1; + continue; + } + }; + answered += 1; + let slots = writes.kernel_slots(); + assert!( + slots.iter().all(|s| s.writes.gap().is_none()), + "{at}: an undetermined slot among {slots:?}" + ); + let reflection = match kernel.reflection(&Budget::standard()) { + Ok(r) => r, + Err(Error::Unsupported(u)) if u.feature == Feature::Reflection => { + refused_reflections += 1; + continue; + } + Err(e) => panic!("{at}: {e:?}"), + }; + // A kernel without a stage input descriptor reflects its own arguments alone, so the + // two lists line up one for one. + let bindings = reflection.bindings(); + assert_eq!(bindings.len(), slots.len(), "{at}"); + for (b, s) in bindings.iter().zip(slots) { + assert_eq!( + ( + b.name(), + Some(b.binding_type()), + Some(b.index()), + b.is_used() + ), + (s.name.as_str(), s.binding_type, s.index, s.used), + "{at}: the two answers name different bindings" + ); + // The declared access is the same value, not merely a compatible verdict. + assert_eq!( + s.access, + Some(b.access()), + "{at}: {} disagrees with its reflection's access", + b.name() + ); + let by_access = match b.access() { + BindingAccess::ReadOnly => SlotWritability::Never, + BindingAccess::WriteOnly | BindingAccess::ReadWrite => SlotWritability::Maybe, + }; + assert_eq!( + s.writes, + by_access, + "{at}: {} reads a verdict its access does not give", + b.name() + ); + compared += 1; + } + } + } + assert!(answered >= 20, "{answered} kernels answered"); + assert!( + unspecialized > 0, + "no kernel needed a constant value, so the leg that proves such a refusal is not a \ + reflection gap never ran" + ); + assert!(compared >= 40, "{compared} bindings compared"); + assert!( + refused_reflections > 0, + "no subject's reflection was refused, so this proves nothing about the gap it covers: \ + the sweep needs a kernel whose argument shapes Metal's answer is unmeasured for" + ); +} diff --git a/crates/metal2vulkan/tests/api_surface.rs b/crates/metal2vulkan/tests/api_surface.rs index 7702880db..6b9fa3473 100644 --- a/crates/metal2vulkan/tests/api_surface.rs +++ b/crates/metal2vulkan/tests/api_surface.rs @@ -306,6 +306,10 @@ surface! { struct ObjectPayloadBinding N; struct PointerType N; struct RenderPipelineReflection N; + struct SlotWrite N; + enum SlotWriteGap N; + enum SlotWritability N; + struct SlotWrites N; struct StructMember N; struct StructType N; struct TextureBinding N; diff --git a/docs/API.md b/docs/API.md index 02fc2c3a2..9885da75c 100644 --- a/docs/API.md +++ b/docs/API.md @@ -269,6 +269,21 @@ for info in sampling.functions() { `Unsupported(Feature::Reflection)`. - A pipeline descriptor's `reflection(&budget)` answers what the `reflection:` out-parameter of Metal's creation call does. +- A pipeline descriptor's `slot_writes(&budget)` answers, per stage, what the function may store + through the object bound at each slot its arguments bind (`SlotWrites`, one `SlotWrite` per + binding). `SlotWrite::may_write(slots, binding_type, index)` answers for one slot: + `SlotWritability::Never` where the declaration is read-only (a `constant` or `const device` + buffer, a texture declared `access::read` or `access::sample`, a sampler, a function table, an + acceleration structure, an imageblock, a mesh function's payload) and for a slot no argument + binds, `Maybe` where it is write-only or read-write, and `Unknown(SlotWriteGap)` for a slot that + one argument alone leaves undetermined. + + The values are the ones `reflection` gives as `Binding::access`, worked out without the type + description a reflection must also give. That is why a state that compiles always answers here, + while its `reflection` is refused where Metal's answer for one argument's *type* was not + measured, and why uncertainty stays on the slot it belongs to instead of refusing the state: + a caller asking whether a read-only buffer may sit at a slot gets an answer per slot, and an + undetermined slot reads as neither writable nor read-only. - `function.argument_buffer_layout(index, &constants, &budget)` gives the layout of the argument buffer the function takes at a buffer index, as `newArgumentEncoderWithBufferIndex:` encodes it: its length, alignment, and each argument's offset and type by `[[id(n)]]`. diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index ba8d35fe8..e5d2bc447 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -14,7 +14,7 @@ Columns: - `none`: no public API path: malformed or non-Metal input, Apple-private calls, or a cap no valid program of ordinary size meets; - `?`: not assessed yet. -Generated at `29dfe07db`. +Generated at `12fdf57fa`. ## Totals @@ -145,7 +145,7 @@ Generated at `29dfe07db`. | `PrivateMemory` | A stage whose private memory (its `thread` variables and arrays, and the constants it holds per thread) takes more Function storage a thread than... | - | via a helper: 1: `crates/metal2vulkan/src/lower/select.rs:1171` | `rare`: very large per-thread arrays | | `SparseTextures` | A sparse heap (`MTLHeapTypeSparse`), or a texture made from one, on a device without what a sparse resident image of it needs, which `missing` names | devices without the capability the site names; every device (not implemented) | 2: `crates/metal2vulkan-runtime/src/sparse/texture.rs:60`, `crates/metal2vulkan-runtime/src/sparse/texture.rs:65` | `rare`: sparse heaps on a device without sparse images | | `TimelineSemaphores` | Command buffers and events, which the runtime completes and signals through timeline semaphores (core in Vulkan 1.2), on a device whose... | every device (no Vulkan mechanism) | 1: `crates/metal2vulkan-runtime/src/device/create.rs:1115` | `none`: a device below the runtime's floor | -| `Reflection` | Reflection of an argument whose answer Metal's has not been measured for (`reflection`) | every device (not implemented) | 9: `crates/metal2vulkan/src/bind/argument_buffer.rs:626`, `crates/metal2vulkan/src/reflection/derive.rs:178` (+7) | `rare`: reflection of argument kinds Metal's answer is unmeasured for | +| `Reflection` | Reflection of an argument whose answer Metal's has not been measured for (`reflection`) | every device (not implemented) | 10: `crates/metal2vulkan-runtime/src/pipeline/texture_access.rs:131`, `crates/metal2vulkan/src/bind/argument_buffer.rs:626` (+8) | `rare`: reflection of argument kinds Metal's answer is unmeasured for | | `HeapTextureTiling` | A texture of a heap whose memory the device's optimal images do not take (a `Shared` heap on a device whose optimal images take no host-visible... | every device (no Vulkan mechanism) | 1: `crates/metal2vulkan-runtime/src/texture/heap.rs:632` | `app`: textures in Shared heaps on a device whose optimal images take no host memory | | `ViewportDepthRange` | A viewport depth range past `[0, 1]` (`setViewport:`), which Metal takes and the runtime draws natively (`VK_EXT_depth_range_unrestricted`) or... | drivers with a defect | 1: `crates/metal2vulkan-runtime/src/render_state.rs:1230` | `rare`: viewport depth outside [0, 1] | | `UndeclaredTextureUsage` | A shader write to a texture made without `ShaderWrite` (or `ShaderAtomic`), or a read of one made without `ShaderRead`, which plain Metal runs,... | every device (not implemented) | 2: `crates/metal2vulkan-runtime/src/binding_view.rs:141`, `crates/metal2vulkan-runtime/src/texture/usage_shadow.rs:72` | `app`: a shader write to a texture made without ShaderWrite, which plain Metal runs | @@ -366,7 +366,7 @@ Each refusal's sites, with the function that builds it. - `feature::RayTracing`: `crates/metal2vulkan/src/bind/acceleration.rs:202 (instance_record)`; `crates/metal2vulkan/src/bind/acceleration.rs:216 (instance_record)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs:1087 (primitive_data_read)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs:1202 (instance_count)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs:1245 (intersect)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs:1257 (intersect)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs:1282 (intersect)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs:1297 (intersect)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs:1312 (intersect)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs:344 (slot_of)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs:385 (select_param)`; `crates/metal2vulkan/src/lower/select.rs:899 (route_air)` - `feature::Tensors`: `crates/metal2vulkan-air/src/canon/matmul2d/synth.rs:32 (refuse)`; `crates/metal2vulkan/src/lower/select.rs:903 (route_air)` - `feature::RasterizationRateMap`: `crates/metal2vulkan/src/lower/fragment/mod.rs:952 (select)` -- `feature::GpuEncodedIndirectCommands`: `crates/metal2vulkan/src/bind/replay.rs:556 (preprocess)`; `crates/metal2vulkan/src/bind/replay.rs:796 (replay_preprocess_module)`; `crates/metal2vulkan/src/bind/replay/draws.rs:280 (draw_replay_preprocess)`; `crates/metal2vulkan/src/bind/replay/draws.rs:482 (draw_replay_module)`; `crates/metal2vulkan/src/bind/replay/flat.rs:247 (flat_dispatch_module)`; `crates/metal2vulkan/src/bind/replay/merged.rs:242 (draw_merge_module)`; `crates/metal2vulkan/src/lower/access/encode.rs:394 (needs)`; `crates/metal2vulkan/src/lower/access/encode.rs:410 (needs)`; `crates/metal2vulkan/src/lower/access/encode.rs:527 (select_command)`; `crates/metal2vulkan/src/lower/access/mod.rs:1540 (plan_replay)`; `crates/metal2vulkan/src/lower/access/mod.rs:1566 (plan_replay)`; `crates/metal2vulkan/src/lower/access/mod.rs:1569 (plan_replay)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:2707 (merged)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:2763 (finish_merged)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:458 (param)`; `crates/metal2vulkan/src/pipeline/compile.rs:2126 (plan_one)`; `crates/metal2vulkan/src/pipeline/compile.rs:2131 (plan_one)` +- `feature::GpuEncodedIndirectCommands`: `crates/metal2vulkan/src/bind/replay.rs:556 (preprocess)`; `crates/metal2vulkan/src/bind/replay.rs:796 (replay_preprocess_module)`; `crates/metal2vulkan/src/bind/replay/draws.rs:280 (draw_replay_preprocess)`; `crates/metal2vulkan/src/bind/replay/draws.rs:482 (draw_replay_module)`; `crates/metal2vulkan/src/bind/replay/flat.rs:247 (flat_dispatch_module)`; `crates/metal2vulkan/src/bind/replay/merged.rs:242 (draw_merge_module)`; `crates/metal2vulkan/src/lower/access/encode.rs:394 (needs)`; `crates/metal2vulkan/src/lower/access/encode.rs:410 (needs)`; `crates/metal2vulkan/src/lower/access/encode.rs:527 (select_command)`; `crates/metal2vulkan/src/lower/access/mod.rs:1540 (plan_replay)`; `crates/metal2vulkan/src/lower/access/mod.rs:1566 (plan_replay)`; `crates/metal2vulkan/src/lower/access/mod.rs:1569 (plan_replay)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:2707 (merged)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:2763 (finish_merged)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:458 (param)`; `crates/metal2vulkan/src/pipeline/compile.rs:2173 (plan_one)`; `crates/metal2vulkan/src/pipeline/compile.rs:2178 (plan_one)` - `feature::VulkanVersion`: `crates/metal2vulkan/src/ash_interop/query.rs:927 (query)`; `crates/metal2vulkan/src/device/derive.rs:105 (with_deviations)` - `feature::Constant`: `crates/metal2vulkan-air/src/bitcode/constants.rs:210 (record)`; `crates/metal2vulkan-air/src/bitcode/constants.rs:268 (record)`; `crates/metal2vulkan/src/error/mod.rs:256 (from)` - `feature::Attribute`: `crates/metal2vulkan-air/src/bitcode/attrs.rs:493 (known)`; `crates/metal2vulkan/src/error/mod.rs:257 (from)` @@ -405,7 +405,7 @@ Each refusal's sites, with the function that builds it. - `feature::PrivateMemory`: `crates/metal2vulkan/src/lower/select.rs:1171 (function_storage)` - `feature::SparseTextures`: `crates/metal2vulkan-runtime/src/sparse/texture.rs:60 (sparse_refusal)`; `crates/metal2vulkan-runtime/src/sparse/texture.rs:65 (sparse_refusal)` - `feature::TimelineSemaphores`: `crates/metal2vulkan-runtime/src/device/create.rs:1115 (timeline_difference)` -- `feature::Reflection`: `crates/metal2vulkan/src/bind/argument_buffer.rs:626 (unmeasured)`; `crates/metal2vulkan/src/reflection/derive.rs:178 (specialized_reads)`; `crates/metal2vulkan/src/reflection/derive.rs:212 (read_attributes)`; `crates/metal2vulkan/src/reflection/derive.rs:239 (gap_at)`; `crates/metal2vulkan/src/reflection/function.rs:172 (unmeasured)`; `crates/metal2vulkan/src/reflection/function.rs:366 (attribute)`; `crates/metal2vulkan/src/reflection/function.rs:437 (module_constants)`; `crates/metal2vulkan/src/reflection/linked.rs:125 (function)`; `crates/metal2vulkan/src/reflection/mod.rs:249 (stage)` +- `feature::Reflection`: `crates/metal2vulkan-runtime/src/pipeline/texture_access.rs:131 (at)`; `crates/metal2vulkan/src/bind/argument_buffer.rs:626 (unmeasured)`; `crates/metal2vulkan/src/reflection/derive.rs:178 (specialized_reads)`; `crates/metal2vulkan/src/reflection/derive.rs:212 (read_attributes)`; `crates/metal2vulkan/src/reflection/derive.rs:239 (gap_at)`; `crates/metal2vulkan/src/reflection/function.rs:172 (unmeasured)`; `crates/metal2vulkan/src/reflection/function.rs:366 (attribute)`; `crates/metal2vulkan/src/reflection/function.rs:437 (module_constants)`; `crates/metal2vulkan/src/reflection/linked.rs:125 (function)`; `crates/metal2vulkan/src/reflection/mod.rs:254 (stage)` - `feature::HeapTextureTiling`: `crates/metal2vulkan-runtime/src/texture/heap.rs:632 (tiling_refusal)` - `feature::ViewportDepthRange`: `crates/metal2vulkan-runtime/src/render_state.rs:1230 (depth_ranges_refused)` - `feature::UndeclaredTextureUsage`: `crates/metal2vulkan-runtime/src/binding_view.rs:141 (binding_view)`; `crates/metal2vulkan-runtime/src/texture/usage_shadow.rs:72 (refused)` @@ -434,7 +434,7 @@ Each refusal's sites, with the function that builds it. - `gap::AccelerationStructures`: `crates/metal2vulkan-runtime/src/binding.rs:1797 (unexpected)` - `gap::FeatureEnable`: `crates/metal2vulkan-runtime/src/enables.rs:1166 (of)` - `gap::ExtensionEnable`: `crates/metal2vulkan-runtime/src/enables.rs:1157 (of)` -- `gap::Render`: `crates/metal2vulkan-runtime/src/attachment_stand_in.rs:404 (stand_in_as)`; `crates/metal2vulkan-runtime/src/attachment_stand_in.rs:461 (stand_in_as)`; `crates/metal2vulkan-runtime/src/attachment_stand_in.rs:685 (check_copies)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:840 (attachment_twin)`; `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:283 (check_sizes)`; `crates/metal2vulkan-runtime/src/kept_bytes.rs:138 (settle)`; `crates/metal2vulkan-runtime/src/linear_attachment.rs:293 (settle)`; `crates/metal2vulkan-runtime/src/nan_clear.rs:204 (plan)`; `crates/metal2vulkan-runtime/src/pipeline/render.rs:1169 (imageblock_sample_length)`; `crates/metal2vulkan-runtime/src/render.rs:2251 (check_pipeline)`; `crates/metal2vulkan-runtime/src/render.rs:6001 (next_instance)`; `crates/metal2vulkan-runtime/src/render.rs:7973 (draw_resident)`; `crates/metal2vulkan-runtime/src/render/tile_dispatch.rs:516 (scratch)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1317 (layout)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1679 (target)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1733 (target)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1794 (attachment_format)`; `crates/metal2vulkan-runtime/src/render_pass.rs:2027 (depth_stencil)`; `crates/metal2vulkan-runtime/src/resolve.rs:1039 (attach)`; `crates/metal2vulkan-runtime/src/resolve.rs:1107 (color_copy)`; `crates/metal2vulkan-runtime/src/resolve.rs:1154 (destination)`; `crates/metal2vulkan-runtime/src/resolve.rs:1171 (destination)`; `crates/metal2vulkan-runtime/src/resolve.rs:1236 (destination)` +- `gap::Render`: `crates/metal2vulkan-runtime/src/attachment_stand_in.rs:404 (stand_in_as)`; `crates/metal2vulkan-runtime/src/attachment_stand_in.rs:461 (stand_in_as)`; `crates/metal2vulkan-runtime/src/attachment_stand_in.rs:685 (check_copies)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:840 (attachment_twin)`; `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:283 (check_sizes)`; `crates/metal2vulkan-runtime/src/kept_bytes.rs:138 (settle)`; `crates/metal2vulkan-runtime/src/linear_attachment.rs:293 (settle)`; `crates/metal2vulkan-runtime/src/nan_clear.rs:204 (plan)`; `crates/metal2vulkan-runtime/src/pipeline/render.rs:1181 (imageblock_sample_length)`; `crates/metal2vulkan-runtime/src/render.rs:2251 (check_pipeline)`; `crates/metal2vulkan-runtime/src/render.rs:6001 (next_instance)`; `crates/metal2vulkan-runtime/src/render.rs:7973 (draw_resident)`; `crates/metal2vulkan-runtime/src/render/tile_dispatch.rs:516 (scratch)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1317 (layout)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1679 (target)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1733 (target)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1794 (attachment_format)`; `crates/metal2vulkan-runtime/src/render_pass.rs:2027 (depth_stencil)`; `crates/metal2vulkan-runtime/src/resolve.rs:1039 (attach)`; `crates/metal2vulkan-runtime/src/resolve.rs:1107 (color_copy)`; `crates/metal2vulkan-runtime/src/resolve.rs:1154 (destination)`; `crates/metal2vulkan-runtime/src/resolve.rs:1171 (destination)`; `crates/metal2vulkan-runtime/src/resolve.rs:1236 (destination)` - `gap::TexelsPastBufferLength`: `crates/metal2vulkan-runtime/src/buffer_texture.rs:260 (refusal_error)`; `crates/metal2vulkan-runtime/src/texture/surface_depth.rs:105 (surface_depth_twin)` - `gap::OverlappingSurfaceRows`: `crates/metal2vulkan-runtime/src/buffer_texture.rs:262 (refusal_error)` - `gap::SamplePositionsAtBegin`: `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:145 (stencil_scratch)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1864 (positioned_stand_in)`; `crates/metal2vulkan-runtime/src/sample_positions.rs:196 (refusal_error)`