Translator: a mesh stage's stated maximum is its required size's threads first, as Metal answers it

What: stated_threads takes the descriptor's required threadgroup size for the stage first: its
threads, then the descriptor's maximum, then the function's attribute, then 1024. mesh_fields
keys both required sizes, since the stated maxima now depend on them. The doc comments say where
each part of the rule was measured.

Why: the conformance probe mesh_pipeline_limits.m, measured on an M3 Max under macOS 27.0.1 with
each case a first compile, records the rule:
- `plain`, with nothing stated, answers 1024 for both stages. That is the source of "else 1024".
- A required size answers its threads, even below a function's own maximum:
  required-object-32x2 answers 64, required-mesh-16x2 answers 32, and
  required-object-32-attribute-64 answers 32.
- A maximum or an attribute answers itself.
The parent commit left the required size out. The descriptor's doc said no limit depended on it,
which those rows contradict.

Tests: a_mesh_pipeline_states_its_thread_maxima_by_metal_s_rule adds three rows:
- (32,2,1) required for the object stage gives (64, 1024);
- (16,2,1) required for the mesh stage gives (1024, 32);
- mesh_outputs with (32,1,1) required for the object stage, whose function states 64, gives
  (32, 32).
The ARTIFACT_FORMAT_VERSION bump of the parent covers this, and every mesh pipeline's key moves.
api_signatures.tsv is re-blessed and unchanged.
This commit is contained in:
Anees Iqbal committed 2026-12-03 17:05:43 -08:00
1 parent ed873cf04b
commit 7fa5ab461e
5 files changed
+94 -36

No files matched your search

+24 -12
View File
@@ -590,9 +590,12 @@ impl Device {
let dependencies = dependencies(&artifacts, self);
let (mut graphics, requirements) =
graphics_requirements(requirements, &linked, &artifacts, p)?;
graphics.max_total_threads_per_object_threadgroup = (object.as_ref())
.map(|o| stated_threads(d.max_total_threads_per_object_threadgroup, o));
graphics.max_total_threads_per_object_threadgroup = object.as_ref().map(|o| {
let required = d.required_threads_per_object_threadgroup;
stated_threads(required, d.max_total_threads_per_object_threadgroup, o)
});
graphics.max_total_threads_per_mesh_threadgroup = Some(stated_threads(
d.required_threads_per_mesh_threadgroup,
d.max_total_threads_per_mesh_threadgroup,
&mesh,
));
@@ -1381,13 +1384,19 @@ fn check_function_maxima(
Ok(())
}
/// A mesh render pipeline stage's thread maximum by Metal's rule, before any device limit: the
/// descriptor's `max` where it states one, else function `f`'s
/// `[[max_total_threads_per_threadgroup(n)]]`, else [`METAL_MAX_THREADS`]
/// (`GraphicsState::max_total_threads_per_object_threadgroup`). Where both are stated they are
/// equal ([`check_function_maxima`]).
fn stated_threads(max: Option<u32>, f: &CompiledFunction) -> u32 {
(max.filter(|&max| max > 0))
/// A mesh render pipeline stage's thread maximum by Metal's rule, before any device limit
/// (`GraphicsState::max_total_threads_per_object_threadgroup`): the threads of the descriptor's
/// `required` size where it states one, else its `max` where it states one, else function `f`'s
/// `[[max_total_threads_per_threadgroup(n)]]`, else [`METAL_MAX_THREADS`]. Measured on an M3 Max
/// under macOS 27.0.1, each a first compile (the conformance probe `mesh_pipeline_limits.m`):
/// `plain`, which states none, answers 1024 for both stages; a required size answers its threads,
/// below a function's maximum too (`required-object-32-attribute-64` answers 32); a maximum or an
/// attribute answers itself. Where a maximum is stated beside another it agrees with it or Metal
/// refuses the descriptor ([`check_mesh_fields`], [`check_function_maxima`]). A required size is
/// within [`METAL_MAX_THREADS`] threads, so its product is a `u32`.
fn stated_threads(required: Option<[u32; 3]>, max: Option<u32>, f: &CompiledFunction) -> u32 {
(required_size(required).map(|axes| axes.iter().product()))
.or(max.filter(|&max| max > 0))
.or(f.artifact().kernel.max_total_threads.filter(|&n| n > 0))
.unwrap_or(METAL_MAX_THREADS)
}
@@ -1672,14 +1681,17 @@ fn primitive_varyings_written(a: &FunctionArtifact) -> std::collections::BTreeSe
}
/// The mesh descriptor fields the artifact's key holds: its fixed-function state, as a render
/// pipeline's ([`render_fields`]), and its thread and grid maxima.
/// pipeline's ([`render_fields`]), its thread and grid maxima, and its required threadgroup
/// sizes, whose threads its stated maxima are (`stated_threads`).
fn mesh_fields(d: &MeshPipelineDescriptor) -> String {
format!(
"{:?} {:?} {:?} {:?}",
"{:?} {:?} {:?} {:?} {:?} {:?}",
RenderLinkInputs::from(d),
d.max_total_threads_per_object_threadgroup,
d.max_total_threads_per_mesh_threadgroup,
d.max_total_threadgroups_per_mesh_grid
d.max_total_threadgroups_per_mesh_grid,
required_size(d.required_threads_per_object_threadgroup),
required_size(d.required_threads_per_mesh_threadgroup),
)
}
@@ -782,9 +782,10 @@ pub struct MeshPipelineDescriptor {
/// `requiredThreadsPerObjectThreadgroup`: `None` for Metal's zero size, no requirement.
/// Refused as Metal's descriptor validation ends the process at it
/// ([`MeshPipelineProblem`](crate::error::MeshPipelineProblem)): with an axis of 0, of more
/// than 1024 threads or more than the stage's maximum, or without an object function. No
/// compiled module and no thread limit the pipeline answers depends on it, and a draw is not
/// held to it.
/// than 1024 threads or more than the stage's maximum, or without an object function. Its
/// threads are the stage's stated maximum, as Metal answers them
/// (`GraphicsState::max_total_threads_per_object_threadgroup`); no compiled module depends on
/// it, and a draw is not held to it.
pub required_threads_per_object_threadgroup: Option<[u32; 3]>,
/// `requiredThreadsPerMeshThreadgroup`: as
/// [`required_threads_per_object_threadgroup`](Self::required_threads_per_object_threadgroup),
+4 -2
View File
@@ -183,8 +183,10 @@ pub struct GraphicsState {
#[cfg_attr(feature = "serde", serde(default))]
pub logic_op: Option<vk::LogicOp>,
/// A mesh render pipeline's `maxTotalThreadsPerObjectThreadgroup` by Metal's rule, before
/// any device limit: the descriptor's maximum where it states one, else the object
/// function's `[[max_total_threads_per_threadgroup(n)]]`, else Metal's 1024. `None` for a
/// any device limit: the threads of the descriptor's required object threadgroup size where
/// it states one, else its maximum where it states one, else the object function's
/// `[[max_total_threads_per_threadgroup(n)]]`, else 1024, each as an M3 Max answers a first
/// compile under macOS 27.0.1 (the conformance probe `mesh_pipeline_limits.m`). `None` for a
/// pipeline without an object function. A consumer answers the least of it and the task
/// stage's `maxTaskWorkGroupInvocations` and `maxTaskWorkGroupSize[0]`, and specializes the
/// object stage's workgroup to that many threads (`SpecKey::ObjectLocalSize`).
+58 -17
View File
@@ -407,11 +407,13 @@ fn a_mesh_pipeline_without_an_object_function_draws_through_a_launcher() {
/// A mesh render pipeline states each stage's thread maximum by Metal's rule, before any device
/// limit (`GraphicsState::max_total_threads_per_object_threadgroup` and
/// `max_total_threads_per_mesh_threadgroup`): the descriptor's maximum where it states one, else
/// the function's `[[max_total_threads_per_threadgroup(n)]]`, else 1024, and none for the object
/// stage of a pipeline without an object function. On the first committed profile whose device
/// lists the mesh stages, of `engine/mesh_pipeline_limits` (no function maximum) and
/// `engine/mesh_outputs` (an object function's 64, a mesh function's 32), rasterization disabled.
/// `max_total_threads_per_mesh_threadgroup`): the threads of the descriptor's required size where
/// it states one, else its maximum where it states one, else the function's
/// `[[max_total_threads_per_threadgroup(n)]]`, else 1024, and none for the object stage of a
/// pipeline without an object function, each as the conformance probe `mesh_pipeline_limits.m`
/// measured on an M3 Max. On the first committed profile whose device lists the mesh stages, of
/// `engine/mesh_pipeline_limits` (no function maximum) and `engine/mesh_outputs` (an object
/// function's 64, a mesh function's 32), rasterization disabled.
#[test]
fn a_mesh_pipeline_states_its_thread_maxima_by_metal_s_rule() {
use crate::budget::Budget;
@@ -435,20 +437,27 @@ fn a_mesh_pipeline_states_its_thread_maxima_by_metal_s_rule() {
library.function(name).expect("function"),
))
};
// The library, the object and the mesh function, the descriptor's two maxima and the stated
// ones.
let (object, mesh) = (
Some("mesh_pipeline_limits_object"),
"mesh_pipeline_limits_mesh",
);
let (outputs_object, outputs_mesh) = (Some("mesh_outputs_object"), "mesh_outputs_triangles");
// The library, the object and the mesh function, the descriptor's two required sizes and two
// maxima, and the stated maxima.
let rows = [
(
&limits,
Some("mesh_pipeline_limits_object"),
"mesh_pipeline_limits_mesh",
object,
mesh,
(None, None),
(None, None),
(Some(1024), Some(1024)),
),
(
&limits,
Some("mesh_pipeline_limits_object"),
"mesh_pipeline_limits_mesh",
object,
mesh,
(None, None),
(Some(64), Some(32)),
(Some(64), Some(32)),
),
@@ -457,22 +466,54 @@ fn a_mesh_pipeline_states_its_thread_maxima_by_metal_s_rule() {
None,
"mesh_pipeline_limits_mesh_alone",
(None, None),
(None, None),
(None, Some(1024)),
),
(
&limits,
object,
mesh,
(Some([32, 2, 1]), None),
(None, None),
(Some(64), Some(1024)),
),
(
&limits,
object,
mesh,
(None, Some([16, 2, 1])),
(None, None),
(Some(1024), Some(32)),
),
(
&outputs,
Some("mesh_outputs_object"),
"mesh_outputs_triangles",
outputs_object,
outputs_mesh,
(None, None),
(None, None),
(Some(64), Some(32)),
),
(
&outputs,
outputs_object,
outputs_mesh,
(Some([32, 1, 1]), None),
(None, None),
(Some(32), Some(32)),
),
];
for (library, object, mesh, (max_object, max_mesh), stated) in rows {
for (library, object, mesh, required, maxima, stated) in rows {
let mut d = MeshPipelineDescriptor::new(stage(library, mesh));
d.object = object.map(|o| stage(library, o));
d.rasterization_enabled = false;
d.max_total_threads_per_object_threadgroup = max_object;
d.max_total_threads_per_mesh_threadgroup = max_mesh;
(
d.required_threads_per_object_threadgroup,
d.required_threads_per_mesh_threadgroup,
) = required;
(
d.max_total_threads_per_object_threadgroup,
d.max_total_threads_per_mesh_threadgroup,
) = maxima;
let p = (dev.compile_mesh_pipeline(&d, &Budget::standard()))
.unwrap_or_else(|e| panic!("{stem} {object:?} {mesh}: {e}"));
let g = &p.graphics;
@@ -482,7 +523,7 @@ fn a_mesh_pipeline_states_its_thread_maxima_by_metal_s_rule() {
g.max_total_threads_per_mesh_threadgroup
),
stated,
"{stem} {object:?} {mesh} stated {max_object:?} {max_mesh:?}"
"{stem} {object:?} {mesh} required {required:?} maxima {maxima:?}"
);
}
}
+4 -2
View File
@@ -1190,8 +1190,10 @@ Where the mesh function reads a payload, the launcher emits an arena of its size
The pipeline states each stage's thread maximum by Metal's rule, before any device limit
(`GraphicsState::max_total_threads_per_object_threadgroup` and
`max_total_threads_per_mesh_threadgroup`): the descriptor's maximum where it states one, else the
function's `[[max_total_threads_per_threadgroup(n)]]`, else 1024; the object one is `None` without
`max_total_threads_per_mesh_threadgroup`): the threads of the descriptor's required size where it
states one, else its maximum where it states one, else the function's
`[[max_total_threads_per_threadgroup(n)]]`, else 1024, each as an M3 Max answers a first compile
(macOS 27.0.1, the conformance probe `mesh_pipeline_limits.m`); the object one is `None` without
an object function. A consumer answers the least of it and the stage's device limits
(`maxTaskWorkGroupInvocations` and `maxTaskWorkGroupSize[0]`, or the mesh stage's), and
specializes the stage's workgroup to that many threads in one row (`SpecKey::ObjectLocalSize` and