From 234a8e144f3c7f4a098ddc7e574570b1499a2afa Mon Sep 17 00:00:00 2001
From: Luxury <357971070+Luxuryig@users.noreply.github.com>
Date: Tue, 24 Nov 2026 06:54:17 +0200
Subject: [PATCH] Tests: compare extra-page tiles when an unaligned va is
placed again (#718)
The device-wide page count also drops when unrelated idle pages are swept, so this check compares that resource's extra-page tiles instead. The cubemap check in the same test stays with #447.
Assisted-by: Grok Build (Grok 4.7)
---
crates/xcl/src/hle/d3d12x/title_textures.rs | 21 ++++++++++++++++++++-
crates/xcl/src/hle/d3d12x/vram.rs | 15 +++++++++++++++
2 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/crates/xcl/src/hle/d3d12x/title_textures.rs b/crates/xcl/src/hle/d3d12x/title_textures.rs
index 820f48500..c10168950 100644
--- a/crates/xcl/src/hle/d3d12x/title_textures.rs
+++ b/crates/xcl/src/hle/d3d12x/title_textures.rs
@@ -1848,8 +1848,27 @@ mod tests {
assert_eq!(read_sub(r, 0), subresources(base + off, &xg::Texture::new(&d).unwrap())[0].data, "4 KiB neighbour at +{off:#x} crosstalk");
}
let pages_before_reuse = dev_pages();
+ // Binding sweeps pages idle for two seconds, so the device-wide count can fall
+ // here even when this placement shares the extra tile it already has.
+ let first = adj[1].as_raw() as usize;
+ let before = super::super::vram::mapped_tiles_for(dev_key, first);
let reused = place_tex(base + 0x4000, &d16);
- assert_eq!(dev_pages(), pages_before_reuse, "reusing unaligned va must share extra_pages tile");
+ if super::super::vram::is_placed_texture(first) {
+ let before = before.expect("the first unaligned placement is mapped");
+ assert!(!before.1.is_empty(), "a 16 KiB texture in a 64 KiB page uses an extra tile");
+ assert_eq!(
+ super::super::vram::mapped_tiles_for(dev_key, first).as_ref(),
+ Some(&before),
+ "the first placement keeps its tiles when the va is placed again",
+ );
+ assert_eq!(
+ super::super::vram::mapped_tiles_for(dev_key, reused.as_raw() as usize).as_ref().map(|t| &t.1),
+ Some(&before.1),
+ "reusing unaligned va must share extra_pages tile",
+ );
+ } else {
+ assert_eq!(dev_pages(), pages_before_reuse, "reusing unaligned va must share extra_pages tile");
+ }
// Overwrite the first 64 KiB (covering +0x0000, +0x4000 (both adj[1] & reused), +0x8000, +0xC000)
// WITHOUT releasing adj/reused: dead extra_pages (+0x4000, +0x8000) must drop immediately!
let cover = place_tex(base, &d64);
diff --git a/crates/xcl/src/hle/d3d12x/vram.rs b/crates/xcl/src/hle/d3d12x/vram.rs
index 8b806d5f8..895c39838 100644
--- a/crates/xcl/src/hle/d3d12x/vram.rs
+++ b/crates/xcl/src/hle/d3d12x/vram.rs
@@ -608,6 +608,21 @@ pub(super) unsafe fn before_execute(queue: &ID3D12CommandQueue) {
#[cfg(test)]
pub(super) static VRAM_TEST_LOCK: Mutex<()> = Mutex::new(());
+/// Tile identities of one mapped resource: title pages, then extra pages.
+/// A device-wide byte count also falls when unrelated idle pages are swept.
+#[cfg(test)]
+pub(super) fn mapped_tiles_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::