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 ¶
- Constants
- Variables
- func Bilinear(pix []byte, stride, w, h int, u, v float32) [4]float32
- func GooCoverage(g Goo, px, py float32) float32
- func GradientAt(from, to [2]float32, stops []color.RGBA, px, py float32) color.RGBA
- func KawaseAt(sample func(u, v float32) [4]float32, up bool, u, v, hx, hy float32) [4]float32
- type AlphaCut
- type Buffer
- type Carry
- type ChromaSiting
- type Codec
- type ColorFunc
- type ColorKind
- type ColorTransform
- type CutUniforms
- type Device
- func (d *Device) Begin(t *Target, damage []image.Rectangle) (*Pass, error)
- func (d *Device) BlockingWaits() uint64
- func (d *Device) Close()
- func (d *Device) Codecs() []Codec
- func (d *Device) CopyToLinear(dst *Linear, src *Target, rects []image.Rectangle) error
- func (d *Device) DecodeCodecs() []demux.Codec
- func (d *Device) ExportModifiers(format fourcc.Format) ([]fourcc.Modifier, error)
- func (d *Device) Exports() bool
- func (d *Device) Finish() error
- func (d *Device) Flush() error
- func (d *Device) Forget(id render.ImageID)
- func (d *Device) FrameDone() (time.Duration, bool, error)
- func (d *Device) FrameIncomplete() bool
- func (d *Device) ImportFormats() []fourcc.Format
- func (d *Device) ImportLinear(b dmabuf.Buffer) (*Linear, error)
- func (d *Device) ImportTarget(b dmabuf.Buffer) (*Target, error)
- func (d *Device) ImportTexture(b dmabuf.Buffer) (*Texture, error)
- func (d *Device) ImportTextureYCbCr(b dmabuf.Buffer, c YCbCr) (*Texture, error)
- func (d *Device) LoseForTesting()
- func (d *Device) Modifiers(format fourcc.Format) ([]fourcc.Modifier, error)
- func (d *Device) Name() string
- func (d *Device) NewBuffer(width, height int, format fourcc.Format, offered []fourcc.Modifier) (*Buffer, error)
- func (d *Device) NewEncoder(cfg EncoderConfig) (*Encoder, error)
- func (d *Device) NewFragmentShader(spv []byte) (*FragmentShader, error)
- func (d *Device) NewOffscreen(width, height int) (*Target, error)
- func (d *Device) NewOffscreenFloat(width, height int) (*Target, error)
- func (d *Device) NewReadback(width, height int) (*Readback, error)
- func (d *Device) NewTarget(width, height int, format fourcc.Format, modifiers []fourcc.Modifier) (*Target, error)
- func (d *Device) NewTexture(format fourcc.Format, width, height int) (*Texture, error)
- func (d *Device) NewVideoDecoder(track demux.Track) (*VideoDecoder, error)
- func (d *Device) OpaqueRuns() uint64
- func (d *Device) Prepare(formats ...fourcc.Format) error
- func (d *Device) PrepareOffscreen(width, height int) (*Target, error)
- func (d *Device) PrepareTarget(width, height int, format fourcc.Format, modifiers []fourcc.Modifier) (*Target, error)
- func (d *Device) Prepared() (bool, error)
- func (d *Device) Publish(t *Target) error
- func (d *Device) Render(l *render.List, t *Target, carry ...Carry) error
- func (d *Device) RenderExplicit(l *render.List, t *Target, carry ...Carry) (int, error)
- func (d *Device) RenderNode() (string, bool)
- func (d *Device) Submissions() uint64
- func (d *Device) SyncFile() (int, error)
- func (d *Device) SyncFiles() bool
- func (d *Device) TargetModifiers(format fourcc.Format) ([]fourcc.Modifier, error)
- func (d *Device) TextureFormats() []fourcc.Format
- func (d *Device) TextureModifiers(format fourcc.Format) ([]fourcc.Modifier, error)
- func (d *Device) Trim() error
- func (d *Device) WaitSyncFile(fd int) error
- type Encoder
- func (e *Encoder) Backend() EncoderBackend
- func (e *Encoder) Close() error
- func (e *Encoder) Encode(src *Buffer, pts time.Duration) ([]Packet, error)
- func (e *Encoder) Flush() ([]Packet, error)
- func (e *Encoder) ParameterSets() [][]byte
- func (e *Encoder) SetOverlay(img *image.RGBA, dst image.Rectangle) error
- type EncoderBackend
- type EncoderConfig
- type FRect
- type Falloff
- type FieldOrder
- type FragmentShader
- type Glass
- type Goo
- type Gradient
- type Linear
- type Losses
- type Mask
- type Packet
- type Pass
- func (p *Pass) Clear(c color.RGBA)
- func (p *Pass) ClearCut()
- func (p *Pass) DrawFragmentShader(s *FragmentShader, t *Texture, dst image.Rectangle, constants [4]float32)
- func (p *Pass) DrawFrame(f *VideoFrame, src FRect, dst image.Rectangle, tr Transform, alpha float32, ...)
- func (p *Pass) DrawGlass(t *Texture, src FRect, dst image.Rectangle, alpha float32, m Mask, g Glass)
- func (p *Pass) DrawTexture(t *Texture, src FRect, dst image.Rectangle, tr Transform, alpha float32, ...)
- func (p *Pass) End() error
- func (p *Pass) FillGoo(r image.Rectangle, c color.RGBA, g Goo)
- func (p *Pass) FillGradient(r image.Rectangle, g Gradient, m Mask)
- func (p *Pass) FillRect(r image.Rectangle, c color.RGBA, m Mask)
- func (p *Pass) Incomplete() bool
- func (p *Pass) Kawase(t *Texture, dst image.Rectangle, offset float32, up bool)
- func (p *Pass) SetColor(t *ColorTransform)
- func (p *Pass) SetCut(t *Texture, c AlphaCut)
- type Readback
- type RoundRect
- type Siting
- type Target
- type Texture
- type Transform
- type VideoDecoder
- type VideoFrame
- type YCbCr
- type YCbCrMatrix
- type YCbCrRange
Constants ¶
const ColorUniforms = 9
ColorUniforms is how many vec4s ColorGLSL reads through CP.
const LossLimit = 3
LossLimit is how many device losses within LossWindow a consumer recovers from by opening a new device; one more within the window is a GPU that cannot keep a device, and the consumer stops recovering.
const LossWindow = time.Minute
LossWindow is the span over which Losses counts losses against LossLimit.
Variables ¶
var ColorGLSL string
ColorGLSL is the GLSL of ColorTransform.Apply, colorApply, valid as GLSL 4.50 and as GLSL ES 1.00, for renderers outside this package to share. CP must name its nine vec4s, ColorTransform.Uniforms.
var CutGLSL string
CutGLSL is the GLSL of CutUniforms.Keeps at CutUniforms.UV, cutCoverage, valid as GLSL 4.50 and as GLSL ES 1.00 with SAMPLE naming the sampling function and CUT_SAMPLER the sampler type, for renderers outside this package to share.
var ErrBusy = errors.New("gpu: frames in flight are at their bound")
ErrBusy reports a frame Render refused, having done nothing, because the GPU is too far behind for one more: try again once the frames ahead of it finish, as FrameDone or a compositor's release will show.
var ErrDeviceClosed = errors.New("gpu: the device is closed")
ErrDeviceClosed reports a target prepared after its device's Close began.
var ErrDeviceLost = errors.New("gpu: the Vulkan device is lost")
ErrDeviceLost reports a Vulkan device that was lost (VK_ERROR_DEVICE_LOST): a GPU reset or a driver fault. Nothing further submitted to it runs: a consumer closes it and opens a new one, or ends so that a supervisor can.
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 ErrNoFrameTime = errors.New("gpu: the device has no calibrated timestamps")
ErrNoFrameTime reports a device whose GPU timestamps do not map onto CLOCK_MONOTONIC (no calibrated timestamps).
var ErrNoSyncFile = errors.New("gpu: the device has no sync_file semaphores")
ErrNoSyncFile reports a device that exports or imports no sync_file.
var ErrNoVideoDecoder = errors.New("gpu: the device has no video decoder")
ErrNoVideoDecoder reports a device that does not decode the codec asked for on a Vulkan video decode queue.
var ErrNoVideoEncoder = errors.New("gpu: the device has no video encoder")
ErrNoVideoEncoder reports a device that does not encode the codec asked for: neither on a Vulkan video encode queue (lavapipe, older radv, anv on Xe2) nor through a VA-API driver.
var ErrNoVulkan = errors.New("gpu: no Vulkan loader")
ErrNoVulkan reports that the Vulkan loader (libvulkan) is missing.
var ErrTimeout = errors.New("gpu: the device did not finish within the wait limit")
ErrTimeout reports work the device had not finished within its wait limit. An Encoder keeps the frame it waited for in flight: a later Encode or Flush waits for it again.
var GlassGLSL string
GlassGLSL is the GLSL of a Glass draw, glassBackdrop and glassAdjust, valid as GLSL 4.50 and as GLSL ES 1.00 after MaskGLSL and with SAMPLE naming the sampling function, for renderers outside this package to share.
var MaskGLSL string
MaskGLSL is the GLSL of Mask.Coverage, maskCoverage, of GradientAt's texture coordinate, gradientUV, and, when SAMPLE names the sampling function (texture or texture2D), of KawaseAt's kawaseDown and kawaseUp, valid as GLSL 4.50 and as GLSL ES 1.00, for renderers outside this package to share.
Functions ¶
func Bilinear ¶
Bilinear samples pix, w x h premultiplied BGRA pixels stride bytes a row, at texture coordinate (u, v) as a linear sampler clamped to its edges does, returning B, G, R, A in 0..255.
func GooCoverage ¶
GooCoverage is the fraction of the pixel whose centre is (px, py) that FillGoo covers for g, as the shader computes it.
func GradientAt ¶
GradientAt is the premultiplied colour FillGradient gives the pixel whose centre is (px, py), for stops spread from from to to, as the shader computes it.
Types ¶
type AlphaCut ¶
AlphaCut keeps a draw only where a texture's alpha is above Threshold: the texture's Src region laid over Dst, in target pixels, through Transform, as DrawTexture lays it. Outside Dst nothing is kept. A texture sampling opaque has alpha 1 everywhere.
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 or the linear copy of a frame another card scans out, 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). It comes in the formats a Target does, the 10-bit ones too, so a copy of any target has a Buffer to land in.
func (*Buffer) Close ¶
func (b *Buffer) Close()
Close releases the buffer and its fd, its image once the conversions that read it (Encoder.Encode) have finished; closing it again, or after its device, does nothing.
type Carry ¶
Carry is what a consumer rotating through targets copies into the one it reuses before drawing: Rects of From, which was shown since, the rest of the target already being up to date. From is read where it stands, since it may still be on screen. A rect r takes From's pixels at r moved by Offset, as scrolling does, and the part of r without a source stays as it was. From may be the target itself when Offset is not zero: the pixels then go through a scratch surface, as one image's overlapping copies are undefined.
type ChromaSiting ¶
type ChromaSiting struct {
X, Y Siting
}
ChromaSiting is where a subsampled chroma sample lies along each axis, relative to the luma samples it covers.
type ColorFunc ¶
ColorFunc is one transfer function. A ColorCurve is ICC's parametric form, mirrored through the origin: (A*x + B)^G + E where x >= D, and C*x + F below it.
type ColorTransform ¶
type ColorTransform struct {
Decode ColorFunc
Luma [3]float32
HLGGamma float32
Matrix [9]float32
Knee float32
Compress float32
Scale float32
Encode ColorFunc
}
ColorTransform takes a premultiplied colour from one encoding to another: un-premultiply, Decode (then, for HLG, the OOTF: scene light scaled by its Luma luminance to the power HLGGamma - 1), Matrix, compress the largest channel above Knee when Compress is positive, multiply by Scale, Encode, and premultiply again. It is a value, so equal transforms compare equal.
func (*ColorTransform) Apply ¶
func (t *ColorTransform) Apply(c [4]float32) [4]float32
Apply is colorApply in Go: c, premultiplied, through the transform. What a client's float buffer holds beyond the finite, NaN and infinities, comes out as nothing, so it cannot stick in a target that blends over it for good.
func (*ColorTransform) Uniforms ¶
func (t *ColorTransform) Uniforms() [ColorUniforms][4]float32
Uniforms packs t for ColorGLSL.
type CutUniforms ¶
type CutUniforms [2][4]float32
CutUniforms is an AlphaCut over one texture as CutGLSL reads it: the texture coordinate's change per target pixel along x and y, then its value at the target's origin, the threshold and 1 for an opaque texture.
func (CutUniforms) Keeps ¶
func (u CutUniforms) Keeps(a float32) bool
Keeps reports whether a texel of alpha a keeps what is drawn over it.
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) Begin ¶
Begin starts a pass drawing into t, where only damage, clipped to t, changes. One pass at a time is open on a device.
func (*Device) BlockingWaits ¶
BlockingWaits counts the times this device's goroutine has waited for the GPU to finish: a frame that adds to it could have missed its deadline for the work ahead of it.
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. The process's Vulkan instance stays for the next Open.
func (*Device) Codecs ¶
Codecs are the codecs the device encodes, on its Vulkan video queue or its VA-API driver.
func (*Device) CopyToLinear ¶
CopyToLinear copies rects of src, clipped to it, into the same rects of dst, a buffer of src's size and format, with the copy engine: no render pass touches dst. Like a Pass it is submitted without waiting; SyncFile signals when it is done. dst outside rects keeps what it held.
func (*Device) DecodeCodecs ¶
DecodeCodecs are the codecs NewVideoDecoder decodes on the device.
func (*Device) ExportModifiers ¶
ExportModifiers are the single-plane DRM modifiers the device allocates format, one of TextureFormats, in for a Buffer: what to intersect with the ones a consumer imports before NewBuffer. A device may export a format in none.
func (*Device) Finish ¶
Finish waits until everything submitted to the device has finished: a CPU read of a target's dmabuf, a test.
func (*Device) Flush ¶
Flush submits the passes ended and the uploads made since the last submission, without waiting for them: what a consumer that waits on no SyncFile calls before handing a target over. SyncFile, Finish and a CPU read submit them too.
func (*Device) Forget ¶
Forget drops what the device keeps for the raster of identity id, its textures and its mask atlas slot, once the frame the device is drawing, or else its next one, is done: an owner that frees the raster (render.Retire) frees the GPU copy with it rather than leaving it to the maxImages bound or Trim, and a List recorded before the eviction still draws from the texture in that frame. A List still open after that frame that draws the raster uploads it again, from pixels Retire keeps until that List ends. It is safe from any goroutine. Zero, no identity, panics: a raster without one is kept by its pixels' address and is the garbage collector's to free.
func (*Device) FrameDone ¶
FrameDone reports when the last ended Pass finished on the GPU, on CLOCK_MONOTONIC: what a compositor's latch budget samples. It reports false while that pass is still running, or before any pass. A pass not yet submitted is submitted, as Flush does.
func (*Device) FrameIncomplete ¶
FrameIncomplete reports that the last Render left out an image still on its way to the GPU: the caller keeps that frame's damage for its next one.
func (*Device) ImportFormats ¶
ImportFormats are the DRM formats ImportTexture may take: what to ask TextureModifiers about, which is empty for one the driver lacks.
func (*Device) ImportLinear ¶
ImportLinear imports b, a dmabuf in one of TextureFormats with the linear modifier and one plane, as a Linear that CopyToLinear writes. b's fd stays the caller's.
func (*Device) ImportTarget ¶
ImportTarget imports b, a dmabuf in one of TextureFormats and a modifier of TargetModifiers (a scanout buffer GBM allocated), as a target a Pass draws into, its contents kept between passes. Like an exported target it is handed back to its consumer after each pass, and a pass waits on the GPU for the fences the buffer's other users left on it. Its Dmabuf has no planes: b's fds stay the caller's.
func (*Device) ImportTexture ¶
ImportTexture imports b, a client's dmabuf in one of ImportFormats (a YUV one as BT.601 limited range; ImportTextureYCbCr takes the buffer's hints), and a modifier of TextureModifiers, as a texture a Pass samples. Its producer writes it; Update refuses it, and a pass that samples it waits on the GPU for the producer's fence on the dmabuf. b's fds stay the caller's: the texture holds the memory, and a dup of each dmabuf, until Close.
func (*Device) ImportTextureYCbCr ¶
ImportTextureYCbCr is ImportTexture sampling a YUV buffer through c; an RGB buffer ignores c.
func (*Device) LoseForTesting ¶
func (d *Device) LoseForTesting()
LoseForTesting arms a device loss, for tests of what handles one: the device's next submission on any of its queues (a pass's, an upload's, a video decode's or encode's) fails with ErrDeviceLost as if the driver had answered VK_ERROR_DEVICE_LOST, and so does everything after it that submits or waits for the GPU, a VideoDecoder's and an Encoder's calls too, until the device is closed. The GPU itself is untouched: the next device opened on it works. A device nobody armed never takes this path.
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 ¶
func (d *Device) NewBuffer(width, height int, format fourcc.Format, offered []fourcc.Modifier) (*Buffer, error)
NewBuffer allocates a width x height Buffer in format, one of TextureFormats, 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 fourcc.Invalid 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 on the device's Vulkan video queue when it encodes cfg.Codec, else on its VA-API driver: ErrNoVideoEncoder, with both backends' reasons, when neither does, and an error naming the limit when the encoder cannot code cfg's size.
func (*Device) NewFragmentShader ¶
func (d *Device) NewFragmentShader(spv []byte) (*FragmentShader, error)
NewFragmentShader takes spv, whole SPIR-V words in the host's byte order. A driver's refusal is an error and leaves the device as it was; the module must still be valid SPIR-V, which nothing checks here.
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) NewOffscreenFloat ¶
NewOffscreenFloat is NewOffscreen in half floats: premultiplied linear light that keeps values above one and below zero, for a compositor's working space. A pass draws into it and samples it as any other, with the same premultiplied blending; its pixels are not read back. It starts transparent: a NaN in fresh memory would survive every blend over it.
func (*Device) NewReadback ¶
NewReadback allocates memory for copies of a width x height target.
func (*Device) NewTarget ¶
func (d *Device) NewTarget(width, height int, format fourcc.Format, modifiers []fourcc.Modifier) (*Target, error)
NewTarget allocates a width x height image in format (one of TextureFormats; Render draws only into ARGB8888 and XRGB8888, a Pass into any) 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 fourcc.Invalid on offer, is an error naming both lists.
func (*Device) NewTexture ¶
NewTexture allocates a width x height texture in format, one of TextureFormats; the X formats sample opaque. It holds transparent black until Update writes it.
func (*Device) NewVideoDecoder ¶
func (d *Device) NewVideoDecoder(track demux.Track) (*VideoDecoder, error)
NewVideoDecoder makes a decoder for track, one of the device's DecodeCodecs; its configuration record is the stream's parameter sets. A codec the device does not decode is ErrNoVideoDecoder, naming the codec and why.
func (*Device) OpaqueRuns ¶
OpaqueRuns counts the runs of draws this device recorded with blending off: opaque fills, opaque textures at full alpha, unmasked, and Kawase levels.
func (*Device) Prepare ¶
Prepare builds, on a worker, the pipelines drawing into targets of formats takes, including the ones a device builds only when first drawn, and from then on any pipeline a frame finds missing goes to the worker too: nothing compiles while a pass records. A pass that meets a pipeline not built yet skips that draw and reports Incomplete. Prepared reports when the worker has nothing left. Bad formats fail at once; a driver's refusal comes from a later Begin.
func (*Device) PrepareOffscreen ¶
PrepareOffscreen is NewOffscreen from any goroutine, as PrepareTarget.
func (*Device) PrepareTarget ¶
func (d *Device) PrepareTarget(width, height int, format fourcc.Format, modifiers []fourcc.Modifier) (*Target, error)
PrepareTarget is NewTarget from any goroutine, with the driver's allocation and the view and framebuffer a first draw would make done there. The target reaches the device's goroutine with no lock: use it there as any other. Close waits for the prepares running; one starting after it is ErrDeviceClosed.
func (*Device) Prepared ¶
Prepared reports whether the worker has built everything asked of it; the pipelines reach passes from the next Begin.
func (*Device) Publish ¶
Publish hands t to its consumer with what the passes ended so far drew into it: what Render does for the target it draws. The passes are submitted, with everything else the device holds back, and t's dmabuf gets a fence that signals once they are done, which linux-dmabuf's implicit synchronization has every reader wait on; Publish then returns without waiting. Where no such fence tells the consumer (NVIDIA's driver, which does not wait on one when a compositor samples a buffer; a device without sync_files; a kernel that attaches none to a dmabuf) Publish waits here until the passes are done. Either way the consumer may take t when it returns. An offscreen target has no consumer: its passes are submitted, no more.
func (*Device) Render ¶
Render draws l onto t and hands t back to its consumer, without waiting for the GPU where the device can tell the consumer when it is done (publish). l is recorded at t's size; its layers keep their GPU surfaces on this device across frames. ErrBusy, before anything is done, means the GPU is too far behind for one more frame. carry is copied into t first, in the frame's own submission.
func (*Device) RenderExplicit ¶
RenderExplicit is Render for a consumer that takes its fence explicitly, never waiting for the GPU: the sync_file it returns, the caller's to close, signals when the frame is done, for wp_linux_drm_syncobj_surface_v1's acquire point (drm.Device.ImportSyncFile then SetAcquirePoint). -1 means it is done already. ErrNoSyncFile reports a device with no sync_files.
func (*Device) RenderNode ¶
RenderNode is the path of the device's DRM render node, as the driver names its major and minor (VK_EXT_physical_device_drm): what a caller opens to reach the same GPU, for timeline syncobjs. False for a device the driver names none for, lavapipe's.
func (*Device) Submissions ¶
Submissions counts the queue submissions this device made: a frame of passes followed by SyncFile is one.
func (*Device) SyncFile ¶
SyncFile returns a sync_file, the caller's to close, that signals once everything submitted to the device so far has finished: a pass's out-fence for KMS or a linux-drm-syncobj release point. -1 with no error means it has all finished already: there is nothing to wait on, as for WaitSyncFile. It costs a submission only when nothing submitted can answer: the newest pass signals a semaphore once SyncFile has been asked for, and until the next submission every later call shares that one fence.
func (*Device) TargetModifiers ¶
TargetModifiers are the DRM modifiers ImportTarget takes format in: what to allocate a scanout buffer the device renders into in.
func (*Device) TextureFormats ¶
TextureFormats are the formats NewTexture takes.
func (*Device) TextureModifiers ¶
TextureModifiers are the DRM modifiers ImportTexture takes format in: what a compositor offers its clients through linux-dmabuf.
func (*Device) Trim ¶
Trim hands back what the device keeps only for speed: the CPU scratch canvases, freed off the Go heap and unmapped, the buffers of finished segments, and the image textures not drawn since the last Trim. A device that draws again allocates them anew. Call it when the device has been idle a while, between frames, on the device's goroutine.
func (*Device) WaitSyncFile ¶
WaitSyncFile makes the device's next submission (the one carrying the passes ended since the last, an upload, a copy) wait for the fence in the sync_file fd before it runs: a client's acquire fence, or a DRM syncobj point exported as one. The device takes fd, closing it even on error; -1 is a fence already signalled, and one that has signalled costs the submission nothing.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder encodes frames into H.264 or H.265 on the device's hardware encoder: its Vulkan video queue, else its VA-API driver. A frame's pixels come from a Buffer a compositor copied a screen into: a compute pass crops, turns, overlays and converts them to NV12, a submission of the device like any pass's, and the backend encodes that while the next frame converts. Like the Device, it belongs to one goroutine.
func (*Encoder) Backend ¶
func (e *Encoder) Backend() EncoderBackend
Backend is the path the encoder encodes through, the Vulkan video queue or the VA-API driver, as NewEncoder chose it.
func (*Encoder) Close ¶
Close waits for the frames in flight, dropping their packets, and releases the encoder; closing it again does nothing. A frame the VA-API driver has not finished within the device's wait limit is ErrTimeout, and what the driver may still be using of it is left allocated rather than released underneath it.
func (*Encoder) Encode ¶
Encode queues src's pixels (a Buffer the size the encoder was made for) for conversion and encoding, presented at pts; it returns the packets of the frames that finished meanwhile, oldest first. src is its writer's again when Encode returns: the conversion that reads it has put its fence on src's dmabuf, which whoever writes the next frame into it under linux-dmabuf's implicit synchronization waits for, so nothing waits here and the Vulkan video queue encodes after the conversion on the GPU. Where no fence tells the writer (NVIDIA's driver, a device without sync_files) Encode waits for the conversion instead, as it does for the VA-API driver, which takes no semaphore: the device's wait limit at most. A packet collected before a conversion or an encode that then fails is not lost: the next Encode or Flush returns it. A frame whose wait times out, ErrTimeout, stays in flight, its slot with it: the next Encode or Flush waits for it again.
func (*Encoder) Flush ¶
Flush waits for the frames in flight and returns their packets, oldest first, behind any an Encode that failed had collected. When collecting a frame fails, the packets before it come out of the next Flush, and a frame whose wait timed out stays in flight for it.
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 EncoderBackend ¶
type EncoderBackend int
EncoderBackend is the path an Encoder encodes through.
const ( // VulkanVideo is the device's Vulkan video encode queue. VulkanVideo EncoderBackend = iota // VAAPI is the device's VA-API driver. VAAPI )
The encoder backends.
func (EncoderBackend) String ¶
func (b EncoderBackend) String() string
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, coded at the
// encoder's finest where that is coarser. 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 FRect ¶
type FRect struct {
X, Y, W, H float64
}
FRect is a rectangle in fractional pixels: the region of a texture a draw samples, as wp_viewporter crops a buffer.
type Falloff ¶
type Falloff struct {
Range, Power float32
}
Falloff softens Keep's edge: coverage falls from 1 at the edge to 0 Range pixels outside it, as (1 - d/Range)^Power, a drop shadow's shape. The zero Falloff is an anti-aliased edge.
type FieldOrder ¶
type FieldOrder uint8
FieldOrder is how a frame's lines were sampled in time: all at once, or as two fields, the even lines (the top field) and the odd lines (the bottom field) a field period apart.
const ( // Progressive frames are one picture. Progressive FieldOrder = iota // TopFieldFirst frames are two fields woven, the top field the // earlier. TopFieldFirst // BottomFieldFirst frames are two fields woven, the bottom field // the earlier. BottomFieldFirst )
The field orders.
func (FieldOrder) String ¶
func (o FieldOrder) String() string
type FragmentShader ¶
type FragmentShader struct {
// contains filtered or unexported fields
}
FragmentShader is a fragment shader the caller built at runtime, to draw a whole texture through. Its SPIR-V module takes the compositor pipeline's interface: the texture at set 0 binding 0, its coordinate at input location 0 (0,0 at the top left of dst), colour at output location 0, and comp.glsl's Draw push constants, of which DrawFragmentShader's constants are keep.
func (*FragmentShader) Close ¶
func (s *FragmentShader) Close() error
Close frees the shader once the frames in flight that may draw with it finish.
func (*FragmentShader) Prepare ¶
func (s *FragmentShader) Prepare(t *Target) error
Prepare builds what drawing into t takes, the part a driver may yet refuse, so that a caller can learn of that before it opens a pass.
type Glass ¶
Glass is how DrawGlass turns a blurred backdrop into a glass surface: the factors of saturate(), brightness() and contrast(), where 1 changes nothing, and the bezel the backdrop bends through along the edge, with its displacement at the rim, both in target pixels, as -lys-refract() does; an empty bezel or no displacement bends nothing.
func (Glass) Check ¶
Check reports a factor or length that is negative, infinite or NaN, and a mask DrawGlass cannot draw through: a falloff or a merge, which a glass surface has no use for.
func (Glass) Mask ¶
Mask is the mask a glass draw over dst uses: m, whose Keep is also the shape the bezel runs along, taking dst for a Keep it does not have.
func (Glass) RefractPlan ¶
func (g Glass) RefractPlan(box RoundRect) render.RefractPlan
RefractPlan is the bend through a bezel along box, the arithmetic lys-ui's -lys-refract() runs, for a renderer without a shader.
type Goo ¶
Goo is two rounded rectangles merged into one blob: their distance fields joined by a smooth minimum that melts them together where they come within Smooth pixels of each other, as metaballs do; zero Smooth is their plain union. GooCoverage mirrors it in Go.
type Gradient ¶
Gradient is a linear gradient from From to To, in target pixels: Stops, an N x 1 texture of N >= 2 premultiplied colours, spread evenly from From (the first) to To (the last), each pixel taking the colour at its projection onto the line, clamped at the ends, the stops between interpolated linearly, all of it at Alpha.
type Linear ¶
type Linear struct {
// contains filtered or unexported fields
}
Linear is a linear single-plane dmabuf imported as a buffer, not an image: what a copy engine writes a frame into for a device that scans out only linear buffers another GPU allocated, even where this device renders into no linear layout (NVIDIA's). Close it when done; the device closes the ones still open with it.
type Losses ¶
type Losses struct {
// contains filtered or unexported fields
}
Losses is the record of a consumer's recent device losses, deciding whether the next one is recovered from. The zero value has none.
type Mask ¶
Mask limits a draw to the pixels inside Keep and outside Cut, each edge anti-aliased by its signed distance at the pixel centre, Keep's softened by Falloff. A non-empty Merge melts a second rectangle with Keep's radius into Keep as Goo does, over Smooth pixels. An empty Keep keeps everything; an empty Cut cuts nothing.
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 Pass ¶
type Pass struct {
// contains filtered or unexported fields
}
Pass draws a compositor's frame into a Target, every call clipped to the damage it began with. The first bad call fails the pass: End reports it and draws nothing. The device reuses it for its next Begin, so a frame costs no allocation: nothing holds one past that Begin.
func (*Pass) ClearCut ¶
func (p *Pass) ClearCut()
ClearCut draws the pass's later calls uncut, as it began.
func (*Pass) DrawFragmentShader ¶
func (p *Pass) DrawFragmentShader(s *FragmentShader, t *Texture, dst image.Rectangle, constants [4]float32)
DrawFragmentShader writes all of t through s into dst's damaged part, sampling t linearly, with no blending and the target's alpha kept.
func (*Pass) DrawFrame ¶
func (p *Pass) DrawFrame(f *VideoFrame, src FRect, dst image.Rectangle, tr Transform, alpha float32, m Mask)
DrawFrame blends src of f's picture, a frame the caller holds, scaled to dst and turned by tr, at alpha over dst's damaged part within m, its colours converted by the stream's YCbCr matrix, range and chroma siting: DrawTexture for a decoded frame. src is in the picture's pixels, within its Size. A picture still decoding is waited for on the GPU: the pass's submission runs after the decode, and nothing waits here.
func (*Pass) DrawGlass ¶
func (p *Pass) DrawGlass(t *Texture, src FRect, dst image.Rectangle, alpha float32, m Mask, g Glass)
DrawGlass blends src of t, scaled to dst and bent and adjusted by g, at alpha over dst's damaged part within m, always sampling linearly, so that a bent pixel lands between texels. The bezel runs along m's Keep, or along dst without one, and the adjusted colour goes through what SetColor set. The pipeline is built at the first draw.
func (*Pass) DrawTexture ¶
func (p *Pass) DrawTexture(t *Texture, src FRect, dst image.Rectangle, tr Transform, alpha float32, m Mask)
DrawTexture blends src of t, scaled to dst and turned by tr, at alpha over dst's damaged part within m. tr is the buffer transform of the texture's content: under Transform90, dst's x runs along src's y and dst's y against src's x. A draw that maps whole source pixels one to one samples them as they are; any other samples bilinearly.
func (*Pass) End ¶
End records what the pass drew, to draw into its target and hand the target back to its consumer, and returns without waiting for the GPU. The passes of a frame reach the queue together, in one submission with one fence: when SyncFile exports, a CPU read or Finish needs them, FrameDone asks about them, or Flush is called, so a consumer that waits on no SyncFile calls Flush before taking the target. SyncFile signals when it is done, and FrameDone says when. A pass whose call failed records nothing and reports the first error.
func (*Pass) FillGoo ¶
FillGoo blends c, premultiplied, over the blob g covers within r's damaged part.
func (*Pass) FillGradient ¶
FillGradient blends g over r's damaged part within m.
func (*Pass) Incomplete ¶
Incomplete reports a draw skipped because its pipeline is still being built (Prepare): the caller keeps this pass's damage for its next frame.
func (*Pass) Kawase ¶
Kawase draws all of t scaled to dst through one pass of a dual Kawase blur, sampling t linearly at offset source half-pixels from each pixel: four diagonal taps around a centre weighted four (down, for a target smaller than t) or eight taps around it (up, for a larger one). KawaseAt mirrors it in Go. It replaces dst's pixels rather than blending over them, so a level covering its whole target needs no Clear and never reads what the target held.
func (*Pass) SetColor ¶
func (p *Pass) SetColor(t *ColorTransform)
SetColor sends every later draw of the pass through t before it blends: a fill's colour, a gradient's stops and a texture's samples of any format after YCbCr conversion, while coverage and alpha stay outside it. Nil, what a pass starts with, draws without a transform. Kawase never takes one: it averages a target already in the pass's encoding.
type Readback ¶
type Readback struct {
// contains filtered or unexported fields
}
Readback is host-visible memory a target is copied into for the CPU to read, without stalling whoever draws: Copy only queues the copy, and Wait, on any goroutine, blocks until it is done. It needs neither a dmabuf nor a sync_file, so it works on every device. Close it when done; the device closes the ones still open with it.
func (*Readback) Close ¶
func (r *Readback) Close()
Close releases the readback; closing it again, or after its device, does nothing.
func (*Readback) Copy ¶
Copy queues copying src, a target of the readback's size that has been drawn, over what the readback held. A copy still running refuses it.
type RoundRect ¶
RoundRect is a rectangle in target pixels whose corners are rounded by Radius, clamped to half its shorter side.
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.
type Texture ¶
type Texture struct {
// contains filtered or unexported fields
}
Texture is an image a Pass samples, kept across frames: one the device allocates and the CPU uploads into (NewTexture), or a dmabuf imported from its producer (ImportTexture). Close it when done; the device closes the ones still open with it.
func (*Texture) Close ¶
func (t *Texture) Close()
Close releases the texture; closing it again, after its device, or closing a target's texture, which its target owns, does nothing.
type Transform ¶
type Transform int
Transform is a wl_output transform: how an output's pixels are turned in its buffer.
type VideoDecoder ¶
type VideoDecoder struct {
// contains filtered or unexported fields
}
VideoDecoder decodes a video track on the device's video decode queue into frames the renderer samples: Decode takes the track's packets in decode order, Next hands out frames in presentation order. A VideoDecoder belongs to its device's goroutine.
func (*VideoDecoder) Busy ¶
func (v *VideoDecoder) Busy() (bool, error)
Busy reports, without waiting, whether the GPU is decodeSlots pictures or more behind the packets decoded. Decode takes a packet either way, and waits for the GPU only with decodeSlotLimit pictures in flight: a caller that holds its next packet back while Busy, as a player does until its loop's next turn, never has Decode wait.
func (*VideoDecoder) Close ¶
func (v *VideoDecoder) Close()
Close releases the decoder and its frames, the ones the caller still holds too: Next has none after. Closing it again does nothing.
func (*VideoDecoder) Decode ¶
func (v *VideoDecoder) Decode(p demux.Packet) error
Decode decodes p, the track's next packet in decode order; the frames it completes come out of Next. A stream in a format that is not decoded is ErrNoVideoDecoder, saying which; any other error is a malformed stream or a failing device. It submits the packet's pictures and waits for the GPU only when that is far behind (Busy). A picture that predicts from pictures before the one decoding started at (after Reset, at a keyframe that is not an IDR) is dropped. A packet that fails, partway through its pictures or at its only one (every frame held, say), may be given again once that is put right: it decodes as though it had not failed.
func (*VideoDecoder) Flush ¶
func (v *VideoDecoder) Flush()
Flush hands every frame held back for presentation order to Next: what the end of the track does.
func (*VideoDecoder) Next ¶
func (v *VideoDecoder) Next() *VideoFrame
Next is the next frame in presentation order, nil when the packets decoded so far complete none: Decode more, or Flush at the end. It waits for nothing: the frame's picture may still be decoding, and the pass that draws it waits for that on the GPU (DrawFrame). The frame is the caller's until Release.
func (*VideoDecoder) Reset ¶
func (v *VideoDecoder) Reset() error
Reset drops every frame not yet handed out and every reference picture, for decoding to start again at a keyframe: what a seek does. Frames the caller holds stay valid until released.
type VideoFrame ¶
type VideoFrame struct {
// contains filtered or unexported fields
}
VideoFrame is a decoded picture a Pass draws (DrawFrame) through the stream's YCbCr conversion. Its texture is the decoder's, which decodes into it again after Release, and never the caller's to update or close: tex is larger than the picture by the codec's padding, with the picture in rect.
func (*VideoFrame) Decoded ¶
func (f *VideoFrame) Decoded() (bool, error)
Decoded reports whether the frame's picture has finished decoding, and the film grain pass of the graphics queue where the decoder synthesizes the grain, without waiting for either. A pass may draw the frame before it has: the pass waits for the decode on the GPU. What then waits here for that pass (Finish, a CPU read, Publish on a device whose dmabufs carry no fence) waits for the decode with it, so a caller that must not stall there draws the frame once Decoded says so.
func (*VideoFrame) Duration ¶
func (f *VideoFrame) Duration() time.Duration
Duration is how long the frame presents, its packet's; zero when the container does not say.
func (*VideoFrame) FieldOrder ¶
func (f *VideoFrame) FieldOrder() FieldOrder
FieldOrder is whether the frame is two fields woven, and which is the earlier: an H.264 frame coded as fields or as field and frame macroblock pairs, by its fields' picture order counts. The decoder deinterlaces nothing: the picture has the fields' lines as the stream codes them.
func (*VideoFrame) PTS ¶
func (f *VideoFrame) PTS() time.Duration
PTS is when the frame presents, its packet's PTS.
func (*VideoFrame) Release ¶
func (f *VideoFrame) Release()
Release hands the frame back for the decoder to decode into once the passes that drew it, the open one too, finish. The frame is not to be used after.
func (*VideoFrame) Size ¶
func (f *VideoFrame) Size() image.Point
Size is the picture's size in pixels, the stream's cropping applied.
type YCbCr ¶
type YCbCr struct {
Matrix YCbCrMatrix
Range YCbCrRange
Chroma ChromaSiting
}
YCbCr is how a YUV buffer's samples become RGB: the colour hints a client gives with it (wp_color_representation, or a video's own). The zero value is BT.601 in limited range, chroma sited as MPEG-2 and H.264 site 4:2:0 chroma.
type YCbCrMatrix ¶
type YCbCrMatrix uint8
YCbCrMatrix is the matrix coefficients a YUV buffer was encoded with.
const ( BT601 YCbCrMatrix = iota BT709 BT2020 )
The matrices.
type YCbCrRange ¶
type YCbCrRange uint8
YCbCrRange is the range a YUV buffer's samples span.
const ( LimitedRange YCbCrRange = iota FullRange )
The ranges: limited (16 to 235 for 8-bit luma) and full.
Source Files
¶
- atlas.go
- buffer.go
- clocks.go
- color.go
- colorpass.go
- commands.go
- compositor.go
- conv.go
- cut.go
- decode.go
- decode_av1.go
- decode_grain.go
- decode_h264.go
- decode_h264dpb.go
- decode_h265.go
- decode_h265dpb.go
- decode_refslots.go
- decode_vp9.go
- device.go
- encode.go
- encode_h264.go
- encode_h265.go
- encode_va.go
- encode_vulkan.go
- export.go
- format.go
- fragment.go
- frame.go
- framebuffers.go
- glass.go
- icd.go
- images.go
- import.go
- linear.go
- losses.go
- mask.go
- occlude.go
- pass.go
- pipeline.go
- prepare.go
- preparetarget.go
- prim.go
- publish.go
- readback.go
- result.go
- retire.go
- scratch.go
- shaders.go
- stagingring.go
- stills.go
- surface.go
- sync.go
- target.go
- texture.go
- video.go
- ycbcr.go
- ycbcr444.go
- ycbcrplanes.go