1023: Drop surfaces and adapters r=cwfitzgerald a=kvark

**Connections**
Not very connected

**Description**
Refactors our destruction paths a bit

**Testing**
tested on wgpu-rs

Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
This commit is contained in:
bors[bot] 2020-11-13 23:50:28 +00:00 committed by GitHub
commit af9713b249
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 13 deletions

View File

@ -641,13 +641,17 @@ impl<B: GfxBackend, F: GlobalIdentityHandlerFactory> Hub<B, F> {
for (index, element) in self.swap_chains.data.write().map.drain(..).enumerate() {
if let Element::Occupied(swap_chain, epoch) = element {
let device = &devices[swap_chain.device_id.value];
let surface = surface_guard
.get_mut(TypedId::zip(index as Index, epoch, B::VARIANT))
.unwrap();
let suf = B::get_surface_mut(surface);
unsafe {
device.raw.destroy_semaphore(swap_chain.semaphore);
suf.unconfigure_swapchain(&device.raw);
}
let suf_id = TypedId::zip(index as Index, epoch, B::VARIANT);
//TODO: hold the surface alive by the swapchain
if surface_guard.contains(suf_id) {
let surface = surface_guard.get_mut(suf_id).unwrap();
let suf = B::get_surface_mut(surface);
unsafe {
suf.unconfigure_swapchain(&device.raw);
}
}
}
}

View File

@ -67,26 +67,26 @@ impl Instance {
}
}
pub(crate) fn destroy_surface(&mut self, surface: Surface) {
pub(crate) fn destroy_surface(&self, surface: Surface) {
backends_map! {
let map = |(surface_backend, self_backend)| {
unsafe {
if let Some(suf) = surface_backend {
self_backend.as_mut().unwrap().destroy_surface(suf);
self_backend.as_ref().unwrap().destroy_surface(suf);
}
}
};
#[cfg(vulkan)]
map((surface.vulkan, &mut self.vulkan)),
map((surface.vulkan, &self.vulkan)),
#[cfg(metal)]
map((surface.metal, &mut self.metal)),
map((surface.metal, &self.metal)),
#[cfg(dx12)]
map((surface.dx12, &mut self.dx12)),
map((surface.dx12, &self.dx12)),
#[cfg(dx11)]
map((surface.dx11, &mut self.dx11)),
map((surface.dx11, &self.dx11)),
#[cfg(gl)]
map((surface.gl, &mut self.gl)),
map((surface.gl, &self.gl)),
}
}
}
@ -373,6 +373,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
id.0
}
pub fn surface_drop(&self, id: SurfaceId) {
span!(_guard, INFO, "Surface::drop");
let mut token = Token::root();
let (surface, _) = self.surfaces.unregister(id, &mut token);
self.instance.destroy_surface(surface.unwrap());
}
pub fn enumerate_adapters(&self, inputs: AdapterInputs<Input<G, AdapterId>>) -> Vec<AdapterId> {
span!(_guard, INFO, "Instance::enumerate_adapters");
@ -613,7 +620,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.map_err(|_| InvalidAdapter)
}
pub fn adapter_destroy<B: GfxBackend>(&self, adapter_id: AdapterId) {
pub fn adapter_drop<B: GfxBackend>(&self, adapter_id: AdapterId) {
span!(_guard, INFO, "Adapter::drop");
let hub = B::hub(self);