Documentation
¶
Overview ¶
Package jsgpu is a thin Go layer over the browser's WebGPU API (https://www.w3.org/TR/webgpu/) through syscall/js, for code running in a Web Worker (the playground's engine worker): a device, storage buffers, compute pipelines from WGSL, dispatches and readback. Every promise is awaited from a goroutine, never from a JS callback.
Index ¶
- Constants
- Variables
- func Await(p js.Value) (js.Value, error)
- type AdapterInfo
- type Device
- func (d *Device) Buffer(size int, usage int) js.Value
- func (d *Device) Destroy()
- func (d *Device) Dispatch(pipeline js.Value, n int, buffers ...js.Value)
- func (d *Device) Done() error
- func (d *Device) Lost() bool
- func (d *Device) Pipeline(wgsl string) (js.Value, error)
- func (d *Device) Read(src js.Value, size int) ([]byte, error)
- func (d *Device) Upload(b []byte) js.Value
Constants ¶
const ( UsageMapRead = 0x0001 UsageCopySrc = 0x0004 UsageCopyDst = 0x0008 UsageUniform = 0x0040 UsageStorage = 0x0080 )
Buffer usage flags (GPUBufferUsage).
Variables ¶
var ErrNoAdapter = errors.New("webgpu: no adapter")
ErrNoAdapter is returned when the browser offers no WebGPU adapter.
Functions ¶
Types ¶
type AdapterInfo ¶
type AdapterInfo struct {
Vendor, Architecture string
// Fallback is a software adapter (SwiftShader and the like): work done
// on it is not GPU work and must not be reported as such.
Fallback bool
}
AdapterInfo describes the adapter a device came from.
type Device ¶
type Device struct {
JS js.Value
Info AdapterInfo
Queue js.Value
// contains filtered or unexported fields
}
Device is a WebGPU device.
func NewDevice ¶
NewDevice requests an adapter and a device. A fallback adapter is refused unless allowFallback.
func (*Device) Destroy ¶
func (d *Device) Destroy()
Destroy releases the device and everything it holds.
func (*Device) Dispatch ¶
Dispatch runs pipeline over n invocations (64 per workgroup, laid over x and y when n exceeds one dimension's limit) with buffers bound at group 0, bindings 0.. in order.
func (*Device) Pipeline ¶
Pipeline returns the compute pipeline of a WGSL module (entry point "main", layout "auto"), compiled once per source.