Documentation
¶
Overview ¶
Package gpudev is a virtio-gpu device model: the host side of the control queue that go-virtio/gpu, the Linux virtio_gpu driver and any other guest driver talk to. It executes the 2D commands (resources, backing, transfers, scanouts, flushes), answers the capset queries, and hosts webgpu-batch contexts (go-virtio/gpu/wgpubatch) whose go-gfx/webgpu command streams it validates and hands to a Backend.
The guest is untrusted. Every id, size, offset, count and rectangle a request carries is bounded in 64-bit arithmetic before it reaches the Backend or guest memory; quotas bound what a guest can make the host hold. References: the virtio spec, device-types/gpu/description.tex; Linux include/uapi/linux/virtio_gpu.h; QEMU hw/display/virtio-gpu.c (the reference 2D device, whose checks are cited where they are followed).
Index ¶
Constants ¶
const ( CmdGetDisplayInfo uint32 = 0x0100 CmdResourceCreate2D uint32 = 0x0101 CmdResourceUnref uint32 = 0x0102 CmdSetScanout uint32 = 0x0103 CmdResourceFlush uint32 = 0x0104 CmdTransferToHost2D uint32 = 0x0105 CmdResourceAttachBacking uint32 = 0x0106 CmdResourceDetachBacking uint32 = 0x0107 CmdGetCapsetInfo uint32 = 0x0108 CmdGetCapset uint32 = 0x0109 CmdCtxCreate uint32 = 0x0200 CmdCtxDestroy uint32 = 0x0201 CmdCtxAttachResource uint32 = 0x0202 CmdCtxDetachResource uint32 = 0x0203 CmdSubmit3D uint32 = 0x0207 CmdUpdateCursor uint32 = 0x0300 CmdMoveCursor uint32 = 0x0301 )
Command types.
const ( RespOKNoData uint32 = 0x1100 RespOKDisplayInfo uint32 = 0x1101 RespOKCapsetInfo uint32 = 0x1102 RespOKCapset uint32 = 0x1103 RespErrUnspec uint32 = 0x1200 RespErrOutOfMemory uint32 = 0x1201 RespErrInvalidScanoutID uint32 = 0x1202 RespErrInvalidResourceID uint32 = 0x1203 RespErrInvalidContextID uint32 = 0x1204 RespErrInvalidParameter uint32 = 0x1205 )
Response types.
const ( FlagFence uint32 = 1 << 0 FlagInfoRingIdx uint32 = 1 << 1 )
ctrl_hdr flags (description.tex:255-256).
const ( FeatureVirgl uint64 = 1 << 0 FeatureEDID uint64 = 1 << 1 FeatureResourceBlob uint64 = 1 << 3 FeatureContextInit uint64 = 1 << 4 )
Feature bits (virtio_gpu.h VIRTIO_GPU_F_*).
const BytesPerPixel = 4
BytesPerPixel of every 2D format.
const HdrSize = 24
HdrSize is sizeof(struct virtio_gpu_ctrl_hdr).
const MaxScanouts = 16
MaxScanouts is VIRTIO_GPU_MAX_SCANOUTS (virtio_gpu.h:244).
Variables ¶
var ErrOutOfRange = errors.New("gpudev: guest address range outside memory")
ErrOutOfRange: an address range outside guest memory.
var ErrWindow = errors.New("gpudev: access outside the bound window")
ErrWindow: an access outside a window, or after its backing went away.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface {
// CreateResource makes a w×h 2D resource (w, h > 0, f valid).
CreateResource(id uint32, f Format, w, h uint32) error
// DestroyResource releases it; the Device has already detached it
// from every scanout.
DestroyResource(id uint32)
// Upload writes r of the resource from src, where row y of r starts
// at src[y*stride] and holds r.Width*BytesPerPixel bytes. src may
// alias guest memory: it is only valid during the call.
Upload(id uint32, r Rect, src []byte, stride uint64) error
// SetScanout shows rect r of resource id on scanout (id 0: disable).
SetScanout(scanout, id uint32, r Rect) error
// Flush presents r (resource coordinates, inside the scanout's rect)
// of resource id on scanout.
Flush(scanout, id uint32, r Rect) error
// NewContext makes the backend half of a webgpu-batch context.
NewContext(ctx uint32) (Context, error)
}
Backend presents what the device model has validated. The Device checks every guest-supplied id, size, offset and rectangle before it calls a Backend, so an implementation may trust its arguments: ids name live resources, rectangles lie inside them, and src holds the rows Upload describes.
type Config ¶
type Config struct {
// Scanouts are the enabled displays' sizes, at most MaxScanouts.
Scanouts []Rect
// MaxHostMem bounds the bytes of all 2D resources (default 256 MiB,
// QEMU's max_hostmem default).
MaxHostMem uint64
// MaxResources bounds the number of live resources (default 4096).
MaxResources int
// MaxBackingEntries bounds ATTACH_BACKING's nr_entries (default
// 16384, QEMU virtio_gpu_create_mapping_iov).
MaxBackingEntries uint32
// WebGPUBatch, when set, offers the webgpu-batch capset with these
// limits and accepts its contexts.
WebGPUBatch *wgpubatch.Caps
// MaxContexts bounds live contexts (default 16).
MaxContexts int
}
Config describes the device a guest sees and the bounds it enforces. Zero values take the defaults documented on each field.
type Context ¶
type Context interface {
// Create makes an object of a go-gfx/webgpu wire kind from its
// descriptor (object references already translated) and returns the
// id the backend's replayer knows it by (nonzero).
Create(kind uint32, desc []byte) (id uint32, err error)
// Destroy releases an object Create returned.
Destroy(id uint32)
// Replay executes one go-gfx/webgpu Recorder submit whose ids are
// all ids Create returned, and returns once it has executed: the
// Device answers a fenced SUBMIT_3D after Replay returns.
Replay(words []uint32, data []byte) error
// Bind gives an object a window of guest memory (a resource's
// backing) for upload and readback.
Bind(id uint32, w Window) error
// Close releases everything the context holds.
Close()
}
Context is the backend half of a webgpu-batch context. The Device has decoded and bounded each message and translated every object id from the guest's namespace to the ids Create returned.
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device is one virtio-gpu device. Its methods are safe for concurrent use; commands execute one at a time.
func (*Device) Features ¶
Features are the device feature bits (VERSION_1 is the transport's). With webgpu-batch: VIRGL, the "3D available" gate guests look for, and CONTEXT_INIT, which selects the capset.
func (*Device) HandleControl ¶
HandleControl executes one control-queue request and writes the response into resp, returning its length (0 when resp cannot hold it: the guest gave a response buffer too short for the answer).
req must be host memory, not a view of guest memory: the device checks a value and then uses it, and a guest rewriting shared memory between the two would defeat the check (virglrenderer copies its commands out for the same reason, vkr_ring.c:312). The pcisim transport gathers every request into a fresh buffer.
func (*Device) NumCapsets ¶
NumCapsets is virtio_gpu_config.num_capsets.
func (*Device) NumScanouts ¶
NumScanouts and NumCapsets are the virtio_gpu_config fields.
type Format ¶
type Format uint32
Format is a VIRTIO_GPU_FORMAT_* value (virtio_gpu.h:381-390). Every format is 4 bytes per pixel; the name gives the byte order in memory.
type Memory ¶
type Memory interface {
// Slice returns a view of n bytes at guest-physical addr, or an
// error if any of them lies outside guest memory.
Slice(addr, n uint64) ([]byte, error)
}
Memory is the guest's physical memory as the device sees it. Every guest-supplied address goes through Slice, which bounds it.
Directories
¶
| Path | Synopsis |
|---|---|
|
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).
|
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). |
|
Package pcisim puts a gpudev.Device behind an emulated virtio-pci modern transport, in process: it implements go-virtio/common.Transport, so the go-virtio/gpu guest driver (or any driver written against that interface) can bring the device up and drive it with no VM.
|
Package pcisim puts a gpudev.Device behind an emulated virtio-pci modern transport, in process: it implements go-virtio/common.Transport, so the go-virtio/gpu guest driver (or any driver written against that interface) can bring the device up and drive it with no VM. |
|
Package virtq is the device side of a virtio split virtqueue: it takes descriptor chains the driver made available and returns them used.
|
Package virtq is the device side of a virtio split virtqueue: it takes descriptor chains the driver made available and returns them used. |
|
Package webgpuback is the browser backend of gpudev, on go-gfx/webgpu.
|
Package webgpuback is the browser backend of gpudev, on go-gfx/webgpu. |