diff --git a/crates/metal2vulkan/src/lower/select.rs b/crates/metal2vulkan/src/lower/select.rs index be0259425..44eb92945 100644 --- a/crates/metal2vulkan/src/lower/select.rs +++ b/crates/metal2vulkan/src/lower/select.rs @@ -1930,11 +1930,36 @@ fn identity_unsourced(f: &RuntimeFact) -> bool { /// variant or the de-indexed and private list forms pull; and the render encoder's alpha test /// reference code a fragment function under the private alpha test compares with /// (`PushField::AlphaTestReference`). Its fields past the push window are a parameter block, whose -/// address the window holds. +/// address the window holds. Its refusal names the first form the plan holds that they do not +/// lower ([`identity_refusal`]). fn identity_admits(plan: &Plan, p: &DeviceProfile) -> Result<(), Error> { - let fields = plan.push.fields.iter().all(|f| match (f.field, f.loc) { - (PushField::ArgumentTableAddress, loc) => matches!(loc, PushLoc::Push { .. }), - (field, _) => matches!( + match identity_refusal(plan, p) { + None => Ok(()), + Some(form) => Err(Unsupported::not_implemented(Feature::IdentityDomains) + .naming(DiagName::new(form)) + .into()), + } +} + +/// The first form plan `plan` on profile `p` holds that the identity domains do not lower yet, as +/// a Metal program reaches it, which [`identity_admits`]'s refusal names (diagnostics only); +/// `None` where it holds none. +fn identity_refusal(plan: &Plan, p: &DeviceProfile) -> Option { + let stage = match plan.stage { + Stage::Kernel => true, + Stage::Vertex | Stage::Fragment => p.push_window() == PushWindow::Floor, + _ => false, + }; + if !stage { + return Some( + "a function of a stage other than a kernel's, or a vertex or fragment function off \ + the floor's push window" + .to_owned(), + ); + } + let field = plan.push.fields.iter().find(|f| match (f.field, f.loc) { + (PushField::ArgumentTableAddress, loc) => !matches!(loc, PushLoc::Push { .. }), + (field, _) => !matches!( field, PushField::SlotGuestBase(_) | PushField::DispatchRegion @@ -1945,23 +1970,48 @@ fn identity_admits(plan: &Plan, p: &DeviceProfile) -> Result<(), Error> { | PushField::AlphaTestReference ), }); - let addressed = plan - .slots - .iter() - .flatten() - .all(|c| c.form == BufferForm::Psb); + if let Some(f) = field { + return Some(format!( + "an encoder value the function reads as {:?}", + f.field + )); + } + if (plan.slots.iter().flatten()).any(|c| c.form != BufferForm::Psb) { + return Some("a buffer argument not reached through its device address".to_owned()); + } let t = &plan.families.texture; // An argument buffer's texture is the element its resource ID's index names in its class's // array (`access::handle::emit_identity_handle`), with no other class to read it through and // nothing from a handle-table entry but its word's out-of-bounds alpha. - let groups = t.heap.values().all(|h| { - h.decl.as_ref().and_then(texture::identity_class) == h.class - && h.plain.is_none() - && h.raw.is_none() - && h.cross.is_empty() - }); + for h in t.heap.values() { + if h.decl.as_ref().and_then(texture::identity_class) != h.class { + return Some( + "an argument buffer's texture of a type the identity arrays hold no element of" + .to_owned(), + ); + } + if h.plain.is_some() { + return Some( + "an argument buffer's depth texture both compared and sampled without comparison" + .to_owned(), + ); + } + if h.raw.is_some() { + return Some( + "an argument buffer's texture read as the raw texels of an extended-range member" + .to_owned(), + ); + } + if !h.cross.is_empty() { + return Some( + "an argument buffer's texture read through another numeric type than its own" + .to_owned(), + ); + } + } + let lookup = plan.families.access.lookup(); let entry = matches!( - plan.families.access.lookup(), + lookup, crate::memory::handles::Lookup::Element | crate::memory::handles::Lookup::Flagged { class: false, @@ -1971,45 +2021,74 @@ fn identity_admits(plan: &Plan, p: &DeviceProfile) -> Result<(), Error> { .. } ); - let textures = groups - && entry - && t.heap_raw.is_empty() - && !t.heap_half - && t.slots.values().all(|s| s.identity_lowered()); + if !entry { + return Some(format!( + "a texture handle that reads its table entry beyond its element ({lookup:?})" + )); + } + if !t.heap_raw.is_empty() { + return Some( + "a read of an argument buffer's texture that decodes an extended-range member" + .to_owned(), + ); + } + if t.heap_half { + return Some( + "a sample or gather of an argument buffer's color texture with a half result" + .to_owned(), + ); + } + if let Some(s) = t.slots.values().find(|s| !s.identity_lowered()) { + return Some(format!( + "texture argument {:?}: a type the identity arrays hold no element of, or state of \ + the bound texture beyond its resource ID", + s.slot + )); + } // Samples only of a texture slot through a runtime sampler slot or a constexpr sampler // (`sampler::IdentitySampling`), a runtime sampler's word read from its resource ID: no // argument buffer's sampler, array of samplers, bicubic filter or specialization of a slot's // state. let sampled = &plan.families.sampler; - let sampling = sampled - .combined - .iter() - .all(|k| sampled.identity.contains_key(k)) - && sampled.decls.is_empty() - && sampled.heap.is_empty() - && sampled.heap_samplers.is_empty() - && sampled.arrays.is_empty() - && sampled.heap_arrays.is_empty() - && sampled.bicubic.is_empty() - && sampled.bicubic_routines.is_empty() - && !sampled.cubic_reach - && sampled.slots.values().all(|r| !r.min_level && !r.emulated); - let stage = match plan.stage { - Stage::Kernel => true, - Stage::Vertex | Stage::Fragment => p.push_window() == PushWindow::Floor, - _ => false, - }; - if stage - && fields - && addressed - && textures - && sampling - && !plan.facts.iter().any(identity_unsourced) - && plan.descriptors.descriptors() == 0 - { - return Ok(()); + let refused = [ + ( + !(sampled.combined.iter()).all(|k| sampled.identity.contains_key(k)) + || !sampled.decls.is_empty(), + "a texture argument sampled through a sampler the identity sampling does not take", + ), + ( + !sampled.heap.is_empty(), + "a sample, gather or comparison of an argument buffer's texture", + ), + ( + !sampled.heap_samplers.is_empty() || sampled.cubic_reach, + "an argument buffer's sampler", + ), + ( + !sampled.arrays.is_empty() || !sampled.heap_arrays.is_empty(), + "an array of samplers", + ), + ( + !sampled.bicubic.is_empty() || !sampled.bicubic_routines.is_empty(), + "a bicubic filter", + ), + ( + (sampled.slots.values()).any(|r| r.min_level || r.emulated), + "a sampler argument whose minimum level or emulated filter the function specializes", + ), + ]; + if let Some((_, form)) = refused.iter().find(|(refused, _)| *refused) { + return Some((*form).to_owned()); } - Err(Unsupported::not_implemented(Feature::IdentityDomains).into()) + if let Some(f) = plan.facts.iter().find(|f| identity_unsourced(f)) { + return Some(format!( + "state of a bound texture or sampler beyond its resource ID ({f:?})" + )); + } + if plan.descriptors.descriptors() != 0 { + return Some("a resource bound through a descriptor".to_owned()); + } + None } /// The words the predicated walk of `plan` adds for the constructs of its structured tree diff --git a/crates/metal2vulkan/src/tests/engine_identity.rs b/crates/metal2vulkan/src/tests/engine_identity.rs index d2f4bfb51..4e552c2e6 100644 --- a/crates/metal2vulkan/src/tests/engine_identity.rs +++ b/crates/metal2vulkan/src/tests/engine_identity.rs @@ -743,6 +743,50 @@ fn a_bicubic_kernel_is_refused_under_the_identity_domains() { } } +/// What the identity domains' refusal of argument buffers tier 2's pointer-indexed form names, the +/// first form of the gate `ab_indexed` holds (`lower::select`'s `identity_refusal`): the texture +/// handle a pointer member's argument buffer holds is read through the root table, whose address +/// the identity domains do not push. +const POINTER_INDEXED_FORM: &str = "an encoder value the function reads as RootTableAddress"; + +/// Argument buffers tier 2's forms under the identity domains (`engine/ab_tier2`): a kernel that +/// copies a texture member from one argument buffer to another (`ab_copy`) and one that reads a +/// texel through an argument buffer's texture (`ab_read`) are lowered, and one that reads the +/// texture of an argument buffer a pointer member of the bound one reaches (`ab_indexed`) is +/// refused as `Unsupported{IdentityDomains}`, not implemented, naming the form the gate refuses +/// ([`POINTER_INDEXED_FORM`]), where the default domains compile it. +#[test] +fn a_texture_of_an_argument_buffer_a_pointer_member_reaches_is_refused_under_the_identity_domains() +{ + let Some(bc) = assemble("ab_tier2") else { + return; + }; + for stem in PROFILES { + let default = profile(stem, DevicePolicy::default()).unwrap_or_else(|e| panic!("{e}")); + compile(&bc, "ab_indexed", &default) + .unwrap_or_else(|e| panic!("{stem}: ab_indexed: default domains: {e}")); + let p = profile(stem, identity()).unwrap_or_else(|e| panic!("{e}")); + for entry in ["ab_copy", "ab_read"] { + compile(&bc, entry, &p).unwrap_or_else(|e| panic!("{stem}: {entry}: {e}")); + } + match compile(&bc, "ab_indexed", &p) { + Err(Error::Unsupported(u)) => { + assert_eq!( + (u.feature, u.needs), + (Feature::IdentityDomains, Needs::NotImplemented), + "{stem}" + ); + assert_eq!( + u.symbol.map(|form| form.to_string()).as_deref(), + Some(POINTER_INDEXED_FORM), + "{stem}" + ); + } + other => panic!("{stem}: {other:?}"), + } + } +} + /// Under the identity domains a kernel that encodes indirect commands is refused for that feature, /// `Unsupported{GpuEncodedIndirectCommands}`, not implemented, on every profile. #[test] diff --git a/docs/API.md b/docs/API.md index 115f48685..5289fcb7f 100644 --- a/docs/API.md +++ b/docs/API.md @@ -170,11 +170,14 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`: static there: no constant or binder decides one. So far they lower a kernel that reaches memory through its buffer slots and reads, writes, sizes or tests for nil its texture slots and its argument buffers' textures, and samples its texture slots through its runtime sampler slots - and its constexpr samplers. Any other function is refused as `Unsupported{IdentityDomains}`: - one that samples through an argument buffer's sampler or an array of samplers or samples an - argument buffer's texture, emulates a sampler's anisotropy or bicubic filter, uses a texture buffer, a slot's levels or swizzle, a - two-plane, extended-range or sRGB-twin form, reads an argument buffer's texture through another - numeric type or as raw texels, or uses any other state of a texture or sampler beyond its ID. + and its constexpr samplers. Any other function is refused as `Unsupported{IdentityDomains}`, + whose symbol names the first such form the function holds: one that samples through an + argument buffer's sampler or an array of samplers or samples an argument buffer's texture, + emulates a sampler's anisotropy or bicubic filter, uses a texture buffer, a slot's levels or + swizzle, a two-plane, extended-range or sRGB-twin form, reads an argument buffer's texture + through another numeric type or as raw texels, reads the texture of an argument buffer that a + pointer another argument buffer holds reaches (it reads the root table, `RootTableAddress`), or + uses any other state of a texture or sampler beyond its ID. An argument buffer's texture reads the element at its ID's index masked to its low 16 bits, so a bad ID reads an element of the arrays ([RESOURCE-ID.md](RESOURCE-ID.md)); the change that first lowers an argument buffer's sampler masks its index the same way.