Return queue_empty for Device::poll

This commit is contained in:
xiaopengli89
2022-05-05 14:58:22 +08:00
committed by Jim Blandy
parent 72dd9d77db
commit 3f3af605db
5 changed files with 16 additions and 11 deletions

View File

@@ -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;
}

View File

@@ -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);
@@ -4966,7 +4968,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
unsafe {
closures.fire();
}
Ok(())
Ok(queue_empty)
}
/// Poll all devices belonging to the backend `A`.

View File

@@ -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"),
}
}

View File

@@ -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(

View File

@@ -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.