diff --git a/crates/xcl/src/hle/d3d12x/title_textures.rs b/crates/xcl/src/hle/d3d12x/title_textures.rs index 5686538e0..683671435 100644 --- a/crates/xcl/src/hle/d3d12x/title_textures.rs +++ b/crates/xcl/src/hle/d3d12x/title_textures.rs @@ -990,9 +990,12 @@ unsafe fn upload_queue(dev: &ID3D12Device, device: usize) -> Result) -> _ => merged.push((a, b)), } } + // each region against the merged ranges it meets (sorted and disjoint: a binary search, not + // a pass over all of them – both lists run to thousands while a game streams) let mut out = Vec::new(); - for (a, b) in merged { - for &(base, size) in regions { - let (lo, hi) = (a.max(base), b.min(base + size)); + for &(base, size) in regions { + let end = base + size; + let first = merged.partition_point(|&(_, b)| b <= base); + for &(a, b) in merged[first..].iter().take_while(|&&(a, _)| a < end) { + let (lo, hi) = (a.max(base), b.min(end)); if lo < hi { out.push((lo, hi - lo)); } @@ -1370,9 +1377,15 @@ mod tests { let regions = [(0x10000, 0x10000), (0x40000, 0x10000), (0x1000_0000, 0x1000_0000)]; let wanted = vec![(0x12000, 0x13000), (0x11000, 0x12800), (0x1F000, 0x41000), (0x60000, 0x61000)]; assert_eq!(watch_ranges(®ions, wanted), vec![(0x11000, 0xF000), (0x40000, 0x10000)]); - // ranges a gap of under 1 MiB apart: one scan; further apart: two - let wanted = vec![(0x1000_0000, 0x1000_1000), (0x1008_0000, 0x1008_1000), (0x1100_0000, 0x1100_1000)]; - assert_eq!(watch_ranges(®ions, wanted), vec![(0x1000_0000, 0x8_1000), (0x1100_0000, 0x1000)]); + // ranges a gap of under WATCH_GAP apart: one scan; further apart: two + let wanted = vec![(0x1000_0000, 0x1000_1000), (0x1008_0000, 0x1008_1000), (0x1100_0000, 0x1100_1000), (0x1800_0000, 0x1800_1000)]; + assert_eq!(watch_ranges(®ions, wanted), vec![(0x1000_0000, 0x100_1000), (0x1800_0000, 0x1000)]); + // a merged range over two regions: a piece in each, whatever order the regions come in + let regions = [(0x40000, 0x10000), (0x10000, 0x10000)]; + assert_eq!(watch_ranges(®ions, vec![(0x18000, 0x48000)]), vec![(0x18000, 0x8000), (0x40000, 0x8000)]); + // a region between two merged ranges, and one past them all + let regions = [(0x2000_0000, 0x10_0000), (0x9000_0000, 0x1000)]; + assert_eq!(watch_ranges(®ions, vec![(0x1000_0000, 0x1000_1000), (0x2008_0000, 0x2009_0000)]), vec![(0x2008_0000, 0x1_0000)]); } fn console_desc(dim: u32, w: u64, h: u32, array_or_depth: u16, mips: u16, format: u32, layout: u32) -> [u8; 0x38] {