From c0e39721a2dd4030015e7c0bee949dc95878f7ce Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Fri, 11 Oct 2024 18:52:49 +0200 Subject: [PATCH] remove `Hub.clear()` --- wgpu-core/src/global.rs | 11 +++++----- wgpu-core/src/hub.rs | 46 ++--------------------------------------- 2 files changed, 7 insertions(+), 50 deletions(-) diff --git a/wgpu-core/src/global.rs b/wgpu-core/src/global.rs index fdb77a375..25a864ec2 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 f4e8b9c75..ae6cbbb87 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(),