Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More complete implementation of "lose the device". #4299

Closed
wants to merge 6 commits into from

Conversation

bradwerth
Copy link
Contributor

@bradwerth bradwerth commented Oct 25, 2023

Checklist

  • Run cargo clippy.
  • Run cargo clippy --target wasm32-unknown-unknown if applicable.
  • Add change to CHANGELOG.md. See simple instructions inside file.

Connections
N/A

Description
This provides a way for wgpu-core to specify a callback on "lose the device". It ensures this callback is called at the appropriate times: either after device.destroy has empty queues, or on demand from device.lose.

Testing
A test has been added to device.rs.

The LoseDeviceClosure is called in two cases:

1) It is returned as one of the closures from `maintain` if
`Device.destroy` has been called. This helps implement the spec for
`destroy` that says that "lose the device" is the final step after the
queues have emptied.
2) It is called directly by `Device.lose`.

To accomplish this, `Device.valid` is set to false in `destroy`, which
is not compliant with the spec but is necessary to ensure that no new
work is enqueued after `destroy`. This means that such calls will return
`DeviceError::InvalidDevice` Errs during this period, similarly to how
they already do after "lose the device". Possibly calls during one or
both of these periods should instant fail silently and return `Ok`, to
be handled in a future patch.
In order to supply a DeviceLoseClosure, the test harness has to be given
access to wgpu-core, so this patch modifies the Cargo files to do that.

The new test confirms that the closure gets the expected value *if it is
run*. As noted in a comment in the test, a more robust test that
confirms the closure has been called requires the test function to
become async, which imposes restrictions on how the test is run.
@bradwerth bradwerth requested a review from a team as a code owner October 25, 2023 20:31
Copy link
Contributor

@nical nical left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer the terminology to match the spec more for API entry points:

  • LoseDeviceClosure -> DeviceLostClosure
  • set_lose_device_callback -> set_device_lost_callback
  • etc.

The spec uses "lose the device" for descriptions of the steps to take but APIs use "lost".

With the exception of fn device_lose(...) which if I understand correctly is the internal entry point for marking that device was lost and isn't part of the public API so we can be a bit more free with the terminology, (or you could rename it into device_mark_lost).

@bradwerth
Copy link
Contributor Author

I'm in some kind of merge hell here, trying to rebase back onto trunk, and I'm really tempted to resubmit as a new PR. If no objections in the next hours, I'll do that.

@bradwerth
Copy link
Contributor Author

Abandoned in favor of #4645.

@bradwerth bradwerth closed this Nov 6, 2023
@bradwerth bradwerth deleted the deviceLose branch November 6, 2023 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants