Skip to content

Commit

Permalink
remove_abandoned fix (#4781)
Browse files Browse the repository at this point in the history
* remove_abandoned fix

* Updated doc
  • Loading branch information
gents83 authored Nov 26, 2023
1 parent 12ee31d commit 281a7ae
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
9 changes: 4 additions & 5 deletions wgpu-core/src/track/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ pub(crate) struct BufferTracker<A: HalApi> {
}

impl<A: HalApi> ResourceTracker<BufferId, Buffer<A>> for BufferTracker<A> {
/// 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:
///
Expand All @@ -308,8 +308,7 @@ impl<A: HalApi> ResourceTracker<BufferId, Buffer<A>> for BufferTracker<A> {
/// `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
Expand Down Expand Up @@ -339,11 +338,11 @@ impl<A: HalApi> ResourceTracker<BufferId, Buffer<A>> for BufferTracker<A> {
id,
existing_ref_count
);
return false;
}
}
}

false
true
}
}

Expand Down
9 changes: 1 addition & 8 deletions wgpu-core/src/track/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,7 @@ impl<A: HalApi, I: TypedId, T: Resource<I>> ResourceMetadata<A, I, T> {
/// 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`.
Expand Down
8 changes: 4 additions & 4 deletions wgpu-core/src/track/stateless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ pub(crate) struct StatelessTracker<A: HalApi, Id: TypedId, T: Resource<Id>> {
impl<A: HalApi, Id: TypedId, T: Resource<Id>> ResourceTracker<Id, T>
for StatelessTracker<A, Id, T>
{
/// 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.
Expand Down Expand Up @@ -113,11 +113,11 @@ impl<A: HalApi, Id: TypedId, T: Resource<Id>> ResourceTracker<Id, T>
id,
existing_ref_count
);
return false;
}
}
}

false
true
}
}

Expand Down
8 changes: 4 additions & 4 deletions wgpu-core/src/track/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ pub(crate) struct TextureTracker<A: HalApi> {
}

impl<A: HalApi> ResourceTracker<TextureId, Texture<A>> for TextureTracker<A> {
/// 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.
Expand Down Expand Up @@ -428,11 +428,11 @@ impl<A: HalApi> ResourceTracker<TextureId, Texture<A>> for TextureTracker<A> {
id,
existing_ref_count
);
return false;
}
}
}

false
true
}
}

Expand Down

0 comments on commit 281a7ae

Please sign in to comment.