Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Multiple components cannot effectively share a GPUDevice because it is stateful #3250

@kainino0x

Description

@kainino0x

Multiple components, for example multiple graph/plot widgets on a page, cannot effectively share a GPUDevice because it is stateful:

  • It has a global error scope state, which means any error scope spanning an async boundary will capture stuff from other components. This is very difficult for an application to work around.
  • It can be destroyed, which means one component which wants to clean up after itself cannot take advantage of GPUDevice.destroy() to do so. An application can somewhat work around this by tracking its own resource allocations, which is also more flexible for more complex ownership models (like refcounting), though that only allows freeing Buffer/Texture/QuerySet.

This can be useful for some other things as well:

  • An application/engine that has some asynchronous (e.g. loading) work that goes on in the "background" can separate the state for that work.
  • A library that wants to expose its GPUDevice to a user can separate the user's state from its own.

It's currently possible to approximate this by carefully using error scopes. However, it requires the developer to be diligent about popping error scopes prior to await and re-pushing afterward. In code that call into WebGPU from more than one level of async function, this becomes very complex very quickly.

Relevant past work:

We don't need to solve this in V1, but we need to make sure we don't block ourselves from solving it later. Editors are working on a proposal about this (that should have no or minimal changes to the current API), will follow up soon.

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiWebGPU API

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions