From 281a7aecd5f82bb91fce4a975f4e242044d309fc Mon Sep 17 00:00:00 2001 From: Mauro Gentile <62186646+gents83@users.noreply.github.com> Date: Sun, 26 Nov 2023 15:58:00 +0100 Subject: [PATCH] remove_abandoned fix (#4781) * remove_abandoned fix * Updated doc --- wgpu-core/src/track/buffer.rs | 9 ++++----- wgpu-core/src/track/metadata.rs | 9 +-------- wgpu-core/src/track/stateless.rs | 8 ++++---- wgpu-core/src/track/texture.rs | 8 ++++---- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/wgpu-core/src/track/buffer.rs b/wgpu-core/src/track/buffer.rs index dc569ff842..4b91a62d12 100644 --- a/wgpu-core/src/track/buffer.rs +++ b/wgpu-core/src/track/buffer.rs @@ -293,7 +293,7 @@ pub(crate) struct BufferTracker { } impl ResourceTracker> for BufferTracker { - /// Removes the buffer `id` from this tracker if it is otherwise unused. + /// Try to remove the buffer `id` from this tracker if it is otherwise unused. /// /// A buffer is 'otherwise unused' when the only references to it are: /// @@ -308,8 +308,7 @@ impl ResourceTracker> for BufferTracker { /// `triage_suspected` will remove 3), leaving 1) as the sole /// remaining reference. /// - /// Return `true` if this tracker contained the buffer `id`. This - /// implies that we removed it. + /// Returns true if the resource was removed or if not existing in metadata. /// /// [`Device::trackers`]: crate::device::Device /// [`self.metadata`]: BufferTracker::metadata @@ -339,11 +338,11 @@ impl ResourceTracker> for BufferTracker { id, existing_ref_count ); + return false; } } } - - false + true } } diff --git a/wgpu-core/src/track/metadata.rs b/wgpu-core/src/track/metadata.rs index 8001776e8c..3464170ebf 100644 --- a/wgpu-core/src/track/metadata.rs +++ b/wgpu-core/src/track/metadata.rs @@ -122,14 +122,7 @@ impl> ResourceMetadata { /// existing tables. See `tracker_assert_in_bounds`. #[inline(always)] pub(super) unsafe fn get_ref_count_unchecked(&self, index: usize) -> usize { - unsafe { - Arc::strong_count( - self.resources - .get_unchecked(index) - .as_ref() - .unwrap_unchecked(), - ) - } + unsafe { Arc::strong_count(self.get_resource_unchecked(index)) } } /// Returns an iterator over the resources owned by `self`. diff --git a/wgpu-core/src/track/stateless.rs b/wgpu-core/src/track/stateless.rs index c312a6abba..27c9e743ec 100644 --- a/wgpu-core/src/track/stateless.rs +++ b/wgpu-core/src/track/stateless.rs @@ -78,10 +78,10 @@ pub(crate) struct StatelessTracker> { impl> ResourceTracker for StatelessTracker { - /// Removes the given resource from the tracker iff we have the last reference to the + /// Try to remove the given resource from the tracker iff we have the last reference to the /// resource and the epoch matches. /// - /// Returns true if the resource was removed. + /// Returns true if the resource was removed or if not existing in metadata. /// /// If the ID is higher than the length of internal vectors, /// false will be returned. @@ -113,11 +113,11 @@ impl> ResourceTracker id, existing_ref_count ); + return false; } } } - - false + true } } diff --git a/wgpu-core/src/track/texture.rs b/wgpu-core/src/track/texture.rs index f966f34709..bfe45f0d05 100644 --- a/wgpu-core/src/track/texture.rs +++ b/wgpu-core/src/track/texture.rs @@ -394,10 +394,10 @@ pub(crate) struct TextureTracker { } impl ResourceTracker> for TextureTracker { - /// Removes the given resource from the tracker iff we have the last reference to the + /// Try to remove the given resource from the tracker iff we have the last reference to the /// resource and the epoch matches. /// - /// Returns true if the resource was removed. + /// Returns true if the resource was removed or if not existing in metadata. /// /// If the ID is higher than the length of internal vectors, /// false will be returned. @@ -428,11 +428,11 @@ impl ResourceTracker> for TextureTracker { id, existing_ref_count ); + return false; } } } - - false + true } }