Link: behind the agx flag a narrower fragment input reads its vertex output's first lanes

Metal makes a render pipeline whose fragment function reads a user varying at
fewer components than the vertex function writes when the vertex module states
agx.allow_mismatched_component_counts as 1, and the input reads the output's
first lanes (Apple M3 Max, macOS 27.0.1, job m3-max-87586: 90 rows of float
under perspective, center_no_perspective and flat, uint and int flat). Link
answered it Unsupported{UnmatchedVarying, NotImplemented}.

Link now matches such an input to its output (reads_first_lanes: the same
class, fewer components, a vertex function of
StageIo::mismatched_component_counts, a description stating maintenance4), so
the input takes the output's location and component. Vulkan matches an input
of fewer components there under maintenance4 (spec 19.1.3; without it
VUID-RuntimeSpirv-maintenance4-06817 forbids it), which the runtime's floor
requires and enables: one form on every device, no query. A description without
maintenance4 keeps the gap, as do a wider input and any mismatch behind a mesh
function. No module changes: the fragment's input keeps its own width.

Docs: the varyings module docs, StageIo::mismatched_component_counts and
Feature::UnmatchedVarying say so. SEMANTICS_VERSION 2394 (a refusal becomes a
link).
This commit is contained in:
Anees Iqbal committed 2026-12-04 21:23:44 -08:00
1 parent ca796ca5ff
commit cb3cc03b6d
4 files changed
+42 -19

No files matched your search

+1 -1
View File
@@ -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 = 2393;
pub const SEMANTICS_VERSION: u32 = 2394;
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
+4 -2
View File
@@ -749,8 +749,10 @@ pub enum Feature {
/// A fragment input without a vertex or mesh output of its key and type: a Metal link error
/// (`NotRepresentable`). One that differs from its output in component count alone, behind a
/// 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):
/// not implemented yet (`NotImplemented`).
/// (`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
/// 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
/// every attribute in fixed function (the identity domains, where the pulled fetch is not
@@ -7,10 +7,14 @@
//! - **Varyings** match across the stages by user key, never by ordinal. The vertex function's
//! outputs are numbered densely in output order, one location each at component 0, and each
//! fragment input takes the number of its key; a fragment input without a vertex output of its
//! key and type is a Metal link error (`UnmatchedVarying`, `NotRepresentable`), but for one that
//! differs from its output in component count alone behind a vertex or mesh function of
//! `StageIo::mismatched_component_counts`, which Metal links and this translator does not yet
//! (`UnmatchedVarying`, `NotImplemented`). Unmatched vertex outputs stay (legal in both APIs). A fragment function alone numbers its inputs densely in declaration order.
//! key and type is a Metal link error (`UnmatchedVarying`, `NotRepresentable`). Behind a vertex
//! or mesh function of `StageIo::mismatched_component_counts`, Metal links an input that differs
//! from its output in component count alone. Behind a vertex function, an input of fewer
//! 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.
//! 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
@@ -61,7 +65,7 @@
use std::collections::{BTreeMap, BTreeSet};
use crate::device::requirements::VkLimit;
use crate::device::requirements::{VkFeature, VkLimit};
use crate::device::DeviceProfile;
use crate::error::{
Capability, Error, Feature, InternalError, InternalKind, RuntimeInput, Unsupported,
@@ -85,18 +89,32 @@ fn invariant(detail: &str) -> Error {
/// component count alone behind a producer of [`StageIo::mismatched_component_counts`], which
/// Metal links and this translator does not yet (see the module docs).
fn unmatched(producer: &StageIo, written: Option<IoType>, read: IoType) -> Error {
let counts_alone = written.is_some_and(|w| {
w.numeric == read.numeric
&& w.source_bits == read.source_bits
&& w.components != read.components
});
if counts_alone && producer.mismatched_component_counts {
if written.is_some_and(|w| counts_alone(w, read)) && producer.mismatched_component_counts {
Unsupported::not_implemented(Feature::UnmatchedVarying).into()
} else {
Unsupported::not_representable(Feature::UnmatchedVarying).into()
}
}
/// Types `written` and `read` differ in component count alone.
fn counts_alone(written: IoType, read: IoType) -> bool {
written.numeric == read.numeric
&& written.source_bits == read.source_bits
&& written.components != read.components
}
/// Fragment input type `read` reads the first lanes of vertex output type `written` (see the
/// module docs): `read` has fewer components of the same class, the vertex function `v` is of
/// [`StageIo::mismatched_component_counts`], and the description states `maintenance4`, under
/// which Vulkan matches an input of fewer components than its output at the output's location
/// and component.
fn reads_first_lanes(v: &StageIo, written: IoType, read: IoType, p: &DeviceProfile) -> bool {
counts_alone(written, read)
&& read.components < written.components
&& v.mismatched_component_counts
&& (p.fields().enabled.features).contains(&VkFeature::Maintenance4)
}
fn limit_error(limit: VkLimit, locations: u64, max_components: u32) -> Error {
Unsupported::needs(
Feature::InterfaceComponents,
@@ -418,7 +436,7 @@ pub fn assign(stages: &[&FunctionArtifact], p: &DeviceProfile) -> Result<Locatio
}
}
}
let varyings = varyings(vertex, fragment)?;
let varyings = varyings(vertex, fragment, p)?;
let output = output_limit(stages, p);
let dense: Vec<(u32, u32)> = (0..varyings.len()).map(|i| (i as u32, 0)).collect();
let placed = match check_limits(&varyings, &dense, output, p) {
@@ -451,6 +469,7 @@ pub fn assign(stages: &[&FunctionArtifact], p: &DeviceProfile) -> Result<Locatio
fn varyings<'a>(
vertex: Option<&'a StageIo>,
fragment: Option<&'a StageIo>,
p: &DeviceProfile,
) -> Result<Vec<Varying<'a>>, Error> {
let interpolation = |x: &crate::pipeline::stage_io::IoVariable| match &x.role {
IoRole::Varying { interpolation, .. } => *interpolation,
@@ -488,7 +507,7 @@ fn varyings<'a>(
let mut matched = BTreeSet::new();
for x in &v.outputs {
let read = match reads.get(&x.key) {
Some((ty, interp)) if *ty == x.ty => {
Some((ty, interp)) if *ty == x.ty || reads_first_lanes(v, x.ty, *ty, p) => {
matched.insert(&x.key);
*interp
}
+5 -3
View File
@@ -346,9 +346,11 @@ pub struct StageIo {
/// (`EntryPoint::mismatched_component_counts` of the AIR crate's `abi`), under which Metal
/// 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). Link refuses such a pipeline as this translator's gap,
/// `Unsupported{UnmatchedVarying, NotImplemented}`, and the same mismatch behind a function
/// without it as Metal's link error, `NotRepresentable`. False for every other function.
/// 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.
#[cfg_attr(feature = "serde", serde(default))]
pub mismatched_component_counts: bool,
}