Translator: the imageblock parameter's value is refused as Imageblocks(ParameterValue) where the planner meets it

The memory planner refused every read of the imageblock parameter's value before
access::select_param's ParameterValue arm, as Lowering(Access) PointerSource or PointerStore, so
that cause was never named. The planner now decides by the root, the parameter whose ABI role is
ParamRole::Imageblock, at its two sites:

- A pointer read out of an argument's aggregate (provenance resolve_walk): the imageblock
  parameter's value is Imageblocks(ParameterValue). Any other argument's aggregate stays
  PointerSource.
- A store of an aggregate that holds a pointer: when the stored value is built from the imageblock
  parameter (through insertvalue, extractvalue, freeze, select and phi, each value visited once,
  metered), Imageblocks(ParameterValue). Otherwise it stays PointerStore.

The PointerSource, PointerStore and ParameterValue docs say so. SEMANTICS_VERSION 2358: a
refusal's kind changes. REFUSALS.md regenerated, unchanged. No public type changes.

Verified, CPU-only potluck jobs at the pair's tip before its rebase onto development:
- m3-max-84488: the two red tests at the red commit, 0 of 2 passed (RED EXIT=100), and at the
  tip 2 of 2 passed; metal2vulkan and metal2vulkan-air 3480 tests run, 3480 passed, 22 skipped;
  metal2vulkan-validation 1349 passed, 3 skipped; conformance and runtime 1280 passed, 2
  skipped; each EXIT=0.
- clippy --workspace --all-targets --all-features -D warnings: plain m3-max-84494, --cfg m2v_gpu
  m3-max-84493, --cfg m2v_cpu_icd m3-max-84495, each EXIT=0.
- m3-max-84482: rustdoc -D warnings EXIT=0, the API reference check EXIT=0.
This commit is contained in:
Anees Iqbal committed 2026-12-03 09:53:05 -08:00
1 parent 742e497f4b
commit 722503da23
3 files changed
+72 -7

No files matched your search

+1 -1
View File
@@ -60,7 +60,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 = 2355;
pub const SEMANTICS_VERSION: u32 = 2358;
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
+6 -3
View File
@@ -1231,10 +1231,12 @@ pub enum AccessCause {
/// A pointer that comes from an operation the memory model does not follow: a call other than
/// an intrinsic's result, an element of an aggregate or a vector, a cast between address
/// spaces, a constant expression other than an address computation or a cast, an argument's
/// aggregate, or a value that is not a pointer on a pointer's path.
/// aggregate (but the imageblock parameter's, [`ImageblockCause::ParameterValue`]), or a
/// value that is not a pointer on a pointer's path.
PointerSource,
/// A store of a pointer, or of a value holding one, into memory: through a buffer pointer,
/// into private or threadgroup memory, or through a wide (64-bit address) pointer.
/// into private or threadgroup memory, or through a wide (64-bit address) pointer. A value
/// built from the imageblock parameter's is [`ImageblockCause::ParameterValue`].
PointerStore,
/// A private variable (`alloca`) of a type the typed form does not hold: nested past the
/// depth bound, an array of no elements, a matrix with no fragment form, a type with no
@@ -1334,7 +1336,8 @@ pub enum ImageblockCause {
MultisampleOperation,
/// The imageblock parameter's value used other than through its intrinsics: a kernel reaches
/// its explicit imageblock only through `air.imageblock_data`, the extent queries and slice
/// writes.
/// writes. The memory planner names it for a pointer read out of that value and for a store
/// of a value built from it, by the parameter's ABI role.
ParameterValue,
/// A slice write of the imageblock to a texture (`write_imageblock_slice`) of a shape not
/// modelled: its origin operand not the constant zero, its trailing flag not the constant
+65 -3
View File
@@ -45,7 +45,9 @@ use crate::air::ir::{
};
use crate::air::Entry;
use crate::budget::Meter;
use crate::error::{AccessCause, Error, Feature, InternalError, InternalKind, Unsupported};
use crate::error::{
AccessCause, Error, Feature, ImageblockCause, InternalError, InternalKind, Unsupported,
};
use crate::memory::abi_index::AbiIndex;
use crate::memory::alloca::{self, Strides};
use crate::memory::union_find::UnionFind;
@@ -719,6 +721,66 @@ fn not_lowered(cause: AccessCause) -> Error {
Unsupported::access(cause).into()
}
/// Whether argument `a` is the entry's imageblock parameter, by its ABI role: its value (a struct
/// holding the imageblock's opaque base) has no lowered form, as a kernel reaches the imageblock
/// only through its intrinsics.
fn is_imageblock_param(e: &Entry, a: crate::air::ir::ArgIdx) -> bool {
(e.ep.params.iter()).any(|b| b.param == a.raw() && matches!(b.role, ParamRole::Imageblock(_)))
}
/// The refusal of a pointer read out of argument `a`'s aggregate value: the imageblock
/// parameter's value names its own cause; another argument's is a pointer source not modelled.
fn aggregate_argument(e: &Entry, a: crate::air::ir::ArgIdx) -> Error {
match is_imageblock_param(e, a) {
true => Unsupported::imageblocks(ImageblockCause::ParameterValue).into(),
false => not_lowered(AccessCause::PointerSource),
}
}
/// The refusal of a store of `val`, an aggregate that holds a pointer: the imageblock parameter's
/// value when `val` is built from it (through `insertvalue`, `extractvalue`, `freeze`, `select`
/// and `phi`), else a pointer store not modelled. Each value is visited once.
fn aggregate_store(e: &Entry, val: Value, m: &mut Meter) -> Result<Error, Error> {
let store = || not_lowered(AccessCause::PointerStore);
let Some(body) = e.module.func(e.func).and_then(|f| f.body.as_ref()) else {
return Ok(store());
};
let entry = map_entry_bytes::<Value, ()>();
let mut seen: std::collections::HashSet<Value> = std::collections::HashSet::new();
let mut work = vec![val];
let mut charged = 0usize;
let found = (|| -> Result<bool, Error> {
while let Some(v) = work.pop() {
m.tick(1)?;
m.charge(entry)?;
charged = charged.saturating_add(entry);
if !seen.insert(v) {
continue;
}
match v {
Value::Arg(a) if is_imageblock_param(e, a) => return Ok(true),
Value::Inst(id) => match body.insts.get(id).map(|i| &i.kind) {
Some(InstKind::InsertValue { agg, val, .. }) => work.extend([*agg, *val]),
Some(InstKind::ExtractValue { agg, .. }) => work.push(*agg),
Some(InstKind::Freeze(v)) => work.push(*v),
Some(InstKind::Select { t, f, .. }) => work.extend([*t, *f]),
Some(InstKind::Phi { incoming, .. }) => {
work.extend(incoming.iter().map(|(v, _)| *v));
}
_ => {}
},
_ => {}
}
}
Ok(false)
})();
m.release(charged);
Ok(match found? {
true => Unsupported::imageblocks(ImageblockCause::ParameterValue).into(),
false => store(),
})
}
/// Constant integer index `v` of `e`'s module, sign-extended from its width; `None` when not
/// constant.
fn const_index(e: &Entry, v: Value) -> Option<i64> {
@@ -1269,7 +1331,7 @@ fn resolve_walk(
}
_ => return Err(not_lowered(AccessCause::PointerSource)),
},
Value::Arg(_) => return Err(not_lowered(AccessCause::PointerSource)),
Value::Arg(a) => return Err(aggregate_argument(e, a)),
Value::Inst(id) => {
let inst = body
.insts
@@ -3322,7 +3384,7 @@ impl Walk<'_, '_> {
.value_ty(*val)
.is_some_and(|t| self.cx.e.module.types().holds_pointer(t)) =>
{
return Err(not_lowered(AccessCause::PointerStore));
return Err(aggregate_store(self.cx.e, *val, m)?);
}
InstKind::Store { val, ptr, .. } => {
let n = size(self.cx, *val);