Documentation
¶
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 ¶
- Variables
- type Backend
- func (b *Backend) CreateResource(id uint32, f gpudev.Format, w, h uint32) error
- func (b *Backend) DestroyResource(id uint32)
- func (b *Backend) Flush(scanout, id uint32, _ gpudev.Rect) error
- func (b *Backend) NewContext(id uint32) (gpudev.Context, error)
- func (b *Backend) SetScanout(scanout, id uint32, r gpudev.Rect) error
- func (b *Backend) Upload(id uint32, r gpudev.Rect, src []byte, stride uint64) error
- type Config
- type Context
Constants ¶
This section is empty.
Variables ¶
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.
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 (*Backend) CreateResource ¶
CreateResource implements gpudev.Backend.
func (*Backend) DestroyResource ¶
DestroyResource implements gpudev.Backend.
func (*Backend) Flush ¶
Flush implements gpudev.Backend: the whole shown rectangle is copied into the canvas texture and presented.
func (*Backend) NewContext ¶
NewContext implements gpudev.Backend.
func (*Backend) SetScanout ¶
SetScanout implements gpudev.Backend.
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.