wasigpu

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: BSD-3-Clause Imports: 5 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 (
	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) Write

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

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

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.

Jump to

Keyboard shortcuts

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