Description
Is your feature request related to a problem? Please describe.
WebGPU and WebGL have functions for directly loading images without copying them to wasm first. This is much more efficient. In WebGPU, an image source can be an ImageBitmap
, HTMLCanvasElement
, or OffscreenCanvas
.
Describe the solution you'd like
The WebGPU spec specifies GPUImageCopyExternalImage. I can't find any reference to this functionality in the wgpu code, so I assume that this is not implemented.
WebGL allows the same via the regular texImage2D
, but it has even more formats, most notably HTMLImageElement
and ImageData
. However, it's quite easy to convert those into ImageBitmap
via createImageBitmap.
Describe alternatives you've considered
It's possible to draw an image to a bitmap canvas and then extract it as a byte array from there, but this is highly inefficient. In theory you can also directly decode images in wasm, but the browser is much faster (since it can do that in native code) and also supports webp, which is not available for Rust on the wasm32 target right now.
Additional context
- This is only relevant for the wasm32 target of course.
- The same applies to
GPUExternalTextureDescriptor
, which allows using video as a source for textures. In WebGL, this is also implemented via thetexImage2D
call.