Description
So far we have WebGPU and BYOW, but it need more work to use the front-end graphics ecology.
Repository for testing and integrating: https://github.com/chirsz-ever/deno-webgpu-window-demos
Seamlessly use WebGPU-backended frameworks
- three.js would be useful since r164 (WebGPUBackend: Allows the device to be created externally mrdoob/three.js#28192)
- pixijs: TODO
- Babylon.js: TODO
Bugs and requirements
- Calling
createImageBitmap
with aBlob
, "TypeError: expected typed ArrayBufferView" occurred. #22649- fix(ext/web): pass
createImageBitmap
when the argument type isBlob
#23518 - support formats other than RGBA8, at least RGB
- support more MIME types, like
"image/jpeg"
- fix(ext/web): pass
- WebGPU: not able to use the
alphaMode
member ofGPUCanvasConfiguration
#23509 - Deno.UnsafeWindowSurface panics with x11 #23433
- WebGPU: Deno's GPUCanvasConfiguration is not standard #23508
- WebGPU: "Error: Invalid Surface Status" triggered randomly #23407
- WebGPU: Implement copyExternalImageToTexture #23576
- WebGPU BYOW: to submit to queue twice would cause the program to freeze in surface.present. #24313
- WebGPU: GPUDevice.createRenderPipelineAsync not return a Promise #24317
Creating and managing native windows
We already have deno_sdl2 and dwm for creating windows. But they rely on third-party libraries SDL2 and GLFW.
Maybe we need some methods to create windows without any third-party libraries? I have two ideas:
import winit and design a set of interfaces to use it;1- only write JavaScript code, use FFI to create window on respective platform, as a third-party library.
The first idea is easier to implement, but add a built-in component increases deno's compatibility costs and technical debt.
Canvas
, CanvasRenderingContext2D
and WebGL
If deno support Canvas
, CanvasRenderingContext2D
and WebGL, it would be more easy to use front-end graphics libraries.
Deno.UnsafeWindowSurface
is analog to Canvas
, and it can use getContext("webgpu")
to create a GPUCanvasContext
. It is worthwhile to support other contexts, getContext("2d")
, getContext("webgl")
, getContext("webgl2")
and getContext("bitmaprenderer")
.
How to implement CanvasRenderingContext2D (Canvas.getContext("2d")
)? There are many methods in #5701, which mostly introduces skia or similar graphics libraries like Vello.
For WebGL, we can just use the native OpenGL implementation (gluton)[https://github.com/deno-windowing/gluten], or import ANGLE to maximize compliance of the WebGL standard.1
Maybe we can do something named "Canvas2D over WebGPU" and "WebGL over WebGPU", which only use JavaScript to implement CanvasRenderingContext2D
and WebGL with WebGPU.
If we resolve all above, implementing OffscreenCanvas
and ImageBitmapRenderingContext
(Canvas.getContext("bitmaprenderer")
) seems not hard.