gpu

package
v0.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gpu turns scenes into what the GPU renderers draw: one instanced quad per operation, for a shader that computes rounded rectangles, borders, gradients, stripes, shadows and atlas coverage itself, in batches that share a scissor rectangle and an image. Every renderer (d3d11, metal, gl) draws the same instances, the way internal/raster draws scenes on the CPU.

An effect (scene.Effect) draws with a pipeline of its own, made from its shader, in a batch of its own. One reading its backdrop has its batch start after a Backdrop step, which renderers take between batches: they read the backdrop's area of what they drew so far, average it over squares (the pass "down") into a texture, blur that along rows into another and along columns back (the pass "blur"), keeping 8 bits a channel, and bind it for the batch (the shaders' backdrop texture), as internal/raster computes it.

The shaders write a second color for blending, the source's alpha for each channel: the alpha of the color for everything but subpixel glyphs, whose subpixels cover each channel by its own. Renderers blend with dual-source blending: the destination times one minus the second color, plus the first.

Index

Constants

View Source
const InstanceSize = int(unsafe.Sizeof(Instance{}))

InstanceSize is the size of an Instance in bytes.

Variables

This section is empty.

Functions

func GoBytes added in v0.2.10

func GoBytes(name string, b []byte) string

GoBytes returns the Go declaration of a variable name holding b, as code compiled ahead of time is generated.

func SourceSum

func SourceSum(src string) string

SourceSum returns the SHA-256, in hex, of a shader's source as the repository holds it, with LF line endings, which shaders compiled ahead of time record: the source matches them however it was checked out, as with CRLF endings on Windows.

Types

type Batch

type Batch struct {
	Start, Count int
	Scissor      Scissor
	// Image is the renderer's texture of the batch's image, or 0.
	Image uintptr
	// Effect is the effect of the batch's one instance, drawn with a
	// pipeline of its own, and Backdrop, unless 0, 1 + the index in
	// Builder.Backdrops of its backdrop, which the renderer reads before
	// drawing it.
	Effect   *scene.Effect
	Backdrop int
}

Batch is a run of instances that draw with the same scissor rectangle and image.

type Builder

type Builder struct {
	Instances []Instance
	Batches   []Batch
	Backdrops []scene.Backdrop
	// Wide draws the colors of scenes outside the sRGB gamut
	// (Scene.Wide), for a target that keeps them, as Metal's float16
	// drawables do; without it, their nearest sRGB colors.
	Wide bool
	// contains filtered or unexported fields
}

Builder builds the instances and batches of scenes, reusing its memory from frame to frame.

func (*Builder) BackdropSize added in v0.2.10

func (b *Builder) BackdropSize() (w, h int)

BackdropSize returns how large the textures of the backdrops of the last scene built must be, in texels: as the largest.

func (*Builder) Build

func (b *Builder) Build(s *scene.Scene, image func(*scene.Image) uintptr)

Build turns the operations of s into Instances and Batches. image returns the renderer's texture of an image, uploading it when new or changed, or 0 to leave the image out.

type Instance

type Instance struct {
	// Rect is x, y, width, height; Radii the corners' radii (top-left,
	// top-right, bottom-right, bottom-left), negative for continuous
	// corners (scene.Corners), which only Metal's shader draws, or a
	// glyph's gamma ratios
	// (scene.TextParams); Inner those of a border's inner edge, or of the
	// box casting a shadow, or a glyph's contrast and thin boost in Inner[0]
	// and Inner[1].
	Rect, Radii, Inner [4]float32
	// Color and Color2 (a gradient's end) and Border are straight RGBA.
	Color, Color2, Border [4]float32
	// Grad holds a gradient's start and end points, or the stripes' unit
	// vector across them, width and period; UV the texture rectangle,
	// normalized, a fill's border widths (top, right, bottom, left), or
	// the box casting a shadow, which shows only outside it (none when
	// empty).
	//
	// An effect has its parameters (scene.EffectOp.Params) in Inner,
	// Color, Color2, Border and Grad, and in UV where its backdrop's area
	// starts in the frame and its size in texels.
	Grad, UV [4]float32
	// Clip and ClipRadii are the innermost clip, which the shader cuts.
	Clip, ClipRadii [4]float32
	// Params is the kind (0 fill, 1 shadow, 2 mask glyph, 3 color glyph, 4
	// image, 5 subpixel glyph, 6 effect); 1 for a dashed border or a
	// grayscale image; the shadow's sigma (0 for none), the paint
	// (scene.Paint) or the size of the squares an effect's backdrop
	// averages; and the opacity.
	Params [4]float32
}

Instance is the data of one quad, in device pixels, as the shaders read it: eleven float4s.

type Pass added in v0.2.10

type Pass struct {
	Origin, Limit, Shift, Dir [2]int32
	Down, Radius              int32
	Sigma                     float32
	// contains filtered or unexported fields
}

Pass is what a pass computing a backdrop reads, the layout of the shaders' Pass: down reads the area from Origin to Limit, frame pixels, at their place less Shift in its source, and averages squares of Down pixels a side; blur reads texels up to Limit, Radius of them each way along Dir, weighted by a Gaussian of standard deviation Sigma.

func BlurPass added in v0.2.10

func BlurPass(bk scene.Backdrop, dir [2]int32) Pass

BlurPass returns the pass blurring bk's texels along rows (dir 1, 0) or columns (0, 1).

func DownPass added in v0.2.10

func DownPass(bk scene.Backdrop, shift [2]int32) Pass

DownPass returns the pass averaging the squares of bk's area, whose frame pixel (x, y) is at (x, y) less shift in the texture it reads.

type Scissor

type Scissor struct{ Left, Top, Right, Bottom int32 }

Scissor is a scissor rectangle in device pixels, the layout of a Direct3D RECT.

func (Scissor) Empty

func (s Scissor) Empty() bool

Empty reports whether the rectangle has no pixels.

Directories

Path Synopsis
Package d3d11 draws scenes with Direct3D 11 into a window through a DXGI flip model swap chain, called through syscall like the rest of the Windows backend (no cgo).
Package d3d11 draws scenes with Direct3D 11 into a window through a DXGI flip model swap chain, called through syscall like the rest of the Windows backend (no cgo).
device
Package device creates Direct3D 11 devices: the device of package d3d11's renderer, and that of the Windows backend, which shows the controls of windows with a material through DirectComposition without the renderer.
Package device creates Direct3D 11 devices: the device of package d3d11's renderer, and that of the Windows backend, which shows the controls of windows with a material through DirectComposition without the renderer.
Package gl draws scenes with OpenGL 3.3 or OpenGL ES 3.0 into the framebuffer bound when Render is called: the one GTK's GtkGLArea binds while it emits its render signal.
Package gl draws scenes with OpenGL 3.3 or OpenGL ES 3.0 into the framebuffer bound when Render is called: the one GTK's GtkGLArea binds while it emits its render signal.
Package gputest has what the tests of the GPU renderers share: a scene that draws every kind of operation, and a comparison of what a renderer drew with what the CPU renderer draws, which the renderers must match.
Package gputest has what the tests of the GPU renderers share: a scene that draws every kind of operation, and a comparison of what a renderer drew with what the CPU renderer draws, which the renderers must match.
Package metal draws scenes with Metal into a CAMetalLayer, called through the Objective-C runtime with purego like the rest of the macOS backend (no cgo).
Package metal draws scenes with Metal into a CAMetalLayer, called through the Objective-C runtime with purego like the rest of the macOS backend (no cgo).

Jump to

Keyboard shortcuts

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