-
Notifications
You must be signed in to change notification settings - Fork 45
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
What is the recommended way for embedding WebGPU in an existing event loop? #491
Comments
It's unfortunately a little bit theoretical still! We have not yet done the work to try to integrate this into Chromium's event loop yet; some people have been looking at Kotlin bindings, but I don't know if they have an integration into the Kotlin runtime yet. With just WaitAny, you do indeed need a thread to sit and wait on things, though unfortunately we don't yet really have a way to interrupt WaitAny early so you can add more futures to the list to wait on, so it still needs to have unnecessary wakes. There's a more integrated idea where we'll expose these as OS events, like D3D does. Explained here: |
I filed #495 about this because we should have it. |
And #496 about this. |
I have been playing with the native dawn APIs to implement the idea of polling in a thread, and I think the current public APIs are quite cumbersome for the purpose. To use Would it be possible to expose (Which led me to another question: is it fine if my app never calls |
cc @lokokung who knows more about Dawn.
That's a deficiency of Dawn's multithreading support (which is not very good); this header says it should work.
Beware of two things:
In theory yes, it's fine, as long as every event is either waited or set to Spontaneous. (I'm sure I've written this down somewhere, but I don't see it in the docs, so we need to document this. (EDIT: #498)) In Dawn right now I'm not sure, it might be possible for things to get stuck if you don't call something that Ticks (ProcessEvents, Tick, Submit, etc.) |
Thanks for your insights!
Calling
Ahh I didn't realize the method does not actually wait! From embedder's side I want a simple API that polls all futures, and another API that interrupts the polling. I'm currently using a custom event for interruption and bookkeeping all the futures created, which is really tedious: struct InterruptEvent final : public dawn::native::EventManager::TrackedEvent {
...
}; |
Jan 23 meeting:
|
|
The WGPUFuture issue (#199) mentioned providing solutions for embedding WebGPU in an existing event loop, like the GPU process of Chromium, or an GUI app. (In my case, I'm adding WebGPU as a new backend to an machine learning framework.)
I suppose the
WaitAny
is the answer, i.e. I pass the futures to a polling thread, which callsWaitAny
and notifies the main thread if any future is completed. However I can not find any living example do that, all the code I found in Chromium were just tests using it to wait for results in the same thread.Is
WaitAny
supposed to support my use case? And is there any existing project actually using it for embedding WebGPU?The text was updated successfully, but these errors were encountered: