jsgpu

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Rendered for js/wasm

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

View Source
const (
	UsageMapRead = 0x0001
	UsageCopySrc = 0x0004
	UsageCopyDst = 0x0008
	UsageUniform = 0x0040
	UsageStorage = 0x0080
)

Buffer usage flags (GPUBufferUsage).

Variables

View Source
var ErrNoAdapter = errors.New("webgpu: no adapter")

ErrNoAdapter is returned when the browser offers no WebGPU adapter.

Functions

func Await

func Await(p js.Value) (js.Value, error)

Await waits for a promise. It must not run inside a js.FuncOf callback.

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

func NewDevice(allowFallback bool) (*Device, error)

NewDevice requests an adapter and a device. A fallback adapter is refused unless allowFallback.

func (*Device) Buffer

func (d *Device) Buffer(size int, usage int) js.Value

Buffer creates a buffer of size bytes (rounded up to 4).

func (*Device) Destroy

func (d *Device) Destroy()

Destroy releases the device and everything it holds.

func (*Device) Dispatch

func (d *Device) Dispatch(pipeline js.Value, n int, buffers ...js.Value)

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) Done

func (d *Device) Done() error

Done waits until the queue's submitted work has completed.

func (*Device) Lost

func (d *Device) Lost() bool

Lost reports whether the device was lost.

func (*Device) Pipeline

func (d *Device) Pipeline(wgsl string) (js.Value, error)

Pipeline returns the compute pipeline of a WGSL module (entry point "main", layout "auto"), compiled once per source.

func (*Device) Read

func (d *Device) Read(src js.Value, size int) ([]byte, error)

Read copies size bytes out of a storage buffer (copy to a mappable buffer, mapAsync, getMappedRange).

func (*Device) Upload

func (d *Device) Upload(b []byte) js.Value

Upload creates a storage buffer holding b.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL