Skip to content

Commit

Permalink
Return all_queue_empty for Instance::poll_all
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaopengli89 committed May 8, 2022
1 parent 7a050f0 commit edd4d0b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
30 changes: 21 additions & 9 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4974,21 +4974,25 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
/// Poll all devices belonging to the backend `A`.
///
/// If `force_wait` is true, block until all buffer mappings are done.
///
/// Return `all_queue_empty` indicating whether there are more queue submissions still in flight.
fn poll_devices<A: HalApi>(
&self,
force_wait: bool,
closures: &mut UserClosures,
) -> Result<(), WaitIdleError> {
) -> Result<bool, WaitIdleError> {
profiling::scope!("poll_devices");

let hub = A::hub(self);
let mut devices_to_drop = vec![];
let mut all_queue_empty = true;
{
let mut token = Token::root();
let (device_guard, mut token) = hub.devices.read(&mut token);

for (id, device) in device_guard.iter(A::VARIANT) {
let (cbs, queue_empty) = device.maintain(hub, force_wait, &mut token)?;
all_queue_empty = all_queue_empty && queue_empty;

// If the device's own `RefCount` clone is the only one left, and
// its submission queue is empty, then it can be freed.
Expand All @@ -5003,41 +5007,49 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
self.exit_device::<A>(device_id);
}

Ok(())
Ok(all_queue_empty)
}

/// Poll all devices on all backends.
///
/// This is the implementation of `wgpu::Instance::poll_all`.
pub fn poll_all_devices(&self, force_wait: bool) -> Result<(), WaitIdleError> {
///
/// Return `all_queue_empty` indicating whether there are more queue submissions still in flight.
pub fn poll_all_devices(&self, force_wait: bool) -> Result<bool, WaitIdleError> {
let mut closures = UserClosures::default();
let mut all_queue_empty = true;

#[cfg(vulkan)]
{
self.poll_devices::<hal::api::Vulkan>(force_wait, &mut closures)?;
all_queue_empty = self.poll_devices::<hal::api::Vulkan>(force_wait, &mut closures)?
&& all_queue_empty;
}
#[cfg(metal)]
{
self.poll_devices::<hal::api::Metal>(force_wait, &mut closures)?;
all_queue_empty =
self.poll_devices::<hal::api::Metal>(force_wait, &mut closures)? && all_queue_empty;
}
#[cfg(dx12)]
{
self.poll_devices::<hal::api::Dx12>(force_wait, &mut closures)?;
all_queue_empty =
self.poll_devices::<hal::api::Dx12>(force_wait, &mut closures)? && all_queue_empty;
}
#[cfg(dx11)]
{
self.poll_devices::<hal::api::Dx11>(force_wait, &mut closures)?;
all_queue_empty =
self.poll_devices::<hal::api::Dx11>(force_wait, &mut closures)? && all_queue_empty;
}
#[cfg(gl)]
{
self.poll_devices::<hal::api::Gles>(force_wait, &mut closures)?;
all_queue_empty =
self.poll_devices::<hal::api::Gles>(force_wait, &mut closures)? && all_queue_empty;
}

unsafe {
closures.fire();
}

Ok(())
Ok(all_queue_empty)
}

pub fn device_label<A: HalApi>(&self, id: id::DeviceId) -> String {
Expand Down
4 changes: 2 additions & 2 deletions wgpu/src/backend/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,10 +824,10 @@ impl crate::Context for Context {
ready(id.ok())
}

fn instance_poll_all_devices(&self, force_wait: bool) {
fn instance_poll_all_devices(&self, force_wait: bool) -> bool {
let global = &self.0;
match global.poll_all_devices(force_wait) {
Ok(()) => (),
Ok(all_queue_empty) => all_queue_empty,
Err(err) => self.handle_error_fatal(err, "Device::poll"),
}
}
Expand Down
8 changes: 5 additions & 3 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ trait Context: Debug + Send + Sized + Sync {
desc: &DeviceDescriptor,
trace_dir: Option<&std::path::Path>,
) -> Self::RequestDeviceFuture;
fn instance_poll_all_devices(&self, force_wait: bool);
fn instance_poll_all_devices(&self, force_wait: bool) -> bool;
fn adapter_is_surface_supported(
&self,
adapter: &Self::AdapterId,
Expand Down Expand Up @@ -1563,8 +1563,10 @@ impl Instance {
/// Polls all devices.
/// If `force_wait` is true and this is not running on the web,
/// then this function will block until all in-flight buffers have been mapped.
pub fn poll_all(&self, force_wait: bool) {
self.context.instance_poll_all_devices(force_wait);
///
/// Return `all_queue_empty` indicating whether there are more queue submissions still in flight.
pub fn poll_all(&self, force_wait: bool) -> bool {
self.context.instance_poll_all_devices(force_wait)
}

/// Generates memory report.
Expand Down

0 comments on commit edd4d0b

Please sign in to comment.