diff --git a/crates/metal2vulkan/src/lower/access/pointer.rs b/crates/metal2vulkan/src/lower/access/pointer.rs index 93251304d..81a914e7f 100644 --- a/crates/metal2vulkan/src/lower/access/pointer.rs +++ b/crates/metal2vulkan/src/lower/access/pointer.rs @@ -812,10 +812,12 @@ pub(super) fn slot_address( } /// Buffer slot `slot`'s Metal address less [`SLOT_ADDRESS_BIAS`](super::SLOT_ADDRESS_BIAS), as its -/// low and high words: its `SlotGuestBase` word where the word is biased ([`biased`]), else that -/// word less the bias, borrowing from the high word. 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. +/// 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. pub(super) fn direct_base( cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, @@ -828,21 +830,11 @@ pub(super) fn direct_base( if let (Some(lo), Some(hi)) = (cx.recall_slot(fb, lo), cx.recall_slot(fb, hi)) { return Ok(Pair { lo, hi }); } + if !biased(cx) { + return Err(cx.fail("a direct access of a slot whose SlotGuestBase word is not biased")); + } let v = cx.push_field(fb, PushField::SlotGuestBase(slot))?; - let word = wide::split(fb, v)?; - let base = match biased(cx) { - true => word, - false => { - let bias = k32(fb, super::SLOT_ADDRESS_BIAS as u32)?; - let less = fb.binary(BinOp::ISubBorrow, word.lo, bias)?; - let low = fb.composite_extract(less, &[0])?; - let borrow = fb.composite_extract(less, &[1])?; - Pair { - lo: low, - hi: fb.binary(BinOp::ISub, word.hi, borrow)?, - } - } - }; + let base = wide::split(fb, v)?; cx.remember_slot(fb, lo, base.lo); cx.remember_slot(fb, hi, base.hi); Ok(base)