translator: the identity domains read the compute encoder's stage-in region from its pushed field

A kernel that reads [[grid_origin]] or [[grid_size]] reads the stage-in region, which the encoder writes into PushField::StageInRegion. The identity domains' admission check took only slot addresses, the dispatch region, integer channel widths and constexpr sampler indices, so such a kernel was refused as Unsupported{IdentityDomains, NotImplemented}. A recorded stream's kernel is refused this way at its compute state, and the old runtime plays that state. The field is a value the encoder pushes, with no descriptor and no address, so the check now takes it. A [[stage_in]] fetch stays out: its stride field and its reach specialization are still not admitted.

SEMANTICS_VERSION 2184: a refusal under the identity domains becomes a module. The same bump covers the earlier change of class of the GPU-encoding kernel's refusal (IdentityDomains to GpuEncodedIndirectCommands), which did not bump it. The old runtime's key of a render descriptor carries the version, so its pinned value in the_old_render_descriptor_key_keeps_its_value moves with the bump (93a63310 to 338f17f9).

Test: engine_identity's the_stage_in_region_is_read_from_its_pushed_field compiles engine/kernel_stage_in's stage_in_region_short under the identity domains on lavapipe and moltenvk-m3. It checks that the kernel takes no descriptor, that StageInRegion is among its push fields and that it passes L3. On the CPU interpreter every thread stores the pushed origin and size, and nothing is stored past the grid.

Verified: check 49270 (msi, at the rt commit on top): cargo clippy of the translator, rt, validation and conformance (all features; --cfg m2v_gpu; rt under --cfg m2v_cpu_icd) clean; rustdoc of the translator and rt clean; the translator's and rt's host suites 3846/3846, the_stage_in_region_is_read_from_its_pushed_field among them; validation's replay tests 60/60; the conformance host suite 1058/1058.
This commit is contained in:
Anees Iqbal committed 2026-11-18 18:57:24 -08:00
1 parent 8f720744ce
commit 3e1e6bf0ec
4 files changed
+81 -3

No files matched your search

+1 -1
View File
@@ -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
+4 -1
View File
@@ -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
@@ -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"
);
}
@@ -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<u8> = (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(&region),
PushField::StageInRegion => push[o..o + 32].copy_from_slice(&region_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 {