diff --git a/crates/metal2vulkan-air/src/abi/module.rs b/crates/metal2vulkan-air/src/abi/module.rs index 7155d03ca..237e16763 100644 --- a/crates/metal2vulkan-air/src/abi/module.rs +++ b/crates/metal2vulkan-air/src/abi/module.rs @@ -120,6 +120,9 @@ pub(super) fn decode( pointees, layouts, }; + // `agx.allow_mismatched_component_counts` stated as 1: the module's, so its producing + // functions' (`EntryPoint::mismatched_component_counts`). + let mut mismatched = false; for &(kind, ops) in &lists { let site = Site::module(); match kind { @@ -137,7 +140,9 @@ pub(super) fn decode( n.finish()?; } Named::CompileOptions => abi.compile = compile_options(m, ops, &site, cx.meter)?, - Named::ModuleFlags => abi.limits = module_flags(m, ops, &site, cx.meter)?, + Named::ModuleFlags => { + (abi.limits, mismatched) = module_flags(m, ops, &site, cx.meter)?; + } Named::Ident => { // Only the first producer is kept, so only it is allocated and charged. for &id in ops { @@ -271,7 +276,7 @@ pub(super) fn decode( } cx.meter.reserve(&mut abi.entries, ops.len())?; for &id in ops { - abi.entries.push(entry(&mut cx, stage, id)?); + abi.entries.push(entry(&mut cx, stage, id, mismatched)?); } } } @@ -387,30 +392,35 @@ fn plain_signature(n: &mut Ops<'_>, site: &Site) -> Result, !"", }`. The `air.max_*` limits are -/// decoded; `wchar_size`, `frame-pointer`, `SDK Version`, and debug info's `Dwarf Version` and -/// `Debug Info Version` are LLVM's and carry nothing the translation reads, and neither do -/// `agx.allow_mismatched_component_counts` (an integer, 0 or 1) and `irc.version_major`, +/// decoded, and returned with whether `agx.allow_mismatched_component_counts` (an integer, 0 or +/// 1, stated at most once) is 1, which the module's vertex and mesh functions carry +/// (`EntryPoint::mismatched_component_counts`, which says what it changes). `wchar_size`, +/// `frame-pointer`, `SDK Version`, and debug info's `Dwarf Version` and `Debug Info Version` are +/// LLVM's and carry nothing the translation reads, and neither do `irc.version_major`, /// `irc.version_minor` and `irc.version_patch` (integers), each stated once: their shapes are -/// checked and nothing is kept. `air.workaround.sampler_state_variable_length_encoding` (an `i1`) -/// names the form of the module's constexpr sampler words, which each `air.sampler_state` global's -/// own type states. Any other flag is unknown. +/// checked and nothing is kept (a measured render pipeline linked the same whatever they state). +/// `air.workaround.sampler_state_variable_length_encoding` (an `i1`) names the form of the +/// module's constexpr sampler words, which each `air.sampler_state` global's own type states. Any +/// other flag is unknown. fn module_flags( m: &Module, ops: &[MdId], site: &Site, meter: &mut Meter, -) -> Result { +) -> Result<(ModuleLimits, bool), Error> { let key = Some("llvm.module.flags"); let mut l = ModuleLimits::default(); let (mut mismatch, mut major, mut minor, mut patch) = (false, false, false, false); + let mut mismatched = false; for &id in ops { meter.tick(1)?; let mut n = Ops::node(m, id, site.clone())?; n.u32(key)?; let flag = n.string(key)?; // The converter's flags: an integer each, stated once; the agx flag 0 or 1. + let agx = flag == b"agx.allow_mismatched_component_counts"; let shape = match flag { - b"agx.allow_mismatched_component_counts" => Some((&mut mismatch, 1)), + _ if agx => Some((&mut mismatch, 1)), b"irc.version_major" => Some((&mut major, u32::MAX)), b"irc.version_minor" => Some((&mut minor, u32::MAX)), b"irc.version_patch" => Some((&mut patch, u32::MAX)), @@ -418,9 +428,11 @@ fn module_flags( }; if let Some((seen, limit)) = shape { let repeated = std::mem::replace(seen, true); - if n.u32(key)? > limit || repeated { + let value = n.u32(key)?; + if value > limit || repeated { return Err(site.err(AbiError::BadValue, key)); } + mismatched |= agx && value == 1; n.finish()?; continue; } @@ -455,7 +467,7 @@ fn module_flags( } n.finish()?; } - Ok(l) + Ok((l, mismatched)) } /// `!{ptr @init, !"", !"", i32 [, i1 ]}`. @@ -521,8 +533,15 @@ fn global_binding(cx: &mut Cx<'_, '_>, id: MdId, site: &Site) -> Result...}`. -fn entry(cx: &mut Cx<'_, '_>, stage: Named, id: MdId) -> Result { +/// An entry node: `!{ptr @fn, !outputs, !inputs, ...}`, of a module whose +/// `agx.allow_mismatched_component_counts` is 1 where `mismatched`, which a vertex or mesh +/// function carries. +fn entry( + cx: &mut Cx<'_, '_>, + stage: Named, + id: MdId, + mismatched: bool, +) -> Result { cx.meter.tick(1)?; let m = cx.m; let module_site = Site::module(); @@ -616,7 +635,8 @@ fn entry(cx: &mut Cx<'_, '_>, stage: Named, id: MdId) -> Result Error { )) } +/// The refusal of fragment input `input` of type `read` whose producer `producer` writes its key +/// as `written` (`None`: not at all): Metal's link error, but for a type that differs in +/// component count alone behind a producer of [`StageIo::mismatched_component_counts`], which +/// Metal links and this translator does not yet (see the module docs). +fn unmatched(producer: &StageIo, written: Option, read: IoType) -> Error { + let counts_alone = written.is_some_and(|w| { + w.numeric == read.numeric + && w.source_bits == read.source_bits + && w.components != read.components + }); + if counts_alone && producer.mismatched_component_counts { + Unsupported::not_implemented(Feature::UnmatchedVarying).into() + } else { + Unsupported::not_representable(Feature::UnmatchedVarying).into() + } +} + fn limit_error(limit: VkLimit, locations: u64, max_components: u32) -> Error { Unsupported::needs( Feature::InterfaceComponents, @@ -296,7 +315,7 @@ fn mesh_fragment( .get(&x.key) .copied() .ok_or_else(|| invariant("a mesh output without its location"))?, - _ => return Err(Unsupported::not_representable(Feature::UnmatchedVarying).into()), + o => return Err(unmatched(m, o.map(|o| o.ty), x.ty)), }; end = end.max(u64::from(at.0) + 1); } @@ -473,7 +492,7 @@ fn varyings<'a>( matched.insert(&x.key); *interp } - Some(_) => return Err(Unsupported::not_representable(Feature::UnmatchedVarying).into()), + Some((ty, _)) => return Err(unmatched(v, Some(x.ty), *ty)), None => None, }; out.push(Varying { diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index f03faf02e..5bf1913ea 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -26,7 +26,7 @@ Columns: | Kind | Variants | With a site | Reach system | Reach app | Reach rare | Reach none | Unassessed | |---|---|---|---|---|---|---|---| -| Translator and front-end refusals | 111 | 111 | 6 | 23 | 61 | 21 | 0 | +| Translator and front-end refusals | 111 | 111 | 6 | 23 | 62 | 20 | 0 | | Translation caps | 14 | 14 | 0 | 0 | 7 | 7 | 0 | | Rate maps the compile layer does not compile | 5 | 5 | 0 | 0 | 4 | 1 | 0 | | The translation deadline | 1 | 1 | 0 | 0 | 0 | 1 | 0 | @@ -39,7 +39,7 @@ Columns: | Kind | `metal-measured` | `metal-documented` | `metal-takes` | `device` | `ours` | `unknown` | `delegated` | `-` | |---|---|---|---|---|---|---|---|---| -| Translator and front-end refusals | 0 | 0 | 3 | 41 | 67 | 0 | 0 | 0 | +| Translator and front-end refusals | 0 | 0 | 3 | 40 | 68 | 0 | 0 | 0 | | Translation caps | 0 | 0 | 0 | 0 | 14 | 0 | 0 | 0 | | Rate maps the compile layer does not compile | 0 | 0 | 0 | 0 | 5 | 0 | 0 | 0 | | The translation deadline | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | @@ -115,7 +115,7 @@ Columns: | `DivergentInterpolation` | Metal's pull-model interpolation at a sample or an offset (`interpolate_at_sample`, `interpolate_at_offset`) outside the fragment function's first... | every device (not implemented) | `ours` | 1: `crates/metal2vulkan/src/lower/stage_io/plan.rs (interpolant_reads)` | `rare`: an interpolant read at a sample or an offset in a branch, a loop or after a discard | | `PixelCoverageAtSampleRate` | The pixel's coverage (`[[sample_mask]]` read) in a fragment function that runs once per sample | every device (no Vulkan mechanism); every device (not implemented) | `ours` | 2: `crates/metal2vulkan/src/lower/simd/mod.rs (select_param)`, `crates/metal2vulkan/src/pipeline/link/graphics.rs (sample_invocations)` | `rare`: coverage read at sample rate | | `InterfaceComponents` | Too many interface components or locations | devices short of a device limit the site names; devices without VkLimit::MaxColorAttachments; devices without VkLimit::MaxVertexInputAttributes | `device` | 3: `crates/metal2vulkan/src/pipeline/link/graphics.rs (graphics_state)`, `crates/metal2vulkan/src/pipeline/link/varyings.rs (assign)` (+1) | `rare`: too many varyings or attachments for a device | -| `UnmatchedVarying` | A fragment input without a vertex producer (a Metal link error) | every device (no Vulkan mechanism) | `device` | 3: `crates/metal2vulkan/src/pipeline/link/varyings.rs (mesh_fragment)`, `crates/metal2vulkan/src/pipeline/link/varyings.rs (varyings, 2 sites)` | `none`: a Metal link error | +| `UnmatchedVarying` | A fragment input without a vertex or mesh output of its key and type | every device (no Vulkan mechanism); every device (not implemented) | `ours` | 3: `crates/metal2vulkan/src/pipeline/link/varyings.rs (unmatched, 2 sites)`, `crates/metal2vulkan/src/pipeline/link/varyings.rs (varyings)` | `rare`: a varying read at another component count than written, behind a vertex module stating agx.allow_mismatched_component_counts as 1 (seen in modules Apple's Metal shader converter wrote); otherwise a Metal link error | | `VertexStepRate` | A vertex buffer layout stepped per instance at a rate above 1, on a profile that fetches every attribute in fixed function (the identity domains,... | devices without a capability the site computes (`needs`) | `device` | 1: `crates/metal2vulkan/src/metal/vertex.rs (divided)` | `app`: instanced vertex layouts stepped at a rate above 1 | | `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 | @@ -150,7 +150,7 @@ Columns: | `DepthClipClamp` | The render encoder's `MTLDepthClipModeClamp` (`depthClampEnable`) on a device without `depthClamp` | devices short of a Vulkan feature the site names | `device` | via a helper: 1: `crates/metal2vulkan/src/metal/state.rs (depth_clamp_enable)` | `app`: depth clamp on a device without depthClamp | | `DepthBiasClamp` | The render encoder's depth bias clamp, nonzero with a nonzero bias, on a device without `depthBiasClamp` | devices short of a Vulkan feature the site names | `device` | via a helper: 1: `crates/metal2vulkan/src/metal/state.rs (depth_bias)` | `app`: depth bias clamp on a device without depthBiasClamp | | `ConstantAlphaBlendFactor` | `CONSTANT_ALPHA` or `ONE_MINUS_CONSTANT_ALPHA` (Metal's `BlendAlpha` factors) as a color blend factor on a portability-subset device without... | devices without VkFeature::ConstantAlphaColorBlendFactors | `device` | 1: `crates/metal2vulkan/src/metal/state.rs (check_constant_alpha)` | `app`: blend-alpha factors on a portability-subset device without them | -| `TextureSwizzle` | A texture swizzle whose Metal behavior is not measured | every device (not implemented) | `ours` | 5: `crates/metal2vulkan/src/bind/heap.rs (member_texel_view)`, `crates/metal2vulkan/src/lower/sampler/select.rs (select_one)` (+3) | `app`: texture swizzles whose Metal behaviour is unmeasured | +| `TextureSwizzle` | A texture swizzle whose Metal behavior is not measured | every device (not implemented) | `ours` | 1: `crates/metal2vulkan/src/bind/heap.rs (member_texel_view)` | `app`: texture swizzles whose Metal behaviour is unmeasured | | `PrivateMemory` | A stage whose private memory (its `thread` variables and arrays, and the constants it holds per thread) takes more Function storage a thread than... | devices without a capability the site computes (`limit`) | `device` | 1: `crates/metal2vulkan/src/lower/access/local.rs (device_arena)` | `rare`: very large per-thread arrays | | `Reflection` | Reflection of an argument whose answer Metal's has not been measured for (`reflection`) | every device (not implemented) | `ours` | 8: `crates/metal2vulkan/src/reflection/derive.rs (gap_at)`, `crates/metal2vulkan/src/reflection/derive.rs (read_attributes)` (+6) | `rare`: reflection of argument kinds Metal's answer is unmeasured for | | `IndirectRenderState` | A `depth_stencil_state` a function reads from an argument buffer or takes as a parameter, the state of an indirect render command, which no record... | every device (not implemented) | `ours` | via a helper: 2: `crates/metal2vulkan/src/lower/access/pointer.rs (unlowered)`, `crates/metal2vulkan/src/lower/select.rs (param_family)` | `rare`: render state set by a kernel on an indirect command | @@ -444,7 +444,7 @@ Each refusal's sites, with the function that builds it. - `feature::DivergentInterpolation`: `crates/metal2vulkan/src/lower/stage_io/plan.rs (interpolant_reads)` - `feature::PixelCoverageAtSampleRate`: `crates/metal2vulkan/src/lower/simd/mod.rs (select_param)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs (sample_invocations)` - `feature::InterfaceComponents`: `crates/metal2vulkan/src/pipeline/link/graphics.rs (graphics_state)`; `crates/metal2vulkan/src/pipeline/link/varyings.rs (assign)`; `crates/metal2vulkan/src/pipeline/link/varyings.rs (limit_error)` -- `feature::UnmatchedVarying`: `crates/metal2vulkan/src/pipeline/link/varyings.rs (mesh_fragment)`; `crates/metal2vulkan/src/pipeline/link/varyings.rs (varyings, 2 sites)` +- `feature::UnmatchedVarying`: `crates/metal2vulkan/src/pipeline/link/varyings.rs (unmatched, 2 sites)`; `crates/metal2vulkan/src/pipeline/link/varyings.rs (varyings)` - `feature::VertexStepRate`: `crates/metal2vulkan/src/metal/vertex.rs (divided)` - `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)` @@ -479,7 +479,7 @@ Each refusal's sites, with the function that builds it. - `feature::DepthClipClamp`: `crates/metal2vulkan/src/metal/state.rs (depth_clamp_enable)` - `feature::DepthBiasClamp`: `crates/metal2vulkan/src/metal/state.rs (depth_bias)` - `feature::ConstantAlphaBlendFactor`: `crates/metal2vulkan/src/metal/state.rs (check_constant_alpha)` -- `feature::TextureSwizzle`: `crates/metal2vulkan/src/bind/heap.rs (member_texel_view)`; `crates/metal2vulkan/src/lower/sampler/select.rs (select_one)`; `crates/metal2vulkan/src/lower/texture/mod.rs (select_read)`; `crates/metal2vulkan/src/lower/texture/mod.rs (select_write)`; `crates/metal2vulkan/src/lower/texture/slice.rs (select)` +- `feature::TextureSwizzle`: `crates/metal2vulkan/src/bind/heap.rs (member_texel_view)` - `feature::PrivateMemory`: `crates/metal2vulkan/src/lower/access/local.rs (device_arena)` - `feature::Reflection`: `crates/metal2vulkan/src/reflection/derive.rs (gap_at)`; `crates/metal2vulkan/src/reflection/derive.rs (read_attributes)`; `crates/metal2vulkan/src/reflection/derive.rs (specialized_reads)`; `crates/metal2vulkan/src/reflection/function.rs (attribute)`; `crates/metal2vulkan/src/reflection/function.rs (module_constants)`; `crates/metal2vulkan/src/reflection/function.rs (unmeasured)`; `crates/metal2vulkan/src/reflection/linked.rs (function)`; `crates/metal2vulkan/src/reflection/mod.rs (kernel_stage)` - `feature::IndirectRenderState`: `crates/metal2vulkan/src/lower/access/pointer.rs (unlowered)`; `crates/metal2vulkan/src/lower/select.rs (param_family)` diff --git a/scripts/refusal-surface/reach.tsv b/scripts/refusal-surface/reach.tsv index e93f9a144..25cd4156e 100644 --- a/scripts/refusal-surface/reach.tsv +++ b/scripts/refusal-surface/reach.tsv @@ -65,7 +65,7 @@ feature PullModelInterpolation rare interpolant inputs read at the centroid, a s feature DivergentInterpolation rare an interpolant read at a sample or an offset in a branch, a loop or after a discard feature PixelCoverageAtSampleRate rare coverage read at sample rate feature InterfaceComponents rare too many varyings or attachments for a device -feature UnmatchedVarying none a Metal link error +feature UnmatchedVarying rare a varying read at another component count than written, behind a vertex module stating agx.allow_mismatched_component_counts as 1 (seen in modules Apple's Metal shader converter wrote); otherwise a Metal link error feature VertexStepRate app instanced vertex layouts stepped at a rate above 1 feature VertexInputLayout rare vertex offsets or strides off their format's alignment, or past a device's limits feature Tessellation rare tessellation