Translator: ZeroAddress is placed where a read may be checked on a device-address slot

Under the identity domains a kernel whose load reaches a typed atomic's device-address slot or
another slot through one pointer select ended in the invariant 'a strategy reads the unplaced
push field ZeroAddress' on every committed profile in the address form (lavapipe, RADV, ANV,
NVIDIA's address form): the select's load is at an offset the memory plan proves constant, so it
noted no variable read and placed no ZeroAddress, but a store at a variable offset made its slot
checked, and the emitted load, whose offset is not a constant there, took the check and read
the zero range outside.

Placement now follows use. note_variable records every read's slot at any offset
(AccessPlan::read) and no longer places the field; place_zero_address decides it once the slots'
forms are final: placed where a slot of variable that a read reaches is in the device-address
form (a memory-plan slot or a pulled fetch's own source), and removed elsewhere, which subsumes
the bound form's removal where no checked slot was left.

SEMANTICS_VERSION 2342 -> 2343: the push layout of a kernel with such a read moves.
This commit is contained in:
Anees Iqbal committed 2026-12-03 05:54:54 -08:00
1 parent 2bd4f51c59
commit 423fbce843
2 files changed
+42 -12

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 = 2342;
pub const SEMANTICS_VERSION: u32 = 2343;
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
+41 -11
View File
@@ -713,6 +713,12 @@ pub struct AccessPlan {
/// ([`note_variable`]): each reads its `PushField::SlotBounds`, and each of those accesses
/// whose emitted offset is not a constant is checked against its buffer (`emit::prepare`).
pub variable: BTreeSet<SlotRef>,
/// Under the identity domains with containment on ([`identity_contained`]), the buffer slots
/// a load, a copy's read or a pulled fetch may reach, at any offset ([`note_variable`]): a
/// read of one of `variable` whose emitted offset is not a constant is checked, and where the
/// slot is reached by its device address reads `PushField::ZeroAddress` outside its buffer
/// (`emit::prepare`, `pulled`), whatever offset its own access proved.
pub read: BTreeSet<SlotRef>,
/// Under the identity domains, a kernel on a device that binds its buffer arguments
/// (`DeviceProfile::binds_kernel_buffers`): its storage views are its slots' buffers, each
/// bound over its buffer, and its pipeline's robust buffer access 2 contains them
@@ -1165,17 +1171,45 @@ pub(crate) fn identity_contained(cx: &SelectCx<'_>) -> bool {
/// An access of buffer slot `slot`, a read where `read`, whose byte offset is a translation-time
/// constant only where `fixed`. Under the identity domains with containment on
/// ([`identity_contained`]), a slot an access may reach at another offset is checked
/// ([`AccessPlan::variable`]): it reads its `PushField::SlotBounds`, and a read of it reads
/// `PushField::ZeroAddress` outside. An access at a constant offset stays unchecked.
/// ([`AccessPlan::variable`]) and reads its `PushField::SlotBounds`, and a read is noted at any
/// offset ([`AccessPlan::read`]): which reads take `PushField::ZeroAddress` is known once the
/// slots' forms are ([`place_zero_address`]). An access at a constant offset of a slot no other
/// access reaches at another stays unchecked.
pub(crate) fn note_variable(cx: &mut SelectCx<'_>, slot: SlotRef, fixed: bool, read: bool) {
if fixed || !identity_contained(cx) {
if !identity_contained(cx) {
return;
}
if read {
cx.families.access.read.insert(slot);
}
if fixed {
return;
}
cx.families.access.variable.insert(slot);
cx.push.insert(PushField::SlotBounds(slot));
if read {
cx.push.insert(PushField::ZeroAddress);
}
}
/// Place `PushField::ZeroAddress` where some read may be checked on a slot reached by its device
/// address (`emit::prepare`, `pulled`): a slot of `variable` that a read reaches
/// ([`AccessPlan::read`]), in the device-address form of `lowering` (by memory-plan slot index)
/// or `own` (a pulled fetch's own source slots); and nowhere else. A read of a storage view
/// clamps its offset instead, and an atomic outside its buffer runs nothing.
fn place_zero_address(
cx: &mut SelectCx<'_>,
lowering: &[Option<SlotLowering>],
own: &[(SlotRef, SlotLowering)],
) {
let access = &cx.families.access;
let checked_read =
|slot: &SlotRef| access.variable.contains(slot) && access.read.contains(slot);
let shared = (cx.memory.slots.iter().zip(lowering))
.any(|(plan, l)| matches!(l, Some(SlotLowering::Psb { .. })) && checked_read(&plan.slot));
let pulled =
(own.iter()).any(|(s, l)| matches!(l, SlotLowering::Psb { .. }) && checked_read(s));
match shared || pulled {
true => cx.push.insert(PushField::ZeroAddress),
false => cx.push.remove(&PushField::ZeroAddress),
};
}
/// Whether static-root pointer `ptr`'s byte offset from its roots is a translation-time
@@ -1467,12 +1501,8 @@ fn place_slots(cx: &mut SelectCx<'_>, m: &mut Meter) -> Result<Vec<Option<SlotCh
if bound && views {
cx.families.access.robust_views = true;
cx.facts.insert(RuntimeFact::RobustStorageBuffers);
// A checked load outside its buffer reads the zero range only where a checked slot is
// left.
if cx.families.access.variable.is_empty() {
cx.push.remove(&PushField::ZeroAddress);
}
}
place_zero_address(cx, &lowering, &own);
let counts = census.counts(stage);
cx.descriptors = cx.descriptors.plus(&counts);
let window = (crate::lower::push::base(cx), p.push_window());