Skip to content

Commit

Permalink
remove Hub.clear()
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy committed Oct 14, 2024
1 parent 3eb9c78 commit c0e3972
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 50 deletions.
11 changes: 5 additions & 6 deletions wgpu-core/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ impl GlobalReport {
}

pub struct Global {
pub instance: Instance,
pub(crate) surfaces: Registry<Arc<Surface>>,
pub(crate) hub: Hub,
// the instance must be dropped last
pub instance: Instance,
}

impl Global {
Expand Down Expand Up @@ -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();
}
}
}

Expand Down
46 changes: 2 additions & 44 deletions wgpu-core/src/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -159,8 +158,7 @@ impl HubReport {
/// Inside the `Registry` there are `Arc<T>` 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<Arc<Adapter>>,
pub(crate) devices: Registry<Arc<Device>>,
Expand Down Expand Up @@ -206,46 +204,6 @@ impl Hub {
}
}

pub(crate) fn clear(&self, surface_guard: &Storage<Arc<Surface>>) {
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(),
Expand Down

0 comments on commit c0e3972

Please sign in to comment.