Census: a mesh function that sets no vertex or primitive and writes nothing needs no fragment stage

The census held five mesh rows unresolved under mesh_companion, each missing a fragment stage:
icb_object_threadgroup_mesh, mesh_partial_barrier_mesh (empty bodies), mesh_object_grid_mesh,
mesh_pipeline_limits_mesh_alone (a constant zero primitive count) and mesh_pipeline_limits_mesh
(a count read from its payload). None sets a vertex or primitive and none writes device memory;
they exist so their modules' object functions can be drawn. The row rule fell through to "needs
a fragment stage" for any mesh function writing neither memory nor its position, although a
fragment stage observes nothing such a function defines: it emits no primitive, or primitives
over vertices it never wrote.

Such a function has no effect a stage observes, so it draws with rasterization off and an empty
observation (OutputSelection::None), as a kernel that writes nothing does: both executors already
draw a mesh pipeline with rasterization off into a one-pixel sink, and the checker accepts an
empty observation where nothing is writable. A mesh function that sets vertices or primitives
without their position, and writes nothing, still needs a fragment stage nothing supplies
(sets_mesh_outputs decides it from the entry's `air.set_*_mesh` calls through the AIR front end's
intrinsic table, never a name).

The five rows' first unresolved commits are their fixtures' add commits (97d01927cb, 1d494932f7,
0f289cdac4); the rule predates them (0175289314).

Tests: the mesh contract's row test holds the three fixtures' effect-free mesh functions to no
missing stage and no call that sets an output; a triage test classifies all five public rows to
no requirement and no missing stage. Both fail without the change. The census test's synthetic
mesh row now sets its primitive's ID without a position, so it stays the gap it demonstrates.
The validation README says what an effect-free mesh row draws with. The classifier version is
structural-triage-v82.

(cherry picked from commit 68d4bbb9b67a72bfcce4d0c6069f1579da43ef04)
This commit is contained in:
Anees Iqbal committed 2026-11-08 20:03:19 -08:00
1 parent c446716580
commit ae42a1acfc
4 files changed
+104 -16

No files matched your search

+3 -1
View File
@@ -133,7 +133,9 @@ payload is whole words, at least as many bytes as the mesh function reads, and a
16 KB. Without rasterization the case selects a buffer its entry writes. The payload length is
the pipeline's default. A stage the case leaves absent and nothing generates is a requirement
(`mesh_companion`). An object row whose payload the launch observer reads, and a mesh row whose
payload a generated object function writes, need none. The Metal oracle draws a case through
payload a generated object function writes, need none. Nor does a mesh row whose function sets no
vertex or primitive and writes no device memory: it has no effect a stage observes, so it draws
without rasterization and its case observes the empty output (`"output": {"kind": "none"}`). The Metal oracle draws a case through
`MTLMeshRenderPipelineDescriptor` and the case's own stage's setters. The engine's candidate
draws it through the runtime's mesh render pipeline state and `draw_mesh_threadgroups` or
`draw_mesh_threads`. On a device without `VK_EXT_mesh_shader` the runtime emulates the draw and
+6 -4
View File
@@ -519,8 +519,10 @@ mod tests {
fn mesh_module(with_object: bool) -> String {
let mesh = "define void @msh(ptr addrspace(7) %m) {\n \
call void @air.set_primitive_count_mesh(ptr addrspace(7) %m, i32 1)\n \
call void @air.set_primitive_id_mesh(ptr addrspace(7) %m, i32 0, i32 0)\n \
ret void\n}\n\
declare void @air.set_primitive_count_mesh(ptr addrspace(7), i32)\n";
declare void @air.set_primitive_count_mesh(ptr addrspace(7), i32)\n\
declare void @air.set_primitive_id_mesh(ptr addrspace(7), i32, i32)\n";
let mesh_md = "!5 = !{ptr @msh, !1, !6}\n!6 = !{!7}\n\
!7 = !{i32 0, !\"air.mesh\", !8, !\"air.arg_type_name\", \
!\"mesh<V, void, 3, 1, triangle>\", !\"air.arg_name\", !\"m\"}\n\
@@ -551,9 +553,9 @@ mod tests {
/// (`case::Stage`): a public module declaring one of each is two entry rows of those stages,
/// and a private module declaring a mesh function is its shard's row. A cold census reflects
/// and classifies all three: the object function draws with the generated launch observer of
/// its payload, and each mesh function, which writes no device memory and states no position,
/// carries `mesh_companion` (a fragment stage no executor generates), so it is classified and
/// unresolved, never skipped; a warm pass selects and reads nothing.
/// its payload, and each mesh function, which sets its primitive's ID but no position and
/// writes no device memory, carries `mesh_companion` (a fragment stage no executor generates),
/// so it is classified and unresolved, never skipped; a warm pass selects and reads nothing.
#[test]
fn object_and_mesh_rows_are_indexed_and_classified() {
let scratch = ScratchDir::new("census-mesh-rows").unwrap();
@@ -21,7 +21,10 @@
//! a rasterizing draw with neither ([`MeshDraw`]), so a case never reaches Metal's abort. A row,
//! which names none, needs each that its structure does and nothing generates: a mesh function
//! whose device writes are observable draws with rasterization off, and one that writes its
//! position draws with the generated observer of it, so neither needs a fragment stage; an
//! position draws with the generated observer of it, so neither needs a fragment stage; nor does
//! one that sets none of its vertices or primitives ([`sets_mesh_outputs`]) and writes no
//! observable memory, which has no effect a stage observes: it draws with rasterization off and
//! an empty observation (`OutputSelection::None`), as a kernel that writes nothing does. An
//! object function whose payload the launch observer reads ([`launch_payload_words`]) draws with
//! the generated mesh stage, and a mesh function whose payload a generated object function
//! writes ([`object_payload_bytes`]) with the generated object stage.
@@ -165,15 +168,21 @@ pub fn missing_stages(
}
// A row is observed through its device writes where it has any, with rasterization
// off, and otherwise through its rasterized output: the generated observer fragment
// reads the position it writes (`air.set_position_mesh`). A case's draw names the
// fragment function it rasterizes with, or the observation its observer reads.
// reads the position it writes (`air.set_position_mesh`). One that sets no vertex or
// primitive and writes nothing has no effect: rasterization off observes all of it,
// the empty output. A case's draw names the fragment function it rasterizes with, or
// the observation its observer reads.
let sets_position =
own.writes_position() && source_ll.contains("@air.set_position_mesh(");
if draw.is_none() && !writes_observable_memory(source_ll) && !sets_position {
if draw.is_none()
&& !writes_observable_memory(source_ll)
&& !sets_position
&& sets_mesh_outputs(source_ll)
{
missing.push((
Stage::Fragment,
"a mesh function that writes neither observable memory nor its position has \
no output a fragment stage observes",
"a mesh function that sets vertices or primitives without their position, \
and writes no observable memory, has no output a fragment stage observes",
));
}
}
@@ -185,6 +194,21 @@ pub fn missing_stages(
missing
}
/// Whether the entry whose text is `source_ll` sets any of its mesh's vertices or primitives: it
/// calls a mesh output setter (`air.set_*_mesh`) other than its primitive count's. One that sets
/// only a count draws primitives over no vertex it wrote, so rasterizing them shows nothing it
/// defined.
pub fn sets_mesh_outputs(source_ll: &str) -> bool {
use metal2vulkan_air::intrinsics::{AirIntrinsic, Mesh};
super::air_call_counts(source_ll).keys().any(|name| {
matches!(
AirIntrinsic::parse(name),
Some(AirIntrinsic::Mesh(op))
if !matches!(op, Mesh::PrimitiveCount | Mesh::ThreadgroupsPerGrid)
)
})
}
/// The mesh requirements of a row or case (`draw` `None` for a row) whose entry's reflection is
/// `reflection`: [`ToolingRequirement::MeshCompanion`] where [`missing_stages`] names a stage.
/// Empty for any other stage. An object function's threadgroup memory needs nothing: both
@@ -318,20 +342,48 @@ mod tests {
/// writing it unless a generated object function writes it. A mesh function needs no fragment
/// stage where
/// one is generated or none is needed: one that writes its position draws with the generated
/// observer of it, and one that writes device memory with rasterization off; one that writes
/// neither needs a fragment stage nothing can observe it through. Each such row carries
/// `mesh_companion`, and a row that needs no stage carries no mesh requirement: both executors
/// draw it.
/// observer of it, one that writes device memory with rasterization off, and one that sets no
/// vertex or primitive and writes nothing (an empty body, or a primitive count alone, constant
/// or read from its payload) with rasterization off and an empty observation; one that sets
/// vertices without their position and writes nothing needs a fragment stage nothing can
/// observe it through. Each such row carries `mesh_companion`, and a row that needs no stage
/// carries no mesh requirement: both executors draw it.
#[test]
fn a_row_needs_the_stages_its_structure_does() {
let draws = fixture("mesh_draws");
let barrier = fixture("mesh_barrier");
let grid = fixture("mesh_object_grid");
let threadgroup = fixture("icb_object_threadgroup");
let limits = fixture("mesh_pipeline_limits");
let rows = [
(&draws, Stage::Object, "mesh_draws_object", &[][..]),
(&draws, Stage::Mesh, "mesh_draws_grid", &[][..]),
(&draws, Stage::Mesh, "mesh_draws_mesh", &[][..]),
(&barrier, Stage::Mesh, "mesh_barrier_writer", &[][..]),
(&grid, Stage::Mesh, "mesh_object_grid_mesh", &[][..]),
(
&threadgroup,
Stage::Mesh,
"icb_object_threadgroup_mesh",
&[][..],
),
(&limits, Stage::Mesh, "mesh_pipeline_limits_mesh", &[][..]),
(
&limits,
Stage::Mesh,
"mesh_pipeline_limits_mesh_alone",
&[][..],
),
];
for (module, entry) in [
(&grid, "mesh_object_grid_mesh"),
(&threadgroup, "icb_object_threadgroup_mesh"),
(&limits, "mesh_pipeline_limits_mesh"),
] {
let (text, _) = reflected(module, Stage::Mesh, entry);
assert!(!sets_mesh_outputs(&text), "{entry}");
assert!(!writes_observable_memory(&text), "{entry}");
}
for (module, stage, entry, stages) in rows {
let (text, reflection) = reflected(module, stage, entry);
let missing = missing_stages(&text, &reflection, None)
+33 -1
View File
@@ -14,7 +14,7 @@ use std::path::Path;
/// bumps it says what changed; this comment keeps no history.
macro_rules! analyzer_version {
() => {
"structural-triage-v81"
"structural-triage-v82"
};
}
@@ -2317,6 +2317,38 @@ define void @{name}(ptr addrspace(2) %ab, ptr addrspace(1) %out) {{
}
}
/// A mesh function that sets no vertex or primitive and writes nothing (an empty body, or a
/// primitive count alone, constant or read from its payload) has no effect a stage observes:
/// its row draws with rasterization off and an empty observation, needs no stage, and carries
/// no requirement.
#[test]
fn an_effect_free_mesh_row_needs_no_stage() {
for (module, entry) in [
(
"engine/icb_object_threadgroup.ll",
"icb_object_threadgroup_mesh",
),
("engine/mesh_object_grid.ll", "mesh_object_grid_mesh"),
(
"engine/mesh_partial_barrier.ll",
"mesh_partial_barrier_mesh",
),
(
"engine/mesh_pipeline_limits.ll",
"mesh_pipeline_limits_mesh",
),
(
"engine/mesh_pipeline_limits.ll",
"mesh_pipeline_limits_mesh_alone",
),
] {
let classified = classify(&entry_of(module, entry)).unwrap();
assert_eq!(classified.tooling_requirements, [], "{entry}");
let draw = classified.mesh_draw.expect("a mesh draw");
assert!(draw.missing.is_empty(), "{entry}: {:?}", draw.missing);
}
}
/// A tile function (a kernel's implicit imageblock over render targets) carries
/// no requirement and stays described by its descriptive fact, which a kernel without the
/// family does not have.