diff --git a/crates/metal2vulkan/src/lower/mesh/mod.rs b/crates/metal2vulkan/src/lower/mesh/mod.rs index fe6a55dad..5975eadd9 100644 --- a/crates/metal2vulkan/src/lower/mesh/mod.rs +++ b/crates/metal2vulkan/src/lower/mesh/mod.rs @@ -315,42 +315,46 @@ fn mesh_outputs<'e>(cx: &SelectCx<'e>) -> Option<&'e MeshOutputs> { }) } -/// What an object (`TaskEXT`) entry needs enabled, `VK_EXT_mesh_shader` and `taskShader`, and a -/// mesh (`MeshEXT`) entry, `VK_EXT_mesh_shader` and `meshShader`: the missing ones, as the -/// refusal names them. -fn missing_caps(cx: &SelectCx<'_>) -> Vec { - let enabled = cx.profile.enabled(); +/// The features object and mesh functions need enabled with `VK_EXT_mesh_shader`, all of them for +/// either stage: `taskShader` and `meshShader` (a mesh render pipeline holds a mesh stage and may +/// hold an object stage), and `multiDrawIndirect` and `drawIndirectCount`, which a mesh draw's +/// pieces take (`bind::mesh_arguments`). +pub const FEATURES: [VkFeature; 4] = [ + VkFeature::TaskShader, + VkFeature::MeshShader, + VkFeature::MultiDrawIndirect, + VkFeature::DrawIndirectCount, +]; + +/// What profile `p` lacks of what an object (`TaskEXT`) or mesh (`MeshEXT`) entry needs enabled, +/// `VK_EXT_mesh_shader` and every one of [`FEATURES`], as the refusal names them. +fn missing_caps(p: &DeviceProfile) -> Vec { + let enabled = p.enabled(); let mut missing = Vec::new(); if !enabled.extensions.contains(&VkExtension::ExtMeshShader) { missing.push(Capability::Extension(VkExtension::ExtMeshShader)); } - let feature = match cx.stage { - Stage::Object => VkFeature::TaskShader, - _ => VkFeature::MeshShader, - }; - if !enabled.features.contains(&feature) { - missing.push(Capability::Feature(feature)); + for feature in FEATURES { + if !enabled.features.contains(&feature) { + missing.push(Capability::Feature(feature)); + } } missing } -/// Whether profile `p` runs mesh functions: it enables `VK_EXT_mesh_shader` and `meshShader`. +/// Whether profile `p` runs object and mesh functions: it enables `VK_EXT_mesh_shader` and every +/// one of [`FEATURES`]. pub fn mesh_stages(p: &DeviceProfile) -> bool { - let enabled = p.enabled(); - enabled.extensions.contains(&VkExtension::ExtMeshShader) - && enabled.features.contains(&VkFeature::MeshShader) + missing_caps(p).is_empty() } /// Whether profile `p` compiles an object function folded (`LoweringInputs::folded_groups`), so /// that its draws run any object grid Metal runs in pieces within the task stage's limits -/// (`bind::mesh_arguments`): it runs mesh functions natively, and has `multiDrawIndirect` (a -/// direct draw's pieces, and `maxDrawIndirectCount` at least 65,535) and `drawIndirectCount` (an -/// indirect draw's). +/// (`bind::mesh_arguments`): it runs mesh functions ([`mesh_stages`], whose `multiDrawIndirect` +/// takes a direct draw's pieces, with `maxDrawIndirectCount` at least 65,535, and whose +/// `drawIndirectCount` an indirect draw's). pub fn folds_object_grids(p: &DeviceProfile) -> bool { - let features = &p.enabled().features; mesh_stages(p) - && features.contains(&VkFeature::MultiDrawIndirect) - && features.contains(&VkFeature::DrawIndirectCount) } /// The bytes of the entry's payload (`air.payload`'s `air.arg_type_size`), if it has one. @@ -456,15 +460,15 @@ pub fn plan_partial_groups(cx: &mut SelectCx<'_>) -> Result<(), Error> { Ok(()) } -/// Plan the entry: an object function needs `VK_EXT_mesh_shader` and `taskShader` enabled, and a -/// mesh function `VK_EXT_mesh_shader` and `meshShader` (`Unsupported{MeshShading}` naming the -/// missing ones); a mesh function's shape, its always-declared outputs ([`CULLED`], +/// Plan the entry: an object or mesh function needs `VK_EXT_mesh_shader` and every one of +/// [`FEATURES`] enabled (`Unsupported{MeshShading}` naming the missing ones); a mesh function's +/// shape, its always-declared outputs ([`CULLED`], /// [`PRIMITIVE_ID`]). Nothing for any other stage. pub fn plan_entry(cx: &mut SelectCx<'_>) -> Result<(), Error> { if !matches!(cx.stage, Stage::Object | Stage::Mesh) { return Ok(()); } - let missing = missing_caps(cx); + let missing = missing_caps(cx.profile); if !missing.is_empty() { return Err(Unsupported::needs_any_of(Feature::MeshShading, vec![missing]).into()); } diff --git a/crates/metal2vulkan/src/pipeline/compile/api.rs b/crates/metal2vulkan/src/pipeline/compile/api.rs index 00287f186..ca61cadcc 100644 --- a/crates/metal2vulkan/src/pipeline/compile/api.rs +++ b/crates/metal2vulkan/src/pipeline/compile/api.rs @@ -476,8 +476,10 @@ impl Device { /// result is a [`RenderPipeline`] whose stages are the object stage (`TASK_EXT`), the mesh /// stage (`MESH_EXT`) and the fragment stage: it has no vertex input and no input assembly (its /// `GraphicsState::topology` is unused), and Metal's draws of it are `drawMeshThreadgroups` and - /// `drawMeshThreads`. A device without `VK_EXT_mesh_shader` and `meshShader` (and `taskShader` - /// for an object function) refuses it (`Unsupported{MeshShading}`). A `Compiled` stage must + /// `drawMeshThreads`. A device without `VK_EXT_mesh_shader`, `taskShader`, `meshShader`, + /// `multiDrawIndirect` and `drawIndirectCount`, all enabled together, refuses it, with or + /// without an object function (`Unsupported{MeshShading}` naming the missing ones). A `Compiled` + /// stage must /// have been compiled under the same inputs and Metal's call stack depth of 1. pub fn compile_mesh_pipeline( &self, diff --git a/crates/metal2vulkan/src/tests/engine_mesh.rs b/crates/metal2vulkan/src/tests/engine_mesh.rs index d0cbe9bbe..44a313d7c 100644 --- a/crates/metal2vulkan/src/tests/engine_mesh.rs +++ b/crates/metal2vulkan/src/tests/engine_mesh.rs @@ -5,7 +5,8 @@ //! `engine/mesh_amplified` what Apple's VFX particle meshes declare (members and an //! amplification id under function constants, a primitive's render target slice and viewport). //! Each mesh function that lowers compiles, on every committed profile whose device lists -//! `VK_EXT_mesh_shader` (which enables it with `taskShader` and `meshShader`), to a `MeshEXT` +//! `VK_EXT_mesh_shader` (which enables it with `taskShader` and `meshShader`, beside +//! `multiDrawIndirect` and `drawIndirectCount`), to a `MeshEXT` //! entry that passes L3 (`spirv-val` and requirements within the profile); the entry states its //! counts and topology, initializes its outputs and culls past its count, its threadgroup memory //! is its workgroup's, and its stage interface lists its user outputs, per vertex or per @@ -85,30 +86,31 @@ fn refusing_profiles() -> Vec<(String, DeviceProfile)> { } /// Without the extension a mesh or object function is refused (`Unsupported{MeshShading}`), needing -/// `VK_EXT_mesh_shader` and the stage's feature (`meshShader`, an object function's `taskShader`) -/// where the profile lacks them. +/// `VK_EXT_mesh_shader` and each of [`MESH_FEATURES`] the profile lacks. #[test] fn without_the_extension_mesh_and_object_functions_are_refused() { let (Some(order), Some(outputs)) = (fixture("mesh_order"), fixture("mesh_outputs")) else { return; }; for (stem, p) in refusing_profiles() { - for (bc, entry, feature) in [ - (&order, "mesh_order_solo", VkFeature::MeshShader), - (&outputs, "mesh_outputs_lines", VkFeature::MeshShader), - (&outputs, "mesh_outputs_points", VkFeature::MeshShader), - (&order, "mesh_order_object", VkFeature::TaskShader), - (&order, "mesh_order_mesh", VkFeature::MeshShader), - ] { - let what = format!("{stem} {entry}"); - let mut missing = vec![Capability::Extension(VkExtension::ExtMeshShader)]; + let mut missing = vec![Capability::Extension(VkExtension::ExtMeshShader)]; + for feature in MESH_FEATURES { if !p.enabled().features.contains(&feature) { missing.push(Capability::Feature(feature)); } + } + for (bc, entry) in [ + (&order, "mesh_order_solo"), + (&outputs, "mesh_outputs_lines"), + (&outputs, "mesh_outputs_points"), + (&order, "mesh_order_object"), + (&order, "mesh_order_mesh"), + ] { + let what = format!("{stem} {entry}"); match compile(bc, entry, &p) { Err(Error::Unsupported(u)) => assert_eq!( (u.feature, &u.needs), - (Feature::MeshShading, &Needs::AnyOf(vec![missing])), + (Feature::MeshShading, &Needs::AnyOf(vec![missing.clone()])), "{what}" ), other => panic!("{what}: {:?}", other.map(|_| ())), diff --git a/docs/API.md b/docs/API.md index f52957164..834504cb7 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1173,10 +1173,11 @@ each instance. A fragment function compiled to read Vulkan's `PrimitiveId` behin `Device::compile_mesh_pipeline` compiles a `MeshPipelineDescriptor` (an optional object function, a mesh function and a fragment function). It draws mesh draws only (`drawMeshThreadgroups:`, `drawMeshThreads:` and their indirect forms). The -stages are task and mesh shaders, which need `VK_EXT_mesh_shader` with `meshShader` (and -`taskShader` for an object function). A device without them (MoltenVK, older ANV) refuses the -pipeline and each of its object and mesh functions (`Unsupported{MeshShading}`, naming what it -lacks). +stages are task and mesh shaders, which need `VK_EXT_mesh_shader` with `taskShader`, `meshShader`, +`multiDrawIndirect` and `drawIndirectCount`, all enabled together, whether or not the pipeline has +an object function (a mesh draw's pieces take the two draw features). A device without any one of +them (MoltenVK, older ANV) refuses the pipeline and each of its object and mesh functions +(`Unsupported{MeshShading}`, naming what it lacks). An object or mesh function that calls a SIMD-group, quad-group or SIMD-group matrix function is refused on every device (`Unsupported{SubgroupOperations}`, `QuadOperations` or `SimdgroupMatrix`,