diff --git a/crates/xcl/src/hle/d3d12x/sparse.rs b/crates/xcl/src/hle/d3d12x/sparse.rs index bcee2b4bb..22c5a22fa 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) } } @@ -1487,6 +1488,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]