Documentation
¶
Overview ¶
Package webgpu is the host side of wasi:webgpu (wasi-gfx, wasi:webgpu@0.3.0-rc.2) for core modules: every function of the WIT interface is a typed import of one host module, lowered and lifted with the Canonical ABI (package wit) by hand, without a component-model runtime. Resources are handles in a per-process table.
The functions run against a Backend: in the browser, WebGPU in the engine's worker (backend_js.go); elsewhere none, so get-gpu works and request-adapter answers "none", and a guest can test for a GPU portably. A process without the container's "gpu" capability (run --gpu) gets no adapter either.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultLimits = Limits{Handles: 4096, MemoryBytes: 256 << 20, ShaderBytes: 1 << 20, Pipelines: 256}
DefaultLimits are the per-process quotas.
var ErrHandles = errors.New("too many live resources")
ErrHandles is the quota error of New.
var Interface = func() *wit.Interface { ifs, err := wit.Parse(witdata.WebGPU) if err != nil { panic(err) } return ifs["webgpu"] }()
Interface is the parsed wasi:webgpu interface.
Functions ¶
Types ¶
type Backend ¶
type Backend interface {
// Open starts a process's session; gpu is its capability.
Open(gpu bool, lim Limits, h *Handles) Session
}
Backend serves the functions for one process.
type Destroyer ¶
type Destroyer interface{ Destroy() }
Destroyer is implemented by objects that release something when their handle is dropped or the process ends.
type Handles ¶
type Handles struct {
// contains filtered or unexported fields
}
Handles is a process's resource table: handles start at 1 (0 is never valid), each tagged with its resource type.
type Limits ¶
type Limits struct {
Handles int // live resources (default 4096)
MemoryBytes int64 // buffer and texture bytes alive (default 256 MiB)
ShaderBytes int // one WGSL source (default 1 MiB)
Pipelines int // pipelines alive (default 256)
}
Limits bound one process's use of the GPU.
type Module ¶
Module is the wasi:webgpu host module.
type Session ¶
type Session interface {
// Call runs import name with lifted arguments and returns the result
// value (nil for none). A *TrapError traps the guest.
Call(name string, args []any) (any, error)
// Async reports whether name waits on the platform (WebGPU promises):
// such calls run off the host call.
Async(name string) bool
// Close releases everything (the process ended).
Close()
}
Session is one process's GPU state.