diff --git a/crates/metal2vulkan/src/tests/engine_mesh.rs b/crates/metal2vulkan/src/tests/engine_mesh.rs index ea29264b3..d0cbe9bbe 100644 --- a/crates/metal2vulkan/src/tests/engine_mesh.rs +++ b/crates/metal2vulkan/src/tests/engine_mesh.rs @@ -161,3 +161,96 @@ fn without_the_extension_a_mesh_pipeline_is_refused() { } } } + +/// The features a device enables with `VK_EXT_mesh_shader` for object and mesh functions, needed +/// all together: `taskShader` and `meshShader`, and `multiDrawIndirect` and `drawIndirectCount`, +/// which a mesh draw's pieces take. +const MESH_FEATURES: [VkFeature; 4] = [ + VkFeature::TaskShader, + VkFeature::MeshShader, + VkFeature::MultiDrawIndirect, + VkFeature::DrawIndirectCount, +]; + +/// The device of committed profile `stem` without `feature`. +fn device_without(stem: &str, feature: VkFeature) -> crate::device::Device { + let mut desc = crate::pipeline::testing::description(stem).unwrap_or_else(|e| panic!("{e}")); + assert!( + desc.features.remove(&feature), + "{stem} lists no {feature:?}" + ); + crate::device::Device::from_queries(desc).unwrap_or_else(|e| panic!("{stem}: {e}")) +} + +/// On every committed profile whose device lists `VK_EXT_mesh_shader`, a device without any one of +/// [`MESH_FEATURES`] refuses every object function, every mesh function and every mesh render +/// pipeline, with or without an object function (`Unsupported{MeshShading}`), needing the one it +/// lacks. +#[test] +fn without_any_one_mesh_feature_mesh_stages_are_refused_naming_it() { + use crate::budget::Budget; + use crate::library::Library; + use crate::pipeline::descriptor::{FunctionDescriptor, MeshPipelineDescriptor, StageSource}; + let (Some(order), Some(outputs), Some(draws)) = ( + fixture("mesh_order"), + fixture("mesh_outputs"), + fixture("mesh_draws"), + ) else { + return; + }; + let library = Library::from_air(&draws).expect("library"); + let stage = |name: &str| { + StageSource::Function(FunctionDescriptor::new( + library.function(name).expect("function"), + )) + }; + let stems: Vec = threadgroup_profiles() + .expect("committed profiles") + .into_iter() + .map(|(stem, _)| stem) + .filter(|stem| lists_mesh_shader(stem)) + .collect(); + assert!( + !stems.is_empty(), + "no committed profile lists the extension" + ); + for stem in &stems { + for feature in MESH_FEATURES { + let dev = device_without(stem, feature); + let want = Needs::AnyOf(vec![vec![Capability::Feature(feature)]]); + for (bc, entry) in [ + (&order, "mesh_order_solo"), + (&order, "mesh_order_object"), + (&order, "mesh_order_mesh"), + (&outputs, "mesh_outputs_lines"), + ] { + let what = format!("{stem} without {feature:?}: {entry}"); + match compile(bc, entry, dev.profile()) { + Err(Error::Unsupported(u)) => assert_eq!( + (u.feature, &u.needs), + (Feature::MeshShading, &want), + "{what}" + ), + other => panic!("{what}: {:?}", other.map(|_| ())), + } + } + for object in [None, Some("mesh_draws_object")] { + let what = format!("{stem} without {feature:?}: pipeline, object {object:?}"); + let mut d = MeshPipelineDescriptor::new(stage(match object { + Some(_) => "mesh_draws_mesh", + None => "mesh_draws_grid", + })); + d.object = object.map(stage); + d.rasterization_enabled = false; + match dev.compile_mesh_pipeline(&d, &Budget::standard()) { + Err(Error::Unsupported(u)) => assert_eq!( + (u.feature, &u.needs), + (Feature::MeshShading, &want), + "{what}" + ), + other => panic!("{what}: {:?}", other.map(|_| ())), + } + } + } + } +}