From b85602215a2f616f734187504d30279e4c249df4 Mon Sep 17 00:00:00 2001 From: AliceWood <36452359+AliceWood@users.noreply.github.com> Date: Tue, 24 Nov 2026 00:13:39 +0300 Subject: [PATCH] Spread aligned sparse tile keys across hash buckets --- crates/xcl/src/hle/d3d12x/sparse.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/hle/d3d12x/sparse.rs b/crates/xcl/src/hle/d3d12x/sparse.rs index 3cf45e559..93b4532eb 100644 --- a/crates/xcl/src/hle/d3d12x/sparse.rs +++ b/crates/xcl/src/hle/d3d12x/sparse.rs @@ -75,7 +75,8 @@ impl Hasher for FxHasher { } #[inline] fn finish(&self) -> u64 { - self.0 + // Tile addresses are 64 KiB aligned. Move mixed bits into the low bucket-index bits. + self.0.rotate_right(23) } } @@ -1433,6 +1434,21 @@ pub fn forget_buffer(res: usize) { mod tests { use super::*; + #[test] + fn aligned_tile_addresses_spread_across_hash_buckets() { + use std::hash::BuildHasher; + + let hasher = BuildHasherDefault::::default(); + let mut used = [false; 256]; + for tile in 0..used.len() { + let address = (1usize << 32) + tile * TILE; + let bucket = hasher.hash_one(address) as usize & (used.len() - 1); + used[bucket] = true; + } + let occupied = used.iter().filter(|&&bucket| bucket).count(); + assert!(occupied >= used.len() / 2, "256 aligned addresses used {occupied} buckets"); + } + /// Only the 64-byte chunks the CPU changed are sent again – the rest of the page may hold /// what the GPU wrote. #[test]