memback

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: 5 Imported by: 0

Documentation

Overview

Package memback is an in-memory gpudev.Backend: resources are byte images, scanouts are framebuffers a flush composes into, and webgpu-batch contexts keep their objects in a table and check every replayed stream with go-gfx/webgpu's own reader (wire.Decode). It is the backend of the tests, the fuzz targets and the in-process end-to-end runs; it renders nothing.

Index

Constants

View Source
const FirstID = 1 << 20

FirstID is the first host id a Context hands out.

Variables

View Source
var ErrUnknown = errors.New("memback: unknown resource or object")

ErrUnknown: a call naming something the backend does not hold. The Device never makes one; tests that drive the backend directly can.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	sync.Mutex
	Resources map[uint32]*Image
	// Scanouts holds what each scanout shows: the image a flush last
	// composed (nil until the first flush of an enabled scanout).
	Scanouts map[uint32]*Image
	Shown    map[uint32]Shown // scanout -> resource and rect
	Flushes  int
	Contexts map[uint32]*Context
	// Fail, when set, makes every call that can fail return it.
	Fail error
}

Backend is the in-memory backend. Its fields are for inspection; lock it (it is a sync.Locker) while reading them during device activity.

func New

func New() *Backend

New returns an empty backend.

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, r gpudev.Rect) error

Flush implements gpudev.Backend: it copies r of the resource into the scanout image, at r's position relative to the scanout's rect.

func (*Backend) NewContext

func (b *Backend) NewContext(ctx 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.

type Context

type Context struct {
	ID      uint32
	Objects map[uint32]Object
	Replays [][]wire.Cmd
	Binds   map[uint32]gpudev.Window
	Closed  bool
	// contains filtered or unexported fields
}

Context is an in-memory webgpu-batch context. Host ids start at FirstID, far from the small ids guests use, so a stream the Device did not translate fails wire.Decode here.

func (*Context) Bind

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

Bind implements gpudev.Context.

func (*Context) Close

func (c *Context) Close()

Close implements gpudev.Context.

func (*Context) Create

func (c *Context) Create(kind uint32, desc []byte) (uint32, error)

Create implements gpudev.Context; the descriptor is kept as given.

func (*Context) Destroy

func (c *Context) Destroy(id uint32)

Destroy implements gpudev.Context.

func (*Context) Replay

func (c *Context) Replay(words []uint32, data []byte) error

Replay implements gpudev.Context: the stream must decode against this context's objects, with go-gfx/webgpu's checks.

type Image

type Image struct {
	Format        gpudev.Format
	Width, Height uint32
	Pix           []byte
}

Image is a resource or scanout: Width×Height pixels, 4 bytes each, rows packed (stride Width*4), in the resource's byte order.

type Object

type Object struct {
	Kind uint32
	Desc []byte
}

Object is what a context holds for one host id.

type Shown

type Shown struct {
	Resource uint32
	Rect     gpudev.Rect
}

Shown is what SET_SCANOUT bound to a scanout.

Jump to

Keyboard shortcuts

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