Skip to content

Commit 049cfaa

Browse files
authored
Fix incorrect memory usage stats for destroyed on-creation-mapped buffers (#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)
1 parent ad46760 commit 049cfaa

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

crates/re_renderer/src/wgpu_resources/dynamic_resource_pool.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ where
148148
self.current_frame_index = frame_index;
149149
let state = self.state.get_mut();
150150

151+
let update_stats = |creation_desc: &Desc| {
152+
self.total_resource_size_in_bytes.fetch_sub(
153+
creation_desc.resource_size_in_bytes(),
154+
std::sync::atomic::Ordering::Relaxed,
155+
);
156+
};
157+
151158
// Throw out any resources that we haven't reclaimed last frame.
152159
for (desc, resources) in state.last_frame_deallocated.drain() {
153160
re_log::trace!(
@@ -160,11 +167,8 @@ where
160167
debug_assert!(false, "a resource was marked as destroyed last frame that we no longer kept track of");
161168
continue;
162169
};
170+
update_stats(&desc);
163171
on_destroy_resource(&removed_resource);
164-
self.total_resource_size_in_bytes.fetch_sub(
165-
desc.resource_size_in_bytes(),
166-
std::sync::atomic::Ordering::Relaxed,
167-
);
168172
}
169173
}
170174

@@ -184,6 +188,7 @@ where
184188
.push(resource.handle);
185189
true
186190
} else {
191+
update_stats(&resource.creation_desc);
187192
on_destroy_resource(&resource.inner);
188193
false
189194
}

0 commit comments

Comments
 (0)