From 85b896a7e10abe3ea529efc611f8dfd29ea39b4d Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Tue, 10 Nov 2026 02:10:41 -0800 Subject: [PATCH] Mesh pipelines: a required object size answers as Metal's first compile, as the mesh stage's does Metal's answers here depend on what its compiler compiled before, which it keeps across processes keyed on the function's AIR. With the probe's salt now in the AIR (d49370d732), an M3 Max under macOS 27.0.1 answered, twice over, each sequence one fresh salt (m3-max-13430): - required-object-32-max-64: refused on a first compile ("Kernel specified max total threads per threadgroup (32) must match compute pipeline specified max total threads per threadgroup (64)"), refused again, and again after required-object-32x2 or plain; made only after required-object-64-max-64. required-mesh-32-max-64 the same, made only after required-mesh-64-max-64. The object stage was made here because an earlier compile let it be. - A required size gives its stage its threads on a first compile: required-object-32x2 answers an object maximum of 64 (we answered 1024), required-mesh-16x2 a mesh maximum of 32, and a required 32 beside a function's [[max_total_threads_per_threadgroup(64)]] 32 in either stage. So the object stage now refuses a required size of other threads than its maximum (MaxThreadsDiffer { stage: Object }), as the mesh stage already did, and each stage's thread limit is the least of the descriptor's maximum, the function's, the required size's threads and 1024. RUNTIME behaviour: new_mesh_render_pipeline_state refuses an object maximum beside a required object size of other threads, and maxTotalThreadsPer{Object,Mesh}Threadgroup answer a required size's threads. The translator's mesh answers change, under the branch's SEMANTICS_VERSION bump (2015). Tests: engine_mesh's refusal test adds the object cases (32 and 16x2 under 64) and makes 64 under 64; its answers test checks a required size alone in each stage and below a function's maximum; the runtime lane's mesh test does the same on a device. docs/API.md's accepted difference, the error's and the getters' docs and the probe's measurements say the first-compile rule and what later compiles answer. (cherry picked from commit 3b05b274aec46c172fd0a38276c5ca45a1ade4ca) --- .../probes/mesh_pipeline_limits.m | 57 ++++++------- .../src/pipeline/render.rs | 15 ++-- .../src/runtime_lane/mesh_draws.rs | 39 +++++++-- crates/metal2vulkan/src/error/mod.rs | 10 ++- crates/metal2vulkan/src/pipeline/artifact.rs | 11 +-- .../metal2vulkan/src/pipeline/compile/api.rs | 52 +++++++----- crates/metal2vulkan/src/tests/engine_mesh.rs | 79 +++++++++++++++---- docs/API.md | 16 ++-- 8 files changed, 185 insertions(+), 94 deletions(-) diff --git a/crates/metal2vulkan-conformance/probes/mesh_pipeline_limits.m b/crates/metal2vulkan-conformance/probes/mesh_pipeline_limits.m index eaa8ef3fb..b9b632a7f 100644 --- a/crates/metal2vulkan-conformance/probes/mesh_pipeline_limits.m +++ b/crates/metal2vulkan-conformance/probes/mesh_pipeline_limits.m @@ -19,48 +19,49 @@ // comparison folds away. `mesh_pipeline_limits --cases` lists the cases. Run one case a process: a // stop of Metal's ends only its own. // -// Measured on an M3 Max under macOS 27.0.1, plain and with `MTL_DEBUG_LAYER=1`, which agree: +// Measured on an M3 Max under macOS 27.0.1, plain and with `MTL_DEBUG_LAYER=1`, which agree; the +// thread limits beside a required size or a function's maximum plain, each a first compile (a +// salt never used before): // - Made, answering (object threads, mesh threads, object width, mesh width, mesh grid): // `plain` 1024, 1024, 32, 32, 1048576, and `maxTotalThreadsPerThreadgroup` 0 in every case; -// `no-object` 3, 1024, 32, 32, 1048576; `max-64-32` 64 and 32; `attribute-64`, -// `attribute-64-max-64` and `required-object-32-attribute-64` 64 for the object stage, -// `mesh-attribute-64`, `mesh-attribute-64-max-64` and `required-mesh-32-attribute-64` 64 for -// the mesh stage; `grid-8` 8, `grid-2097152` 2097152, `grid-8-no-object` 8; `grid-attribute-4` -// 1048576 (an object function's `max_total_threadgroups_per_mesh_grid` changes nothing), with -// `grid-attribute-4-grid-8` 8 and `-grid-2` 2; `payload-64`, `payload-16384` and -// `amplification-2` as `plain`. A required size is answered as given and changes no thread -// limit: `required-object-32x2` (32,2,1), `required-mesh-16x2` (16,2,1), -// `required-object-32-max-64` and `required-object-64-max-64` (64 for the object stage), -// `required-mesh-64-max-64` (64 for the mesh stage). +// `no-object` 3, 1024, 32, 32, 1048576; `max-64-32` 64 and 32; `attribute-64` and +// `attribute-64-max-64` 64 for the object stage, `mesh-attribute-64` and +// `mesh-attribute-64-max-64` 64 for the mesh stage; `grid-8` 8, `grid-2097152` 2097152, +// `grid-8-no-object` 8; `grid-attribute-4` 1048576 (an object function's +// `max_total_threadgroups_per_mesh_grid` changes nothing), with `grid-attribute-4-grid-8` 8 and +// `-grid-2` 2; `payload-64`, `payload-16384` and `amplification-2` as `plain`. A required size +// is answered as given and its threads are its stage's limit, below a function's own maximum +// too: `required-object-32x2` (32,2,1) 64 for the object stage, `required-mesh-16x2` (16,2,1) +// 32 for the mesh stage, `required-object-64-max-64` and `required-mesh-64-max-64` 64, +// `required-object-32-attribute-64` and `required-mesh-32-attribute-64` 32. // - Refused, domain `AGXMetalG15X_M1`, code 3: a maximum of 2048 for either stage, with or // without an object function (`max-object-2048`, `max-mesh-2048`, `max-mesh-2048-no-object`: // "Specified total max threads per threadgroup (2048) exceeds the maximum total threads per // threadgroup supported (1024)"); a function's maximum beside another of the descriptor's // (`attribute-64-max-32`, `-max-128`, `mesh-attribute-64-max-32`, `-max-128`: "Kernel specified // max total threads per threadgroup (64) must match compute pipeline specified max total threads -// per threadgroup (32)"); a required mesh size of fewer threads than the mesh maximum -// (`required-mesh-32-max-64`, the same words, 32 and 64); `payload-16385` ("Object shader payload -// size (16385) exceeds the maximum payload size allowed (16384)"). Code 2: -// `payload-16385-no-object` ("Payload size > 16384"). +// per threadgroup (32)"); a required size of fewer threads than its stage's maximum +// (`required-object-32-max-64`, `required-mesh-32-max-64`, the same words, 32 and 64); +// `payload-16385` ("Object shader payload size (16385) exceeds the maximum payload size allowed +// (16384)"). Code 2: `payload-16385-no-object` ("Payload size > 16384"). // - The process ends at the descriptor's validation (exit 134), with or without API validation: // `amplification-0` ("maxVertexAmplificationCount (0) cannot be set to zero."); a required size // with an axis of 0 (`required-object-4x0`, `required-mesh-4x0`: "... must not be 0."), of 2048 // threads (`required-object-2048`, `required-mesh-2048`: "must be <= 1024 (device limit)"), of // more threads than its stage's maximum (`required-object-64-max-32`, `required-mesh-64-max-32`: -// "must be <= maxTotalThreadsPerThreadgroup (32)"); a required object size without an object -// function (`required-object-no-object`: "If objectFunction is nil, +// "must be <= maxTotalThreadsPerThreadgroup (32)"); a required size of an object stage without an +// object function (`required-object-no-object`: "If objectFunction is nil, // requiredThreadsPerObjectThreadgroup must be [0, 0, 0] but is [32, 1, 1]"). -// - The answers of a required size, and of a function's `[[max_total_threads_per_threadgroup]]`, -// change with what the compiler compiled before, the answers above among them. Each creation of -// a source compiled once and never before (a comment unique to it), on the same M3 Max: a -// required mesh size of 32 under a mesh maximum of 64 is refused as above, plain and under API -// validation, and made, answering 64, after the same source's compile under a required 64; a -// required object size of 32 under an object maximum of 64 is refused with the same words; a -// required mesh size of 16x2 with no maximum answered a mesh maximum of 1024 plain and 32 under -// API validation, and a required 32 answered 1024 in one source and 32 in another; `obj64` -// answered an object maximum of 32, and `msh64` a mesh maximum of 32, where this probe's -// `attribute-64` and `mesh-attribute-64` answered 64. The conformance suite's `mesh-limits` -// cases leave both out. +// - Later compiles of the same functions answer from what the compiler compiled before, which it +// keeps across processes. In one salt each, twice over: `required-object-32-max-64` is refused +// again, and again after `required-object-32x2` or `plain`, and made (64 for the object stage) +// after `required-object-64-max-64`; `required-mesh-32-max-64` is refused again, and after +// `required-mesh-16x2`, and made (64) after `required-mesh-64-max-64`; +// `required-object-32-attribute-64` answers 64 after `attribute-64`, and +// `required-mesh-32-attribute-64` 64 after `mesh-attribute-64`; after `required-object-32x2`, +// `required-mesh-16x2` and `plain` answer 64 for the object stage. Unsalted, after earlier runs, +// `required-object-32-max-64` and `required-mesh-32-max-64` were made. The conformance suite's +// `mesh-limits` cases leave required sizes and functions' maxima out. #import #import #include diff --git a/crates/metal2vulkan-runtime/src/pipeline/render.rs b/crates/metal2vulkan-runtime/src/pipeline/render.rs index 071c605ed..0473bbaff 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/render.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/render.rs @@ -1286,13 +1286,14 @@ impl RenderPipelineState { } /// `maxTotalThreadsPerObjectThreadgroup`: a mesh state's - /// ([`MeshPipelineMetalInfo::max_total_threads_per_object_threadgroup`]): the descriptor's - /// maximum, else the object function's `[[max_total_threads_per_threadgroup(n)]]`, else - /// 1024, as an M3 Max answers, held to this device's limit for the stage where that is lower - /// (the task stage's invocations with `VK_EXT_mesh_shader`, else the compute stage's), as a - /// compute state's `maxTotalThreadsPerThreadgroup` is. 0 for a mesh state without an object - /// function, where an M3 Max answers 3 (docs/API.md, accepted differences), and for any - /// other state. A draw is not held to it. + /// ([`MeshPipelineMetalInfo::max_total_threads_per_object_threadgroup`]): the least of the + /// descriptor's maximum, the object function's `[[max_total_threads_per_threadgroup(n)]]`, + /// the threads of the required object size and 1024, as an M3 Max answers on a first compile, + /// held to this device's limit for the stage where that is lower (the task stage's + /// invocations with `VK_EXT_mesh_shader`, else the compute stage's), as a compute state's + /// `maxTotalThreadsPerThreadgroup` is. 0 for a mesh state without an object function, where + /// an M3 Max answers 3 (docs/API.md, accepted differences), and for any other state. A draw + /// is not held to it. pub fn max_total_threads_per_object_threadgroup(&self) -> u32 { self.mesh_info() .map_or(0, |i| i.max_total_threads_per_object_threadgroup) diff --git a/crates/metal2vulkan-validation/src/runtime_lane/mesh_draws.rs b/crates/metal2vulkan-validation/src/runtime_lane/mesh_draws.rs index 3d2db89ce..5bd81fc53 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/mesh_draws.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/mesh_draws.rs @@ -1058,12 +1058,13 @@ fn mesh_draws_answer_as_plain_metal_and_refuse_the_rest() { /// A mesh state answers Metal's queries on this device, and a descriptor Metal refuses is refused /// naming Metal's rule (`Compile(InvalidDescriptor(MeshPipeline))`, as an M3 Max refuses each, -/// `mesh_pipeline_limits.m`): each stage's thread limit is the descriptor's maximum, else 1024, -/// within the device's limit for the stage (the task and mesh stages' invocations with -/// `VK_EXT_mesh_shader`, else the compute stage's), the widths 32, the mesh grid the -/// descriptor's maximum, else 2^20, within the device's `maxMeshWorkGroupTotalCount` where it -/// runs mesh functions natively; the required sizes are the descriptor's, and change no limit; -/// without an object function the object stage answers 0. Each answer and refusal is printed. +/// `mesh_pipeline_limits.m`, on a first compile): each stage's thread limit is the least of the +/// descriptor's maximum, the threads of the stage's required size and 1024, within the device's +/// limit for the stage (the task and mesh stages' invocations with `VK_EXT_mesh_shader`, else the +/// compute stage's), the widths 32, the mesh grid the descriptor's maximum, else 2^20, within the +/// device's `maxMeshWorkGroupTotalCount` where it runs mesh functions natively; the required sizes +/// are the descriptor's; without an object function the object stage answers 0. Each answer and +/// refusal is printed. #[test] fn a_mesh_state_answers_metals_queries_and_refuses_what_metal_refuses() { use metal2vulkan::error::{DescriptorError, MeshPipelineProblem as P}; @@ -1127,7 +1128,7 @@ fn a_mesh_state_answers_metals_queries_and_refuses_what_metal_refuses() { limited.max_total_threads_per_object_threadgroup = Some(64); limited.max_total_threads_per_mesh_threadgroup = Some(32); limited.max_total_threadgroups_per_mesh_grid = Some(8); - limited.required_threads_per_object_threadgroup = Some([16, 2, 1]); + limited.required_threads_per_object_threadgroup = Some([32, 2, 1]); limited.required_threads_per_mesh_threadgroup = Some([32, 1, 1]); let state = make(&limited).unwrap_or_else(|e| panic!("limited on {name}: {e}")); eprintln!("MESH-ANSWERS limited on {name}: {:?}", answers(&state)); @@ -1138,7 +1139,17 @@ fn a_mesh_state_answers_metals_queries_and_refuses_what_metal_refuses() { ); assert_eq!( state.required_threads_per_object_threadgroup(), - size([16, 2, 1]) + size([32, 2, 1]) + ); + // A required size alone gives its stage its threads. + let mut required = plain.clone(); + required.required_threads_per_object_threadgroup = Some([32, 2, 1]); + let state = make(&required).unwrap_or_else(|e| panic!("required on {name}: {e}")); + eprintln!("MESH-ANSWERS required on {name}: {:?}", answers(&state)); + assert_eq!( + answers(&state), + [object.min(64), mesh.min(1024), 32, 32, total.min(1 << 20)], + "required on {name}" ); assert_eq!( state.required_threads_per_mesh_threadgroup(), @@ -1211,6 +1222,18 @@ fn a_mesh_state_answers_metals_queries_and_refuses_what_metal_refuses() { max: 64, }, ), + ( + "required-object-32-max-64", + with(&plain, &|d| { + d.max_total_threads_per_object_threadgroup = Some(64); + d.required_threads_per_object_threadgroup = Some([32, 1, 1]); + }), + P::MaxThreadsDiffer { + stage: Stage::Object, + specified: 32, + max: 64, + }, + ), ( "payload-16385", with(&plain, &|d| d.payload_memory_length = Some(16385)), diff --git a/crates/metal2vulkan/src/error/mod.rs b/crates/metal2vulkan/src/error/mod.rs index da030c3ab..3b6650202 100644 --- a/crates/metal2vulkan/src/error/mod.rs +++ b/crates/metal2vulkan/src/error/mod.rs @@ -2021,10 +2021,12 @@ pub enum MeshPipelineProblem { /// with or without an object function. MaxThreadsOverLimit { stage: Stage, max: u32, limit: u32 }, /// `stage`'s descriptor maximum `max` beside other `specified` threads: those of its - /// function's `[[max_total_threads_per_threadgroup(n)]]`, or of the mesh stage's required - /// size. The creation fails, code 3, "Kernel specified max total threads per threadgroup (64) - /// must match compute pipeline specified max total threads per threadgroup (32)". An object - /// stage's required size of fewer threads than its maximum is made. + /// function's `[[max_total_threads_per_threadgroup(n)]]`, or of the stage's required size. + /// The creation fails, code 3, "Kernel specified max total threads per threadgroup (64) + /// must match compute pipeline specified max total threads per threadgroup (32)". Metal + /// refuses a required size so on its first compile of the stage's function; it makes it + /// once it compiled that function under the same maximum and a required size of the + /// maximum's threads, which this refusal does not follow. MaxThreadsDiffer { stage: Stage, specified: u32, diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index ba892f616..5b0c4462a 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -568,14 +568,15 @@ impl RuntimeDependency { } /// Answers to Metal's queries of a mesh render pipeline's state (`MTLRenderPipelineState`'s -/// mesh properties), as an M3 Max under macOS 27.0.1 answers them (`mesh_pipeline_limits.m`). -/// Each thread limit is Metal's: the descriptor's maximum, else the stage function's own -/// `[[max_total_threads_per_threadgroup(n)]]`, else 1024 (Metal refuses the two apart and either -/// above 1024, [`MeshPipelineProblem`](crate::error::MeshPipelineProblem)), held to this device's +/// mesh properties), as an M3 Max under macOS 27.0.1 answers them on a first compile of the +/// functions (`mesh_pipeline_limits.m`). Each thread limit is Metal's: the least of the +/// descriptor's maximum, the stage function's own `[[max_total_threads_per_threadgroup(n)]]`, +/// the threads of the stage's required threadgroup size and 1024 (Metal refuses a descriptor +/// maximum other than the function's or the required size's threads, and any of them above +/// 1024, [`MeshPipelineProblem`](crate::error::MeshPipelineProblem)), held to this device's /// limit for the stage where that is lower: `maxTaskWorkGroupInvocations` and /// `maxMeshWorkGroupInvocations` with `VK_EXT_mesh_shader`, and `maxComputeWorkGroupInvocations` /// where the device runs both stages as compute work (`DeviceProfile::emulates_mesh_shading`). -/// A required threadgroup size changes none of them, as on Metal. #[non_exhaustive] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/crates/metal2vulkan/src/pipeline/compile/api.rs b/crates/metal2vulkan/src/pipeline/compile/api.rs index d043e8121..d53b13f4e 100644 --- a/crates/metal2vulkan/src/pipeline/compile/api.rs +++ b/crates/metal2vulkan/src/pipeline/compile/api.rs @@ -693,15 +693,21 @@ impl Device { limits.mesh.max_mesh_work_group_invocations, ) }; - // Metal's: the least of 1024, the function's own maximum and the descriptor's (Metal's 0 - // is none), within the device's. - let threads = |f: &CompiledFunction, given: Option, device: u32| { - [f.artifact().kernel.max_total_threads, given] - .into_iter() - .flatten() - .filter(|&n| n > 0) - .fold(METAL_MAX_THREADS.min(device), u32::min) - }; + // Metal's on a first compile: the least of 1024, the function's own maximum, the + // descriptor's (Metal's 0 is none) and the threads of the stage's required size (Metal's + // all-zero size is none), within the device's. + let threads = + |f: &CompiledFunction, given: Option, required: Option<[u32; 3]>, device: u32| { + let required = required_size(required).map(|axes| { + let threads: u64 = axes.iter().map(|&axis| u64::from(axis)).product(); + u32::try_from(threads).unwrap_or(u32::MAX) + }); + [f.artifact().kernel.max_total_threads, given, required] + .into_iter() + .flatten() + .filter(|&n| n > 0) + .fold(METAL_MAX_THREADS.min(device), u32::min) + }; let width = self.metal_properties().thread_execution_width; // The descriptor's, else Metal's: an object function's // `[[max_total_threadgroups_per_mesh_grid(n)]]` changes nothing Metal answers. @@ -715,11 +721,17 @@ impl Device { }; MeshPipelineMetalInfo { max_total_threads_per_object_threadgroup: object.map_or(0, |o| { - threads(o, d.max_total_threads_per_object_threadgroup, object_limit) + threads( + o, + d.max_total_threads_per_object_threadgroup, + d.required_threads_per_object_threadgroup, + object_limit, + ) }), max_total_threads_per_mesh_threadgroup: threads( mesh, d.max_total_threads_per_mesh_threadgroup, + d.required_threads_per_mesh_threadgroup, mesh_limit, ), object_thread_execution_width: object.map_or(0, |_| width), @@ -1468,8 +1480,8 @@ fn required_size(required: Option<[u32; 3]>) -> Option<[u32; 3]> { /// Metal's refusals of mesh descriptor `d` before any compile ([`MeshPipelineProblem`]), in /// Metal's order: those its descriptor validation ends the process at (the required sizes, an -/// amplification count of 0), then the creation's errors over the thread maxima, the mesh -/// stage's required size and the payload length. +/// amplification count of 0), then the creation's errors over the thread maxima, each stage's +/// required size beside its maximum and the payload length. fn check_mesh_fields(d: &MeshPipelineDescriptor) -> Result<(), Error> { let stages = [ ( @@ -1532,18 +1544,18 @@ fn check_mesh_fields(d: &MeshPipelineDescriptor) -> Result<(), Error> { })); } } - // The mesh stage's required size gives its threads, as its function's maximum does; an - // object stage's does not. - let required = required_size(d.required_threads_per_mesh_threadgroup); - let max = d - .max_total_threads_per_mesh_threadgroup - .filter(|&max| max > 0); - if let (Some(required), Some(max)) = (required, max) { + // A stage's required size gives its threads, as its function's maximum does, in either + // stage: Metal's first compile refuses a maximum of other threads. + for (stage, required, max) in stages { + let (Some(required), Some(max)) = (required_size(required), max.filter(|&max| max > 0)) + else { + continue; + }; // Within the limit, so within `u32`. let specified = required.iter().product::(); if specified != max { return Err(mesh_refusal(MeshPipelineProblem::MaxThreadsDiffer { - stage: Stage::Mesh, + stage, specified, max, })); diff --git a/crates/metal2vulkan/src/tests/engine_mesh.rs b/crates/metal2vulkan/src/tests/engine_mesh.rs index 5df37c495..43a203539 100644 --- a/crates/metal2vulkan/src/tests/engine_mesh.rs +++ b/crates/metal2vulkan/src/tests/engine_mesh.rs @@ -1942,14 +1942,14 @@ fn a_mesh_functions_buffer_writes_need_no_stage_store_feature() { } /// A mesh render pipeline's answers to Metal's mesh queries (`RenderPipeline::mesh_info`), on -/// every committed profile, emulated or not: each stage's thread limit is the descriptor's maximum, -/// else the function's `[[max_total_threads_per_threadgroup(n)]]`, else 1024, within the device's -/// limit for the stage (the task and mesh stages' invocations, or the compute stage's where it -/// runs them as compute work); the widths are 32; the mesh grid is the descriptor's maximum, else -/// 2^20 whatever the object function's `[[max_total_threadgroups_per_mesh_grid(n)]]`, within the -/// device's `maxMeshWorkGroupTotalCount` where it runs mesh functions natively. Without an object -/// function the object stage answers 0 and 0. A required size leaves the limits. Each as an M3 -/// Max answers (`mesh_pipeline_limits.m`). +/// every committed profile, emulated or not: each stage's thread limit is the least of the +/// descriptor's maximum, the function's `[[max_total_threads_per_threadgroup(n)]]`, the threads of +/// the stage's required size and 1024, within the device's limit for the stage (the task and mesh +/// stages' invocations, or the compute stage's where it runs them as compute work); the widths are +/// 32; the mesh grid is the descriptor's maximum, else 2^20 whatever the object function's +/// `[[max_total_threadgroups_per_mesh_grid(n)]]`, within the device's `maxMeshWorkGroupTotalCount` +/// where it runs mesh functions natively. Without an object function the object stage answers 0 +/// and 0. Each as an M3 Max answers on a first compile (`mesh_pipeline_limits.m`). #[test] fn a_mesh_pipeline_answers_metals_mesh_queries_within_the_device() { use crate::budget::Budget; @@ -2007,8 +2007,8 @@ fn a_mesh_pipeline_answers_metals_mesh_queries_within_the_device() { answers(object.min(1024), mesh.min(1024), 32, total.min(1 << 20)), "{stem}" ); - // The descriptor's maxima, a grid past 2^20 among them, and a required size, which - // leaves them. + // The descriptor's maxima, a grid past 2^20 among them, and a required size of the + // object maximum's threads. let mut limited = d.clone(); limited.max_total_threads_per_object_threadgroup = Some(64); limited.max_total_threads_per_mesh_threadgroup = Some(32); @@ -2019,12 +2019,28 @@ fn a_mesh_pipeline_answers_metals_mesh_queries_within_the_device() { "{stem}" ); limited.max_total_threadgroups_per_mesh_grid = Some(1 << 21); - limited.required_threads_per_object_threadgroup = Some([16, 2, 1]); + limited.required_threads_per_object_threadgroup = Some([32, 2, 1]); assert_eq!( info(&limited), answers(object.min(64), mesh.min(32), 32, total.min(1 << 21)), "{stem}" ); + // A required size alone gives its stage its threads (an M3 Max's first compile answers 64 + // for `required-object-32x2` and 32 for `required-mesh-16x2`). + let mut required = d.clone(); + required.required_threads_per_object_threadgroup = Some([32, 2, 1]); + assert_eq!( + info(&required), + answers(object.min(64), mesh.min(1024), 32, total.min(1 << 20)), + "{stem}" + ); + required.required_threads_per_object_threadgroup = None; + required.required_threads_per_mesh_threadgroup = Some([16, 2, 1]); + assert_eq!( + info(&required), + answers(object.min(1024), mesh.min(32), 32, total.min(1 << 20)), + "{stem}" + ); // The functions' own maxima (`mesh_outputs_object`'s 64 threads, `mesh_outputs_triangles`' // 32 threads), and the descriptor's equal ones; the object function's 16 threadgroups // change no grid. @@ -2042,6 +2058,17 @@ fn a_mesh_pipeline_answers_metals_mesh_queries_within_the_device() { total.min(32), "{stem}" ); + // A required size below the function's own maximum gives its stage its threads (an M3 + // Max's first compile answers 32 for `required-object-32-attribute-64`). + own.max_total_threads_per_object_threadgroup = None; + own.max_total_threads_per_mesh_threadgroup = None; + own.max_total_threadgroups_per_mesh_grid = None; + own.required_threads_per_mesh_threadgroup = Some([16, 1, 1]); + assert_eq!( + info(&own), + answers(object.min(64), mesh.min(16), 32, total.min(1 << 20)), + "{stem}" + ); // Without an object function. let mut alone = MeshPipelineDescriptor::new(stage(&draws, "mesh_draws_grid")); alone.rasterization_enabled = false; @@ -2053,7 +2080,7 @@ fn a_mesh_pipeline_answers_metals_mesh_queries_within_the_device() { alone.required_threads_per_mesh_threadgroup = Some([16, 2, 1]); assert_eq!( info(&alone), - answers(0, mesh.min(1024), 0, total.min(1 << 20)), + answers(0, mesh.min(32), 0, total.min(1 << 20)), "{stem}" ); } @@ -2063,8 +2090,8 @@ fn a_mesh_pipeline_answers_metals_mesh_queries_within_the_device() { /// (`InvalidDescriptor(MeshPipeline)`, measured on an M3 Max, `mesh_pipeline_limits.m`), on every /// committed profile, and the descriptors beside each are made: a required size with an axis of /// 0, of more than 1024 threads or more than its stage's maximum, or of an object stage without an -/// object function; a maximum past 1024; a mesh stage's required size of other threads than its -/// maximum (an object stage's of fewer is made); a function's maximum other than the +/// object function; a maximum past 1024; a required size of other threads than its stage's +/// maximum, in either stage (Metal's first compile); a function's maximum other than the /// descriptor's; a payload past 16384 bytes. An amplification count of 0 is refused as a render /// pipeline's, and one of 2 is made, as Metal makes it ([`an_amplified_mesh_pipeline_draws_one_amplification`]). #[test] @@ -2178,6 +2205,28 @@ fn a_mesh_descriptor_metal_refuses_is_refused_as_its_rule() { max: 64, }), ), + ( + with(&|d| { + d.max_total_threads_per_object_threadgroup = Some(64); + d.required_threads_per_object_threadgroup = Some([32, 1, 1]); + }), + refused(P::MaxThreadsDiffer { + stage: Stage::Object, + specified: 32, + max: 64, + }), + ), + ( + with(&|d| { + d.max_total_threads_per_object_threadgroup = Some(64); + d.required_threads_per_object_threadgroup = Some([16, 2, 1]); + }), + refused(P::MaxThreadsDiffer { + stage: Stage::Object, + specified: 32, + max: 64, + }), + ), ( with(&|d| d.payload_memory_length = Some(16385)), refused(P::PayloadOverLimit { @@ -2205,7 +2254,7 @@ fn a_mesh_descriptor_metal_refuses_is_refused_as_its_rule() { ( with(&|d| { d.max_total_threads_per_object_threadgroup = Some(64); - d.required_threads_per_object_threadgroup = Some([32, 1, 1]); + d.required_threads_per_object_threadgroup = Some([64, 1, 1]); }), None, ), diff --git a/docs/API.md b/docs/API.md index 7bf36e5bb..49e2624ab 100644 --- a/docs/API.md +++ b/docs/API.md @@ -4926,13 +4926,15 @@ each item named states the rule in full. rest), and its creation refuses what Metal refuses of them (`MeshPipelineProblem`); a draw of other threadgroup sizes within the device's limits runs, and so does an object function's mesh grid past the state's maximum (within Metal's 2^20 above). -- **A mesh state under a required threadgroup size or a function's own maximum follows one rule - every time.** Its thread maxima are the descriptor's, else the function's, else 1024; a - required mesh size of other threads than the mesh maximum is refused, and a required object - size of fewer threads than the object maximum is made. An M3 Max under macOS 27.0.1 answers - these from what its compiler compiled before: a first compile refused a required size of 32 - under a maximum of 64 in either stage and made it after a compile under 64, and a first compile - of a function of `[[max_total_threads_per_threadgroup(64)]]` answered 32 +- **A mesh state under a required threadgroup size or a function's own maximum answers as + Metal's first compile of its functions, every time.** Its thread maxima are the least of the + descriptor's, the function's, the required size's threads and 1024, and a required size of + other threads than its stage's maximum is refused in either stage. An M3 Max under macOS + 27.0.1 answers these from what its compiler compiled before, which it keeps across processes + keyed on the function's AIR: a first compile refused a required size of 32 under a maximum of + 64 in either stage, and made it once the same function had compiled under that maximum and a + required size of 64; after a compile under a required object size of 32 by 2, a plain state + of the same functions answered an object maximum of 64, where a first compile answers 1024 (`mesh_pipeline_limits.m`). **Process exit**