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 Buffer
- type Carry
- type ChromaSiting
- type Codec
- type ColorFunc
- type ColorKind
- type ColorTransform
- 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) ExportModifiers(format fourcc.Format) ([]fourcc.Modifier, error)
- func (d *Device) Exports() bool
- func (d *Device) Finish() 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) 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) 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) 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) 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()
- 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 FragmentShader
- type Glass
- type Goo
- type Gradient
- type Linear
- type Mask
- type Packet
- type Pass
- func (p *Pass) Clear(c color.RGBA)
- func (p *Pass) DrawFragmentShader(s *FragmentShader, t *Texture, dst image.Rectangle, constants [4]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)
- type Readback
- type RoundRect
- type Siting
- type Target
- type Texture
- type Transform
- type YCbCr
- type YCbCrMatrix
- type YCbCrRange
Constants ¶
const ColorUniforms = 9
ColorUniforms is how many vec4s ColorGLSL reads through CP.
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 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 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 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 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 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 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) 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) Finish ¶
Finish waits until everything submitted to the device has finished: a CPU read of a target's dmabuf, a test.
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.
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. 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. b's fds stay the caller's: the texture holds the memory itself until Close.
func (*Device) ImportTextureYCbCr ¶
ImportTextureYCbCr is ImportTexture sampling a YUV buffer through c; an RGB buffer ignores c.
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 (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 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) OpaqueRuns ¶
OpaqueRuns counts the runs of draws this device recorded with blending off: opaque fills and opaque textures at full alpha, unmasked.
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) 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) 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 (a Pass's End, 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, 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 ¶
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 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. 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 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 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) 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) 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 submits what the pass recorded, to draw into its target and hand the target back to its consumer, and returns without waiting for the GPU: SyncFile signals when it is done, and FrameDone says when. A pass whose call failed submits 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.
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 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
- 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
- mask.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