From 83e5e067891afe4e17b2c0d22c00e6576da69773 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Tue, 10 Nov 2026 05:32:20 -0800 Subject: [PATCH] DescriptorError::ColorAttachment carries Metal's answer: nil with an NSError, or the process ends A layer that answers as Metal does needs to know, per refused pipeline, whether Metal returns nil with an NSError or its descriptor validation asserts and ends the process. ColorAttachment now carries `metal: MetalAnswer` (NilWithError | EndsProcess), set at each of its 17 sites from plain Metal's answer on an Apple M3 Max under macOS 27.0.1 (probes/color_attachment_answers.m, no MTL_DEBUG_LAYER, job m3-max-13738): - EndsProcess (SIGABRT, "Render Pipeline Descriptor Validation"): blending on a bfloat attachment, with a function, a fetching function or none ("... MTLPixelFormatRGBA16Bfloat for this render target is not blendable."); alpha to coverage over an integer attachment 0, rasterizing or not ("... alphaToCoverageEnabled requires a float/unorm pixel format ..."). The link's doc said the second was unmeasured with rasterization off; it is measured now. - NilWithError (code 3, domain AGXMetalG15X_M1): an output of another numeric class (half4, float4 and int4 into RGBA8Uint; uint4 into RGBA8Unorm and RGBA8Sint; a fetching uint4 of RGBA8Unorm); a color input of another class (uint4 of RGBA8Unorm, BGR10_XR, A8Unorm); fewer output components than channels (with and without fetch); a blend of the second source without the second output, or without the first (with and without fetch); a color input without an attachment; a tile function's imageblock member without a format ("Invalid pixel format for render target 1"). - A `Compiled` tile function compiled under another format than the descriptor's has no Metal counterpart (Metal compiles the function for its pipeline) and answers EndsProcess, the answer of an unmeasured case; under no format it answers Metal's NilWithError. Public API: the new `error::MetalAnswer` and the changed variant are in api_signatures.tsv and the api_surface table. Refusals are not serialized in any cache, and translation output is unchanged, so neither ARTIFACT_FORMAT_VERSION nor SEMANTICS_VERSION moves. docs/REFUSALS.md regenerates unchanged (descriptor errors are not in it). docs/API.md states the two answers. Tests: each existing test of a ColorAttachment refusal now names its answer (bfloat blends, alpha to coverage, a tile function compiled for other formats: EndsProcess; output class and components, the second source, unattached inputs, unformatted tile members: NilWithError), and a new unit test holds the storage form's class refusal to NilWithError for reads and writes. (cherry picked from commit cd17476e5a4ae2b9fbf8118453ad089691adaba2) --- .../metal2vulkan-runtime/src/pipeline/tile.rs | 7 +-- .../metal2vulkan-validation/src/acceptance.rs | 2 +- .../src/candidate/engine/graphics.rs | 7 ++- .../src/candidate/engine/mesh.rs | 7 ++- .../src/candidate/engine/variants.rs | 5 ++- .../src/runtime_lane/color_groups.rs | 8 +++- .../src/runtime_lane/tile_states.rs | 7 ++- crates/metal2vulkan/src/error/mod.rs | 43 +++++++++++++++--- crates/metal2vulkan/src/lower/access/tile.rs | 3 +- .../metal2vulkan/src/lower/fragment/color.rs | 6 ++- .../metal2vulkan/src/lower/fragment/fetch.rs | 17 +++++-- .../src/lower/fragment/fetch/tests.rs | 45 ++++++++++++++++++- .../src/lower/fragment/input_blend.rs | 8 +++- .../src/lower/stage_io/extended_color.rs | 7 ++- crates/metal2vulkan/src/pipeline/compile.rs | 4 +- .../metal2vulkan/src/pipeline/compile/api.rs | 25 +++++++---- .../src/pipeline/link/graphics.rs | 33 +++++++++----- .../src/pipeline/link/tests/render.rs | 22 ++++++--- .../src/tests/engine_dead_reads.rs | 3 +- .../tests/engine_extended_range/targets.rs | 12 +++-- .../src/tests/engine_fetch_blend8.rs | 7 ++- .../src/tests/engine_fetch_generic_blend.rs | 7 ++- .../metal2vulkan/src/tests/engine_fragment.rs | 1 + crates/metal2vulkan/src/tests/engine_link.rs | 29 +++++++++--- .../src/tests/engine_padded_blends.rs | 7 ++- crates/metal2vulkan/src/tests/engine_tile.rs | 8 ++-- crates/metal2vulkan/tests/api_signatures.tsv | 5 ++- crates/metal2vulkan/tests/api_surface.rs | 6 ++- docs/API.md | 7 +++ 29 files changed, 273 insertions(+), 75 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/pipeline/tile.rs b/crates/metal2vulkan-runtime/src/pipeline/tile.rs index 377dd6079..2b3e9728a 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/tile.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/tile.rs @@ -7,9 +7,10 @@ //! as `compile_tile_pipeline` compiles it, with a compute state's variants, stand-ins, memo, //! archives and disk cache. What the compile refuses is refused (`Compile`, `Unsupported`): //! among it a function that reaches an attachment without a format in the descriptor -//! (`InvalidDescriptor(ColorAttachment)`), where Metal's creation answers "Invalid pixel format -//! for render target 0", and a member whose type the attachment's format does not hold, which -//! Metal's API validation stops (an M3 Max and an M4). +//! (`InvalidDescriptor(ColorAttachment)` answering `MetalAnswer::NilWithError`), where Metal's +//! creation answers nil and "Invalid pixel format for render target 0", and a member whose +//! type the attachment's format does not hold, which Metal's API validation stops (an M3 Max +//! and an M4). //! - **Answers.** A tile pipeline's state answers its descriptor's //! `threadgroup_size_matches_tile_size`, no indirect command buffers, and a //! `max_total_threads_per_threadgroup`. That is the threads of the descriptor's diff --git a/crates/metal2vulkan-validation/src/acceptance.rs b/crates/metal2vulkan-validation/src/acceptance.rs index 550d884de..f74022df8 100644 --- a/crates/metal2vulkan-validation/src/acceptance.rs +++ b/crates/metal2vulkan-validation/src/acceptance.rs @@ -1637,7 +1637,7 @@ mod tests { /// A fragment row whose outputs have fewer than four components compiles: its attachments have /// no more channels than its outputs write, which the product, as Metal, requires (a `uint2` - /// target into `RGBA32Uint` was `InvalidDescriptor(ColorAttachment { index: 2 })`). + /// target into `RGBA32Uint` was `InvalidDescriptor(ColorAttachment { index: 2, .. })`). #[test] fn a_fragment_row_with_narrow_outputs_compiles_into_its_derived_attachments() { let Some(bitcode) = fixture("signed_color.ll") else { diff --git a/crates/metal2vulkan-validation/src/candidate/engine/graphics.rs b/crates/metal2vulkan-validation/src/candidate/engine/graphics.rs index c8980c3b5..6767b8de6 100644 --- a/crates/metal2vulkan-validation/src/candidate/engine/graphics.rs +++ b/crates/metal2vulkan-validation/src/candidate/engine/graphics.rs @@ -65,7 +65,7 @@ use metal2vulkan::bind::{ BindShape, BindState, BoundBuffer, DrawCall, IndexBufferRef, RasterizationRateMap, RateMapRegions, RegionLimits, StageTable, TessellationFactorBuffer, TessellationFactors, }; -use metal2vulkan::error::{DescriptorError, Error}; +use metal2vulkan::error::{DescriptorError, Error, MetalAnswer}; use metal2vulkan::library::FunctionConstantValues; use metal2vulkan::metal::{self, RenderStages}; use metal2vulkan::pipeline::Stage as ShaderStage; @@ -1108,7 +1108,10 @@ impl RenderTemplate { descriptor.vertex_descriptor = self.vertex_descriptor.clone(); for (&index, attachment) in &self.color_attachments { let slot = descriptor.color_attachments.get_mut(index as usize).ok_or( - Error::InvalidDescriptor(DescriptorError::ColorAttachment { index }), + Error::InvalidDescriptor(DescriptorError::ColorAttachment { + index, + metal: MetalAnswer::EndsProcess, + }), )?; *slot = Some(*attachment); } diff --git a/crates/metal2vulkan-validation/src/candidate/engine/mesh.rs b/crates/metal2vulkan-validation/src/candidate/engine/mesh.rs index a35355f3d..a29ed20b7 100644 --- a/crates/metal2vulkan-validation/src/candidate/engine/mesh.rs +++ b/crates/metal2vulkan-validation/src/candidate/engine/mesh.rs @@ -28,7 +28,7 @@ use crate::companion::Companion; use crate::engine::RowSource; use crate::literal::LiteralResources; use metal2vulkan::bind::{BindShape, BindState, BoundBuffer}; -use metal2vulkan::error::{DescriptorError, Error}; +use metal2vulkan::error::{DescriptorError, Error, MetalAnswer}; use metal2vulkan::library::FunctionConstantValues; use metal2vulkan::pipeline::Stage as ShaderStage; use metal2vulkan::pipeline::{ColorAttachmentDescriptor, MeshPipelineDescriptor, StageSource}; @@ -230,7 +230,10 @@ impl MeshTemplate { descriptor.rasterization_enabled = self.rasterization; for (&index, attachment) in &self.color_attachments { let slot = descriptor.color_attachments.get_mut(index as usize).ok_or( - Error::InvalidDescriptor(DescriptorError::ColorAttachment { index }), + Error::InvalidDescriptor(DescriptorError::ColorAttachment { + index, + metal: MetalAnswer::EndsProcess, + }), )?; *slot = Some(*attachment); } diff --git a/crates/metal2vulkan-validation/src/candidate/engine/variants.rs b/crates/metal2vulkan-validation/src/candidate/engine/variants.rs index de569d9ff..21ed4c3f8 100644 --- a/crates/metal2vulkan-validation/src/candidate/engine/variants.rs +++ b/crates/metal2vulkan-validation/src/candidate/engine/variants.rs @@ -28,7 +28,9 @@ use metal2vulkan::bind::{BindShape, Dispatch, TextureShape}; use metal2vulkan::cache::VariantKey; use metal2vulkan::device::{Device, DeviceProfile}; -use metal2vulkan::error::{DescriptorError, Error, InternalError, InternalKind, RuntimeInput}; +use metal2vulkan::error::{ + DescriptorError, Error, InternalError, InternalKind, MetalAnswer, RuntimeInput, +}; use metal2vulkan::metal::format::storage_image_choice; use metal2vulkan::metal::PixelFormat; use metal2vulkan::pipeline::{ @@ -178,6 +180,7 @@ pub fn compile_tile_for_shape( .and_then(|index| descriptor.color_attachment_formats.get_mut(index)) .ok_or(Error::InvalidDescriptor(DescriptorError::ColorAttachment { index, + metal: MetalAnswer::EndsProcess, }))?; *attachment = Some(format); } diff --git a/crates/metal2vulkan-validation/src/runtime_lane/color_groups.rs b/crates/metal2vulkan-validation/src/runtime_lane/color_groups.rs index 29aeb88bb..f53137f9a 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/color_groups.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/color_groups.rs @@ -52,7 +52,8 @@ use crate::gpu::TEST_DEVICE; use crate::observation::PROFILES_LAYER; use metal2vulkan::device::VkLimit; use metal2vulkan::error::{ - Capability, DescriptorError, Error as CompileError, Feature, RuntimeDriverDefect, Unsupported, + Capability, DescriptorError, Error as CompileError, Feature, MetalAnswer, RuntimeDriverDefect, + Unsupported, }; use metal2vulkan::library::{FunctionConstantValue, FunctionConstantValues}; use metal2vulkan::metal::state::{DepthStencilDescriptor, StencilDescriptor}; @@ -851,7 +852,10 @@ fn dead_scene(lane: &Lane, five: &[usize]) { } // A color input without an attachment, read or not: Metal's pipeline error. let unattached = Error::Compile(CompileError::InvalidDescriptor( - DescriptorError::ColorAttachment { index: 1 }, + DescriptorError::ColorAttachment { + index: 1, + metal: MetalAnswer::NilWithError, + }, )); for reads in [false, true] { let made = dead_pipeline(lane, (&lane.rog, "dfr_lacks"), &[0], reads); diff --git a/crates/metal2vulkan-validation/src/runtime_lane/tile_states.rs b/crates/metal2vulkan-validation/src/runtime_lane/tile_states.rs index 427862b37..d64671a88 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/tile_states.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/tile_states.rs @@ -21,7 +21,7 @@ use super::render_state::texture; use super::{layer_reported_nothing_at_all, validated_device_with, Messages, ScratchCache}; use crate::air_library::AirLibrary; use crate::gpu::TEST_DEVICE; -use metal2vulkan::error::DescriptorError; +use metal2vulkan::error::{DescriptorError, MetalAnswer}; use metal2vulkan::metal::{PixelFormat, PrimitiveType}; use metal2vulkan::pipeline::{StageSource, TileRenderPipelineDescriptor}; use metal2vulkan_devtools::{engine_dir, llvm_assemble}; @@ -188,7 +188,10 @@ fn a_tile_state_is_refused_where_metal_refuses_it() { state(device, &missing), Err(Error::Compile( metal2vulkan::error::Error::InvalidDescriptor( - DescriptorError::ColorAttachment { index: 0 } + DescriptorError::ColorAttachment { + index: 0, + metal: MetalAnswer::NilWithError, + } ) )) ), diff --git a/crates/metal2vulkan/src/error/mod.rs b/crates/metal2vulkan/src/error/mod.rs index 3b6650202..ef69d5dc3 100644 --- a/crates/metal2vulkan/src/error/mod.rs +++ b/crates/metal2vulkan/src/error/mod.rs @@ -1847,6 +1847,20 @@ pub enum RuntimeInput { UniformVaryings, } +/// How Metal answers a pipeline it refuses, where a [`DescriptorError`] carries it +/// ([`DescriptorError::ColorAttachment`]): measured with plain Metal, no API validation layer, on +/// an Apple M3 Max under macOS 27.0.1. +#[non_exhaustive] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum MetalAnswer { + /// The creation call answers nil and an `NSError` (code 3, in the GPU driver's error domain, + /// `AGXMetalG15X_M1` on the device measured), and the process goes on. + NilWithError, + /// Metal's descriptor validation asserts ("Render Pipeline Descriptor Validation") and the + /// process ends (`SIGABRT`). Also the answer of a case whose Metal answer is not measured. + EndsProcess, +} + /// The caller's descriptor or request is inconsistent. #[non_exhaustive] #[derive(Clone, Debug, PartialEq, Eq)] @@ -1872,12 +1886,29 @@ pub enum DescriptorError { /// at: a set attribute names it and it has no layout, or it has a layout of a nonzero or /// dynamic stride and no set attribute names it. VertexLayout { layout: u32 }, - /// A color attachment format without a fragment output, or of the wrong type class; one a - /// fragment output has fewer components for than its channels; one whose blend reads a - /// second output the function does not write, or writes without the first; a bfloat one - /// (`R16Bfloat`, `RG16Bfloat`, `RGBA16Bfloat`) with blending enabled; or an integer - /// attachment 0 under alpha to coverage (Metal refuses each pipeline). - ColorAttachment { index: u32 }, + /// Color attachment `index` and the pipeline's function or blend disagree, and Metal refuses + /// the pipeline. `metal` is how, as plain Metal answers each case on an Apple M3 Max under + /// macOS 27.0.1 (`metal2vulkan-conformance/probes/color_attachment_answers.m`): + /// + /// - [`MetalAnswer::NilWithError`]: an output, or a `[[color(n)]]` input, of another numeric + /// class than the attachment's format ("output of type half4 is not compatible with a + /// MTLPixelFormatRGBA8Uint color attachment."; "input of type uint4 is not compatible + /// ..."); an output with fewer components than the format's channels ("fragment shader + /// color output does not have enough components for the pixel format"); a blend of the + /// second source whose function writes no second output, or no first ("Fragment shader + /// does not write to render target color(0), index(1) that is required for blending"); and + /// a `[[color(n)]]` input, or a tile function's imageblock member, of an attachment without + /// a format ("Shaders reads from a color attachment whose pixel format is + /// MTLPixelFormatInvalid"; "Invalid pixel format for render target 1"). + /// - [`MetalAnswer::EndsProcess`]: blending enabled on a bfloat attachment (`R16Bfloat`, + /// `RG16Bfloat`, `RGBA16Bfloat`), whatever the function writes and with no function ("the + /// pixelformat MTLPixelFormatRGBA16Bfloat for this render target is not blendable"); and + /// alpha to coverage over an integer attachment 0, rasterizing or not + /// ("MTLRenderPipelineDescriptor with alphaToCoverageEnabled requires a float/unorm pixel + /// format"). Also a `StageSource::Compiled` tile function compiled under another format of + /// the attachment than the descriptor gives it: Metal compiles a tile function for its + /// pipeline, so the case has no Metal answer to measure, and is answered as unmeasured. + ColorAttachment { index: u32, metal: MetalAnswer }, /// A raw Metal enum value outside the known set. UnknownEnumValue { ty: &'static str, value: u32 }, /// A pipeline descriptor without a required stage. diff --git a/crates/metal2vulkan/src/lower/access/tile.rs b/crates/metal2vulkan/src/lower/access/tile.rs index 2e3c493d6..1da7f10d4 100644 --- a/crates/metal2vulkan/src/lower/access/tile.rs +++ b/crates/metal2vulkan/src/lower/access/tile.rs @@ -121,7 +121,7 @@ use crate::air::ir::{Call, Const, Value}; use crate::device::profile::FloatFunctions; use crate::device::requirements::{FormatUsage, VkFeature}; use crate::error::{ - Attachment, Capability, DescriptorError, Error, Feature, RuntimeInput, Unsupported, + Attachment, Capability, DescriptorError, Error, Feature, MetalAnswer, RuntimeInput, Unsupported, }; use crate::lower::arith::{math, ops, pack, FloatFmt, Form, Held}; use crate::lower::dispatch::KernelBuiltin; @@ -551,6 +551,7 @@ fn build(cx: &SelectCx<'_>) -> Result { let Some(&pixel_format) = formats.get(&color) else { return Err(Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: color, + metal: MetalAnswer::NilWithError, })); }; let aliased = aliased_colors.contains(&color); diff --git a/crates/metal2vulkan/src/lower/fragment/color.rs b/crates/metal2vulkan/src/lower/fragment/color.rs index c401d5c1c..b261571fb 100644 --- a/crates/metal2vulkan/src/lower/fragment/color.rs +++ b/crates/metal2vulkan/src/lower/fragment/color.rs @@ -71,7 +71,9 @@ use crate::air::abi::{AbiInt, OutputRole, ParamBinding, ParamRole}; use crate::air::ir::{ArgIdx, TypeId as AirTypeId, Value}; use crate::device::requirements::VkFeature; -use crate::error::{Attachment, Capability, DescriptorError, Error, Feature, Unsupported}; +use crate::error::{ + Attachment, Capability, DescriptorError, Error, Feature, MetalAnswer, Unsupported, +}; use crate::lower::arith::legal::{form_on, refuse_int64_interface}; use crate::lower::arith::{extended_range, narrow, ops, Form, Held}; use crate::lower::emit::EmitCx; @@ -222,6 +224,7 @@ pub(super) fn select_param(cx: &mut SelectCx<'_>, b: &ParamBinding) -> Result, b: &ParamBinding) -> Result) -> Result<(), Error> { .is_some_and(|e| e.form.bfloat()) }); if let Some(&(color, _)) = bfloat { - let invalid = DescriptorError::ColorAttachment { index: color }; + let invalid = DescriptorError::ColorAttachment { + index: color, + metal: MetalAnswer::EndsProcess, + }; return Err(Error::InvalidDescriptor(invalid)); } let fetched = colors_read(cx, &body.used)?; @@ -1663,7 +1667,10 @@ pub(super) fn plan(cx: &mut SelectCx<'_>) -> Result<(), Error> { a.blending_enabled && a.equation.is_some_and(|eq| eq.reads_second_source()) }); if reads_second && second.is_none() { - let invalid = DescriptorError::ColorAttachment { index: color }; + let invalid = DescriptorError::ColorAttachment { + index: color, + metal: MetalAnswer::NilWithError, + }; return Err(Error::InvalidDescriptor(invalid)); } let generic_of = |view: StorageView, exact: &mut bool| { @@ -1978,6 +1985,7 @@ fn class_of(form: Form, numeric: SampledType, color: u32, write: bool) -> Result if !ok { return Err(Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: color, + metal: MetalAnswer::NilWithError, })); } if write && numeric == SampledType::Sint && !matches!(form.held, Held::Int { bits: 32, .. }) { @@ -2129,6 +2137,7 @@ pub fn select_output( if color_output_components(pf).is_some_and(|n| form.lanes < n) { return Err(Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: color, + metal: MetalAnswer::NilWithError, })); } plan_sample(cx)?; diff --git a/crates/metal2vulkan/src/lower/fragment/fetch/tests.rs b/crates/metal2vulkan/src/lower/fragment/fetch/tests.rs index e0208717c..88d485640 100644 --- a/crates/metal2vulkan/src/lower/fragment/fetch/tests.rs +++ b/crates/metal2vulkan/src/lower/fragment/fetch/tests.rs @@ -1043,6 +1043,48 @@ fn device_gaps_name_what_the_device_lacks() { ); } +/// A storage-form read or write of another numeric class than its attachment's format is Metal's +/// pipeline error, which Metal answers nil and an `NSError` ("input of type uint4 is not +/// compatible with a MTLPixelFormatRGBA8Unorm color attachment.", "output of type uint4 ...": an +/// Apple M3 Max under macOS 27.0.1, `color_attachment_answers.m`); a read or write of the +/// format's class is planned. +#[test] +fn a_read_or_write_of_another_class_is_refused_as_metal_answers_it() { + let uint4 = Form { + held: Held::Int { + bits: 32, + container: 32, + }, + lanes: 4, + }; + let float4 = Form { + held: Held::Float(FloatFmt::F32), + lanes: 4, + }; + let refused = Err(Error::InvalidDescriptor(DescriptorError::ColorAttachment { + index: 1, + metal: MetalAnswer::NilWithError, + })); + for write in [false, true] { + for (form, numeric) in [ + (uint4, SampledType::Float), + (float4, SampledType::Uint), + (float4, SampledType::Sint), + ] { + let got = class_of(form, numeric, 1, write); + assert_eq!(got, refused, "{form:?} into {numeric:?}, write {write}"); + } + for (form, numeric) in [ + (float4, SampledType::Float), + (uint4, SampledType::Uint), + (uint4, SampledType::Sint), + ] { + let got = class_of(form, numeric, 1, write); + assert_eq!(got, Ok(()), "{form:?} into {numeric:?}, write {write}"); + } + } +} + /// No attachment at the color read refuses the pipeline whatever the form. #[test] fn a_missing_attachment_is_a_descriptor_error() { @@ -1051,7 +1093,8 @@ fn a_missing_attachment_is_a_descriptor_error() { assert_eq!( storage_form(0, &none, false, READS, &p), Err(Error::InvalidDescriptor(DescriptorError::ColorAttachment { - index: 0 + index: 0, + metal: MetalAnswer::NilWithError, })) ); } diff --git a/crates/metal2vulkan/src/lower/fragment/input_blend.rs b/crates/metal2vulkan/src/lower/fragment/input_blend.rs index 04320ecc2..16a7a6166 100644 --- a/crates/metal2vulkan/src/lower/fragment/input_blend.rs +++ b/crates/metal2vulkan/src/lower/fragment/input_blend.rs @@ -55,7 +55,8 @@ use std::collections::BTreeMap; use crate::air::abi::{AbiInt, OutputRole}; use crate::air::ir::TypeId as AirTypeId; use crate::error::{ - Attachment, DescriptorError, Error, ExtendedRangeBlend, Feature, RuntimeInput, Unsupported, + Attachment, DescriptorError, Error, ExtendedRangeBlend, Feature, MetalAnswer, RuntimeInput, + Unsupported, }; use crate::lower::arith::{extended_range, FloatFmt, Form}; use crate::lower::emit::EmitCx; @@ -211,7 +212,10 @@ pub(super) fn plan(cx: &mut SelectCx<'_>) -> Result<(), Error> { return Err(tied(Unsupported::not_implemented(gap).into())); } None => { - let invalid = DescriptorError::ColorAttachment { index: color }; + let invalid = DescriptorError::ColorAttachment { + index: color, + metal: MetalAnswer::NilWithError, + }; return Err(Error::InvalidDescriptor(invalid)); } } diff --git a/crates/metal2vulkan/src/lower/stage_io/extended_color.rs b/crates/metal2vulkan/src/lower/stage_io/extended_color.rs index 0292a612c..fe126263d 100644 --- a/crates/metal2vulkan/src/lower/stage_io/extended_color.rs +++ b/crates/metal2vulkan/src/lower/stage_io/extended_color.rs @@ -36,7 +36,7 @@ //! is built: the output's write stores the raw texel of Metal's blend over the texel the input //! attachment reads, which `stage_io` writes through the output variable as it writes [`encode`]'s. -use crate::error::{DescriptorError, Error, Feature, Unsupported}; +use crate::error::{DescriptorError, Error, Feature, MetalAnswer, Unsupported}; use crate::lower::arith::extended_range; use crate::lower::arith::texel_round::{self, HalfRounding}; use crate::lower::arith::{FloatFmt, Form, Held}; @@ -83,7 +83,10 @@ pub(super) fn plan( // A blend into a bfloat attachment is Metal's pipeline error (link refuses it whatever the // function writes there). if e.blended && e.form.bfloat() { - let invalid = DescriptorError::ColorAttachment { index: color }; + let invalid = DescriptorError::ColorAttachment { + index: color, + metal: MetalAnswer::EndsProcess, + }; return Err(Error::InvalidDescriptor(invalid)); } let blended = e.blended && !cx.families.fragment.input_blends.contains_key(&color); diff --git a/crates/metal2vulkan/src/pipeline/compile.rs b/crates/metal2vulkan/src/pipeline/compile.rs index 962798fc6..26810ac09 100644 --- a/crates/metal2vulkan/src/pipeline/compile.rs +++ b/crates/metal2vulkan/src/pipeline/compile.rs @@ -36,7 +36,8 @@ use crate::cache::Hash256; use crate::cache::VariantKey; use crate::device::DeviceProfile; use crate::error::{ - DescriptorError, DiagName, Error, Feature, InternalError, InternalKind, Unsupported, + DescriptorError, DiagName, Error, Feature, InternalError, InternalKind, MetalAnswer, + Unsupported, }; use crate::library::function::FunctionSource; use crate::library::{ @@ -289,6 +290,7 @@ fn color_inputs_attached(spec: &air::Entry, inputs: InputsFrom<'_>) -> Result<() if !attached { return Err(Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: color, + metal: MetalAnswer::NilWithError, })); } } diff --git a/crates/metal2vulkan/src/pipeline/compile/api.rs b/crates/metal2vulkan/src/pipeline/compile/api.rs index d53b13f4e..8c6268aa5 100644 --- a/crates/metal2vulkan/src/pipeline/compile/api.rs +++ b/crates/metal2vulkan/src/pipeline/compile/api.rs @@ -28,7 +28,7 @@ use crate::device::requirements::{Requirements, VkExtension, VkFeature, VkLimit, use crate::device::{mechanism, Device, DeviceProfile}; use crate::error::{ ComputePipelineProblem, DescriptorError, Error, Feature, InternalError, InternalKind, - MeshPipelineProblem, RuntimeInput, Unsupported, + MeshPipelineProblem, MetalAnswer, RuntimeInput, Unsupported, }; use crate::library::{CompiledFunction, FunctionArtifact, FunctionCompileKey}; use crate::lower::select::LowerInputs; @@ -314,7 +314,7 @@ impl Device { /// render area, binding each attachment it reaches (`WriteSource::TileAttachment`). A /// `Compiled` tile function must have been compiled under the same formats: one compiled /// without tile inputs is `InvalidDescriptor(StageMismatch)`, and one that stages an attachment - /// the descriptor gives another format (`RuntimeFact::TileAttachmentFormat`) is + /// the descriptor gives another format, or none (`RuntimeFact::TileAttachmentFormat`), is /// `InvalidDescriptor(ColorAttachment)`. A multisampled pass (`raster_sample_count` above 1) is /// `Unsupported{TileShading, NotImplemented}`: what its imageblock's samples are is not read. /// The tile function's recursion is sized for `d`'s `maxCallStackDepth` as a compute kernel's @@ -1408,7 +1408,10 @@ fn check_tile_threadgroup( /// Each attachment the tile function of artifact `a` stages has the format it was compiled for in /// `d`: a `Compiled` tile function compiled under other formats is -/// `InvalidDescriptor(ColorAttachment)` (a `Function` one is compiled under `d`'s). +/// `InvalidDescriptor(ColorAttachment)` (a `Function` one is compiled under `d`'s). It answers +/// Metal's nil and `NSError` where `d` gives the attachment no format, as Metal answers a tile +/// function reaching one; under another format it answers `EndsProcess`, the answer of a case +/// with no Metal counterpart. fn check_tile_formats(a: &FunctionArtifact, d: &TileRenderPipelineDescriptor) -> Result<(), Error> { for fact in &a.facts { let RuntimeFact::TileAttachmentFormat { color, format } = *fact else { @@ -1417,11 +1420,17 @@ fn check_tile_formats(a: &FunctionArtifact, d: &TileRenderPipelineDescriptor) -> let given = usize::try_from(color) .ok() .and_then(|i| d.color_attachment_formats.get(i).copied().flatten()); - if given != Some(format) { - return Err(Error::InvalidDescriptor(DescriptorError::ColorAttachment { - index: color, - })); - } + // Without a format, Metal's answer; under another, compiled for another pipeline, which + // has no Metal counterpart. + let metal = match given { + Some(given) if given == format => continue, + Some(_) => MetalAnswer::EndsProcess, + None => MetalAnswer::NilWithError, + }; + return Err(Error::InvalidDescriptor(DescriptorError::ColorAttachment { + index: color, + metal, + })); } Ok(()) } diff --git a/crates/metal2vulkan/src/pipeline/link/graphics.rs b/crates/metal2vulkan/src/pipeline/link/graphics.rs index 571606d83..28b514dd5 100644 --- a/crates/metal2vulkan/src/pipeline/link/graphics.rs +++ b/crates/metal2vulkan/src/pipeline/link/graphics.rs @@ -18,7 +18,8 @@ //! unmodified, and an extended-range one (a padded 10-bit one among them) no blend: its raw //! unsigned format blends nothing, and nothing is written to blend. A bfloat attachment with //! blending enabled is `InvalidDescriptor(ColorAttachment)` whatever the function writes: Metal's -//! pipeline validation asserts that the format is not blendable. That is what Metal +//! pipeline validation asserts that the format is not blendable, ending the process +//! (`MetalAnswer::EndsProcess`). That is what Metal //! does where measured: an unblended attachment the function reads //! through framebuffer fetch but has no output for, which a draw's later fragments read as //! loaded; an attachment without an output whose blend would change it (`Zero`/`Zero`, @@ -131,7 +132,9 @@ //! - **Fragment outputs**: a color output to an attachment the descriptor sets must have the //! attachment's numeric class (`float` to a float, normalized, or sRGB format, `uint` to an //! unsigned-integer one, `int` to a signed-integer one); an output of another class is Metal's -//! pipeline error or a fragment compiled for other attachments (`ColorAttachment`). An integer +//! pipeline error (nil and an `NSError`: `ColorAttachment` answering +//! `MetalAnswer::NilWithError`, as each `ColorAttachment` below does unless it says otherwise) +//! or a fragment compiled for other attachments. An integer //! output is declared `int` exactly when the fragment compiled under its attachment in //! `LoweringInputs::signed_color_attachments`, so a `uint` output to a signed-integer attachment //! is a stage compiled for another pipeline. An output to an absent attachment is discarded, as @@ -146,9 +149,10 @@ //! four-component float output there (none, fewer components, or an integer one) Metal's //! coverage stays the rasterizer's, measured at 1 and 4 samples, while Vulkan requires an alpha //! output at location 0 (`VUID-VkGraphicsPipelineCreateInfo-alphaToCoverageEnable-08891`), so -//! link turns it off. Over an integer attachment 0 it is Metal's pipeline error -//! (`ColorAttachment`). Over an `A8Unorm` attachment 0 whose image holds Metal's alpha in red -//! (`R8_UNORM`, no `A8_UNORM`), the output holds Metal's alpha in its alpha lane too +//! link turns it off. Over an integer attachment 0 it is Metal's pipeline error, whose descriptor +//! validation ends the process (`ColorAttachment`, `MetalAnswer::EndsProcess`). Over an +//! `A8Unorm` attachment 0 whose image holds Metal's alpha in red (`R8_UNORM`, no `A8_UNORM`), +//! the output holds Metal's alpha in its alpha lane too //! (`StageIo::alpha_in_red_colors`), so Vulkan's coverage, which reads the output's alpha //! whatever the format keeps (the specification's multisample coverage section: "All alpha //! values in this section refer only to the alpha component of the fragment shader output that @@ -187,8 +191,8 @@ use std::collections::{BTreeMap, BTreeSet}; use crate::device::requirements::{FormatUsage, VkFeature, VkLimit, VkProperty}; use crate::device::{DeviceProfile, DriverWorkaround}; use crate::error::{ - Attachment, Capability, DescriptorError, DriverDeviation, Error, Feature, RuntimeInput, - Unsupported, + Attachment, Capability, DescriptorError, DriverDeviation, Error, Feature, MetalAnswer, + RuntimeInput, Unsupported, }; use crate::metal; use crate::metal::format::{ @@ -379,6 +383,7 @@ pub fn graphics_state( if let Some(index) = unblendable { return Err(Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: index as u32, + metal: MetalAnswer::EndsProcess, })); } let mut color_attachments = Vec::with_capacity(used as usize); @@ -609,6 +614,7 @@ pub fn graphics_state( .flatten() .ok_or(Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: color, + metal: MetalAnswer::NilWithError, }))?; // An input attachment of an image holding Metal's channels rotated reads them so: a // color input of one is not modelled, which a stage compiled for the attachment refuses @@ -1064,8 +1070,9 @@ pub(crate) fn coverage_notes(g: &GraphicsState, p: &DeviceProfile) -> FixedFunct /// Whether the pipeline's alpha to coverage stays enabled (see the module docs): only over a /// fragment output whose alpha it reads, a four-component float first output at attachment 0. /// Without one, Metal's coverage is the rasterizer's, as with alpha to coverage off. A -/// descriptor that enables it over an integer attachment 0 is Metal's pipeline error; that was -/// measured with rasterization on, and is refused with it off as well (unmeasured). +/// descriptor that enables it over an integer attachment 0 is Metal's pipeline error, whose +/// descriptor validation asserts and ends the process with rasterization on and off (an Apple M3 +/// Max under macOS 27.0.1, `color_attachment_answers.m`). fn reads_alpha_to_coverage( r: &RenderLinkInputs, fs: Option<&StageInterface>, @@ -1082,6 +1089,7 @@ fn reads_alpha_to_coverage( if integer { return Err(Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: 0, + metal: MetalAnswer::EndsProcess, })); } // An extended-range attachment 0 is written as raw texels, whose alpha the coverage cannot @@ -1271,7 +1279,12 @@ fn check_outputs( states: &[Option], p: &DeviceProfile, ) -> Result<(), Error> { - let invalid = |index: u32| Error::InvalidDescriptor(DescriptorError::ColorAttachment { index }); + let invalid = |index: u32| { + Error::InvalidDescriptor(DescriptorError::ColorAttachment { + index, + metal: MetalAnswer::NilWithError, + }) + }; let mut written = BTreeSet::new(); let mut second = BTreeSet::new(); for o in &fs.io.outputs { diff --git a/crates/metal2vulkan/src/pipeline/link/tests/render.rs b/crates/metal2vulkan/src/pipeline/link/tests/render.rs index 5424a0f49..e88d38264 100644 --- a/crates/metal2vulkan/src/pipeline/link/tests/render.rs +++ b/crates/metal2vulkan/src/pipeline/link/tests/render.rs @@ -2,7 +2,7 @@ use super::*; use crate::device::requirements::VkFeature; -use crate::error::{Attachment, Capability, Location}; +use crate::error::{Attachment, Capability, Location, MetalAnswer}; use crate::metal::{PixelFormat, VertexFormat, VertexStepFunction}; use crate::pipeline::descriptor::{VertexAttributeDescriptor, VertexBufferLayoutDescriptor}; use crate::pipeline::lower_inputs::VertexFetch; @@ -981,7 +981,10 @@ fn the_constant_alpha_drop_follows_the_descriptor_checks() { withheld.edit(|x| { x.enabled.features.remove(&constant_alpha); }); - let invalid = Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: 0 }); + let invalid = Error::InvalidDescriptor(DescriptorError::ColorAttachment { + index: 0, + metal: MetalAnswer::NilWithError, + }); for (output, mask) in [ (color(0, 1, f4), ColorWriteMask::ALL), (color(0, 0, f4), ColorWriteMask::NONE), @@ -1129,7 +1132,10 @@ fn graphics_state_maps_the_descriptor() { missing.color_attachments[2] = None; assert_eq!( link(&[&va, &fa], &LinkInputs::Render(Box::new(missing)), &p).unwrap_err(), - Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: 2 }) + Error::InvalidDescriptor(DescriptorError::ColorAttachment { + index: 2, + metal: MetalAnswer::NilWithError, + }) ); // The sample count maps (the fetching stage was compiled for one sample). let mut msaa = r.clone(); @@ -1925,7 +1931,12 @@ fn color_outputs_follow_metals_measured_rules() { .graphics .expect("graphics")) }; - let invalid = |index| Error::InvalidDescriptor(DescriptorError::ColorAttachment { index }); + let invalid = |index| { + Error::InvalidDescriptor(DescriptorError::ColorAttachment { + index, + metal: MetalAnswer::NilWithError, + }) + }; let lavapipe = profile("lavapipe"); let floor = profile("vk12-floor"); for p in [&lavapipe, &profile("moltenvk-m3")] { @@ -2089,7 +2100,8 @@ fn alpha_to_coverage_reads_a_four_component_float_output_at_attachment_0() { Some(&fragment(vec![color(0, 0, u4)])) ), Err(Error::InvalidDescriptor(DescriptorError::ColorAttachment { - index: 0 + index: 0, + metal: MetalAnswer::EndsProcess, })) ); } diff --git a/crates/metal2vulkan/src/tests/engine_dead_reads.rs b/crates/metal2vulkan/src/tests/engine_dead_reads.rs index c98230f0c..169f275b0 100644 --- a/crates/metal2vulkan/src/tests/engine_dead_reads.rs +++ b/crates/metal2vulkan/src/tests/engine_dead_reads.rs @@ -25,7 +25,7 @@ use crate::budget::Budget; use crate::cache::VariantKey; use crate::device::requirements::VkFeature; use crate::device::{Device, DevicePolicy}; -use crate::error::{DescriptorError, Error, Feature}; +use crate::error::{DescriptorError, Error, Feature, MetalAnswer}; use crate::library::{FunctionConstantValue, FunctionConstantValues, Library}; use crate::metal::{DataType, PixelFormat}; use crate::pipeline::artifact::RenderPipeline; @@ -236,6 +236,7 @@ fn a_color_input_without_an_attachment_is_refused_dead_or_live() { match made { Err(Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: 1, + metal: MetalAnswer::NilWithError, })) => {} Ok(()) => misses.entry("made".into()).or_default().push(what), Err(e) => misses diff --git a/crates/metal2vulkan/src/tests/engine_extended_range/targets.rs b/crates/metal2vulkan/src/tests/engine_extended_range/targets.rs index 751b08994..3fa54d54d 100644 --- a/crates/metal2vulkan/src/tests/engine_extended_range/targets.rs +++ b/crates/metal2vulkan/src/tests/engine_extended_range/targets.rs @@ -34,7 +34,7 @@ //! pipeline's attachments does not. use super::*; -use crate::error::{DescriptorError, Error, Needs, RuntimeInput}; +use crate::error::{DescriptorError, Error, MetalAnswer, Needs, RuntimeInput}; use crate::metal::format::ClearRoute; use crate::metal::ColorWriteMask; use crate::pipeline::descriptor::ColorAttachmentDescriptor; @@ -455,7 +455,10 @@ fn fragment_outputs_to_bfloat_targets_write_raw_codes() { // the device orders fetch only through the interlock) and at link, with no fragment // function too. let what = format!("{stem} {pf:?} blended"); - let invalid = Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: 0 }); + let invalid = Error::InvalidDescriptor(DescriptorError::ColorAttachment { + index: 0, + metal: MetalAnswer::EndsProcess, + }); let r = pipeline_of(pf, ColorWriteMask::ALL, true); for entry in ["rt6_fill_rgba32float", "rt6_fill_rgba16float"] { let e = compile_with(&bc, entry, &p, &blended_inputs(&r, &p)).expect_err(&what); @@ -657,7 +660,10 @@ fn unmodelled_extended_range_targets_are_refused() { assert!( matches!( e, - Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: 0 }) + Error::InvalidDescriptor(DescriptorError::ColorAttachment { + index: 0, + metal: MetalAnswer::NilWithError, + }) ), "{what} {entry}: {e}" ); diff --git a/crates/metal2vulkan/src/tests/engine_fetch_blend8.rs b/crates/metal2vulkan/src/tests/engine_fetch_blend8.rs index 99c321fe2..632232d31 100644 --- a/crates/metal2vulkan/src/tests/engine_fetch_blend8.rs +++ b/crates/metal2vulkan/src/tests/engine_fetch_blend8.rs @@ -32,7 +32,7 @@ use std::path::Path; use crate::budget::Budget; use crate::device::{Device, DeviceDescription, DevicePolicy, DeviceProfile}; -use crate::error::{Attachment, DescriptorError, Error, Feature, Needs}; +use crate::error::{Attachment, DescriptorError, Error, Feature, MetalAnswer, Needs}; use crate::library::{FunctionArtifact, Library}; use crate::metal::{BlendFactor, BlendOperation, ColorWriteMask, PixelFormat}; use crate::pipeline::artifact::PrecisionNote; @@ -493,7 +493,10 @@ fn a_second_source_blend_without_its_output_is_refused_as_metal_refuses_it() { let inputs = state(&p, PixelFormat::BGRA8Unorm, eq, ColorWriteMask::ALL); let what = format!("{stem} {eq:?}"); match compile_with(&fast, "fbl8_over_loaded", &p, &inputs) { - Err(Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: 0 })) => { + Err(Error::InvalidDescriptor(DescriptorError::ColorAttachment { + index: 0, + metal: MetalAnswer::NilWithError, + })) => { checked += 1; } Err(e) if device_gap(&e) => eprintln!("{what}: {e}"), diff --git a/crates/metal2vulkan/src/tests/engine_fetch_generic_blend.rs b/crates/metal2vulkan/src/tests/engine_fetch_generic_blend.rs index 5460bbf40..8f328dd02 100644 --- a/crates/metal2vulkan/src/tests/engine_fetch_generic_blend.rs +++ b/crates/metal2vulkan/src/tests/engine_fetch_generic_blend.rs @@ -28,7 +28,7 @@ use std::sync::Arc; use crate::budget::Budget; use crate::device::{Device, DeviceDescription, DevicePolicy, DeviceProfile}; -use crate::error::{DescriptorError, Error, Needs}; +use crate::error::{DescriptorError, Error, MetalAnswer, Needs}; use crate::library::{FunctionArtifact, Library}; use crate::metal::{BlendFactor, BlendOperation, ColorWriteMask, PixelFormat}; use crate::pipeline::artifact::PrecisionNote; @@ -482,7 +482,10 @@ fn a_second_source_blend_without_its_output_is_refused_as_metal_refuses_it() { let inputs = state(0, &r, &p); let what = format!("{stem} {pf:?} {eq:?}"); match compile_with(&fast, "fbl8_over_loaded", &p, &inputs) { - Err(Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: 0 })) => { + Err(Error::InvalidDescriptor(DescriptorError::ColorAttachment { + index: 0, + metal: MetalAnswer::NilWithError, + })) => { checked += 1; } Err(Error::Unsupported(u)) => eprintln!("{what}: {u}"), diff --git a/crates/metal2vulkan/src/tests/engine_fragment.rs b/crates/metal2vulkan/src/tests/engine_fragment.rs index 7c62cab18..f11547bff 100644 --- a/crates/metal2vulkan/src/tests/engine_fragment.rs +++ b/crates/metal2vulkan/src/tests/engine_fragment.rs @@ -3022,6 +3022,7 @@ fn a_second_source_blend_without_fast_math_reads_the_second_output() { match pipeline(&safe, "stage_io_fragment_point") { Err(Error::InvalidDescriptor(crate::error::DescriptorError::ColorAttachment { index: 0, + metal: crate::error::MetalAnswer::NilWithError, })) => {} r => panic!("{stem}: no second output: {:?}", r.map(|_| ())), } diff --git a/crates/metal2vulkan/src/tests/engine_link.rs b/crates/metal2vulkan/src/tests/engine_link.rs index a3f8ecaed..77c457faf 100644 --- a/crates/metal2vulkan/src/tests/engine_link.rs +++ b/crates/metal2vulkan/src/tests/engine_link.rs @@ -16,7 +16,9 @@ use std::sync::Arc; use crate::budget::SPIRV_WORDS; use crate::device::requirements::{FormatUsage, VkFeature}; use crate::device::{Device, DeviceDescription, DevicePolicy, DeviceProfile}; -use crate::error::{DescriptorError, Error, Feature, LowerFamily, Needs, RuntimeInput}; +use crate::error::{ + DescriptorError, Error, Feature, LowerFamily, MetalAnswer, Needs, RuntimeInput, +}; use crate::library::{FunctionArtifact, FunctionConstantValues}; use crate::metal::{BlendFactor, PixelFormat, VertexFormat}; use crate::pipeline::compile::{compile_bitcode, EntryRef}; @@ -261,14 +263,20 @@ fn pipeline_mismatches_are_typed_refusals() { r.color_attachments[2] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA8Unorm)); assert_eq!( link(&[&v, &f], &render(&r), &p).unwrap_err(), - Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: 2 }) + Error::InvalidDescriptor(DescriptorError::ColorAttachment { + index: 2, + metal: MetalAnswer::NilWithError, + }) ); // A signed-integer attachment: the fragment compiled for an unsigned one declares the output // `uint`, so it is a stage of another pipeline. r.color_attachments[2] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA32Sint)); assert_eq!( link(&[&v, &f], &render(&r), &p).unwrap_err(), - Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: 2 }) + Error::InvalidDescriptor(DescriptorError::ColorAttachment { + index: 2, + metal: MetalAnswer::NilWithError, + }) ); // An absent attachment discards the output. r.color_attachments[2] = None; @@ -509,7 +517,10 @@ fn a_signed_integer_attachment_takes_an_int_output() { assert_eq!(color_class(&plain, 1), Some(IoNumeric::Uint), "{stem}"); assert_eq!( link(&[&v, &plain], &render(&signed_targets()), &p).unwrap_err(), - Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: 1 }), + Error::InvalidDescriptor(DescriptorError::ColorAttachment { + index: 1, + metal: MetalAnswer::NilWithError, + }), "{stem}" ); let mut unsigned = signed_targets(); @@ -517,7 +528,10 @@ fn a_signed_integer_attachment_takes_an_int_output() { Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA32Uint)); assert_eq!( link(&[&v, &f], &render(&unsigned), &p).unwrap_err(), - Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: 1 }), + Error::InvalidDescriptor(DescriptorError::ColorAttachment { + index: 1, + metal: MetalAnswer::NilWithError, + }), "{stem}" ); } @@ -548,7 +562,10 @@ fn dual_source_blending_needs_the_second_output() { ); assert_eq!( link(&[&v, &single], &render(&r), &p).unwrap_err(), - Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: 0 }) + Error::InvalidDescriptor(DescriptorError::ColorAttachment { + index: 0, + metal: MetalAnswer::NilWithError, + }) ); } diff --git a/crates/metal2vulkan/src/tests/engine_padded_blends.rs b/crates/metal2vulkan/src/tests/engine_padded_blends.rs index 0d73c87fd..73dbba778 100644 --- a/crates/metal2vulkan/src/tests/engine_padded_blends.rs +++ b/crates/metal2vulkan/src/tests/engine_padded_blends.rs @@ -21,7 +21,7 @@ use std::path::Path; use crate::budget::Budget; use crate::device::{Device, DeviceDescription, DevicePolicy, DeviceProfile}; -use crate::error::{DescriptorError, Error, Needs}; +use crate::error::{DescriptorError, Error, MetalAnswer, Needs}; use crate::library::{FunctionArtifact, Library}; use crate::metal::{BlendFactor, BlendOperation, ColorWriteMask, PixelFormat}; use crate::pipeline::artifact::RenderPipeline; @@ -299,7 +299,10 @@ fn a_blend_into_a_bfloat_attachment_is_metals_pipeline_error() { let Some(fills) = assembled("rt6_samples") else { return; }; - let invalid = Error::InvalidDescriptor(DescriptorError::ColorAttachment { index: 0 }); + let invalid = Error::InvalidDescriptor(DescriptorError::ColorAttachment { + index: 0, + metal: MetalAnswer::EndsProcess, + }); let fills = (fills.as_slice(), "rt6_fill_vertex", "rt6_fill_rgba16float"); let (mut refused, mut unblended) = (0, 0); for (stem, p) in committed_profiles().expect("profiles") { diff --git a/crates/metal2vulkan/src/tests/engine_tile.rs b/crates/metal2vulkan/src/tests/engine_tile.rs index 0a8873bdd..651dad34c 100644 --- a/crates/metal2vulkan/src/tests/engine_tile.rs +++ b/crates/metal2vulkan/src/tests/engine_tile.rs @@ -44,7 +44,7 @@ use crate::bind::{ use crate::budget::Budget; use crate::device::profile::DeviceProfile; use crate::device::{Device, DeviceDescription, DevicePolicy}; -use crate::error::{BindError, DescriptorError, Error, Feature, Needs, RuntimeInput}; +use crate::error::{BindError, DescriptorError, Error, Feature, MetalAnswer, Needs, RuntimeInput}; use crate::library::Library; use crate::lower::select::{LowerInputs, Plan}; use crate::lower::texture::TexelClass; @@ -1209,7 +1209,8 @@ fn tile_refusals_are_typed() { assert_eq!( dev.compile_tile_pipeline(&missing, &b).map(|_| ()), Err(Error::InvalidDescriptor(DescriptorError::ColorAttachment { - index: 1 + index: 1, + metal: MetalAnswer::NilWithError, })) ); let mut msaa = descriptor( @@ -1256,7 +1257,8 @@ fn tile_refusals_are_typed() { PixelFormat::R32Uint ]), Err(Error::InvalidDescriptor(DescriptorError::ColorAttachment { - index: 1 + index: 1, + metal: MetalAnswer::EndsProcess, })) ); } diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 0fbe012a3..a63b6499a 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -1482,6 +1482,7 @@ enum metal2vulkan::error::LinearNeed #[derive(Clone, Copy, Debug, PartialEq, Eq, enum metal2vulkan::error::LinkProblem #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum LinkProblem enum metal2vulkan::error::LowerFamily #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum LowerFamily enum metal2vulkan::error::MeshPipelineProblem #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum MeshPipelineProblem +enum metal2vulkan::error::MetalAnswer #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum MetalAnswer enum metal2vulkan::error::Needs #[derive(Clone, Debug, PartialEq, Eq)] #[non_exhaustive] pub enum Needs enum metal2vulkan::error::Permanence #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum Permanence enum metal2vulkan::error::PrivateRenderField #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum PrivateRenderField @@ -13712,7 +13713,7 @@ variant metal2vulkan::error::ContainerError::NoAirSlice NoAirSlice variant metal2vulkan::error::ContainerError::Truncated Truncated { need: u64, have: u64 } variant metal2vulkan::error::ContainerError::UnsupportedContainerVersion UnsupportedContainerVersion { major: u16, minor: u16 } variant metal2vulkan::error::DescriptorError::AmbiguousEntry AmbiguousEntry { requested: DiagName } -variant metal2vulkan::error::DescriptorError::ColorAttachment ColorAttachment { index: u32 } +variant metal2vulkan::error::DescriptorError::ColorAttachment ColorAttachment { index: u32, metal: MetalAnswer } variant metal2vulkan::error::DescriptorError::ComputePipeline ComputePipeline { problem: ComputePipelineProblem } variant metal2vulkan::error::DescriptorError::DeviceDescription DeviceDescription { detail: String } variant metal2vulkan::error::DescriptorError::DuplicateColorOutput DuplicateColorOutput { color: u32, index: u32 } @@ -13991,6 +13992,8 @@ variant metal2vulkan::error::MeshPipelineProblem::RequiredEmptyAxis RequiredEmpt variant metal2vulkan::error::MeshPipelineProblem::RequiredOverLimit RequiredOverLimit { stage: Stage, threads: u64, limit: u32 } variant metal2vulkan::error::MeshPipelineProblem::RequiredOverMax RequiredOverMax { stage: Stage, threads: u64, max: u32 } variant metal2vulkan::error::MeshPipelineProblem::RequiredWithoutObjectFunction RequiredWithoutObjectFunction { required: [u32; 3] } +variant metal2vulkan::error::MetalAnswer::EndsProcess EndsProcess +variant metal2vulkan::error::MetalAnswer::NilWithError NilWithError variant metal2vulkan::error::Needs::AnyOf AnyOf(Vec>) variant metal2vulkan::error::Needs::DeviceCapability DeviceCapability(&'static str) variant metal2vulkan::error::Needs::DriverDefect DriverDefect(DriverWorkaround) diff --git a/crates/metal2vulkan/tests/api_surface.rs b/crates/metal2vulkan/tests/api_surface.rs index 76dad3b25..802b30cb3 100644 --- a/crates/metal2vulkan/tests/api_surface.rs +++ b/crates/metal2vulkan/tests/api_surface.rs @@ -200,6 +200,7 @@ surface! { enum ExtendedRangeBlend N; enum RuntimeInput N; enum DescriptorError N; + enum MetalAnswer N; enum DynamicLibraryProblem N; enum MeshPipelineProblem N; enum ComputePipelineProblem N; @@ -1472,7 +1473,10 @@ fn a_signed_integer_attachment_compiles_the_fragment_for_it() { dev.compile_render_pipeline(&foreign, &Budget::standard()) .unwrap_err(), metal2vulkan::error::Error::InvalidDescriptor( - metal2vulkan::error::DescriptorError::ColorAttachment { index: 1 } + metal2vulkan::error::DescriptorError::ColorAttachment { + index: 1, + metal: metal2vulkan::error::MetalAnswer::NilWithError, + } ), "{stem}" ); diff --git a/docs/API.md b/docs/API.md index d04bc01bd..6598cb23e 100644 --- a/docs/API.md +++ b/docs/API.md @@ -786,6 +786,13 @@ Where Metal's rules differ from Vulkan's, the pipeline gives Metal's answer: fewer components than its attachment's channels, a blend that reads the second output without the first, alpha to coverage over an integer attachment 0. Function-constant values that put two outputs at one attachment are `InvalidDescriptor(DuplicateColorOutput)`. +- `ColorAttachment`'s `metal` is how plain Metal answers the pipeline (measured on an Apple M3 Max + under macOS 27.0.1): `MetalAnswer::NilWithError`, nil and an `NSError` (code 3), for an output or + color input of another numeric class than its attachment, an output with fewer components, a + blend of the second source without both outputs, and a color input or tile imageblock member of + an attachment without a format; `MetalAnswer::EndsProcess`, Metal's descriptor validation + asserting, for a blend into a bfloat attachment and for alpha to coverage over an integer + attachment 0. A layer that answers as Metal does ends the process only for the second. - On a device without `independentBlend`, attachments the function does not write copy the blend state of those it does; where those differ the pipeline is refused, naming the feature. - A packed 16-bit attachment (`A1BGR5Unorm`, `ABGR4Unorm`, `BGRA4Unorm`) of a format the device