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

Has anyone ever gotten WebGPU working with PROXY_TO_PTHREAD ? #22484

Open
jankrassnigg opened this issue Aug 31, 2024 · 2 comments
Open

Has anyone ever gotten WebGPU working with PROXY_TO_PTHREAD ? #22484

jankrassnigg opened this issue Aug 31, 2024 · 2 comments

Comments

@jankrassnigg
Copy link

Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.65 (7f8a05d)
clang version 20.0.0git (https:/github.com/llvm/llvm-project 547917aebd1e79a8929b53f0ddf3b5185ee4df74)
Target: wasm32-unknown-emscripten
Thread model: posix

I am using this sample to figure out how to get started with porting an engine to Emscripten + WebGPU:
https://developer.chrome.com/docs/web-platform/webgpu/build-app

The sample works, as is. But I also want PROXY_TO_PTHREAD because I need to wait for threads on the main thread.

The sample uses GLFW for window creation and surface setup. This already doesn't seem to work well. glfwInit() already fails, if I run it on my apps main thread.

I can proxy it to the browser thread with this:

proxy_queue = em_proxying_queue_create();
emscripten_proxy_sync(proxy_queue, emscripten_main_runtime_thread_id(), InitBrowser, nullptr);
emscripten_proxy_execute_queue(proxy_queue);

That seems to get around the first issue. However, quickly I run into various other issues. For example the "device" is not accessible on all threads, I found OFFSCREENCANVAS_SUPPORT and tried that, that seems to make some stuff work and break others.

And so on and so forth. It would be very tedious to write down all the ways that this endeavor failed.

So my question is, is it generally possible to use WebGPU today (with emsdk 3.1.65) using PROXY_TO_PTHREAD ? Does anyone have a sample that shows which hoops one has to jump through to make it work?

I'm also wondering whether the issues are mainly in GLFW (which seems to assume that it always runs on the browser thread). Maybe rolling my own for window setup could make this work? Again, if someone has a working example somewhere, that would be very helpful.

@kripken
Copy link
Member

kripken commented Sep 3, 2024

Relevant discussion may be here: #19645

@juj
Copy link
Collaborator

juj commented Sep 6, 2024

Here is an example of using WebGPU via PROXY_TO_PTHREAD, albeit using a different bindings API so it might not apply to your use case.

However maybe this commit can illustrate how support for PROXY_TO_PTHREAD could be implemented in Emscripten's WebGPU bindings.

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

3 participants