Skip to content

Commit 597ccdd

Browse files
jimblandyEriKWDev
authored andcommitted
[core] Doc fixes for lifetime management, minor typos.
- Document `LifetimeTracker::triage_resources`. - Fix various typos and bad grammar.
1 parent 09af0ca commit 597ccdd

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

wgpu-core/src/device/global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2091,7 +2091,7 @@ impl Global {
20912091
}
20922092

20932093
#[cfg(feature = "replay")]
2094-
/// Only triangle suspected resource IDs. This helps us to avoid ID collisions
2094+
/// Only triage suspected resource IDs. This helps us to avoid ID collisions
20952095
/// upon creating new resources when re-playing a trace.
20962096
pub fn device_maintain_ids<A: HalApi>(&self, device_id: DeviceId) -> Result<(), InvalidDevice> {
20972097
let hub = A::hub(self);

wgpu-core/src/device/life.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,20 @@ impl<A: HalApi> LifetimeTracker<A> {
468468
}
469469

470470
impl<A: HalApi> LifetimeTracker<A> {
471+
/// Remove abandoned resources from `resources_map` and return them.
472+
///
473+
/// Consult `trackers` to see which resources in `resources_map` are
474+
/// abandoned (that is, referenced only by `resources_map` and `trackers`
475+
/// itself) and remove them from `resources_map`.
476+
///
477+
/// If the abandoned resources are in use by a command submission still in
478+
/// flight, as listed in `active`, add them to that submission's
479+
/// `ActiveSubmission::last_resources` map.
480+
///
481+
/// Use `get_resource_map` to find the appropriate member of
482+
/// `ActiveSubmission::last_resources` to hold resources of type `R`.
483+
///
484+
/// Return a vector of all the abandoned resources that were removed.
471485
fn triage_resources<R>(
472486
resources_map: &mut FastHashMap<TrackerIndex, Arc<R>>,
473487
active: &mut [ActiveSubmission<A>],
@@ -584,6 +598,12 @@ impl<A: HalApi> LifetimeTracker<A> {
584598
&mut trackers.views,
585599
|maps| &mut maps.texture_views,
586600
);
601+
// You might be tempted to add the view's parent texture to
602+
// suspected_resources here, but don't. Texture views get dropped all
603+
// the time, and once a texture is added to
604+
// `LifetimeTracker::suspected_resources` it remains there until it's
605+
// actually dropped, which for long-lived textures could be at the end
606+
// of execution.
587607
self
588608
}
589609

@@ -782,7 +802,8 @@ impl<A: HalApi> LifetimeTracker<A> {
782802
pub(crate) fn triage_suspected(&mut self, trackers: &Mutex<Tracker<A>>) {
783803
profiling::scope!("triage_suspected");
784804

785-
//NOTE: the order is important to release resources that depends between each other!
805+
// NOTE: The order in which resource types are processed here is
806+
// crucial. See "Entrained resources" in this function's doc comment.
786807
self.triage_suspected_render_bundles(trackers);
787808
self.triage_suspected_compute_pipelines(trackers);
788809
self.triage_suspected_render_pipelines(trackers);

wgpu-core/src/track/buffer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ impl<A: HalApi> ResourceTracker for BufferTracker<A> {
303303
///
304304
/// A buffer is 'otherwise unused' when the only references to it are:
305305
///
306-
/// 1) the `Arc` that our caller, `LifetimeTracker::triage_suspected`, has just
307-
/// drained from `LifetimeTracker::suspected_resources`,
306+
/// 1) the `Arc` that our caller, `LifetimeTracker::triage_resources`, is
307+
/// considering draining from `LifetimeTracker::suspected_resources`,
308308
///
309309
/// 2) its `Arc` in [`self.metadata`] (owned by [`Device::trackers`]), and
310310
///

0 commit comments

Comments
 (0)