fix(core): re-read the fence before the queue-empty assert in Device::maintain (#9958)

This commit is contained in:
AdrianEddy authored and GitHub committed 2026-08-07 23:44:56 +00:00
1 parent 41bac0dffb
commit 385520f72f
2 files changed
+31 -11

No files matched your search

+1
View File
@@ -83,6 +83,7 @@ Bottom level categories:
- Zero-initialize padding (if any) at the end of a buffer allocation. This was application-visible in rare cases on Vulkan when a shader read beyond the valid range of a vertex buffer. By @andyleiserson in [#9791](https://github.com/gfx-rs/wgpu/pull/9791).
- Fix required immediate slots calculation and remove `naga::valid::FunctionInfo::immediate_slots_used`. By @beicause in [#9725](https://github.com/gfx-rs/wgpu/pull/9725).
- Fix a spurious assertion failure in `Device::maintain` when multiple threads race polling the same device. By @AdrianEddy in [#9958](https://github.com/gfx-rs/wgpu/pull/9958).
- Fix `PendingSubmission` releasing its lock guards out of stacking order, which tripped `--cfg wgpu_validate_locks` on any submission. By @AdrianEddy in [#9960](https://github.com/gfx-rs/wgpu/pull/9960).
- Fixed some cases where initialization tracking was not correct. By @andyleiserson in [#10002](https://github.com/gfx-rs/wgpu/pull/10002).
+30 -11
View File
@@ -993,8 +993,10 @@ impl Device {
wgt::PollType::Poll => None,
};
// Wait for the submission index if requested.
if let Some(target_submission_index) = wait_submission_index {
// If a target submission index was specified, wait for it, and set
// `wait_succeeded` to `Some(bool)` indicating success or timeout. If
// no target was specified, set `wait_succeeded` to `None`.
let wait_succeeded = if let Some(target_submission_index) = wait_submission_index {
log::trace!("Device::maintain: waiting for submission index {target_submission_index}");
let wait_timeout = match poll_type {
@@ -1009,13 +1011,16 @@ impl Device {
.wait(self.fence.as_ref(), target_submission_index, wait_timeout)
};
// This error match is only about `DeviceErrors`. At this stage we do not care if
// the wait succeeded or not, and the `Ok(bool)`` variant is ignored.
if let Err(e) = wait_result {
let hal_error: WaitIdleError = self.handle_hal_error(e).into();
return (user_closures, Err(hal_error));
match wait_result {
Ok(succeeded) => Some(succeeded),
Err(e) => {
let hal_error: WaitIdleError = self.handle_hal_error(e).into();
return (user_closures, Err(hal_error));
}
}
}
} else {
None
};
// Get the currently finished submission index. This may be higher than the requested
// wait, or it may be less than the requested wait if the wait failed.
@@ -1071,10 +1076,22 @@ impl Device {
// Based on the queue empty status, and the current finished submission index, determine
// the result of the poll.
let result = if queue_empty {
//
// After a successful wait, `current_finished_submission` should match or exceed
// the target. But after a timeout, more work may have finished before
// `current_finished_submission` is read, so it could be on either side of the
// target, and the queue can also become empty before `Queue::maintain`
// computes `queue_empty`.
//
// We report as accurately as we can with the information available. In
// particular, when our wait timed out but `queue_empty` comes back `true`, we
// report `WaitSucceeded` if `current_finished_submission` reached the target,
// and `Timeout` if it didn't. We don't want to risk reporting `QueueEmpty`
// without actually having seen that the target submission is retired.
let result = if queue_empty && wait_succeeded != Some(false) {
if let Some(wait_submission_index) = wait_submission_index {
// Assert to ensure that if we received a queue empty status, the fence shows the
// correct value. This is defensive, as this should never be hit.
// Sanity-check that we don't report `QueueEmpty` without
// reaching the target submission index.
assert!(
current_finished_submission >= wait_submission_index,
concat!(
@@ -1084,6 +1101,8 @@ impl Device {
current_finished_submission,
wait_submission_index,
);
} else {
// We didn't wait (passive poll), safe to report `QueueEmpty`.
}
Ok(wgt::PollStatus::QueueEmpty)