diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 8f3c741ce..760780bb0 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -4726,8 +4726,12 @@ cache is answered compile-required on both. refused (`Gap::PartialThreadgroups`) at a threadgroup that is not whole subgroups of a kernel that runs only whole subgroups where the translator refuses its partial-threadgroups variant on emulated SIMD groups (site `SimdGroups`), and for a kernel that observes its threadgroup - partition and whose partial-threadgroups variant the translator refuses. It refuses the - variant of a kernel whose barriers in a + partition and whose partial-threadgroups variant the translator refuses, the site naming why: + the vote word below (`VoteWord`), a structure of the kernel's the variant does not take + (`Structure`, its `PartialThreadgroupsCause`: compute derivatives, an imageblock slice write + every invocation shares, a tile function), or another refusal of the variant's (`Translator`). + The cache directory keeps the site with the refusal. It refuses the variant of a kernel whose + barriers in a loop need a vote word that does not fit beside its threadgroup memory in `maxComputeSharedMemorySize`, which `Device::max_threadgroup_memory_length` leaves room for: a kernel that takes more threadgroup memory than that answer, as one built for a Mac's 32,768 diff --git a/crates/metal2vulkan-runtime/src/cache.rs b/crates/metal2vulkan-runtime/src/cache.rs index 53cba9e16..15e3d7d8b 100644 --- a/crates/metal2vulkan-runtime/src/cache.rs +++ b/crates/metal2vulkan-runtime/src/cache.rs @@ -59,7 +59,8 @@ //! function's AIR, entry, constants and linked functions, its lowering inputs, the device //! profile's fingerprint and the translator's semantics version. The bytes are the translator's //! self-checking encoding (`CompiledFunction::to_bytes`), and bytes that do not decode for the key -//! are a miss. A partial-threadgroups variant the translator refused is kept too, as a marker, and +//! are a miss. A partial-threadgroups variant the translator refused is kept too, as a marker of +//! why (the vote word, the structure the refusal names, or another refusal), and //! so is the translator's answer that a kernel observes its threadgroup partition, under its //! variant's key, until that variant's lowering replaces it. //! @@ -137,6 +138,7 @@ use crate::pipeline::VariantRefusal; use crate::times::host_time; use ash::vk; use metal2vulkan::cache::{Hash256, ARTIFACT_FORMAT_VERSION, SEMANTICS_VERSION}; +use metal2vulkan::error::PartialThreadgroupsCause; use std::collections::VecDeque; use std::fs::{self, File}; use std::io::{self, ErrorKind, Read, Write}; @@ -181,20 +183,46 @@ pub(crate) const BLOBS_KEPT: usize = 4; /// waits, so the heaviest kernels, the costliest to lower again, are kept too. pub(crate) const PENDING_BYTES: u64 = 8 << 20; /// What a translation file holds where the translator refused the lowering, but for the vote word -/// ([`REFUSED_VOTE`]): bytes no lowering encodes to, and that a file cut short is not. +/// ([`REFUSED_VOTE`]) or a structure of the kernel's ([`REFUSALS`]): bytes no lowering encodes +/// to, and that a file cut short is not. const REFUSED: &[u8] = b"m2v-refused"; +/// Each refusal of a partial-threadgroups variant the cache directory keeps +/// ([`VariantRefusal`]), with the marker its translation file holds: the vote word's +/// ([`REFUSED_VOTE`]), one for each structure of the kernel's the translator names, and any +/// other refusal's ([`REFUSED`]). The markers are bytes no lowering encodes to, no two alike nor +/// [`OBSERVES`], and none a file cut short. +pub(crate) const REFUSALS: [(VariantRefusal, &[u8]); 6] = [ + (VariantRefusal::VoteWord, REFUSED_VOTE), + ( + VariantRefusal::Structure(PartialThreadgroupsCause::ComputeDerivatives), + b"m2v-refused-derivatives", + ), + ( + VariantRefusal::Structure(PartialThreadgroupsCause::OtherForm), + b"m2v-refused-form", + ), + ( + VariantRefusal::Structure(PartialThreadgroupsCause::SharedSliceWrite), + b"m2v-refused-slice", + ), + ( + VariantRefusal::Structure(PartialThreadgroupsCause::TileFunction), + b"m2v-refused-tile", + ), + (VariantRefusal::Translator, REFUSED), +]; /// What a partial-threadgroups variant's translation file holds where the translator refused it /// for its predicated walk's vote word ([`VariantRefusal::VoteWord`]): bytes no lowering encodes /// to, nor [`REFUSED`] or [`OBSERVES`], and that a file cut short is not. pub(crate) const REFUSED_VOTE: &[u8] = b"m2v-refused-vote"; /// What a partial-threadgroups variant's translation file holds where the translator answered /// that the kernel observes its threadgroup partition, until the variant is lowered over it: -/// bytes no lowering encodes to, nor [`REFUSED`] or [`REFUSED_VOTE`], and that a file cut short is +/// bytes no lowering encodes to, nor another marker, and that a file cut short is /// not. The file is named by the variant's `FunctionCompileKey`, which covers everything that changes the answer: /// the kernel's AIR, entry, constants and linked functions, its lowering inputs, the device /// profile's fingerprint and the translator's semantics version, which a change to the answer /// bumps. It is 12 bytes, written and counted as a lowering is, within the store's cap. -const OBSERVES: &[u8] = b"m2v-observes"; +pub(crate) const OBSERVES: &[u8] = b"m2v-observes"; /// The translations' directory, under a generation. const TRANSLATIONS: &str = "translations"; /// The render contents' records' directory, under a generation. @@ -1143,11 +1171,13 @@ fn keep(core: &Core, file: String, bytes: Vec) { /// Hands the translator's refusal of the lowering of key digest `key`, and `why`, to the reaper, /// as [`keep_translation`] does a lowering. pub(crate) fn keep_refusal(core: &Core, key: &[u8], why: VariantRefusal) { - let marker = match why { - VariantRefusal::VoteWord => REFUSED_VOTE, - VariantRefusal::Translator => REFUSED, - }; - keep_translation(core, key, marker.to_vec()); + keep_translation(core, key, refusal_marker(why).to_vec()); +} + +/// The marker [`REFUSALS`] keeps for `why`; [`REFUSED`] for a structure it holds none of. +pub(crate) fn refusal_marker(why: VariantRefusal) -> &'static [u8] { + let kept = REFUSALS.iter().find(|&&(refusal, _)| refusal == why); + kept.map_or(REFUSED, |&(_, marker)| marker) } /// Hands the translator's answer that a kernel observes its threadgroup partition to the reaper, @@ -1502,8 +1532,10 @@ impl Caches { decode: impl FnOnce(&[u8]) -> Option, ) -> Option { let file = Caches::translation_file(key); + let refusal = |bytes: &[u8]| REFUSALS.iter().any(|&(_, marker)| marker == bytes); let kept = self.store.as_ref()?.get(&file, |bytes| match bytes { - REFUSED | REFUSED_VOTE | OBSERVES => Some(None), + OBSERVES => Some(None), + marker if refusal(marker) => Some(None), lowering => decode(lowering).map(Some), }); kept.flatten() @@ -1537,12 +1569,10 @@ impl Caches { pub(crate) fn refused(&self, key: &[u8]) -> Option { let store = self.store.as_ref()?; let file = Caches::translation_file(key); - if store.holds(&file, REFUSED_VOTE) { - return Some(VariantRefusal::VoteWord); - } - store - .holds(&file, REFUSED) - .then_some(VariantRefusal::Translator) + REFUSALS + .iter() + .find(|&&(_, marker)| store.holds(&file, marker)) + .map(|&(why, _)| why) } /// Whether the translator answered on a device before that the kernel whose diff --git a/crates/metal2vulkan-runtime/src/encoder.rs b/crates/metal2vulkan-runtime/src/encoder.rs index 44d08e701..a2e401857 100644 --- a/crates/metal2vulkan-runtime/src/encoder.rs +++ b/crates/metal2vulkan-runtime/src/encoder.rs @@ -1656,6 +1656,7 @@ pub(crate) fn decide<'a>( static_length: compiled.static_length(), max, }, + VariantRefusal::Structure(cause) => PartialThreadgroupsSite::Structure { cause }, VariantRefusal::Translator => PartialThreadgroupsSite::Translator, }) }; diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index 7c43d4510..bb50fe88f 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -100,6 +100,11 @@ pub enum Error { /// `docs/REFUSALS.md` lists. pub use metal2vulkan::error::RefusalBasis; +/// The structure of a kernel's that the translator's partial-threadgroups variant does not take +/// ([`PartialThreadgroupsSite::Structure`]): the translator's type. Metal has no counterpart: +/// Metal runs every partial threadgroup. +pub use metal2vulkan::error::PartialThreadgroupsCause; + /// A call Metal refuses, with what it was asked. #[non_exhaustive] #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -2318,9 +2323,14 @@ pub enum PartialThreadgroupsSite { /// held against. max: u32, }, - /// The translator refused the variant for another of the kernel's structures: compute - /// derivatives, an imageblock slice write every invocation shares, or another refusal of the - /// variant's lowering or compile. + /// The translator refused the variant for a structure of the kernel's that it names: compute + /// derivatives, an imageblock slice write every invocation shares, or a tile function. + Structure { + /// The structure. + cause: PartialThreadgroupsCause, + }, + /// The translator refused the variant with a refusal that names no structure of the + /// kernel's: another refusal of the variant's lowering or compile. Translator, /// The threadgroup is not whole SIMD groups of the variant, whose tier runs only whole ones, /// and the translator refused the variant on emulated SIMD groups that runs such a diff --git a/crates/metal2vulkan-runtime/src/lib.rs b/crates/metal2vulkan-runtime/src/lib.rs index ff5f35d28..501d00947 100644 --- a/crates/metal2vulkan-runtime/src/lib.rs +++ b/crates/metal2vulkan-runtime/src/lib.rs @@ -89,9 +89,9 @@ pub use device::{Device, DeviceOptions, RawDevice}; pub use encoder::{ComputeCommandEncoder, Dispatch, DispatchType, Resource, ResourceUsage}; pub use error::{ DrawInputCause, DrawKind, Error, Gap, IndirectCommandsKind, KernelInputKind, Limit, - PartialThreadgroupsSite, Refusal, RefusalBasis, RenderPassKind, RenderPipelineKind, - SamplePositionsKind, StageGap, StageInKind, StorageElementCase, TextureBacking, - TextureBytesCause, TextureViewKind, + PartialThreadgroupsCause, PartialThreadgroupsSite, Refusal, RefusalBasis, RenderPassKind, + RenderPipelineKind, SamplePositionsKind, StageGap, StageInKind, StorageElementCase, + TextureBacking, TextureBytesCause, TextureViewKind, }; pub use event::{Event, SharedEvent}; pub use export::{Export, ExportHandle}; diff --git a/crates/metal2vulkan-runtime/src/pipeline.rs b/crates/metal2vulkan-runtime/src/pipeline.rs index 66878f469..323631459 100644 --- a/crates/metal2vulkan-runtime/src/pipeline.rs +++ b/crates/metal2vulkan-runtime/src/pipeline.rs @@ -75,8 +75,10 @@ use crate::stage::{Create, Heavy}; use crate::times::host_time; use ash::vk; use metal2vulkan::cache::Hash256; -use metal2vulkan::device::{VkLimit, KERNEL_BUFFER_BINDINGS}; -use metal2vulkan::error::{Capability, Error as TranslationError, Feature, Needs, Unsupported}; +use metal2vulkan::device::KERNEL_BUFFER_BINDINGS; +use metal2vulkan::error::{ + Cause, Error as TranslationError, Feature, PartialThreadgroupsCause, Unsupported, +}; use metal2vulkan::library::{CompiledFunction, FunctionCompileKey}; use metal2vulkan::metal::{BindingAccess, BindingType, TextureType, TextureUsage}; use metal2vulkan::pipeline::{ @@ -442,7 +444,7 @@ pub(crate) enum Lowered { /// The module, and the translator's notes of it. Made(Box, Vec), /// The translator refused the variant (`Unsupported`), now or on a device on the cache - /// directory before (which keeps that it refused, and whether for the vote word): the need's + /// directory before (which keeps that it refused, and why: `VariantRefusal`): the need's /// own refusal, the variant's gap. Refused(VariantRefusal), /// The translator's lowering or compile of the variant failed otherwise, a translator bug or @@ -459,30 +461,26 @@ pub(crate) enum Lowered { #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub(crate) enum VariantRefusal { /// Its predicated walk's vote word does not fit beside the kernel's threadgroup memory: - /// `Unsupported{PartialThreadgroups}` needing the `Limit` of `maxComputeSharedMemorySize`. + /// `Unsupported{PartialThreadgroups}` of cause `VoteWord`, needing the `Limit` of + /// `maxComputeSharedMemorySize`. VoteWord, + /// A structure of the kernel's the variant does not take: `Unsupported{PartialThreadgroups}` + /// of another cause. + Structure(PartialThreadgroupsCause), /// Any other refusal of its lowering or compile. Translator, } impl VariantRefusal { - /// Why the translator's refusal `refused` refused the variant. + /// Why the translator's refusal `refused` refused the variant: the partial-threadgroups + /// cause it names, if any. pub(crate) fn of(refused: &Unsupported) -> VariantRefusal { - let shared_memory = |capability: &Capability| { - matches!( - capability, - Capability::Limit { - limit: VkLimit::MaxComputeSharedMemorySize, - .. - } - ) - }; - let vote = refused.feature == Feature::PartialThreadgroups - && matches!(&refused.needs, Needs::AnyOf(alternatives) - if alternatives.iter().flatten().any(shared_memory)); - match vote { - true => VariantRefusal::VoteWord, - false => VariantRefusal::Translator, + match refused.cause { + Some(Cause::PartialThreadgroups(PartialThreadgroupsCause::VoteWord)) => { + VariantRefusal::VoteWord + } + Some(Cause::PartialThreadgroups(cause)) => VariantRefusal::Structure(cause), + _ => VariantRefusal::Translator, } } } diff --git a/crates/metal2vulkan-runtime/src/tests/lowered.rs b/crates/metal2vulkan-runtime/src/tests/lowered.rs index 6cdd1008e..28d9abb7a 100644 --- a/crates/metal2vulkan-runtime/src/tests/lowered.rs +++ b/crates/metal2vulkan-runtime/src/tests/lowered.rs @@ -60,3 +60,46 @@ fn a_lowering_error_is_not_reported_as_the_variant_s_gap() { reported(&Lowered::Refused(VariantRefusal::Translator)) ); } + +/// The translator's refusal of the partial-threadgroups variant keeps its cause +/// (`VariantRefusal::of`): the vote word, each structure of the kernel's the translator names +/// (`PartialThreadgroupsCause`), and any other refusal, which names none. The cache directory +/// keeps each under a marker of its own (`cache::REFUSALS`), no two alike and none the observer's +/// answer, so a refusal read back from it names the same cause. +#[test] +fn a_variant_refusal_keeps_the_translator_s_cause() { + use crate::cache::{refusal_marker, OBSERVES, REFUSALS}; + use metal2vulkan::error::{Cause, Feature, PartialThreadgroupsCause, Unsupported}; + use std::collections::BTreeSet; + let of = |cause: Option| { + let mut refused = Unsupported::not_implemented(Feature::PartialThreadgroups); + refused.cause = cause; + VariantRefusal::of(&refused) + }; + let vote = Cause::PartialThreadgroups(PartialThreadgroupsCause::VoteWord); + assert_eq!(of(Some(vote)), VariantRefusal::VoteWord); + assert_eq!(of(None), VariantRefusal::Translator); + let structures = [ + PartialThreadgroupsCause::ComputeDerivatives, + PartialThreadgroupsCause::OtherForm, + PartialThreadgroupsCause::SharedSliceWrite, + PartialThreadgroupsCause::TileFunction, + ]; + let mut kept = vec![VariantRefusal::VoteWord, VariantRefusal::Translator]; + for cause in structures { + let why = of(Some(Cause::PartialThreadgroups(cause))); + assert_eq!(why, VariantRefusal::Structure(cause)); + kept.push(why); + } + for why in kept { + let marker = refusal_marker(why); + let back: Vec = (REFUSALS.iter()) + .filter(|&&(_, m)| m == marker) + .map(|&(w, _)| w) + .collect(); + assert_eq!(back, [why], "{why:?}"); + } + let markers: BTreeSet<&[u8]> = REFUSALS.iter().map(|&(_, marker)| marker).collect(); + assert_eq!(markers.len(), REFUSALS.len()); + assert!(!markers.contains(OBSERVES)); +} diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index c64102c00..0bcf70c76 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 = 2361; +pub const SEMANTICS_VERSION: u32 = 2362; /// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the /// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another @@ -93,7 +93,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 608; /// changes no behaviour, and then updates that hash alone with the commit saying why, or changes /// behaviour and also bumps this version. The commit that bumps it says what changed; this comment /// keeps no history. -pub const RUNTIME_VERSION: u32 = 2566; +pub const RUNTIME_VERSION: u32 = 2567; /// Writes a digest as lowercase hex. pub(crate) fn write_hex(f: &mut fmt::Formatter<'_>, name: &str, hash: &Hash256) -> fmt::Result { diff --git a/crates/metal2vulkan/src/error/mod.rs b/crates/metal2vulkan/src/error/mod.rs index 4d0577cb1..54c0d5fcc 100644 --- a/crates/metal2vulkan/src/error/mod.rs +++ b/crates/metal2vulkan/src/error/mod.rs @@ -453,6 +453,15 @@ impl Unsupported { ..Unsupported::not_implemented(Feature::IdentityDomains) } } + + /// The partial-threadgroups variant's refusal of the structure `cause` names + /// (`Feature::PartialThreadgroups`, not implemented). + pub(crate) fn partial_threadgroups(cause: PartialThreadgroupsCause) -> Unsupported { + Unsupported { + cause: Some(Cause::PartialThreadgroups(cause)), + ..Unsupported::not_implemented(Feature::PartialThreadgroups) + } + } } impl fmt::Display for Unsupported { @@ -596,13 +605,11 @@ pub enum Feature { axis: Option, }, /// A kernel's partial-threadgroups variant (`LoweringInputs::partial_threadgroups`) that the - /// lowering cannot make: a tile function, a kernel that reads a stage-input region, one with - /// compute derivatives or a cooperative imageblock slice write; a kernel whose simdgroups run - /// on the emulated tier (its profile's subgroups, its lockstep order or its large body's - /// pinned width give it that tier), whose exchanges are not walked past the grid; a body whose + /// lowering cannot make, its cause named (`PartialThreadgroupsCause`): a tile function, one + /// with compute derivatives or an imageblock slice write every invocation shares, a body whose /// uniform barriers need a vote word that the stage's workgroup memory cannot hold beside its - /// static arena; or the input beside `flat_grid`, `folded_groups`, `replay_bindings` or - /// `emulated_simdgroups`. The kernel's dispatches keep the plain module's exact split. + /// static arena, or the input beside `flat_grid`, `folded_groups` or `replay_bindings`. The + /// kernel's dispatches keep the plain module's exact split. PartialThreadgroups, /// An irreducible region containing a convergent instruction. IrreducibleConvergent, @@ -1057,6 +1064,8 @@ pub enum Cause { /// The identity domains' refusal of a form they do not lower (`Feature::IdentityDomains`, /// [`Needs::NotImplemented`]). Identity(IdentityCause), + /// A kernel's partial-threadgroups variant's refusal (`Feature::PartialThreadgroups`). + PartialThreadgroups(PartialThreadgroupsCause), } impl fmt::Display for Cause { @@ -1066,6 +1075,7 @@ impl fmt::Display for Cause { Cause::Tessellation(cause) => write!(f, "{cause:?}"), Cause::Imageblocks(cause) => write!(f, "{cause:?}"), Cause::Identity(cause) => write!(f, "{cause:?}"), + Cause::PartialThreadgroups(cause) => write!(f, "{cause:?}"), } } } @@ -1350,6 +1360,33 @@ pub enum ImageblockCause { TwoImageblocks, } +/// The structure a kernel's partial-threadgroups variant (`LoweringInputs::partial_threadgroups`) +/// does not take (`Feature::PartialThreadgroups`): what the kernel holds, or the form the variant +/// was asked beside. Each is [`Needs::NotImplemented`] but `VoteWord`, which names the limit the +/// word passes. Refusals that meet the same structure name the same cause, wherever the +/// translator meets it. +#[non_exhaustive] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum PartialThreadgroupsCause { + /// Compute derivatives: the quads of a threadgroup whose invocations past the grid return + /// would be left partial. + ComputeDerivatives, + /// The variant asked beside `LoweringInputs::flat_grid`, `folded_groups` or `replay_bindings`: + /// each runs a dispatch other than the direct `dispatchThreads` whose invocations past the + /// grid the variant walks. + OtherForm, + /// An imageblock slice write every invocation of the threadgroup shares, each writing a + /// strided share of the slice's cells after a threadgroup barrier: invocations past the grid + /// would write no share. + SharedSliceWrite, + /// A tile function (`LoweringInputs::tile_attachments`): its threadgroups are its tile's. + TileFunction, + /// Workgroup-uniform barriers that the walk takes to with a vote word, which the stage's + /// workgroup memory cannot hold beside the kernel's static threadgroup memory: the refusal + /// needs `maxComputeSharedMemorySize` at the bytes of both. + VoteWord, +} + /// A pipeline input that the caller did not supply. #[non_exhaustive] #[derive(Clone, Debug, PartialEq, Eq, Hash)] diff --git a/crates/metal2vulkan/src/lower/mesh/mod.rs b/crates/metal2vulkan/src/lower/mesh/mod.rs index 10c72f147..ac833fa72 100644 --- a/crates/metal2vulkan/src/lower/mesh/mod.rs +++ b/crates/metal2vulkan/src/lower/mesh/mod.rs @@ -88,7 +88,9 @@ use crate::air::Entry; use crate::bind::mesh_arguments::{METAL_MESH_GRID_AXIS, METAL_MESH_GRID_TOTAL}; use crate::device::requirements::{VkExtension, VkFeature, VkLimit}; use crate::device::DeviceProfile; -use crate::error::{Capability, Error, Feature, LowerFamily, Unsupported}; +use crate::error::{ + Capability, Error, Feature, LowerFamily, PartialThreadgroupsCause, Unsupported, +}; use crate::lower::dispatch::KernelBuiltin; use crate::lower::emit::EmitCx; use crate::lower::select::{Plan, SelectCx}; @@ -432,17 +434,23 @@ pub fn check_payload(cx: &SelectCx<'_>, size: u64) -> Result<(), Error> { /// (`lower::stage_io::stage_in`). A tile function, one with compute derivatives (whose quads a /// returned lane would leave partial) and one with a cooperative imageblock slice write /// (`texture::cooperative`, whose cells every invocation of the workgroup shares) are refused the -/// kernel's input, `Unsupported{PartialThreadgroups, NotImplemented}`. Called before the push -/// fields are placed. +/// kernel's input, `Unsupported{PartialThreadgroups, NotImplemented}` naming the structure +/// (`PartialThreadgroupsCause`). Called before the push fields are placed. pub fn plan_partial_groups(cx: &mut SelectCx<'_>) -> Result<(), Error> { match cx.stage { Stage::Object => {} Stage::Kernel if cx.inputs.partial_threadgroups => { - if crate::lower::access::tile::is_tile(cx) - || cx.families.barrier.compute_derivatives - || !cx.families.texture.cooperative.is_empty() - { - return Err(Unsupported::not_implemented(Feature::PartialThreadgroups).into()); + let cause = if crate::lower::access::tile::is_tile(cx) { + Some(PartialThreadgroupsCause::TileFunction) + } else if cx.families.barrier.compute_derivatives { + Some(PartialThreadgroupsCause::ComputeDerivatives) + } else if !cx.families.texture.cooperative.is_empty() { + Some(PartialThreadgroupsCause::SharedSliceWrite) + } else { + None + }; + if let Some(cause) = cause { + return Err(Unsupported::partial_threadgroups(cause).into()); } } _ => return Ok(()), diff --git a/crates/metal2vulkan/src/lower/simd/divergent.rs b/crates/metal2vulkan/src/lower/simd/divergent.rs index 69a63134b..fa8f00b6c 100644 --- a/crates/metal2vulkan/src/lower/simd/divergent.rs +++ b/crates/metal2vulkan/src/lower/simd/divergent.rs @@ -61,7 +61,7 @@ use std::collections::BTreeMap; use crate::air::ir::{BlockId, Idx, InstKind, Value, ValueId}; use crate::budget::Meter; use crate::device::subgroup::Tier; -use crate::error::{Error, Feature, Location, Needs, Unsupported}; +use crate::error::{Cause, Error, Feature, Location, Needs, PartialThreadgroupsCause, Unsupported}; use crate::graph::LoopForest; use crate::lower::select::SelectCx; use crate::lower::strategy::{FamilyStrategy, Strategy}; @@ -261,8 +261,8 @@ pub const VOTE_BYTES: u32 = 4; /// barriers are uniform and whose word does not fit runs no partial threadgroup instead /// (`MeshPlan::partial_groups` cleared, so the binder refuses such a draw), and a kernel's /// partial-threadgroups variant (`LoweringInputs::partial_threadgroups`) is refused, -/// `Unsupported{PartialThreadgroups}` needing the `Limit` of `maxComputeSharedMemorySize` its -/// arena and word pass. +/// `Unsupported{PartialThreadgroups}` of cause `VoteWord` needing the `Limit` of +/// `maxComputeSharedMemorySize` its arena and word pass. pub fn barriers( cx: &mut SelectCx<'_>, strategy: &[Option], @@ -335,9 +335,12 @@ pub fn barriers( .. })) if !divergent => { if cx.stage == Stage::Kernel { - return Err( - Unsupported::needs_any_of(Feature::PartialThreadgroups, limit).into(), - ); + let cause = PartialThreadgroupsCause::VoteWord; + return Err(Unsupported { + cause: Some(Cause::PartialThreadgroups(cause)), + ..Unsupported::needs_any_of(Feature::PartialThreadgroups, limit) + } + .into()); } cx.families.mesh.partial_groups = false; return Ok(()); diff --git a/crates/metal2vulkan/src/pipeline/compile.rs b/crates/metal2vulkan/src/pipeline/compile.rs index f7c77bd3e..2c6fa5d49 100644 --- a/crates/metal2vulkan/src/pipeline/compile.rs +++ b/crates/metal2vulkan/src/pipeline/compile.rs @@ -2894,7 +2894,8 @@ fn analyze_one(r: &Request<'_>, p: &DeviceProfile, m: &mut Meter) -> Result>) variant metal2vulkan::error::Needs::NotImplemented NotImplemented variant metal2vulkan::error::Needs::NotRepresentable NotRepresentable +variant metal2vulkan::error::PartialThreadgroupsCause::ComputeDerivatives ComputeDerivatives +variant metal2vulkan::error::PartialThreadgroupsCause::OtherForm OtherForm +variant metal2vulkan::error::PartialThreadgroupsCause::SharedSliceWrite SharedSliceWrite +variant metal2vulkan::error::PartialThreadgroupsCause::TileFunction TileFunction +variant metal2vulkan::error::PartialThreadgroupsCause::VoteWord VoteWord variant metal2vulkan::error::PrivateRenderField::AlphaTest AlphaTest variant metal2vulkan::error::PrivateRenderField::ExplicitVisibilityGroup ExplicitVisibilityGroup variant metal2vulkan::error::PrivateRenderField::FragmentDepthCompareClamp FragmentDepthCompareClamp diff --git a/crates/metal2vulkan/tests/api_surface.rs b/crates/metal2vulkan/tests/api_surface.rs index df4925276..80a5b87e5 100644 --- a/crates/metal2vulkan/tests/api_surface.rs +++ b/crates/metal2vulkan/tests/api_surface.rs @@ -197,6 +197,7 @@ surface! { enum AccessCause N; enum TessellationCause N; enum ImageblockCause N; + enum PartialThreadgroupsCause N; enum IdentityCause N; enum PrivateRenderField N; enum RuntimeInput N; diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index ec120159a..79c5b32e7 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -68,7 +68,7 @@ Columns: | `Linking` | Linkage signatures / stitching / dynamic libraries | every device (not implemented) | `ours` | 3: `crates/metal2vulkan-air/src/canon/link.rs (not_implemented)`, `crates/metal2vulkan-air/src/canon/mod.rs (post_check)` (+1) | `rare`: dynamic libraries and linked functions | | `SimdWidth` | Simdgroup width 32 is not achievable for this usage, stage, and device | devices without a capability the site computes (`subgroup::width_needs(cx.stage, model.stage(cx.stage))`); devices without a capability the site computes (`width_needs(stage, st)`) | `device` | 2: `crates/metal2vulkan/src/device/subgroup.rs (subgroup_tier)`, `crates/metal2vulkan/src/lower/simd/mod.rs (finish)` | `app`: simdgroup functions on a device whose subgroups cannot run 32 wide for the use | | `LocalSize` | A local size beyond a device limit on this axis (`None` | - | `-` | 0 | `app`: a threadgroup size past a smaller device's limit | -| `PartialThreadgroups` | A kernel's partial-threadgroups variant (`LoweringInputs::partial_threadgroups`) that the lowering cannot make | devices without a capability the site computes (`limit`); every device (not implemented) | `ours` | 3: `crates/metal2vulkan/src/lower/mesh/mod.rs (plan_partial_groups)`, `crates/metal2vulkan/src/lower/simd/divergent.rs (barriers)` (+1) | `app`: a dispatchThreads grid that is not whole threadgroups, of a kernel whose partial-threadgroups variant cannot be made | +| `PartialThreadgroups` | A kernel's partial-threadgroups variant (`LoweringInputs::partial_threadgroups`) that the lowering cannot make, its cause named... | devices without a capability the site computes (`limit`); every device (not implemented) | `ours` | 2: `crates/metal2vulkan/src/error/mod.rs (partial_threadgroups)`, `crates/metal2vulkan/src/lower/simd/divergent.rs (barriers)` | `app`: a dispatchThreads grid that is not whole threadgroups, of a kernel whose partial-threadgroups variant cannot be made | | `IrreducibleConvergent` | An irreducible region containing a convergent instruction | every device (no Vulkan mechanism) | `device` | 1: `crates/metal2vulkan/src/structurize/irreducible.rs (refuse_tangled)` | `rare`: irreducible loops around barriers or simd operations | | `ComputeDerivativesWithSimd` | Compute derivatives in a flattened simd tier | every device (no Vulkan mechanism) | `device` | 1: `crates/metal2vulkan/src/lower/dispatch.rs (plan_kernel)` | `rare`: derivatives in a kernel | | `ComputeDerivatives` | Derivatives outside fragment without compute-derivative support | devices without VkFeature::ComputeDerivativeGroupLinear; every device (no Vulkan mechanism); every device (not implemented) | `ours` | 3: `crates/metal2vulkan/src/lower/sync/barrier.rs (select_derivative, 3 sites)` | `rare`: derivatives in a kernel | @@ -403,7 +403,7 @@ Each refusal's sites, with the function that builds it. - `feature::InlineAsm`: `crates/metal2vulkan-air/src/canon/mod.rs (post_check)` - `feature::Linking`: `crates/metal2vulkan-air/src/canon/link.rs (not_implemented)`; `crates/metal2vulkan-air/src/canon/mod.rs (post_check)`; `crates/metal2vulkan-air/src/canon/mod.rs (specialize_dynamic)` - `feature::SimdWidth`: `crates/metal2vulkan/src/device/subgroup.rs (subgroup_tier)`; `crates/metal2vulkan/src/lower/simd/mod.rs (finish)` -- `feature::PartialThreadgroups`: `crates/metal2vulkan/src/lower/mesh/mod.rs (plan_partial_groups)`; `crates/metal2vulkan/src/lower/simd/divergent.rs (barriers)`; `crates/metal2vulkan/src/pipeline/compile.rs (analyze_one)` +- `feature::PartialThreadgroups`: `crates/metal2vulkan/src/error/mod.rs (partial_threadgroups)`; `crates/metal2vulkan/src/lower/simd/divergent.rs (barriers)` - `feature::IrreducibleConvergent`: `crates/metal2vulkan/src/structurize/irreducible.rs (refuse_tangled)` - `feature::ComputeDerivativesWithSimd`: `crates/metal2vulkan/src/lower/dispatch.rs (plan_kernel)` - `feature::ComputeDerivatives`: `crates/metal2vulkan/src/lower/sync/barrier.rs (select_derivative, 3 sites)`