diff --git a/crates/metal2vulkan/src/lower/access/mod.rs b/crates/metal2vulkan/src/lower/access/mod.rs index ea2b1aae3..6943e79ea 100644 --- a/crates/metal2vulkan/src/lower/access/mod.rs +++ b/crates/metal2vulkan/src/lower/access/mod.rs @@ -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), diff --git a/crates/metal2vulkan/src/pipeline/compile/tests.rs b/crates/metal2vulkan/src/pipeline/compile/tests.rs index da18d39e1..d0d5e64fb 100644 --- a/crates/metal2vulkan/src/pipeline/compile/tests.rs +++ b/crates/metal2vulkan/src/pipeline/compile/tests.rs @@ -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 = (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 = (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 diff --git a/crates/metal2vulkan/src/tests/engine_device_replay.rs b/crates/metal2vulkan/src/tests/engine_device_replay.rs index 542d03b2e..5f2add26d 100644 --- a/crates/metal2vulkan/src/tests/engine_device_replay.rs +++ b/crates/metal2vulkan/src/tests/engine_device_replay.rs @@ -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 = (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 = (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| 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 = 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"); -} diff --git a/docs/API.md b/docs/API.md index c4289b8e9..353a0341f 100644 --- a/docs/API.md +++ b/docs/API.md @@ -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