diff --git a/wgpu-core/src/global.rs b/wgpu-core/src/global.rs index fdb77a375d..25a864ec27 100644 --- a/wgpu-core/src/global.rs +++ b/wgpu-core/src/global.rs @@ -24,9 +24,10 @@ impl GlobalReport { } pub struct Global { - pub instance: Instance, pub(crate) surfaces: Registry>, pub(crate) hub: Hub, + // the instance must be dropped last + pub instance: Instance, } impl Global { @@ -88,12 +89,10 @@ impl Drop for Global { fn drop(&mut self) { profiling::scope!("Global::drop"); resource_log!("Global::drop"); - let mut surfaces_locked = self.surfaces.write(); - // destroy hub before the instance gets dropped - self.hub.clear(&surfaces_locked); - - surfaces_locked.map.clear(); + for (_, device) in self.hub.devices.read().iter() { + device.prepare_to_die(); + } } } diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index f4e8b9c756..ae6cbbb874 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -104,11 +104,10 @@ use crate::{ binding_model::{BindGroup, BindGroupLayout, PipelineLayout}, command::{CommandBuffer, RenderBundle}, device::{queue::Queue, Device}, - instance::{Adapter, Surface}, + instance::Adapter, pipeline::{ComputePipeline, PipelineCache, RenderPipeline, ShaderModule}, registry::{Registry, RegistryReport}, resource::{Buffer, Fallible, QuerySet, Sampler, StagingBuffer, Texture, TextureView}, - storage::{Element, Storage}, }; use std::{fmt::Debug, sync::Arc}; @@ -159,8 +158,7 @@ impl HubReport { /// Inside the `Registry` there are `Arc` where `T` is a Resource /// Lock of `Registry` happens only when accessing to get the specific resource /// -/// -/// [`A::hub(global)`]: HalApi::hub +/// [`Storage`]: crate::storage::Storage pub struct Hub { pub(crate) adapters: Registry>, pub(crate) devices: Registry>, @@ -206,46 +204,6 @@ impl Hub { } } - pub(crate) fn clear(&self, surface_guard: &Storage>) { - let mut devices = self.devices.write(); - for element in devices.map.iter() { - if let Element::Occupied(ref device, _) = *element { - device.prepare_to_die(); - } - } - - self.command_buffers.write().map.clear(); - self.samplers.write().map.clear(); - self.texture_views.write().map.clear(); - self.textures.write().map.clear(); - self.buffers.write().map.clear(); - self.bind_groups.write().map.clear(); - self.shader_modules.write().map.clear(); - self.bind_group_layouts.write().map.clear(); - self.pipeline_layouts.write().map.clear(); - self.compute_pipelines.write().map.clear(); - self.render_pipelines.write().map.clear(); - self.pipeline_caches.write().map.clear(); - self.query_sets.write().map.clear(); - - for element in surface_guard.map.iter() { - if let Element::Occupied(ref surface, _epoch) = *element { - if let Some(ref mut present) = surface.presentation.lock().take() { - let suf = surface.raw(present.device.backend()); - unsafe { - suf.unwrap().unconfigure(present.device.raw()); - } - } - } - } - - self.queues.write().map.clear(); - devices.map.clear(); - - drop(devices); - self.adapters.write().map.clear(); - } - pub fn generate_report(&self) -> HubReport { HubReport { adapters: self.adapters.generate_report(),