webgpuback

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Rendered for js/wasm

Overview

Package webgpuback is the browser backend of gpudev, on go-gfx/webgpu.

2D (option 2 of go-virtio/gpu docs/WEBGPU.md): each resource is a GPU texture; TRANSFER_TO_HOST_2D is one Queue.WriteTexture straight from the rows the device hands over (a view of guest RAM when contiguous); RESOURCE_FLUSH copies the scanout's rectangle of the resource into the scanout's canvas texture on the GPU and presents it. A canvas texture starts cleared every frame, so a flush copies the whole scanout, not only the damaged rectangle: one GPU copy, no CPU work.

webgpu-batch (option 4): contexts create objects from go-gfx/webgpu wire descriptors (DecodeDescriptor) and submit streams with Device.Replay, naming only their own objects; a context's backend ids are the objects' replay ids (ReplayID), so the device's translation of guest ids lands directly on what replay.js knows.

Index

Constants

This section is empty.

Variables

View Source
var ErrBind = errors.New("webgpuback: BIND_RESOURCE is not implemented")

ErrBind: BIND_RESOURCE windows (readback into guest memory) are not implemented by this backend yet.

View Source
var ErrFormat = errors.New("webgpuback: format needs a swizzle")

ErrFormat: a 2D format WebGPU has no texture format for (the A8/X8-first orders need a swizzle pass, not implemented).

Functions

This section is empty.

Types

type Backend

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

Backend implements gpudev.Backend.

func New

func New(cfg Config) *Backend

New returns a backend presenting through cfg.

func (*Backend) CreateResource

func (b *Backend) CreateResource(id uint32, f gpudev.Format, w, h uint32) error

CreateResource implements gpudev.Backend.

func (*Backend) DestroyResource

func (b *Backend) DestroyResource(id uint32)

DestroyResource implements gpudev.Backend.

func (*Backend) Flush

func (b *Backend) Flush(scanout, id uint32, _ gpudev.Rect) error

Flush implements gpudev.Backend: the whole shown rectangle is copied into the canvas texture and presented.

func (*Backend) NewContext

func (b *Backend) NewContext(id uint32) (gpudev.Context, error)

NewContext implements gpudev.Backend.

func (*Backend) SetScanout

func (b *Backend) SetScanout(scanout, id uint32, r gpudev.Rect) error

SetScanout implements gpudev.Backend.

func (*Backend) Upload

func (b *Backend) Upload(id uint32, r gpudev.Rect, src []byte, stride uint64) error

Upload implements gpudev.Backend: one writeTexture.

type Config

type Config struct {
	Device *webgpu.Device
	// Surfaces are the scanouts' canvases, configured with this device,
	// with COPY_DST in their usage and the format of the resources they
	// will show (bgra8unorm for go-virtio/gpu's framebuffer).
	Surfaces map[uint32]*webgpu.Surface
	// BeforePresent, if set, runs after a flush's copy with the canvas
	// texture, before the frame is presented (tests read it back here).
	BeforePresent func(scanout uint32, canvas *webgpu.Texture) error
	// Present receives each presented frame, an ImageBitmap; nil drops it.
	Present func(scanout uint32, frame js.Value)
}

Config is what a Backend presents to.

type Context

type Context struct {
	*batch.DeviceBackend
	// contains filtered or unexported fields
}

Context is a webgpu-batch context on the device: go-gfx/webgpu's batch.DeviceBackend (creation, replay, read-back), and BIND_RESOURCE.

func (*Context) Bind

func (c *Context) Bind(uint32, gpudev.Window) error

Bind implements gpudev.Context.

func (*Context) Close

func (c *Context) Close()

Close implements gpudev.Context.

Jump to

Keyboard shortcuts

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