A kernel's patch control-point input stays refused: pin it and say why
What: an ABI test, a_kernel_takes_no_control_point_input, decodes one synthetic module's
air.patch_control_point_input (its declared, never-defined fetch function and two fields) on a
post-tessellation vertex function and checks that the same input on a kernel is refused,
InvalidInput(Abi(UnknownKey)) at argument 0 and that key. docs/API.md's kernel [[stage_in]]
section states the refusal, Metal's answer, and the two forms through which a kernel does read
vertices by index.
Why: Metal refuses the shape too. `metal` (32023.922) writes no control-point input for a
kernel: every MSL spelling fails to compile ("invalid type 'patch_control_point<CP>' for input
declaration in a kernel function"). A kernel assembled by hand in the post-tessellation shape
(xcrun metal-as, metallib) gives a library and a function on an M3 Max under macOS 27.0.1, whose
reflection lists both fields as control-point stage-input attributes. Every compute pipeline of
it fails, "Internal compiler error.", under Constant, ThreadPositionInGridX (rates 1 and 2, a
region origin of 2), ThreadPositionInGridY and both indexed steps. Without a descriptor Metal
asks for one, and a vertex step function in a compute descriptor stops at a framework
assertion. As a check that the module was well formed, the same body as a [[patch(quad, 4)]]
vertex function makes its render pipeline and fetches patch p's point j as element 4p + j. As a
check of the host and the descriptors, an MSL kernel [[stage_in]] of the same attributes makes
a pipeline under every one of them. So the refusal stays where it is, at the pipeline compile.
The ABI has no error kind for a role outside its stage other than UnknownKey (its documentation
covers a role the stage does not accept), so the error kind is unchanged and REFUSALS.md does
not move.
Verified: the M3 probes ran as potluck jobs m3-max-30194, 30197, 30201 and 30203. The test,
clippy, and a negative control (the role allowed on a kernel, which fails the test) ran in one
msi job, named in the report.
Checks (msi m3-max-30227 at 70b57adf99): clippy -D warnings plain and cpu_icd exit 0; 74 touched
tests pass; negative control (the refusal made to accept) fails the new test, exit 100. No
RUNTIME bump: the refusal and its error are unchanged.
This commit is contained in:
1 parent
b8b03a31cc
commit
1a6fcf6ece
2 files changed
+108
No files matched your search
@@ -4496,6 +4496,106 @@ fn control_point_fetches_are_exposed() {
|
||||
);
|
||||
}
|
||||
|
||||
/// A patch control-point input belongs to a post-tessellation vertex function alone. Metal's
|
||||
/// compiler writes `air.patch_control_point_input` for no kernel, and Metal makes no compute
|
||||
/// pipeline of a kernel that takes one: an M3 Max under macOS 27.0.1 makes the library and the
|
||||
/// function, and refuses the pipeline ("Internal compiler error.") under every compute step
|
||||
/// function. The same input, function and fields decode on a post-tessellation vertex function and
|
||||
/// are refused on a kernel, at the argument and the key.
|
||||
#[test]
|
||||
fn a_kernel_takes_no_control_point_input() {
|
||||
let decoded = |list: &'static str| {
|
||||
module_with(|b| {
|
||||
let ptr = b.ptr(AddrSpace::Thread);
|
||||
let void = b.void();
|
||||
let i32t = b.int(32);
|
||||
let f32t = b.float();
|
||||
let float2 = b.vector(f32t, 2);
|
||||
let float4 = b.vector(f32t, 4);
|
||||
// The fetch `metal` declares for a post-tessellation vertex function's control
|
||||
// points: `{ T0, .. } (i32 index, ptr input)`, one member per field, never defined.
|
||||
let point = b.struct_ty(&[float2, float4]);
|
||||
let fetch_ty = b.fn_ty(point, &[i32t, ptr]);
|
||||
let fetch = b.declare("fetch", fetch_ty);
|
||||
let f = entry_fn(b, "entry", void, &[ptr, i32t]);
|
||||
let function = node(b, &[S("air.patch_control_point_function"), F(fetch)]);
|
||||
let field = |b: &mut ModuleBuilder, location, ty, name| {
|
||||
node(
|
||||
b,
|
||||
&[
|
||||
S("air.location_index"),
|
||||
I(location),
|
||||
I(1),
|
||||
S("air.arg_type_name"),
|
||||
S(ty),
|
||||
S("air.arg_name"),
|
||||
S(name),
|
||||
],
|
||||
)
|
||||
};
|
||||
let p = field(b, 0, "float2", "p");
|
||||
let q = field(b, 1, "float4", "q");
|
||||
let input = node(
|
||||
b,
|
||||
&[
|
||||
I(0),
|
||||
S("air.patch_control_point_input"),
|
||||
N(function),
|
||||
N(p),
|
||||
N(q),
|
||||
],
|
||||
);
|
||||
// The index each stage has: a kernel's grid position, a patch's id.
|
||||
let builtin = if list == "air.kernel" {
|
||||
"air.thread_position_in_grid"
|
||||
} else {
|
||||
"air.patch_id"
|
||||
};
|
||||
let index = node(
|
||||
b,
|
||||
&[
|
||||
I(1),
|
||||
S(builtin),
|
||||
S("air.arg_type_name"),
|
||||
S("uint"),
|
||||
S("air.arg_name"),
|
||||
S("i"),
|
||||
],
|
||||
);
|
||||
let inputs = node(b, &[N(input), N(index)]);
|
||||
let outputs = node(b, &[]);
|
||||
let e = if list == "air.kernel" {
|
||||
node(b, &[F(f), N(outputs), N(inputs)])
|
||||
} else {
|
||||
let patch = node(
|
||||
b,
|
||||
&[
|
||||
S("air.patch"),
|
||||
S("quad"),
|
||||
S("air.patch_control_point"),
|
||||
I(4),
|
||||
],
|
||||
);
|
||||
node(b, &[F(f), N(outputs), N(inputs), N(patch)])
|
||||
};
|
||||
b.named_md(list, &[e]);
|
||||
})
|
||||
};
|
||||
let abi = decoded("air.vertex").expect("a post-tessellation vertex function's control points");
|
||||
assert!(matches!(
|
||||
abi.entries[0].params[0].role,
|
||||
ParamRole::PatchInput(PatchInput::ControlPoints { .. })
|
||||
));
|
||||
let Err(Error::InvalidInput(e)) = decoded("air.kernel") else {
|
||||
panic!("a kernel's control-point input must be refused");
|
||||
};
|
||||
assert_eq!(e.kind, InputErrorKind::Abi(AbiError::UnknownKey));
|
||||
let (entry, arg, key) = e.at.in_metadata().expect("an ABI-metadata location");
|
||||
assert_eq!(entry.map(ToString::to_string).as_deref(), Some("entry"));
|
||||
assert_eq!(arg, Some(0));
|
||||
assert_eq!(key, Some(Key::PatchControlPointInput.name()));
|
||||
}
|
||||
|
||||
/// A post-tessellation vertex function's `air.patch` with each count form: `[[patch(quad, 4)]]`
|
||||
/// states its count, `[[patch(quad)]]` none (the node ends at the kind), and a count key without a
|
||||
/// count is malformed.
|
||||
|
||||
@@ -862,6 +862,14 @@ let compiled = device.compile_function(&kernel, &inputs, budget)?;
|
||||
A fresh `StageInputLayoutDescriptor` steps per vertex at rate 1, as a fresh Metal layout does. A
|
||||
layout stride of `None` is `MTLBufferLayoutStrideDynamic`: the stride comes from the encoder.
|
||||
|
||||
A kernel that takes a patch control-point input (`air.patch_control_point_input`, the input of a
|
||||
post-tessellation vertex function) is refused, `InvalidInput(Abi(UnknownKey))` at that argument and
|
||||
key. Metal's compiler writes that input for no kernel, and Metal makes no compute pipeline of a
|
||||
kernel that takes one: on an M3 Max under macOS 27.0.1 it makes the library and the function, then
|
||||
fails the pipeline with "Internal compiler error." under every compute step function. A kernel reads
|
||||
vertices by index through `[[stage_in]]` under a stage-input descriptor (one element per thread), or
|
||||
through buffer arguments it reads at any index.
|
||||
|
||||
### Other compute features
|
||||
|
||||
- **Visible functions and recursion.** Linked visible functions, function tables and
|
||||
|
||||
Reference in new issue
Block a user