From 2c5573d5981346706103d04ffb92bb39aad7dd72 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Fri, 20 Nov 2026 22:02:06 -0800 Subject: [PATCH] rt: a refused pipeline state's Error::Translation names its functions What: Error::Translation is now Error::Translation { error, functions }. new_compute_pipeline_state and new_render_pipeline_state fill `functions` at their public entry with each Function stage's own name in its library (FunctionInfo::name), in stage order (the vertex function before the fragment function), and the Display prints them: "the translator made no pipeline of a, b: ...". A compiled stage has no name; a sampler state, a device and a dispatch's late kernel variant name none, and then the text is as before. It is a diagnostic for the program's log, documented as the text of the NSError Metal's failed creation gives; no lowering or decision reads it. Why: the consumer logged only the first refusal of each kind, which hid 6 of one 3D modelling app's 8 refused kernels; with the names it logs every refused create. How: the existing creation bodies moved to private compute_pipeline_state and render_pipeline_state, whose translator errors name no function (Error::translation, for map_err), and the public entries map them through Error::of_stages. The one-token map_err edits are in pipeline.rs, render.rs, sampler.rs:371 and device.rs:1290 and 1294. Same commit: 10 rt test patterns; validation's candidate/platform/runtime.rs (2), candidate/tests/engine_compute.rs, replay/new_runtime/mod.rs and replay/new_runtime/tests.rs (3); conformance's rt_side.rs, rt_side/states.rs and case.rs. Conformance's Failure::of_rt records the error's text without the names (they are the case's own functions), so the 484 answers in known-gaps-rt.tsv stay as they are. The rt README's compute and render state entries say what `functions` holds; REFUSALS.md and api_signatures.tsv are regenerated (one changed signature). Consumer break to follow: reims-vgpu builds or matches rt::Error::Translation(..) at 17 sites, all in crates/reims-vgpu-vulkan/src/rt_platform/: unbuilt.rs (7), diag.rs (5), library.rs (3), pipeline.rs (1), argument.rs (1). Each becomes Translation { error, .. } in a match, or Translation { error, functions: Vec::new() } where it builds one. Tests (device cfgs): every_device_names_the_function_of_a_refused_compute_state (translate.rs): a compute state of the vertex function colored_vertex is Error::Translation with functions ["colored_vertex"], and its text starts "the translator made no pipeline of colored_vertex: ". every_device_refuses_the_patch_draws_it_does_not_build (patch.rs) now also holds the control-point index type's Tessellation refusal to functions ["tess_triangle_points", "tess_fragment"] and to the text that names them in that order. Without the entry mapping both fail on an empty `functions`. --- crates/metal2vulkan-conformance/src/case.rs | 23 +++++-- .../metal2vulkan-conformance/src/rt_side.rs | 5 +- .../src/rt_side/states.rs | 5 +- crates/metal2vulkan-runtime/README.md | 8 ++- crates/metal2vulkan-runtime/src/device.rs | 4 +- crates/metal2vulkan-runtime/src/error.rs | 64 ++++++++++++++++--- crates/metal2vulkan-runtime/src/pipeline.rs | 39 +++++++---- crates/metal2vulkan-runtime/src/render.rs | 33 +++++++--- crates/metal2vulkan-runtime/src/sampler.rs | 2 +- .../src/tests/barycentrics.rs | 5 +- crates/metal2vulkan-runtime/src/tests/draw.rs | 24 +++---- .../src/tests/interpolation.rs | 8 ++- .../metal2vulkan-runtime/src/tests/layered.rs | 5 +- .../metal2vulkan-runtime/src/tests/lowered.rs | 2 +- .../metal2vulkan-runtime/src/tests/min_lod.rs | 5 +- .../metal2vulkan-runtime/src/tests/patch.rs | 17 ++++- .../src/tests/pixel_interlock.rs | 5 +- .../src/tests/quad_control.rs | 5 +- .../metal2vulkan-runtime/src/tests/sampler.rs | 2 +- .../src/tests/translate.rs | 30 +++++++++ .../src/candidate/platform/runtime.rs | 7 +- .../src/candidate/tests/engine_compute.rs | 7 +- .../src/replay/new_runtime/mod.rs | 2 +- .../src/replay/new_runtime/tests.rs | 15 ++++- crates/metal2vulkan/tests/api_signatures.tsv | 2 +- docs/REFUSALS.md | 4 +- 26 files changed, 247 insertions(+), 81 deletions(-) diff --git a/crates/metal2vulkan-conformance/src/case.rs b/crates/metal2vulkan-conformance/src/case.rs index 86105bd4e..3f078e2dc 100644 --- a/crates/metal2vulkan-conformance/src/case.rs +++ b/crates/metal2vulkan-conformance/src/case.rs @@ -490,11 +490,24 @@ pub struct Failure { impl Failure { /// The failure a typed error of the runtime (`metal2vulkan-runtime`) is. A translator refusal /// that names a capability the device could enable is the venue's gap ([`device_gap_of`]). + /// The functions a refused pipeline state names are the case's own, a diagnostic: the failure + /// holds the error's text without them. pub fn of_rt(error: &metal2vulkan_runtime::Error) -> Self { + let text = match error { + metal2vulkan_runtime::Error::Translation { error, .. } => { + let unnamed = metal2vulkan_runtime::Error::Translation { + error: error.clone(), + functions: Vec::new(), + }; + unnamed.to_string() + } + other => other.to_string(), + }; let lacks = match error { - metal2vulkan_runtime::Error::Translation(metal2vulkan::error::Error::Unsupported( - unsupported, - )) => device_gap_of(unsupported), + metal2vulkan_runtime::Error::Translation { + error: metal2vulkan::error::Error::Unsupported(unsupported), + .. + } => device_gap_of(unsupported), // A threadgroup Metal runs and this device's limits for the kernel do not. metal2vulkan_runtime::Error::Limit( metal2vulkan_runtime::Limit::ThreadgroupThreads { .. }, @@ -504,10 +517,10 @@ impl Failure { Self { error: Value::Variant { name: error_variant(error), - payload: Box::new(Value::Lines(vec![error.to_string()])), + payload: Box::new(Value::Lines(vec![text.clone()])), }, lacks, - refusal: Some(error.to_string()), + refusal: Some(text), } } diff --git a/crates/metal2vulkan-conformance/src/rt_side.rs b/crates/metal2vulkan-conformance/src/rt_side.rs index 53455e43b..3abee2df4 100644 --- a/crates/metal2vulkan-conformance/src/rt_side.rs +++ b/crates/metal2vulkan-conformance/src/rt_side.rs @@ -160,7 +160,10 @@ impl RtDevice { /// refusal of the runtime's until a stream uses it, and the failure is the runtime's refusal. pub(crate) fn failure(&self, error: &rt::Error) -> Failure { let mut failure = Failure::of_rt(error); - if let rt::Error::Translation(metal2vulkan::error::Error::Unsupported(unsupported)) = error + if let rt::Error::Translation { + error: metal2vulkan::error::Error::Unsupported(unsupported), + .. + } = error { if offers_one(&self.offered, unsupported) { failure.lacks = None; diff --git a/crates/metal2vulkan-conformance/src/rt_side/states.rs b/crates/metal2vulkan-conformance/src/rt_side/states.rs index beca99084..99115d78a 100644 --- a/crates/metal2vulkan-conformance/src/rt_side/states.rs +++ b/crates/metal2vulkan-conformance/src/rt_side/states.rs @@ -21,7 +21,10 @@ fn refuses_as_metal(error: &rt::Error) -> bool { matches!( error, rt::Error::Refused(_) - | rt::Error::Translation(metal2vulkan::error::Error::InvalidDescriptor(_)) + | rt::Error::Translation { + error: metal2vulkan::error::Error::InvalidDescriptor(_), + .. + } ) } diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 494b94dac..b23de33b9 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -2183,7 +2183,10 @@ while the driver's exit handler waited on a lock, with every runtime thread alre budget per lowering, for what device creation enabled and under its identity domains: each buffer argument is the guest address of the bound buffer plus its offset, and each texture and sampler argument the bound object's resource ID, pushed; set 1 is the only descriptor set a - kernel reads. A refusal of the translator is `Error::Translation`. + kernel reads. A refusal of the translator is `Error::Translation`, whose `functions` names the + kernel by its own name in its library and whose text prints it, for the program's log as the + text of Metal's `NSError` is; nothing decides by it. A kernel the consumer compiled has no name + there. - rt builds no pipeline reflection and acts on no `MTLPipelineOption`; its consumer builds reflection from the library's AIR. The options it leaves to the consumer are `MTLPipelineOptionFailOnBinaryArchiveMiss`, `MTLPipelineOptionArgumentInfo`, @@ -2693,7 +2696,8 @@ or does not check is rebuilt from the generations' names, with young counted ful `newRenderPipelineStateWithDescriptor:error:` without reflection. The translator lowers the vertex and fragment functions on the calling thread, which waits for them, within its 20-second budget per lowering, for what device creation enabled and under its identity domains, as for a - compute state. A refusal of the translator is `Error::Translation`. + compute state. A refusal of the translator is `Error::Translation`, whose `functions` names the + vertex function and then the fragment function, as for a compute state. - rt builds no pipeline reflection and acts on no `MTLPipelineOption`; its consumer builds reflection from the library's AIR, as for a compute state. - `RenderPipelineState::texture_accesses(stage)` answers each texture slot the vertex diff --git a/crates/metal2vulkan-runtime/src/device.rs b/crates/metal2vulkan-runtime/src/device.rs index c77b2fd1f..00f540031 100644 --- a/crates/metal2vulkan-runtime/src/device.rs +++ b/crates/metal2vulkan-runtime/src/device.rs @@ -1287,11 +1287,11 @@ unsafe fn translator( unsafe { DeviceDescription::query(instance, raw, ApiVersion::from_packed(floor::VERSION)) }; let description = described .and_then(|description| description.with_enabled(&floor::shader_enables(capabilities))) - .map_err(Error::Translation)?; + .map_err(Error::translation)?; let mut policy = DevicePolicy::default(); policy.pointer_domain = PointerDomain::Identity; policy.handle_domain = HandleDomain::Identity; - metal2vulkan::device::Device::from_queries(description, policy).map_err(Error::Translation) + metal2vulkan::device::Device::from_queries(description, policy).map_err(Error::translation) } /// The features device creation enables: the floor's of `capabilities`, and each of `asked` the diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index d2b9b4807..908daaf32 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -7,6 +7,7 @@ use crate::import::ImportHandle; use crate::memory::{BlockId, MemoryClass}; use ash::vk; use metal2vulkan::metal::{PixelFormat, PrimitiveTopologyClass, TextureType}; +use metal2vulkan::pipeline::StageSource; use std::{fmt, io}; /// What a failing call returns. @@ -49,15 +50,27 @@ pub enum Error { /// duplicate of the runtime's own fd of the surface's dma-buf, which the buffer's import /// takes, as where the process holds as many open fds as it may. Metal has no counterpart. Fd(io::Error), - /// [`Device::new_compute_pipeline_state`](crate::Device::new_compute_pipeline_state): the - /// translator made no pipeline of the kernel: a typed refusal of what it does not translate, - /// a descriptor Metal refuses, or a translation past its 20-second budget. + /// [`Device::new_compute_pipeline_state`](crate::Device::new_compute_pipeline_state) and + /// [`Device::new_render_pipeline_state`](crate::Device::new_render_pipeline_state): the + /// translator made no pipeline of the descriptor's functions: a typed refusal of what it does + /// not translate, a descriptor Metal refuses, or a translation past its 20-second budget. + /// Metal's counterpart is `newComputePipelineStateWithFunction:error:` or + /// `newRenderPipelineStateWithDescriptor:error:` failing, which Metal does only for a + /// descriptor it refuses, with an `NSError` whose text says why. /// [`Device::new_sampler_state`](crate::Device::new_sampler_state): the translator made no - /// device sampler of the descriptor. Metal's - /// counterpart is `newComputePipelineStateWithFunction:error:` failing, which Metal does only - /// for a descriptor it refuses. [`Device::new`](crate::Device::new) gives it too where the + /// device sampler of the descriptor. [`Device::new`](crate::Device::new) gives it too where the /// translator takes no description of the device, which the floor leaves no device to do. - Translation(metal2vulkan::error::Error), + Translation { + /// The translator's error. + error: metal2vulkan::error::Error, + /// The functions of the pipeline state made, each by its own name in its library + /// (`MTLFunction`'s `name`), in stage order (the vertex function before the fragment + /// function), which the error's text prints: a diagnostic for the program's log, as the + /// `NSError`'s text of Metal's failed creation is, that nothing decides by. A stage the + /// consumer compiled (`StageSource::Compiled`) has no name here; a sampler state, a + /// device and a dispatch's variant of a kernel name none. + functions: Vec, + }, /// A Metal feature the runtime does not build yet: a typed known gap. Unsupported(Gap), /// A call that needs one of the runtime's threads, after @@ -1825,6 +1838,32 @@ pub enum Limit { } impl Error { + /// The translator's `error` ([`Error::Translation`]), naming no function, for `map_err`. + pub(crate) fn translation(error: metal2vulkan::error::Error) -> Error { + Error::Translation { + error, + functions: Vec::new(), + } + } + + /// This error, where it is the translator's ([`Error::Translation`]), naming each function of + /// `stages` by its own name in its library; any other error as it is. + pub(crate) fn of_stages<'a>(self, stages: impl IntoIterator) -> Error { + match self { + Error::Translation { error, .. } => Error::Translation { + error, + functions: (stages.into_iter()) + .filter_map(|stage| match stage { + StageSource::Function(function) => Some(function.function.info().name), + StageSource::Compiled(_) => None, + }) + .map(str::to_owned) + .collect(), + }, + other => other, + } + } + /// The error of a failed Vulkan `call`, for `map_err`. pub(crate) fn vulkan(call: &'static str) -> impl FnOnce(vk::Result) -> Error { move |result| Error::Vulkan { call, result } @@ -1867,7 +1906,14 @@ impl fmt::Display for Error { Error::Thread(error) => write!(f, "a runtime thread did not start: {error}"), Error::Fd(error) => write!(f, "no duplicate of a dma-buf's fd: {error}"), Error::Quiesced => f.write_str("the device is quiesced"), - Error::Translation(error) => write!(f, "the translator made no pipeline: {error}"), + Error::Translation { error, functions } if functions.is_empty() => { + write!(f, "the translator made no pipeline: {error}") + } + Error::Translation { error, functions } => write!( + f, + "the translator made no pipeline of {}: {error}", + functions.join(", ") + ), Error::Unsupported(gap) => write!(f, "{gap}"), } } @@ -2474,7 +2520,7 @@ impl std::error::Error for Error { Error::BelowFloor(below) => Some(below), Error::Vulkan { result, .. } => Some(result), Error::Thread(error) | Error::Fd(error) => Some(error), - Error::Translation(error) => Some(error), + Error::Translation { error, .. } => Some(error), Error::NoDirectDriverLoading | Error::Refused(_) | Error::Limit(_) diff --git a/crates/metal2vulkan-runtime/src/pipeline.rs b/crates/metal2vulkan-runtime/src/pipeline.rs index 4add75ba0..952012311 100644 --- a/crates/metal2vulkan-runtime/src/pipeline.rs +++ b/crates/metal2vulkan-runtime/src/pipeline.rs @@ -321,7 +321,7 @@ fn constexpr_uses( for (_, sampler) in uses.iter().filter(|(place, _)| *place == at) { let desc = sampler .constexpr_sampler(profile) - .map_err(Error::Translation)? + .map_err(Error::translation)? .ok_or_else(gap)?; held[sampler_array(sampler)] = Some(canonical(desc)); } @@ -809,15 +809,26 @@ impl crate::Device { /// their indices. What `sampler_ids` answers as an error, the call answers; once it has /// answered, a failing call holds none of the indices. /// - /// Err: [`Error::Translation`], the translator's typed refusal or a descriptor Metal refuses; - /// [`Gap::IndirectCommandBuffers`]; [`Gap::KernelInput`] for a kernel that reads what the - /// compute encoder does not supply yet; [`Refusal::SamplerIds`] where `sampler_ids` answers - /// another count; [`Refusal::IndicesNotGranted`] for a constexpr sampler's index; - /// [`Limit::DeviceSamplers`](crate::Limit::DeviceSamplers); [`Error::Vulkan`]. + /// Err: [`Error::Translation`], the translator's typed refusal or a descriptor Metal refuses, + /// naming the kernel; [`Gap::IndirectCommandBuffers`]; [`Gap::KernelInput`] for a kernel that + /// reads what the compute encoder does not supply yet; [`Refusal::SamplerIds`] where + /// `sampler_ids` answers another count; [`Refusal::IndicesNotGranted`] for a constexpr + /// sampler's index; [`Limit::DeviceSamplers`](crate::Limit::DeviceSamplers); [`Error::Vulkan`]. pub fn new_compute_pipeline_state( &self, descriptor: &ComputePipelineDescriptor, sampler_ids: impl FnOnce(&[NumberedSampler]) -> Result, Error>, + ) -> Result { + (self.compute_pipeline_state(descriptor, sampler_ids)) + .map_err(|error| error.of_stages([&descriptor.kernel])) + } + + /// [`new_compute_pipeline_state`](Self::new_compute_pipeline_state), its translator's error + /// naming no function. + fn compute_pipeline_state( + &self, + descriptor: &ComputePipelineDescriptor, + sampler_ids: impl FnOnce(&[NumberedSampler]) -> Result, Error>, ) -> Result { if descriptor.support_indirect_command_buffers { return Err(Error::Unsupported(Gap::IndirectCommandBuffers)); @@ -866,7 +877,7 @@ impl Compiled { entries, ) }) - .map_err(Error::Translation)?; + .map_err(Error::translation)?; let source = ( function, plain.kernel_variant(KernelVariant::EmulatedSimdgroups), @@ -893,7 +904,7 @@ impl Compiled { let observes = translating(&core, || { translator.kernel_observes_partition(function, &inputs, &budget, entries) }) - .map_err(Error::Translation); + .map_err(Error::translation); core.note_entries(); if observes? { cache::keep_observer(&core, &variant_key); @@ -907,7 +918,7 @@ impl Compiled { cache::keep_refusal(&core, &variant_key); Found::Refused } - Err(error) => return Err(Error::Translation(error)), + Err(error) => return Err(Error::translation(error)), } } }; @@ -917,7 +928,7 @@ impl Compiled { Found::Lowered(variant) if !variant.observes_threadgroup_partition() => { let image_only = variant.is_image_only(); let imageblock = declares_imageblock(descriptor, &variant, &budget); - let pipeline = compiled(variant).map_err(Error::Translation)?; + let pipeline = compiled(variant).map_err(Error::translation)?; let partial = (!grid_tiles(&pipeline)).then_some(None); let answers = Answers::of(&pipeline, imageblock); (pipeline, partial, image_only, Some(source), answers) @@ -925,9 +936,9 @@ impl Compiled { // The kernel observes its partition, or its variant is refused: its plain // module, and the variant for the grids that need it. variant => { - let plain = lower(&plain).map_err(Error::Translation)?; + let plain = lower(&plain).map_err(Error::translation)?; let imageblock = declares_imageblock(descriptor, &plain, &budget); - let plain = compiled(plain).map_err(Error::Translation)?; + let plain = compiled(plain).map_err(Error::translation)?; let answers = Answers::of(&plain, imageblock); let partial = Some((function, inputs, variant)); (plain, Some(partial), false, Some(source), answers) @@ -939,7 +950,7 @@ impl Compiled { let pipeline = translating(&core, || { translator.compile_compute_pipeline(descriptor, &budget) }) - .map_err(Error::Translation)?; + .map_err(Error::translation)?; // Only a non-observer's partial variant runs its grid in tiles. It has no // emulated variant: the kernel keeps the variant it was compiled under. The // translator links a compiled kernel only for its own profile @@ -1859,7 +1870,7 @@ impl Lowered { match self { Lowered::Made(kernel, _) => Ok(&**kernel), Lowered::Refused => Err(refused()), - Lowered::Translation(error) => Err(Error::Translation(error.clone())), + Lowered::Translation(error) => Err(Error::translation(error.clone())), &Lowered::Unsupplied(kind) => Err(gap(kind)), &Lowered::Failed(result) => Err(Error::Vulkan { call: "vkCreateShaderModule", diff --git a/crates/metal2vulkan-runtime/src/render.rs b/crates/metal2vulkan-runtime/src/render.rs index 3c994e4ec..4a39adcb3 100644 --- a/crates/metal2vulkan-runtime/src/render.rs +++ b/crates/metal2vulkan-runtime/src/render.rs @@ -362,16 +362,29 @@ impl crate::Device { /// Each constexpr sampler a function samples through takes the device sampler of each use it /// has at its index before the call returns, and every draw pushes the index. /// - /// Err: [`Error::Translation`], the translator's typed refusal or a descriptor Metal refuses; - /// [`Gap::IndirectCommandBuffers`]; [`Gap::RenderPipeline`] for what the runtime does not - /// build, naming it; [`Refusal::PointSizeTopology`] for a vertex function that writes - /// `[[point_size]]` under the line or the triangle class; [`Refusal::SamplerIds`] where - /// `sampler_ids` answers another count; [`Refusal::IndicesNotGranted`] for a constexpr - /// sampler's index; [`Limit::DeviceSamplers`](crate::Limit::DeviceSamplers); [`Error::Vulkan`]. + /// Err: [`Error::Translation`], the translator's typed refusal or a descriptor Metal refuses, + /// naming the vertex and the fragment function; [`Gap::IndirectCommandBuffers`]; + /// [`Gap::RenderPipeline`] for what the runtime does not build, naming it; + /// [`Refusal::PointSizeTopology`] for a vertex function that writes `[[point_size]]` under + /// the line or the triangle class; [`Refusal::SamplerIds`] where `sampler_ids` answers another + /// count; [`Refusal::IndicesNotGranted`] for a constexpr sampler's index; + /// [`Limit::DeviceSamplers`](crate::Limit::DeviceSamplers); [`Error::Vulkan`]. pub fn new_render_pipeline_state( &self, descriptor: &RenderPipelineDescriptor, sampler_ids: impl FnOnce(&[NumberedSampler]) -> Result, Error>, + ) -> Result { + let stages = std::iter::once(&descriptor.vertex).chain(&descriptor.fragment); + (self.render_pipeline_state(descriptor, sampler_ids)) + .map_err(|error| error.of_stages(stages)) + } + + /// [`new_render_pipeline_state`](Self::new_render_pipeline_state), its translator's error + /// naming no function. + fn render_pipeline_state( + &self, + descriptor: &RenderPipelineDescriptor, + sampler_ids: impl FnOnce(&[NumberedSampler]) -> Result, Error>, ) -> Result { refuse(descriptor)?; let core = self.core(); @@ -396,7 +409,7 @@ impl crate::Device { entries, ) }) - .map_err(Error::Translation)?; + .map_err(Error::translation)?; let lowered = lower_stages(core, descriptor, &keys, &budget, entries); core.note_entries(); let (lowered, lowerings) = lowered?; @@ -881,7 +894,7 @@ fn lower_stages( (&descriptor.vertex, &keys.vertex_inputs) { let function = lower(core, function, inputs, budget, entries); - let function = function.map_err(Error::Translation)?; + let function = function.map_err(Error::translation)?; lowerings.vertex = Some(*function.key().digest()); lowered.vertex = StageSource::Compiled(function); } @@ -891,7 +904,7 @@ fn lower_stages( (&descriptor.fragment, &keys.fragment_inputs) { let function = lower(core, function, inputs, budget, entries); - let function = function.map_err(Error::Translation)?; + let function = function.map_err(Error::translation)?; lowerings.fragment = Some(*function.key().digest()); lowered.fragment = Some(StageSource::Compiled(function)); } @@ -942,7 +955,7 @@ impl RenderCompiled { ) -> Result { let translator = &core.translator; let pipeline = translating(core, || translator.compile_render_pipeline(lowered, budget)) - .map_err(Error::Translation)?; + .map_err(Error::translation)?; // Metal makes no pipeline of a vertex function that writes `[[point_size]]` under the line // or the triangle class. let class = lowered.input_primitive_topology; diff --git a/crates/metal2vulkan-runtime/src/sampler.rs b/crates/metal2vulkan-runtime/src/sampler.rs index 2e352928c..84f8afb5f 100644 --- a/crates/metal2vulkan-runtime/src/sampler.rs +++ b/crates/metal2vulkan-runtime/src/sampler.rs @@ -368,7 +368,7 @@ impl Device { let desc = |compare, integer| { vk_sampler(descriptor, SamplerUse::new(compare, integer), profile) .map(canonical) - .map_err(Error::Translation) + .map_err(Error::translation) }; let compare = descriptor.compare_function != CompareFunction::Never; let uses = [ diff --git a/crates/metal2vulkan-runtime/src/tests/barycentrics.rs b/crates/metal2vulkan-runtime/src/tests/barycentrics.rs index d61a1136b..9a44dfa68 100644 --- a/crates/metal2vulkan-runtime/src/tests/barycentrics.rs +++ b/crates/metal2vulkan-runtime/src/tests/barycentrics.rs @@ -90,7 +90,10 @@ mod on_device { crate::tests::no_constexpr_samplers, ) { Ok(state) => state, - Err(Error::Translation(metal2vulkan::error::Error::Unsupported(u))) if !on => { + Err(Error::Translation { + error: metal2vulkan::error::Error::Unsupported(u), + .. + }) if !on => { assert_eq!(u.feature, Feature::Barycentrics, "{name}: {u:?}"); println!( "barycentrics: {name}: no fragmentShaderBarycentric; {fragment}'s \ diff --git a/crates/metal2vulkan-runtime/src/tests/draw.rs b/crates/metal2vulkan-runtime/src/tests/draw.rs index e3a1663c9..bdcc7fda0 100644 --- a/crates/metal2vulkan-runtime/src/tests/draw.rs +++ b/crates/metal2vulkan-runtime/src/tests/draw.rs @@ -2292,17 +2292,19 @@ define internal void @_GLOBAL__sub_I_() section "air.static_init" { let divides = profile.fragment().vertex_attribute_divisor && profile.limits().max_vertex_attrib_divisor >= 2; let nonzero = profile.limits().supports_non_zero_first_instance; - let state = match device - .new_render_pipeline_state(&d, crate::tests::no_constexpr_samplers) - { - Ok(state) => state, - Err(Error::Translation(metal2vulkan::error::Error::Unsupported(u))) if !divides => { - assert_eq!(u.feature, Feature::VertexStepRate, "{name}: {u:?}"); - println!("{name}: no step rates; a step rate of 2 refused"); - return; - } - Err(other) => panic!("{name}: {other}"), - }; + let state = + match device.new_render_pipeline_state(&d, crate::tests::no_constexpr_samplers) { + Ok(state) => state, + Err(Error::Translation { + error: metal2vulkan::error::Error::Unsupported(u), + .. + }) if !divides => { + assert_eq!(u.feature, Feature::VertexStepRate, "{name}: {u:?}"); + println!("{name}: no step rates; a step rate of 2 refused"); + return; + } + Err(other) => panic!("{name}: {other}"), + }; assert!(divides, "{name}: a step rate of 2 made a state"); let from_zero = two_instances(name, &device, &state, 0) .unwrap_or_else(|error| panic!("{name}: from base instance 0: {error}")); diff --git a/crates/metal2vulkan-runtime/src/tests/interpolation.rs b/crates/metal2vulkan-runtime/src/tests/interpolation.rs index f0139a613..6625a5a19 100644 --- a/crates/metal2vulkan-runtime/src/tests/interpolation.rs +++ b/crates/metal2vulkan-runtime/src/tests/interpolation.rs @@ -168,9 +168,11 @@ keep: match device .new_render_pipeline_state(&with(function), crate::tests::no_constexpr_samplers) { - Err(Error::Translation(metal2vulkan::error::Error::Unsupported(u))) - if u.feature == Feature::DivergentInterpolation - && u.needs == Needs::NotImplemented => {} + Err(Error::Translation { + error: metal2vulkan::error::Error::Unsupported(u), + .. + }) if u.feature == Feature::DivergentInterpolation + && u.needs == Needs::NotImplemented => {} Err(error) => panic!("{name}: {function}: {error}"), Ok(_) => panic!("{name}: {function} was made"), } diff --git a/crates/metal2vulkan-runtime/src/tests/layered.rs b/crates/metal2vulkan-runtime/src/tests/layered.rs index 060dd046a..acd66b78d 100644 --- a/crates/metal2vulkan-runtime/src/tests/layered.rs +++ b/crates/metal2vulkan-runtime/src/tests/layered.rs @@ -215,7 +215,10 @@ mod on_device { crate::tests::no_constexpr_samplers, ); let refused = match differing { - Err(Error::Translation(metal2vulkan::error::Error::Unsupported(u))) => { + Err(Error::Translation { + error: metal2vulkan::error::Error::Unsupported(u), + .. + }) => { assert_eq!(u.feature, Feature::LayeredRendering, "{name}: {u:?}"); u } diff --git a/crates/metal2vulkan-runtime/src/tests/lowered.rs b/crates/metal2vulkan-runtime/src/tests/lowered.rs index 49d6e01d2..b7d5fa4c5 100644 --- a/crates/metal2vulkan-runtime/src/tests/lowered.rs +++ b/crates/metal2vulkan-runtime/src/tests/lowered.rs @@ -36,7 +36,7 @@ fn a_lowering_error_is_not_reported_as_the_variant_s_gap() { assert!( matches!( Lowered::Translation(internal.clone()).kernel(partial_simdgroups), - Err(Error::Translation(ref error)) if *error == internal + Err(Error::Translation { ref error, .. }) if *error == internal ), "a builder error: {}", reported(&Lowered::Translation(internal)) diff --git a/crates/metal2vulkan-runtime/src/tests/min_lod.rs b/crates/metal2vulkan-runtime/src/tests/min_lod.rs index 2e976a432..18b308707 100644 --- a/crates/metal2vulkan-runtime/src/tests/min_lod.rs +++ b/crates/metal2vulkan-runtime/src/tests/min_lod.rs @@ -58,7 +58,10 @@ mod on_device { let state = match device.new_render_pipeline_state(&d, crate::tests::no_constexpr_samplers) { Ok(state) => state, - Err(Error::Translation(metal2vulkan::error::Error::Unsupported(u))) if !on => { + Err(Error::Translation { + error: metal2vulkan::error::Error::Unsupported(u), + .. + }) if !on => { assert_eq!(u.feature, Feature::MinLodClamp, "{name}: {u:?}"); println!("min_lod: {name}: no shaderResourceMinLod; the state is refused"); return; diff --git a/crates/metal2vulkan-runtime/src/tests/patch.rs b/crates/metal2vulkan-runtime/src/tests/patch.rs index fb35a4368..49b1f4dd7 100644 --- a/crates/metal2vulkan-runtime/src/tests/patch.rs +++ b/crates/metal2vulkan-runtime/src/tests/patch.rs @@ -690,11 +690,22 @@ BUFFER_META"#; assert!( matches!( &got, - Err(Error::Translation(metal2vulkan::error::Error::Unsupported(u))) - if u.feature == Feature::Tessellation + Err(Error::Translation { + error: metal2vulkan::error::Error::Unsupported(u), + functions, + }) if u.feature == Feature::Tessellation + && *functions == ["tess_triangle_points", "tess_fragment"] ), "{name}: a control-point index type: {:?}", - got.err() + got.as_ref().err() + ); + // The error's text names the vertex and the fragment function, in that order. + let text = got.err().map(|error| error.to_string()).unwrap_or_default(); + assert!( + text.starts_with( + "the translator made no pipeline of tess_triangle_points, tess_fragment: " + ), + "{name}: {text}" ); let patch_state = state(name, &device, &d); let plain_state = state(name, &device, &plain); diff --git a/crates/metal2vulkan-runtime/src/tests/pixel_interlock.rs b/crates/metal2vulkan-runtime/src/tests/pixel_interlock.rs index 1833bee3a..ac8c21212 100644 --- a/crates/metal2vulkan-runtime/src/tests/pixel_interlock.rs +++ b/crates/metal2vulkan-runtime/src/tests/pixel_interlock.rs @@ -51,7 +51,10 @@ mod on_device { .new_render_pipeline_state(&d, crate::tests::no_constexpr_samplers) { Ok(state) => state, - Err(Error::Translation(metal2vulkan::error::Error::Unsupported(u))) if !on => { + Err(Error::Translation { + error: metal2vulkan::error::Error::Unsupported(u), + .. + }) if !on => { assert_eq!(u.feature, Feature::RasterOrderGroups, "{name}: {u:?}"); println!("pixel_interlock: {name}: no pixel interlock; the state is refused"); return; diff --git a/crates/metal2vulkan-runtime/src/tests/quad_control.rs b/crates/metal2vulkan-runtime/src/tests/quad_control.rs index 315451441..f06d62d39 100644 --- a/crates/metal2vulkan-runtime/src/tests/quad_control.rs +++ b/crates/metal2vulkan-runtime/src/tests/quad_control.rs @@ -57,7 +57,10 @@ mod on_device { let state = match device.new_render_pipeline_state(&d, crate::tests::no_constexpr_samplers) { Ok(state) => state, - Err(Error::Translation(metal2vulkan::error::Error::Unsupported(u))) if !on => { + Err(Error::Translation { + error: metal2vulkan::error::Error::Unsupported(u), + .. + }) if !on => { assert_eq!(u.feature, Feature::SubgroupOperations, "{name}: {u:?}"); println!("quad_control: {name}: no quad control; the state is refused"); return; diff --git a/crates/metal2vulkan-runtime/src/tests/sampler.rs b/crates/metal2vulkan-runtime/src/tests/sampler.rs index bc3d7c954..abc9112f2 100644 --- a/crates/metal2vulkan-runtime/src/tests/sampler.rs +++ b/crates/metal2vulkan-runtime/src/tests/sampler.rs @@ -262,7 +262,7 @@ mod on_device { }, ); assert!( - matches!(numbered, Err(Error::Translation(_))), + matches!(numbered, Err(Error::Translation { .. })), "{name}: the NaN bias is the translator's refusal" ); assert_eq!( diff --git a/crates/metal2vulkan-runtime/src/tests/translate.rs b/crates/metal2vulkan-runtime/src/tests/translate.rs index 50c97f5e2..9f0569aae 100644 --- a/crates/metal2vulkan-runtime/src/tests/translate.rs +++ b/crates/metal2vulkan-runtime/src/tests/translate.rs @@ -3650,4 +3650,34 @@ declare i32 @air.get_height_texture_2d(ptr addrspace(1), i32) ); }); } + + /// A refused state's error names its function by its own name in its library: a compute + /// state of the examples' vertex function `colored_vertex`, which Metal makes no compute state + /// of, is `Error::Translation` naming it, and its text prints the name. + #[test] + fn every_device_names_the_function_of_a_refused_compute_state() { + let Some(examples) = crate::tests::draw::on_device::examples() else { + return; + }; + let descriptor = ComputePipelineDescriptor::new(StageSource::Function( + FunctionDescriptor::new(examples.function("colored_vertex").expect("the function")), + )); + each_device("refused compute names", |name, _, device| { + let got = device + .new_compute_pipeline_state(&descriptor, |samplers| Ok(vec![0; samplers.len()])); + match got { + Err(Error::Translation { error, functions }) => { + assert_eq!(functions, ["colored_vertex"], "{name}: {error}"); + let text = Error::Translation { error, functions }.to_string(); + assert!( + text.starts_with("the translator made no pipeline of colored_vertex: "), + "{name}: {text}" + ); + println!("{name}: {text}"); + } + Err(other) => panic!("{name}: {other}"), + Ok(_) => panic!("{name}: a compute state of a vertex function was made"), + } + }); + } } diff --git a/crates/metal2vulkan-validation/src/candidate/platform/runtime.rs b/crates/metal2vulkan-validation/src/candidate/platform/runtime.rs index b8a0618ed..79b07b472 100644 --- a/crates/metal2vulkan-validation/src/candidate/platform/runtime.rs +++ b/crates/metal2vulkan-validation/src/candidate/platform/runtime.rs @@ -251,7 +251,10 @@ pub fn make_kernel( ) -> Result { let function = Library::from_air(bitcode) .and_then(|library| library.function(entry)) - .map_err(rt::Error::Translation)?; + .map_err(|error| rt::Error::Translation { + error, + functions: Vec::new(), + })?; let descriptor = ComputePipelineDescriptor::new(StageSource::Function( FunctionDescriptor::new(function).with_specialized(true), )); @@ -358,7 +361,7 @@ fn environment(identity: &Identity, tools: &[ActiveTool], executor: &str) -> ser /// ([`execute_runtime`]). pub(super) fn runtime_error(what: &str, error: rt::Error) -> ExecutorError { match error { - rt::Error::Translation(error) => product_refusal(&error), + rt::Error::Translation { error, .. } => product_refusal(&error), rt::Error::Unsupported(gap @ rt::Gap::TextureFormat { .. }) => { ExecutorError::NotSupported(NotSupported::NotEnabled(vec![format!("{what}: {gap}")])) } diff --git a/crates/metal2vulkan-validation/src/candidate/tests/engine_compute.rs b/crates/metal2vulkan-validation/src/candidate/tests/engine_compute.rs index 837f329ce..32d150fb4 100644 --- a/crates/metal2vulkan-validation/src/candidate/tests/engine_compute.rs +++ b/crates/metal2vulkan-validation/src/candidate/tests/engine_compute.rs @@ -797,9 +797,10 @@ fn a_texture_buffer_member_is_refused_at_the_make_where_a_2d_member_is_made() { let bitcode = llvm_assemble(&engine_dir().join("rlm_runtime_limits.ll")).unwrap(); platform::on_runtime_device(crate::gpu::TEST_DEVICE, |device| { match platform::make_kernel(device, &bitcode, "rlm_member_texture_buffer") { - Err(metal2vulkan_runtime::Error::Translation( - metal2vulkan::error::Error::Unsupported(refused), - )) => assert!( + Err(metal2vulkan_runtime::Error::Translation { + error: metal2vulkan::error::Error::Unsupported(refused), + .. + }) => assert!( matches!( refused.feature, Feature::IdentityDomains | Feature::ArgumentBufferTextures diff --git a/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs b/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs index a08a40c8e..015b3d526 100644 --- a/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs +++ b/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs @@ -141,7 +141,7 @@ impl Skips { ) -> bool { let gap = match error { rt::Error::Unsupported(gap) => format!("{gap:?}"), - rt::Error::Translation(refused) => translation_kind(refused), + rt::Error::Translation { error: refused, .. } => translation_kind(refused), _ => return false, }; let kind = states.entry(gap); diff --git a/crates/metal2vulkan-validation/src/replay/new_runtime/tests.rs b/crates/metal2vulkan-validation/src/replay/new_runtime/tests.rs index 5a3da2c13..908af29b0 100644 --- a/crates/metal2vulkan-validation/src/replay/new_runtime/tests.rs +++ b/crates/metal2vulkan-validation/src/replay/new_runtime/tests.rs @@ -24,14 +24,20 @@ fn made(result: u64) -> Call { fn translator_refusals_are_counted_by_kind() { let tessellation = || { let feature = Feature::Lowering(LowerFamily::Tessellation); - rt::Error::Translation(Unsupported::not_implemented(feature).into()) + rt::Error::Translation { + error: Unsupported::not_implemented(feature).into(), + functions: Vec::new(), + } }; let answers = [ (7, tessellation()), (8, tessellation()), ( 9, - rt::Error::Translation(Error::LimitExceeded(Limit::SpirvWords)), + rt::Error::Translation { + error: Error::LimitExceeded(Limit::SpirvWords), + functions: Vec::new(), + }, ), ( 10, @@ -75,7 +81,10 @@ fn creations_not_attempted_are_counted_by_kind_and_root() { skips.not_attempted(&function, Via::Receiver, 2); skips.not_attempted(&made(4), Via::Argument, 3); skips.not_attempted(&made(5), Via::Argument, 3); - let refused = rt::Error::Translation(Error::LimitExceeded(Limit::SpirvWords)); + let refused = rt::Error::Translation { + error: Error::LimitExceeded(Limit::SpirvWords), + functions: Vec::new(), + }; assert!(Skips::skipped_state( &mut skips.render_states, &made(6), diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index ec112f97e..974d9493d 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -9200,7 +9200,7 @@ variant metal2vulkan-runtime::Error::NoSuchBlock NoSuchBlock(BlockId) variant metal2vulkan-runtime::Error::Quiesced Quiesced variant metal2vulkan-runtime::Error::Refused Refused(Refusal) variant metal2vulkan-runtime::Error::Thread Thread(io::Error) -variant metal2vulkan-runtime::Error::Translation Translation(metal2vulkan::error::Error) +variant metal2vulkan-runtime::Error::Translation Translation { error: metal2vulkan::error::Error, functions: Vec } variant metal2vulkan-runtime::Error::Unsupported Unsupported(Gap) variant metal2vulkan-runtime::Error::Vulkan Vulkan { call: &'static str, result: vk::Result } variant metal2vulkan-runtime::ExportHandle::DmaBuf DmaBuf diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index 20625eb10..d3526ec91 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -359,7 +359,7 @@ Columns: | Variant | What it blocks | Where | Basis | Sites | Reach | |---|---|---|---|---|---| -| `IndirectCommandBuffers` | A compute pipeline state for indirect command buffers (`supportIndirectCommandBuffers`) | every device (a public call's own check of its arguments) | `ours`: indirect command buffers are not built | 2: `crates/metal2vulkan-runtime/src/pipeline.rs (new_compute_pipeline_state)`, `crates/metal2vulkan-runtime/src/render.rs (refuse)` | `-` | +| `IndirectCommandBuffers` | A compute pipeline state for indirect command buffers (`supportIndirectCommandBuffers`) | every device (a public call's own check of its arguments) | `ours`: indirect command buffers are not built | 2: `crates/metal2vulkan-runtime/src/pipeline.rs (compute_pipeline_state)`, `crates/metal2vulkan-runtime/src/render.rs (refuse)` | `-` | | `KernelInput` | A kernel that reads something the compute encoder does not supply yet, `kind` naming what | every device (a public call's own check of its arguments) | `ours`: the encoder supplies only those | 1: `crates/metal2vulkan-runtime/src/pipeline.rs (gap)` | `-` | | `ImageblockLength` | An imageblock length Metal answers that no case measures | every device (a public call's own check of its arguments) | `ours`: the length is not measured against Metal's | 2: `crates/metal2vulkan-runtime/src/pipeline.rs (imageblock_memory_length_for_dimensions)`, `crates/metal2vulkan-runtime/src/render.rs (imageblock_sample_length)` | `-` | | `PartialSimdgroups` | A dispatch whose threadgroup is not whole SIMD groups of a kernel whose tier runs each SIMD group as one subgroup of `width` threads (a pinned... | every device (a public call's own check of its arguments) | `ours`: no emulated-SIMD-group module | 1: `crates/metal2vulkan-runtime/src/encoder.rs (decide)` | `-` | @@ -644,7 +644,7 @@ Each refusal's sites, with the function that builds it. - `rt:Limit::NoExport`: `crates/metal2vulkan-runtime/src/export.rs (handle, 2 sites)`; `crates/metal2vulkan-runtime/src/export.rs (new_exported_block)`; `crates/metal2vulkan-runtime/src/surface.rs (dma_buf_in_place)`; `crates/metal2vulkan-runtime/src/surface.rs (new_exported_surface)` - `rt:Limit::ExportType`: `crates/metal2vulkan-runtime/src/export.rs (new_exported_block)`; `crates/metal2vulkan-runtime/src/import.rs (surface_import)`; `crates/metal2vulkan-runtime/src/memory.rs (export)`; `crates/metal2vulkan-runtime/src/memory.rs (surface_view)`; `crates/metal2vulkan-runtime/src/surface.rs (dma_buf_in_place)`; `crates/metal2vulkan-runtime/src/surface.rs (new_exported_surface)` - `rt:Limit::TextureSamples`: `crates/metal2vulkan-runtime/src/texture.rs (plan)` -- `rt:Gap::IndirectCommandBuffers`: `crates/metal2vulkan-runtime/src/pipeline.rs (new_compute_pipeline_state)`; `crates/metal2vulkan-runtime/src/render.rs (refuse)` +- `rt:Gap::IndirectCommandBuffers`: `crates/metal2vulkan-runtime/src/pipeline.rs (compute_pipeline_state)`; `crates/metal2vulkan-runtime/src/render.rs (refuse)` - `rt:Gap::KernelInput`: `crates/metal2vulkan-runtime/src/pipeline.rs (gap)` - `rt:Gap::ImageblockLength`: `crates/metal2vulkan-runtime/src/pipeline.rs (imageblock_memory_length_for_dimensions)`; `crates/metal2vulkan-runtime/src/render.rs (imageblock_sample_length)` - `rt:Gap::PartialSimdgroups`: `crates/metal2vulkan-runtime/src/encoder.rs (decide)`