Commit 8c3320fe9165
tarball1 file changed+16-2
@@ -2,16 +2,25 @@ use crate::Error;
22
use ash::vk;33
use gpu_allocator::AllocationSizes;44
use gpu_allocator::vulkan::{Allocator, AllocatorCreateDesc};5
+use std::mem::ManuallyDrop;56
use std::sync::Mutex;67
78
/// Everything that must outlive every Vulkan object the renderer hands out.89
/// Fields drop in declaration order, so the allocator frees its memory before910
/// the device is destroyed.1011
pub(crate) struct Shared {11
- pub allocator: Mutex<Allocator>,12
+ pub allocator: ManuallyDrop<Mutex<Allocator>>,1213
pub device: Device,1314
}1415
16
+impl Drop for Shared {17
+ fn drop(&mut self) {18
+ if !crate::error::device_lost() {19
+ unsafe { ManuallyDrop::drop(&mut self.allocator) };20
+ }21
+ }22
+}23
+1524
/// Loaders for the extensions that dmabuf import, export and fence export1625
/// need. Absent when the device lacks any of them.1726
pub(crate) struct DmabufExt {@@ -43,8 +52,13 @@ pub(crate) struct Device {
4352
pub spare_fences: Mutex<Vec<vk::Fence>>,4453
}4554
55
+/// A lost or hung device is leaked. Waiting on it or destroying it can block56
+/// forever in the driver, and the process is about to exit anyway.4657
impl Drop for Device {4758
fn drop(&mut self) {59
+ if crate::error::device_lost() {60
+ return;61
+ }4862
unsafe {4963
let _ = self.device.device_wait_idle();5064
for f in self@@ -202,7 +216,7 @@ impl Shared {
202216
spare_fences: Mutex::new(Vec::new()),203217
};204218
Ok(Self {205
- allocator: Mutex::new(allocator?),219
+ allocator: ManuallyDrop::new(Mutex::new(allocator?)),206220
device,207221
})208222
}