Skip to content

Commit 6040820

Browse files
refactor: extract Global::poll_single_device helper
1 parent 9499e8c commit 6040820

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

wgpu-core/src/device/global.rs

+32-15
Original file line numberDiff line numberDiff line change
@@ -2106,19 +2106,32 @@ impl Global {
21062106
}
21072107
}
21082108

2109-
let (closures, queue_empty) = {
2110-
let fence = device.fence.read();
2111-
let fence = fence.as_ref().unwrap();
2112-
device.maintain(fence, maintain)?
2113-
};
2109+
let DevicePoll {
2110+
closures,
2111+
queue_empty,
2112+
} = Self::poll_single_device(&device, maintain)?;
2113+
2114+
closures.fire();
2115+
2116+
Ok(queue_empty)
2117+
}
2118+
2119+
fn poll_single_device<A: HalApi>(
2120+
device: &crate::device::Device<A>,
2121+
maintain: wgt::Maintain<queue::WrappedSubmissionIndex>,
2122+
) -> Result<DevicePoll, WaitIdleError> {
2123+
let fence = device.fence.read();
2124+
let fence = fence.as_ref().unwrap();
2125+
let (closures, queue_empty) = device.maintain(fence, maintain)?;
21142126

21152127
// Some deferred destroys are scheduled in maintain so run this right after
21162128
// to avoid holding on to them until the next device poll.
21172129
device.deferred_resource_destruction();
21182130

2119-
closures.fire();
2120-
2121-
Ok(queue_empty)
2131+
Ok(DevicePoll {
2132+
closures,
2133+
queue_empty,
2134+
})
21222135
}
21232136

21242137
/// Poll all devices belonging to the backend `A`.
@@ -2145,16 +2158,15 @@ impl Global {
21452158
} else {
21462159
wgt::Maintain::Poll
21472160
};
2148-
let fence = device.fence.read();
2149-
let fence = fence.as_ref().unwrap();
2150-
let (cbs, queue_empty) = device.maintain(fence, maintain)?;
2161+
2162+
let DevicePoll {
2163+
closures: cbs,
2164+
queue_empty,
2165+
} = Self::poll_single_device(device, maintain)?;
2166+
21512167
all_queue_empty &= queue_empty;
21522168

21532169
closures.extend(cbs);
2154-
2155-
// Some deferred destroys are scheduled in maintain so run this right after
2156-
// to avoid holding on to them until the next device poll.
2157-
device.deferred_resource_destruction();
21582170
}
21592171
}
21602172

@@ -2567,3 +2579,8 @@ impl Global {
25672579
buffer.unmap()
25682580
}
25692581
}
2582+
2583+
struct DevicePoll {
2584+
closures: UserClosures,
2585+
queue_empty: bool,
2586+
}

0 commit comments

Comments
 (0)