From 6040820099bc72b827a6a5f53d66dda3e301f944 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Mon, 11 Mar 2024 12:28:24 -0400 Subject: [PATCH] refactor: extract `Global::poll_single_device` helper --- wgpu-core/src/device/global.rs | 47 +++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index 8a997e40fd..539b92e0f3 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -2106,19 +2106,32 @@ impl Global { } } - let (closures, queue_empty) = { - let fence = device.fence.read(); - let fence = fence.as_ref().unwrap(); - device.maintain(fence, maintain)? - }; + let DevicePoll { + closures, + queue_empty, + } = Self::poll_single_device(&device, maintain)?; + + closures.fire(); + + Ok(queue_empty) + } + + fn poll_single_device( + device: &crate::device::Device, + maintain: wgt::Maintain, + ) -> Result { + let fence = device.fence.read(); + let fence = fence.as_ref().unwrap(); + let (closures, queue_empty) = device.maintain(fence, maintain)?; // Some deferred destroys are scheduled in maintain so run this right after // to avoid holding on to them until the next device poll. device.deferred_resource_destruction(); - closures.fire(); - - Ok(queue_empty) + Ok(DevicePoll { + closures, + queue_empty, + }) } /// Poll all devices belonging to the backend `A`. @@ -2145,16 +2158,15 @@ impl Global { } else { wgt::Maintain::Poll }; - let fence = device.fence.read(); - let fence = fence.as_ref().unwrap(); - let (cbs, queue_empty) = device.maintain(fence, maintain)?; + + let DevicePoll { + closures: cbs, + queue_empty, + } = Self::poll_single_device(device, maintain)?; + all_queue_empty &= queue_empty; closures.extend(cbs); - - // Some deferred destroys are scheduled in maintain so run this right after - // to avoid holding on to them until the next device poll. - device.deferred_resource_destruction(); } } @@ -2567,3 +2579,8 @@ impl Global { buffer.unmap() } } + +struct DevicePoll { + closures: UserClosures, + queue_empty: bool, +}