You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is OffscreenCanvas rendering supported in WebGPU context? #17776
Looking at current implementation of wgpuInstanceCreateSurface(), it appears to me that rendering to OffscreenCanvas is currently not available in native webgpu API.
This code section shows that wgpuInstanceCreateSurface() asserts expect webgpu surface to be associated only to HTML canvas element? https://github.com/emscripten-core/emscripten/blob/main/src/library_webgpu.js#L2410
Is my understanding correct?
If so, is there any known alternatives to render to canvas on webworker then transfer rendered output to main thread for chrome browser display?
@sbc100 and @kainino0x FYI, I managed to overcome this issue in my prototype by setting specialHTMLTargets["!canvas"] = Module.canvas; and referencing it in the HTML selector with "!canvas" in the web worker.
Sorry, I forgot to reply to this. We haven't put any work specifically into getting OffscreenCanvas to work. I never tried it but thought it would work with WGPUSurfaceDescriptorFromCanvasHTMLSelector which calls findCanvasEventTarget which has special logic for OffscreenCanvases:
Activity
sbc100 commentedon Sep 1, 2022
@kainino0x
lisanlow commentedon Sep 12, 2022
@sbc100 and @kainino0x FYI, I managed to overcome this issue in my prototype by setting
specialHTMLTargets["!canvas"] = Module.canvas;and referencing it in the HTML selector with"!canvas"in the web worker.kainino0x commentedon Sep 12, 2022
Sorry, I forgot to reply to this. We haven't put any work specifically into getting OffscreenCanvas to work. I never tried it but thought it would work with
WGPUSurfaceDescriptorFromCanvasHTMLSelectorwhich calls findCanvasEventTarget which has special logic for OffscreenCanvases:emscripten/src/library_html5.js
Line 333 in 44fd8b1
However it looks like this is only for transferControlToOffscreen and not for raw OffscreenCanvases.
Thanks for reporting your workaround!
lisanlow commentedon Sep 14, 2022
@kainino0x Thanks for your attention on this issue.
I just realized that the approach that I described above with specialHTMLTargets is mentioned in emscripten documentation.
I assume that its well verified working with WebGL and it's great that this works seamlessly for WebGPU for me :)
lisanlow commentedon Sep 19, 2022
@kainino0x This ASSERT line is failing for me when working with offscreen canvas in debug build (works well in release build).
https://github.com/emscripten-core/emscripten/blob/main/src/library_webgpu.js#L2412
Any chance that its possible to update this line for the check to allow canvas of offscreen (non-html) type?
kainino0x commentedon Sep 19, 2022
@lisanlow Of course! Thanks for finding that bug. #17889
lisanlow commentedon Sep 20, 2022
@kainino0x Thanks for the prompt fix! Really appreciate it.
alienself commentedon Apr 21, 2023
I am facing a similar issue: #19225
I would like to run webgpu off the main thread in a separate thread while rendering on an offscreen canvas passed from the main thread.
@kainino0x Is this possible with emscripten? I am using proxy to pthread but i am unable to retrieve the canvas context.