Skip to content

Pass DeviceLostCallback in at device creation time. #173

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

Closed
toji opened this issue Feb 10, 2023 · 4 comments
Closed

Pass DeviceLostCallback in at device creation time. #173

toji opened this issue Feb 10, 2023 · 4 comments

Comments

@toji
Copy link

toji commented Feb 10, 2023

The WebGPU spec was changed a little while back to return a device which has already been lost rather than a null device if requestDevice fails. This poses some complications for the current wgpuDeviceSetDeviceLostCallback() API in webgpu.h

Since wgpuDeviceSetDeviceLostCallback() cannot be called until a device is acquired, with the updated logic there's no way to set the callback until the device has already been lost. This then necessitates that the lost reason and message be cached if there is not callback set until a callback is eventually set, which would fire immediately upon setting. When attempting to implement this in Dawn I found that the logic was unexpectedly tricky and contained multiple subtle edge cases.

A cleaner alternative would be to pass the device lost callback and userdata in at device creation time as part of the descriptor and remove the wgpuDeviceSetDeviceLostCallback() call entirely. This way the device will be able to use a unified path for handling any device loss at any point in time. Applications that need more flexibility will still be able to build their own message propagation system on top of it, and can probably do it more confidently since this change would remove questions such as "What happens if I set the callback twice?"

New descriptor would look like this:

typedef struct WGPUDeviceDescriptor {
    WGPUChainedStruct const * nextInChain;
    char const * label; // nullable
    uint32_t requiredFeaturesCount;
    WGPUFeatureName const * requiredFeatures;
    WGPURequiredLimits const * requiredLimits; // nullable
    WGPUQueueDescriptor defaultQueue;
+   WGPUDeviceLostCallback deviceLostCallback;
+   void * deviceLostUserdata;
} WGPUDeviceDescriptor;

Any concerns?

@Kangz
Copy link
Collaborator

Kangz commented Feb 13, 2023

I would like the opinion from wgpu folks as well: @cwfitzgerald @teoxoy?

@teoxoy
Copy link

teoxoy commented Feb 14, 2023

The proposal looks solid to me.

@Beyley
Copy link

Beyley commented Jun 27, 2023

This seems to have been completed in
8f819a4

@kainino0x
Copy link
Collaborator

Indeed!

@kainino0x kainino0x mentioned this issue Mar 26, 2024
3 tasks
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

No branches or pull requests

5 participants