wasigpu

package
v0.12.0 Latest Latest
Warning

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

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

Documentation

Overview

Package wasigpu is the guest side of wasi:webgpu (wasi:webgpu@0.3.0-rc.2) for Go programs built with GOOS=wasip1: the compute subset (adapter, device, buffers, WGSL modules, compute pipelines, bind groups, command encoders, queue, mapping). Every call lowers its arguments and lifts its result with package wit, the same Canonical ABI code the host uses; imports_wasip1.go is generated from the WIT by internal/cmd/witgen. Outside wasip1 every call fails with ErrUnavailable.

Resources are released with Drop (the WIT's resource-drop). Objects not dropped are released when the process ends.

Index

Constants

View Source
const (
	PointerDown = "pointer-down"
	PointerUp   = "pointer-up"
	PointerMove = "pointer-move"
	KeyDown     = "key-down"
	KeyUp       = "key-up"
)

Input kinds (the surface methods on-<kind>).

View Source
const (
	MapRead  = 1 << 0
	MapWrite = 1 << 1
	CopySrc  = 1 << 2
	CopyDst  = 1 << 3
	Index    = 1 << 4
	Vertex   = 1 << 5
	Uniform  = 1 << 6
	Storage  = 1 << 7
)

Buffer usages (gpu-buffer-usage flags, in WIT order).

Variables

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

ErrNoAdapter is returned when the host offers no GPU (none there, or the container was not started with --gpu).

View Source
var ErrUnavailable = errors.New("wasi:webgpu: not available on this platform")

ErrUnavailable is returned outside GOOS=wasip1.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	Size uint64
	// contains filtered or unexported fields
}

Buffer is a GPU buffer.

func (*Buffer) Drop

func (b *Buffer) Drop()

Drop releases the buffer.

func (*Buffer) Read

func (b *Buffer) Read() ([]byte, error)

Read maps a MAP_READ buffer and copies its bytes out.

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device is a GPU device and its queue.

func Open

func Open() (*Device, error)

Open asks for an adapter and a device: ErrNoAdapter when the host has none for this process.

func (*Device) Buffer

func (d *Device) Buffer(size uint64, usage uint32) (*Buffer, error)

Buffer creates a buffer of size bytes with usage flags.

func (*Device) ComputePipeline

func (d *Device) ComputePipeline(wgsl, entry string) (*Pipeline, error)

ComputePipeline compiles WGSL and makes a compute pipeline of its entry point (layout "auto").

func (*Device) Copy

func (d *Device) Copy(src, dst *Buffer, size uint64) error

Copy copies size bytes from src to dst on the GPU.

func (*Device) Dispatch

func (d *Device) Dispatch(p *Pipeline, buffers []*Buffer, x, y, z uint32) error

Dispatch runs p over x*y*z workgroups with buffers bound at group 0, bindings 0.. in order, and waits until the queue has submitted it.

func (*Device) Drop

func (d *Device) Drop()

Drop releases the device.

func (*Device) Surface added in v0.5.0

func (d *Device) Surface(w, h uint32) (*Surface, error)

Surface creates a surface of w x h pixels configured for d.

func (*Device) Write

func (d *Device) Write(b *Buffer, offset uint64, data []byte) error

Write copies data into b at offset (queue.writeBuffer).

type KeyEvent added in v0.6.0

type KeyEvent struct {
	Key, Text              string
	Alt, Ctrl, Meta, Shift bool
}

KeyEvent is a key: Key is its wasi-gfx:surface key label ("key-a", "arrow-up", "space"; "" when the host could not identify it), Text the text it produces ("" for none).

type KeyEvents added in v0.6.0

type KeyEvents struct {
	// contains filtered or unexported fields
}

KeyEvents is a surface's stream of one key kind.

func (*KeyEvents) Closed added in v0.6.0

func (k *KeyEvents) Closed() bool

Closed reports whether the stream ended (its surface is gone).

func (*KeyEvents) Drop added in v0.6.0

func (k *KeyEvents) Drop()

Drop releases the stream.

func (*KeyEvents) Poll added in v0.6.0

func (k *KeyEvents) Poll() ([]KeyEvent, error)

Poll returns the events since the last call, oldest first; it never blocks.

type Pipeline

type Pipeline struct {
	// contains filtered or unexported fields
}

Pipeline is a compute pipeline and its first bind group's layout.

func (*Pipeline) Drop

func (p *Pipeline) Drop()

Drop releases the pipeline.

type PointerEvent added in v0.6.0

type PointerEvent struct{ X, Y float64 }

PointerEvent is a pointer position in surface pixels from the top-left.

type PointerEvents added in v0.6.0

type PointerEvents struct {
	// contains filtered or unexported fields
}

PointerEvents is a surface's stream of one pointer kind.

func (*PointerEvents) Closed added in v0.6.0

func (p *PointerEvents) Closed() bool

Closed reports whether the stream ended (its surface is gone).

func (*PointerEvents) Drop added in v0.6.0

func (p *PointerEvents) Drop()

Drop releases the stream.

func (*PointerEvents) Poll added in v0.6.0

func (p *PointerEvents) Poll() ([]PointerEvent, error)

Poll returns the events since the last call, oldest first; it never blocks.

type RenderPipeline added in v0.5.0

type RenderPipeline struct {
	// contains filtered or unexported fields
}

RenderPipeline is a render pipeline and its first bind group's layout.

func (*RenderPipeline) Drop added in v0.5.0

func (p *RenderPipeline) Drop()

Drop releases the pipeline.

type Surface added in v0.5.0

type Surface struct {
	W, H uint32
	// contains filtered or unexported fields
}

Surface is a window-like target and its configured context.

func (*Surface) Drop added in v0.5.0

func (s *Surface) Drop()

Drop releases the surface.

func (*Surface) Frame added in v0.5.0

func (s *Surface) Frame(p *RenderPipeline, buffers []*Buffer, clear [4]float64, vertices uint32) error

Frame clears the surface to clear (RGBA in [0, 1]), draws vertices with p (buffers bound at group 0, bindings 0.. in order; none for none) and presents the frame. Present is paced by the host (60 per second at most in the playground), so a loop of Frame calls is an animation.

func (*Surface) Keys added in v0.6.0

func (s *Surface) Keys(kind string) (*KeyEvents, error)

Keys opens the surface's key stream of kind (KeyDown or KeyUp).

func (*Surface) Pointer added in v0.6.0

func (s *Surface) Pointer(kind string) (*PointerEvents, error)

Pointer opens the surface's pointer stream of kind (PointerDown, PointerUp or PointerMove).

func (*Surface) RenderPipeline added in v0.5.0

func (s *Surface) RenderPipeline(wgsl, vertex, fragment string) (*RenderPipeline, error)

RenderPipeline compiles WGSL with a vertex and a fragment entry point drawing triangle lists into s's format.

Directories

Path Synopsis
Package batchsink is the guest side of the host module wasi_webgpu_batch (package gpubatch): a webgpu.ReadSink over its four imports, so that a wasip1 Go program writes against the go-gfx/webgpu API unchanged.
Package batchsink is the guest side of the host module wasi_webgpu_batch (package gpubatch): a webgpu.ReadSink over its four imports, so that a wasip1 Go program writes against the go-gfx/webgpu API unchanged.

Jump to

Keyboard shortcuts

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