Has anyone ever gotten WebGPU working with PROXY_TO_PTHREAD ?
Version of emscripten/emsdk: emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.65 (7f8a05dd4e37cbd7ffde6d624f91fd545f7b52e3) 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.
Relevant discussion may be here: https://github.com/emscripten-core/emscripten/issues/19645
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.