Support creating invalid devices in wgpu-core
https://gpuweb.github.io/gpuweb/#dom-gpuadapter-requestdevice says that it can return invalid GPUDevice:
- If adapter.[[state]] is "expired" or the user agent otherwise cannot fulfill the request:
- Let device be a new device.
- Lose the device(device, "unknown").
but this is currently not possible in wgpu-core, because we use ? before id assign:
https://github.com/gfx-rs/wgpu/blob/64698614786dd55c31bce803c2d5217cf84c2b95/wgpu-core/src/instance.rs#L1194-L1200
typically we do:
For other resources we usually return invalid objects (as per specs): https://github.com/gfx-rs/wgpu/blob/64698614786dd55c31bce803c2d5217cf84c2b95/wgpu-core/src/device/global.rs#L146
and we should do it here too.
This is problematic in servo and it will be in firefox too once it starts to differentiate errors like it should per spec instead of just mapping all of them to OperationError: https://searchfox.org/firefox-main/rev/a9196d32a914f0bcf6b76168b83c70e61bc90980/dom/webgpu/ipc/WebGPUChild.cpp#133
Alternatives considered
Change the spec. Instead of returning invalid device we could just throw some error or return null (like it's done for adapter). For other resources it make sense to have invalid state (to get the async of timelines), but here we already have promise so this is kind of stupid.
Source: gfx-rs/wgpu