diff --git a/CHANGELOG.md b/CHANGELOG.md index 243f35b767..485945fa39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/wgpu-core/src/device/life.rs b/wgpu-core/src/device/life.rs index 22699d1068..b454fcaa8f 100644 --- a/wgpu-core/src/device/life.rs +++ b/wgpu-core/src/device/life.rs @@ -837,47 +837,4 @@ impl LifetimeTracker { } 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(); - } - */ - } } diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 547774ec63..3523981562 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -380,7 +380,7 @@ impl Device { 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 Device { // 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 Device { // 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(); + } } }