Drop a shader's stores into read-only memory as Metal drops them

The steps this packet landed as, in order:
- Keep the dropped-store key's doc off a private item
- Charge and request the dropped-store guard on every store path
- Bless the golden tables after the dropped-store mask

Content: the tree of `development` at 5589a6c3c7, unchanged.
This commit is contained in:
Anees Iqbal committed 2026-10-26 13:19:17 +02:00
1 parent 7ce12fa4d2
commit ef82ba784e
77 files changed
+2461 -1807

No files matched your search

@@ -938,6 +938,7 @@ impl ArgumentTable {
table.buffers.insert(index, bound);
}
}
table.dropped_store_buffers = self.dropped_store_buffers();
for (&index, bytes) in &self.bytes {
table.buffers.insert(index, bound_bytes(bytes));
}
@@ -952,6 +953,21 @@ impl ArgumentTable {
table
}
/// The buffer slots bound to memory whose GPU writes Metal drops
/// (`StageTable::dropped_store_buffers`): bit `i` where the buffer at index `i` drops them
/// (`Buffer::drops_writes`, no-copy memory of Metal's private option bit 24). Inline bytes
/// are the runtime's own upload and drop nothing. Metal holds 31 buffers a stage, so every
/// slot has a bit.
fn dropped_store_buffers(&self) -> u32 {
let mut slots = 0;
for (&index, (buffer, _)) in &self.buffers {
if index < u32::BITS && buffer.drops_writes() {
slots |= 1 << index;
}
}
slots
}
/// The table as `stage`'s function of `interface` reads it: `stage_table`, but a buffer bound
/// where the function reads a visible-function table is left out, so the slot reads its
/// neutral, a null table of size 0, as plain Metal reads such a buffer where its validation
@@ -1041,6 +1057,10 @@ impl ArgumentTable {
// The slots that tell the view base alignment apart first, which the buffers' shapes
// read.
reshape.field(&mut kept.at_bind_views, self.at_bind_views(stage, views));
reshape.field(
&mut kept.dropped_store_buffers,
self.dropped_store_buffers(),
);
let alignment = views.alignment;
kept.buffers.retain(|&index, _| {
let bound = !self.reads_unbound(read, index)
+11
View File
@@ -3284,6 +3284,17 @@ impl Buffer {
}
}
/// Whether the GPU's writes into the buffer's bytes are dropped, as Metal drops them for
/// no-copy memory of its private option bit 24 and for pages replaced read-only
/// (`read_only_view.rs`): a heap's buffer answers its heap's. A dispatch's or draw's stores
/// through a slot the buffer is bound at are dropped in the shader
/// (`StageTable::dropped_store_buffers`, `SpecKey::DroppedStoreSlots`), and the buffer's
/// memory keeps them out as well where the device imports the pages through a read-only view
/// of them.
pub(super) fn drops_writes(&self) -> bool {
self.pages_cell().is_some_and(|cell| cell.drops_writes())
}
/// `device`.
pub fn device(&self) -> &Device {
&self.0.device
@@ -347,6 +347,28 @@ impl DeviceProperties {
metal2vulkan::metal::TextureWriteRoundingMode::from_raw(mode).is_ok()
}
/// Whether this device keeps the GPU's writes out of read-only memory as Metal does
/// everywhere Metal does: no-copy memory made with
/// [`ResourceOptions::PRIVATE_BIT`](crate::ResourceOptions::PRIVATE_BIT), Metal's private
/// option bit 24, which is what marks a range read-only (the companion of Apple's
/// `replaceBackingWithRanges:readOnly:`). Metal has no query of its own for this: it is one of
/// the runtime's, so that a consumer can tell what it may stop guarding.
///
/// A shader's stores through a buffer slot bound to such memory are dropped on **every**
/// device, whatever this answers: the stage's dropped-store word gates them
/// (`read_only_view.rs`). This answers yes only where the memory itself takes the GPU's
/// writes nowhere, so that Metal's other shapes hold too: a store through an address loaded out
/// of an argument buffer or a pointer, a blit fill and a visibility result all complete and
/// leave the pages as they were, and a colour attachment with
/// [`StoreAction::Store`](crate::StoreAction::Store), a resolve target or a depth or stencil
/// attachment over such memory ends its command buffer in error. On macOS, where the device
/// imports the pages through a read-only view of them, that is yes; elsewhere the import is of
/// the caller's own pages and this answers no, with the difference announced
/// ([`Degradation::PrivateResourceOption`](crate::Degradation::PrivateResourceOption)).
pub fn drops_gpu_writes_to_read_only_memory(&self) -> bool {
crate::read_only_view::VIEWS_DROP_WRITES
}
/// `minimumLinearTextureAlignmentForPixelFormat:`: the alignment of a texture's offset and
/// rows in a buffer, 16 bytes for every format a buffer can back, as Metal answers on an M3 Max
/// and an M4. Refused, `Invalid` with
@@ -12,17 +12,38 @@
//! kernel's stores, a vertex-stage store, a fragment-stage store, a kernel or fragment store
//! through an address loaded out of an argument buffer, and a pass's visibility result all
//! complete with no error, and neither the CPU nor a later command buffer sees any of it.
//! - **What a render pass's own machinery writes faults the command buffer.** A colour
//! attachment over such memory, a resolve into it, and a depth or stencil attachment in a heap
//! made with the bit end their command buffer with `MTLCommandBufferErrorDomain` /
//! `kIOGPUCommandBufferCallbackErrorPageFault`, on the first command buffer of a fresh
//! process, every run — and every later command buffer of that process then errors too.
//! - **Later commands of the same command buffer may read a dropped write back** from the GPU's
//! caches, and whether they do is not stable: a blit fill and both compute stores were visible
//! there in every run including the first of a fresh process, while the visibility result and
//! the three draw-stage stores were not visible there in the first run of a fresh process
//! (twelve of twelve) and were in seven runs of eight once the process had run them. It is not
//! a contract to reproduce.
//! - **What faults a render pass is the store-out, not the binding and not the read.** An
//! attachment over such memory that the pass does not store completes: a colour attachment at
//! `storeAction = DontCare` over 484 fresh processes, each with a witness buffer proving the
//! fragment stage ran, and a depth, stencil or combined attachment at `DontCare` over
//! 2,248 of 2,248 (`Depth32Float`, `Depth16Unorm`, `Stencil8`, `Depth32Float_Stencil8` bound
//! to both points, and 4x multisampled `Depth32Float`, the draw's own values read back
//! against the clear). `loadAction = Load` completes the same 2,248 of 2,248 for colour,
//! depth and stencil, so the clean run is not Metal quietly refusing the memory. The same
//! attachments at `storeAction = Store` end their command buffer with
//! `MTLCommandBufferErrorDomain` / `kIOGPUCommandBufferCallbackErrorPageFault`, 200 of 200,
//! and every later command buffer of that process then errors too; the writable control is
//! clean through `Store`, 306 of 306.
//! - **A resolve is the same lever: whichever attachment stores out.** Attaching a resolve
//! destination over such memory and not resolving into it is clean 2,248 of 2,248 on both
//! read-only routes, and so is reading a read-only multisample primary and resolving out of
//! it; storing that primary into such memory faults 188 of 188. **Resolving into such memory
//! is unknown**: 0 page faults over 520 processes, but about 99 per cent of them were
//! discarded as recovery victims at two spacings, so the cell has no denominator to read a
//! verdict off. Nothing is built for it. An earlier record called a resolve into such memory
//! settled and faulting; that shape kept its multisample primary in Metal's own private
//! memory under `MultisampleResolve`, so it never stored a primary into read-only memory at
//! all, and its page fault does not reproduce.
//! - **Later commands of the same command buffer read a dropped write back** from the GPU's
//! caches, deterministically, and what decides it is the process's state rather than chance. A
//! blit fill and both compute stores were visible there in every run, the first of a fresh
//! process included. The visibility result and the three draw-stage stores were visible in
//! every run but a process's own first: over 61 fresh processes, each running one shape once,
//! not one saw the write (0 of 61, bit 24 and the `detachBacking` pair alike), and within one
//! process running a shape 512 times the split was exactly `answer[1/512] same=none` and
//! `answer[511/512] same=visible` in seven processes of eight (`[2/512]` and `[510/512]` in
//! the eighth). So the cold first run of a process never reads the dropped write back and every
//! later run does. It is still not a contract to reproduce: the caches, not Metal, decide it.
//! - **Bit 24 is not the only read-only state, and the other one agrees with it.** A consumer's
//! production path reaches read-only backing through Apple's SPI instead:
//! `detachBacking`, then `replaceBackingWithRanges:readOnly:YES` over its pages (the ranges as
@@ -30,7 +51,7 @@
//! `supportsResourceDetachBacking`, which this M3 Max does. Measured against bit 24 over the
//! same programs, eight runs a shape, each with the writable control of its own creation path:
//! the two forms agree on **all ten shapes measurable under both**, byte for byte, error for
//! error and flap for flap, so what is written above holds for either state. The SPI pair also
//! error and first run for first run, so what is written above holds for either state. The SPI pair also
//! behaves the same on a buffer made with `newBufferWithBytesNoCopy:` as on one made through the
//! private `MTLBufferDescriptor`, so the creation path does not enter it. A **detached** backing
//! is a different state and not this one: a command buffer that names a detached resource ends
@@ -40,7 +61,10 @@
//! `newHeapWithDescriptor:` in either storage mode, because Metal offers no heap over the
//! caller's bytes for it to detach (`MTLHeapDescriptor` answers no `setContents:`, `setNoCopy:`
//! or `setDeallocator:`, and the device does not respond to `newHeapWithBytesNoCopy:`). The
//! runtime's own `new_heap_with_bytes_no_copy` is an extension with no Metal counterpart.
//! runtime's own `new_heap_with_bytes_no_copy` is an extension with no Metal counterpart. The
//! bit is behavioural there rather than declarative: `heap.resourceOptions` reports it absent on
//! the read-only heap and on its writable twin alike, while `storeAction = Store` faults on the
//! one and not the other.
//! - **How.** A no-copy buffer made without the bit over a read-only view of the same pages
//! (`mach_vm_remap` sharing them, then `mprotect` read-only) behaved the same on every count
//! measured, and the probe above found it agreeing with bit 24 on **every one of its eleven
@@ -55,6 +79,17 @@
//! the import's 11 to 20 ms per GiB.
//! - **Freed.** The view is unmapped once the memory imported from it is freed (`memory.rs`'s
//! `Block`), as the import requires it mapped for its whole life.
//! - **The shader drops its own stores as well**, on every device and through either read-only
//! state: a slot bound to such a buffer has its bit set in the stage's dropped-store word
//! (`StageTable::dropped_store_buffers`, the translator's `SpecKey::DroppedStoreSlots`), which a
//! function that stores through a buffer slot reads as ordinary pipeline data and branches each
//! of its stores on. The word is per draw and per dispatch, so one pipeline runs with any of its
//! values, and only a function that stores pays the uniform branch. It reaches a store through a
//! bound slot alone: a store through an address loaded out of an argument buffer or a pointer
//! names no slot, an atomic is not gated (what Metal's atomics do to such memory is not
//! measured), and a blit fill, a visibility result and a render pass's own attachment writes are
//! not a shader's stores at all. On this system the read-only view keeps all of those out of the
//! pages, and the two agree on every shape measured above.
//! - **Elsewhere** the import is of the caller's pages: Linux drivers pin imported pages for
//! writing and refuse or fault on read-only ones (`host_memory.rs`), so there the GPU's writes
//! reach the pages, and the difference is announced
@@ -83,7 +83,8 @@ fn the_check_compares_every_field() {
"samplers",
"threadgroup_lengths",
"acceleration_structures",
"at_bind_views"
"at_bind_views",
"dropped_store_buffers"
]
);
let sampler = BoundSampler::new(SamplerDescriptor::new());
@@ -207,6 +207,7 @@ pub(crate) fn bound_value(
SpecKey::SparseTexture(slot) => sparse_texture(shape, slot),
SpecKey::ConstantLanes(slot) => constant_lanes(shape, slot),
SpecKey::OffsetBaseAxes(slot) => offset_base_axes(shape, slot),
SpecKey::DroppedStoreSlots(stage) => u64::from(dropped_store_slots(shape, stage)),
SpecKey::RangeAtBindOffset(slot) => match resources.slots.get(&slot) {
Some(SlotInterface::Buffer(b)) => u64::from(range_at_bind_offset(
b,
@@ -245,6 +246,18 @@ pub(crate) fn record_specialized(
Ok(())
}
/// The `SpecKey::DroppedStoreSlots` of `stage` for `shape`: the stage's buffer slots bound to
/// memory whose GPU writes Metal drops (`StageShape::dropped_store_buffers`, over the slots the
/// shape binds a buffer at), whose stores the stage's function drops
/// (`lower::access::emit::store_one`). A stage the shape holds nothing for binds nothing, so none
/// of its stores is dropped.
pub(crate) fn dropped_store_slots(shape: &BindShape, stage: Stage) -> u32 {
shape
.stages
.get(&stage)
.map_or(0, |s| s.dropped_store_buffers)
}
/// Whether `shape` binds anything at `slot`.
fn present(shape: &BindShape, slot: SlotRef) -> bool {
shape
@@ -737,3 +737,39 @@ fn only_a_map_that_moves_a_constexpr_mode_enters_the_variant() {
// A slot with no texture bound takes no map.
assert!(address_map_variant(&repeat, &BindShape::default()).is_empty());
}
/// A stage's dropped-store word reaches the shape over the slots it binds a buffer at, and is
/// what `SpecKey::DroppedStoreSlots` takes there: a bit of a slot the state binds nothing at names
/// nothing a store can reach, so the shape leaves it out and one set of bindings keeps one shape
/// whatever the runtime has recorded for its empty slots.
#[test]
fn a_dropped_store_word_covers_the_slots_the_shape_binds() {
let bound = |length| BoundBuffer::Buffer {
length,
offset: 0,
gpu_address: 0x1000,
device_address: None,
attribute_stride: None,
};
let mut state = BindState::default();
let table = state.stages.entry(Stage::Kernel).or_default();
table.buffers.insert(0, bound(64));
table.buffers.insert(2, bound(64));
// Slots 0 and 1 drop their writes; nothing is bound at 1.
table.dropped_store_buffers = 0b011;
let shape = state.shape();
assert_eq!(shape.stages[&Stage::Kernel].dropped_store_buffers, 0b001);
assert_eq!(dropped_store_slots(&shape, Stage::Kernel), 0b001);
// A stage the shape holds nothing for drops nothing.
assert_eq!(dropped_store_slots(&shape, Stage::Fragment), 0);
// The state answers its own shape, the word included, without making it again.
assert!(state.has_shape(&shape));
// The bit alone decides the word: the same bindings with it clear give 0, and the shapes
// differ, so a plan is not reused across the change.
let table = state.stages.entry(Stage::Kernel).or_default();
table.dropped_store_buffers = 0;
let kept = state.shape();
assert_eq!(dropped_store_slots(&kept, Stage::Kernel), 0);
assert_ne!(kept, shape);
assert!(!state.has_shape(&shape));
}
+28
View File
@@ -1039,9 +1039,22 @@ impl StageTable {
textures: self.textures.iter().map(|(i, t)| (*i, t.shape())).collect(),
samplers: self.samplers.iter().map(|(i, s)| (*i, s.shape())).collect(),
threadgroup_lengths: self.threadgroup_lengths.clone(),
dropped_store_buffers: self.dropped_stores(),
}
}
/// [`StageTable::dropped_store_buffers`] over the slots this table binds a buffer at, the
/// shape's word: a bit of an unbound slot names nothing a store can reach, so leaving it out
/// keeps one shape for the draws of one set of bindings.
fn dropped_stores(&self) -> u32 {
let bound = self
.buffers
.keys()
.filter(|i| **i < u32::BITS)
.fold(0u32, |m, i| m | 1 << i);
self.dropped_store_buffers & bound
}
/// Whether its shape is the empty one, which [`BindState::shape`] leaves out.
fn has_empty_shape(&self) -> bool {
self.buffers.is_empty()
@@ -1058,6 +1071,7 @@ impl StageTable {
textures,
samplers,
threadgroup_lengths,
dropped_store_buffers,
} = shape;
let buffer_shapes = (self.buffers.iter())
.map(|(i, b)| (*i, b.shape(self.class_alignment(*i, view_base_alignment))));
@@ -1067,6 +1081,7 @@ impl StageTable {
&& texture_shapes.eq(textures.iter().map(|(i, t)| (*i, *t)))
&& sampler_shapes.eq(samplers.iter().map(|(i, s)| (*i, *s)))
&& self.threadgroup_lengths == *threadgroup_lengths
&& self.dropped_stores() == *dropped_store_buffers
}
/// The alignment above the vertex fetch's that the bind offset class of a buffer at index
@@ -1251,6 +1266,14 @@ pub struct StageTable {
/// runtime leaves out a slot it finds bound at moving offsets, so that its draws keep one shape.
#[cfg_attr(feature = "serde", serde(default))]
pub at_bind_views: u64,
/// The buffer slots (bit `i` for index `i`) bound to memory whose GPU writes Metal drops,
/// which the runtime sets: no-copy memory of Metal's private option bit 24, or pages a
/// consumer replaced read-only (`metal2vulkan-runtime`'s `read_only_view.rs`). A function's
/// stores through such a slot are dropped and nothing else of the draw or dispatch changes
/// (`SpecKey::DroppedStoreSlots`, `lower::access::emit::store_one`), as Metal drops a shader's
/// stores to such memory and completes. A slot left out (none, the default) keeps its stores.
#[cfg_attr(feature = "serde", serde(default))]
pub dropped_store_buffers: u32,
}
/// What the consumer knows of a Metal acceleration structure bound at a buffer slot.
@@ -1940,6 +1963,11 @@ pub struct StageShape {
pub textures: BTreeMap<u32, TextureShape>,
pub samplers: BTreeMap<u32, BoundSamplerShape>,
pub threadgroup_lengths: BTreeMap<u32, u32>,
/// The bound buffer slots whose GPU writes are dropped
/// ([`StageTable::dropped_store_buffers`] over the slots this shape binds a buffer at), which
/// a function that stores through a buffer slot reads (`SpecKey::DroppedStoreSlots`).
#[cfg_attr(feature = "serde", serde(default))]
pub dropped_store_buffers: u32,
}
/// The shape of a bound buffer.
+1
View File
@@ -817,6 +817,7 @@ codec_enum! {
ObjectLocalSize(f0), ObjectFlatLocalSize, ObjectMultiRegion, SamplerMinLevel(f0),
ConstantLanes(f0), UnmeasuredTexels(f0), BoundTexelFormat(f0), OffsetBaseAxes(f0),
SamplerAnisotropy(f0), RangeAtBindOffset(f0), PlainHalfTexels(f0),
DroppedStoreSlots(f0),
}
PushField {
RootTableAddress, ExecutionStatusAddress, DispatchRegion, BaseVertexInstance,
+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 = 1849;
pub const SEMANTICS_VERSION: u32 = 1850;
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
@@ -1349,7 +1349,10 @@ pub fn emit(
let m = fb.composite_extract(fat, &[1])?;
let mut prepared = Vec::with_capacity(targets.len());
for t in targets {
let prep = prepare(cx, fb, t, m, bytes)?;
// An atomic is not gated on the slot's dropped-store word: what Metal's
// atomics do to memory whose writes it drops is not measured
// (`SpecKey::DroppedStoreSlots`), and unknown stays unknown.
let prep = prepare(cx, fb, t, m, bytes, false)?;
if typed.is_some() && !matches!(prep.mem, Mem::Psb(_)) {
return Err(cx.fail("a typed atomic through a descriptor view"));
}
@@ -537,6 +537,9 @@ fn static_access(
return Err(cx.invariant("a pointer store through a uniform view"));
}
cx.push.insert(PushField::SlotBindOffset(plan.slot));
if write {
super::request_dropped_store_word(cx, plan.slot);
}
}
Ok(Access {
ptr: operand(cx, ptr)?,
+49 -9
View File
@@ -7,7 +7,7 @@ use crate::lower::emit::EmitCx;
use crate::memory::contain::{self, Check};
use crate::memory::leaf::{self, k32, u32_op, Leaf, Units, WordMem, WordOps};
use crate::memory::views::{self, UnitViews, View, ViewKind};
use crate::pipeline::sym::PushField;
use crate::pipeline::sym::{PushField, SpecKey};
use crate::spirv::builder::constructs::{ArmEnd, ArmFn};
use crate::spirv::builder::FunctionBuilder;
use crate::spirv::error::BResult;
@@ -245,19 +245,50 @@ pub(super) struct Prepared {
/// A store needs `if_(inb)`: a view's out-of-bounds offset is not redirected (a PSB access
/// already points at the sink).
pub(super) guard_store: bool,
/// The draw's or dispatch's word says the slot's memory keeps the GPU's writes: a store runs
/// only where it holds, so a store through memory whose writes Metal drops is dropped
/// ([`writable`], `SpecKey::DroppedStoreSlots`). `None` where the access stores nothing, or at
/// a slot no guest buffer can be bound to.
pub(super) writable: Option<SValue>,
}
/// Prepare `t` for an access of `n` bytes at Metal offset `m`.
/// Whether the draw's or dispatch's `SpecKey::DroppedStoreSlots` word leaves `slot`'s stores
/// standing: `(word >> slot.index) & 1 == 0`, one uniform word read and three uniform
/// instructions, which every store through the slot branches on. `None` at a slot that is not a
/// guest buffer slot of the stage's argument table (a synthetic binding, which the runtime owns
/// and never places over a caller's read-only pages) and so has no bit of the word.
fn writable(
cx: &mut EmitCx<'_>,
fb: &mut FunctionBuilder<'_>,
slot: crate::pipeline::sym::SlotRef,
) -> BResult<Option<SValue>> {
if slot.class != crate::pipeline::sym::SlotClass::Buffer || slot.index >= u32::BITS {
return Ok(None);
}
let field = PushField::Specialized(SpecKey::DroppedStoreSlots(slot.stage));
let word = cx.push_field(fb, field)?;
let bit = k32(fb, 1 << slot.index)?;
let dropped = u32_op(fb, BinOp::BitwiseAnd, word, bit)?;
let zero = k32(fb, 0)?;
Ok(Some(fb.binary(BinOp::IEqual, dropped, zero)?))
}
/// Prepare `t` for an access of `n` bytes at Metal offset `m`, which stores where `store`.
pub(super) fn prepare(
cx: &mut EmitCx<'_>,
fb: &mut FunctionBuilder<'_>,
t: &Target,
m: SValue,
n: u32,
store: bool,
) -> BResult<Prepared> {
let Some(choice) = cx.plan.slots.get(t.slot).copied().flatten() else {
return Err(cx.fail("an access names an unplanned slot"));
};
let writable = match store {
true => writable(cx, fb, choice.slot)?,
false => None,
};
let lowering = cx.plan.families.access.slots.get(t.slot).copied().flatten();
let ops = WordOps::of(crate::lower::sync::memory_model::coherence(cx.plan));
if let Some(SlotLowering::Psb { start }) = lowering {
@@ -269,6 +300,7 @@ pub(super) fn prepare(
off: a.off,
inb: a.inb,
guard_store: false,
writable,
});
}
let Some(view) = cx.decl.families.access.views.get(t.slot).copied().flatten() else {
@@ -323,6 +355,7 @@ pub(super) fn prepare(
off,
inb,
guard_store,
writable,
})
}
@@ -339,12 +372,19 @@ fn load_one(fb: &mut FunctionBuilder<'_>, leaf: &Leaf, p: Prepared) -> BResult<S
}
}
/// Store `v` as `leaf` at `p`, contained. Returns whether the store merges a partial word
/// ([`leaf::store`]).
/// Store `v` as `leaf` at `p`, contained and only where the slot's memory keeps the GPU's writes
/// ([`Prepared::writable`]). Returns whether the store merges a partial word ([`leaf::store`]).
fn store_one(fb: &mut FunctionBuilder<'_>, leaf: &Leaf, p: Prepared, v: SValue) -> BResult<bool> {
let mut mem = p.mem;
match (p.inb, p.guard_store) {
(Some(inb), true) => {
let contained = p.guard_store.then_some(p.inb).flatten();
let guard = match (contained, p.writable) {
(Some(inb), Some(keeps)) => Some(fb.binary(BinOp::LogicalAnd, inb, keeps)?),
(Some(inb), None) => Some(inb),
(None, Some(keeps)) => Some(keeps),
(None, None) => None,
};
match guard {
Some(guard) => {
let leaf = *leaf;
let then: ArmFn<'_, bool> = Box::new(move |fb, merged| {
let mut mem = p.mem;
@@ -352,10 +392,10 @@ fn store_one(fb: &mut FunctionBuilder<'_>, leaf: &Leaf, p: Prepared, v: SValue)
Ok(ArmEnd::FallThrough(Vec::new()))
});
let mut merged = false;
fb.if_(&mut merged, inb, then, None)?;
fb.if_(&mut merged, guard, then, None)?;
Ok(merged)
}
_ => leaf::store(fb, &mut mem, leaf, p.off, v),
None => leaf::store(fb, &mut mem, leaf, p.off, v),
}
}
@@ -421,7 +461,7 @@ pub(super) fn access_at(
};
let mut prepared = Vec::with_capacity(a.targets.len());
for t in &a.targets {
let mut p = prepare(cx, fb, t, m, a.leaf.bytes)?;
let mut p = prepare(cx, fb, t, m, a.leaf.bytes, stored.is_some())?;
p.mem = p.mem.with(ops);
prepared.push((t.root, t.slot, p));
}
+32 -3
View File
@@ -140,7 +140,7 @@ use crate::pipeline::facts::{RuntimeFact, UniformViewChoice};
use crate::pipeline::interface::{
AccessSet, BufferForm, DescriptorView, PushLoc, PushPlacement, Window,
};
use crate::pipeline::sym::{PushField, SlotRef};
use crate::pipeline::sym::{PushField, SlotClass, SlotRef, SpecKey};
use crate::spirv::builder::{FunctionBuilder, ModuleBuilder};
use crate::spirv::error::BResult;
use crate::spirv::ids::{DemoteTy, TypeId, Value as SValue};
@@ -320,11 +320,21 @@ impl Access {
Some(_) => leaf_words(&self.leaf).saturating_add(96),
None => 0,
};
// A store's dropped-store guard, per target. Charged for a load too: a memory
// intrinsic's endpoint and a stored pointer carry no `value` here, so the access cannot
// tell a store from a load, and the estimate must bound what emission writes.
let guard = DROPPED_STORE_GUARD_WORDS.saturating_mul(self.targets.len() as u32);
per.saturating_add(blob)
.saturating_add(guard)
.saturating_add(16u32.saturating_mul(self.targets.len() as u32 + 2))
}
}
/// SPIR-V words of one store's dropped-store guard: the stage's `SpecKey::DroppedStoreSlots`
/// word read from its push field or the argument table, the bit test, and the selection the store
/// runs in (`emit::store_one`).
const DROPPED_STORE_GUARD_WORDS: u32 = 64;
fn leaf_words(l: &Leaf) -> u32 {
l.cost()
}
@@ -1989,8 +1999,10 @@ fn blob_roots(
}
/// Give each of `targets` the profile's containment check and read its slot's `SlotBindOffset`;
/// a written target is a storage view. Every static-root access places its targets here
/// ([`access_with_leaf`], `copy::endpoint`).
/// a written target is a storage view. A written target also reads the draw's or dispatch's
/// `SpecKey::DroppedStoreSlots` word, which gates every store through the slot
/// (`emit::store_one`), so only a function that stores through a buffer slot reads it. Every
/// static-root access places its targets here ([`access_with_leaf`], `copy::endpoint`).
fn place_targets(cx: &mut SelectCx<'_>, targets: &mut [Target], write: bool) -> Result<(), Error> {
let check = contain::encoding(cx.profile);
for t in targets {
@@ -2004,10 +2016,27 @@ fn place_targets(cx: &mut SelectCx<'_>, targets: &mut [Target], write: bool) ->
return Err(cx.invariant("a write through a uniform view"));
}
cx.push.insert(PushField::SlotBindOffset(plan.slot));
if write {
request_dropped_store_word(cx, plan.slot);
}
}
Ok(())
}
/// Read the stage's `SpecKey::DroppedStoreSlots` word where a store through `slot` branches on it:
/// a guest buffer slot of the stage's argument table, the only slot a caller's memory is bound to
/// (`emit::writable` reads the same predicate, so every selection that emits a store through a
/// static root asks here). A synthetic binding the runtime owns has no bit of the word and no
/// branch.
pub(super) fn request_dropped_store_word(cx: &mut SelectCx<'_>, slot: SlotRef) {
if slot.class == SlotClass::Buffer && slot.index < u32::BITS {
cx.push
.insert(PushField::Specialized(SpecKey::DroppedStoreSlots(
slot.stage,
)));
}
}
/// Give each slot of `targets` the unit views that read or write `leaf` (a store when `write`)
/// in whole units ([`leaf::leaf_units`]): a storage slot the narrow views the profile can access,
/// and any slot a `uvec4` view.
@@ -479,6 +479,7 @@ fn store_pointer(
if in_blob {
return Err(refuse());
}
let mut slots = Vec::with_capacity(targets.len());
for t in &targets {
let plan = cx
.memory
@@ -488,6 +489,12 @@ fn store_pointer(
if super::view_kind(cx.profile, plan) != super::ViewKind::Storage {
return Err(cx.invariant("a pointer store through a uniform view"));
}
// The store is emitted through `emit::access_at` with a value, so it branches on the
// stage's dropped-store word; `access_with_leaf` below is given none and would not ask.
slots.push(plan.slot);
}
for slot in slots {
super::request_dropped_store_word(cx, slot);
}
let to = super::access_with_leaf(cx, ptr, None, leaf, targets, null, None)?;
let words = !cx.profile.fields().leaf.int64;
+10 -3
View File
@@ -1,4 +1,7 @@
//! The bound texture values a function reads as data.
//! The bound values a function reads as data.
//!
//! A key the module declares no constant for (`SpecKey::data_only`, the dropped-store word) is
//! read by its own reader from its push field and localized nowhere here.
//!
//! The format class of the texture bound at a slot (`SpecKey::TexelFormat`) was a
//! specialization constant, so each new format a guest bound made a new `VkPipeline`, a whole
@@ -61,7 +64,9 @@ pub(crate) fn emit_entry(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>) -> B
.fields
.iter()
.filter_map(|f| match f.field {
PushField::Specialized(key) => Some(key),
// A data-only key declares no constant, so nothing here localizes one
// (`SpecKey::data_only`): its reader loads the field itself.
PushField::Specialized(key) if !key.data_only() => Some(key),
_ => None,
})
.collect();
@@ -76,7 +81,9 @@ pub(crate) fn emit_entry(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>) -> B
ConstKind::Spec { key, .. } if placed.contains(key) => {
declared.insert(*key, c);
}
ConstKind::Spec { key, .. } if key.read_as_data() => stray = Some(*key),
ConstKind::Spec { key, .. } if key.read_as_data() && !key.data_only() => {
stray = Some(*key)
}
ConstKind::SpecOp { op, operands } => ops.push((c, *op, operands.to_vec())),
_ => {}
}
+20 -1
View File
@@ -851,6 +851,15 @@ pub enum SpecKey {
/// which a driver can load into registers ahead of the shader (Mesa's ANV does so only for a
/// uniform load at a constant offset); elsewhere at the residual plus the offset.
RangeAtBindOffset(SlotRef),
/// Which of the stage's buffer slots are bound to memory whose GPU writes Metal drops (`u32`,
/// default 0): bit `n` for `[[buffer(n)]]`, over the slots a stage can hold (Metal's 31
/// argument-table entries, so every bit of the word). A stage reads it only where it stores
/// through a buffer slot, and a store it sets the bit for is dropped
/// (`lower::access::emit::store_one`), as Metal drops the GPU's writes to such memory
/// (`metal2vulkan-runtime`'s `read_only_view.rs`). It is never a specialization constant and
/// no pipeline's key carries it (`SpecKey::data_only`): one pipeline runs with any mask, and
/// a function that stores pays one uniform branch per store.
DroppedStoreSlots(Stage),
}
impl SpecKey {
@@ -878,7 +887,17 @@ impl SpecKey {
/// least. Every other key stays a specialization; read as data, the bound sampler's word, say,
/// made one NVIDIA making cost about four times a specialized one.
pub fn read_as_data(self) -> bool {
matches!(self, SpecKey::TexelFormat(_))
matches!(
self,
SpecKey::TexelFormat(_) | SpecKey::DroppedStoreSlots(_)
)
}
/// Whether the key is read as data alone: no stage declares a specialization constant of it,
/// so nothing localizes one (`lower::specialized::emit_entry`) and no pipeline's key carries
/// it. A function reads it from its push field where it reads it at all.
pub(crate) fn data_only(self) -> bool {
matches!(self, SpecKey::DroppedStoreSlots(_))
}
}
@@ -86,14 +86,18 @@ fn run_kernel(plan: &Plan, m: &TypedModule) -> Vec<u32> {
spec.insert(SpecKey::LocalSize(axis), v);
}
spec.insert(SpecKey::FlatLocalSize, 4);
// Zero push bytes: each buffer is bound at its start, and the dispatch is one region at the
// grid's origin.
// Zero push bytes: each buffer is bound at its start, the dispatch is one region at the
// grid's origin, and no slot's stores are dropped
// (`PushField::Specialized(SpecKey::DroppedStoreSlots)`, which a kernel that stores through a
// buffer slot reads; `tests::engine_dropped_stores` runs it set).
for f in &plan.push.fields {
assert!(matches!(f.loc, PushLoc::Push { .. }), "{f:?}");
assert!(
matches!(
f.field,
PushField::SlotBindOffset(_) | PushField::DispatchRegion
PushField::SlotBindOffset(_)
| PushField::DispatchRegion
| PushField::Specialized(SpecKey::DroppedStoreSlots(_))
),
"unexpected push field {f:?}"
);
@@ -702,6 +702,8 @@ fn one_buffer(plan: &Plan, words: usize, threads: u32) -> Resources {
(PushField::SlotBindOffset(_), PushLoc::Push { offset }) => {
push[offset as usize..offset as usize + 4].fill(0)
}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -113,6 +113,8 @@ fn resources(
(PushField::SlotBindOffset(_), PushLoc::Push { offset }) => {
push[offset as usize..offset as usize + 4].fill(0)
}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -129,7 +129,11 @@ fn resources(plan: &Plan, threads: u32, init: &[Vec<u8>]) -> Resources {
matches!(
(f.field, f.loc),
(
PushField::SlotBindOffset(_) | PushField::DispatchRegion,
PushField::SlotBindOffset(_)
| PushField::DispatchRegion
| PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(
_
)),
PushLoc::Push { .. }
)
),
@@ -172,6 +172,11 @@ fn resources(plan: &Plan, init: &[Vec<u32>], threads: u32) -> Resources {
(PushField::ExecutionStatusAddress, PushLoc::Push { offset }) => {
(offset, Some(STATUS_AT))
}
// No slot's writes dropped: the word stays 0.
(
PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)),
PushLoc::Push { offset },
) => (offset, None),
other => panic!("unexpected push field {other:?}"),
};
let at = at as usize;
@@ -1151,6 +1156,8 @@ fn device_address_atomics_are_exact_and_contained() {
(PushField::RootTableAddress, PushLoc::Push { offset }) => {
push[offset as usize..offset as usize + 8].copy_from_slice(&TABLE.to_le_bytes())
}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -310,6 +310,8 @@ fn resources(plan: &Plan, init: &[Vec<u8>], class: BicubicTexels) -> Resources {
(PushField::SlotBindOffset(_) | PushField::DispatchRegion, PushLoc::Push { .. }) => {}
// A bound value read as data, which the interpreter writes from `spec`.
(PushField::Specialized(_), PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -128,7 +128,9 @@ fn push_bytes(plan: &Plan) -> Vec<u8> {
assert!(
matches!(
f.field,
PushField::SlotBindOffset(_) | PushField::DispatchRegion
PushField::SlotBindOffset(_)
| PushField::DispatchRegion
| PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_))
),
"{:?}",
f.field
@@ -149,6 +149,8 @@ fn dispatch(
for f in &plan.push.fields {
match (f.field, f.loc) {
(PushField::SlotBindOffset(_) | PushField::DispatchRegion, PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("{kernel}: unexpected push field {other:?}"),
}
}
@@ -174,6 +174,8 @@ fn resources(plan: &Plan, init: &[Vec<u8>], threads: u32, spec: &[(SpecKey, u64)
}
// A single-region dispatch: the region is unused.
(PushField::DispatchRegion, PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -99,6 +99,8 @@ fn run_word0(plan: &Plan, m: &TypedModule, d: &Dispatch) -> u32 {
PushField::ExecutionStatusAddress => {
push[o..o + 8].copy_from_slice(&STATUS_AT.to_le_bytes())
}
// No slot's writes dropped: the word stays 0.
PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -520,7 +522,13 @@ fn run_derivatives(
assert!(
matches!(
(f.field, f.loc),
(PushField::SlotBindOffset(_), PushLoc::Push { .. })
(
PushField::SlotBindOffset(_)
| PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(
_
)),
PushLoc::Push { .. }
)
),
"{f:?}"
);
@@ -382,7 +382,9 @@ fn run_case(plan: &Plan, m: &TypedModule, c: Case, lanes: SubgroupSize) -> Vec<u
assert!(
matches!(
f.field,
PushField::SlotBindOffset(_) | PushField::DispatchRegion
PushField::SlotBindOffset(_)
| PushField::DispatchRegion
| PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_))
),
"unexpected push field {f:?}"
);
@@ -168,6 +168,10 @@ fn each_vertex_reads_its_draw_s_bases() {
push[at..at + 4].copy_from_slice(&first[0].to_le_bytes());
push[at + 4..at + 8].copy_from_slice(&first[1].to_le_bytes());
}
// No slot's writes dropped: the word stays 0.
PushField::Specialized(
crate::pipeline::sym::SpecKey::DroppedStoreSlots(_),
) => {}
other => panic!("{what}: unexpected push field {other:?}"),
}
}
@@ -0,0 +1,174 @@
//! Stores through a buffer slot bound to memory whose GPU writes Metal drops.
//!
//! Metal takes a shader's stores to such memory nowhere and completes the command buffer with no
//! error: no-copy memory of its private option bit 24, or pages a consumer replaced read-only
//! (`metal2vulkan-runtime`'s `read_only_view.rs`, measured on an M3 Max; the user's own shape, a
//! reachable store gated off at runtime, completed in every one of 8,314 runs). Vulkan has no
//! read-only import of host memory, so the drop is the shader's: a function that stores through a
//! buffer slot reads the draw's or dispatch's `SpecKey::DroppedStoreSlots` word as push data and
//! branches each store on the slot's bit (`lower::access::emit::store_one`). One pipeline runs
//! with any word.
//!
//! Here the kernel of the owned fixture `engine/fca_kernel_absent_builtin`, whose one store writes
//! `out[tid]`, runs on the CPU interpreter with the word clear, with its slot's bit set, and with
//! another slot's bit set, on every committed profile. `llvm-as` assembles the fixture; without it
//! the tests skip visibly. No GPU is used.
use std::collections::BTreeMap;
use crate::device::{DevicePolicy, DeviceProfile};
use crate::library::{FunctionConstantValue, FunctionConstantValues};
use crate::lower::select::Plan;
use crate::metal::DataType;
use crate::pipeline::interface::PushLoc;
use crate::pipeline::sym::{Axis, PushField, ResourceKind, ResourceSlot, SpecKey, Stage};
use crate::pipeline::testing::{
engine_dir, llvm_assemble, profile, typed_module_specialized, AssembleError,
};
use crate::spirv::interp::{run, Buffer, Config, Order, Resources};
use crate::spirv::ir::TypedModule;
use crate::spirv::testing::committed_profiles;
/// The fixture's entry, whose `has_width` constant is on: every thread stores
/// `threads_per_threadgroup`, [`THREADS`], to `out[tid]`.
const ENTRY: &str = "fca_kernel_absent_builtin";
/// The threads of the one threadgroup the kernel runs in, and so the value it stores.
const THREADS: u32 = 4;
/// The byte every word of the output buffer holds before the dispatch: a store that is dropped
/// leaves them all.
const SENTINEL: u8 = 0xab;
fn assemble() -> Option<Vec<u8>> {
match llvm_assemble(&engine_dir().join(format!("{ENTRY}.ll"))) {
Ok(b) => Some(b),
Err(AssembleError::Missing(why)) => {
eprintln!("SKIPPED: {why}");
None
}
Err(AssembleError::Rejected(why)) => panic!("llvm-as rejected {ENTRY}.ll: {why}"),
}
}
/// Every word of `out` after one workgroup of [`THREADS`] threads ran `m` (planned as `plan`) with
/// the kernel stage's `SpecKey::DroppedStoreSlots` word `dropped`, the buffer filled with
/// [`SENTINEL`] first; identical in both scheduling orders. The interpreter writes the word into
/// the push bytes of its placed field (`interp::specialized_push`).
fn run_kernel(plan: &Plan, m: &TypedModule, dropped: u32) -> Vec<u32> {
let mut spec = BTreeMap::new();
for (axis, v) in [(Axis::X, THREADS), (Axis::Y, 1), (Axis::Z, 1)] {
spec.insert(SpecKey::LocalSize(axis), u64::from(v));
}
spec.insert(SpecKey::FlatLocalSize, u64::from(THREADS));
spec.insert(
SpecKey::DroppedStoreSlots(Stage::Kernel),
u64::from(dropped),
);
let res = Resources {
buffers: vec![Buffer {
slot: Some(ResourceSlot {
stage: Stage::Kernel,
kind: ResourceKind::Buffer,
index: 0,
}),
address: None,
bytes: [SENTINEL; 4 * THREADS as usize].to_vec(),
}],
push: vec![0u8; plan.push.push_range.map_or(0, |(_, end)| end as usize)],
spec,
};
let mut outs = Vec::new();
for order in [Order::Forward, Order::Reverse] {
let cfg = Config {
order,
..Config::default()
};
let out = run(m, &cfg, res.clone()).unwrap_or_else(|e| panic!("{order:?}: {e:?}"));
outs.push(out.buffers);
}
assert_eq!(outs[0], outs[1], "scheduling orders disagree");
outs[0][0]
.as_chunks::<4>()
.0
.iter()
.map(|w| u32::from_le_bytes([w[0], w[1], w[2], w[3]]))
.collect()
}
/// The constants of the fixture with `has_width` on, so that the kernel stores
/// `threads_per_threadgroup`.
fn constants() -> FunctionConstantValues {
FunctionConstantValues::defaults()
.with_index(0, FunctionConstantValue::new(DataType::Bool, [1]))
}
fn prof(stem: &str) -> DeviceProfile {
profile(stem, DevicePolicy::default()).expect("committed profile")
}
/// A kernel that stores through a buffer slot reads the dispatch's `DroppedStoreSlots` word from
/// its push window: the word is ordinary pipeline data, so one pipeline runs with any of its
/// values.
#[test]
fn a_storing_kernel_reads_the_dropped_store_word() {
let Some(bc) = assemble() else {
return;
};
for (stem, p) in committed_profiles().expect("profiles") {
let _ = prof(&stem);
let (plan, _) = typed_module_specialized(&bc, ENTRY, &p, &constants())
.unwrap_or_else(|e| panic!("{stem}: {e}"));
let field = PushField::Specialized(SpecKey::DroppedStoreSlots(Stage::Kernel));
let placed = plan
.push
.fields
.iter()
.find(|f| f.field == field)
.unwrap_or_else(|| panic!("{stem}: the dropped-store word is not placed"));
assert!(
matches!(placed.loc, PushLoc::Push { .. }),
"{stem}: {placed:?}"
);
assert_eq!(placed.size, 4, "{stem}");
}
}
/// With the slot's bit of the word set, the kernel's store is dropped and the buffer's bytes are
/// the ones it held: Metal's drop, and the dispatch runs to its end. With the word clear, or with
/// another slot's bit set, the same pipeline stores.
#[test]
fn a_dropped_slots_store_leaves_the_bytes_and_the_dispatch_runs() {
let Some(bc) = assemble() else {
return;
};
let kept = u32::from_le_bytes([SENTINEL; 4]);
for (stem, p) in committed_profiles().expect("profiles") {
let (plan, m) = typed_module_specialized(&bc, ENTRY, &p, &constants())
.unwrap_or_else(|e| panic!("{stem}: {e}"));
// No slot's writes dropped: the store lands.
assert_eq!(
run_kernel(&plan, &m, 0),
[THREADS; THREADS as usize],
"{stem}: the store did not land with the word clear"
);
// Slot 0's dropped: the store is taken nowhere and every word is as it was.
assert_eq!(
run_kernel(&plan, &m, 1),
[kept; THREADS as usize],
"{stem}: the store reached memory whose writes are dropped"
);
// Another slot's bit is another slot's: the store through slot 0 lands.
assert_eq!(
run_kernel(&plan, &m, 0b10),
[THREADS; THREADS as usize],
"{stem}: slot 1's bit dropped slot 0's store"
);
// Every bit of the word, slot 0's among them: still dropped, and nothing else changes.
assert_eq!(
run_kernel(&plan, &m, u32::MAX),
[kept; THREADS as usize],
"{stem}: a full word let the store through"
);
}
}
@@ -219,6 +219,8 @@ fn push_bytes(plan: &Plan) -> Vec<u8> {
out[at..at + 8].copy_from_slice(&STATUS.to_le_bytes())
}
PushField::SlotBindOffset(_) => {}
// No slot's writes dropped: the word stays 0.
PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -373,6 +373,8 @@ fn resources(plan: &Plan, bytes: usize, spec: &[(SpecKey, u64)]) -> Resources {
(PushField::SlotBindOffset(_) | PushField::DispatchRegion, PushLoc::Push { .. }) => {}
// A bound value read as data, which the interpreter writes from `spec`.
(PushField::Specialized(_), PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -271,6 +271,8 @@ pub(super) fn run_samples(
// A bound value the function reads as data, which the interpreter writes from the
// specialization it is given.
(PushField::Specialized(_), PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("{what}: unexpected push field {other:?}"),
}
}
@@ -140,7 +140,9 @@ fn push_bytes(plan: &Plan) -> Vec<u8> {
assert!(
matches!(
f.field,
PushField::SlotBindOffset(_) | PushField::DispatchRegion
PushField::SlotBindOffset(_)
| PushField::DispatchRegion
| PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_))
),
"{:?}",
f.field
@@ -708,7 +710,8 @@ fn push_fields_in_the_argument_table_are_read_exactly() {
.filter(|f| matches!(f.loc, PushLoc::ArgumentTable { .. }))
.map(|f| f.field)
.collect();
assert_eq!(spilled.len(), 7, "{what}: {spilled:?}");
// Seven slot residuals and the stage's dropped-store word.
assert_eq!(spilled.len(), 8, "{what}: {spilled:?}");
assert_eq!(a.interface.push.argument_table_size, 32, "{what}");
let (table, _) = link_and_validate(&a, &p).unwrap_or_else(|e| panic!("{what}: {e}"));
assert!(table.bindings.contains_key(&table_slot), "{what}");
@@ -721,6 +724,10 @@ fn push_fields_in_the_argument_table_are_read_exactly() {
PushField::SlotBindOffset(s) => residual(s.index),
// `MultiRegion` is 0: the region is not read.
PushField::DispatchRegion => continue,
// No slot's writes dropped: the word stays 0.
PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)) => {
continue
}
other => panic!("{what}: unexpected {other:?}"),
};
let (bytes, at) = match f.loc {
@@ -290,7 +290,11 @@ fn run_kernel(bc: &[u8], local: [u32; 3], words: usize) -> Vec<u32> {
for f in &plan.push.fields {
assert!(matches!(f.loc, PushLoc::Push { .. }), "{f:?}");
assert!(
matches!(f.field, PushField::SlotBindOffset(_)),
matches!(
f.field,
PushField::SlotBindOffset(_)
| PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_))
),
"unexpected push field {f:?}"
);
}
@@ -156,6 +156,8 @@ fn resources(plan: &Plan) -> Resources {
| PushField::Specialized(_),
PushLoc::Push { .. },
) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -136,6 +136,8 @@ fn run(
(PushField::TextureHalfChannels(_), PushLoc::Push { .. }) => {}
// A bound value read as data, which the interpreter writes from `spec`.
(PushField::Specialized(_), PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -136,7 +136,11 @@ fn push_bytes(plan: &Plan) -> Vec<u8> {
f.field
);
assert!(
matches!(f.field, PushField::SlotBindOffset(_)),
matches!(
f.field,
PushField::SlotBindOffset(_)
| PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_))
),
"{:?}",
f.field
);
@@ -451,6 +451,8 @@ fn push_bytes(plan: &Plan) -> Vec<u8> {
}
// A zero residual (every slot is bound at its start), and a single region.
PushField::SlotBindOffset(_) | PushField::DispatchRegion => {}
// No slot's writes dropped: the word stays 0.
PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -201,6 +201,8 @@ pub(super) fn resources(plan: &Plan, lanes: &[[u32; 4]], bytes: usize, class: u3
(PushField::SlotBindOffset(_) | PushField::DispatchRegion, PushLoc::Push { .. }) => {}
// A bound value read as data, which the interpreter writes from `spec`.
(PushField::Specialized(_), PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -324,6 +324,8 @@ fn resources(plan: &Plan, init: &[Vec<u8>], class: u32) -> Resources {
(PushField::SlotBindOffset(_) | PushField::DispatchRegion, PushLoc::Push { .. }) => {}
// A bound value read as data, which the interpreter writes from `spec`.
(PushField::Specialized(_), PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -223,7 +223,11 @@ fn resources(plan: &Plan, threads: u32, init: &[Vec<u8>]) -> Resources {
matches!(
(f.field, f.loc),
(
PushField::SlotBindOffset(_) | PushField::DispatchRegion,
PushField::SlotBindOffset(_)
| PushField::DispatchRegion
| PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(
_
)),
PushLoc::Push { .. }
)
),
@@ -497,7 +497,11 @@ fn run_fixture(bc: &[u8], entry: &str, stem: &str, threads: u32, per_thread: u32
matches!(
(f.field, f.loc),
(
PushField::SlotBindOffset(_) | PushField::DispatchRegion,
PushField::SlotBindOffset(_)
| PushField::DispatchRegion
| PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(
_
)),
PushLoc::Push { .. }
)
),
@@ -213,6 +213,8 @@ fn resources(plan: &Plan, init: &[Vec<u8>]) -> Resources {
for f in &plan.push.fields {
match (f.field, f.loc) {
(PushField::SlotBindOffset(_) | PushField::DispatchRegion, PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -183,6 +183,8 @@ fn resources(plan: &Plan, bytes: Vec<u8>) -> Resources {
}
// A single-region dispatch: the region is unused.
(PushField::DispatchRegion, PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -134,6 +134,8 @@ fn resources(plan: &Plan, bufs: &[Vec<u32>]) -> Resources {
let base = 0x1_0000_0000u64 + u64::from(slot.index) * 0x10_0000;
push[offset as usize..offset as usize + 8].copy_from_slice(&base.to_le_bytes())
}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -301,6 +301,8 @@ fn resources_bound(plan: &Plan, mem: &Memory, threads: u32, binds: &[Bind]) -> (
};
push[at..at + 8].copy_from_slice(&guest.to_le_bytes())
}
// No slot's writes dropped: the word stays 0.
PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -225,6 +225,8 @@ fn resources(
assert_eq!(f.size, 8, "a guest base is eight bytes");
push[at..at + 8].copy_from_slice(&guest(s.index as usize).to_le_bytes())
}
// No slot's writes dropped: the word stays 0.
PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -273,6 +273,8 @@ fn resources(plan: &Plan, buffer: Vec<u8>) -> Resources {
(PushField::SlotBindOffset(_) | PushField::DispatchRegion, PushLoc::Push { .. }) => {}
// A bound value read as data, which the interpreter writes from `spec`.
(PushField::Specialized(_), PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -233,6 +233,8 @@ fn resources(plan: &Plan, init: &[Vec<u8>]) -> Resources {
(PushField::SlotBindOffset(_) | PushField::DispatchRegion, PushLoc::Push { .. }) => {}
// A bound value read as data, which the interpreter writes from `spec`.
(PushField::Specialized(_), PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -320,6 +320,8 @@ fn resources(plan: &Plan, init: &[Vec<u8>], spec: &[(SpecKey, u64)]) -> Resource
(PushField::SlotBindOffset(_) | PushField::DispatchRegion, PushLoc::Push { .. }) => {}
// A bound value read as data, which the interpreter writes from `spec`.
(PushField::Specialized(_), PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
+5 -1
View File
@@ -94,7 +94,11 @@ fn run_all(plan: &Plan, m: &TypedModule, local: [u32; 3], lanes: SubgroupSize) -
assert!(matches!(f.loc, PushLoc::Push { .. }), "{f:?}");
// A zero residual: buffer 0 is bound at its start.
assert!(
matches!(f.field, PushField::SlotBindOffset(_)),
matches!(
f.field,
PushField::SlotBindOffset(_)
| PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_))
),
"unexpected push field {f:?}"
);
}
@@ -121,7 +121,11 @@ fn run_all(
assert!(matches!(f.loc, PushLoc::Push { .. }), "{f:?}");
// Zero residuals: each buffer is bound at its start.
assert!(
matches!(f.field, PushField::SlotBindOffset(_)),
matches!(
f.field,
PushField::SlotBindOffset(_)
| PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_))
),
"unexpected push field {f:?}"
);
}
@@ -323,7 +323,9 @@ fn run_all(
assert!(
matches!(
f.field,
PushField::SlotBindOffset(_) | PushField::DispatchRegion
PushField::SlotBindOffset(_)
| PushField::DispatchRegion
| PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_))
),
"unexpected push field {f:?}"
);
@@ -212,7 +212,9 @@ fn run_all(
assert!(
matches!(
f.field,
PushField::SlotBindOffset(_) | PushField::DispatchRegion
PushField::SlotBindOffset(_)
| PushField::DispatchRegion
| PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_))
),
"unexpected push field {f:?}"
);
@@ -89,13 +89,22 @@ fn check_artifact(a: &FunctionArtifact, what: &str) {
i.push.fields.iter().map(|f| (f.field, f.loc)).collect();
assert_eq!(
placed,
vec![(
PushField::SlotBindOffset(buffer0()),
PushLoc::Push { offset: 0 }
)],
vec![
(
PushField::SlotBindOffset(buffer0()),
PushLoc::Push { offset: 0 }
),
// The kernel stores through the slot, so it reads the stage's dropped-store word.
(
PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(
crate::pipeline::sym::Stage::Kernel
)),
PushLoc::Push { offset: 4 }
),
],
"{what}"
);
assert_eq!(i.push.push_range, Some((0, 4)), "{what}");
assert_eq!(i.push.push_range, Some((0, 8)), "{what}");
assert_eq!(i.push.argument_table_size, 0, "{what}");
assert_eq!(
i.descriptors,
@@ -177,18 +186,34 @@ fn containment_without_robustness_guards_the_store() {
desc.features.remove(&VkFeature::RobustBufferAccess2);
let dev = Device::new(desc, DevicePolicy::default()).expect("device");
let p = dev.profile();
let merges = |words: &[u32]| {
opcodes(words)
.iter()
.filter(|op| **op == crate::spv::Op::SelectionMerge as u32)
.count()
};
let a = compile(&bitcode, "store_const", p).expect("compile");
assert!(a.strategies.entries.contains_key("access.store.checked"));
let (_, words) = link_and_validate(&a, p).unwrap_or_else(|e| panic!("{e}"));
let ops = opcodes(&words);
assert!(ops.contains(&(crate::spv::Op::ArrayLength as u32)));
assert!(ops.contains(&(crate::spv::Op::SelectionMerge as u32)));
// One selection: `store_one` ands the containment check into the dropped-store guard's
// condition, so the store runs in one `if`.
assert_eq!(merges(&words), 1);
let robust = profile("vk12-floor", DevicePolicy::default()).expect("profile");
let bare = compile(&bitcode, "store_const", &robust).expect("compile");
assert!(bare.strategies.entries.contains_key("access.store"));
let (_, words) = link_and_validate(&bare, &robust).unwrap_or_else(|e| panic!("{e}"));
assert!(
!opcodes(&words).contains(&(crate::spv::Op::SelectionMerge as u32)),
"no selection with robustness"
!opcodes(&words).contains(&(crate::spv::Op::ArrayLength as u32)),
"no bound read with robustness"
);
// The store's one selection with robustness is the dropped-store guard, which every store
// runs in whatever the profile (`SpecKey::DroppedStoreSlots`): no containment selection.
assert_eq!(
merges(&words),
1,
"only the dropped-store guard's selection"
);
}
@@ -101,6 +101,8 @@ fn resources(plan: &Plan, init: &[Vec<u8>]) -> Resources {
(PushField::SlotBindOffset(_) | PushField::DispatchRegion, PushLoc::Push { .. }) => {}
// A bound value read as data, which the interpreter writes from `spec`.
(PushField::Specialized(_), PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -68,6 +68,11 @@ fn texel_formats_are_push_fields_and_other_bound_values_specializations() {
}
for f in &a.interface.push.fields {
if let PushField::Specialized(key) = f.field {
// A kernel that stores through a buffer slot also pushes the stage's
// dropped-store word, which no pipeline's key carries either.
if matches!(key, SpecKey::DroppedStoreSlots(_)) {
continue;
}
assert!(
matches!(key, SpecKey::TexelFormat(_)),
"{what}: a pushed {key:?}"
@@ -362,6 +362,8 @@ fn resources(plan: &Plan, bytes: usize) -> Resources {
(PushField::SlotBindOffset(_) | PushField::DispatchRegion, PushLoc::Push { .. }) => {}
// A bound value read as data, which the interpreter writes from `spec`.
(PushField::Specialized(_), PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -385,6 +385,8 @@ fn resources(plan: &Plan, buffer: Vec<u8>, spec: &[(SpecKey, u64)]) -> Resources
(PushField::SlotBindOffset(_) | PushField::DispatchRegion, PushLoc::Push { .. }) => {}
// A bound value read as data, which the interpreter writes from `spec`.
(PushField::Specialized(_), PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -121,6 +121,8 @@ fn resources(plan: &Plan, init: &[Vec<u8>]) -> Resources {
// 0: no channel narrower than the written word, every integer lane as written (the
// interpreter's images hold words; the kernels write in-range values).
(PushField::TextureIntegerChannels(_), PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -204,6 +204,8 @@ fn push_bytes(plan: &Plan, levels: &[(u32, u32)]) -> Vec<u8> {
(PushField::TextureHalfChannels(_), PushLoc::Push { .. }) => {}
// A bound value read as data, which the interpreter writes from `spec`.
(PushField::Specialized(_), PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -1220,6 +1220,8 @@ fn resources(plan: &Plan, p: &[[u32; 4]], out: usize) -> Resources {
// 0: no channel narrower than the written word, every integer lane as written (the
// interpreter's images hold words; the kernels write in-range values).
(PushField::TextureIntegerChannels(_), PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -96,6 +96,8 @@ fn resources(plan: &Plan, init: &[Vec<u8>]) -> Resources {
(PushField::SlotBindOffset(_) | PushField::DispatchRegion, PushLoc::Push { .. }) => {}
// A bound value read as data, which the interpreter writes from `spec`.
(PushField::Specialized(_), PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -169,6 +169,8 @@ fn resources(plan: &Plan, out: usize) -> Resources {
(PushField::SlotBindOffset(_) | PushField::DispatchRegion, PushLoc::Push { .. }) => {}
// A bound value read as data, which the interpreter writes from `spec`.
(PushField::Specialized(_), PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -99,6 +99,8 @@ fn resources(plan: &Plan, init: &[Vec<u8>]) -> Resources {
(PushField::SlotBindOffset(_) | PushField::DispatchRegion, PushLoc::Push { .. }) => {}
// A bound value read as data, which the interpreter writes from `spec`.
(PushField::Specialized(_), PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -228,6 +228,8 @@ fn run_images(
spec.insert(SpecKey::MultiRegion, 1);
}
}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -671,6 +673,8 @@ fn run_memory(
match (f.field, f.loc) {
// One region, every buffer bound at its start.
(PushField::SlotBindOffset(_) | PushField::DispatchRegion, PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -108,6 +108,8 @@ fn resources(plan: &Plan, local: (u64, u64), bufs: &[Vec<u32>]) -> Resources {
(PushField::SlotBindOffset(_), PushLoc::Push { offset }) => {
push[offset as usize..offset as usize + 4].fill(0)
}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -137,6 +137,8 @@ fn resources(plan: &Plan) -> Resources {
(PushField::SlotBindOffset(_), PushLoc::Push { offset }) => {
push[offset as usize..offset as usize + 4].fill(0)
}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -567,6 +567,10 @@ fn capture_push(plan: &Plan, run: &IndexedRun<'_>, index_address: u64, stride: u
PushField::RootTableAddress => TABLE.to_le_bytes().to_vec(),
PushField::SlotBindOffset(_) => vec![0; 4],
PushField::VertexBufferStride(_) => stride.to_le_bytes().to_vec(),
// No slot's writes dropped: the word stays 0.
PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)) => {
vec![0; 4]
}
other => panic!("unexpected push field {other:?}"),
};
out[at..at + bytes.len()].copy_from_slice(&bytes);
@@ -738,6 +742,10 @@ fn an_indexed_capture_reads_each_vertex_from_its_index() {
.iter()
.flat_map(|w| w.to_le_bytes())
.collect(),
// No slot's writes dropped: the word stays 0.
PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)) => {
vec![0; 4]
}
other => panic!("{what}: unexpected push field {other:?}"),
};
push[at..at + bytes.len()].copy_from_slice(&bytes);
@@ -1022,6 +1022,8 @@ fn push_bytes(plan: &Plan) -> Vec<u8> {
out[at..at + 4].copy_from_slice(&STRIDE.to_le_bytes())
}
PushField::RootTableAddress => out[at..at + 8].copy_from_slice(&TABLE.to_le_bytes()),
// No slot's writes dropped: the word stays 0.
PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -134,6 +134,8 @@ fn resources(plan: &Plan, bufs: &[Vec<u32>]) -> Resources {
(PushField::SlotBindOffset(_), PushLoc::Push { offset }) => {
push[offset as usize..offset as usize + 4].fill(0)
}
// No slot's writes dropped: the word stays 0.
(PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)), _) => {}
other => panic!("unexpected push field {other:?}"),
}
}
@@ -304,6 +304,11 @@ impl Execute for CpuInterp {
// A single-region dispatch: `SpecKey::MultiRegion` keeps its default 0, so the
// region words are never read.
(PushField::DispatchRegion, PushLoc::Push { .. }) => {}
// No slot's writes dropped: the word stays 0.
(
PushField::Specialized(crate::pipeline::sym::SpecKey::DroppedStoreSlots(_)),
_,
) => {}
other => return Err(format!("unexpected push field {other:?}")),
}
}
+1
View File
@@ -43,6 +43,7 @@ mod engine_device_replay;
mod engine_dispatch;
mod engine_divergent_barriers;
mod engine_draw_bases;
mod engine_dropped_stores;
mod engine_dynamic_libraries;
mod engine_dynamic_roots;
mod engine_extended_range;
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+23
View File
@@ -284,6 +284,29 @@ recorded here.
Open differences from Metal that no note announces yet, and runtime costs still above the
driver's. Each is open work.
- **GPU writes into read-only memory are dropped only through a bound buffer slot.** A shader's
stores through a slot bound to memory whose GPU writes Metal drops (no-copy memory of its private
option bit 24, or pages replaced read-only) are now dropped in the shader, gated on a uniform
per-draw and per-dispatch word (`SpecKey::DroppedStoreSlots`). Four shapes stay open. A store
through an address loaded out of an argument buffer or a pointer names no slot and no bit, so the
word does not reach it; an atomic is not gated, because what Metal's atomics do to such memory is
unmeasured; a blit fill and a visibility result are not a shader's stores and the runtime does not
drop them; and a render pass's own store-out over such memory must instead end its command buffer
in error (`MTLCommandBufferErrorDomain` / `kIOGPUCommandBufferCallbackErrorPageFault`), which the
runtime does not do. That last one is the store-out alone, measured on an M3 Max under macOS
27.0.1: a colour, depth, stencil or combined attachment over such memory at
`storeAction = DontCare` completes with its draw's own values, and `loadAction = Load` completes
too, so those shapes are ours to keep rather than refuse; the same attachments at
`storeAction = Store` fault, as does storing a multisample primary into such memory. Resolving
*into* such memory is unknown — no page fault in 520 processes, but almost all of them were
recovery victims, so the cell has no denominator — and nothing is built for it. On macOS the
import's read-only view of the pages keeps all of those out of the pages anyway, so the open
shapes are off macOS, where the import is of the
caller's own pages and the word is never set: making it set there means honouring bit 24 without
a read-only view (`Device::no_copy_options`, `host_lie`'s `drops_writes`) and measuring what the
drivers then do, since ANV lost the device and RADV failed every submission over read-only
imported pages. Announced meanwhile as `private-resource-option` and `read-only-pages-written`.
- **A function linked from a module that declares function constants** is refused
(`Unsupported{Linking; NotImplemented}` at a surviving call to the stub, `canon::link`), keyed on
the module declaring any constant at all. Metal is narrower: it refuses only an *unresolved*