mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-23 16:01:04 +01:00
fix: unlock guard for release_gpu_resources call in Device::maintain
This commit is contained in:
1 parent
d828f27de4
commit
0c5bebca51
4 files changed
+46
-6
No files matched your search
@@ -776,3 +776,42 @@ fn vs_main() -> @builtin(position) vec4<f32> {
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
#[gpu_test]
|
||||
static DEVICE_DESTROY_THEN_BUFFER_CLEANUP: GpuTestConfiguration = GpuTestConfiguration::new()
|
||||
.parameters(TestParameters::default())
|
||||
.run_sync(|ctx| {
|
||||
// When a device is destroyed, its resources should be released,
|
||||
// without causing a deadlock.
|
||||
|
||||
// Create a buffer to be left around until the device is destroyed.
|
||||
let _buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: None,
|
||||
size: 256,
|
||||
usage: wgpu::BufferUsages::MAP_READ,
|
||||
mapped_at_creation: false,
|
||||
});
|
||||
|
||||
// Create a texture to be left around until the device is destroyed.
|
||||
let texture_extent = wgpu::Extent3d {
|
||||
width: 512,
|
||||
height: 512,
|
||||
depth_or_array_layers: 1,
|
||||
};
|
||||
let _texture = ctx.device.create_texture(&wgpu::TextureDescriptor {
|
||||
label: None,
|
||||
size: texture_extent,
|
||||
mip_level_count: 2,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: wgpu::TextureFormat::Rg8Uint,
|
||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||
view_formats: &[],
|
||||
});
|
||||
|
||||
// Destroy the device.
|
||||
ctx.device.destroy();
|
||||
|
||||
// Poll the device, which should try to clean up its resources.
|
||||
ctx.instance.poll_all(true);
|
||||
});
|
||||
@@ -2019,7 +2019,7 @@ impl Global {
|
||||
let snatch_guard = device.snatchable_lock.read();
|
||||
let fence = device.fence.read();
|
||||
let fence = fence.as_ref().unwrap();
|
||||
match device.maintain(fence, wgt::Maintain::Wait, &snatch_guard) {
|
||||
match device.maintain(fence, wgt::Maintain::Wait, snatch_guard) {
|
||||
Ok((closures, _)) => {
|
||||
user_callbacks = closures;
|
||||
}
|
||||
@@ -2132,7 +2132,7 @@ impl Global {
|
||||
let snatch_guard = device.snatchable_lock.read();
|
||||
let fence = device.fence.read();
|
||||
let fence = fence.as_ref().unwrap();
|
||||
let (closures, queue_empty) = device.maintain(fence, maintain, &snatch_guard)?;
|
||||
let (closures, queue_empty) = device.maintain(fence, maintain, snatch_guard)?;
|
||||
|
||||
// Some deferred destroys are scheduled in maintain so run this right after
|
||||
// to avoid holding on to them until the next device poll.
|
||||
|
||||
@@ -1545,7 +1545,7 @@ impl Global {
|
||||
|
||||
// This will schedule destruction of all resources that are no longer needed
|
||||
// by the user but used in the command stream, among other things.
|
||||
let (closures, _) = match device.maintain(fence, wgt::Maintain::Poll, &snatch_guard) {
|
||||
let (closures, _) = match device.maintain(fence, wgt::Maintain::Poll, snatch_guard) {
|
||||
Ok(closures) => closures,
|
||||
Err(WaitIdleError::Device(err)) => return Err(QueueSubmitError::Queue(err)),
|
||||
Err(WaitIdleError::StuckGpu) => return Err(QueueSubmitError::StuckGpu),
|
||||
|
||||
@@ -394,7 +394,7 @@ impl<A: HalApi> Device<A> {
|
||||
&'this self,
|
||||
fence: &A::Fence,
|
||||
maintain: wgt::Maintain<queue::WrappedSubmissionIndex>,
|
||||
snatch_guard: &SnatchGuard,
|
||||
snatch_guard: SnatchGuard,
|
||||
) -> Result<(UserClosures, bool), WaitIdleError> {
|
||||
profiling::scope!("Device::maintain");
|
||||
let last_done_index = if maintain.is_wait() {
|
||||
@@ -449,7 +449,7 @@ impl<A: HalApi> Device<A> {
|
||||
}
|
||||
|
||||
let mapping_closures =
|
||||
life_tracker.handle_mapping(self.raw(), &self.trackers, snatch_guard);
|
||||
life_tracker.handle_mapping(self.raw(), &self.trackers, &snatch_guard);
|
||||
|
||||
let queue_empty = life_tracker.queue_empty();
|
||||
|
||||
@@ -476,8 +476,9 @@ impl<A: HalApi> Device<A> {
|
||||
}
|
||||
}
|
||||
|
||||
// Don't hold the lock while calling release_gpu_resources.
|
||||
// Don't hold the locks while calling release_gpu_resources.
|
||||
drop(life_tracker);
|
||||
drop(snatch_guard);
|
||||
|
||||
if should_release_gpu_resource {
|
||||
self.release_gpu_resources();
|
||||
|
||||
Reference in new issue
Block a user