diff --git a/crates/metal2vulkan-validation/runtime-sources.sha256 b/crates/metal2vulkan-validation/runtime-sources.sha256 index 50c01c290..b05e46d1a 100644 --- a/crates/metal2vulkan-validation/runtime-sources.sha256 +++ b/crates/metal2vulkan-validation/runtime-sources.sha256 @@ -1 +1 @@ -e8575b0936d24b1521baba9e7361b71b9fa89b155300507b943f527ce6610649 +4203ea5bcb2efa022b91460bcaf5ece7e6894a4670dcbd306f8dfc73685b11d7 diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 54f5082e0..35e89b831 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 = 2379; +pub const SEMANTICS_VERSION: u32 = 2380; /// 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/device/derive.rs b/crates/metal2vulkan/src/device/derive.rs index 57dd6e612..2b22c5588 100644 --- a/crates/metal2vulkan/src/device/derive.rs +++ b/crates/metal2vulkan/src/device/derive.rs @@ -261,7 +261,8 @@ fn derive_fields(desc: &DeviceDescription) -> ProfileFields { /// A stage is `pinnable` when subgroup size control is enabled and the stage is in /// `requiredSubgroupSizeStages`; its size range is then `[minSubgroupSize, maxSubgroupSize]`. /// Otherwise SPIR-V 1.5 modules run with the API-constant `subgroupSize`, which is the only size -/// the stage exposes. `full_subgroups` is compute-only (`computeFullSubgroups`). +/// the stage exposes. `full_subgroups` is for the stages that run in workgroups, the compute, task +/// and mesh stages, the three `computeFullSubgroups` lets require full subgroups. fn subgroup_model(desc: &DeviceDescription) -> SubgroupModel { let sg = &desc.subgroup; let control = desc.has(VkFeature::SubgroupSizeControl); @@ -288,13 +289,15 @@ fn subgroup_model(desc: &DeviceDescription) -> SubgroupModel { } }, pinnable, - full_subgroups: stage == Stage::Kernel && desc.has(VkFeature::ComputeFullSubgroups), + full_subgroups: stage.has_workgroup() && desc.has(VkFeature::ComputeFullSubgroups), } }; SubgroupModel { vertex: stage(Stage::Vertex), fragment: stage(Stage::Fragment), kernel: stage(Stage::Kernel), + object: stage(Stage::Object), + mesh: stage(Stage::Mesh), maximal_reconvergence: desc.has(VkFeature::ShaderMaximalReconvergence), uniform_control_flow: desc.has(VkFeature::ShaderSubgroupUniformControlFlow), quad_control: desc.has(VkFeature::ShaderQuadControl), @@ -603,10 +606,12 @@ fn enabled_caps(desc: &DeviceDescription) -> EnabledCaps { } /// The Metal stages and their Vulkan stages. -pub(crate) const STAGE_BITS: [(Stage, vk::ShaderStage); 3] = [ +pub(crate) const STAGE_BITS: [(Stage, vk::ShaderStage); 5] = [ (Stage::Vertex, vk::ShaderStage::VERTEX), (Stage::Fragment, vk::ShaderStage::FRAGMENT), (Stage::Kernel, vk::ShaderStage::COMPUTE), + (Stage::Object, vk::ShaderStage::TASK_EXT), + (Stage::Mesh, vk::ShaderStage::MESH_EXT), ]; /// The Vulkan stage of a Metal stage. diff --git a/crates/metal2vulkan/src/device/subgroup.rs b/crates/metal2vulkan/src/device/subgroup.rs index d67952c00..0b9134677 100644 --- a/crates/metal2vulkan/src/device/subgroup.rs +++ b/crates/metal2vulkan/src/device/subgroup.rs @@ -59,7 +59,8 @@ pub enum SimdClass { None, /// Only per-lane arithmetic on simd builtins (e.g. lane index). LaneArithmetic, - /// Quad operations. In compute and vertex this is tiered as `CrossLane(QUAD)`. + /// Quad operations. In the compute, object, mesh and vertex stages this is tiered as + /// `CrossLane(QUAD)`. Quad, /// Cross-lane operations of these classes. CrossLane(OpBits), @@ -112,17 +113,6 @@ pub struct StageSubgroup { pub full_subgroups: bool, } -/// The subgroup facts of a stage the profile does not record (an object or a mesh function): no -/// subgroup support. -static UNMODELED_STAGE: StageSubgroup = StageSubgroup { - supported: false, - ops: OpBits::NONE, - api_size: 0, - sizes: SubgroupSizes { min: 0, max: 0 }, - pinnable: false, - full_subgroups: false, -}; - /// The profile's subgroup model ([`DeviceProfile::subgroups`]). /// /// [`DeviceProfile::subgroups`]: crate::device::DeviceProfile::subgroups @@ -132,6 +122,10 @@ pub struct SubgroupModel { pub vertex: StageSubgroup, pub fragment: StageSubgroup, pub kernel: StageSubgroup, + /// Metal's object stage, Vulkan's task stage. + pub object: StageSubgroup, + /// Metal's mesh stage, Vulkan's mesh stage. + pub mesh: StageSubgroup, /// `shaderMaximalReconvergence`. pub maximal_reconvergence: bool, /// `shaderSubgroupUniformControlFlow`. @@ -209,18 +203,17 @@ impl SubgroupModel { Stage::Vertex => &self.vertex, Stage::Fragment => &self.fragment, Stage::Kernel => &self.kernel, - // The profile records no task or mesh stage's subgroup facts: an object or mesh - // function lowers as on a device without subgroups there. - Stage::Object | Stage::Mesh => &UNMODELED_STAGE, + Stage::Object => &self.object, + Stage::Mesh => &self.mesh, } } /// Whether a `stage` function can take Vulkan's quad instructions /// (`OpGroupNonUniformQuadBroadcast`, `OpGroupNonUniformQuadSwap`): the stage has subgroups /// of the quad class. Without them a constant lane's quad broadcast or shuffle-xor is a - /// shuffle, as it is outside kernels (`lower::simd`), so no module needs - /// `subgroupQuadOperationsInAllStages`, which Vulkan asks of quad instructions outside the - /// fragment and compute stages. + /// shuffle, as it is outside kernels (`lower::simd`), object and mesh functions included, so + /// no module needs `subgroupQuadOperationsInAllStages`, which Vulkan asks of quad + /// instructions outside the fragment and compute stages. pub fn quad_instructions(&self, stage: Stage) -> bool { let st = self.stage(stage); st.supported && st.ops.contains(OpBits::QUAD) @@ -229,7 +222,14 @@ impl SubgroupModel { /// The device's `[minSubgroupSize, maxSubgroupSize]`: the range of a stage that can pin a /// size (every such stage has that range), or the kernel's API size where none can. pub fn pinnable_sizes(&self) -> SubgroupSizes { - [&self.kernel, &self.fragment, &self.vertex] + let stages = [ + &self.kernel, + &self.fragment, + &self.vertex, + &self.object, + &self.mesh, + ]; + stages .into_iter() .find(|s| s.pinnable) .unwrap_or(&self.kernel) @@ -251,7 +251,8 @@ impl StageSubgroup { } /// The operation classes a usage class needs in a stage, and the refused feature if they are -/// missing. Compute and vertex quads are cross-lane quad operations over consecutive lanes. +/// missing. Compute, object, mesh and vertex quads are cross-lane quad operations over +/// consecutive lanes. /// /// Simdgroup matrices are lowered with shuffles over a 32-lane subgroup (`lower::simd`); the /// operation set they need is `BASIC | SHUFFLE` until that lowering names a larger one. @@ -274,14 +275,16 @@ fn needed_ops(class: &SimdClass) -> (OpBits, Feature) { /// - `None` needs nothing; compute `LaneArithmetic` derives lanes from the linear index (`Linear`). /// - Every other use needs the stage in `subgroupSupportedStages` and the class's operations /// (`Unsupported{SubgroupOperations | QuadOperations | SimdgroupMatrix}` otherwise). -/// - Compute (quads included) needs full subgroups and a 32-wide subgroup (`Direct`) or a -/// 64/128-wide one split into 32-lane clusters (`Cluster32`); else `Unsupported{SimdWidth}`. +/// - Compute, object and mesh functions (quads included) need full subgroups and a 32-wide +/// subgroup (`Direct`) or a 64/128-wide one split into 32-lane clusters (`Cluster32`); else +/// `Unsupported{SimdWidth}`. /// - Vertex and fragment: 32 → `Direct`; 64/128 → `Cluster32`; narrower → `PartialFragment` (the /// simdgroup is the whole subgroup, upper lanes permanently inactive, which Metal permits for a /// partially occupied simdgroup). Quads need `4 | S`. /// - Simdgroup matrices are `Direct` only. /// - A kernel that none of these admits is `Emulated`: its simdgroups need no subgroup feature, -/// only workgroup memory and barriers, which every compute stage has. Whether the function's +/// only workgroup memory and barriers, which every compute stage has. An object or mesh +/// function has no emulated tier. Whether the function's /// operations can be emulated exactly (every one in workgroup-uniform control flow) and whether /// the workgroup memory fits are the function's facts, which `select` checks. pub fn tier(class: &SimdClass, stage: Stage, model: &SubgroupModel) -> Result { @@ -328,9 +331,12 @@ fn subgroup_tier( (SimdClass::LaneArithmetic, Stage::Kernel | Stage::Object | Stage::Mesh) => { return Ok(Tier::Linear) } - // Metal compute and vertex quads are four consecutive linear threads, which Vulkan does - // not relate to subgroup lanes: tier them as cross-lane quad operations. - (SimdClass::Quad, Stage::Kernel | Stage::Vertex) => SimdClass::CrossLane(OpBits::QUAD), + // Metal compute, object, mesh and vertex quads are four consecutive linear threads, + // which Vulkan does not relate to subgroup lanes: tier them as cross-lane quad + // operations. + (SimdClass::Quad, Stage::Kernel | Stage::Object | Stage::Mesh | Stage::Vertex) => { + SimdClass::CrossLane(OpBits::QUAD) + } (c, _) => *c, }; let st = model.stage(stage); @@ -363,7 +369,7 @@ fn subgroup_tier( } let matrix = class == SimdClass::Matrix; let width = || Unsupported::needs_any_of(Feature::SimdWidth, vec![width_needs(stage, st)]); - if stage == Stage::Kernel { + if stage.has_workgroup() { if !st.full_subgroups { return Err(width()); } @@ -403,8 +409,8 @@ fn subgroup_tier( } /// What stage `stage` (facts `st`) lacks to run 32-lane subgroups (`Tier::Direct`): a required -/// subgroup size where the stage takes none, full subgroups for a kernel, and 32 within its -/// sizes. +/// subgroup size where the stage takes none, full subgroups for a kernel, object or mesh +/// function, and 32 within its sizes. pub fn width_needs(stage: Stage, st: &StageSubgroup) -> Vec { let mut needs = Vec::new(); if !st.pinnable { @@ -413,7 +419,7 @@ pub fn width_needs(stage: Stage, st: &StageSubgroup) -> Vec { stage, ))); } - if stage == Stage::Kernel && !st.full_subgroups { + if stage.has_workgroup() && !st.full_subgroups { needs.push(Capability::Feature(VkFeature::ComputeFullSubgroups)); } if st.sizes.max < 32 { @@ -433,9 +439,10 @@ pub fn width_needs(stage: Stage, st: &StageSubgroup) -> Vec { needs } -/// What a tier asks of the pipeline's subgroup configuration. Compute `Direct`/`Cluster32` need -/// full subgroups and a local size that is a multiple of the subgroup size; a size is pinned only -/// where the stage is pinnable (otherwise the API-constant size is the one `tier` accepted). +/// What a tier asks of the pipeline's subgroup configuration. `Direct`/`Cluster32` in the compute, +/// object and mesh stages need full subgroups and a local size that is a multiple of the subgroup +/// size; a size is pinned only where the stage is pinnable (otherwise the API-constant size is the +/// one `tier` accepted). pub fn requirement(t: Tier, stage: Stage, model: &SubgroupModel) -> SubgroupRequirement { let st = model.stage(stage); let size = match t { @@ -445,16 +452,17 @@ pub fn requirement(t: Tier, stage: Stage, model: &SubgroupModel) -> SubgroupRequ Tier::Direct => 32, Tier::Cluster32 => st.cluster_size().unwrap_or(st.api_size), }; - let compute = stage == Stage::Kernel; + let workgroup = stage.has_workgroup(); SubgroupRequirement { size: st.pinnable.then_some(size), - full_subgroups: compute, - local_size_multiple: if compute { size } else { 1 }, + full_subgroups: workgroup, + local_size_multiple: if workgroup { size } else { 1 }, varying: false, } } -/// Whether a kernel of class `class` whose every cross-lane operation stays inside its quad +/// Whether a kernel, object or mesh function of class `class` whose every cross-lane operation +/// stays inside its quad /// (`lower::simd::quad_only`) takes its quads from the subgroup at the size the device gives /// (`Tier::Direct` under [`quad_requirement`]): the 32 lanes are needed only by operations that /// read outside a quad, so the pin to 32 stays only where 32 is the stage's narrowest size. The @@ -462,7 +470,7 @@ pub fn requirement(t: Tier, stage: Stage, model: &SubgroupModel) -> SubgroupRequ /// every size it runs is a multiple of 4, so a quad is four aligned lanes of one subgroup (Vulkan /// 9.27.9). Read from the size range and the operation classes alone. pub fn quad_free(class: &SimdClass, stage: Stage, model: &SubgroupModel) -> bool { - if stage != Stage::Kernel { + if !stage.has_workgroup() { return false; } let class = match class { @@ -479,7 +487,7 @@ pub fn quad_free(class: &SimdClass, stage: Stage, model: &SubgroupModel) -> bool && st.sizes.min < 32 } -/// The subgroup requirement of a [`quad_free`] kernel: full subgroups, no pinned size, the size +/// The subgroup requirement of a [`quad_free`] function: full subgroups, no pinned size, the size /// varying where the stage can pin one (`subgroupSizeControl`), and a local size that is a /// multiple of the largest size the stage may run, the only one that guarantees full subgroups of /// a size the device picks (`VUID-VkPipelineShaderStageCreateInfo-flags-02758`); without diff --git a/crates/metal2vulkan/src/device/tests/subgroup.rs b/crates/metal2vulkan/src/device/tests/subgroup.rs index b3fe76017..4abbcd71f 100644 --- a/crates/metal2vulkan/src/device/tests/subgroup.rs +++ b/crates/metal2vulkan/src/device/tests/subgroup.rs @@ -11,7 +11,13 @@ use crate::error::{Capability, Feature}; use crate::metal::{ArgumentBuffersTier, ReadWriteTextureTier}; use crate::pipeline::sym::Stage; -const STAGES: [Stage; 3] = [Stage::Vertex, Stage::Fragment, Stage::Kernel]; +const STAGES: [Stage; 5] = [ + Stage::Vertex, + Stage::Fragment, + Stage::Kernel, + Stage::Object, + Stage::Mesh, +]; fn classes() -> Vec<(&'static str, SimdClass)> { vec![ @@ -44,25 +50,25 @@ fn short(t: &Result) -> String { } /// The tier of every (class, stage) on every committed profile. Rows: profile; cells per stage -/// `vertex|fragment|kernel`, classes in `classes()` order. `D` Direct, `C` Cluster32, `P` -/// PartialFragment, `L` Linear, `E` Emulated, `-` no subgroup; `xW` width refusal, `xO`/`xQ`/`xM` -/// missing operations (subgroup ops, quads, matrix ops). +/// `vertex|fragment|kernel|object|mesh`, classes in `classes()` order. `D` Direct, `C` +/// Cluster32, `P` PartialFragment, `L` Linear, `E` Emulated, `-` no subgroup; `xW` width refusal, +/// `xO`/`xQ`/`xM` missing operations (subgroup ops, quads, matrix ops). const GOLDEN: &str = "\ -amd-780m-hawkpoint-radv: -,C,C,C,C,C,xW | -,D,D,D,D,D,D | -,L,D,D,D,D,D -amd-780m-radv: -,C,C,C,C,C,xW | -,D,D,D,D,D,D | -,L,D,D,D,D,D -amd-rdna2-apu-radv: -,C,C,C,C,C,xW | -,D,D,D,D,D,D | -,L,D,D,D,D,D -gate-lavapipe: -,xO,xO,xO,xO,xO,xM | -,P,P,P,P,P,xW | -,L,E,E,E,E,E -gate-lavapipe-x86_64: -,xO,xO,xO,xO,xO,xM | -,P,P,P,P,P,xW | -,L,E,E,E,E,E -intel-arl-anv: -,D,D,D,D,D,D | -,D,D,D,D,D,D | -,L,D,D,D,D,D -intel-irisxe-anv: -,D,D,D,D,D,D | -,D,D,D,D,D,D | -,L,D,D,D,D,D -intel-irisxe-rplp-anv: -,D,D,D,D,D,D | -,D,D,D,D,D,D | -,L,D,D,D,D,D -intel-uhd770-rpls-anv: -,D,D,D,D,D,D | -,D,D,D,D,D,D | -,L,D,D,D,D,D -lavapipe: -,xO,xO,xO,xO,xO,xM | -,P,P,P,P,P,xW | -,L,E,E,E,E,E -moltenvk-m3: -,xO,xO,xO,xO,xO,xM | -,D,D,D,D,D,D | -,L,D,D,D,D,D -nvidia-pascal-linux: -,D,D,D,D,D,D | -,D,D,D,D,D,D | -,L,D,D,D,D,D -nvidia-rtx50-linux: -,D,D,D,D,D,D | -,D,D,D,D,D,D | -,L,D,D,D,D,D -nvidia-rtx5080-laptop: -,D,D,D,D,D,D | -,D,D,D,D,D,D | -,L,D,D,D,D,D -runtime-floor: -,xO,xO,xO,xO,xO,xM | -,xO,xQ,xO,xO,xO,xM | -,L,E,E,E,E,E +amd-780m-hawkpoint-radv: -,C,C,C,C,C,xW | -,D,D,D,D,D,D | -,L,D,D,D,D,D | -,L,D,D,D,D,D | -,L,D,D,D,D,D +amd-780m-radv: -,C,C,C,C,C,xW | -,D,D,D,D,D,D | -,L,D,D,D,D,D | -,L,D,D,D,D,D | -,L,D,D,D,D,D +amd-rdna2-apu-radv: -,C,C,C,C,C,xW | -,D,D,D,D,D,D | -,L,D,D,D,D,D | -,L,D,D,D,D,D | -,L,D,D,D,D,D +gate-lavapipe: -,xO,xO,xO,xO,xO,xM | -,P,P,P,P,P,xW | -,L,E,E,E,E,E | -,L,xW,xW,xW,xW,xW | -,L,xW,xW,xW,xW,xW +gate-lavapipe-x86_64: -,xO,xO,xO,xO,xO,xM | -,P,P,P,P,P,xW | -,L,E,E,E,E,E | -,L,xW,xW,xW,xW,xW | -,L,xW,xW,xW,xW,xW +intel-arl-anv: -,D,D,D,D,D,D | -,D,D,D,D,D,D | -,L,D,D,D,D,D | -,L,D,D,D,D,D | -,L,D,D,D,D,D +intel-irisxe-anv: -,D,D,D,D,D,D | -,D,D,D,D,D,D | -,L,D,D,D,D,D | -,L,xO,xO,xO,xO,xM | -,L,xO,xO,xO,xO,xM +intel-irisxe-rplp-anv: -,D,D,D,D,D,D | -,D,D,D,D,D,D | -,L,D,D,D,D,D | -,L,xO,xO,xO,xO,xM | -,L,xO,xO,xO,xO,xM +intel-uhd770-rpls-anv: -,D,D,D,D,D,D | -,D,D,D,D,D,D | -,L,D,D,D,D,D | -,L,xO,xO,xO,xO,xM | -,L,xO,xO,xO,xO,xM +lavapipe: -,xO,xO,xO,xO,xO,xM | -,P,P,P,P,P,xW | -,L,E,E,E,E,E | -,L,xW,xW,xW,xW,xW | -,L,xW,xW,xW,xW,xW +moltenvk-m3: -,xO,xO,xO,xO,xO,xM | -,D,D,D,D,D,D | -,L,D,D,D,D,D | -,L,xO,xO,xO,xO,xM | -,L,xO,xO,xO,xO,xM +nvidia-pascal-linux: -,D,D,D,D,D,D | -,D,D,D,D,D,D | -,L,D,D,D,D,D | -,L,xO,xO,xO,xO,xM | -,L,xO,xO,xO,xO,xM +nvidia-rtx50-linux: -,D,D,D,D,D,D | -,D,D,D,D,D,D | -,L,D,D,D,D,D | -,L,D,D,D,D,D | -,L,D,D,D,D,D +nvidia-rtx5080-laptop: -,D,D,D,D,D,D | -,D,D,D,D,D,D | -,L,D,D,D,D,D | -,L,D,D,D,D,D | -,L,D,D,D,D,D +runtime-floor: -,xO,xO,xO,xO,xO,xM | -,xO,xQ,xO,xO,xO,xM | -,L,E,E,E,E,E | -,L,xO,xO,xO,xO,xM | -,L,xO,xO,xO,xO,xM "; fn table() -> String { @@ -104,8 +110,8 @@ fn tier_invariants_on_every_profile() { if t == Ok(Tier::Cluster32) { assert!(st.sizes.min >= 32, "{stem} {stage:?} {name}"); } - // Compute quads are tiered as cross-lane quad operations. - if class == SimdClass::Quad && stage == Stage::Kernel { + // Compute, object and mesh quads are tiered as cross-lane quad operations. + if class == SimdClass::Quad && stage.has_workgroup() { assert_eq!( t, tier(&SimdClass::CrossLane(OpBits::QUAD), stage, model), @@ -131,10 +137,11 @@ fn tier_invariants_on_every_profile() { if stage == Stage::Kernel && class != SimdClass::None { assert!(t.is_ok(), "{stem} {name}: every kernel class has a tier"); } - // Compute Direct/Cluster32 always require full subgroups and a multiple. + // Compute, object and mesh Direct/Cluster32 always require full subgroups and a + // multiple. if let Ok(t @ (Tier::Direct | Tier::Cluster32)) = t { let r = requirement(t, stage, model); - if stage == Stage::Kernel { + if stage.has_workgroup() { assert!(r.full_subgroups); assert!(r.local_size_multiple >= 32); assert!(st.fits(r.local_size_multiple), "{stem}"); @@ -157,6 +164,14 @@ fn model(stage: StageSubgroup) -> SubgroupModel { full_subgroups: true, ..stage }, + object: StageSubgroup { + full_subgroups: true, + ..stage + }, + mesh: StageSubgroup { + full_subgroups: true, + ..stage + }, maximal_reconvergence: false, uniform_control_flow: false, quad_control: false, @@ -345,6 +360,18 @@ fn narrow_subgroups_partial_in_graphics_emulated_in_compute() { tier(&SimdClass::LaneArithmetic, Stage::Kernel, &m), Ok(Tier::Linear) ); + // An object or mesh function has no emulated tier: its simdgroups need a subgroup of 32, or + // of 64 or 128 split into 32-lane clusters. + for stage in [Stage::Object, Stage::Mesh] { + assert_eq!( + tier(&vote, stage, &m).unwrap_err().feature, + Feature::SimdWidth + ); + assert_eq!( + tier(&SimdClass::LaneArithmetic, stage, &m), + Ok(Tier::Linear) + ); + } // Quads need 4 | S. let m = model(fixed(2)); assert_eq!( @@ -359,7 +386,8 @@ fn narrow_subgroups_partial_in_graphics_emulated_in_compute() { /// kernel stage runs full subgroups of the class's operations and its narrowest size is below 32, /// read from the size range alone: 8 to 32 takes it; 32 to 32 and 32 to 64 keep today's pin to 32; /// a narrowest size below 4 is excluded by the guard, since a quad is four lanes of one subgroup. -/// No other stage takes it. A stage that pins no size runs the API's alone, with no varying flag. +/// Object and mesh functions take it as kernels do, from their own stage's facts; no render stage +/// takes it. A stage that pins no size runs the API's alone, with no varying flag. #[test] fn a_quad_only_kernel_reads_the_size_range_alone() { let quad = SimdClass::CrossLane(OpBits::QUAD); @@ -384,6 +412,14 @@ fn a_quad_only_kernel_reads_the_size_range_alone() { for stage in [Stage::Vertex, Stage::Fragment] { assert!(!quad_free(&quad, stage, &m), "{stage:?}"); } + for stage in [Stage::Object, Stage::Mesh] { + assert!(quad_free(&quad, stage, &m), "{stage:?}"); + assert_eq!( + quad_requirement(stage, &m), + quad_requirement(Stage::Kernel, &m), + "{stage:?}" + ); + } for (min, max) in [(4, 4), (8, 8), (16, 64)] { assert!( quad_free(&quad, Stage::Kernel, &range(min, max)), @@ -471,6 +507,86 @@ fn quad_free_on_the_committed_profiles() { ); } +/// The object and mesh stages read Vulkan's task and mesh stages' own facts, each apart from the +/// other and from the compute stage's: `subgroupSupportedStages`, `requiredSubgroupSizeStages` +/// (with `subgroupSizeControl`) and `computeFullSubgroups`, which Vulkan gives the compute, task +/// and mesh stages alone. On the 780M's description, a mesh stage that pins no size runs its API +/// size of 64 as two 32-lane clusters while the task stage pins 32; without full subgroups +/// neither runs a simdgroup on its subgroups; without the task stage listed, an object function +/// is refused naming it while a mesh function keeps its tier. +#[test] +fn object_and_mesh_stages_read_their_own_subgroup_facts() { + use crate::device::requirements::VkFeature; + use crate::error::Needs; + use crate::vk::{ShaderStage, ShaderStageFlags}; + let without = |flags: ShaderStageFlags, bit: ShaderStage| { + ShaderStageFlags::from_raw(flags.as_raw() & !bit.flags().as_raw()) + }; + let shuffle = SimdClass::CrossLane(OpBits::SHUFFLE); + let desc = profile("amd-780m-radv"); + let dev = Device::from_queries(desc.clone()).expect("device"); + let m = &dev.profile().fields().subgroup; + for stage in [Stage::Object, Stage::Mesh] { + assert_eq!(tier(&shuffle, stage, m), Ok(Tier::Direct), "{stage:?}"); + assert_eq!( + requirement(Tier::Direct, stage, m), + SubgroupRequirement { + size: Some(32), + full_subgroups: true, + local_size_multiple: 32, + varying: false, + }, + "{stage:?}" + ); + } + + let mut d = desc.clone(); + d.subgroup.required_size_stages = + without(d.subgroup.required_size_stages, ShaderStage::MESH_EXT); + let dev = Device::from_queries(d).expect("device"); + let m = &dev.profile().fields().subgroup; + assert_eq!(tier(&shuffle, Stage::Object, m), Ok(Tier::Direct)); + assert_eq!(tier(&shuffle, Stage::Mesh, m), Ok(Tier::Cluster32)); + assert_eq!( + requirement(Tier::Cluster32, Stage::Mesh, m), + SubgroupRequirement { + size: None, + full_subgroups: true, + local_size_multiple: 64, + varying: false, + } + ); + + let mut d = desc.clone(); + d.features.remove(&VkFeature::ComputeFullSubgroups); + let dev = Device::from_queries(d).expect("device"); + let m = &dev.profile().fields().subgroup; + for stage in [Stage::Object, Stage::Mesh] { + let err = tier(&shuffle, stage, m).unwrap_err(); + assert_eq!(err.feature, Feature::SimdWidth, "{stage:?}"); + assert_eq!( + err.needs, + Needs::AnyOf(vec![vec![Capability::Feature( + VkFeature::ComputeFullSubgroups + )]]), + "{stage:?}" + ); + } + + let mut d = desc; + d.subgroup.supported_stages = without(d.subgroup.supported_stages, ShaderStage::TASK_EXT); + let dev = Device::from_queries(d).expect("device"); + let m = &dev.profile().fields().subgroup; + assert!(!m.object.supported && m.mesh.supported); + assert_eq!( + tier(&shuffle, Stage::Object, m).unwrap_err().needs, + Needs::AnyOf(vec![vec![Capability::Property(VkProperty::SubgroupStage( + Stage::Object + ))]]) + ); + assert_eq!(tier(&shuffle, Stage::Mesh, m), Ok(Tier::Direct)); +} + #[test] fn missing_stage_or_operations_are_named() { let mut st = fixed(32); diff --git a/docs/API.md b/docs/API.md index 773278287..fe768b224 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1179,12 +1179,21 @@ an object function (a mesh draw's pieces take the two draw features). A device w them (MoltenVK, older ANV) refuses the pipeline and each of its object and mesh functions (`Unsupported{MeshShading}`, naming what it lacks). -An object or mesh function that calls a SIMD-group, quad-group or SIMD-group matrix function is -refused on every device (`Unsupported{SubgroupOperations}`, `QuadOperations` or `SimdgroupMatrix`, -naming the stage's `VkProperty::SubgroupStage`), a device that lists the task and mesh stages in -`subgroupSupportedStages` included: the translator models no subgroup facts for those stages. Metal -gives both stages `[[thread_index_in_simdgroup]]`, which compiles, the lane derived from the linear -thread index as a kernel's is. +An object or mesh function's SIMD groups run on its stage's own subgroups, as a kernel's run on +the compute stage's, read from Vulkan's task and mesh stage facts: the stage in +`subgroupSupportedStages` with the operations' classes, full subgroups (`computeFullSubgroups`, +which Vulkan gives the compute, task and mesh stages), and either 32 lanes pinned (the stage in +`requiredSubgroupSizeStages` under `subgroupSizeControl`) or 64 or 128 lanes split into 32-lane +clusters. Its workgroup, the pipeline's stated maximum, is then made a multiple of that size, +rounded up (`RuntimeFact::LocalSizeConstraint`): the invocations past a draw's threadgroup are +not live, so a partial SIMD group has Metal's inactive lanes. A function whose only cross-lane operations stay inside their +quads runs at the size the stage gives, as such a kernel does. Where the stage pins no size and +runs subgroups below 32 lanes (lavapipe), a SIMD-group function is refused +(`Unsupported{SimdWidth}`, naming `subgroupSizeControl`, the stage's +`VkProperty::RequiredSubgroupSizeStage` and its `maxSubgroupSize`): object and mesh functions have +no emulated tier. A quad operation in either stage is a shuffle, never a quad instruction, so +neither stage needs `subgroupQuadOperationsInAllStages`. A SIMD-group matrix function in either +stage is refused as not implemented (`Unsupported{SimdgroupMatrix}`), as outside kernels. The mesh lowering is only compiled and validated: no mesh draw it makes has been compared with Metal on a GPU, and the runtime makes no mesh pipeline (its README's known gaps of render pipeline