From 7a050f09b237a2dff1ca303df288a14c8cfede48 Mon Sep 17 00:00:00 2001 From: xiaopengli89 Date: Thu, 5 May 2022 14:58:22 +0800 Subject: [PATCH] Return `queue_empty` for Device::poll --- deno_webgpu/src/buffer.rs | 2 +- wgpu-core/src/device/mod.rs | 8 +++++--- wgpu/src/backend/direct.rs | 6 +++--- wgpu/src/backend/web.rs | 3 ++- wgpu/src/lib.rs | 8 +++++--- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/deno_webgpu/src/buffer.rs b/deno_webgpu/src/buffer.rs index 845f218372f..45eab483d15 100644 --- a/deno_webgpu/src/buffer.rs +++ b/deno_webgpu/src/buffer.rs @@ -128,7 +128,7 @@ pub async fn op_webgpu_buffer_get_map_async( { let state = state.borrow(); let instance = state.borrow::(); - gfx_select!(device => instance.device_poll(device, false)).unwrap() + gfx_select!(device => instance.device_poll(device, false)).unwrap(); } tokio::time::sleep(Duration::from_millis(10)).await; } diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 760de1195c6..9d014c39c9d 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -4949,12 +4949,14 @@ impl Global { } /// Check `device_id` for freeable resources and completed buffer mappings. + /// + /// Return `queue_empty` indicating whether there are more queue submissions still in flight. pub fn device_poll( &self, device_id: id::DeviceId, force_wait: bool, - ) -> Result<(), WaitIdleError> { - let (closures, _) = { + ) -> Result { + let (closures, queue_empty) = { let hub = A::hub(self); let mut token = Token::root(); let (device_guard, mut token) = hub.devices.read(&mut token); @@ -4966,7 +4968,7 @@ impl Global { unsafe { closures.fire(); } - Ok(()) + Ok(queue_empty) } /// Poll all devices belonging to the backend `A`. diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 753b08d9424..62014032f1c 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -1554,7 +1554,7 @@ impl crate::Context for Context { #[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))] { match wgc::gfx_select!(device.id => global.device_poll(device.id, true)) { - Ok(()) => (), + Ok(_) => (), Err(err) => self.handle_error_fatal(err, "Device::drop"), } } @@ -1562,7 +1562,7 @@ impl crate::Context for Context { wgc::gfx_select!(device.id => global.device_drop(device.id)); } - fn device_poll(&self, device: &Self::DeviceId, maintain: crate::Maintain) { + fn device_poll(&self, device: &Self::DeviceId, maintain: crate::Maintain) -> bool { let global = &self.0; match wgc::gfx_select!(device.id => global.device_poll( device.id, @@ -1571,7 +1571,7 @@ impl crate::Context for Context { crate::Maintain::Wait => true, } )) { - Ok(()) => (), + Ok(queue_empty) => queue_empty, Err(err) => self.handle_error_fatal(err, "Device::poll"), } } diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index d45d491f411..6e766b06a79 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -1691,8 +1691,9 @@ impl crate::Context for Context { // Device is dropped automatically } - fn device_poll(&self, _device: &Self::DeviceId, _maintain: crate::Maintain) { + fn device_poll(&self, _device: &Self::DeviceId, _maintain: crate::Maintain) -> bool { // Device is polled automatically + true } fn device_on_uncaptured_error( diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index afe3e7ac8ab..1463e179611 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -322,7 +322,7 @@ trait Context: Debug + Send + Sized + Sync { desc: &RenderBundleEncoderDescriptor, ) -> Self::RenderBundleEncoderId; fn device_drop(&self, device: &Self::DeviceId); - fn device_poll(&self, device: &Self::DeviceId, maintain: Maintain); + fn device_poll(&self, device: &Self::DeviceId, maintain: Maintain) -> bool; fn device_on_uncaptured_error( &self, device: &Self::DeviceId, @@ -1687,9 +1687,11 @@ impl Adapter { impl Device { /// Check for resource cleanups and mapping callbacks. /// + /// Return `queue_empty` indicating whether there are more queue submissions still in flight. + /// /// no-op on the web, device is automatically polled. - pub fn poll(&self, maintain: Maintain) { - Context::device_poll(&*self.context, &self.id, maintain); + pub fn poll(&self, maintain: Maintain) -> bool { + Context::device_poll(&*self.context, &self.id, maintain) } /// List all features that may be used with this device.