这是indexloc提供的服务,不要输入任何密码
Skip to content

Support webgpu context canvas for copyExternalImageToTexture #2350

@qjia7

Description

@qjia7

The current spec copyexternalimagetotexture says that If source.source is an HTMLCanvasElement: Its canvas context mode must be "2d", "webgl", or "webgl2". It seems that webgpu context mode is not supported.
However, for tfjs-webgpu, we are meeting a scenario which may need webgpu context mode supported.

Some users of tfjs are using tfjs' result in their gpu programs. If they directly use gpu backend (webgl/webgpu) to do the prediction, they hope only have gpu->gpu copying to move tfjs's result to the GPUTexture of their gpu program. However, for tfjs-webgpu, we create a GPUDevice silently for webgpu backend and donot expose it to upper user. To get the result, the user either reads data to cpu by tensor.data() or gets data from a HTMLCanvasElement. For the latter, the user can implement gpu-gpu copying to move tfjs's result to another device's GPUTexture. However, to support the latter path, we need webgpu context mode is supported for copyExternalImageToTexture. Otherwise, there will be an extra copy needed (webgpu canvas -> 2d canvas/webgl canvas -> webgpu canvas). And webgl doesn't exist such kind of problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestA request for a new GPU feature exposed in the API

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions