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
- Variables
- type Buffer
- type Device
- func (d *Device) Buffer(size uint64, usage uint32) (*Buffer, error)
- func (d *Device) ComputePipeline(wgsl, entry string) (*Pipeline, error)
- func (d *Device) Copy(src, dst *Buffer, size uint64) error
- func (d *Device) Dispatch(p *Pipeline, buffers []*Buffer, x, y, z uint32) error
- func (d *Device) Drop()
- func (d *Device) Surface(w, h uint32) (*Surface, error)
- func (d *Device) Write(b *Buffer, offset uint64, data []byte) error
- type KeyEvent
- type KeyEvents
- type Pipeline
- type PointerEvent
- type PointerEvents
- type RenderPipeline
- type Surface
- func (s *Surface) Drop()
- func (s *Surface) Frame(p *RenderPipeline, buffers []*Buffer, clear [4]float64, vertices uint32) error
- func (s *Surface) Keys(kind string) (*KeyEvents, error)
- func (s *Surface) Pointer(kind string) (*PointerEvents, error)
- func (s *Surface) RenderPipeline(wgsl, vertex, fragment string) (*RenderPipeline, error)
Constants ¶
const ( PointerDown = "pointer-down" PointerUp = "pointer-up" PointerMove = "pointer-move" KeyDown = "key-down" KeyUp = "key-up" )
Input kinds (the surface methods on-<kind>).
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 ¶
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).
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.
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device is a GPU device and its queue.
func Open ¶
Open asks for an adapter and a device: ErrNoAdapter when the host has none for this process.
func (*Device) ComputePipeline ¶
ComputePipeline compiles WGSL and makes a compute pipeline of its entry point (layout "auto").
func (*Device) Dispatch ¶
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.
type KeyEvent ¶ added in v0.6.0
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.
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline is a compute pipeline and its first bind group's layout.
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) 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
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. |