diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 282c7679f..1524b3820 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 = 2353; +pub const SEMANTICS_VERSION: u32 = 2354; /// 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/error/mod.rs b/crates/metal2vulkan/src/error/mod.rs index e046ed3fe..0376165c0 100644 --- a/crates/metal2vulkan/src/error/mod.rs +++ b/crates/metal2vulkan/src/error/mod.rs @@ -185,7 +185,8 @@ impl From for Error { impl From for Unsupported { /// The front end's refusal, not implemented. Its `Tessellation` is one structure, a /// control-point input used other than through its function or that function called on - /// another pointer, so it names that cause; the front end's other refusals name none. + /// another pointer, and its `Imageblocks` one, a multisample imageblock's operation, so each + /// names that cause; the front end's other refusals name none. fn from(u: crate::air::error::Unsupported) -> Unsupported { let crate::air::error::Unsupported { feature, @@ -196,6 +197,9 @@ impl From for Unsupported { crate::air::error::Feature::Tessellation => { Some(Cause::Tessellation(TessellationCause::ControlPointInput)) } + crate::air::error::Feature::Imageblocks => { + Some(Cause::Imageblocks(ImageblockCause::MultisampleOperation)) + } _ => None, }; Unsupported { @@ -431,6 +435,15 @@ impl Unsupported { ..Unsupported::not_implemented(Feature::Tessellation) } } + + /// The imageblocks' refusal of the structure `cause` names (`Feature::Imageblocks`, not + /// implemented). + pub(crate) fn imageblocks(cause: ImageblockCause) -> Unsupported { + Unsupported { + cause: Some(Cause::Imageblocks(cause)), + ..Unsupported::not_implemented(Feature::Imageblocks) + } + } } impl fmt::Display for Unsupported { @@ -755,12 +768,10 @@ pub enum Feature { Tessellation, MeshShading, TileShading, - /// An imageblock outside the forms implemented: a multisample imageblock's operation (its - /// sample count, the colors a pixel holds, a color's coverage mask, or a store to the samples - /// a coverage mask selects); a fragment imageblock on a layered or amplified pass, written - /// under alpha to coverage, or whose write a test may drop where no form runs the test first; - /// or an explicit layout, imageblock data operand or slice write of a shape not modelled. Tile - /// functions run on single-sample passes; fragment imageblocks hold a block per sample. + /// An imageblock outside the forms implemented, its cause named (`ImageblockCause`): a + /// multisample imageblock's operation, a fragment function's imageblock view, or an explicit + /// imageblock's stage, parameters, layout, data operands, memory or slice write of a shape not + /// modelled. Tile functions run on single-sample passes. Imageblocks, RayTracing, Tensors, @@ -1034,6 +1045,8 @@ pub enum Cause { Access(AccessCause), /// Tessellation's refusal (`Feature::Tessellation`, [`Needs::NotImplemented`]). Tessellation(TessellationCause), + /// The imageblocks' refusal (`Feature::Imageblocks`, [`Needs::NotImplemented`]). + Imageblocks(ImageblockCause), } impl fmt::Display for Cause { @@ -1041,6 +1054,7 @@ impl fmt::Display for Cause { match self { Cause::Access(cause) => write!(f, "{cause:?}"), Cause::Tessellation(cause) => write!(f, "{cause:?}"), + Cause::Imageblocks(cause) => write!(f, "{cause:?}"), } } } @@ -1235,6 +1249,52 @@ pub enum TessellationCause { VertexInput, } +/// The structure an imageblock the translator does not implement met (`Feature::Imageblocks`, +/// [`Needs::NotImplemented`]): the stage it is in, the kernel's imageblock parameters and their +/// layout, an intrinsic's operands, or the use of its memory. 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 ImageblockCause { + /// A pointer into the imageblock's memory (its address space) that `air.imageblock_data` does + /// not make, in a function that is not a tile function: the imageblock parameter's own value + /// taken as a pointer. + CellPointer, + /// An imageblock intrinsic `air.imageblock_data` called with operands other than + /// `(coord, 0, 0)`, the form every `imageblock::data(ushort2)` passes. + DataOperands, + /// An explicit imageblock without a data size (`air.imageblock_data_size` missing or 0). + DataSize, + /// A fragment function's imageblock view (`[[imageblock_data]]`), as an input or an output. + FragmentData, + /// A kernel's explicit imageblock whose layout the threadgroup arena does not model: an + /// alignment that is not a power of two, cells past 4 GiB, or an explicit imageblock beside + /// an implicit one it does not alias. + Layout, + /// An imageblock intrinsic in a kernel that declares no imageblock. + Missing, + /// A multisample imageblock's operation, which does not decode: its sample count, the colors + /// its pixel holds or a color's coverage mask, or a store to the samples of a coverage mask. + MultisampleOperation, + /// The imageblock parameter's value used other than through its intrinsics: a kernel reaches + /// its explicit imageblock only through `air.imageblock_data`, the extent queries and slice + /// writes. + ParameterValue, + /// A slice write of the imageblock to a texture (`write_imageblock_slice`) of a shape not + /// modelled: its origin operand not the constant zero, its trailing flag not the constant + /// `false`, a field pointer that is not one exact in-cell offset of imageblock cells, a + /// texture that is no static slot or heap element, or an element type or texel class the + /// write does not hold. + SliceWrite, + /// An imageblock in a function whose stage has none of its kind: an explicit imageblock, or an + /// imageblock intrinsic, outside a kernel or a tile function, or an imageblock view outside a + /// fragment function. + Stage, + /// A kernel with more than one explicit imageblock, or more than one implicit one: + /// `air.imageblock_data` names none of them. + TwoImageblocks, +} + /// A pipeline input that the caller did not supply. #[non_exhaustive] #[derive(Clone, Debug, PartialEq, Eq, Hash)] diff --git a/crates/metal2vulkan/src/lower/access/imageblock.rs b/crates/metal2vulkan/src/lower/access/imageblock.rs index 5cfab4c1b..4505b5ba3 100644 --- a/crates/metal2vulkan/src/lower/access/imageblock.rs +++ b/crates/metal2vulkan/src/lower/access/imageblock.rs @@ -24,14 +24,16 @@ //! (`access::tile`); a kernel compiled without tile inputs that reaches one is //! `NeedsInput(TileAttachments)`. //! -//! Refused: an imageblock outside a kernel, a kernel with two explicit imageblocks -//! (`imageblock_data` names none), one without a data size, and `imageblock_data` operands other -//! than `(coord, 0, 0)` are `Unsupported{Imageblocks, NotImplemented}`. +//! Refused (`Unsupported{Imageblocks, NotImplemented}`, each naming its `ImageblockCause`): an +//! imageblock outside a kernel (`Stage`), a kernel with two explicit imageblocks +//! (`imageblock_data` names none: `TwoImageblocks`), one without a data size (`DataSize`) or of a +//! layout the arena does not model (`Layout`), an intrinsic in a kernel with no imageblock +//! (`Missing`), and `imageblock_data` operands other than `(coord, 0, 0)` (`DataOperands`). use crate::air::abi::{ImageblockKind, ParamRole}; use crate::air::intrinsics::{AirIntrinsic, Imageblock}; use crate::air::ir::{Callee, Const, Inst, InstKind, Value, ValueId}; -use crate::error::{Error, Feature, LowerFamily, Unsupported}; +use crate::error::{Error, Feature, ImageblockCause, LowerFamily, Unsupported}; use crate::lower::emit::EmitCx; use crate::lower::select::SelectCx; use crate::memory::arena::Arena; @@ -93,8 +95,8 @@ impl ImageblockStrategy { } } -fn imageblocks() -> Error { - Unsupported::not_implemented(Feature::Imageblocks).into() +fn imageblocks(cause: ImageblockCause) -> Error { + Unsupported::imageblocks(cause).into() } /// What a use of the imageblock reaches: a tile function stages the attachments whose cells it @@ -131,14 +133,14 @@ pub(crate) fn use_imageblock(cx: &mut SelectCx<'_>, cells: CellUse) -> Result region.cell_bytes, + (None, Some(cause)) => return Err(imageblocks(cause)), + (None, None) => return Err(imageblocks(ImageblockCause::Missing)), + }; place_region(cx, cell_bytes)?; Ok(cell_bytes) } @@ -199,7 +201,7 @@ pub fn select(cx: &mut SelectCx<'_>, inst: &Inst) -> Result, b: &ParamBinding) -> Result<(), Error ParamRole::Threadgroup(_) | ParamRole::Payload { .. } => local::select_param(cx, b), // The imageblock's value (a struct holding its opaque base) has no lowered form: a kernel // reaches the imageblock only through its intrinsics. - ParamRole::Imageblock(_) => Err(Unsupported::not_implemented(Feature::Imageblocks).into()), + ParamRole::Imageblock(_) => { + Err(Unsupported::imageblocks(ImageblockCause::ParameterValue).into()) + } _ => Err(refuse(AccessCause::Parameter)), } } diff --git a/crates/metal2vulkan/src/lower/fragment/mod.rs b/crates/metal2vulkan/src/lower/fragment/mod.rs index cfc7edfc0..fb38a9a16 100644 --- a/crates/metal2vulkan/src/lower/fragment/mod.rs +++ b/crates/metal2vulkan/src/lower/fragment/mod.rs @@ -12,7 +12,7 @@ //! entry-wrapper hook of `lower::emit`); inside it a discard only records `discarded`, and `main` //! kills after the critical section. //! - **Imageblocks**: an `[[imageblock_data]]` input or output is not implemented -//! (`Unsupported{Imageblocks, NotImplemented}`). +//! (`Unsupported{Imageblocks, NotImplemented}`, `ImageblockCause::FragmentData`). //! - **Sample count** (`get_num_samples`): Metal's header spells `get_num_samples()` as the call //! with operand 0, the pipeline's rasterization sample count. It reads the `SpecKey::SampleCount` //! specialization constant (`RuntimeFact::SampleCount`, default 1), which the binder sets to the @@ -57,7 +57,7 @@ use crate::air::intrinsics::{AirIntrinsic, Fragment}; use crate::air::ir::{Callee, Const, Inst, InstId, InstKind, Value}; use crate::budget::Meter; use crate::device::subgroup::OpBits; -use crate::error::{Attachment, Error, Feature, LowerFamily, Unsupported}; +use crate::error::{Attachment, Error, Feature, ImageblockCause, LowerFamily, Unsupported}; use crate::lower::arith::legal::{form_on, Form}; use crate::lower::arith::ops; use crate::lower::emit::{EmitCx, FamilyDecls}; @@ -410,7 +410,7 @@ pub(super) fn load_coverage( /// input is not implemented. pub fn select_param(cx: &mut SelectCx<'_>, b: &ParamBinding) -> Result<(), Error> { if let ParamRole::Imageblock(_) = &b.role { - return Err(Unsupported::not_implemented(Feature::Imageblocks).into()); + return Err(Unsupported::imageblocks(ImageblockCause::FragmentData).into()); } let c = color::select_param(cx, b).map_err(|e| match b.role { ParamRole::ColorInput { diff --git a/crates/metal2vulkan/src/lower/select.rs b/crates/metal2vulkan/src/lower/select.rs index 3b933100d..09e8ede1f 100644 --- a/crates/metal2vulkan/src/lower/select.rs +++ b/crates/metal2vulkan/src/lower/select.rs @@ -52,7 +52,8 @@ use crate::device::requirements::{VkFeature, VkLimit}; use crate::device::subgroup::{self, SimdClass, SubgroupRequirement, Tier}; use crate::device::DeviceProfile; use crate::error::{ - Capability, DiagName, Error, Feature, InternalError, InternalKind, LowerFamily, Unsupported, + Capability, DiagName, Error, Feature, ImageblockCause, InternalError, InternalKind, + LowerFamily, Unsupported, }; use crate::lower::dispatch::DispatchPlan; use crate::lower::push; @@ -768,7 +769,9 @@ pub fn param_family(stage: Stage, role: &ParamRole) -> Result return refuse(Feature::Imageblocks), + ParamRole::Imageblock(_) => { + return Err(Unsupported::imageblocks(ImageblockCause::Stage).into()) + } ParamRole::AccelerationStructure { .. } => LowerFamily::RayTracing, ParamRole::FunctionTable(_) => return refuse(Feature::DynamicCall), // Its only readers are intersect calls, which read its words. @@ -2482,7 +2485,7 @@ mod tests { let explicit = if stage == Stage::Kernel { Ok(LowerFamily::Access) } else { - Err(Unsupported::not_implemented(Feature::Imageblocks).into()) + Err(Unsupported::imageblocks(ImageblockCause::Stage).into()) }; assert_eq!( param_family(stage, &imageblock(ImageblockKind::Explicit, false)), @@ -2503,7 +2506,7 @@ mod tests { let data = if stage == Stage::Fragment { Ok(LowerFamily::Fragment) } else { - Err(Unsupported::not_implemented(Feature::Imageblocks).into()) + Err(Unsupported::imageblocks(ImageblockCause::Stage).into()) }; assert_eq!( param_family(stage, &imageblock(ImageblockKind::Data, false)), diff --git a/crates/metal2vulkan/src/lower/stage_io/plan.rs b/crates/metal2vulkan/src/lower/stage_io/plan.rs index 7f4f508fa..c8a881862 100644 --- a/crates/metal2vulkan/src/lower/stage_io/plan.rs +++ b/crates/metal2vulkan/src/lower/stage_io/plan.rs @@ -10,7 +10,9 @@ use crate::air::abi::{ use crate::air::intrinsics::{AirIntrinsic, Fragment as AirFragment, InterpolateAt}; use crate::air::ir::{ArgIdx, Callee, InstKind, Type, TypeId as AirTypeId, Value}; use crate::device::requirements::{VkExtension, VkFeature, VkLimit, VkProperty}; -use crate::error::{Attachment, Capability, Error, Feature, TessellationCause, Unsupported}; +use crate::error::{ + Attachment, Capability, Error, Feature, ImageblockCause, TessellationCause, Unsupported, +}; use crate::lower::arith::legal::{form_on, refuse_bfloat_color, refuse_int64_interface}; use crate::lower::arith::{Form, Held}; use crate::lower::select::SelectCx; @@ -2097,7 +2099,7 @@ pub fn entry(cx: &mut SelectCx<'_>) -> Result<(), Error> { } // An imageblock output is not implemented. if let OutputRole::ImageblockData(_) = &o.role { - return Err(Unsupported::not_implemented(Feature::Imageblocks).into()); + return Err(Unsupported::imageblocks(ImageblockCause::FragmentData).into()); } // A stencil output on a device without stencil export is no output: each return keeps // the fragment only where the output holds the bit the draw pushes, and the consumer diff --git a/crates/metal2vulkan/src/lower/texture/mod.rs b/crates/metal2vulkan/src/lower/texture/mod.rs index 1d144ee5d..53f4f2606 100644 --- a/crates/metal2vulkan/src/lower/texture/mod.rs +++ b/crates/metal2vulkan/src/lower/texture/mod.rs @@ -214,7 +214,7 @@ use crate::air::intrinsics::{ }; use crate::air::ir::{Callee, Const, Inst, InstId, InstKind, Value, ValueId}; use crate::budget::Meter; -use crate::error::{Error, Feature, LowerFamily, Unsupported}; +use crate::error::{Error, Feature, ImageblockCause, LowerFamily, Unsupported}; use crate::lower::arith::{FloatFmt, Form, Held}; use crate::lower::emit::EmitCx; use crate::lower::sampler::Sampling; @@ -1850,7 +1850,7 @@ pub fn select( slice::select(cx, (at, t), &ops, ImageRef::Slot(index), m) } // A slice write to a switched or null texture is not modelled yet. - _ => Err(Unsupported::not_implemented(Feature::Imageblocks).into()), + _ => Err(Unsupported::imageblocks(ImageblockCause::SliceWrite).into()), }; } if sampling { diff --git a/crates/metal2vulkan/src/lower/texture/slice.rs b/crates/metal2vulkan/src/lower/texture/slice.rs index 7aa226694..2c2772938 100644 --- a/crates/metal2vulkan/src/lower/texture/slice.rs +++ b/crates/metal2vulkan/src/lower/texture/slice.rs @@ -29,7 +29,8 @@ //! past the imageblock's extent in either axis is clipped to it (the cells past it are not the //! imageblock's; Metal leaves them undefined). //! -//! Only these are pinned (else `Unsupported{Imageblocks, NotImplemented}`): the origin operand the +//! Only these are pinned (else `Unsupported{Imageblocks, NotImplemented}`, +//! `ImageblockCause::SliceWrite`): the origin operand the //! constant zero, the trailing flag the constant `false`, the flag a constant, a field pointer //! whose roots are all imageblock cells at one exact in-cell offset (in a tile function whose pass //! keeps fewer bytes of its cells, `LoweringInputs::kept_imageblock_bytes`, a field within them), @@ -47,7 +48,7 @@ use crate::air::intrinsics::{Elem, TexRole, Texture}; use crate::air::ir::{InstId, Value, ValueId}; use crate::budget::Meter; -use crate::error::{Error, Feature, RuntimeInput, Unsupported}; +use crate::error::{Error, ImageblockCause, RuntimeInput, Unsupported}; use crate::lower::access::imageblock; use crate::lower::arith::legal::held_on; use crate::lower::arith::{FloatFmt, Form, Held}; @@ -104,7 +105,7 @@ impl Slice { } fn imageblocks() -> Error { - Unsupported::not_implemented(Feature::Imageblocks).into() + Unsupported::imageblocks(ImageblockCause::SliceWrite).into() } /// Whether `v` is the constant `i1` `b`. diff --git a/crates/metal2vulkan/src/memory/plan.rs b/crates/metal2vulkan/src/memory/plan.rs index 7c0ff6e6a..478eb6b71 100644 --- a/crates/metal2vulkan/src/memory/plan.rs +++ b/crates/metal2vulkan/src/memory/plan.rs @@ -53,7 +53,7 @@ use super::provenance::{ ALIGN_LOG_CAP, }; use super::window; -use crate::air::abi::{AbiInt, Access, ImageblockKind, ParamRole}; +use crate::air::abi::{AbiInt, Access, ImageblockArg, ImageblockKind, ParamRole}; use crate::air::ir::{ AddrSpace, Const, ConstId, GlobalId, InstId, InstKind, Type, TypeId, TypeLayouts, Value, ValueId, ValueIndex, @@ -62,7 +62,9 @@ use crate::air::Entry; use crate::budget::{tree_bytes, vec_bytes, Meter}; use crate::device::profile::{BufferAccess, PointerDomain}; use crate::device::DeviceProfile; -use crate::error::{AccessCause, Error, Feature, InternalError, InternalKind, Limit, Unsupported}; +use crate::error::{ + AccessCause, Error, Feature, ImageblockCause, InternalError, InternalKind, Limit, Unsupported, +}; use crate::pipeline::interface::{AccessSet, Window}; use crate::pipeline::sym::{SlotClass, SlotRef}; @@ -150,6 +152,9 @@ pub struct ArenaLayout { pub dynamic: Vec, /// The threadgroup arena's imageblock, last. pub imageblock: Option, + /// Why the threadgroup arena has no imageblock where the entry's imageblock parameters give + /// it none: the cause a use of the imageblock refuses with (`lower::access::imageblock`). + pub imageblock_refused: Option, /// The arena keeps its first word ([`NULL_WORD`] bytes) for the null pointer: no object lies /// at offset 0, so a pointer into it that may be null is null at offset 0, the value zero /// bytes hold. The private arena keeps it when some pointer into it may be null @@ -1574,7 +1579,10 @@ impl Planner<'_> { align: 16, }); } - arena.imageblock = self.imageblock(); + (arena.imageblock, arena.imageblock_refused) = match self.imageblock() { + Ok(region) => (region, None), + Err(cause) => (None, Some(cause)), + }; Ok(arena) } @@ -1827,12 +1835,16 @@ impl Planner<'_> { Ok((order?, known)) } - /// The threadgroup arena's imageblock region, when it has a model. + /// The threadgroup arena's imageblock region, when it has a model; `None` for an entry with + /// no imageblock, and the cause where its imageblock parameters give it none, which + /// `lower::access::imageblock` refuses a use with. /// /// A kernel's explicit imageblock parameter: exactly one explicit imageblock with an /// `air.imageblock_data_size` and a power-of-two `air.arg_type_align_size`, unaliased. - /// `air.imageblock_data` names no imageblock, so a kernel with two has none; - /// `lower::access::imageblock` refuses a use without one. The cell stride is the data size + /// `air.imageblock_data` names no imageblock, so a kernel with two has none + /// ([`ImageblockCause::TwoImageblocks`]); one without a data size is + /// [`ImageblockCause::DataSize`], and another layout without a model + /// [`ImageblockCause::Layout`]. The cell stride is the data size /// rounded up to the alignment (Metal's own sizes already are multiples): the layout is /// unobservable, and a stride that is not would misalign every other cell's fields. A cell /// pointer may reach past the data size (a `{half v}` cell stored as a `half2`, a slice of a @@ -1845,7 +1857,7 @@ impl Planner<'_> { /// texels at their offsets); with only one implicit imageblock, its layout's members' extent /// rounded up to a word. No function observes the stride. `lower::access::tile` checks the layouts against each other and the /// attachments. - fn imageblock(&self) -> Option { + fn imageblock(&self) -> Result, ImageblockCause> { let of = |kind: ImageblockKind| { self.e.ep.params.iter().filter_map(move |b| match &b.role { ParamRole::Imageblock(arg) if arg.kind == kind => Some((b, arg)), @@ -1857,13 +1869,13 @@ impl Planner<'_> { let (first_explicit, second_explicit) = (explicit.next(), explicit.next()); let (first_implicit, second_implicit) = (implicit.next(), implicit.next()); if second_explicit.is_some() || second_implicit.is_some() { - return None; + return Err(ImageblockCause::TwoImageblocks); } + let layout = ImageblockCause::Layout; match (first_explicit, first_implicit) { - // An unaliased explicit imageblock beside an implicit one has no model. (Some((b, arg)), implicit) if arg.alias_implicit || implicit.is_none() => { - let size = arg.data_size.filter(|n| *n > 0)?; - let align = b.ty.align.filter(|a| a.is_power_of_two())?; + let size = (arg.data_size.filter(|n| *n > 0)).ok_or(ImageblockCause::DataSize)?; + let align = (b.ty.align.filter(|a| a.is_power_of_two())).ok_or(layout)?; // A tile function's cells are whole words, which its staging zeroes where no // attachment texel covers them (`lower::access::tile`). let align = if arg.alias_implicit { @@ -1873,29 +1885,35 @@ impl Planner<'_> { }; let size = match arg.alias_implicit { true => size, - false => size.max(self.imageblock_reach()?), + false => size.max(self.imageblock_reach().ok_or(layout)?), }; - Some(ImageblockRegion { + Ok(Some(ImageblockRegion { param: b.param, - cell_bytes: size.checked_next_multiple_of(align)?, - }) + cell_bytes: size.checked_next_multiple_of(align).ok_or(layout)?, + })) } - (None, Some((b, arg))) => { - let layout = self.e.structs.get(usize::try_from(arg.layout?.0).ok()?)?; - let mut end = 0u32; - for m in &layout.members { - let n = m.size.checked_mul(m.array_len.max(1))?; - end = end.max(m.offset.checked_add(n)?); - } - Some(ImageblockRegion { - param: b.param, - cell_bytes: end.checked_next_multiple_of(4)?.max(4), - }) - } - _ => None, + (None, Some((b, arg))) => Ok(Some(ImageblockRegion { + param: b.param, + cell_bytes: self.implicit_cell_bytes(arg).ok_or(layout)?, + })), + (None, None) => Ok(None), + // An unaliased explicit imageblock beside an implicit one has no model. + (Some(_), _) => Err(layout), } } + /// An implicit imageblock's cell bytes: its layout's members' extent rounded up to a word, + /// `None` for a layout it does not name or past 4 GiB. + fn implicit_cell_bytes(&self, arg: &ImageblockArg) -> Option { + let layout = self.e.structs.get(usize::try_from(arg.layout?.0).ok()?)?; + let mut end = 0u32; + for m in &layout.members { + let n = m.size.checked_mul(m.array_len.max(1))?; + end = end.max(m.offset.checked_add(n)?); + } + Some(end.checked_next_multiple_of(4)?.max(4)) + } + /// The end of the widest access through a kernel's cell pointers (`air.imageblock_data`): /// the highest byte past its cell's start that a load, a store, an atomic, or a slice write /// reaches through one, 0 for none. An access at an offset the analysis does not bound, or @@ -2285,12 +2303,12 @@ impl Planner<'_> { // implicit imageblock. (_, AddrSpace::ThreadgroupImageblock) => { if !roots.iter().all(|r| imageblock_cell(self.e, *r)) { - let feature = if self.tile_shading() { - Feature::TileShading + let refusal = if self.tile_shading() { + Unsupported::not_implemented(Feature::TileShading) } else { - Feature::Imageblocks + Unsupported::imageblocks(ImageblockCause::CellPointer) }; - return Err(Unsupported::not_implemented(feature).into()); + return Err(refusal.into()); } Repr::TgPtr } diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 13e280448..623250cdc 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -695,6 +695,7 @@ enum metal2vulkan::error::Error #[derive(Clone, Debug, PartialEq, Eq)] #[non_exh enum metal2vulkan::error::ErrorClass #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum ErrorClass enum metal2vulkan::error::Feature #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum Feature enum metal2vulkan::error::GenericPointer #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum GenericPointer +enum metal2vulkan::error::ImageblockCause #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum ImageblockCause enum metal2vulkan::error::InputErrorKind #[derive(Clone, Debug, PartialEq, Eq)] #[non_exhaustive] pub enum InputErrorKind enum metal2vulkan::error::InternalKind #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum InternalKind enum metal2vulkan::error::IntrinsicError #[derive(Clone, Debug, PartialEq, Eq)] #[non_exhaustive] pub enum IntrinsicError @@ -9534,6 +9535,7 @@ variant metal2vulkan::error::Capability::Format Format { format: vk::Format, usa variant metal2vulkan::error::Capability::Limit Limit { limit: VkLimit, required: u64, available: u64 } variant metal2vulkan::error::Capability::Property Property(VkProperty) variant metal2vulkan::error::Cause::Access Access(AccessCause) +variant metal2vulkan::error::Cause::Imageblocks Imageblocks(ImageblockCause) variant metal2vulkan::error::Cause::Tessellation Tessellation(TessellationCause) variant metal2vulkan::error::ComputePipelineProblem::MaxThreadsDiffer MaxThreadsDiffer { specified: u32, max: u32 } variant metal2vulkan::error::ComputePipelineProblem::MaxThreadsOverLimit MaxThreadsOverLimit { max: u32, limit: u32 } @@ -9736,6 +9738,17 @@ variant metal2vulkan::error::GenericPointer::Call Call variant metal2vulkan::error::GenericPointer::Integer Integer variant metal2vulkan::error::GenericPointer::Memory Memory variant metal2vulkan::error::GenericPointer::TwoSpaces TwoSpaces +variant metal2vulkan::error::ImageblockCause::CellPointer CellPointer +variant metal2vulkan::error::ImageblockCause::DataOperands DataOperands +variant metal2vulkan::error::ImageblockCause::DataSize DataSize +variant metal2vulkan::error::ImageblockCause::FragmentData FragmentData +variant metal2vulkan::error::ImageblockCause::Layout Layout +variant metal2vulkan::error::ImageblockCause::Missing Missing +variant metal2vulkan::error::ImageblockCause::MultisampleOperation MultisampleOperation +variant metal2vulkan::error::ImageblockCause::ParameterValue ParameterValue +variant metal2vulkan::error::ImageblockCause::SliceWrite SliceWrite +variant metal2vulkan::error::ImageblockCause::Stage Stage +variant metal2vulkan::error::ImageblockCause::TwoImageblocks TwoImageblocks variant metal2vulkan::error::InputErrorKind::Abi Abi(AbiError) variant metal2vulkan::error::InputErrorKind::Bitcode Bitcode(BitcodeError) variant metal2vulkan::error::InputErrorKind::Bitstream Bitstream(BitstreamError) diff --git a/crates/metal2vulkan/tests/api_surface.rs b/crates/metal2vulkan/tests/api_surface.rs index 167125040..3d4ac322a 100644 --- a/crates/metal2vulkan/tests/api_surface.rs +++ b/crates/metal2vulkan/tests/api_surface.rs @@ -196,6 +196,7 @@ surface! { enum Cause N; enum AccessCause N; enum TessellationCause N; + enum ImageblockCause N; enum PrivateRenderField N; enum RuntimeInput N; enum DescriptorError N; diff --git a/docs/API.md b/docs/API.md index 9707d7479..839ffc290 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1519,7 +1519,7 @@ match floor.compile_function(&min_lod, &LoweringInputs::new(), &Budget::standard | Variant | Means | Retry | |---|---|---| -| `Unsupported` | The device cannot run this exactly. `feature` names the Metal feature, `needs` what would change it, and `cause`, where the feature covers more than one cause, the structure the translator met (`Cause::Access` names an access's: `AccessCause::PointerStore`, `AccessCause::UnderAligned`, ...; `Cause::Tessellation` a tessellation input's: `TessellationCause::UncountedPatch`, `TessellationCause::SimdGroup`, ...); its `Display` prints the cause after the feature | No | +| `Unsupported` | The device cannot run this exactly. `feature` names the Metal feature, `needs` what would change it, and `cause`, where the feature covers more than one cause, the structure the translator met (`Cause::Access` names an access's: `AccessCause::PointerStore`, `AccessCause::UnderAligned`, ...; `Cause::Tessellation` a tessellation input's: `TessellationCause::UncountedPatch`, `TessellationCause::SimdGroup`, ...; `Cause::Imageblocks` an imageblock's: `ImageblockCause::TwoImageblocks`, `ImageblockCause::DataOperands`, ...); its `Display` prints the cause after the feature | No | | `NeedsInput` | The compile needs a pipeline input you did not supply | After supplying it | | `InvalidInput` | The AIR or container is malformed | No | | `InvalidDescriptor` | The descriptor is invalid as Metal would refuse it, or names a missing entry | No | diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index ada30da27..49309defb 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -127,8 +127,8 @@ Columns: | `VertexInputLayout` | A vertex attribute whose layout fixed-function input cannot fetch, on a profile that fetches every attribute in fixed function (the identity... | devices without a capability the site computes (`limit`); every device (not implemented) | `ours` | 4: `crates/metal2vulkan/src/pipeline/link/vertex.rs (resolve, 4 sites)` | `rare`: vertex offsets or strides off their format's alignment, or past a device's limits | | `Tessellation` | Tessellation | devices without VkFeature::TessellationShader; devices without VkLimit::MaxTessellationGenerationLevel; every device (not implemented) | `ours` | 5: `crates/metal2vulkan-air/src/canon/mod.rs (post_check, 2 sites)`, `crates/metal2vulkan/src/error/mod.rs (tessellation)` (+2) | `rare`: tessellation | | `MeshShading` | | devices short of a device limit the site names; devices without VkLimit::MaxTaskPayloadSize; devices without a capability the site computes (`missing`); every device (not implemented) | `ours` | 4: `crates/metal2vulkan/src/lower/mesh/mod.rs (check_payload)`, `crates/metal2vulkan/src/lower/mesh/mod.rs (plan_entry, 2 sites)` (+1) | `rare`: mesh pipelines | -| `TileShading` | | every device (not implemented) | `ours` | 3: `crates/metal2vulkan/src/lower/access/tile.rs (not_implemented)`, `crates/metal2vulkan/src/lower/sync/barrier.rs (tile_shading)` (+1) | `rare`: tile shaders (Apple GPU families) | -| `Imageblocks` | An imageblock outside the forms implemented | every device (not implemented) | `ours` | 6: `crates/metal2vulkan/src/lower/access/imageblock.rs (imageblocks)`, `crates/metal2vulkan/src/lower/access/mod.rs (select_param)` (+4) | `rare`: imageblocks (Apple GPU families) | +| `TileShading` | | every device (not implemented) | `ours` | 4: `crates/metal2vulkan/src/lower/access/tile.rs (not_implemented)`, `crates/metal2vulkan/src/lower/sync/barrier.rs (tile_shading)` (+2) | `rare`: tile shaders (Apple GPU families) | +| `Imageblocks` | An imageblock outside the forms implemented, its cause named (`ImageblockCause`) | every device (not implemented) | `ours` | 1: `crates/metal2vulkan/src/error/mod.rs (imageblocks)` | `rare`: imageblocks (Apple GPU families) | | `RayTracing` | | devices without a capability the site computes (`missing`); every device (no Vulkan mechanism); every device (not implemented) | `ours` | 10: `crates/metal2vulkan/src/lower/raytracing/mod.rs (instance_count)`, `crates/metal2vulkan/src/lower/raytracing/mod.rs (intersect, 5 sites)` (+4) | `rare`: ray tracing (out of scope by ruling) | | `Tensors` | | every device (not implemented) | `ours` | 3: `crates/metal2vulkan-air/src/canon/matmul2d/synth.rs (refuse)`, `crates/metal2vulkan-air/src/canon/mod.rs (post_check)` (+1) | `rare`: shader tensors | | `RasterizationRateMap` | | devices without VkFeature::MultiViewport; devices without VkFeature::ShaderDrawParameters; devices without VkFeature::ShaderOutputViewportIndex; every device (not implemented) | `ours` | 2: `crates/metal2vulkan/src/lower/stage_io/plan.rs (region_viewport, 2 sites)` | `rare`: rasterization rate maps | @@ -461,8 +461,8 @@ Each refusal's sites, with the function that builds it. - `feature::VertexInputLayout`: `crates/metal2vulkan/src/pipeline/link/vertex.rs (resolve, 4 sites)` - `feature::Tessellation`: `crates/metal2vulkan-air/src/canon/mod.rs (post_check, 2 sites)`; `crates/metal2vulkan/src/error/mod.rs (tessellation)`; `crates/metal2vulkan/src/lower/tessellation/mod.rs (plan_entry)`; `crates/metal2vulkan/src/pipeline/link/tessellation/mod.rs (control_plan)` - `feature::MeshShading`: `crates/metal2vulkan/src/lower/mesh/mod.rs (check_payload)`; `crates/metal2vulkan/src/lower/mesh/mod.rs (plan_entry, 2 sites)`; `crates/metal2vulkan/src/memory/plan.rs (reprs)` -- `feature::TileShading`: `crates/metal2vulkan/src/lower/access/tile.rs (not_implemented)`; `crates/metal2vulkan/src/lower/sync/barrier.rs (tile_shading)`; `crates/metal2vulkan/src/pipeline/compile/api.rs (tile_pipeline)` -- `feature::Imageblocks`: `crates/metal2vulkan/src/lower/access/imageblock.rs (imageblocks)`; `crates/metal2vulkan/src/lower/access/mod.rs (select_param)`; `crates/metal2vulkan/src/lower/fragment/mod.rs (select_param)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs (entry)`; `crates/metal2vulkan/src/lower/texture/mod.rs (select)`; `crates/metal2vulkan/src/lower/texture/slice.rs (imageblocks)` +- `feature::TileShading`: `crates/metal2vulkan/src/lower/access/tile.rs (not_implemented)`; `crates/metal2vulkan/src/lower/sync/barrier.rs (tile_shading)`; `crates/metal2vulkan/src/memory/plan.rs (reprs)`; `crates/metal2vulkan/src/pipeline/compile/api.rs (tile_pipeline)` +- `feature::Imageblocks`: `crates/metal2vulkan/src/error/mod.rs (imageblocks)` - `feature::RayTracing`: `crates/metal2vulkan/src/lower/raytracing/mod.rs (instance_count)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs (intersect, 5 sites)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs (primitive_data_read)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs (select_param)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs (slot_of)`; `crates/metal2vulkan/src/lower/select.rs (route_air)` - `feature::Tensors`: `crates/metal2vulkan-air/src/canon/matmul2d/synth.rs (refuse)`; `crates/metal2vulkan-air/src/canon/mod.rs (post_check)`; `crates/metal2vulkan/src/lower/select.rs (route_air)` - `feature::RasterizationRateMap`: `crates/metal2vulkan/src/lower/stage_io/plan.rs (region_viewport, 2 sites)`