Documentation
¶
Overview ¶
Package webgpu is the WebGPU backend of the explicit renderer (SPEC §9.5): an explicit.Device over navigator.gpu, through syscall/js, so that internal/gpu/explicit draws on the web the way it draws on Vulkan.
The browser's GPU API is asynchronous, and the UI goroutine never waits for a promise once the event listeners are installed (SPEC §23.3). So the adapter and the device are awaited by Acquire, which the engine calls while it starts, before the platform installs its listeners; what comes after is a callback that posts to the UI goroutine: a read-back that finishes later (ReadTexture), the loss of the device, and the new device that follows a loss.
The decisions that need no browser are plain Go, tested in the normal run and under Node: the names the API uses for formats, usages, blend factors and vertex formats (mapping.go), the bind group layouts of a pipeline (layout.go), the supply of devices (supply.go), the loss of a device (loss.go) and the rows of a read-back (readback.go). The files that touch the browser carry the js tag; elsewhere Acquire fails with WebGPUUnavailable (unavailable.go).
Flutter: Impeller's Metal and Vulkan backends are its counterparts; Flutter web uses CanvasKit or Skwasm (lib/web_ui/lib/src/engine/).
Index ¶
Constants ¶
const ( TagUnavailable = "WebGPUUnavailable" // TagDeviceFailed is the tag of an adapter that does not give a device. TagDeviceFailed = "WebGPUDeviceFailed" // TagShaderInvalid is the tag of a WGSL module the browser rejects: an internal bug. TagShaderInvalid = "ShaderModuleInvalid" // TagDeviceLost is the tag of a device that was lost, which explicit.Renderer recovers from. TagDeviceLost = explicit.TagGPUDeviceLost )
The tags of the errors of this package. Each failure has a tag of its own (CLAUDE.md), and the route of an error lists the calls it came through.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// Logger gets the log of the backend: a lost device, the messages the browser's validation
// reports; slog.Default() when nil.
Logger *slog.Logger
// Post runs fn on the UI goroutine. The browser's callbacks (a finished read-back, a lost
// device, a device that came after a loss) call it so that their work happens where the
// framework runs (SPEC §23.3). When nil, fn runs inside the callback.
Post func(fn func())
// OnDeviceReady is called on the UI goroutine, through Post, when the device that was
// asked for after a loss has arrived; the handle is the window the last device was opened
// for. The engine asks for a frame of that window, which opens the device.
OnDeviceReady func(h gpu.SurfaceHandle)
// Timeout is how long Acquire waits for the adapter and the device; 20 seconds when zero.
Timeout time.Duration
}
Options are the optional parameters of Acquire.
Flutter: no counterpart
type Provider ¶
type Provider struct{}
Provider hands out the device of the browser's WebGPU. Off the web there is none: Acquire fails and Open on a nil provider says so.
Flutter: no counterpart
func Acquire ¶
Acquire fails with WebGPUUnavailable: only a browser has WebGPU.
Flutter: no counterpart
type Renderer ¶
Renderer is the explicit renderer over a WebGPU device (SPEC §9.5). It draws as the Vulkan renderer does, with one difference: a snapshot (Picture.ToImage) is drawn by the software renderer. A WebGPU read-back finishes in a later browser task and the UI goroutine does not wait for one (SPEC §23.3), while ToImage returns at once (SPEC §12.10).
Flutter: no counterpart (flutter::Rasterizer)
func NewRenderer ¶
func NewRenderer(open func(gpu.SurfaceHandle) (explicit.Device, error), opts ...explicit.RendererOpts) *Renderer
NewRenderer returns a renderer that opens its device with open when it draws its first frame: the Open method of a Provider, or a function that gives another device. More than one options value panics with MultipleOptions.
Flutter: no counterpart
func (*Renderer) RasterizeScene ¶
RasterizeScene draws the scene into a new image of width x height pixels, as Snapshot does: the ui.Rasterizer for Picture.ToImage and Scene.ToImage.
Flutter: no counterpart
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Command gpuwebtest is the program of the browser tests of the WebGPU renderer (step 21.5, SPEC §9.5, §17).
|
Command gpuwebtest is the program of the browser tests of the WebGPU renderer (step 21.5, SPEC §9.5, §17). |