Documentation
¶
Overview ¶
Package gpu renders on the GPU through Vulkan, into memory shared with the compositor (or a display) as dmabufs: what a frame draws is handed over by file descriptor, with no copy. lys-ui's windows, lys-shell's surfaces and lys-wm's output all draw through it.
Vulkan loads at runtime (third_party/vk, pure Go, no cgo). Open fails with ErrNoVulkan or ErrNoDevice where there is no loader or no device that draws; callers then draw on the CPU (package render). A device that cannot export dmabufs still renders offscreen (NewOffscreen); its NewTarget fails with ErrNoDmabuf.
A Device and everything made from it belong to one goroutine.
Index ¶
- Variables
- type Buffer
- type Codec
- type Device
- func (d *Device) Close()
- func (d *Device) Codecs() []Codec
- func (d *Device) ExportModifiers(format uint32) ([]uint64, error)
- func (d *Device) Exports() bool
- func (d *Device) Modifiers(format uint32) ([]uint64, error)
- func (d *Device) Name() string
- func (d *Device) NewBuffer(width, height int, format uint32, offered []uint64) (*Buffer, error)
- func (d *Device) NewEncoder(cfg EncoderConfig) (*Encoder, error)
- func (d *Device) NewOffscreen(width, height int) (*Target, error)
- func (d *Device) NewTarget(width, height int, format uint32, modifiers []uint64) (*Target, error)
- func (d *Device) Render(l *render.List, t *Target) error
- type Encoder
- type EncoderConfig
- type Packet
- type Target
- type Transform
Constants ¶
This section is empty.
Variables ¶
var ErrNoDevice = errors.New("gpu: no Vulkan device draws")
ErrNoDevice reports that no Vulkan device has a graphics queue.
var ErrNoDmabuf = errors.New("gpu: the device does not export dmabufs")
ErrNoDmabuf reports a device that cannot render into dmabufs.
var ErrNoVideoEncoder = errors.New("gpu: the device has no video encoder")
ErrNoVideoEncoder reports a device that does not encode the codec asked for: no video encode queue (lavapipe, older radv and anv), or one without that codec.
var ErrNoVulkan = errors.New("gpu: no Vulkan loader")
ErrNoVulkan reports that the Vulkan loader (libvulkan) is missing.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is an image whose memory is a dmabuf this device allocates for others to write and read, a screencast frame a compositor copies into, and never draws into itself: it asks only for transfer and sampling, so layouts a device cannot render to (NVIDIA's linear) are on offer (ExportModifiers).
func (*Buffer) Close ¶
func (b *Buffer) Close()
Close releases the buffer and its fd; closing it again, or after its device, does nothing.
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device is a Vulkan device rendering into dmabufs.
func Open ¶
Open picks the first Vulkan device with a graphics queue that exports dmabufs, else the first with a graphics queue.
func OpenNode ¶
OpenNode opens the Vulkan device behind the DRM node dev, its device number (st_rdev, as of /dev/dri/renderD128 or /dev/dri/card0): the device a dmabuf consumer negotiated, which must export dmabufs. linux-dmabuf's main device may name either node of a GPU.
func (*Device) Close ¶
func (d *Device) Close()
Close releases the device and the targets still open on it: a target closed after is already closed. Closing it again does nothing.
func (*Device) Codecs ¶
Codecs are the codecs the device encodes; none on a device without a video encode queue.
func (*Device) ExportModifiers ¶
ExportModifiers are the single-plane DRM modifiers the device allocates format in for a Buffer: what to intersect with the ones a consumer imports before NewBuffer.
func (*Device) Modifiers ¶
Modifiers are the DRM modifiers the device renders format into as a single-plane color attachment: what to intersect with the ones a consumer imports before NewTarget.
func (*Device) Name ¶
Name is the device's name, "NVIDIA GeForce RTX 3060 Ti" or "llvmpipe (LLVM 21.1.8, 256 bits)".
func (*Device) NewBuffer ¶
NewBuffer allocates a width x height Buffer in format (a DRM fourcc: ARGB8888 or XRGB8888) whose layout the driver picks among offered, the modifiers the consumer imports, that the device exports format in (ExportModifiers). None in common, as with only the implicit dmabuf.ModifierInvalid on offer, is an error naming both lists.
func (*Device) NewEncoder ¶
func (d *Device) NewEncoder(cfg EncoderConfig) (*Encoder, error)
NewEncoder makes an encoder for cfg: ErrNoVideoEncoder when the device does not encode cfg.Codec, an error naming the limit when it cannot encode cfg's size.
func (*Device) NewOffscreen ¶
NewOffscreen allocates a width x height target in device memory no other process imports: a frame rendered for its pixels (ReadPixels), a screenshot or a test.
func (*Device) NewTarget ¶
NewTarget allocates a width x height image in format (a DRM fourcc: dmabuf.FormatARGB8888, or FormatXRGB8888 with the same bytes) whose layout the driver picks among modifiers, the ones the consumer imports, that the device renders format in (Modifiers): linear when both take it. None in common, as with only the implicit dmabuf.ModifierInvalid on offer, is an error naming both lists.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder encodes frames into H.264 or H.265 on the device's video queue. A frame's pixels come from a Buffer a compositor copied a screen into: a compute pass converts them to NV12, and the video queue encodes that while the next frame converts. Like the Device, it belongs to one goroutine.
func (*Encoder) Close ¶
func (e *Encoder) Close()
Close waits for the frames in flight, dropping their packets, and releases the encoder; closing it again does nothing.
func (*Encoder) Encode ¶
Encode converts src's pixels (a Buffer the size the encoder was made for) and queues them for encoding, presented at pts; it returns the packets of the frames that finished meanwhile, oldest first. src is free to take the next frame when Encode returns.
func (*Encoder) Flush ¶
Flush waits for the frames in flight and returns their packets, oldest first.
func (*Encoder) ParameterSets ¶
ParameterSets are the stream's parameter sets as NAL units without start codes: the SPS and the PPS for H.264, the VPS, SPS and PPS for H.265.
func (*Encoder) SetOverlay ¶
SetOverlay draws img over every following frame's pixels, scaled (linear filtering) to fill dst in frame coordinates, opaque, before the NV12 conversion; nil removes it. img is uploaded here, so the caller may reuse it once SetOverlay returns. dst is clipped to the frame; an empty dst, or one off the frame, is an error.
type EncoderConfig ¶
type EncoderConfig struct {
Codec Codec
// Width and Height are the frame size. The stream is coded in the
// device's units and at least its smallest size, the padding's
// pixels the edge's repeated and cropped off on decode; an odd size
// decodes one pixel larger, its last row or column twice.
Width, Height int
// FrameRate is the frames a second the stream runs at, for its
// level; frames may come at any time.
FrameRate int
// KeyInterval is the frames from one keyframe to the next.
KeyInterval int
// Source is the region of the buffer Encode reads, in the buffer's
// own orientation; the zero rectangle reads all of it.
Source image.Rectangle
// Transform is the captured output's wl_output transform: the
// buffer holds the output's pixels so turned, and the encoder turns
// them back, so the frame shows what the output shows. Width and
// Height are the frame's, turned: a 90 or 270 degree transform
// swaps the source region's.
Transform Transform
// QP is the constant quantiser, 0 (best) to 51. A device without
// constant-QP coding runs its own rate control at a bitrate
// matching QP 20 on desktop content instead.
QP int
}
EncoderConfig is a video stream's shape.
type Packet ¶
Packet is one encoded frame: an Annex-B access unit (start-code delimited NAL units, without the parameter sets, which ParameterSets gives), the time it was handed in at, and whether it is a keyframe (an IDR).
type Target ¶
type Target struct {
// contains filtered or unexported fields
}
Target is an image the GPU renders into whose memory is a dmabuf: a window's frame handed to the compositor, or an output's scanout buffer. Its layout (the DRM modifier) is one the caller offered, as the consumer imports it. Between frames it belongs to the consumer.
func (*Target) Close ¶
func (t *Target) Close()
Close releases the target and its dmabuf fd; closing it again, or after its device, does nothing.
func (*Target) Dmabuf ¶
Dmabuf describes the target's memory for its consumer. Its fd is the target's, open until Close; an offscreen target has none.
func (*Target) ReadPixels ¶
ReadPixels copies the target back into memory as premultiplied RGBA: tests and screenshots.