diff --git a/crates/metal2vulkan-runtime/src/tests/tracker.rs b/crates/metal2vulkan-runtime/src/tests/tracker.rs index 2e9f68650..89046b871 100644 --- a/crates/metal2vulkan-runtime/src/tests/tracker.rs +++ b/crates/metal2vulkan-runtime/src/tests/tracker.rs @@ -2579,4 +2579,22 @@ fn placed_images_share_memory_where_their_bytes_meet() { assert!(whole.shares_memory(&UseRange::Bytes(1 << 40..(1 << 40) + 1))); assert!(whole.shares_memory(&a) && a.shares_memory(&whole)); assert_eq!(a.hull(&b).map(|h| h == placed(0..8192)), Some(false)); + // A place counts 64-byte granules, rounded out: a texture ending inside one meets the bytes + // after it there, and none past it, where the next texture's aligned offset lies. + let short = placed(0..1000); + assert!(short.shares_memory(&UseRange::Bytes(1000..1016))); + assert!(!short.shares_memory(&placed(1024..2048))); + // Past the 256 GiB the granules count, the whole key's memory. + let far = placed(1 << 40..(1 << 40) + 4096); + assert!( + far.shares_memory(&a), + "a place past the granules meets every range" + ); +} + +/// A use's range is copied and compared by every use of every command (`EncoderUses::note`, +/// `command_uses_into`): an image's place in its heap takes 8 bytes of it, so it stays 32. +#[test] +fn a_use_range_stays_32_bytes() { + assert_eq!(std::mem::size_of::(), 32); } diff --git a/crates/metal2vulkan-runtime/src/tracker.rs b/crates/metal2vulkan-runtime/src/tracker.rs index 464d740db..3d2a59977 100644 --- a/crates/metal2vulkan-runtime/src/tracker.rs +++ b/crates/metal2vulkan-runtime/src/tracker.rs @@ -174,31 +174,41 @@ pub(super) enum UseRange { /// asks whether two uses touch the same memory reads it ([`UseRange::shares_memory`]): a draw that /// reads a texture placed apart from its attachment in the attachment's heap reads no memory the /// attachment renders. +/// +/// It holds the bytes in [`PLACE_GRANULE`]s, rounded out (its start down, its end up), so a +/// [`UseRange`] stays 32 bytes, which every use of every command copies and compares. Rounding +/// out only adds bytes, so two places whose bytes meet meet; two that share a granule alone (a +/// texture of 16-byte alignment, a linear one's, placed right after another) are taken to meet, +/// which costs at most a barrier or a copy no byte needed, never one missed. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] pub(super) struct ImagePlace { - start: u64, - end: u64, + start: u32, + end: u32, } +/// The bytes of a heap's memory one unit of an [`ImagePlace`] counts: offsets to 256 GiB fit. +const PLACE_GRANULE: u64 = 64; + impl ImagePlace { /// The whole of the key's memory: an image whose key is its own, or one whose place is not /// known. pub(super) const WHOLE: ImagePlace = ImagePlace { start: 0, end: 0 }; - /// The bytes `bytes` of the key's memory; [`WHOLE`](Self::WHOLE) for an empty range. + /// The bytes `bytes` of the key's memory, rounded out to granules; [`WHOLE`](Self::WHOLE) + /// for an empty range, and for one past what the granules count. pub(super) fn bytes(bytes: Range) -> ImagePlace { - match bytes.is_empty() { - true => ImagePlace::WHOLE, - false => ImagePlace { - start: bytes.start, - end: bytes.end, - }, + let start = u32::try_from(bytes.start / PLACE_GRANULE); + let end = u32::try_from(bytes.end.div_ceil(PLACE_GRANULE)); + match (bytes.is_empty(), start, end) { + (false, Ok(start), Ok(end)) => ImagePlace { start, end }, + _ => ImagePlace::WHOLE, } } - /// Its bytes, where it names some. + /// Its bytes, rounded out, where it names some. fn range(self) -> Option> { - (self != ImagePlace::WHOLE).then_some(self.start..self.end) + let bytes = |granules: u32| u64::from(granules) * PLACE_GRANULE; + (self != ImagePlace::WHOLE).then(|| bytes(self.start)..bytes(self.end)) } /// Whether an image here and one at `other`, of the same key, may share memory: always, but diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 05f4dc2e3..0432ed989 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -94,7 +94,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 522; /// changes no behaviour, and then updates that hash alone with the commit saying why, or changes /// behaviour and also bumps this version. The commit that bumps it says what changed; this comment /// keeps no history. -pub const RUNTIME_VERSION: u32 = 2258; +pub const RUNTIME_VERSION: u32 = 2259; /// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex, /// of the manifest, the build script, and exactly the files the crate roots' module tree compiles