SEMANTICS 2138: Fragment simdgroup lane: run it on Cluster32 tiers, refuse it only below 32 lanes

What: a fragment function that reads [[thread_index_in_simdgroup]] on a profile
without DriverDeviation::MetalFragmentSimdgroups was refused Unsupported{SimdWidth}
on every tier but Direct. It is now refused only on Tier::PartialFragment (fragment
subgroups narrower than 32). On Tier::Cluster32 (a 64- or 128-lane fragment stage,
e.g. RADV on Polaris, wave64 only) the lane is the subgroup lane's low five bits.

Why: the guest is told an Apple GPU's width, 32 (threadExecutionWidth 32,
[[threads_per_simdgroup]] the constant 32), and its shaders are built for 32-lane
simdgroups. On Cluster32 each aligned 32 lanes of the device's subgroup is one
simdgroup. The function's simdgroup operations already ran there, and the emitter
already gave the lane as L & 31 (group::Lane::metal), the same cluster the shuffles
and ballot words use. So the device lacked nothing; the refusal was ours. The lane
is the device's grouping, which Metal allows, and records the existing
PrecisionNote::FragmentSimdgroupGrouping as before.

Tests: engine_simd's fragment-lane test also runs on wave64() (the committed RDNA3
description narrowed to 64 lanes) and requires every lane form to compile there on
Cluster32 with the note, the low-bits mask and L3. Without the fix it is refused and
the test panics. Device test fragment_simdgroup_lanes_are_metal_s accepts the
SimdWidth refusal only where the fragment stage's sizes are all below 32, so on a
wave64-only device it fails without the fix; it also prints the stage's sizes.

Docs: the note's text in docs/API.md and PrecisionNote, the doc comments in
lower::simd. SEMANTICS_VERSION 2137 -> 2138. REFUSALS.md regenerated, unchanged.

Checks (lane simd64): msi m3-max-37237 clippy plain 0, tests 88/88 (engine_simd, public_fixtures_engine, fast_paths, device::tests::subgroup); m3-max-37255 clippy GPU and CPU-ICD cfgs 0, rustdoc 0. The RX 550 run (m3-max-37259) follows on development.
This commit is contained in:
Anees Iqbal committed 2026-11-16 10:47:52 -08:00
1 parent a8b791bd12
commit 2bafb6537a
6 files changed
+87 -52

No files matched your search

@@ -95,9 +95,11 @@
//! takes the deviation, the lane is the subgroup lane and every pixel holds Metal's lane of the
//! same draw (the quads of an aligned 8x4 block in row-major order where one primitive covers it,
//! the rasterizer's packing elsewhere, measured on the M3 Max and the M4 alike). Elsewhere, on a
//! device whose fragment stage runs 32-lane subgroups, the lane is the device's own grouping's,
//! which the lane checks only for coverage and range; on any other device each pipeline state is
//! refused `SimdWidth`, needing `VkProperty::MetalFragmentSimdgroups` or a 32-lane stage. A
//! device whose fragment stage runs 32-lane subgroups, or 64- or 128-lane ones split into 32-lane
//! simdgroups (the RX 550's), the lane is the device's own grouping's, which the lane checks only
//! for coverage and range; on a device whose fragment subgroups are all narrower than 32 each
//! pipeline state is refused `SimdWidth`, needing `VkProperty::MetalFragmentSimdgroups` or a
//! 32-lane stage. A
//! fourth function writes the lane beside shuffles of it and the ballot's first lane, which must
//! name the same lanes on every device that makes it. The fixture's `[[threads_per_simdgroup]]`
//! parameter draws 32 on every device.
@@ -2169,16 +2171,18 @@ fn device_lanes(drawn: &[u32], metal: &[u32]) -> Option<String> {
}
/// Why `error` is not the refusal a device without Metal's fragment simdgroups (`metals` false)
/// gives a fragment lane where its fragment stage runs no 32-lane subgroups: `SimdWidth`, needing
/// `VkProperty::MetalFragmentSimdgroups` or what the stage lacks for 32 lanes, or, on a stage
/// without the subgroup tier, `SubgroupOperations`.
fn lane_refusal(error: &RuntimeError, metals: bool) -> Option<String> {
/// gives a fragment lane: `SimdWidth`, needing `VkProperty::MetalFragmentSimdgroups` or what the
/// stage lacks for 32 lanes, where every fragment subgroup the stage may run is narrower than 32
/// (`narrow`; a 64- or 128-lane one runs as 32-lane simdgroups), or, on a stage without the
/// subgroup tier, `SubgroupOperations`.
fn lane_refusal(error: &RuntimeError, metals: bool, narrow: bool) -> Option<String> {
let property = vec![Capability::Property(VkProperty::MetalFragmentSimdgroups)];
match error {
RuntimeError::Compile(CompileError::Unsupported(u)) | RuntimeError::Unsupported(u)
if !metals =>
{
let width = u.feature == Feature::SimdWidth
let width = narrow
&& u.feature == Feature::SimdWidth
&& matches!(&u.needs, Needs::AnyOf(alternatives) if alternatives.first() == Some(&property));
(!width && u.feature != Feature::SubgroupOperations).then(|| format!("{error}"))
}
@@ -2191,9 +2195,10 @@ fn lane_refusal(error: &RuntimeError, metals: bool) -> Option<String> {
/// of a fragment's simdgroup lane (a `uint` and a `ushort` parameter, a program-scope `uint`)
/// draws Metal's lanes of the same draws on every pixel, those of a primitive covering an
/// aligned 8x4 block whole and those the rasterizer packs across blocks and primitives.
/// - Elsewhere, where the device's fragment stage runs 32-lane subgroups, each draws the lanes of
/// the device's own grouping: every pixel Metal covers, each lane below 32. Where it
/// runs none, each pipeline state is refused ([`lane_refusal`]).
/// - Elsewhere, where the device's fragment stage runs 32-lane subgroups, or 64- or 128-lane ones
/// split into 32-lane simdgroups, each draws the lanes of the device's own grouping: every pixel
/// Metal covers, each lane below 32. Where its subgroups are all narrower than 32, each pipeline
/// state is refused ([`lane_refusal`]).
/// - `fragment_lane_shuffles` writes the lane beside a shuffle of the lane from itself, the first
/// active lane by the ballot's bits, and a shuffle of the lane from that first lane. Wherever it
/// is made, each pixel's own shuffle is its lane, the first lane's shuffle is the first lane,
@@ -2209,6 +2214,12 @@ fn fragment_simdgroup_lanes_are_metal_s() {
let device = validated_device_with(TEST_DEVICE, &messages, cache.path(), at_plan).unwrap();
let name = device.name().to_owned();
let metals = takes(&device, DriverDeviation::MetalFragmentSimdgroups);
let fragment = device.compile_device().profile().subgroups().fragment;
let narrow = fragment.sizes.max < 32;
eprintln!(
"fragment subgroups on {name}: sizes {}..={}, pinnable {}",
fragment.sizes.min, fragment.sizes.max, fragment.pinnable
);
let r32 = (PixelFormat::R32Uint, 1);
let lanes_verdict = |drawn: &[u32], metal: &[u32], what: &str| {
let differ = differing_lanes(drawn, metal);
@@ -2240,7 +2251,7 @@ fn fragment_simdgroup_lanes_are_metal_s() {
Ok(drawn) => lanes_verdict(&drawn, &metal, &format!("{draw} {fragment}")),
Err(error) => {
eprintln!("fragment lanes {draw} {fragment} on {name}: {error}");
lane_refusal(&error, metals)
lane_refusal(&error, metals, narrow)
}
};
if let Some(why) = verdict {
@@ -2285,7 +2296,7 @@ fn fragment_simdgroup_lanes_are_metal_s() {
}
Err(error) => {
eprintln!("fragment lanes {draw} {shuffles} on {name}: {error}");
lane_refusal(&error, metals)
lane_refusal(&error, metals, narrow)
}
};
if let Some(why) = verdict {
+1 -1
View File
@@ -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 = 2137;
pub const SEMANTICS_VERSION: u32 = 2138;
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
+22 -19
View File
@@ -316,11 +316,13 @@ pub struct SimdPlan {
/// fragment subgroups are Metal's simdgroups ([`select_param`]): the module requires
/// `VkProperty::MetalFragmentSimdgroups`.
pub metal_lane: bool,
/// A fragment's `[[thread_index_in_simdgroup]]` is the subgroup lane on a profile whose
/// fragment subgroups are not Metal's simdgroups ([`select_param`]): the function records
/// `PrecisionNote::FragmentSimdgroupGrouping`, and [`finish`] refuses it unless the stage runs
/// 32-lane subgroups (`Tier::Direct`), the simdgroups its operations and
/// `[[threads_per_simdgroup]]` name.
/// A fragment's `[[thread_index_in_simdgroup]]` is the lane of the device's grouping on a
/// profile whose fragment subgroups are not Metal's simdgroups ([`select_param`]): the
/// function records `PrecisionNote::FragmentSimdgroupGrouping`, and [`finish`] refuses it
/// unless the stage's tier gives 32-lane simdgroups, the ones its operations and
/// `[[threads_per_simdgroup]]` name: a 32-lane subgroup (`Tier::Direct`, the subgroup lane) or
/// a 32-lane cluster of a 64- or 128-lane one (`Tier::Cluster32`, the subgroup lane's low five
/// bits).
pub device_lane: bool,
/// Some operation reads or combines other lanes of the simdgroup (a simdgroup-scope group
/// operation, an AGX multiply-add), or the function reads the lane itself, so its answer
@@ -468,16 +470,15 @@ pub fn finish(cx: &mut SelectCx<'_>) -> Result<(), Error> {
}
};
}
// The device's lane is the lane of the subgroups the function's operations run over, and
// `[[threads_per_simdgroup]]` names 32 of them: only a 32-lane subgroup is that simdgroup. On
// a tier of other subgroups the lane is refused, needing Metal's own grouping or a 32-lane
// fragment stage; a refused tier is `select`'s refusal.
// The device's lane is the lane of the simdgroups the function's operations run over, and
// `[[threads_per_simdgroup]]` names 32 of them: a 32-lane subgroup (`Direct`), or a 32-lane
// cluster of a 64- or 128-lane subgroup (`Cluster32`), whose lane is the subgroup lane's low
// five bits, as its operations' lanes are. On a subgroup narrower than 32 (`PartialFragment`)
// the lane is refused, needing Metal's own grouping or a 32-lane fragment stage; a refused
// tier is `select`'s refusal.
if cx.families.simd.device_lane {
let model = &cx.profile.fields().subgroup;
if matches!(
subgroup::tier(&cx.simd, cx.stage, model),
Ok(t) if t != Tier::Direct
) {
if subgroup::tier(&cx.simd, cx.stage, model) == Ok(Tier::PartialFragment) {
use crate::device::requirements::VkProperty;
return Err(Unsupported::needs_any_of(
Feature::SimdWidth,
@@ -840,12 +841,14 @@ pub fn partly_live_words(s: &Strategy, tier: Tier) -> u32 {
/// rasterizer's packing: on the M3 Max and the M4 a primitive that covers an aligned 8x4 block
/// whole runs it as one simdgroup, its quads in row-major order, and elsewhere the covered quads
/// of several blocks and primitives share one. Nothing in Vulkan states or pins a device's
/// packing. The lane is the subgroup lane and raises the basic class. Where the profile takes
/// `DriverDeviation::MetalFragmentSimdgroups` (the driver runs the fragment on Metal) that is
/// Metal's lane, and the module requires `VkProperty::MetalFragmentSimdgroups`. Elsewhere it is
/// the lane of the device's grouping, which Metal does not rule out: the function records
/// packing. The lane is the tier's simdgroup lane and raises the basic class. Where the profile
/// takes `DriverDeviation::MetalFragmentSimdgroups` (the driver runs the fragment on Metal) that
/// is Metal's lane, and the module requires `VkProperty::MetalFragmentSimdgroups`. Elsewhere it
/// is the lane of the device's grouping, which Metal does not rule out: the function records
/// `PrecisionNote::FragmentSimdgroupGrouping`, as its simdgroup operations do, and [`finish`]
/// refuses it `Unsupported{SimdWidth}` unless the stage runs 32-lane subgroups. Under the loop
/// refuses it `Unsupported{SimdWidth}` unless the stage's tier gives 32-lane simdgroups (a
/// 32-lane subgroup, or a 32-lane cluster of a wider one, whose lane is the subgroup lane's low
/// five bits). Under the loop
/// over the covered samples one invocation runs a pixel's samples, each of which Metal runs in a
/// lane of its own, so it is refused there `NotImplemented(PixelCoverageAtSampleRate)`.
/// - `[[threads_per_simdgroup]]`: 32, as `get_simdgroup_size` is, raising no class.
@@ -882,7 +885,7 @@ pub fn select_param(cx: &mut SelectCx<'_>, b: &crate::air::abi::ParamBinding) ->
cx.families.simd.metal_lane = true;
} else {
// The device's own grouping, announced as its operations' is ([`finish`]
// checks the tier gives 32-lane subgroups).
// checks the tier gives 32-lane simdgroups).
cx.families.simd.device_lane = true;
cx.families.simd.simdgroup_members = true;
}
+5 -3
View File
@@ -1376,9 +1376,11 @@ pub enum PrecisionNote {
/// [`DriverDeviation::MetalFragmentSimdgroups`](crate::error::DriverDeviation::MetalFragmentSimdgroups)).
/// A simdgroup operation runs over the pixels the device's rasterizer packs into a subgroup,
/// so a sum, a ballot or a shuffle combines other pixels than on an Apple GPU, whose packing is
/// measured, and the lane is the pixel's place in the device's subgroup. Metal does not fix
/// which pixels share a simdgroup, so each device subgroup is a simdgroup Metal's API allows,
/// not the reference's. An Apple GPU also shades some quads of a function that discards as
/// measured, and the lane is the pixel's place in the device's subgroup, or in its aligned 32
/// lanes where the subgroup holds 64 or 128 (`Tier::Cluster32`: each such run of 32 lanes is
/// one simdgroup, as `[[threads_per_simdgroup]]`'s 32 says). Metal does not fix which pixels
/// share a simdgroup, so each device subgroup, or each run of 32 lanes of one, is a simdgroup
/// Metal's API allows, not the reference's. An Apple GPU also shades some quads of a function that discards as
/// several partial quads, from the function's start, each run holding the quad's other covered
/// pixels as helpers, where the device shades a primitive's covered pixels of a quad as one
/// quad: a ballot of the helper query names covered pixels of the quad as helpers on the Apple
+32 -15
View File
@@ -1244,15 +1244,17 @@ fn a_fragment_quad_lane_is_its_subgroup_lane_or_its_place_in_the_pixel_quad() {
/// The owned fixture `gsm2_fragment_lanes`. A fragment's `[[thread_index_in_simdgroup]]`, read as a
/// `uint` or `ushort` parameter or as a Metal 3.1 program-scope `uint`, and beside the shuffles and
/// ballot of `fragment_lane_shuffles`, is its subgroup lane wherever the stage gives one 32-lane
/// simdgroup:
/// ballot of `fragment_lane_shuffles`, is the lane of its tier's 32-lane simdgroup, over every
/// committed profile and the wave64-only device ([`wave64`], the shape of AMD GCN):
/// - where the profile takes `MetalFragmentSimdgroups` (MoltenVK on the M3 Max and the M4) the
/// module requires `VkProperty::MetalFragmentSimdgroups` and records no grouping note;
/// - on every other profile whose fragment stage runs 32-lane subgroups (`Tier::Direct`) it
/// requires no property and records `PrecisionNote::FragmentSimdgroupGrouping`;
/// - where the stage's subgroups are other widths it is refused `SimdWidth`, needing the property
/// or what the stage lacks for 32 lanes; where the stage has no subgroup tier, that refusal
/// (`SubgroupOperations`);
/// - on every other profile whose fragment stage runs 32-lane subgroups (`Tier::Direct`), or 64- or
/// 128-lane ones split into 32-lane clusters (`Tier::Cluster32`, the wave64 device: the lane is
/// the subgroup lane's low five bits) it requires no property and records
/// `PrecisionNote::FragmentSimdgroupGrouping`;
/// - where the stage's subgroups are narrower than 32 (`Tier::PartialFragment`) it is refused
/// `SimdWidth`, needing the property or what the stage lacks for 32 lanes; where the stage has no
/// subgroup tier, that refusal (`SubgroupOperations`);
/// - `fragment_lane_shuffles` on a 32-lane stage without `shaderQuadControl` is refused needing
/// it: its shuffles and ballot count Metal's helpers, which only full quads give.
///
@@ -1260,7 +1262,7 @@ fn a_fragment_quad_lane_is_its_subgroup_lane_or_its_place_in_the_pixel_quad() {
/// `[[threads_per_simdgroup]]` parameter is 32 on every profile, with no subgroup capability, no
/// property and no note.
#[test]
fn a_fragment_simdgroup_lane_is_the_subgroup_lane_where_the_stage_runs_32_lanes() {
fn a_fragment_simdgroup_lane_is_the_lane_of_a_32_lane_simdgroup_where_the_tier_gives_one() {
use crate::device::subgroup::width_needs;
use crate::error::{Capability, DriverDeviation, Needs};
let Some(bc) = assemble("gsm2_fragment_lanes") else {
@@ -1270,8 +1272,12 @@ fn a_fragment_simdgroup_lane_is_the_subgroup_lane_where_the_stage_runs_32_lanes(
let note = PrecisionNote::FragmentSimdgroupGrouping;
let lane = OpBits::BASIC;
let shuffles = lane.union(OpBits::BALLOT).union(OpBits::SHUFFLE);
let (mut taken, mut noted, mut narrow) = (Vec::new(), 0, 0);
for (stem, p) in committed_profiles().expect("profiles") {
let (mut taken, mut noted, mut narrow, mut clustered) = (Vec::new(), 0, 0, 0);
let profiles = committed_profiles().expect("profiles");
for (stem, p) in profiles
.into_iter()
.chain([("wave64".to_owned(), wave64())])
{
let takes = p.takes_driver_deviation(DriverDeviation::MetalFragmentSimdgroups);
if takes {
taken.push(stem.clone());
@@ -1285,7 +1291,7 @@ fn a_fragment_simdgroup_lane_is_the_subgroup_lane_where_the_stage_runs_32_lanes(
] {
let tier = subgroup::tier(&SimdClass::CrossLane(ops), Stage::Fragment, model);
match (compile(&bc, entry, &p), &tier) {
(Ok(a), Ok(Tier::Direct)) => {
(Ok(a), Ok(t @ (Tier::Direct | Tier::Cluster32))) => {
assert_eq!(
a.requirements.properties.contains(&property),
takes,
@@ -1299,14 +1305,22 @@ fn a_fragment_simdgroup_lane_is_the_subgroup_lane_where_the_stage_runs_32_lanes(
noted += usize::from(!takes);
let (_, words) = link_and_validate(&a, &p)
.unwrap_or_else(|e| panic!("{stem} {entry}: L3: {e}"));
let text = spirv_dis(&words);
assert!(
spirv_dis(&words).contains("BuiltIn SubgroupLocalInvocationId"),
text.contains("BuiltIn SubgroupLocalInvocationId"),
"{stem} {entry}: the lane"
);
if *t == Tier::Cluster32 {
assert!(
text.contains("OpBitwiseAnd"),
"{stem} {entry}: the low bits"
);
clustered += 1;
}
}
// Shuffles and a ballot count the helpers Metal runs, which a profile without
// `shaderQuadControl` cannot give.
(Err(Error::Unsupported(u)), Ok(Tier::Direct))
(Err(Error::Unsupported(u)), Ok(Tier::Direct | Tier::Cluster32))
if ops == shuffles && !model.quad_control =>
{
assert_eq!(
@@ -1320,7 +1334,7 @@ fn a_fragment_simdgroup_lane_is_the_subgroup_lane_where_the_stage_runs_32_lanes(
"{stem} {entry}"
);
}
(Err(Error::Unsupported(u)), Ok(_)) => {
(Err(Error::Unsupported(u)), Ok(Tier::PartialFragment)) => {
assert!(!takes, "{stem} {entry}: refused with the deviation: {u}");
let needs = Needs::AnyOf(vec![
vec![Capability::Property(property)],
@@ -1350,7 +1364,10 @@ fn a_fragment_simdgroup_lane_is_the_subgroup_lane_where_the_stage_runs_32_lanes(
);
}
assert_eq!(taken, ["moltenvk-m3"]);
assert!(noted > 0 && narrow > 0, "noted {noted}, narrow {narrow}");
assert!(
noted > 0 && narrow > 0 && clustered > 0,
"noted {noted}, narrow {narrow}, clustered {clustered}"
);
}
/// Kernel `group_k(device float *out [[buffer(0)]], uint t [[thread_index_in_threadgroup]])`
+3 -1
View File
@@ -4872,7 +4872,9 @@ bound.
Metal's simdgroups (the profile does not take `DriverDeviation::MetalFragmentSimdgroups`). A
simdgroup operation runs over the pixels the device's rasterizer packs into a subgroup, so a sum,
a ballot or a shuffle combines other pixels than on an Apple GPU, whose packing is measured, and
the lane is the pixel's place in the device's subgroup. An Apple GPU also shades some quads of a
the lane is the pixel's place in the device's subgroup, or in its aligned 32 lanes where the
subgroup holds 64 or 128 (each such run of 32 lanes is one simdgroup, as
`[[threads_per_simdgroup]]`'s 32 says). An Apple GPU also shades some quads of a
function that discards as several partial quads from the function's start, each run holding the
quad's other covered pixels as helpers, where the device shades them as one quad: a ballot of the
helper query names covered pixels as helpers on the M3 Max (3 of the 16 quads of an 8x8 target, 2