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 Pipeline
- type RenderPipeline
- type Surface
Constants ¶
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 Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline is a compute pipeline and its first bind group's layout.
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) 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.