Release GPU resources from device.trackers, not from lifetime_tracker. (#5075)

This commit is contained in:
Brad Werth
2024-01-22 08:55:42 -08:00
committed by GitHub
parent 20f3a9fdf1
commit ac8756c2d3
3 changed files with 25 additions and 46 deletions

View File

@@ -45,6 +45,8 @@ Bottom level categories:
### New features
#### General
- Many numeric built-ins have had a constant evaluation implementation added for them, which allows them to be used in a `const` context:
- [#4879](https://github.com/gfx-rs/wgpu/pull/4879) by @ErichDonGubler:
- `abs`
@@ -64,6 +66,8 @@ Bottom level categories:
- `step`
- `tan`
- `tanh`
- Eager release of GPU resources comes from device.trackers. By @bradwerth in [#5075](https://github.com/gfx-rs/wgpu/pull/5075)
### Bug Fixes

View File

@@ -837,47 +837,4 @@ impl<A: HalApi> LifetimeTracker<A> {
}
pending_callbacks
}
pub(crate) fn release_gpu_resources(&mut self) {
// This is called when the device is lost, which makes every associated
// resource invalid and unusable. This is an opportunity to release all of
// the underlying gpu resources, even though the objects remain visible to
// the user agent. We purge this memory naturally when resources have been
// moved into the appropriate buckets, so this function just needs to
// initiate movement into those buckets, and it can do that by calling
// "destroy" on all the resources we know about which aren't already marked
// for cleanup.
// During these iterations, we discard all errors. We don't care!
// Destroy all the mapped buffers.
for buffer in &self.mapped {
let _ = buffer.destroy();
}
// Destroy all the unmapped buffers.
for buffer in &self.ready_to_map {
let _ = buffer.destroy();
}
// Destroy all the future_suspected_buffers.
for buffer in &self.future_suspected_buffers {
let _ = buffer.destroy();
}
// Destroy the buffers in all active submissions.
for submission in &self.active {
for buffer in &submission.mapped {
let _ = buffer.destroy();
}
}
// Destroy all the future_suspected_textures.
// TODO: texture.destroy is not implemented
/*
for texture in &self.future_suspected_textures {
let _ = texture.destroy();
}
*/
}
}

View File

@@ -380,7 +380,7 @@ impl<A: HalApi> Device<A> {
let mut device_lost_invocations = SmallVec::new();
if !self.is_valid() && life_tracker.queue_empty() {
// We can release gpu resources associated with this device.
life_tracker.release_gpu_resources();
self.release_gpu_resources();
// If we have a DeviceLostClosure, build an invocation with the
// reason DeviceLostReason::Destroyed and no message.
@@ -3331,7 +3331,6 @@ impl<A: HalApi> Device<A> {
// It's important to not hold the lock while calling the closure.
drop(life_lock);
device_lost_closure.call(DeviceLostReason::Unknown, message.to_string());
life_lock = self.lock_life();
}
// 2) Complete any outstanding mapAsync() steps.
@@ -3343,7 +3342,26 @@ impl<A: HalApi> Device<A> {
// until they are cleared, and then drop the device.
// Eagerly release GPU resources.
life_lock.release_gpu_resources();
self.release_gpu_resources();
}
pub(crate) fn release_gpu_resources(&self) {
// This is called when the device is lost, which makes every associated
// resource invalid and unusable. This is an opportunity to release all of
// the underlying gpu resources, even though the objects remain visible to
// the user agent. We purge this memory naturally when resources have been
// moved into the appropriate buckets, so this function just needs to
// initiate movement into those buckets, and it can do that by calling
// "destroy" on all the resources we know about.
// During these iterations, we discard all errors. We don't care!
let trackers = self.trackers.lock();
for buffer in trackers.buffers.used_resources() {
let _ = buffer.destroy();
}
for texture in trackers.textures.used_resources() {
let _ = texture.destroy();
}
}
}