Push placement: on the floor each stage's push ends with its tail, 24 bytes above its other fields

A driver that uploads a stage's push bytes up to the highest one the stage reads, and widens a
push load past its last byte by up to 28 bytes, read past the upload where a stage's last field
ended its push (RADV: 49 compute stages at tip). A read pinned past the fields (R7) cost the
stages a driver holds whole in registers those registers: the pin raised the used-word count past
the driver's limit (RADV keeps all 16 words of the harness's lcg_step in user SGPRs at tip, none
under R7). The tail adds no read where the stage has a field of a tail kind, and moves one.

- lower/push.rs: on PushWindow::Floor, place() lays the longest prefix of the kind order that
  fits with its tail: the highest field of a tail kind (SlotBounds or ZeroAddress, the two kinds
  whose value the consumer never pushes with every bit set) moves HOLE_BYTES (24) above the other
  pushed fields' end; where the pushed fields hold no tail kind, the zero tail word
  (PushField::TailWord at PushPlacement::tail_word) takes that place, with which push_range ends.
  One pushed field of one or two words has no tail. The guaranteed window is packed as before.
- tail(), check_floor(): the structural tail and the floor's bound, which select checks on every
  placement as an invariant error.
- emit: the stage reads its tail in its first block and returns where it holds the value the
  consumer never pushes there (emit_tail_guard): the word non-zero, bounds with both words all
  ones, the zero range's address all ones.
- PushPlacement::tail_word (public, serde default, codec), PushField::TailWord (codec, API
  table); SEMANTICS_VERSION 2201, ARTIFACT_FORMAT_VERSION 556; the old render descriptor key
  re-pinned at 2201.
- Tests: push.rs's floor placements at their tails, the bound's refusals; engine_identity's
  31-slot kernel spills 4 addresses to its block; engine_identity_render's vertex range ends at
  64. Docs: API.md section 5 (the tail and what the consumer pushes), rt README (24 addresses
  below the tail), the profile's window doc.

Verified at 855d973a38 (this change before development's c39f6e8350 and 1de18aa609, which
touch no translator file), m3-max-58299 on msi: the metal2vulkan and metal2vulkan-rt suites
3911 of 3911 passed; the old-path pins (golden hashes over Device::new and the old render key)
pass. Clippy failed there on four indexing lints in push.rs, fixed here with get().
RADV dump (m3-max-58310, Radeon 780M, Mesa 26.2.6): lcg_step keeps the same 16 push words in
user SGPRs with no push pointer, plus a 3-instruction scalar guard; the 18-word kernel keeps its
two loads (+0x20, 32 bytes; the second now at +0x58).
This commit is contained in:
Anees Iqbal committed 2026-11-20 05:17:29 -08:00
1 parent a507907bd8
commit 0cd2ad765d
16 files changed
+544 -96

No files matched your search

+4 -4
View File
@@ -1871,9 +1871,9 @@ while the driver's exit handler waited on a lock, with every runtime thread alre
API validation refuses the bind offset. Plain Metal runs such a dispatch at addresses of its
own; `docs/API.md` section 10 says which.
- Parameters: fields in the push window, `[0, 256)` on every device, are pushed: the dispatch
region and up to 28 buffer addresses, each kernel pushing only the bytes it reads. Fields past it
go to a 16-byte aligned block in the parameter ring, whose address is a field in the window: a
kernel with more than 28 buffers. `Counters::metrics`' `ring_writes` counts each block and each
region and up to 24 buffer addresses below the kernel's tail (`docs/API.md` section 5), each
kernel pushing only the bytes it reads. Fields past it go to a 16-byte aligned block in the
parameter ring, whose address is a field in the window: a kernel with more than 24 buffers. `Counters::metrics`' `ring_writes` counts each block and each
`set_bytes` copy.
`set_bytes` copies its bytes into the ring at the call, as Metal copies them. The ring is 2 MiB
blocks of the floor's ring memory type (device-local, host-visible, coherent), split into
@@ -3241,7 +3241,7 @@ A Boolean limit's minimum is 1,
| `maxSamplerAllocationCount` | `4000` | Vulkan's minimum: live samplers |
| `maxPerStageUpdateAfterBindResources` | `131072` | both texture arrays in one stage; a fragment stage needs its `maxColorAttachments` more |
| `maxUpdateAfterBindDescriptorsInAllPools` | `143072` | all five arrays |
| `maxPushConstantsSize` | `256` | per-command values: a compute kernel's dispatch region and 28 buffer addresses, anything larger in a block whose address is pushed; a render pipeline's vertex and fragment functions' values in the same 256 bytes, dense by link, anything larger in a block whose address is pushed |
| `maxPushConstantsSize` | `256` | per-command values: a compute kernel's dispatch region and 24 buffer addresses below its tail, anything larger in a block whose address is pushed; a render pipeline's vertex and fragment functions' values in the same 256 bytes, dense by link, anything larger in a block whose address is pushed |
| `maxComputeWorkGroupInvocations` | `1024` | Metal's most threads per threadgroup |
| `maxComputeWorkGroupSize[0]` | `1024` | a threadgroup's width |
| `maxComputeWorkGroupSize[1]` | `1024` | a threadgroup's height |
+2 -1
View File
@@ -927,6 +927,7 @@ codec_enum! {
SlotBounds(f0),
ZeroAddress,
FetchedColor { color, texels },
TailWord,
}
Symbol { Binding(f0), DescriptorSet(f0), Location(f0), Component(f0), SpecId(f0) }
}
@@ -1169,7 +1170,7 @@ codec_struct! {
AccessSet { read, write }
StageDescriptor { slot, ty, count }
StageSpec { key, size, default, unread_bits }
PushPlacement { stage, fields, push_range, argument_table_size }
PushPlacement { stage, fields, push_range, argument_table_size, tail_word }
PlacedField { field, loc, size }
ThreadgroupArgument { stage, index, alignment }
StageIo {
+2 -2
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 = 2200;
pub const SEMANTICS_VERSION: u32 = 2201;
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
@@ -72,7 +72,7 @@ pub const SEMANTICS_VERSION: u32 = 2200;
/// re-typed in an encoded type, its `codec` body or its `envelope`. A variant removed while its tag
/// stays unused needs no bump: an entry holding it fails to decode, which is a miss. The commit that
/// bumps it says what changed; this comment keeps no history.
pub const ARTIFACT_FORMAT_VERSION: u32 = 555;
pub const ARTIFACT_FORMAT_VERSION: u32 = 556;
/// The version of what this crate's runtime does with a compiled pipeline: instantiating a binding
/// plan (`BindingPlan::instantiate_*`: descriptor ranges, push bytes, root, argument, and handle
+2 -1
View File
@@ -688,7 +688,8 @@ pub(crate) enum PushWindow {
/// 128 bytes, what Vulkan guarantees (`maxPushConstantsSize`): `Device::new`'s profile.
Guaranteed,
/// 256 bytes, the new runtime's floor for `maxPushConstantsSize`, which every captured device
/// reports: a dispatch region and 28 buffer addresses. `Device::from_queries`' profile.
/// reports: a dispatch region and 24 buffer addresses below a stage's tail
/// (`lower::push::tail`). `Device::from_queries`' profile.
Floor,
}
+22
View File
@@ -143,6 +143,10 @@ fn declare(mb: &mut ModuleBuilder, plan: &Plan) -> BResult<Declared> {
};
d.push.push(mb.push_member(f.field, ty, offset)?);
}
// The floor's tail word, above every placed field (`PushPlacement::tail_word`).
if let Some(at) = plan.push.tail_word {
d.push.push(mb.push_member(PushField::TailWord, u32_, at)?);
}
if !d.push.is_empty() {
d.push_global = Some(mb.push_global()?);
}
@@ -462,6 +466,22 @@ impl<'a> EmitCx<'a> {
Ok(())
}
/// Where the plan's placement ends with a tail (`lower::push::tail`): read it from the push
/// block, and return where it holds the value the consumer never pushes there
/// ([`crate::lower::push::emit_tail_guard`]).
fn emit_tail_guard(&mut self, fb: &mut FunctionBuilder<'_>) -> BResult<()> {
let Some(field) = crate::lower::push::tail(&self.plan.push) else {
return Ok(());
};
let member = (self.decl.push.iter()).find(|m| m.field == field);
match (member, self.decl.push_global) {
(Some(member), Some(push)) => {
crate::lower::push::emit_tail_guard(fb, push, member.index, field)
}
_ => Err(self.fail("a placed tail the push block does not hold")),
}
}
/// Checked slot `slot`'s bounds (`PushField::SlotBounds`), split: its buffer's bytes before
/// the bind offset and its length, each a `u32`, where they dominate the open block.
/// [`EmitCx::load_push_fields`] splits them in the function's first block, so a checked
@@ -1462,6 +1482,8 @@ pub fn emit_module(e: &Entry, plan: &Plan, m: &mut Meter) -> Result<Emitted, Err
// the other hooks emit, where every invocation of the simdgroup is active.
let r = crate::lower::simd::emit_entry(&mut em.cx, &mut fb)
.and_then(|()| em.cx.load_push_fields(&mut fb))
// The floor's tail, read in the first block (`lower::push::emit_tail_guard`).
.and_then(|()| em.cx.emit_tail_guard(&mut fb))
// The bound values the function reads as data, right after their fields.
.and_then(|()| crate::lower::specialized::emit_entry(&mut em.cx, &mut fb))
.and_then(|()| dispatch::emit_entry(&mut em.cx, &mut fb))
+442 -65
View File
@@ -4,7 +4,7 @@
//! Vulkan guarantees `maxPushConstantsSize ≥ 128`, so those windows depend neither on the other
//! stage nor on the device. On a profile whose push window is the new runtime's floor
//! (`PushWindow::Floor`, `Device::from_queries`'), which requires `maxPushConstantsSize ≥ 256`, a
//! compute window is `[0, 256)` (a dispatch region and 28 buffer addresses), and a render
//! compute window is `[0, 256)` (a dispatch region and 24 buffer addresses below its tail), and a render
//! pipeline's two stages share one range `[0, 256)`, dense by link: the vertex function's fields
//! from 0, the fragment function's from its `LoweringInputs::push_base`, the vertex function's push
//! end, so only the fields the pair places take space (a four-byte field the fragment function
@@ -25,6 +25,18 @@
//! (`PushField::ArgumentTableAddress`) whenever its fields spill, and reads its spilled fields
//! from at the same offsets.
//!
//! On the floor each stage's pushed fields end with its tail ([`tail`]): its highest field of a
//! tail kind ([`tail_kind`], one or two words) moves above the others, [`HOLE_BYTES`] past their
//! end, or, where the pushed fields hold no tail kind, the zero word `PushField::TailWord` does
//! (`PushPlacement::tail_word`).
//! A driver that uploads a stage's push bytes up to the highest one it reads then uploads at least
//! 28 bytes past the other fields, which holds every load it widens from them, and the tail's own
//! load, one or two words, is never widened. The stage reads the tail in its first block and
//! returns where it holds a value the consumer never pushes there ([`emit_tail_guard`]), so no
//! optimizer drops the read. A stage that pushes one field of one or two words has no other load
//! to widen and no tail. The hole moves no field the stage reads and adds no read where the tail
//! is a field of its own, so the words a driver keeps in registers are the same.
//!
//! Field shapes are chosen so that the `ArgumentTable`'s std140 and std430 layouts agree (scalars,
//! 2-vectors, and 16-byte-strided arrays only), so the table is a valid uniform block on every
//! profile without `uniformBufferStandardLayout`.
@@ -67,6 +79,19 @@ pub const FLOOR_BYTES: u32 = 256;
/// of 8).
pub const VERTEX_FLOOR_END: u32 = FLOOR_BYTES - 8;
/// The bytes between the end of a floor stage's other pushed fields and its tail ([`tail`]). A
/// driver widens a push load past its last byte by at most 28 bytes, so a load from those fields
/// ends inside the tail's first word, and it never merges a load with one 24 bytes or more away.
pub const HOLE_BYTES: u32 = 24;
/// Whether a field of kind `field` can be a floor stage's tail: one or two words whose value the
/// consumer never pushes with every bit set, which the stage returns on ([`emit_tail_guard`]). A
/// slot's bounds hold a length of at most 2 GiB, and the zero range is at a multiple of 16
/// (`PushField::SlotBounds`, `PushField::ZeroAddress`).
pub const fn tail_kind(field: PushField) -> bool {
matches!(field, PushField::SlotBounds(_) | PushField::ZeroAddress)
}
/// The SPIR-V shape of a push field's value.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum FieldShape {
@@ -198,6 +223,8 @@ pub const fn shape(f: PushField) -> FieldShape {
// The whole indices from the bound index offset to the buffer's end, unsaturated:
// `firstIndex + indexCount` reaches `2^33`.
PushField::IndexCapacity => FieldShape::U64,
// The floor's tail word, pushed zero.
PushField::TailWord => FieldShape::U32,
}
}
@@ -206,7 +233,7 @@ fn align_up(v: u32, a: u32) -> u32 {
}
/// Place `fields` for `stage` in its push window on a profile whose push window is `w`, from a
/// fragment function's `base` there ([`window`]).
/// fragment function's `base` there ([`window`]): on the floor with its tail ([`tail`]).
pub fn place(
stage: Stage,
w: PushWindow,
@@ -214,22 +241,25 @@ pub fn place(
fields: &BTreeSet<PushField>,
) -> PushPlacement {
let (start, end) = window(stage, w, base);
let mut cursor = start;
let (pushed, offsets, word, push_end) = match w {
PushWindow::Guaranteed => {
let (n, offsets, push_end) = dense(start, end, fields);
(n, offsets, None, push_end)
}
PushWindow::Floor => floor(start, end, fields),
};
let mut table = 0u32;
let mut spilled = false;
let mut placed = Vec::with_capacity(fields.len());
// `BTreeSet` iterates in the derived `Ord`: exactly the kind order, then slot order.
for &field in fields {
for (i, &field) in fields.iter().enumerate() {
let sh = shape(field);
let at = align_up(cursor, sh.align());
let loc = if !spilled && at.saturating_add(sh.size()) <= end {
cursor = at + sh.size();
PushLoc::Push { offset: at }
} else {
spilled = true;
let off = align_up(table, sh.align());
table = off.saturating_add(sh.size());
PushLoc::ArgumentTable { offset: off }
let loc = match offsets.get(i) {
Some(&offset) if i < pushed => PushLoc::Push { offset },
_ => {
let off = align_up(table, sh.align());
table = off.saturating_add(sh.size());
PushLoc::ArgumentTable { offset: off }
}
};
placed.push(PlacedField {
field,
@@ -239,32 +269,230 @@ pub fn place(
}
PushPlacement {
stage,
push_range: (cursor > start).then_some((start, cursor - start)),
push_range: (push_end > start).then_some((start, push_end - start)),
argument_table_size: align_up(table, 16),
fields: placed,
tail_word: word,
}
}
/// How many of `fields`, a prefix of the kind order, `[start, end)` holds packed: each at the
/// next offset aligned to it, until the first that does not fit; their offsets, and their end.
/// Reads `fields` only up to that first one.
fn dense(start: u32, end: u32, fields: &BTreeSet<PushField>) -> (usize, Vec<u32>, u32) {
let mut cursor = start;
let mut offsets = Vec::new();
for &field in fields {
let sh = shape(field);
let at = align_up(cursor, sh.align());
if at.saturating_add(sh.size()) > end {
break;
}
cursor = at + sh.size();
offsets.push(at);
}
(offsets.len(), offsets, cursor)
}
/// The floor's placement of `fields` in `[start, end)`: the longest prefix of the kind order that
/// fits with its tail ([`tail_layout`]); how many it pushes, their offsets, the tail word's offset
/// where it takes one, and the push's end. The prefix the window holds packed bounds it: the hole
/// only takes room, so `fields` is read only up to the first field that does not fit packed.
fn floor(
start: u32,
end: u32,
fields: &BTreeSet<PushField>,
) -> (usize, Vec<u32>, Option<u32>, u32) {
let (most, _, _) = dense(start, end, fields);
let prefix: Vec<PushField> = fields.iter().copied().take(most).collect();
(0..=most)
.rev()
.find_map(|n| {
let pushed = prefix.get(..n)?;
tail_layout(start, end, pushed)
.map(|(offsets, word, push_end)| (n, offsets, word, push_end))
})
.unwrap_or((0, Vec::new(), None, start))
}
/// `pushed`, in kind order, laid out from `start` with its tail, where they fit by `end`: every
/// field but the highest of a tail kind packed in order, then that one [`HOLE_BYTES`] above their
/// end, or, where none is of a tail kind, the tail word there. One field of one or two words, or
/// none, is placed alone. The offsets by index in `pushed`, the tail word's, and the push's end.
fn tail_layout(start: u32, end: u32, pushed: &[PushField]) -> Option<(Vec<u32>, Option<u32>, u32)> {
match pushed {
[] => return Some((Vec::new(), None, start)),
[only] if shape(*only).size() <= 8 => {
let sh = shape(*only);
let at = align_up(start, sh.align());
return (at.saturating_add(sh.size()) <= end).then(|| (vec![at], None, at + sh.size()));
}
_ => {}
}
let tail = pushed.iter().rposition(|&f| tail_kind(f));
let mut offsets = Vec::with_capacity(pushed.len());
let mut cursor = start;
for (i, &field) in pushed.iter().enumerate() {
if Some(i) == tail {
// Its offset comes once the others' end is known.
offsets.push(0);
continue;
}
let sh = shape(field);
let at = align_up(cursor, sh.align());
offsets.push(at);
cursor = at + sh.size();
}
let top = tail.and_then(|i| pushed.get(i).copied());
let sh = shape(top.unwrap_or(PushField::TailWord));
let at = align_up(cursor.saturating_add(HOLE_BYTES), sh.align());
let push_end = at.saturating_add(sh.size());
if push_end > end {
return None;
}
let word = match tail.and_then(|i| offsets.get_mut(i)) {
Some(offset) => {
*offset = at;
None
}
None => Some(at),
};
Some((offsets, word, push_end))
}
/// Whether `stage`'s placement of `fields` spills into the `ArgumentTable`: whether [`place`]
/// gives it a size. That is the first field with a size that does not fit, so the fields are read
/// only up to it, at most the window's worth plus one, however many there are; a step that asks
/// once per slot it moves (`access::finish_slots`) then costs no walk of every slot's field.
pub fn spills(stage: Stage, w: PushWindow, base: u32, fields: &BTreeSet<PushField>) -> bool {
let (start, end) = window(stage, w, base);
let mut cursor = start;
let mut spilled = false;
for &field in fields {
let sh = shape(field);
let at = align_up(cursor, sh.align());
if !spilled && at.saturating_add(sh.size()) <= end {
cursor = at + sh.size();
} else if sh.size() > 0 {
return true;
} else {
spilled = true;
let pushed = match w {
PushWindow::Guaranteed => dense(start, end, fields).0,
PushWindow::Floor => floor(start, end, fields).0,
};
// Every shape has a size, so any field past the pushed ones gives the table one.
pushed < fields.len()
}
/// The tail of `placement` ([`place`] on the floor): its tail word (`PushField::TailWord`), or
/// its highest pushed field, where it lies at least [`HOLE_BYTES`] above every other pushed
/// field's end. A placement packed in the guaranteed window has none: no alignment there leaves
/// 24 bytes.
pub fn tail(placement: &PushPlacement) -> Option<PushField> {
let pushed = || {
(placement.fields.iter()).filter_map(|f| match f.loc {
PushLoc::Push { offset } => Some((f.field, offset, f.size)),
PushLoc::ArgumentTable { .. } => None,
})
};
let below = |skip: Option<PushField>| {
pushed()
.filter(|&(f, _, _)| Some(f) != skip)
.map(|(_, offset, size)| offset + size)
.max()
};
let (field, at, skip) = match placement.tail_word {
Some(at) => (PushField::TailWord, at, None),
None => {
let (field, at, _) = pushed().max_by_key(|&(_, offset, _)| offset)?;
(field, at, Some(field))
}
};
(at >= below(skip)? + HOLE_BYTES).then_some(field)
}
/// The floor's bound on `placement`, a stage's on a profile whose push window is `w`: on the
/// floor a stage that pushes more than one field, or one of more than two words, ends with its
/// tail ([`tail`]), a field of a tail kind or the tail word, of one or two words; its push range
/// ends with its highest pushed byte, by the floor's end; off the floor no stage pushes the tail
/// word. `Err` names the placement that passes it.
pub fn check_floor(w: PushWindow, placement: &PushPlacement) -> Result<(), String> {
let pushed: Vec<(PushField, u32, u32)> = (placement.fields.iter())
.filter_map(|f| match f.loc {
PushLoc::Push { offset } => Some((f.field, offset, f.size)),
PushLoc::ArgumentTable { .. } => None,
})
.collect();
let word = placement
.tail_word
.map(|at| at + shape(PushField::TailWord).size());
let top = (pushed.iter())
.map(|&(_, offset, size)| offset + size)
.chain(word)
.max();
let ok = match w {
PushWindow::Guaranteed => word.is_none(),
PushWindow::Floor => {
let single =
word.is_none() && matches!(pushed.as_slice(), [(_, _, size)] if *size <= 8);
let tailed = tail(placement).is_some_and(|t| {
(tail_kind(t) || t == PushField::TailWord) && shape(t).size() <= 8
});
let range = placement.push_range.map(|(offset, size)| offset + size);
(pushed.is_empty() || single || tailed)
&& range == top
&& top.is_none_or(|t| t <= FLOOR_BYTES)
}
};
match ok {
true => Ok(()),
false => Err(format!(
"{:?} push range {:?} with fields {pushed:?} and tail word {:?} passes the floor's \
tail bound",
placement.stage, placement.push_range, placement.tail_word
)),
}
false
}
/// In the open block of a function whose push block `push` holds the stage's tail `field` as
/// member `member` ([`tail`]): read it, and return from the function where it holds the value the
/// consumer never pushes there: the tail word non-zero, a two-word field with both words all
/// ones, an address all ones. The branch is never taken; the return keeps the read from any
/// optimizer, as everything the function does after it depends on it.
pub(crate) fn emit_tail_guard(
fb: &mut crate::spirv::builder::FunctionBuilder<'_>,
push: crate::spirv::ids::GlobalId,
member: u32,
field: PushField,
) -> crate::spirv::error::BResult<()> {
use crate::spirv::builder::constructs::{ArmEnd, ArmFn};
use crate::spirv::ir::{BinOp, ConstBits, Constant, MemAccess};
let base = fb.module().global_value(push)?;
let index = fb.u32_const(member)?;
let index = fb.module().const_value(index)?;
let ptr = fb.access_chain(base, &[index])?;
let value = fb.load(ptr, MemAccess::default())?;
let set = match (field, shape(field)) {
(PushField::TailWord, _) => {
let zero = fb.u32_const(0)?;
let zero = fb.module().const_value(zero)?;
fb.binary(BinOp::INotEqual, value, zero)?
}
(_, FieldShape::UVec2) => {
let low = fb.composite_extract(value, &[0])?;
let high = fb.composite_extract(value, &[1])?;
let both = fb.binary(BinOp::BitwiseAnd, low, high)?;
let ones = fb.u32_const(u32::MAX)?;
let ones = fb.module().const_value(ones)?;
fb.binary(BinOp::IEqual, both, ones)?
}
(_, FieldShape::U64) => {
let ty = fb.uint_ty(64)?;
let ones = fb.module().constant(Constant::Scalar {
ty,
bits: ConstBits(u64::MAX),
})?;
let ones = fb.module().const_value(ones)?;
fb.binary(BinOp::IEqual, value, ones)?
}
(_, FieldShape::U32 | FieldShape::UVec4Array(_)) => return Ok(()),
};
let leave: ArmFn<'_, ()> = Box::new(|fb, _| {
fb.ret(None)?;
Ok(ArmEnd::Exits)
});
fb.if_(&mut (), set, leave, None)?;
Ok(())
}
#[cfg(test)]
@@ -282,7 +510,9 @@ mod tests {
/// The placement invariants every field set satisfies: placement order, alignment, push fields
/// inside the window without overlap, the prefix property (nothing is pushed after the first
/// spill), and a push range and table size that cover their fields.
/// spill), and a push range and table size that cover their fields. On the floor the tail
/// ([`tail`]) lies above every other pushed field and the floor's bound holds
/// ([`check_floor`]); the guaranteed window has no tail.
fn check(stage: Stage, fields: &BTreeSet<PushField>) -> PushPlacement {
check_in(stage, PushWindow::Guaranteed, fields)
}
@@ -305,11 +535,22 @@ mod tests {
assert_eq!(p.stage, stage);
let order: Vec<PushField> = p.fields.iter().map(|f| f.field).collect();
assert_eq!(order, fields.iter().copied().collect::<Vec<_>>());
assert_eq!(check_floor(w, &p), Ok(()));
let top = tail(&p);
if w == PushWindow::Guaranteed {
assert_eq!(top, None);
}
let (mut push_end, mut table_end, mut spilled) = (start, 0u32, false);
let mut tail_end = p.tail_word.map(|at| (at, at + 4));
for f in &p.fields {
let sh = shape(f.field);
assert_eq!(f.size, sh.size());
match f.loc {
PushLoc::Push { offset } if Some(f.field) == top => {
assert_eq!(offset % sh.align(), 0);
assert!(offset + f.size <= end);
tail_end = Some((offset, offset + f.size));
}
PushLoc::Push { offset } => {
assert!(!spilled, "{:?} pushed after a spill", f.field);
assert_eq!(offset % sh.align(), 0);
@@ -324,6 +565,10 @@ mod tests {
}
}
}
if let Some((at, tail_end)) = tail_end {
assert!(at >= push_end + HOLE_BYTES, "the tail above the hole");
push_end = tail_end;
}
match p.push_range {
Some((off, size)) => {
assert_eq!(off, start);
@@ -416,11 +661,12 @@ mod tests {
}
/// A kernel's dispatch region and its buffers' addresses: 12 addresses fill the guaranteed
/// window and 28 the floor's, which places the first 12 as the guaranteed one does, and a 29th
/// spills; with a spill, the table's address and the region's alignment take the first 16
/// bytes, and 26 addresses stay in the window. The render windows are the same on both.
/// window. On the floor the addresses hold no tail kind, so the tail word ends the push, 24
/// bytes above them: 24 addresses end at 224 and the word at 252, and a 25th spills; with a
/// spill, the table's address and the region's alignment take the first 16 bytes, and 22
/// addresses stay in the window. The render windows are the same on both.
#[test]
fn the_floor_window_holds_a_region_and_twenty_eight_addresses() {
fn the_floor_window_holds_a_region_and_twenty_four_addresses_below_its_tail() {
let fields = |n: u32| -> BTreeSet<PushField> {
let mut f: BTreeSet<PushField> = (0..n)
.map(|i| PushField::SlotGuestBase(slot(Stage::Kernel, i)))
@@ -445,26 +691,25 @@ mod tests {
0,
&fields(13)
));
let floor = check_in(Stage::Kernel, PushWindow::Floor, &fields(28));
let floor = check_in(Stage::Kernel, PushWindow::Floor, &fields(24));
assert_eq!(
(floor.push_range, floor.argument_table_size),
(Some((0, 256)), 0)
(Some((0, 252)), 0)
);
assert_eq!(pushed(&floor), 29);
let same = check_in(Stage::Kernel, PushWindow::Floor, &fields(12));
assert_eq!(pushed(&floor), 25, "the region and 24 addresses");
assert_eq!(
same, guaranteed,
"within 128 bytes the two windows place alike"
(tail(&floor), floor.tail_word),
(Some(PushField::TailWord), Some(248))
);
assert!(spills(Stage::Kernel, PushWindow::Floor, 0, &fields(29)));
let mut spilled = fields(29);
assert!(spills(Stage::Kernel, PushWindow::Floor, 0, &fields(25)));
let mut spilled = fields(25);
spilled.insert(PushField::ArgumentTableAddress);
let p = check_in(Stage::Kernel, PushWindow::Floor, &spilled);
assert_eq!((p.push_range, p.argument_table_size), (Some((0, 256)), 32));
assert_eq!((p.push_range, p.argument_table_size), (Some((0, 252)), 32));
assert_eq!(
pushed(&p),
28,
"the address, the region and 26 buffer addresses"
(pushed(&p), p.tail_word),
(24, Some(248)),
"the address, the region and 22 buffer addresses"
);
for stage in [Stage::Object, Stage::Mesh] {
assert_eq!(
@@ -474,6 +719,134 @@ mod tests {
}
}
/// The floor's tail: a kernel's highest field of a tail kind moves 24 bytes above its other
/// fields, the rest packed as before; the tail word ends a push of no tail kind, and a single
/// field of one or two words has none. The same kernel on the guaranteed window is packed.
#[test]
fn the_floor_places_each_stage_s_tail_above_a_hole() {
let at = |p: &PushPlacement, field: PushField| {
(p.fields.iter())
.find(|f| f.field == field)
.map(|f| f.loc)
.expect("placed")
};
let (a, b) = (slot(Stage::Kernel, 0), slot(Stage::Kernel, 1));
// A region, two addresses, the zero range and one slot's bounds.
let mut fields: BTreeSet<PushField> = [
PushField::DispatchRegion,
PushField::SlotGuestBase(a),
PushField::SlotGuestBase(b),
PushField::ZeroAddress,
PushField::SlotBounds(a),
]
.into();
let packed = check_in(Stage::Kernel, PushWindow::Guaranteed, &fields);
assert_eq!(packed.push_range, Some((0, 64)));
let p = check_in(Stage::Kernel, PushWindow::Floor, &fields);
assert_eq!(tail(&p), Some(PushField::SlotBounds(a)));
assert_eq!(at(&p, PushField::ZeroAddress), PushLoc::Push { offset: 48 });
assert_eq!(
at(&p, PushField::SlotBounds(a)),
PushLoc::Push { offset: 80 }
);
assert_eq!(p.push_range, Some((0, 88)));
let words = |p: &PushPlacement| -> u32 {
(p.fields.iter())
.filter(|f| matches!(f.loc, PushLoc::Push { .. }))
.map(|f| f.size / 4)
.sum()
};
assert_eq!(words(&p), words(&packed), "no word added");
assert_eq!(p.tail_word, None);
// A second slot's bounds: the higher one is the tail, the first stays packed.
fields.insert(PushField::SlotBounds(b));
let p = check_in(Stage::Kernel, PushWindow::Floor, &fields);
assert_eq!(tail(&p), Some(PushField::SlotBounds(b)));
assert_eq!(
at(&p, PushField::SlotBounds(a)),
PushLoc::Push { offset: 56 }
);
assert_eq!(
at(&p, PushField::SlotBounds(b)),
PushLoc::Push { offset: 88 }
);
assert_eq!(p.push_range, Some((0, 96)));
// A region alone: the tail word, 24 bytes above it.
let region = check_in(
Stage::Kernel,
PushWindow::Floor,
&[PushField::DispatchRegion].into(),
);
assert_eq!(tail(&region), Some(PushField::TailWord));
assert_eq!(region.tail_word, Some(56));
assert_eq!(region.push_range, Some((0, 60)));
// One address alone: no tail.
let one = check_in(
Stage::Kernel,
PushWindow::Floor,
&[PushField::SlotGuestBase(a)].into(),
);
assert_eq!((tail(&one), one.push_range), (None, Some((0, 8))));
assert!(check_in(Stage::Kernel, PushWindow::Floor, &BTreeSet::new())
.fields
.is_empty());
}
/// The floor's bound, which `select` checks on every placement: a stage that pushes more than
/// one short field without a tail 24 bytes above the others, a long field on top, a range that
/// does not end with the highest pushed byte or passes 256, and the tail word off the floor are
/// refused.
#[test]
fn the_floor_refuses_a_placement_without_its_tail() {
let a = slot(Stage::Kernel, 0);
let fields: BTreeSet<PushField> = [
PushField::DispatchRegion,
PushField::SlotGuestBase(a),
PushField::SlotBounds(a),
]
.into();
let p = place(Stage::Kernel, PushWindow::Floor, 0, &fields);
assert_eq!(check_floor(PushWindow::Floor, &p), Ok(()));
let packed = place(Stage::Kernel, PushWindow::Guaranteed, 0, &fields);
assert_eq!(check_floor(PushWindow::Guaranteed, &packed), Ok(()));
assert!(check_floor(PushWindow::Floor, &packed).is_err(), "no hole");
let mut short = p.clone();
short.push_range = Some((0, 80));
assert!(
check_floor(PushWindow::Floor, &short).is_err(),
"a range that does not end with the tail"
);
let mut moved = p.clone();
for f in &mut moved.fields {
if f.field == PushField::SlotBounds(a) {
f.loc = PushLoc::Push { offset: 56 };
}
}
moved.push_range = Some((0, 64));
assert!(
check_floor(PushWindow::Floor, &moved).is_err(),
"a hole of 16"
);
let region = place(
Stage::Kernel,
PushWindow::Floor,
0,
&[PushField::DispatchRegion].into(),
);
assert_eq!(check_floor(PushWindow::Floor, &region), Ok(()));
assert!(check_floor(PushWindow::Guaranteed, &region).is_err());
let mut bare = region.clone();
bare.tail_word = None;
bare.push_range = Some((0, 32));
assert!(
check_floor(PushWindow::Floor, &bare).is_err(),
"a long field alone"
);
let mut past = region;
past.push_range = Some((0, 260));
assert!(check_floor(PushWindow::Floor, &past).is_err());
}
/// The windows a pipeline of each kind pushes, pinned: on the guaranteed window the fixed
/// ones, whatever a fragment function's base; on the floor a compute kernel's `[0, 256)`, and a
/// render pipeline's one range `[0, 256)`, the vertex function's from 0 and the fragment
@@ -500,48 +873,50 @@ mod tests {
}
/// On the floor a render pipeline's fields are dense by link: a fragment function placed from
/// the vertex function's push end starts there, its fields fill the rest of
/// the 256 bytes, and from the first that does not fit it spills. A vertex function's window
/// ends at 248, so a fragment function from its end can always push its block's address.
/// the vertex function's push end starts there, its fields fill the rest of the 256 bytes
/// below its own tail, and from the first that does not fit it spills. Each stage has its own
/// tail: here the addresses hold no tail kind, so each ends with the tail word. A vertex
/// function's window ends at 248, so a fragment function from its end can always push its
/// block's address.
#[test]
fn the_floor_places_a_fragment_function_from_its_base() {
let vertex: BTreeSet<PushField> = (0..3)
.map(|i| PushField::SlotGuestBase(slot(Stage::Vertex, i)))
.collect();
let v = check_at(Stage::Vertex, PushWindow::Floor, 0, &vertex);
assert_eq!(v.push_range, Some((0, 24)));
assert_eq!(v.push_range, Some((0, 52)), "the tail word at 48");
let fragment = |n: u32| -> BTreeSet<PushField> {
(0..n)
.map(|i| PushField::SlotGuestBase(slot(Stage::Fragment, i)))
.collect()
};
let f = check_at(Stage::Fragment, PushWindow::Floor, 24, &fragment(2));
assert_eq!(f.push_range, Some((24, 16)));
let full = check_at(Stage::Fragment, PushWindow::Floor, 24, &fragment(29));
assert_eq!(full.push_range, Some((24, 232)), "to the floor's end");
let f = check_at(Stage::Fragment, PushWindow::Floor, 52, &fragment(2));
assert_eq!(
f.push_range,
Some((52, 48)),
"two addresses from 56, the word at 96"
);
let full = check_at(Stage::Fragment, PushWindow::Floor, 24, &fragment(25));
assert_eq!(full.push_range, Some((24, 228)), "to the word at 248");
assert_eq!(full.argument_table_size, 0);
assert!(spills(
Stage::Fragment,
PushWindow::Floor,
24,
&fragment(30)
&fragment(26)
));
// A vertex function's window ends at 248: 31 addresses fill it, and a 32nd spills.
// A vertex function's window ends at 248: 27 addresses end at 216 below the word at 240,
// and a 28th spills.
let wide = |n: u32| -> BTreeSet<PushField> {
(0..n)
.map(|i| PushField::SlotGuestBase(slot(Stage::Vertex, i)))
.collect()
};
let v = check_at(Stage::Vertex, PushWindow::Floor, 0, &wide(31));
assert_eq!((v.push_range, v.argument_table_size), (Some((0, 248)), 0));
assert!(spills(Stage::Vertex, PushWindow::Floor, 0, &wide(32)));
// Fields that would reach 252, 4 bytes into what was the fragment function's, spill.
let mut past = wide(31);
past.insert(PushField::VertexBufferStride(0));
assert!(spills(Stage::Vertex, PushWindow::Floor, 0, &past));
// The fragment function from the fullest vertex function's end pushes its block's
// address there, at 248, and spills the rest; from an end of 244 (a base rounded to 4)
// the address, 8-aligned, is still at 248.
let v = check_at(Stage::Vertex, PushWindow::Floor, 0, &wide(27));
assert_eq!((v.push_range, v.argument_table_size), (Some((0, 244)), 0));
assert!(spills(Stage::Vertex, PushWindow::Floor, 0, &wide(28)));
// The fragment function from the fullest vertex function's end, 244, pushes its block's
// address, 8-aligned, at 248, alone, and spills the rest; from 248 the same.
let mut spilled = fragment(2);
spilled.insert(PushField::ArgumentTableAddress);
for (base, range) in [(248, (248, 8)), (244, (244, 12))] {
@@ -590,6 +965,8 @@ mod tests {
class: SlotClass::Texture,
index: i,
})),
PushField::ZeroAddress,
PushField::SlotBounds(slot(stage, i)),
]
};
let mut state = 0x2545_f491_4f6c_dd1du64;
@@ -605,7 +982,7 @@ mod tests {
state ^= state << 17;
let n = (state % 40) as u32;
for i in 0..n {
let pick = ((state >> (i % 50)) % 8) as usize;
let pick = ((state >> (i % 50)) % 10) as usize;
fields.insert(kinds(stage, i % 31)[pick]);
}
check_in(stage, w, &fields);
+4
View File
@@ -1687,6 +1687,10 @@ fn finish(
&cx.push,
);
access::accept_placement(&cx, &placement)?;
// On the floor every stage that pushes more than one short field ends with its tail, a hole
// above the others, so every load a driver widens from them stays inside its upload.
push::check_floor(cx.profile.push_window(), &placement)
.map_err(|detail| Error::Internal(InternalError::new(InternalKind::Invariant, detail)))?;
// A kernel compiled for dispatches with a partial simdgroup emulates its simdgroups whatever
// tier the profile's subgroups give them, and depends on that variant. A kernel whose lockstep
@@ -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, "383cb53de9ee2eb1bd58f4e716b6efedb0f03d6960d68d2be3fd70d4fc19bbbc",
hex, "7db91256cad4f906a76cb491703c77a1a5d26767149739c836ff0d626da9715e",
"the old runtime's key of the descriptor"
);
}
@@ -1089,6 +1089,12 @@ pub struct PushPlacement {
/// Under the identity domains it is the size of the parameter block at
/// `PushField::ArgumentTableAddress`, which no descriptor binds.
pub argument_table_size: u32,
/// On `Device::from_queries`' profile, where a stage whose pushed fields include no tail kind
/// reads its tail word (`PushField::TailWord`, 4 bytes at this offset, 24 bytes or more above
/// its fields, with which `push_range` ends): the consumer pushes it zero with the fields.
/// `None` for any other stage, and on any other profile.
#[cfg_attr(feature = "serde", serde(default))]
pub tail_word: Option<u32>,
}
impl PushPlacement {
@@ -219,6 +219,7 @@ impl ControlPlan {
.collect(),
push_range: Some((push_offset, self.push_bytes().0)),
argument_table_size: 0,
tail_word: None,
})
}
+12 -2
View File
@@ -1301,7 +1301,8 @@ pub enum PushField {
/// Under the identity domains, the device address (`u64`) of 16 bytes of zeros, at a multiple
/// of 16, that nothing writes: a load of a buffer slot checked against its `SlotBounds`
/// reads each of its units there where the check fails, so it reads zero (`docs/API.md`,
/// section 5).
/// section 5). Being a multiple of 16 it is never `u64::MAX`, the value a floor stage whose
/// tail it is returns on (`lower::push::emit_tail_guard`).
ZeroAddress,
/// Under the identity domains, a buffer slot's buffer (`uvec2`): the bytes of the buffer before
/// the slot's bind offset (the bind offset), then the buffer's length; for a `set*Bytes` copy 0
@@ -1309,8 +1310,17 @@ pub enum PushField {
/// from the bind offset, read as signed, that is not a translation-time constant is checked
/// against the buffer, `(len >= n) && (m + before <= len - n)` in `u32`, as `m + before <
/// len - min(len, n - 1)` with the limit made once per slot and size: outside, a load reads
/// zero at `ZeroAddress` and a store or atomic runs nothing (`docs/API.md`, section 5).
/// zero at `ZeroAddress` and a store or atomic runs nothing (`docs/API.md`, section 5). A
/// buffer is at most 2 GiB, so the length is never `u32::MAX`: a floor stage whose tail it is
/// returns where both words are all ones (`lower::push::emit_tail_guard`), which the consumer
/// never pushes.
SlotBounds(SlotRef),
/// On `Device::from_queries`' profile (`PushWindow::Floor`), the zero word (`u32`) a stage
/// whose pushed fields include no tail kind (`lower::push::tail_kind`) pushes as its tail,
/// `lower::push::HOLE_BYTES` above them, and returns where it is non-zero: the consumer pushes
/// it zero with the stage's other fields, so the branch is never taken. No placement lists it
/// among its fields: it is the push-block member at `PushPlacement::tail_word`.
TailWord,
}
/// A relocatable literal: which decoration operand the serializer reserved, and for what.
@@ -376,6 +376,15 @@ pub struct Resources {
fn specialized_push(m: &TypedModule, spec: &BTreeMap<SpecKey, u64>, mut push: Vec<u8>) -> Vec<u8> {
use crate::pipeline::sym::PushField;
for member in m.push_members() {
// The floor's tail word, which a runtime pushes zero.
if member.field == PushField::TailWord {
let end = member.offset as usize + 4;
if push.len() < end {
push.resize(end, 0);
}
push[end - 4..end].fill(0);
continue;
}
let PushField::Specialized(key) = member.field else {
continue;
};
@@ -9,7 +9,9 @@
//! (`ArgumentTableAddress`), the addresses that fit after it, and reads the rest from the block
//! at their placed offsets, with no descriptor; it passes L3 and computes its answer on the CPU
//! interpreter. On `Device::from_queries`' profile, whose kernel window is 256 bytes, the same
//! kernel pushes all 21 addresses with no block, and one of 31 slots, Metal's most, all 31.
//! kernel pushes all 21 addresses with no block, below its tail word; one of 31 slots, Metal's
//! most, pushes its block's address and 27 slot addresses below the tail word at 248, and reads
//! the other 4 from the block.
//! - A kernel that reads grid builtins (`grid`, generated) declares no `MultiRegion` constant and
//! reads Metal's grid from its pushed `DispatchRegion` on every dispatch: whole, split in two
//! pieces at a base, and indirect (a zero grid, its grid `NumWorkgroups · L`) store the same
@@ -1526,11 +1528,13 @@ fn slot_addresses_past_the_window_are_read_from_the_pushed_parameter_block() {
}
/// On `Device::from_queries`' profile a kernel's push window is 256 bytes (`PushWindow::Floor`):
/// the same kernel's 21 slot addresses are all pushed, with no block, and so are a kernel's 31,
/// Metal's most buffer slots (248 bytes). Each computes its answer.
/// the same kernel's 21 slot addresses are all pushed, with no block, below its tail word 24 bytes
/// above them (`PushPlacement::tail_word`). A kernel's 31, Metal's most buffer slots, would end
/// past the floor with the word: its block's address and 27 slot addresses end at 224, the word is
/// at 248, and the other 4 are read from the block. Each computes its answer.
#[test]
fn the_floor_window_pushes_every_slot_address_of_a_kernel_without_a_region() {
for reads in [READS, 30] {
fn the_floor_window_pushes_a_kernel_s_slot_addresses_below_its_tail_word() {
for (reads, in_window) in [(READS, READS as usize + 1), (30, 27)] {
let Some(bc) = assemble_text("many", &many_of(reads)) else {
return;
};
@@ -1540,12 +1544,12 @@ fn the_floor_window_pushes_every_slot_address_of_a_kernel_without_a_region() {
let device = Device::from_queries(desc, identity()).unwrap_or_else(|e| panic!("{e}"));
let (first, pushed, spilled, table) = many_placed(stem, device.profile(), &bc, reads);
let what = format!("{stem}, {} slots", reads + 1);
assert_eq!(pushed.len(), (reads + 1) as usize, "{what}");
assert!(spilled.is_empty(), "{what}");
assert_eq!(table, 0, "{what}");
assert_ne!(
first.map(|(f, _)| f),
Some(PushField::ArgumentTableAddress),
assert_eq!(pushed.len(), in_window, "{what}");
assert_eq!(spilled.len(), (reads + 1) as usize - in_window, "{what}");
assert_eq!(table, if spilled.is_empty() { 0 } else { 32 }, "{what}");
assert_eq!(
first.map(|(f, _)| f) == Some(PushField::ArgumentTableAddress),
!spilled.is_empty(),
"{what}"
);
}
@@ -11,7 +11,8 @@
//! (not implemented), as before: its push window is not the floor's.
//! - On `Device::from_queries`' profile the two stages push one range, dense by link: with
//! `sampled_fragment`, which pushes its constexpr sampler's index, the fragment function's
//! fields start at the vertex function's end (40), where the fixed windows put
//! fields start at the vertex function's end (64: its second slot's bounds are its tail, 24
//! bytes above its other fields), where the fixed windows put
//! them at 64. A fragment compiled on its own at base 0 and linked after that vertex function is
//! `InvalidDescriptor(PushBase)`; compiled under the vertex function's
//! `CompiledFunction::fragment_push_base` it links.
@@ -159,12 +160,13 @@ fn from_queries_pushes_a_render_pipeline_dense_by_link() {
p.interface.push.iter().map(|s| s.push_range).collect();
assert_eq!(
ranges[0],
Some((0, 40)),
"{stem}: two buffer addresses, the zero range and their bounds from 0"
Some((0, 64)),
"{stem}: two buffer addresses, the zero range and the first bounds from 0, then the \
second bounds, the tail, at 56"
);
let fragment = ranges[1].unwrap_or_else(|| panic!("{stem}: the fragment pushes"));
assert_eq!(
fragment.0, 40,
fragment.0, 64,
"{stem}: the fragment's fields follow the vertex's"
);
// The stages compiled apart, then linked.
@@ -179,7 +181,7 @@ fn from_queries_pushes_a_render_pipeline_dense_by_link() {
&budget,
))
.unwrap_or_else(|e| panic!("{stem}: {e:?}"));
assert_eq!(vertex.fragment_push_base(), 40, "{stem}");
assert_eq!(vertex.fragment_push_base(), 64, "{stem}");
let mut inputs = keys.fragment_inputs.clone().expect("fragment inputs");
let compiled = |inputs: &crate::pipeline::lower_inputs::LoweringInputs| {
(device.compile_function(&function(&d.fragment), inputs, &budget))
@@ -192,7 +194,7 @@ fn from_queries_pushes_a_render_pipeline_dense_by_link() {
Err(Error::InvalidDescriptor(DescriptorError::PushBase {
fragment,
vertex_end,
})) => assert_eq!((fragment, vertex_end), (0, 40), "{stem}"),
})) => assert_eq!((fragment, vertex_end), (0, 64), "{stem}"),
other => panic!("{stem}: {:?}", other.map(|_| "linked")),
}
inputs.push_base = vertex.fragment_push_base();
@@ -201,7 +203,7 @@ fn from_queries_pushes_a_render_pipeline_dense_by_link() {
.unwrap_or_else(|e| panic!("{stem}: {e:?}"));
assert_eq!(
linked.interface.push[1].push_range.map(|r| r.0),
Some(40),
Some(64),
"{stem}"
);
}
@@ -5955,6 +5955,7 @@ field metal2vulkan::pipeline::PushPlacement.argument_table_size pub argument_tab
field metal2vulkan::pipeline::PushPlacement.fields pub fields: Vec<PlacedField>
field metal2vulkan::pipeline::PushPlacement.push_range pub push_range: Option<(u32, u32)>
field metal2vulkan::pipeline::PushPlacement.stage pub stage: Stage
field metal2vulkan::pipeline::PushPlacement.tail_word pub tail_word: Option<u32>
field metal2vulkan::pipeline::RenderPipeline.dependencies pub dependencies: Vec<RuntimeDependency>
field metal2vulkan::pipeline::RenderPipeline.graphics pub graphics: GraphicsState
field metal2vulkan::pipeline::RenderPipeline.interface pub interface: PipelineInterface
@@ -17107,6 +17108,7 @@ variant metal2vulkan::pipeline::PushField::Specialized Specialized(SpecKey)
variant metal2vulkan::pipeline::PushField::StageInRegion StageInRegion
variant metal2vulkan::pipeline::PushField::StageInStride StageInStride(u32)
variant metal2vulkan::pipeline::PushField::StorageKeptChannels StorageKeptChannels
variant metal2vulkan::pipeline::PushField::TailWord TailWord
variant metal2vulkan::pipeline::PushField::TessellationChunk TessellationChunk
variant metal2vulkan::pipeline::PushField::TessellationFactorAddress TessellationFactorAddress
variant metal2vulkan::pipeline::PushField::TessellationFactorInstanceStride TessellationFactorInstanceStride
Can't render this file because it is too large.
+11 -2
View File
@@ -140,7 +140,7 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`:
never writes it, so the consumer places it at a multiple of 16 and leaves it unchanged while
the command reads it. A kernel's window is 128 bytes
(256 on a device made by `Device::from_queries`, whose runtime's floor requires that much
`maxPushConstantsSize`: a dispatch region and 28 buffer addresses). On such a device a render
`maxPushConstantsSize`: a dispatch region and 24 buffer addresses below its tail). On such a device a render
pipeline's two functions share one 256-byte range: the vertex function's window is `[0, 248)`,
and the fragment function's runs from the vertex function's end to 256. A
vertex function is lowered without knowing its fragment function, so it leaves the last 8
@@ -148,7 +148,16 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`:
costs only a vertex function whose own fields pass 248 bytes, which spills where it would have
filled them. The fields only a checked access reads
(`PushField::ZeroAddress` and each `PushField::SlotBounds`) come last in the order, so they
are the first to move to the block. A kernel that reads a grid builtin reads `PushField::DispatchRegion` on
are the first to move to the block. On a device made by `Device::from_queries` each function's
push ends with its tail, 24 bytes or more above its other pushed fields: its highest
`PushField::SlotBounds` or `PushField::ZeroAddress`, moved there, or where it pushes neither, the
zero word `PushField::TailWord` at `PushPlacement::tail_word`, with which its `push_range` ends;
a function that pushes one field of 8 bytes or fewer has none. A driver that uploads a stage's
push bytes up to the highest one the stage reads then holds every load it widens from the other
fields. The function returns at its start where its tail holds what the consumer never pushes
there (a tail word other than zero, bounds whose two words are both all ones, a zero-range
address of all ones), so the consumer pushes the tail word zero with the other fields; the
bytes of the hole are not read. A kernel that reads a grid builtin reads `PushField::DispatchRegion` on
every dispatch: a dispatch the host knows states Metal's grid and its piece's first threadgroup
there, and an indirect dispatch a zero grid, whose kernel takes `NumWorkgroups` times its
workgroup size. On a device made by `Device::new` it declares no `MultiRegion` constant. On one