From ca6c86facdbbfa39c12d5c9962b96f26e9216091 Mon Sep 17 00:00:00 2001 From: fogydes Date: Wed, 25 Nov 2026 12:42:56 +0530 Subject: [PATCH] gpu: a released view's resource stays alive in its copy-goes test a_released_targets_copy_goes_when_its_memory_is_used_again compared the placed view's resource before and after the title's new texture with assert_ne!(now, shown), a pointer compare of a resource that was queued for release. The queue (RELEASED) is the process's, and five other tests drain it with release_waiting(ZERO) at any moment: that frees `shown` before the check, and the next resource made can get the same heap address, so the compare failed now and then in the parallel run (#54). The test takes a reference on `shown` and gives it back at the end, so the address cannot be reused. No production code changes: the 2 s grace is only drained early by tests. Co-Authored-By: Claude Opus 5.5 --- crates/xtp-gpu/src/resource.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/xtp-gpu/src/resource.rs b/crates/xtp-gpu/src/resource.rs index d3f92f99..8d486253 100644 --- a/crates/xtp-gpu/src/resource.rs +++ b/crates/xtp-gpu/src/resource.rs @@ -3477,6 +3477,7 @@ mod tests { use super::*; use crate::object::slot; + type AddRef = extern "system" fn(This) -> u32; type Release = extern "system" fn(This) -> u32; type Map = extern "system" fn(This, u32, *const c_void, *mut *mut u8) -> HRESULT; type Address = extern "system" fn(This) -> u64; @@ -4744,6 +4745,13 @@ mod tests { let target = at(address, &ResourceDesc { flags: 1, ..plain }); let view = words(&plain, [0, 0]); let shown = texture_at(address, &view).unwrap(); + // The view's resource is released when the title's new texture takes + // its place, and the queue it waits in is the process's: a test beside + // this one that drains it (`release_waiting`) frees the resource + // before the check below, and the next one made can take its address. + // Our own reference keeps `shown` alive, so `now != shown` is about + // the view's resource, not about where the allocator puts the next. + assert_eq!(slot::(shown, 0x08)(shown), 2); assert!(same_copy(shown, target)); let drawn = host_copy(target).unwrap(); assert_eq!(slot::(target, 0x10)(target), 0); @@ -4761,6 +4769,9 @@ mod tests { assert_eq!(slot::(streamed, 0x10)(streamed), 0); memory_remapped(address as usize, KIB_64 as usize); release_waiting(std::time::Duration::ZERO); + // The queue's reference goes here or in another test, still on its + // way out maybe: ours is the one left to give back. + slot::(shown, 0x10)(shown); } /// Textures the title fills itself are placed in the texture pool;