Skip to content

Add in a way to manually commit the canvas texture #4496

@greggman

Description

@greggman

IIRC the spec says canvas textures are destroyed when the current JavaScript event exits

This seems problematic for wasm projects. wasm appears to be getting JSPI support as a way to let wasm call asynchronous functions as though they were synchronous. Given that, any API call in a wasm might bottom out in a JSPI call. This means code like this

    texture = context.getCurrentTexture();
    callSomeFunction();       // happens to use JSPI directly or indirectly
    ...use texture here...    // error: Texture is expired

Do we need to look into some way to manually commit the canvas texture? For example

  device = await adapert.requestDevice({
    features: ["canvas-manual-commit"],
  });

  context.configure({
    device,
    commit: "manual",
    ...
  });

  // -- at render time --

    texture = context.getCurrentTexture();
    callSomeFunction();   // happens to use JSPI directly or indirectly
    ... use texture here ...     
    context.commit();     // manually signal the texture should be swapped"

Or something? Is this an issue that needs solving? You could maybe argue that wasm should be using "bitmaprender" but if that's the solution, should that be the default in emscripten so that devs don't run into this gotcha issue?

I know discussion of manual commit/swap was discussed before. I'm wondering if this JSPI issue warrants a revisit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiWebGPU APIapi-milestone-2-202502api issues that were in milestone 2 before we triaged milestone 1 on 2025-02-19

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions