Translator: a slot's direct base and address are made before the body, in the function's first block
e2e76d8879 made a slot's direct base and Metal address once, in the block that first asks for
them, and recalled them where that block dominates. Where that block was the walk's first one,
the first application of a function inlined more than once made the base after work of its own,
and every later application read it: the applications were no longer the same code, and
spirv::roll wrote the body twice where it had written it once. The identity-domains engine_roll
case shows it: three applications weighed 26,737 against one's 13,355 on lavapipe (m3-max-78287).
Now EmitCx::load_push_fields, the first hook, makes every placed SlotGuestBase slot's direct base
and address under the identity domains (pointer::make_ahead), after the push fields load and
before any other hook or the body: every block recalls them, and every application reads them
from before it. Those no access reads leave with the other unused values (spirv::dead, at the end
of emission, before the roll and the weighing). Making them in the entry block where first asked
(fb.in_entry_block) is not enough: the walk's first block is the entry block itself until a hook
closes a construct, so the base still landed inside the first application (m3-max-78326: 2.00
bodies, as before).
The arithmetic is unchanged; module bytes change (the bases move to the first block):
SEMANTICS_VERSION 2310 -> 2311. The golden table is re-blessed at the next pin.
Verified: nothing run yet for this commit; the roll, identity, identity-flow, access-size and
golden tests run next on msi.
This commit is contained in:
1 parent
edabd70447
commit
fd8b132834
3 files changed
+39
-12
No files matched your search
Vendored
+1
-1
@@ -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 = 2310;
|
||||
pub const SEMANTICS_VERSION: u32 = 2311;
|
||||
|
||||
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
|
||||
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
|
||||
|
||||
@@ -787,9 +787,9 @@ fn slot_word(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, slot: SlotRef) -
|
||||
/// Buffer slot `slot`'s Metal address, the bound buffer's `gpuAddress` plus the bind offset, as a
|
||||
/// `u64` (needs `shaderInt64`): its `SlotGuestBase` word, plus
|
||||
/// [`SLOT_ADDRESS_BIAS`](super::SLOT_ADDRESS_BIAS) where the word is biased ([`biased`]), added to
|
||||
/// the low word with the carry into the high word (`psb::add_slot_offset`). Made once where it
|
||||
/// dominates. What a pointer compare, a converted or stored pointer, and an access from the word
|
||||
/// below it read.
|
||||
/// the low word with the carry into the high word (`psb::add_slot_offset`). Made once, before the
|
||||
/// body ([`make_ahead`]). What a pointer compare, a converted or stored pointer, and an access
|
||||
/// from the word below it read.
|
||||
pub(super) fn slot_address(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
@@ -811,13 +811,27 @@ pub(super) fn slot_address(
|
||||
Ok(address)
|
||||
}
|
||||
|
||||
/// Make buffer slot `slot`'s direct base ([`direct_base`]) and Metal address ([`slot_address`])
|
||||
/// in the open block, where every later block recalls them: `EmitCx::load_push_fields` makes them
|
||||
/// in the function's first block, before the body, so no application of a function the body
|
||||
/// repeats makes them inside itself.
|
||||
pub(crate) fn make_ahead(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
slot: SlotRef,
|
||||
) -> BResult<()> {
|
||||
direct_base(cx, fb, slot)?;
|
||||
slot_address(cx, fb, slot)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Buffer slot `slot`'s Metal address less [`SLOT_ADDRESS_BIAS`](super::SLOT_ADDRESS_BIAS), as its
|
||||
/// low and high words: its biased `SlotGuestBase` word ([`biased`]). The base an access reached
|
||||
/// from the slot's own address adds its biased offset to (`psb::prepare_direct`), made once where
|
||||
/// it dominates, so each access adds its offset to the low word and the carry to the high word,
|
||||
/// and no more. Only the identity domains reach a slot so, and they refuse a device-replay
|
||||
/// variant, whose word is not biased (`select::identity_admits`): an unbiased word here is an
|
||||
/// invariant error.
|
||||
/// from the slot's own address adds its biased offset to (`psb::prepare_direct`), made once,
|
||||
/// before the body ([`make_ahead`]), so each access adds its offset to the low word and the carry
|
||||
/// to the high word, and no more. Only the identity domains reach a slot so, and they refuse a
|
||||
/// device-replay variant, whose word is not biased (`select::identity_admits`): an unbiased word
|
||||
/// here is an invariant error.
|
||||
pub(super) fn direct_base(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
|
||||
@@ -263,8 +263,9 @@ enum Invariant {
|
||||
Slot(SlotMemo),
|
||||
}
|
||||
|
||||
/// A value of a buffer slot's address under the identity domains that a block makes once
|
||||
/// (`access::pointer`): recalled where the block that made it dominates.
|
||||
/// A value of a buffer slot's address under the identity domains, made once
|
||||
/// (`access::pointer`): in the function's first block, before the hooks and the body
|
||||
/// ([`EmitCx::load_push_fields`]), so every block recalls it.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum SlotMemo {
|
||||
/// The slot's address less `SLOT_ADDRESS_BIAS`, the base a direct access adds its biased
|
||||
@@ -528,7 +529,8 @@ impl<'a> EmitCx<'a> {
|
||||
///
|
||||
/// The fields read from their push members load first, then the tail folds into them
|
||||
/// ([`EmitCx::fold_tail`]), then the spilled fields and those the function derives, which may
|
||||
/// read through the folded values (the parameter block's address, a slot table's).
|
||||
/// read through the folded values (the parameter block's address, a slot table's),
|
||||
/// then, under the identity domains, each slot's direct base and address.
|
||||
fn load_push_fields(&mut self, fb: &mut FunctionBuilder<'_>) -> BResult<()> {
|
||||
let plan: &Plan = self.plan;
|
||||
let member = |s: &Self, field: PushField| {
|
||||
@@ -552,6 +554,17 @@ impl<'a> EmitCx<'a> {
|
||||
self.fold_tail(fb)?;
|
||||
}
|
||||
}
|
||||
// Under the identity domains each slot's direct base and Metal address, made here, before
|
||||
// the hooks and the body: every block recalls them, so every application of a function
|
||||
// the body repeats reads them from before it and the applications stay the same code,
|
||||
// which `spirv::roll` writes once. One nothing reads leaves with the other unused values.
|
||||
if plan.families.access.identity {
|
||||
for placed in &plan.push.fields {
|
||||
if let PushField::SlotGuestBase(slot) = placed.field {
|
||||
access::pointer::make_ahead(self, fb, slot)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user