diff --git a/crates/metal2vulkan/src/error/mod.rs b/crates/metal2vulkan/src/error/mod.rs index 31f7ad757..df577b150 100644 --- a/crates/metal2vulkan/src/error/mod.rs +++ b/crates/metal2vulkan/src/error/mod.rs @@ -751,7 +751,9 @@ pub enum Feature { /// vertex or mesh function whose module states `agx.allow_mismatched_component_counts` as 1 /// (`StageIo::mismatched_component_counts`), Metal links (measured for a vertex function). /// Link places a narrower one behind a vertex function at its output, where the description - /// states `maintenance4`; a wider one, one behind a mesh function, and a narrower one on a + /// states `maintenance4`, and a render pipeline's compile declares a vertex output a wider + /// one reads at its count (`LoweringInputs::widened_varyings`); a wider one behind a vertex + /// function compiled without that, one behind a mesh function, and a narrower one on a /// description without `maintenance4` are not implemented (`NotImplemented`). UnmatchedVarying, /// A vertex buffer layout stepped per instance at a rate above 1, on a profile that fetches diff --git a/crates/metal2vulkan/src/lower/stage_io/mod.rs b/crates/metal2vulkan/src/lower/stage_io/mod.rs index 7df6428c8..15d364224 100644 --- a/crates/metal2vulkan/src/lower/stage_io/mod.rs +++ b/crates/metal2vulkan/src/lower/stage_io/mod.rs @@ -397,6 +397,10 @@ pub struct StageIoPlan { /// The color outputs a fragment function compiled under `LoweringInputs::zeroed_colors` /// stores zero to at every return, one per such color. pub zeroed: Vec, + /// The varying objects a vertex function compiled under `LoweringInputs::widened_varyings` + /// declares wider than it writes them: [`store`] writes the value's lanes and 0 in every lane + /// past them. + pub widened: BTreeSet, /// The shape of the returned value. pub returned: Returned, /// The `PointSize` object a vertex function without a point-size output writes 1.0 to. @@ -2641,6 +2645,36 @@ fn store(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, link: &Link, x: SVal } else { x }; + // A varying declared wider than the value (`LoweringInputs::widened_varyings`): its lanes + // first, 0 in every lane past them. + let sp = &cx.plan.families.stage_io; + let widened = match sp.objects.get(link.object) { + Some(&IoObject::User { + numeric, + components, + .. + }) if sp.widened.contains(&link.object) => Some((numeric, components)), + _ => None, + }; + let x = match widened { + Some((numeric, components)) if components > link.form.lanes => { + let elem = io_elem(fb.module(), numeric)?; + let zero = fb.module().constant(Constant::Scalar { + ty: elem, + bits: ConstBits(0), + })?; + let zero = fb.module().const_value(zero)?; + let ty = fb.module().ty(SType::Vector { + elem, + len: components, + })?; + let mut parts = vec![x]; + parts.resize(usize::from(components - link.form.lanes) + 1, zero); + fb.composite_construct(ty, &parts)? + } + Some(_) => return Err(cx.fail("a varying widened to no more lanes than it holds")), + None => x, + }; match link.place { Place::Weights { .. } => Err(cx.fail("an output stored through the barycentric weights")), Place::Whole | Place::Element0 => { diff --git a/crates/metal2vulkan/src/lower/stage_io/plan.rs b/crates/metal2vulkan/src/lower/stage_io/plan.rs index 847309706..8547c208e 100644 --- a/crates/metal2vulkan/src/lower/stage_io/plan.rs +++ b/crates/metal2vulkan/src/lower/stage_io/plan.rs @@ -2708,12 +2708,25 @@ fn output(cx: &mut SelectCx<'_>, o: &OutputBinding, ty: AirTypeId) -> Result { let f = varying_form(cx, ty)?; let key = VaryingKey::user(&k.0); + // Widened to the count the pipeline's fragment function reads + // (`LoweringInputs::widened_varyings`): `store` writes 0 past the value's lanes. + let declared = match cx.inputs.widened_varyings.get(&key) { + Some(&n) if n > f.lanes && n <= 4 => IoType { + components: n, + ..io_type(f) + }, + Some(_) => return Err(cx.invariant("a varying widened to no more lanes")), + None => io_type(f), + }; let sp = &mut cx.families.stage_io; let deco = IoDecor { packed: true, ..IoDecor::default() }; - let object = user(sp, key.clone(), IoDir::Output, io_type(f), deco)?; + let object = user(sp, key.clone(), IoDir::Output, declared, deco)?; + if declared.components > f.lanes { + sp.widened.insert(object); + } push_var( &mut sp.interface.outputs, IoVariable { @@ -2722,7 +2735,7 @@ fn output(cx: &mut SelectCx<'_>, o: &OutputBinding, ty: AirTypeId) -> Result { /// and whether the pipeline state is made for indirect command buffers /// (`supportIndirectCommandBuffers`): a vertex function then pulls every attribute it reads /// and tests its command against the execution range (`LoweringInputs::indirect_range`). + /// Last, the varyings the pipeline's fragment function reads wider than the entry writes them + /// ([`widened_varyings`], `LoweringInputs::widened_varyings`); [`NO_WIDENED_VARYINGS`] for + /// none. Vertex( Option<&'a VertexDescriptor>, &'a VariantKey, u32, bool, bool, + &'a BTreeMap, ), /// The fragment stage of this render pipeline under a variant key: the key's fragment-stage /// inputs, the attachments among the pipeline's color attachments that the specialized entry @@ -133,6 +137,10 @@ pub enum InputsFrom<'a> { /// a mesh render pipeline's. pub(crate) static NO_PRIMITIVE_VARYINGS: BTreeSet = BTreeSet::new(); +/// No varying widened: a vertex stage's whose fragment function reads none wider +/// ([`InputsFrom::Vertex`]). +pub(crate) static NO_WIDENED_VARYINGS: BTreeMap = BTreeMap::new(); + /// The pipeline state a fragment stage compiles under ([`InputsFrom::Fragment`]): its render /// pipeline's, or its mesh render pipeline's, which has no call stack depth of its own (Metal's /// default, 1). @@ -1643,6 +1651,90 @@ pub(crate) fn reads_primitive_id_varying( }) } +/// A user varying's AIR scalar type and lane count: a scalar's own, or a vector's element and +/// length. +type VaryingShape = (air::ir::Type, u32); + +/// The shape of type `ty` of `spec`'s module ([`VaryingShape`]); `None` for a type that is no +/// scalar or vector. +fn varying_shape(spec: &air::Entry, ty: air::ir::TypeId) -> Option { + let types = spec.module.types(); + match types.get(ty)? { + air::ir::Type::Vector { elem, len } => Some((types.get(*elem)?.clone(), *len)), + t @ (air::ir::Type::Int(_) + | air::ir::Type::Half + | air::ir::Type::BFloat + | air::ir::Type::Float + | air::ir::Type::Double) => Some((t.clone(), 1)), + _ => None, + } +} + +/// The user varyings vertex function `spec` writes, by key, with their shapes. +fn written_shapes(spec: &air::Entry) -> BTreeMap { + let types = spec.module.types(); + let ret = match spec.module.func(spec.func).and_then(|f| types.get(f.ty)) { + Some(air::ir::Type::Function { ret, .. }) => *ret, + _ => return BTreeMap::new(), + }; + let fields: &[air::ir::TypeId] = match types.get(ret) { + Some(air::ir::Type::Struct { fields, .. }) => fields, + _ => std::slice::from_ref(&ret), + }; + (spec.ep.outputs.iter()) + .filter_map(|o| match &o.role { + OutputRole::VertexOutput(k) => { + let ty = *fields.get(o.field as usize)?; + Some((VaryingKey::user(&k.0), varying_shape(spec, ty)?)) + } + _ => None, + }) + .collect() +} + +/// The user varyings fragment function `spec` reads, by key, with their shapes. +fn read_shapes(spec: &air::Entry) -> BTreeMap { + let types = spec.module.types(); + let params: &[air::ir::TypeId] = match spec.module.func(spec.func).and_then(|f| types.get(f.ty)) + { + Some(air::ir::Type::Function { params, .. }) => params, + _ => &[], + }; + (spec.ep.params.iter()) + .filter_map(|p| match &p.role { + ParamRole::FragmentInput(v) => { + let ty = *params.get(p.param as usize)?; + Some((VaryingKey::user(&v.key.0), varying_shape(spec, ty)?)) + } + _ => None, + }) + .collect() +} + +/// The varyings vertex function `vertex` writes at fewer lanes than fragment function `fragment` +/// reads them, of the same scalar type, each with the lanes `fragment` reads +/// (`LoweringInputs::widened_varyings`): decided from the two entries' types alone, and only +/// where `vertex`'s module states `agx.allow_mismatched_component_counts` as 1, under which Metal +/// makes that pipeline (measured). Empty for any other pair. +pub(crate) fn widened_varyings( + vertex: &air::Entry, + fragment: &air::Entry, +) -> BTreeMap { + if !vertex.ep.mismatched_component_counts { + return BTreeMap::new(); + } + let reads = read_shapes(fragment); + written_shapes(vertex) + .into_iter() + .filter_map(|(key, (elem, lanes))| match reads.get(&key) { + Some((read, n)) if *read == elem && *n > lanes => { + Some((key, u8::try_from(*n).ok().filter(|&n| n <= 4)?)) + } + _ => None, + }) + .collect() +} + /// Run `g` on the compile request of function `f`. A visible function is not a stage: it is /// `EntryNotFound`, as for a module that does not declare the entry. fn with_request( @@ -2507,7 +2599,7 @@ fn lower_inputs( match inputs { InputsFrom::Given(i) => Ok(given_inputs(spec, i)), // A post-tessellation vertex function pulls every attribute it reads. - InputsFrom::Vertex(desc, variant, depth, primitive_id, indirect) + InputsFrom::Vertex(desc, variant, depth, primitive_id, indirect, widened) if matches!(spec.ep.stage, AbiStage::Vertex { patch: Some(_) }) => { let attributes = crate::lower::tessellation::attributes_read(spec); @@ -2521,9 +2613,10 @@ fn lower_inputs( // A state made for indirect command buffers tests each evaluation's command against // the execution range, as a plain vertex function tests its vertex's. out.indirect_range = indirect; + out.widened_varyings = widened.clone(); Ok(key::canonical_inputs(&out)) } - InputsFrom::Vertex(desc, variant, depth, primitive_id, indirect) => { + InputsFrom::Vertex(desc, variant, depth, primitive_id, indirect, widened) => { let attributes = declared_attributes(spec); // The primitive ID's de-indexed form, the private list form and a state made for // indirect command buffers pull every attribute, whatever the caller's projection @@ -2544,6 +2637,7 @@ fn lower_inputs( out.primitive_id_varying = primitive_id && primitive_id_varying_on(p); out.indirect_range = indirect; out.instanced_attributes = instanced_attributes(spec, &out, desc, m)?; + out.widened_varyings = widened.clone(); Ok(key::canonical_inputs(&out)) } InputsFrom::Fragment(d, variant, written, primitive, varyings, uniform) => { diff --git a/crates/metal2vulkan/src/pipeline/compile/api.rs b/crates/metal2vulkan/src/pipeline/compile/api.rs index 3f557a516..5ebe21266 100644 --- a/crates/metal2vulkan/src/pipeline/compile/api.rs +++ b/crates/metal2vulkan/src/pipeline/compile/api.rs @@ -41,7 +41,8 @@ use crate::pipeline::compile::key::{function_key, pipeline_key, queried_render_d use crate::pipeline::compile::{ compile_stage, compile_stage_from, dynamic_order, guarded, kernel_observes_partition, linked_keys, primitive_id_varying_on, reads_primitive_id_varying, stage_inputs, - vertex_push_end, FragmentPass, InputsFrom, RawIndices, StageEntries, NO_PRIMITIVE_VARYINGS, + vertex_push_end, widened_varyings, FragmentPass, InputsFrom, RawIndices, StageEntries, + NO_PRIMITIVE_VARYINGS, NO_WIDENED_VARYINGS, }; use crate::pipeline::descriptor::{ ComputePipelineDescriptor, FunctionDescriptor, MeshPipelineDescriptor, @@ -360,6 +361,9 @@ impl Device { )?, false => false, }; + // The varyings the vertex function writes narrower than the fragment function reads + // them, which it declares wider (`render_pipeline`). + let widened = widened_for(d, entries, &mut Meter::new(b))?; let from = || { InputsFrom::Vertex( d.vertex_descriptor.as_ref(), @@ -367,6 +371,7 @@ impl Device { d.max_vertex_call_stack_depth, primitive_id, d.support_indirect_command_buffers, + &widened, ) }; let (vertex, vertex_inputs, written, varyings, uniform, push_end) = match &d.vertex { @@ -805,7 +810,7 @@ impl Device { )?, None => false, }; - let vertex = self.stage( + let mut vertex = self.stage( &d.vertex, InputsFrom::Vertex( d.vertex_descriptor.as_ref(), @@ -813,9 +818,36 @@ impl Device { d.max_vertex_call_stack_depth, primitive_id, d.support_indirect_command_buffers, + &NO_WIDENED_VARYINGS, ), m, )?; + // Behind a vertex function whose module states `agx.allow_mismatched_component_counts` + // as 1, the varyings it writes narrower than the fragment function reads them, which it + // compiles again declaring wider (`LoweringInputs::widened_varyings`), decided from the + // two entries alone. + if vertex.artifact().interface.io.mismatched_component_counts { + let own; + let e = match &entries { + Some(e) => e, + None => { + own = StageEntries::new(); + &own + } + }; + let widened = widened_for(d, e, m)?; + if !widened.is_empty() { + let inputs = InputsFrom::Vertex( + d.vertex_descriptor.as_ref(), + v, + d.max_vertex_call_stack_depth, + primitive_id, + d.support_indirect_command_buffers, + &widened, + ); + vertex = self.stage(&d.vertex, inputs, m)?; + } + } check_call_stack(vertex.artifact(), d.max_vertex_call_stack_depth)?; // On the floor the fragment function's push fields follow the vertex function's. let base = vertex.fragment_push_base(); @@ -1616,6 +1648,28 @@ fn stage_module(c: &CompiledFunction, linked: &Linked, i: usize) -> Result Result, Error> { + let (StageSource::Function(vertex), Some(StageSource::Function(fragment))) = + (&d.vertex, &d.fragment) + else { + return Ok(std::collections::BTreeMap::new()); + }; + let vertex = entries.specialized(vertex, d.max_vertex_call_stack_depth, false, m)?; + if !vertex.spec.ep.mismatched_component_counts { + return Ok(std::collections::BTreeMap::new()); + } + let fragment = entries.specialized(fragment, d.max_fragment_call_stack_depth, false, m)?; + Ok(widened_varyings(&vertex.spec, &fragment.spec)) +} + /// The user varyings `a` writes when it is a vertex function, or a mesh function's per-vertex /// and per-primitive ones (`LoweringInputs::absent_varyings`). fn varyings_written(a: &FunctionArtifact) -> std::collections::BTreeSet { diff --git a/crates/metal2vulkan/src/pipeline/compile/entry.rs b/crates/metal2vulkan/src/pipeline/compile/entry.rs index 7e36a435d..23952f0ea 100644 --- a/crates/metal2vulkan/src/pipeline/compile/entry.rs +++ b/crates/metal2vulkan/src/pipeline/compile/entry.rs @@ -20,7 +20,7 @@ use crate::pipeline::artifact::StrategyUse; use crate::pipeline::compile::api::CompileReport; use crate::pipeline::compile::{ census, compile_one, guarded, lower_inputs, ordered_entry, plan_one, specialize_one, EntryRef, - InputsFrom, LinkedSource, Request, + InputsFrom, LinkedSource, Request, NO_WIDENED_VARYINGS, }; use crate::pipeline::descriptor::VertexDescriptor; use crate::pipeline::layout::PipelineLayout; @@ -158,7 +158,14 @@ impl DeviceProfile { let mut m = Meter::new(budget); let variant = VariantKey::new(); guarded(|| { - let r = d.request(InputsFrom::Vertex(vertex, &variant, 1, false, false)); + let r = d.request(InputsFrom::Vertex( + vertex, + &variant, + 1, + false, + false, + &NO_WIDENED_VARYINGS, + )); let spec = specialize_one(&r, &mut m)?.spec; lower_inputs(&spec, r.inputs, self, &mut m) }) diff --git a/crates/metal2vulkan/src/pipeline/compile/key.rs b/crates/metal2vulkan/src/pipeline/compile/key.rs index 863e1e455..a451b07fb 100644 --- a/crates/metal2vulkan/src/pipeline/compile/key.rs +++ b/crates/metal2vulkan/src/pipeline/compile/key.rs @@ -405,6 +405,12 @@ pub fn function_key( h.bytes(b"uniform-varyings") .bytes(format!("{:?}", inputs.uniform_varyings).as_bytes()); } + // Appended only when set, as `uniform_varyings` (an ordered map of byte keys to counts): a + // vertex function whose fragment function reads none of its varyings wider keeps its key. + if !inputs.widened_varyings.is_empty() { + h.bytes(b"widened-varyings") + .bytes(format!("{:?}", inputs.widened_varyings).as_bytes()); + } // Appended only when set, as `uniform_varyings` (an ordered set of attribute indices): a // vertex function no per-instance attribute makes write a varying alike keeps its key. if !inputs.instanced_attributes.is_empty() { diff --git a/crates/metal2vulkan/src/pipeline/compile/tests.rs b/crates/metal2vulkan/src/pipeline/compile/tests.rs index 360071c0d..5f85fa929 100644 --- a/crates/metal2vulkan/src/pipeline/compile/tests.rs +++ b/crates/metal2vulkan/src/pipeline/compile/tests.rs @@ -678,6 +678,7 @@ fn the_inputs_encoding_is_the_earlier_derived_debug() { .replace(", rotated_blends: {}", "") .replace(", texture_write_rounding: TowardZero", "") .replace(", uniform_varyings: {}", "") + .replace(", widened_varyings: {}", "") .replace(", instanced_attributes: {}", "") .replace(", object_payload: None", "") .replace(", tessellation: None", "") diff --git a/crates/metal2vulkan/src/pipeline/link/varyings.rs b/crates/metal2vulkan/src/pipeline/link/varyings.rs index 8948f49ef..fe608b395 100644 --- a/crates/metal2vulkan/src/pipeline/link/varyings.rs +++ b/crates/metal2vulkan/src/pipeline/link/varyings.rs @@ -13,8 +13,12 @@ //! components reads the output's first lanes, as Metal's does (measured), and takes the //! output's location and component: Vulkan matches it there under `maintenance4`, which the //! runtime's floor enables, and a description without it is this translator's gap -//! (`UnmatchedVarying`, `NotImplemented`). An input of more components, or any behind a mesh -//! function, is that gap too. Unmatched vertex outputs stay (legal in both APIs). A fragment function alone numbers its inputs densely in declaration order. +//! (`UnmatchedVarying`, `NotImplemented`). An input of more components never reaches link from +//! a render pipeline's compile, whose vertex function declares such an output at the input's +//! count, 0 in the lanes past its own (`LoweringInputs::widened_varyings`); behind a vertex +//! function compiled without that, and any behind a mesh function, it is that gap too. +//! Unmatched vertex outputs stay (legal in both APIs). A fragment function alone numbers its +//! inputs densely in declaration order. //! The raw viewport index (`IoRole::ViewportIndex`) is such a varying, of its own key, which the //! fragment stage reads flat: one more flat input component under the limits below. A fragment //! function reads it exactly when compiled for a vertex function that writes @@ -87,7 +91,7 @@ fn invariant(detail: &str) -> Error { /// The refusal of fragment input `input` of type `read` whose producer `producer` writes its key /// as `written` (`None`: not at all): Metal's link error, but for a type that differs in /// component count alone behind a producer of [`StageIo::mismatched_component_counts`], which -/// Metal links and this translator does not yet (see the module docs). +/// Metal links and this translator does not here (see the module docs). fn unmatched(producer: &StageIo, written: Option, read: IoType) -> Error { if written.is_some_and(|w| counts_alone(w, read)) && producer.mismatched_component_counts { Unsupported::not_implemented(Feature::UnmatchedVarying).into() diff --git a/crates/metal2vulkan/src/pipeline/lower_inputs.rs b/crates/metal2vulkan/src/pipeline/lower_inputs.rs index 7e9017f5f..324d00ba7 100644 --- a/crates/metal2vulkan/src/pipeline/lower_inputs.rs +++ b/crates/metal2vulkan/src/pipeline/lower_inputs.rs @@ -641,6 +641,21 @@ pub struct LoweringInputs { /// any other function. #[cfg_attr(feature = "serde", serde(default))] pub uniform_varyings: BTreeSet, + /// The user varyings a vertex function whose module states + /// `agx.allow_mismatched_component_counts` as 1 (`StageIo::mismatched_component_counts`) + /// writes at fewer components than its render pipeline's fragment function reads them, each + /// with the count the fragment function reads, of the same scalar type: the function declares + /// each such output at that count, its own lanes first and 0 in every lane past them, and + /// lists it so among its `StageIo::outputs`, so the two match. Metal makes that pipeline, and + /// its input reads values past the output's lanes that are no constant (measured on an Apple + /// M3 Max, job m3-max-87586): Metal defines none, so the 0 there emulates nothing + /// (docs/API.md, Accepted differences). `Device::compile_render_pipeline` and + /// `Device::render_variant_key` set it for a `Function` vertex stage behind a `Function` + /// fragment stage, from the two specialized entries' types; behind a vertex function compiled + /// without it, link answers such a pipeline `Unsupported{UnmatchedVarying, NotImplemented}`. + /// Empty for any other function. + #[cfg_attr(feature = "serde", serde(default))] + pub widened_varyings: BTreeMap, /// The attributes, by Metal attribute index, that the vertex function fetches in fixed /// function from layouts its vertex descriptor steps per instance, which every vertex of one /// instance (so of one primitive) reads alike; set only where one of them makes a varying the diff --git a/crates/metal2vulkan/src/pipeline/stage_io.rs b/crates/metal2vulkan/src/pipeline/stage_io.rs index 7d8ede57a..28bbc2979 100644 --- a/crates/metal2vulkan/src/pipeline/stage_io.rs +++ b/crates/metal2vulkan/src/pipeline/stage_io.rs @@ -347,10 +347,12 @@ pub struct StageIo { /// makes a render pipeline whose fragment function reads one of the function's user /// varyings at another component count than the function writes (measured for a vertex /// function). Behind a vertex function link places a narrower input at its output, which - /// Vulkan matches under `maintenance4` (`pipeline::link`'s varyings), and answers a wider one, - /// or either behind a mesh function, `Unsupported{UnmatchedVarying, NotImplemented}`; the same - /// mismatch behind a function without it is Metal's link error, `NotRepresentable`. False for - /// every other function. + /// Vulkan matches under `maintenance4` (`pipeline::link`'s varyings); a render pipeline's + /// compile declares the output a wider input reads at the input's count + /// (`LoweringInputs::widened_varyings`), and link answers a wider one behind a vertex + /// function compiled without that, or either behind a mesh function, + /// `Unsupported{UnmatchedVarying, NotImplemented}`; the same mismatch behind a function + /// without it is Metal's link error, `NotRepresentable`. False for every other function. #[cfg_attr(feature = "serde", serde(default))] pub mismatched_component_counts: bool, } diff --git a/crates/metal2vulkan/src/tests/engine_converter_module_flags.rs b/crates/metal2vulkan/src/tests/engine_converter_module_flags.rs index 224196d19..30b616ae0 100644 --- a/crates/metal2vulkan/src/tests/engine_converter_module_flags.rs +++ b/crates/metal2vulkan/src/tests/engine_converter_module_flags.rs @@ -221,9 +221,10 @@ fn location(a: &FunctionArtifact, words: &[u32], key: &VaryingKey) -> u32 { /// A vertex function whose module states the agx flag as 1 carries it to its stage interface /// (`StageIo::mismatched_component_counts`); one stating 0 or nothing, and a fragment function, /// do not. Without it, a fragment function reading the varying at another component count, wider -/// or narrower, is Metal's link error (`NotRepresentable`); behind it a wider one is this -/// translator's gap (`Unsupported{UnmatchedVarying, NotImplemented}`), whose lanes past the -/// output's Metal leaves undefined. At the same count it links, flag or not. +/// or narrower, is Metal's link error (`NotRepresentable`); behind it a wider one, linked from +/// stages compiled alone, is this translator's gap (`Unsupported{UnmatchedVarying, +/// NotImplemented}`): only a render pipeline's compile declares the output at the input's count. +/// At the same count it links, flag or not. #[test] fn the_agx_flag_reaches_link_and_a_wider_input_is_our_gap() { let p = profile("lavapipe").expect("profile"); diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 7ef90aee4..01f71d074 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -2623,6 +2623,7 @@ field metal2vulkan::pipeline::LoweringInputs.unattached_colors pub unattached_co field metal2vulkan::pipeline::LoweringInputs.uniform_varyings pub uniform_varyings: BTreeSet field metal2vulkan::pipeline::LoweringInputs.vertex_fetch pub vertex_fetch: Option field metal2vulkan::pipeline::LoweringInputs.viewport_index_varying pub viewport_index_varying: bool +field metal2vulkan::pipeline::LoweringInputs.widened_varyings pub widened_varyings: BTreeMap field metal2vulkan::pipeline::LoweringInputs.word_bound_buffers pub word_bound_buffers: BTreeSet field metal2vulkan::pipeline::LoweringInputs.word_colors pub word_colors: BTreeMap field metal2vulkan::pipeline::LoweringInputs.zeroed_colors pub zeroed_colors: BTreeMap diff --git a/docs/API.md b/docs/API.md index 29462130c..edfcfb8a2 100644 --- a/docs/API.md +++ b/docs/API.md @@ -2789,6 +2789,11 @@ named states the rule in full. 27.0.1) refuses it outside the private OpenGL mode with "depthAttachmentPixelFormat is not valid and shader writes to depth" (the probe `metal2vulkan-conformance/probes/opengl_mode.m`), a refusal no Metal document states (`MTLRenderPipeline.h`, `depthAttachmentPixelFormat`). +- **A fragment input wider than its vertex output reads 0 in the lanes past the output's**, behind + a vertex function whose module states `agx.allow_mismatched_component_counts` as 1 + (`LoweringInputs::widened_varyings`). Metal makes that pipeline and leaves those lanes + undefined: measured on an Apple M3 Max (macOS 27.0.1, job m3-max-87586), 150 such lanes read + 147 distinct values, none of them written by the function. **Resource IDs and identifiers** diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index 5bf1913ea..313643ea8 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -115,7 +115,7 @@ Columns: | `DivergentInterpolation` | Metal's pull-model interpolation at a sample or an offset (`interpolate_at_sample`, `interpolate_at_offset`) outside the fragment function's first... | every device (not implemented) | `ours` | 1: `crates/metal2vulkan/src/lower/stage_io/plan.rs (interpolant_reads)` | `rare`: an interpolant read at a sample or an offset in a branch, a loop or after a discard | | `PixelCoverageAtSampleRate` | The pixel's coverage (`[[sample_mask]]` read) in a fragment function that runs once per sample | every device (no Vulkan mechanism); every device (not implemented) | `ours` | 2: `crates/metal2vulkan/src/lower/simd/mod.rs (select_param)`, `crates/metal2vulkan/src/pipeline/link/graphics.rs (sample_invocations)` | `rare`: coverage read at sample rate | | `InterfaceComponents` | Too many interface components or locations | devices short of a device limit the site names; devices without VkLimit::MaxColorAttachments; devices without VkLimit::MaxVertexInputAttributes | `device` | 3: `crates/metal2vulkan/src/pipeline/link/graphics.rs (graphics_state)`, `crates/metal2vulkan/src/pipeline/link/varyings.rs (assign)` (+1) | `rare`: too many varyings or attachments for a device | -| `UnmatchedVarying` | A fragment input without a vertex or mesh output of its key and type | every device (no Vulkan mechanism); every device (not implemented) | `ours` | 3: `crates/metal2vulkan/src/pipeline/link/varyings.rs (unmatched, 2 sites)`, `crates/metal2vulkan/src/pipeline/link/varyings.rs (varyings)` | `rare`: a varying read at another component count than written, behind a vertex module stating agx.allow_mismatched_component_counts as 1 (seen in modules Apple's Metal shader converter wrote); otherwise a Metal link error | +| `UnmatchedVarying` | A fragment input without a vertex or mesh output of its key and type | every device (no Vulkan mechanism); every device (not implemented) | `ours` | 3: `crates/metal2vulkan/src/pipeline/link/varyings.rs (unmatched, 2 sites)`, `crates/metal2vulkan/src/pipeline/link/varyings.rs (varyings)` | `rare`: a varying read wider than written behind a vertex function compiled alone, or at another component count behind a mesh function, under agx.allow_mismatched_component_counts as 1 (seen in modules Apple's Metal shader converter wrote); otherwise a Metal link error | | `VertexStepRate` | A vertex buffer layout stepped per instance at a rate above 1, on a profile that fetches every attribute in fixed function (the identity domains,... | devices without a capability the site computes (`needs`) | `device` | 1: `crates/metal2vulkan/src/metal/vertex.rs (divided)` | `app`: instanced vertex layouts stepped at a rate above 1 | | `VertexInputLayout` | A vertex attribute whose layout fixed-function input cannot fetch, on a profile that fetches every attribute in fixed function (the identity... | devices without a capability the site computes (`limit`); every device (not implemented) | `ours` | 4: `crates/metal2vulkan/src/pipeline/link/vertex.rs (resolve, 4 sites)` | `rare`: vertex offsets or strides off their format's alignment, or past a device's limits | | `Tessellation` | Tessellation | devices without VkFeature::TessellationShader; devices without VkLimit::MaxTessellationGenerationLevel; every device (not implemented) | `ours` | 5: `crates/metal2vulkan-air/src/canon/mod.rs (post_check, 2 sites)`, `crates/metal2vulkan/src/error/mod.rs (tessellation)` (+2) | `rare`: tessellation | diff --git a/scripts/refusal-surface/reach.tsv b/scripts/refusal-surface/reach.tsv index 25cd4156e..bb6409169 100644 --- a/scripts/refusal-surface/reach.tsv +++ b/scripts/refusal-surface/reach.tsv @@ -65,7 +65,7 @@ feature PullModelInterpolation rare interpolant inputs read at the centroid, a s feature DivergentInterpolation rare an interpolant read at a sample or an offset in a branch, a loop or after a discard feature PixelCoverageAtSampleRate rare coverage read at sample rate feature InterfaceComponents rare too many varyings or attachments for a device -feature UnmatchedVarying rare a varying read at another component count than written, behind a vertex module stating agx.allow_mismatched_component_counts as 1 (seen in modules Apple's Metal shader converter wrote); otherwise a Metal link error +feature UnmatchedVarying rare a varying read wider than written behind a vertex function compiled alone, or at another component count behind a mesh function, under agx.allow_mismatched_component_counts as 1 (seen in modules Apple's Metal shader converter wrote); otherwise a Metal link error feature VertexStepRate app instanced vertex layouts stepped at a rate above 1 feature VertexInputLayout rare vertex offsets or strides off their format's alignment, or past a device's limits feature Tessellation rare tessellation