WebGPU for Node.js via Google Dawn. Allows you to use WebGPU without a browser.
It should work on Linux, Mac, and Windows. Prebuilt binaries are available for x64 architectures, and arm-based Macs.
Check the examples for how to use this package. You can use both compute and render pipelines. For render pipelines, you can either render the result to a buffer and save it as an image, or you can use @kmamal/sdl to render directly to a window as in this example.
flags: <string>[]
An array of flags to pass to dawn_node.
Creates a WebGPU instance object.
The returned object is equivalent to the browser's GPU
object.
Any flags passed to the create()
function must be in the form of 'key=value'
.
It is usually a good idea to pass at least the 'verbose=1'
flag to help with debugging.
Instances created with gpu.create()
need to be cleaned up before the program exits.
Usually you will call gpu.destroy(instance)
right after calling device.destroy()
.
options: <object>
device:
<GPUDevice>
The device to render from.window:
<Window>
The window to render to.presentMode: <string>
The swapchain mode. Default:'fifo'
Crates a Renderer object that is used to connect a device to a window so that the device output renders directly to the window.
Possible options for presentMode
are 'fifo'
, 'fifoRelaxed'
, 'immediate'
, and 'mailbox'
.
This class is not directly exposed by the API so you can't use it with the new operator.
Instead, objects returned by gpu.renderGPUDeviceToWindow()
are of this type.
Return an object of type GPUTexture
.
Things drawn to the texture will appear on the window when renderer.swap()
is called.
Return an object of type GPUTextureView
.
Things drawn to the texture view will appear on the window when renderer.swap()
is called.
Call this function after your render pass to display the results on the window.
Must be called after the window has been resized.