Offscreen Canvas support (with emcc -sPROXY_TO_PTHREAD flag on)
Hi,
Chrome does support offscreen canvas with GPU, therefore how can I make this work with emscripten and your library?
Without the -sPROXY_TO_PTHREAD flag on, everything runs fine, however I would like to run my wasm file off the main thread.
How can I archive this?
Thanks!
-sPROXY_TO_PTHREAD flag is something that is currently unsupported, but it is a configuration that I do want to add support for.
A tricky part with that linker flag is that supporting it will require modifying Emscripten itself, to adjust its proxy bootstrap code.
If you are building a new Wasm WebGPU application codebase from scratch, then I would probably be better to manually proxy to a pthread, i.e. have a regular -pthread compiled Wasm app, where you create a WebGPU renderer pthread manually. Or maybe even slimmer, use the Wasm Worklets feature for lightweight Worker access, if you don't have any existing native pthreads code as a ballast.
I hope to find a bit of time to complete these features to the library in the near future. In the lightest form, this would amount to adding a new function for transferring the canvas offscreen. There exists some machinery for that in upstream Emscripten, although not yet 100% sure if that will be adequate for WebGPU use.
After commit https://github.com/juj/wasm_webgpu/commit/8e0a8379e2ba669261f381f46b4cb785899c67dc, there is now support to render WebGPU using OffscreenCanvas from a Wasm Worker.
Example code in https://github.com/juj/wasm_webgpu/blob/main/samples/offscreen_canvas/offscreen_canvas.c.
Also added an example of how to render via OffscreenCanvas from a pthread: https://github.com/juj/wasm_webgpu/commit/adc6acf9a54d105b4211b9bb57278c7cb007524c .
Finally, added support and an example for -sPROXY_TO_PTHREAD rendering at https://github.com/juj/wasm_webgpu/commit/403ae09cfa978bb713e9d98263e992a73086a01b . With that, I'll close this ticket as resolved.