Skip to content

Is OffscreenCanvas rendering supported in WebGPU context? #17776

Closed

Description

@lisanlow

I see that webgpu OffscreenCanvas rendering is already available in chromium with this bug fix:

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
WebGPUOffscreenNotSupported
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?

In my prototype code, I am trying to configure OffscreenCanvas in the HTML and referencing this canvas in wgpuInstanceCreateSurface() call to be used for subsequent rendering.
It appears mandatory to define WGPUSurfaceDescriptorFromCanvasHTMLSelector when creating webgpu surface.
https://github.com/emscripten-core/emscripten/blob/main/src/library_webgpu.js#L2399
OffscreenHTML

Activity

  1. sbc100 commented on Sep 1, 2022

    @sbc100
    Collaborator
  2. lisanlow commented on Sep 12, 2022

    @lisanlow
    Author

    @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.

  3. kainino0x commented on Sep 12, 2022

    @kainino0x
    Collaborator

    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:

    $findCanvasEventTarget: function(target) {

    However it looks like this is only for transferControlToOffscreen and not for raw OffscreenCanvases.

    Thanks for reporting your workaround!

  4. lisanlow commented on Sep 14, 2022

    @lisanlow
    Author

    @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 :)

  5. lisanlow commented on Sep 19, 2022

    @lisanlow
    Author

    @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?

  6. kainino0x commented on Sep 19, 2022

    @kainino0x
    Collaborator

    @lisanlow Of course! Thanks for finding that bug. #17889

  7. lisanlow commented on Sep 20, 2022

    @lisanlow
    Author

    @lisanlow Of course! Thanks for finding that bug. #17889

    @kainino0x Thanks for the prompt fix! Really appreciate it.

  8. alienself commented on Apr 21, 2023

    @alienself

    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.

  9. linked a pull request that will close this issueFix Getting WebGPU Context in pthread #21467on Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions