Translator: a replay variant under the identity domains is refused, typed

The commit before this one placed the RootTableAddress a device-replay variant
(VariantKey::replay_bindings) reads its buffer slots' addresses from, so under the identity
domains the variant no longer ends in the internal error "a strategy reads the unplaced push field
RootTableAddress". Its message said the variant then compiles there; it does not. With the field
placed, the plan reaches select::identity_admits, whose admitted push fields hold no
RootTableAddress: the identity domains read no root table, and the variant is refused,
Unsupported{IdentityDomains} (NotImplemented) naming "an encoder value the function reads as
RootTableAddress". That refusal is the true answer: only the binder (bind/replay, bind/dispatch,
bind/graphics) asks for a replay variant, and the runtime, the one consumer of the identity
domains, never sets replay_bindings (no hit in crates/metal2vulkan-runtime/src). The refusal
site and its row are the existing ones, so docs/REFUSALS.md does not change.

So the tests say the refusal:
- pipeline::compile::tests::a_replay_variant_under_the_identity_domains_is_refused_typed (was
  ..._reads_its_root_entries): icb_render_replay_template, icb_render_stride_template under the
  pulled-vertex-buffer variant and icb_replay_template under the identity domains with replay
  bindings are each refused, typed, with that feature, need and symbol.
- tests::engine_device_replay::
  a_replay_variant_under_the_identity_domains_reads_its_slots_from_their_root_entries goes, with
  its module-doc paragraph: no such module is made.
docs/API.md section 5 now says the variant is refused there, and slot_address_field's comment
names the admission that refuses it.

Verified: before this commit, on m3-max-66628 (the product suite at 84c6726dd8, a
card-free host build), both item tests failed with exactly this refusal at the three compile
calls and the engine kernel; without the placement, m3-max-66629 (probe branch
steelbrain/halfmoves-probe-nofix2) failed both with the internal error, so the new test fails
without the placement. This commit's own run is the next compile job.
This commit is contained in:
Anees Iqbal committed 2026-11-22 02:05:42 -08:00
1 parent 46a9a57522
commit 8ed044f2e8
4 files changed
+36 -168

No files matched your search

+3 -1
View File
@@ -1098,7 +1098,9 @@ impl Census {
/// The push field a device-address slot's address is read from: its own ([`address_field`]) where
/// `own`, under the identity domains outside a device-replay variant, else the root table, where a
/// replay variant's slots are its replayed command's (`replay_guest_base`).
/// replay variant's slots are its replayed command's (`replay_guest_base`). The identity domains
/// read no root table, so they refuse a replay variant once its fields are placed
/// (`select::identity_admits`).
fn slot_address_field(own: bool, slot: SlotRef) -> PushField {
match own {
true => address_field(slot),
@@ -3498,44 +3498,32 @@ fn a_replayed_draw_reads_its_buffers_through_the_slot_table() {
}
}
/// Under the identity domains a device-replay variant (`VariantKey::replay_bindings`) reads every
/// buffer slot's address from its replayed command's root entry at the stage's
/// `RootTableAddress`, and pushes neither a buffer's `SlotGuestBase` nor its `SlotBounds`: a vertex
/// function's buffer arguments (`icb_render_replay_template`), the attribute of the
/// pulled-vertex-buffer variant (`icb_render_stride_template`, its layout pulled, as a draw
/// replay pulls every layout), and a kernel's buffers (`icb_replay_template`). Each compiles with
/// its buffer slots at their device addresses, and every stage passes L3.
/// Under the identity domains a device-replay variant (`VariantKey::replay_bindings`), which reads
/// every buffer slot's address from its replayed command's root entry at the stage's
/// `RootTableAddress`, is refused, typed (`Unsupported{IdentityDomains}` naming the field the
/// identity domains do not read), never an internal error: a vertex function's buffer arguments
/// (`icb_render_replay_template`), the attribute of the pulled-vertex-buffer variant
/// (`icb_render_stride_template`, its layout pulled, as a draw replay pulls every layout), and a
/// kernel's buffers (`icb_replay_template`) alike.
#[test]
fn a_replay_variant_under_the_identity_domains_reads_its_root_entries() {
fn a_replay_variant_under_the_identity_domains_is_refused_typed() {
use crate::cache::VariantKey;
use crate::pipeline::interface::{BufferForm, PipelineInterface, SlotInterface};
use crate::pipeline::sym::PushField;
let dev =
Device::from_queries(description("moltenvk-m3"), DevicePolicy::default()).expect("device");
let reads_root_entries = |what: &str, interface: &PipelineInterface| {
let forms: Vec<BufferForm> = (interface.slots.values())
.filter_map(|s| match s {
SlotInterface::Buffer(b) => Some(b.form),
_ => None,
})
.collect();
assert!(
!forms.is_empty() && forms.iter().all(|f| *f == BufferForm::Psb),
"{what}: {forms:?}"
);
let fields: Vec<PushField> = (interface.push.iter())
.flat_map(|p| p.fields.iter().map(|f| f.field))
.collect();
assert!(
fields.contains(&PushField::RootTableAddress),
"{what}: {fields:?}"
);
assert!(
!fields
.iter()
.any(|f| matches!(f, PushField::SlotGuestBase(_) | PushField::SlotBounds(_))),
"{what}: {fields:?}"
);
let refused = |what: &str, e: Error| match e {
Error::Unsupported(u) => {
assert_eq!(
(u.feature, u.needs),
(Feature::IdentityDomains, Needs::NotImplemented),
"{what}"
);
assert_eq!(
u.symbol.map(|f| f.to_string()).as_deref(),
Some("an encoder value the function reads as RootTableAddress"),
"{what}"
);
}
other => panic!("{what}: {other}"),
};
for (stem, pulled) in [
("icb_render_replay_template", false),
@@ -3557,17 +3545,11 @@ fn a_replay_variant_under_the_identity_domains_reads_its_root_entries() {
d.vertex_descriptor = Some(vertex_descriptor(&[(0, metal::VertexFormat::UInt)]));
key.pulled_vertex_buffers.insert(0);
}
let p = dev
let e = dev
.compile_render_variant(&d, &key, &Budget::standard())
.unwrap_or_else(|e| panic!("{stem}: {e}"));
if pulled {
assert!(p.vertex_input.bindings.is_empty(), "{stem}");
assert_eq!(p.vertex_input.pulled.len(), 1, "{stem}");
}
reads_root_entries(stem, &p.interface);
for stage in &p.stages {
l3(&stage.spirv, &p.requirements, &dev);
}
.map(|_| ())
.expect_err(stem);
refused(stem, e);
}
let Some(bc) = fixture("icb_replay_template") else {
return;
@@ -3576,15 +3558,11 @@ fn a_replay_variant_under_the_identity_domains_reads_its_root_entries() {
let f = FunctionDescriptor::new(lib.function("icb_replay_template").expect("kernel"));
let mut inputs = LoweringInputs::new();
inputs.replay_bindings = true;
let compiled = dev
let e = dev
.compile_function(&f, &inputs, &Budget::standard())
.expect("the kernel's replay variant");
let d = ComputePipelineDescriptor::new(StageSource::Compiled(compiled));
let p = dev
.compile_compute_pipeline(&d, &Budget::standard())
.expect("its pipeline");
reads_root_entries("icb_replay_template", &p.interface);
l3(&p.stage.spirv, &p.requirements, &dev);
.map(|_| ())
.expect_err("icb_replay_template");
refused("icb_replay_template", e);
}
/// A render pipeline made for indirect command buffers links its vertex input as its vertex stage
@@ -15,9 +15,6 @@
//! (`VariantKey::folded_groups`), which states its key; a direct or indirect dispatch of its plan
//! is refused.
//!
//! Under the identity domains a replay variant reads each buffer slot at the address its root
//! entry names, from a root table the test writes.
//!
//! `llvm-as` assembles the fixture; without it the tests skip visibly.
use std::collections::BTreeMap;
@@ -1164,111 +1161,3 @@ fn a_folded_variant_states_its_key_and_runs_only_indirect_threadgroups() {
}
assert!(ran > 0, "no profile with device addresses");
}
/// A replay variant under the identity domains reads each slot at its replayed command's address:
/// a kernel adding 1 to each word of `src` into `out`, compiled with `replay_bindings` on every
/// committed profile `Device::from_queries` derives under the identity domains, pushes
/// `RootTableAddress` alone. On the CPU interpreter, with a root table whose `src` entry binds its
/// buffer 16 bytes past its start and whose `out` entry binds its own at 0, each above 4 GiB, every
/// thread reads its word at the address `src`'s entry names (`guest` plus `bind_offset`) and stores
/// it plus 1 at the address `out`'s names. Nothing else is written.
#[test]
fn a_replay_variant_under_the_identity_domains_reads_its_slots_from_their_root_entries() {
const THREADS: u32 = 8;
const TABLE: u64 = 0x5_0000_0000;
const SRC: u64 = 0x1_0000_0000;
const OUT: u64 = 0x2_0000_1000;
const BIND: u64 = 16;
let text = r#"define void @replayed(ptr addrspace(1) %src, ptr addrspace(1) %out, i32 %t) {
%p = getelementptr inbounds i32, ptr addrspace(1) %src, i32 %t
%v = load i32, ptr addrspace(1) %p, align 4
%w = add i32 %v, 1
%q = getelementptr inbounds i32, ptr addrspace(1) %out, i32 %t
store i32 %w, ptr addrspace(1) %q, align 4
ret void
}
!air.kernel = !{!0}
!0 = !{ptr @replayed, !1, !2}
!1 = !{}
!2 = !{!3, !4, !5}
!3 = !{i32 0, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 1, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"src"}
!4 = !{i32 1, !"air.buffer", !"air.location_index", i32 1, i32 1, !"air.read_write", !"air.address_space", i32 1, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"out"}
!5 = !{i32 2, !"air.thread_index_in_threadgroup", !"air.arg_type_name", !"uint", !"air.arg_name", !"t"}
"#;
let Some(bc) = assemble("identity_replay", text) else {
return;
};
let src: Vec<u8> = (0..BIND as u32 / 4 + THREADS)
.flat_map(|i| (0x1000 * i + 7).to_le_bytes())
.collect();
// The null and sink entries, then `src` and `out`: `{host, guest, size, bind_offset}`.
let mut table = vec![0u8; 4 * 32];
for (root, (guest, size, bind)) in [(2usize, (SRC, src.len() as u64, BIND)), (3, (OUT, 64, 0))]
{
for (field, v) in [guest, guest, size, bind].into_iter().enumerate() {
let at = 32 * root + 8 * field;
table[at..at + 8].copy_from_slice(&v.to_le_bytes());
}
}
let want: Vec<u32> = (0..THREADS)
.map(|t| 0x1000 * (BIND as u32 / 4 + t) + 8)
.collect();
let mut ran = 0;
for (stem, p) in super::engine_word_phases::identity_profiles() {
let (plan, m) = typed_module_with(&bc, "replayed", &p, &replay_inputs())
.unwrap_or_else(|e| panic!("{stem}: {e}"));
let mut push = vec![0u8; plan.push.push_range.map_or(0, |(_, end)| end as usize)];
for f in &plan.push.fields {
match (f.field, f.loc) {
(
PushField::RootTableAddress,
crate::pipeline::interface::PushLoc::Push { offset },
) => {
let o = offset as usize;
push[o..o + 8].copy_from_slice(&TABLE.to_le_bytes());
}
other => panic!("{stem}: unexpected push field {other:?}"),
}
}
let addressed = |address: u64, bytes: Vec<u8>| Buffer {
slot: None,
address: Some(address),
bytes,
};
let res = Resources {
buffers: vec![
addressed(TABLE, table.clone()),
addressed(SRC, src.clone()),
addressed(OUT, vec![0; 64]),
],
push,
spec: BTreeMap::from([
(
SpecKey::LocalSize(crate::pipeline::sym::Axis::X),
u64::from(THREADS),
),
(SpecKey::LocalSize(crate::pipeline::sym::Axis::Y), 1),
(SpecKey::LocalSize(crate::pipeline::sym::Axis::Z), 1),
(SpecKey::FlatLocalSize, u64::from(THREADS)),
]),
};
let cfg = Config {
workgroups: [1, 1, 1],
..Config::default()
};
let o = run(&m, &cfg, res).unwrap_or_else(|e| panic!("{stem}: run: {e:?}"));
let out: Vec<u32> = o.buffers[2]
.as_chunks::<4>()
.0
.iter()
.map(|w| u32::from_le_bytes(*w))
.collect();
assert_eq!(out[..THREADS as usize], want[..], "{stem}");
assert!(out[THREADS as usize..].iter().all(|w| *w == 0), "{stem}");
assert_eq!(o.buffers[0], table, "{stem}: the root table");
assert_eq!(o.buffers[1], src, "{stem}: src");
ran += 1;
}
assert!(ran > 0, "no profile under the identity domains");
}
+3 -4
View File
@@ -1090,10 +1090,9 @@ for dependency in &pipeline.dependencies {
program stored) and a pointer made from an integer are the device address the word holds,
unbiased and used directly, unchecked: there is no root table, no `PushField::RootTableAddress`
and no search. A texture's or sampler's `SlotGuestBase` is its `gpuResourceID`, unbiased. A
device-replay variant (`VariantKey::replay_bindings`, section 6) pushes no buffer slot's
`SlotGuestBase`: it reads each slot's address, unbiased, from its replayed command's root entry
(`guest` plus `bind_offset`) in the slot table at its `PushField::RootTableAddress`, and checks
no access against `PushField::SlotBounds`.
device-replay variant (`VariantKey::replay_bindings`, section 6) reads each buffer slot's
address from its replayed command's root entry, at `PushField::RootTableAddress`, which the
identity domains do not read: it is refused, `Unsupported{IdentityDomains}` naming that field.
- Under the identity domains, a buffer slot that an access may reach at a
byte offset that is not a translation-time constant (an index the memory plan does not prove
one value, a looping `memcpy` or `memset`, a pulled fetch) also reads