remove Hub.clear()

This commit is contained in:
teoxoy 2024-10-11 18:52:49 +02:00 committed by Teodor Tanasoaia
parent 3eb9c781cf
commit c0e39721a2
2 changed files with 7 additions and 50 deletions

View File

@ -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 {
@ -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();
}
}
}

View File

@ -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<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>>,
@ -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(),