diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 0d75a1746..5731b53fa 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -62,7 +62,7 @@ mod tests; /// unchanged version, and its bless records the version. Independent of the crate's version and of /// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no /// history. -pub const SEMANTICS_VERSION: u32 = 2183; +pub const SEMANTICS_VERSION: u32 = 2184; /// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the /// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another diff --git a/crates/metal2vulkan/src/lower/select.rs b/crates/metal2vulkan/src/lower/select.rs index 0d4e8f6c3..7b3402d89 100644 --- a/crates/metal2vulkan/src/lower/select.rs +++ b/crates/metal2vulkan/src/lower/select.rs @@ -1922,7 +1922,9 @@ fn identity_unsourced(f: &RuntimeFact) -> bool { /// function, that reaches memory only through its buffer slots' device addresses, its textures' /// and runtime samplers' resource IDs and its constexpr samplers' pushed indices, with no /// descriptor and no state of a bound texture or sampler but its resource ID's -/// (`SlotPlan::identity_lowered`, [`identity_unsourced`]). Its fields past the push window are a +/// (`SlotPlan::identity_lowered`, [`identity_unsourced`]). The values it reads of the encoder are +/// pushed: the dispatch's region, a storage texture's integer channel widths and the compute +/// encoder's stage-in region (`PushField::StageInRegion`). Its fields past the push window are a /// parameter block, whose address the window holds. fn identity_admits(plan: &Plan, p: &DeviceProfile) -> Result<(), Error> { let fields = plan.push.fields.iter().all(|f| match (f.field, f.loc) { @@ -1933,6 +1935,7 @@ fn identity_admits(plan: &Plan, p: &DeviceProfile) -> Result<(), Error> { | PushField::DispatchRegion | PushField::TextureIntegerChannels(_) | PushField::ConstexprSampler(_) + | PushField::StageInRegion ), }); let addressed = plan diff --git a/crates/metal2vulkan/src/pipeline/compile/tests.rs b/crates/metal2vulkan/src/pipeline/compile/tests.rs index f2e1d6b83..df7d53332 100644 --- a/crates/metal2vulkan/src/pipeline/compile/tests.rs +++ b/crates/metal2vulkan/src/pipeline/compile/tests.rs @@ -1274,7 +1274,7 @@ fn the_old_render_descriptor_key_keeps_its_value() { let key = device("moltenvk-m3").render_descriptor_key(&d); let hex: String = key.digest().iter().map(|b| format!("{b:02x}")).collect(); assert_eq!( - hex, "93a63310c210033309a70688004c8bd8e6cecdb22fb2c5e106662635e64e0833", + hex, "338f17f920e67f971fe4d88574a615aa8da7e2bc96ae3418a8faa266da758e40", "the old runtime's key of the descriptor" ); } diff --git a/crates/metal2vulkan/src/tests/engine_identity.rs b/crates/metal2vulkan/src/tests/engine_identity.rs index e70eb5d92..bd14152ce 100644 --- a/crates/metal2vulkan/src/tests/engine_identity.rs +++ b/crates/metal2vulkan/src/tests/engine_identity.rs @@ -61,6 +61,10 @@ //! argument buffer (`engine/icb_replay_encode`) is refused as //! `Unsupported{GpuEncodedIndirectCommands}`, not implemented: the feature it uses, not the //! domains' generic refusal. +//! - A kernel that reads the compute encoder's stage-in region (`engine/kernel_stage_in`'s +//! `stage_in_region_short`: `[[grid_origin]]` and `[[grid_size]]`, with no `[[stage_in]]`) +//! reads it from its pushed field (`PushField::StageInRegion`), with no descriptor; it passes +//! L3 and, on the CPU interpreter, every thread stores the region's origin and size. //! - A kernel's emulated-simdgroup variant (`engine/gsm2_simd_products`'s `simd_float_products`) //! opens every barrier of its exchanges under a branch on `1 < N`, which the default domains do //! not; on the CPU interpreter a threadgroup of one thread passes no barrier, and threadgroups of @@ -641,6 +645,77 @@ fn a_gpu_encoding_kernel_is_refused_as_gpu_encoded_commands_under_the_identity_d } } +/// A kernel that reads the stage-in region (`stage_in_region_short`: `out[t] = (origin.xy, +/// size.xy)` as `ushort`s) reads it from its pushed `StageInRegion` field, two `uvec4`s of the +/// origin and the size as the binder writes them, beside its output's address and the dispatch's +/// region, with no descriptor; every thread of the grid stores the region's origin and size. +#[test] +fn the_stage_in_region_is_read_from_its_pushed_field() { + let Some(bc) = assemble("kernel_stage_in") else { + return; + }; + const ENTRY: &str = "stage_in_region_short"; + const GROUP: u32 = 4; + const GROUPS: u32 = 2; + const ORIGIN: [u32; 3] = [3, 5, 7]; + const SIZE: [u32; 3] = [11, 13, 1]; + let threads = (GROUP * GROUPS) as usize; + let mut region_in = Vec::new(); + for v in [ORIGIN, SIZE] { + for word in v.into_iter().chain([0]) { + region_in.extend_from_slice(&word.to_le_bytes()); + } + } + let lane = |x: u32| u16::try_from(x).expect("a ushort"); + let value = [ORIGIN[0], ORIGIN[1], SIZE[0], SIZE[1]].map(lane); + let mut expected: Vec = (0..threads) + .flat_map(|_| value.iter().flat_map(|half| half.to_le_bytes())) + .collect(); + // One spare element past the grid, which the kernel must not write. + expected.extend_from_slice(&[0; 8]); + for stem in PROFILES { + let p = profile(stem, identity()).unwrap_or_else(|e| panic!("{e}")); + let (a, plan, module) = + compile_kept(&bc, ENTRY, &p).unwrap_or_else(|e| panic!("{stem}: {e}")); + assert!(a.interface.descriptors.is_empty(), "{stem}"); + link_and_validate(&a, &p).unwrap_or_else(|e| panic!("{stem}: L3: {e}")); + let mut push = vec![0u8; plan.push.push_range.map_or(0, |(_, end)| end as usize)]; + let region = region_bytes([0; 3], [GROUP * GROUPS, 1, 1], [GROUP, 1, 1]).expect("packs"); + let mut read = BTreeSet::new(); + for f in &plan.push.fields { + let PushLoc::Push { offset } = f.loc else { + panic!("{stem}: {f:?} spilled"); + }; + let o = offset as usize; + match f.field { + PushField::SlotGuestBase(s) if s == slot(0) => { + push[o..o + 8].copy_from_slice(&OUT.to_le_bytes()) + } + PushField::DispatchRegion => push[o..o + 32].copy_from_slice(®ion), + PushField::StageInRegion => push[o..o + 32].copy_from_slice(®ion_in), + _ => panic!("{stem}: unexpected push field {f:?}"), + } + read.insert(f.field); + } + assert!(read.contains(&PushField::StageInRegion), "{stem}: {read:?}"); + let res = Resources { + buffers: vec![Buffer { + slot: None, + address: Some(OUT), + bytes: vec![0u8; expected.len()], + }], + push, + spec: local_size(GROUP), + }; + let cfg = Config { + workgroups: [GROUPS, 1, 1], + ..Config::default() + }; + let got = run(&module, &cfg, res).unwrap_or_else(|e| panic!("{stem}: {e}")); + assert_eq!(got.buffers[0], expected, "{stem}: out"); + } +} + /// The `gpuResourceID` high word of a texture of pixel format `pf` with the identity swizzle, from the test vectors (`docs/RESOURCE-ID.md`), checked against /// `TextureWord::of`: the word the runtime writes. fn vector_word(pf: PixelFormat) -> u32 {