diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 6d7815bce..4fea73423 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -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 diff --git a/crates/metal2vulkan/src/lower/access/pointer.rs b/crates/metal2vulkan/src/lower/access/pointer.rs index 81a914e7f..381fb5bfd 100644 --- a/crates/metal2vulkan/src/lower/access/pointer.rs +++ b/crates/metal2vulkan/src/lower/access/pointer.rs @@ -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<'_>, diff --git a/crates/metal2vulkan/src/lower/emit.rs b/crates/metal2vulkan/src/lower/emit.rs index c3e7e46b6..874f5a28a 100644 --- a/crates/metal2vulkan/src/lower/emit.rs +++ b/crates/metal2vulkan/src/lower/emit.rs @@ -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(()) }