Skip to content

Commit

Permalink
Fix incorrect memory usage stats for destroyed on-creation-mapped buf…
Browse files Browse the repository at this point in the history
…fers (#1963)

We actually don't have anywhere where we discard this kind of buffer yet, but if we would the stats would be wrong (noticed while doing quick & dirty experiments on the staging belt)
  • Loading branch information
Wumpf authored Apr 25, 2023
1 parent ad46760 commit 049cfaa
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions crates/re_renderer/src/wgpu_resources/dynamic_resource_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ where
self.current_frame_index = frame_index;
let state = self.state.get_mut();

let update_stats = |creation_desc: &Desc| {
self.total_resource_size_in_bytes.fetch_sub(
creation_desc.resource_size_in_bytes(),
std::sync::atomic::Ordering::Relaxed,
);
};

// Throw out any resources that we haven't reclaimed last frame.
for (desc, resources) in state.last_frame_deallocated.drain() {
re_log::trace!(
Expand All @@ -160,11 +167,8 @@ where
debug_assert!(false, "a resource was marked as destroyed last frame that we no longer kept track of");
continue;
};
update_stats(&desc);
on_destroy_resource(&removed_resource);
self.total_resource_size_in_bytes.fetch_sub(
desc.resource_size_in_bytes(),
std::sync::atomic::Ordering::Relaxed,
);
}
}

Expand All @@ -184,6 +188,7 @@ where
.push(resource.handle);
true
} else {
update_stats(&resource.creation_desc);
on_destroy_resource(&resource.inner);
false
}
Expand Down

0 comments on commit 049cfaa

Please sign in to comment.