RUNTIME 2259: a use's range stays 32 bytes: an image's place in its heap counts 64-byte granules

What: tracker::ImagePlace, which RUNTIME 2257 added to UseRange::Image so that
images placed apart in one heap (one tracker key) share no memory, held its
bytes as two u64s, growing UseRange from 24 to 40 bytes. It now holds two u32
counts of 64-byte granules (PLACE_GRANULE), rounded out (start down, end up),
so UseRange is 32 bytes; a place past what u32 granules count (256 GiB) is
WHOLE, the key's whole memory. Rounding out only adds bytes, so places whose
bytes meet still meet; two that share a granule alone are taken to meet, at
most a needless barrier or copy.

Why: every use of every command copies and compares a UseRange
(EncoderUses::note's map, command_uses_into, the kept uses). The XTX's
per-draw bench (walk_costs, exclusive, tip/before alternating, m3-max-27858)
put the no-barrier draw path about 1.2 us a draw (8-12%) above the build
before RUNTIME 2257, the barriers shape unchanged. This change narrows the
range back toward its old size. Whether it recovers the cost is the XTX
confirm's question; the commit claims only the size.

Verified: tests::tracker 76/76 including a_use_range_stays_32_bytes, clippy plain exit 0, lavapipe
heap_placed_reads, heap_placed_targets, attached_levels, color_groups and tracker 82/82
(m3-max-28099). On the XTX (m3-max-28098, exclusive, release walk_costs, tip/before/compact
twice and once under perf) the timings were bimodal in every build (frames at ~185 or 250-285 us),
wider than the 8% effect, so they settle nothing; the encoding thread's cycles:u profile puts the
tip's extra samples in RenderLowering::draw_rebound (51 against 18 before) and
State::shadows_to_carry (23 against <6), both copying and walking uses, and the compact build at
17 and 9: one perf run a build, evidence rather than proof.
This commit is contained in:
Anees Iqbal committed 2026-11-13 21:44:18 -08:00
1 parent 12fa641450
commit 1895fe40d6
3 files changed
+40 -12

No files matched your search

@@ -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::<UseRange>(), 32);
}
+21 -11
View File
@@ -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<u64>) -> 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<Range<u64>> {
(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
+1 -1
View File
@@ -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