Skip to content

Commit

Permalink
Return queue_empty for Device::poll
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaopengli89 committed May 5, 2022
1 parent af259aa commit 7a050f0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion deno_webgpu/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub async fn op_webgpu_buffer_get_map_async(
{
let state = state.borrow();
let instance = state.borrow::<super::Instance>();
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;
}
Expand Down
8 changes: 5 additions & 3 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4949,12 +4949,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}

/// 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<A: HalApi>(
&self,
device_id: id::DeviceId,
force_wait: bool,
) -> Result<(), WaitIdleError> {
let (closures, _) = {
) -> Result<bool, WaitIdleError> {
let (closures, queue_empty) = {
let hub = A::hub(self);
let mut token = Token::root();
let (device_guard, mut token) = hub.devices.read(&mut token);
Expand All @@ -4966,7 +4968,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
unsafe {
closures.fire();
}
Ok(())
Ok(queue_empty)
}

/// Poll all devices belonging to the backend `A`.
Expand Down
6 changes: 3 additions & 3 deletions wgpu/src/backend/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1554,15 +1554,15 @@ 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"),
}
}

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,
Expand All @@ -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"),
}
}
Expand Down
3 changes: 2 additions & 1 deletion wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 5 additions & 3 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 7a050f0

Please sign in to comment.