From 48e7434f5fa51934c3cd225eed4336a0bf9b0747 Mon Sep 17 00:00:00 2001 From: Prime1997 Date: Mon, 23 Nov 2026 16:18:15 -0800 Subject: [PATCH] Tests: check cube reuse by tile identity instead of idle pages A placement sweeps pages belonging to unrelated targets idle for two seconds. Comparing device-wide bytes before and after the second cube can therefore fail when those old targets expire. Snapshot the mapped title-page and extra-page pool/tile identities for the cube and require the new and original resources to share all of them. Keep the existing placement-growth, reclamation and pixel-readback checks. --- crates/xcl/src/hle/d3d12x/title_textures.rs | 11 +++++++++-- crates/xcl/src/hle/d3d12x/vram.rs | 13 +++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/title_textures.rs b/crates/xcl/src/hle/d3d12x/title_textures.rs index 2f3303a97..1153b8f75 100644 --- a/crates/xcl/src/hle/d3d12x/title_textures.rs +++ b/crates/xcl/src/hle/d3d12x/title_textures.rs @@ -1622,9 +1622,16 @@ mod tests { } // Placing a second cubemap at the same va must reuse every tile including extra_pages. if label.contains("cubemap") { - let p0 = dev_pages(); + // Binding sweeps unrelated targets idle for two seconds, so a device-wide + // byte count can fall here even when every tile of this cube is shared. + let mappings = super::super::vram::tile_mappings_for(dev.as_raw() as usize, res.as_raw() as usize).expect("cube is mapped"); + assert!(!mappings.0.is_empty() || !mappings.1.is_empty(), "cube must have mapped tiles"); let res2 = place_tex(base, &d); - assert_eq!(dev_pages(), p0, "cubemap extra_pages must be reused at same va"); + assert_eq!(super::super::vram::tile_mappings_for(dev.as_raw() as usize, res2.as_raw() as usize).as_ref(), Some(&mappings), + "the second cube must reuse every title-page and extra-page tile"); + assert_eq!(super::super::vram::tile_mappings_for(dev.as_raw() as usize, res.as_raw() as usize).as_ref(), Some(&mappings), + "the original cube must keep the same tile mappings"); + println!("{label}: reused {} title-page tiles and {} extra-page tiles", mappings.0.len(), mappings.1.len()); drop(res2); } drop(res); diff --git a/crates/xcl/src/hle/d3d12x/vram.rs b/crates/xcl/src/hle/d3d12x/vram.rs index 507c5b696..066132f4f 100644 --- a/crates/xcl/src/hle/d3d12x/vram.rs +++ b/crates/xcl/src/hle/d3d12x/vram.rs @@ -587,6 +587,19 @@ pub(super) fn page_bytes_for(device: usize) -> (usize, usize) { ((p.pages.len() + p.extra_pages.len()) * PAGE, p.pools.len() * POOL_PAGES as usize * PAGE) } +/// Pool/tile identities used by one mapped resource: title pages, then extra pages. +/// Unlike device-wide byte counts, these cannot shrink when unrelated idle targets expire. +#[cfg(test)] +pub(super) fn tile_mappings_for(device: usize, resource: usize) -> Option<(Vec<(u32, u32)>, Vec<(u32, u32)>)> { + let g = PAGES.lock().unwrap(); + let p = g.get(&device)?.as_ref()?; + let target = p.targets.get(&resource)?; + if !target.mapped { return None; } + let used = target.used.iter().map(|key| p.pages.get(key).map(|page| page.tile)).collect::>>()?; + let extra = target.used_extra.iter().map(|key| p.extra_pages.get(key).map(|page| page.tile)).collect::>>()?; + (used.len() + extra.len() == target.total as usize).then_some((used, extra)) +} + /// (bytes of pages in use by tiled textures, bytes of pool heaps) – `XCL_ACTIVITY` pub fn page_bytes() -> (usize, usize) { let g = PAGES.lock().unwrap();