gputest

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 10 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 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.

Index

Constants

This section is empty.

Variables

View Source
var (
	LensEffect = &scene.Effect{
		Name:     "lens",
		Backdrop: true,
		Metal: scene.EffectCode{Source: `
float4 effect(float2 p, Effect e, texture2d<float> backdrop) {
	float d = max(8.0f + sdRoundRect(p, e.rect, e.radii), 0.0f) * e.p0.x;
	float3 c = sampleBackdrop(backdrop, e, p + float2(d, 0.0f));
	c += (e.p1.rgb - c) * e.p1.a;
	return float4(c, 1.0f);
}`},
		HLSL: scene.EffectCode{Source: `
float4 effect(float2 p, Effect e) {
	float d = max(8 + sdRoundRect(p, e.rect, e.radii), 0) * e.p0.x;
	float3 c = sampleBackdrop(e, p + float2(d, 0));
	c += (e.p1.rgb - c) * e.p1.a;
	return float4(c, 1);
}`},
		GLSL: `
vec4 effect(vec2 p, Effect e) {
	float d = max(8.0 + sdRoundRect(p, e.rect, e.radii), 0.0) * e.p0.x;
	vec3 c = sampleBackdrop(e, p + vec2(d, 0.0));
	c += (e.p1.rgb - c) * e.p1.a;
	return vec4(c, 1.0);
}`,
		Pixels: func() scene.EffectPixels { return &testPixels{} },
	}
	TintEffect = &scene.Effect{
		Name: "tint",
		Metal: scene.EffectCode{Source: `
float4 effect(float2 p, Effect e, texture2d<float> backdrop) {
	return float4(e.p1.rgb * e.p1.a, e.p1.a);
}`},
		HLSL: scene.EffectCode{Source: `
float4 effect(float2 p, Effect e) {
	return float4(e.p1.rgb * e.p1.a, e.p1.a);
}`},
		GLSL: `
vec4 effect(vec2 p, Effect e) {
	return vec4(e.p1.rgb * e.p1.a, e.p1.a);
}`,
		Pixels: func() scene.EffectPixels { return &testPixels{} },
	}
)

Effects for the renderers' tests, as plugins define theirs (see scene.Effect). LensEffect shows its backdrop, sampled further right within 8 pixels of its edge, by p0.x pixels a pixel, mixed with the straight color p1 by its alpha; TintEffect paints p1 alone, reading no backdrop.

Functions

func AxisClipScene

func AxisClipScene() *scene.Scene

AxisClipScene is content under a hard clip that a pose scales and moves (a scroll view in a panel that is entering): the clip edges fall in the middle of pixels (the CPU renderer samples a pixel on a 4x4 grid, so its coverage is exact there).

func BoxesScene

func BoxesScene(w, h, n int, translated bool) *scene.Scene

BoxesScene returns a w×h frame of n rounded boxes of 24 pixels, each casting a shadow, in rows of 30, as an animation of boxes moving draws them: under translations (Element.Translate) when translated, else at the same places without transforms. The places fall between pixels.

func CanvasScene

func CanvasScene() *scene.Scene

CanvasScene returns a 120×80 scene showing canvases (scene.NewCanvas): a 16×12 one drawn with fills, a rounded one, an image and a canvas of its own, shown 4 times as large pixelated, then smooth and flipped; and a canvas shown only within another, with nothing new to draw the second time the renderer draws the scene; and a canvas drawing a conic gradient, shown blurred, as a view blurred is (ui.Element.Blur).

func CardsScene

func CardsScene(w, h int) *scene.Scene

CardsScene returns a w×h scene of cards with continuous corners (as macOS draws them) at the sizes of panels, which the builder draws as nine-patches: each casting a soft shadow and a tight one, at places between pixels, with radii from 4 to 60 and uneven ones; a card with a border, a dashed border, a gradient, a translucent color, a border only, a large image, an inner shadow, a hard shadow, a shadow offset beyond its blur, one under a rounded clip and one under a continuous clip.

func Compare

func Compare(t testing.TB, name string, got []byte, stride int, s *scene.Scene)

Compare compares pixels a renderer drew, premultiplied BGRA rows of stride bytes, with what the CPU renderer draws of s. Antialiased edges and interpolated images may differ a little; anything else fails t. With GOLET_GPU_PNG naming a directory, it saves both images there.

func ContinuousScene

func ContinuousScene() *scene.Scene

ContinuousScene returns a 320×70 scene with continuous corners, which only the renderers of macOS draw (scene.Op.Continuous): a card with a border, its shadow and an inner one, a pill, a circle, which stays one, sides too short for their corners' curves, one with an inner shadow without blur, a corner reaching past the middle of its sides, a clip and an image, a shadow without blur, cut by the box casting it, and an effect reading its backdrop.

func Continuously

func Continuously(s *scene.Scene) *scene.Scene

Continuously returns a copy of s whose ops all have continuous corners (scene.Op.Continuous): fills, shadows, images, holes, effects and clips.

func FillScene

func FillScene(w, h int) *scene.Scene

FillScene returns a w×h scene of plain fills, the kind most of a window is made of: layers as large as the frame, panels with square and round corners at fractional places, rows in a clip that holds some whole and cuts others, fills of every opacity, a gradient, a border and a transformed fill among them, over the clear color. Sizes at or above 2048 pixels take the interpolated coordinates across binades of float32.

func OpaqueScene

func OpaqueScene(w, h int) *scene.Scene

OpaqueScene returns a w×h scene (at least 600×500) of opaque fills large enough for the builder to draw as cores without blending, over content that shows if one is wrong: translucent shadows, glyphs and half transparent fills under them, and fills with square, round and continuous corners, a translucent border, fractional places, edges at the frame's, rectangular clips with whole and fractional edges, and some that are not cores (half opacity, a gradient, a rounded clip, a transformed fill).

func PanelsScene

func PanelsScene(w, h, n int) *scene.Scene

PanelsScene returns a w×h frame of n cards in rows of 8, as a page of an app draws them: each a shadowed white card, its content in a rounded clip, an icon (one of four images), a label of glyphs and a colored badge. Clips and images change from card to card, so the frame takes several batches a card, as pages of real windows do.

func PerspectiveScene

func PerspectiveScene() *scene.Scene

PerspectiveScene exercises all primitives and effects seen in perspective: the scene turned 20 degrees about its vertical center line, seen from 900 pixels, as RotationY and Perspective make it, with a skewed glyph and a nested clip turned the other way.

func RowsScene

func RowsScene(w, h, n int) *scene.Scene

RowsScene returns a w×h frame of a list of n rows, as a window of a list draws them: each a rounded background, a label of glyphs, a rounded badge and a second label, so that plain fills and glyphs alternate.

func Scene

func Scene() *scene.Scene

Scene returns a 320×600 scene with fills, borders of every width and dashed, gradients mixed in sRGB and Oklab, stripes, shadows, blurred or not, and cut by the boxes casting them, inner shadows, a hole, nested rounded clips, glyphs from both atlases and subpixel ones, plain and in gradients, with Direct2D's gamma and contrast, images, in color and in gray, and effects, reading their backdrop blurred at each size or not, over each other, clipped and at the frame's edge, or reading none.

func ShadowPanelScene

func ShadowPanelScene(c ShadowCase) *scene.Scene

ShadowPanelScene returns a 480×360 scene with a panel of 340×220 that casts the shadows of c, each shown only outside the panel (Cast), as kit surfaces draw them, and a fill over the panel.

func SpriteScene

func SpriteScene(w, h int, scale float32, layers, sprites int) *scene.Scene

SpriteScene returns a w×h frame of a 2D game: layers of tiles of 16 pixels drawn scale times as large, pixelated, from one sheet, covering the frame, and sprites of 16×32 over them, all ops of one image. With scale 3 at 1920×1080, three layers and 300 sprites, it draws 1,872 sprites, about what a top-down farming game draws.

func Transformed

func Transformed(s *scene.Scene) *scene.Scene

Transformed returns a copy of s with a one pixel transformed fill drawn first, which makes the builder give rounded and rotated clips masks (a scene with any transformed op has them), so that every case also runs with masked clips.

func TransformedScene

func TransformedScene() *scene.Scene

TransformedScene exercises all primitives and effects under affine composition, with nested transformed clips and an inline glyph transform.

func TranslatedScenes

func TranslatedScenes() []*scene.Scene

TranslatedScenes are the reference scene moved by translations, by whole pixels and between them (not by halves: the centers of pixels would fall on the seam of a conic gradient, which renderers round apart), which renderers fold into the geometry of its fills, shadows, images and (by whole pixels) glyphs, its clips and effects keeping theirs (scene.TranslationFolder).

func WideScene

func WideScene() *scene.Scene

WideScene returns a 600×500 scene with colors outside the sRGB gamut (Scene.Wide, Op.Wide, Glyph.Wide) in large opaque fills, a ring, a gradient glyph run inside a continuous rounded clip, and plain fills, which the float16 targets of Metal keep and the others draw as their nearest sRGB colors.

func WithoutNewPaints

func WithoutNewPaints(s *scene.Scene) *scene.Scene

WithoutNewPaints returns s without what shaders older than gradients of stops draw differently: ops painting with stops (scene.Stop), borders painted with a gradient (Op.BorderPaint) and images blurred, for tests that compare a renderer with an earlier copy of its shader.

Types

type Changing

type Changing struct {

	// Clear is the color scenes start with.
	Clear scene.Color
	// contains filtered or unexported fields
}

Changing makes random scenes and changes them a little at a time, as the frames of an app do, for the tests of renderers drawing only what changed: fills (with continuous corners too), shadows, glyphs, images, gradients, effects reading their backdrops, clips (one nested in another, transformed, now and then), transforms, and colors outside the sRGB gamut.

func NewChanging

func NewChanging(seed uint64) *Changing

NewChanging returns a maker of scenes from seed.

func (*Changing) Change

func (m *Changing) Change(s *scene.Scene) string

Change changes s a little, as a frame of an app would, and says how.

func (*Changing) Scene

func (m *Changing) Scene() *scene.Scene

Scene returns a scene of 320×240 pixels.

type CullCase

type CullCase struct {
	Name  string
	Scene *scene.Scene
	// Culled is how many ops the shared builder leaves out.
	Culled int
}

CullCase is a scene of ops, some of them under later opaque fills, and how many of them a renderer may leave out, which must change no pixel. The identity tests use it as a named scene.

func CullCases

func CullCases() []CullCase

CullCases are scenes of overlapping fills and what they hide: text, images, shadows and fills under opaque panels, with square, round and continuous corners; panels that do not hide what is under them (translucent, transformed, at half opacity, gradients, clipped to less, rounded clips, an effect reading what is under them); layers as large as the frame; and an occluder in the clear color.

type MaskedCase

type MaskedCase struct {
	Name  string
	Scene *scene.Scene
}

MaskedCase is a named scene whose clips are masked.

func MaskedCases

func MaskedCases() []MaskedCase

MaskedCases are scenes with rounded, continuous and rotated clips (which are masks in a scene with a transformed op) holding what the builder draws in pieces or as cores: a border-only ring, a shadow cast by a box, large opaque fills, plain fills, glyphs and holes, with content after them in the same clip that reaches the clip's corners.

type RingCase

type RingCase struct {
	Name  string
	Scene *scene.Scene
	// Split is whether the builder draws the first ring around its core.
	Split bool
}

RingCase is a scene of border-only fills (a transparent solid color and a border), over content that shows when one of them wrongly changes a pixel.

func RingCases

func RingCases() []RingCase

RingCases are border-only fills at the size of panels (the shaders shade their cores for nothing unless the builder draws around them): square, round and continuous corners, uneven widths and radii, a dashed border, fractional places, borders under clips, translucent and opaque border colors, at half opacity, one with a border wider than half the panel, and fills that are not split: a gradient, a translucent color, a transformed fill, a small one and a thin one.

type ShadowCase

type ShadowCase struct {
	Radius     float32
	Continuous bool
	// Blur, Spread and DY describe each layer.
	Blur, Spread, DY []float32
}

ShadowCase is a panel with a stack of shadows cast by it, as an elevated surface has: its corner radius, the blur, spread and offset of each layer.

func ShadowCases

func ShadowCases() []ShadowCase

ShadowCases are panels of several radii, blurs, spreads and offsets, among them an offset larger than the blur and a shadow that does not reach out of the panel.

Jump to

Keyboard shortcuts

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