Skip to content

Commit

Permalink
Triage suspected resources after triaging submissions (#5050)
Browse files Browse the repository at this point in the history
  • Loading branch information
nical authored Jan 12, 2024
1 parent 11c29c8 commit 376d901
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
4 changes: 0 additions & 4 deletions tests/tests/mem_leaks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,6 @@ fn draw_test_with_reports(

ctx.device
.poll(wgpu::Maintain::WaitForSubmissionIndex(submit_index));
// Because of dependency between resources, A resource being destroyed during poll
// can cause another resource to be ready for destruction next time poll is called.
// Call poll twice to ensure all destroyable resources are destroyed.
ctx.device.poll(wgpu::Maintain::Poll);

let global_report = ctx.instance.generate_report();
let report = global_report.hub_report(ctx.adapter_info.backend);
Expand Down
38 changes: 19 additions & 19 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,25 +319,6 @@ impl<A: HalApi> Device<A> {
maintain: wgt::Maintain<queue::WrappedSubmissionIndex>,
) -> Result<(UserClosures, bool), WaitIdleError> {
profiling::scope!("Device::maintain");
{
// Normally, `temp_suspected` exists only to save heap
// allocations: it's cleared at the start of the function
// call, and cleared by the end. But `Global::queue_submit` is
// fallible; if it exits early, it may leave some resources in
// `temp_suspected`.
let temp_suspected = self
.temp_suspected
.lock()
.replace(ResourceMaps::new())
.unwrap();

let mut life_tracker = self.lock_life();
life_tracker.suspected_resources.extend(temp_suspected);

life_tracker.triage_suspected(&self.trackers);
life_tracker.triage_mapped();
}

let last_done_index = if maintain.is_wait() {
let index_to_wait_for = match maintain {
wgt::Maintain::WaitForSubmissionIndex(submission_index) => {
Expand Down Expand Up @@ -370,6 +351,25 @@ impl<A: HalApi> Device<A> {
last_done_index,
self.command_allocator.lock().as_mut().unwrap(),
);

{
// Normally, `temp_suspected` exists only to save heap
// allocations: it's cleared at the start of the function
// call, and cleared by the end. But `Global::queue_submit` is
// fallible; if it exits early, it may leave some resources in
// `temp_suspected`.
let temp_suspected = self
.temp_suspected
.lock()
.replace(ResourceMaps::new())
.unwrap();

life_tracker.suspected_resources.extend(temp_suspected);

life_tracker.triage_suspected(&self.trackers);
life_tracker.triage_mapped();
}

let mapping_closures = life_tracker.handle_mapping(self.raw(), &self.trackers);

// Detect if we have been destroyed and now need to lose the device.
Expand Down

0 comments on commit 376d901

Please sign in to comment.