From e3fbf2ca99fb3e19ed1097e8cba06d36d8e8f476 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sat, 21 Nov 2026 23:38:23 -0800 Subject: [PATCH] PrecisionNote::VertexSimdgroupGrouping: a vertex function's simdgroup and quad operations run over the device's grouping A vertex function that runs a simdgroup or quad operation (any group operation or AGX multiply-add: the simd plan's observes_lanes) records PrecisionNote::VertexSimdgroupGrouping on every device (lower::simd::finish). Metal's shading language defines its SIMD-group and quad-group functions for kernel and fragment functions (MSL 4.1 sections 6.10.2 and 6.10.3) and names no lane among a vertex function's inputs (Table 5.2), so in a vertex function the groups are the device's own, as FragmentSimdgroupGrouping already says of fragment functions. Validation takes the note as unbounded (a difference is a noted difference) and C3 defers its rows (DEFERRED_NEAR_EQUIVALENTS), as it does the fragment note; conformance names it metal2vulkan-degrade-vertex-simdgroup-grouping; docs/API.md's catalogue states it. SEMANTICS 2272. Why: on the Iris Xe (RPL-P, Mesa 26.2.6) 8 authored vertex cases mismatched the M3 Max while the Radeon 780M and the RTX 3090 matched. A raw Vulkan probe outside the runtime (a SPIR-V 1.5 vertex shader over 64 rasterizer-discarded points, validation layer on, 0 messages; Iris Xe job m3-max-66302, Radeon 780M m3-max-66303, RTX 3090 m3-max-66304) read SubgroupSize 32 in every Iris vertex invocation with lane ids 0 to 7 only: 8 subgroups of 8, in each run of 16 vertices the even ones in one and the odd ones in another, every vote, sum, shuffle and quad broadcast exact over the driver's own groups. The 780M runs one 64-lane group in vertex order, the 3090 two 32-lane groups. Vulkan holds SubgroupSize to subgroupSize for a SPIR-V 1.5 module and promises full subgroups only to stages with workgroups, so the driver answers per its properties, and the translator's tier follows the stage's queries (Iris: vertex not in requiredSubgroupSizeStages, Direct at the API size 32). The 8 cases' outputs on the Iris (m3-max-66342) equal, word for word, Metal's semantics over the Iris's own groups with the partly-live rule's own-value read for a lane that takes no part (0 differing words in each of the 8; the grouping of the 40- and 42-point draws is inferred from the 64-point rule). --- .../src/degradation.rs | 7 ++++ crates/metal2vulkan-validation/src/c3.rs | 14 ++++++- .../metal2vulkan-validation/src/c3/tests.rs | 10 +++++ .../src/observation_contract/comparison.rs | 6 ++- .../observation_contract/comparison/tests.rs | 1 + crates/metal2vulkan/src/cache/codec.rs | 1 + crates/metal2vulkan/src/cache/mod.rs | 2 +- crates/metal2vulkan/src/lower/simd/mod.rs | 5 +++ crates/metal2vulkan/src/pipeline/artifact.rs | 14 +++++++ crates/metal2vulkan/src/tests/engine_simd.rs | 41 +++++++++++++++++++ crates/metal2vulkan/tests/api_signatures.tsv | 2 + docs/API.md | 10 +++++ 12 files changed, 110 insertions(+), 3 deletions(-) diff --git a/crates/metal2vulkan-conformance/src/degradation.rs b/crates/metal2vulkan-conformance/src/degradation.rs index 95c3cf7af..47fa0b226 100644 --- a/crates/metal2vulkan-conformance/src/degradation.rs +++ b/crates/metal2vulkan-conformance/src/degradation.rs @@ -175,6 +175,8 @@ pub enum Degradation { DeviceFragmentRuns, /// `metal2vulkan-degrade-device-occlusion-count`. DeviceOcclusionCount, + /// `metal2vulkan-degrade-vertex-simdgroup-grouping`. + VertexSimdgroupGrouping, } impl Degradation { @@ -262,6 +264,7 @@ impl Degradation { Degradation::DeviceLineRasterization, Degradation::DeviceFragmentRuns, Degradation::DeviceOcclusionCount, + Degradation::VertexSimdgroupGrouping, ]; /// The kind's code, `metal2vulkan-degrade-`. @@ -389,6 +392,9 @@ impl Degradation { } Degradation::DeviceFragmentRuns => "metal2vulkan-degrade-device-fragment-runs", Degradation::DeviceOcclusionCount => "metal2vulkan-degrade-device-occlusion-count", + Degradation::VertexSimdgroupGrouping => { + "metal2vulkan-degrade-vertex-simdgroup-grouping" + } } } @@ -479,6 +485,7 @@ impl Degradation { PrecisionNote::DeviceLineRasterization => Degradation::DeviceLineRasterization, PrecisionNote::DeviceFragmentRuns => Degradation::DeviceFragmentRuns, PrecisionNote::DeviceOcclusionCount => Degradation::DeviceOcclusionCount, + PrecisionNote::VertexSimdgroupGrouping => Degradation::VertexSimdgroupGrouping, } } } diff --git a/crates/metal2vulkan-validation/src/c3.rs b/crates/metal2vulkan-validation/src/c3.rs index 3ba49408a..b29d614df 100644 --- a/crates/metal2vulkan-validation/src/c3.rs +++ b/crates/metal2vulkan-validation/src/c3.rs @@ -712,6 +712,10 @@ pub struct SlotRow { /// rasterizer packs together, or a quad Apple's GPU may shade as several partial quads, a group /// Metal allows, and its value is ordinary data later words use. No exact path exists on such a /// device. +/// - A vertex function's simdgroup or quad operation (`VertexSimdgroupGrouping`): the operation +/// combines the vertices the device packs into a subgroup, a group Metal allows, and its value +/// is ordinary data later words use. No exact path exists: nothing in Vulkan fills a vertex +/// subgroup or fixes which vertices share one. /// - A half-float color channel under `textureWriteRoundingMode` 2 that blends with factors /// other than one and zero (`BlendedWriteRounding`): the device's blend converts its result by /// its own rounding where Metal rounds it to nearest even, and the stored half is ordinary data @@ -739,13 +743,14 @@ pub struct SlotRow { /// denormal, a `half` rounding) belongs in a per-word judgement of a reading's differing words, /// beside the check of each against Apple's bound, never in this list: a row-level match would /// reopen every signed-off reading whose row merely records the note. -pub const DEFERRED_NEAR_EQUIVALENTS: [PrecisionNote; 9] = [ +pub const DEFERRED_NEAR_EQUIVALENTS: [PrecisionNote; 10] = [ PrecisionNote::RasterizationRateMap, PrecisionNote::SparseResidency, PrecisionNote::CubeGradientFootprint, PrecisionNote::QuadsCountedBeforeDiscard, PrecisionNote::BicubicFilterArithmetic, PrecisionNote::FragmentSimdgroupGrouping, + PrecisionNote::VertexSimdgroupGrouping, PrecisionNote::BlendedWriteRounding, PrecisionNote::CoverageReadsRoundedAlpha, PrecisionNote::RotatedBlendRounding, @@ -835,6 +840,13 @@ fn near_equivalent_bound(note: PrecisionNote) -> &'static str { others as helpers (3 of 16 quads at 8x8, 2 to 4 of 12 at 7x5, gsm2_helper_threads); \ no exact path: no Vulkan device states or pins its packing" } + PrecisionNote::VertexSimdgroupGrouping => { + "a vertex function's simdgroup or quad holds the vertices the device packs into a \ + subgroup, where Apple M3 Max's answers group 32 consecutive vertices (MSL defines \ + these functions for kernel and fragment functions); Iris Xe (Mesa 26.2.6) runs 8 of \ + 64 points a subgroup, the even or the odd vertices of a run of 16; no exact path: \ + nothing in Vulkan fills a vertex subgroup or fixes which vertices share one" + } PrecisionNote::BlendedWriteRounding => { "a half-float color channel under textureWriteRoundingMode 2 blended with factors \ other than one and zero stores the device's rounding of the blend's result, where \ diff --git a/crates/metal2vulkan-validation/src/c3/tests.rs b/crates/metal2vulkan-validation/src/c3/tests.rs index da0bd427d..cbb3b5cbc 100644 --- a/crates/metal2vulkan-validation/src/c3/tests.rs +++ b/crates/metal2vulkan-validation/src/c3/tests.rs @@ -1158,6 +1158,16 @@ fn a_fragment_simdgroup_grouping_row_is_deferred_and_never_a_reviewed_reading() ); } +/// A vertex function's simdgroup or quad operation, which runs over the vertices the device packs +/// into a subgroup (`VertexSimdgroupGrouping`), is deferred the same way. +#[test] +fn a_vertex_simdgroup_grouping_row_is_deferred_and_never_a_reviewed_reading() { + deferred_and_never_reviewed( + PrecisionNote::VertexSimdgroupGrouping, + "VertexSimdgroupGrouping:a vertex function's simdgroup", + ); +} + /// A blended half-float color channel under `textureWriteRoundingMode` 2, which the device's /// blend rounds (`BlendedWriteRounding`), is deferred the same way. #[test] diff --git a/crates/metal2vulkan-validation/src/observation_contract/comparison.rs b/crates/metal2vulkan-validation/src/observation_contract/comparison.rs index 919986996..6f8828359 100644 --- a/crates/metal2vulkan-validation/src/observation_contract/comparison.rs +++ b/crates/metal2vulkan-validation/src/observation_contract/comparison.rs @@ -213,6 +213,9 @@ impl UlpTable { /// device's rasterizer packs together, not Apple's, which moves a sum, a ballot, or a shuffle by /// whole pixels; and a quad of a function that discards holds every covered pixel where Apple's /// GPU may run some as helpers, which moves a ballot of a helper query by whole lanes. +/// - `VertexSimdgroupGrouping`: unbounded: a vertex function's simdgroup or quad holds the vertices +/// the device packs into a subgroup, not Apple's, which moves a sum, a vote, or a shuffle by +/// whole vertices. /// - `BlendedWriteRounding`: unbounded: a blended half-float channel under /// `textureWriteRoundingMode` 2 stores the device's rounding of the blend's result, which no /// Vulkan blend states, where Metal rounds it to nearest even. @@ -336,7 +339,8 @@ pub fn allowance(note: PrecisionNote) -> Allowance { | N::SwizzledOpaqueBlackBorder | N::DeviceLineRasterization | N::DeviceFragmentRuns - | N::DeviceOcclusionCount => Allowance::Unbounded, + | N::DeviceOcclusionCount + | N::VertexSimdgroupGrouping => Allowance::Unbounded, } } diff --git a/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs b/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs index 5d142e201..df25de352 100644 --- a/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs +++ b/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs @@ -91,6 +91,7 @@ fn every_precision_note_has_its_table_row() { (N::DeviceLineRasterization, Allowance::Unbounded), (N::DeviceFragmentRuns, Allowance::Unbounded), (N::DeviceOcclusionCount, Allowance::Unbounded), + (N::VertexSimdgroupGrouping, Allowance::Unbounded), ]; for (note, expected) in rows { assert_eq!(allowance(note), expected, "{note:?}"); diff --git a/crates/metal2vulkan/src/cache/codec.rs b/crates/metal2vulkan/src/cache/codec.rs index 1a96cc60f..9dc2ae367 100644 --- a/crates/metal2vulkan/src/cache/codec.rs +++ b/crates/metal2vulkan/src/cache/codec.rs @@ -1449,6 +1449,7 @@ codec_enum! { DeviceLineRasterization, DeviceFragmentRuns, DeviceOcclusionCount, + VertexSimdgroupGrouping, } BindingSource { Buffer(f0), Texture(f0), Sampler(f0), CombinedTextureSampler { texture, sampler }, diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 161cd49be..d617309cf 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -61,7 +61,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 = 2271; +pub const SEMANTICS_VERSION: u32 = 2272; /// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the /// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another diff --git a/crates/metal2vulkan/src/lower/simd/mod.rs b/crates/metal2vulkan/src/lower/simd/mod.rs index ce9c15293..fe27275c8 100644 --- a/crates/metal2vulkan/src/lower/simd/mod.rs +++ b/crates/metal2vulkan/src/lower/simd/mod.rs @@ -411,6 +411,11 @@ pub fn finish(cx: &mut SelectCx<'_>) -> Result<(), Error> { cx.precision .insert(PrecisionNote::FragmentSimdgroupGrouping); } + // A vertex function's simdgroups and quads are the vertices the device packs into a subgroup, + // so every operation over other lanes combines a group Metal allows, not the reference's. + if cx.stage == Stage::Vertex && cx.families.simd.observes_lanes { + cx.precision.insert(PrecisionNote::VertexSimdgroupGrouping); + } let plan = &cx.families.simd; if plan.groups { let model = &cx.profile.fields().subgroup; diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index a0424907a..0a11a4b3c 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -2085,6 +2085,20 @@ pub enum PrecisionNote { /// Validation derives no tolerance from it: a difference stays a mismatch, which the note /// explains. DeviceOcclusionCount, + /// A vertex function runs a simdgroup or quad operation (a reduction, scan, vote, ballot, + /// shuffle, broadcast or AGX multiply-add), on every device. Metal's shading language defines + /// its SIMD-group and quad-group functions for kernel and fragment functions (MSL 4.1 sections + /// 6.10.2 and 6.10.3), and no vertex input names a lane (Table 5.2): in a vertex function the + /// groups are the device's own. The operation runs over the vertices the device packs into a + /// subgroup, in the device's lane order, so a sum, a vote or a shuffle can combine other + /// vertices than on the M3 Max, whose answers group 32 consecutive vertices. Vulkan promises + /// full subgroups only to stages with workgroups, and nothing pins which vertices share one: + /// measured on an Iris Xe (RPL-P, Mesa 26.2.6), whose vertex `SubgroupSize` is 32, each + /// subgroup of 64 points holds 8 of them, the even or the odd vertices of a run of 16, and the + /// other 24 lanes take no part. + /// + /// Validation derives no tolerance from it: a difference stays a noted difference for review. + VertexSimdgroupGrouping, } /// Which lowering strategies a module used, with their word costs. diff --git a/crates/metal2vulkan/src/tests/engine_simd.rs b/crates/metal2vulkan/src/tests/engine_simd.rs index dbdbabf49..afac67da1 100644 --- a/crates/metal2vulkan/src/tests/engine_simd.rs +++ b/crates/metal2vulkan/src/tests/engine_simd.rs @@ -721,6 +721,47 @@ fn fragment_simdgroup_functions_record_the_grouping() { assert!(noted > 0, "no profile recorded the note"); } +/// A vertex function of simdgroup operations (`rvc_simd_vertex`: a sum, shuffles and a ballot) or +/// of quad operations (`gsm2_vertex_quad_permutes`' broadcasts and shuffle-xors) records +/// `PrecisionNote::VertexSimdgroupGrouping` on every committed profile that compiles it; a +/// kernel's (`simd_ops`' sum) and a fragment function's (`fragment_discard_counts`' sums) record +/// none. +#[test] +fn vertex_simdgroup_functions_record_the_grouping() { + let note = PrecisionNote::VertexSimdgroupGrouping; + let (Some(simd), Some(quads), Some(kernels), Some(counts)) = ( + assemble("rvc_simd_vertex"), + assemble("gsm2_vertex_quad_permutes"), + assemble("simd_ops"), + assemble("fragment_discard_counts"), + ) else { + return; + }; + let (mut noted, mut unnoted) = (0, 0); + for (name, p) in committed_profiles().expect("profiles") { + for (bc, entry) in [ + (&simd, "simd_functions_in_a_vertex_function"), + (&quads, "quad_permutes_in_a_vertex_function"), + ] { + if let Ok(a) = compile(bc, entry, &p) { + assert!(a.precision.contains(¬e), "{entry} on {name}"); + noted += 1; + } + } + for (bc, entry) in [(&kernels, "simd_sum_k"), (&counts, "discard_counts")] { + if let Ok(a) = compile(bc, entry, &p) { + assert!(!a.precision.contains(¬e), "{entry} on {name}"); + unnoted += 1; + } + } + } + assert!(noted > 0, "no profile compiled a vertex function"); + assert!( + unnoted > 0, + "no profile compiled a kernel or fragment function" + ); +} + /// An operation over the group's active lanes records `PrecisionNote::QuadsSplitByClipping` in a /// fragment function alone (`fragment_discard_counts`' sums), where clipping may split a quad, on /// every committed profile that compiles it; a kernel's (`simd_ops`' sum, vote, ballot and first diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index bced97b97..fd0c0b855 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -9392,6 +9392,7 @@ variant metal2vulkan-runtime::PrecisionNote::TessellationTriangleOrder Tessellat variant metal2vulkan-runtime::PrecisionNote::TessellationWinding TessellationWinding variant metal2vulkan-runtime::PrecisionNote::UnmeasuredGroupSpeculation UnmeasuredGroupSpeculation variant metal2vulkan-runtime::PrecisionNote::UnorderedFetchWithinDraw UnorderedFetchWithinDraw +variant metal2vulkan-runtime::PrecisionNote::VertexSimdgroupGrouping VertexSimdgroupGrouping variant metal2vulkan-runtime::PrecisionNote::ViewBaseTexelOffset ViewBaseTexelOffset variant metal2vulkan-runtime::RangeKind::Allocation Allocation(AllocationId, MemoryClass) variant metal2vulkan-runtime::RangeKind::Export Export @@ -10895,6 +10896,7 @@ variant metal2vulkan::pipeline::PrecisionNote::TessellationTriangleOrder Tessell variant metal2vulkan::pipeline::PrecisionNote::TessellationWinding TessellationWinding variant metal2vulkan::pipeline::PrecisionNote::UnmeasuredGroupSpeculation UnmeasuredGroupSpeculation variant metal2vulkan::pipeline::PrecisionNote::UnorderedFetchWithinDraw UnorderedFetchWithinDraw +variant metal2vulkan::pipeline::PrecisionNote::VertexSimdgroupGrouping VertexSimdgroupGrouping variant metal2vulkan::pipeline::PrecisionNote::ViewBaseTexelOffset ViewBaseTexelOffset variant metal2vulkan::pipeline::PushField::AlphaTestReference AlphaTestReference variant metal2vulkan::pipeline::PushField::AmplificationId AmplificationId diff --git a/docs/API.md b/docs/API.md index a42d98a0f..3cad4f1bf 100644 --- a/docs/API.md +++ b/docs/API.md @@ -2197,6 +2197,16 @@ bound. drops, where an Apple GPU's simdgroup counts the dropped quads of its 8x4 pixel block; the device states one fragment subgroup size, so no required size widens it, and no exact form exists there. +- `metal2vulkan-degrade-vertex-simdgroup-grouping` (precision). + `PrecisionNote::VertexSimdgroupGrouping`: A vertex function runs a simdgroup or quad operation + (a reduction, scan, vote, ballot, shuffle, broadcast or AGX multiply-add), on every device. + Metal's shading language defines its SIMD-group and quad-group functions for kernel and + fragment functions (MSL 4.1 sections 6.10.2 and 6.10.3); in a vertex function the groups are the + device's own. The operation runs over the vertices the device packs into a subgroup, in its + lane order, so a sum, a vote or a shuffle can combine other vertices than on the M3 Max, whose + answers group 32 consecutive vertices. Vulkan neither fills a vertex subgroup nor fixes which + vertices share one: an Iris Xe (Mesa 26.2.6) whose vertex subgroup size is 32 runs 8 of 64 + points in each, the even or the odd vertices of a run of 16. - `metal2vulkan-degrade-blended-write-rounding` (precision). `PrecisionNote::BlendedWriteRounding`: A fragment function writes a float to a half-float color channel of a render pipeline under `TextureWriteRoundingMode::NearestEven` that blends with factors other than one and zero