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 ¶
- Variables
- func AxisClipScene() *scene.Scene
- func BehindOriginScene() *scene.Scene
- func BorderedCardScene(continuous bool) *scene.Scene
- func BoxesScene(w, h, n int, translated bool) *scene.Scene
- func CanvasScene() *scene.Scene
- func CardsScene(w, h int) *scene.Scene
- func Compare(t testing.TB, name string, got []byte, stride int, s *scene.Scene)
- func CompareStraightEdges(t testing.TB, name string, got []byte, stride int, s *scene.Scene)
- func ContinuousScene() *scene.Scene
- func Continuously(s *scene.Scene) *scene.Scene
- func CornerClipScene() *scene.Scene
- func FillScene(w, h int) *scene.Scene
- func MaskedClipScene() *scene.Scene
- func OpaqueScene(w, h int) *scene.Scene
- func PanelsScene(w, h, n int) *scene.Scene
- func PerspectiveScene() *scene.Scene
- func RowsScene(w, h, n int) *scene.Scene
- func Scene() *scene.Scene
- func ShadowPanelScene(c ShadowCase) *scene.Scene
- func SpriteScene(w, h int, scale float32, layers, sprites int) *scene.Scene
- func Transformed(s *scene.Scene) *scene.Scene
- func TransformedScene() *scene.Scene
- func TranslatedScenes() []*scene.Scene
- func WideScene() *scene.Scene
- func WithoutNewPaints(s *scene.Scene) *scene.Scene
- type Changing
- type CullCase
- type MaskedCase
- type RingCase
- type ShadowCase
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 BehindOriginScene ¶ added in v0.1.17
BehindOriginScene is a card far from its drawing's origin, turned over in perspective around its center, which the frame shows at (160, 370): the origin is behind the viewer, past the turned plane's horizon (scene.Affine.Behind), the card in front (#1406). A rounded clip, its shadow, a border and a gradient turn with it; red shows at the frame's center.
func BorderedCardScene ¶ added in v0.1.13
BorderedCardScene returns the 756×640 frame of #531, a window of 378×320 DIPs at scale 2: an opaque backdrop, and on it a card of an opaque white face with a border of 1 DIP (2 pixels) and corners of 12 DIPs (24 pixels), continuous (as macOS draws them) or not, on whole pixels, large enough for the builder to draw it as an opaque core with pieces around it; and a button with the same border above it, too small for that. Their straight edges cover whole pixels, by 1 or 0, so a renderer draws them exactly as the CPU renderer does (see CompareStraightEdges).
func BoxesScene ¶
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 ¶
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 ¶
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 ¶
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 CompareStraightEdges ¶ added in v0.1.13
CompareStraightEdges compares pixels a renderer drew, as Compare does, and requires more of those away from the corners of the scene's rounded fills, along their straight edges and inside them, where coverage is exactly 1 or 0 for shapes on whole pixels: each channel within 2 levels of the CPU renderer's, at every pixel. It reports the rows (or columns) that differ, so that a stray line along an edge shows where it is.
func ContinuousScene ¶
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 ¶
Continuously returns a copy of s whose ops all have continuous corners (scene.Op.Continuous): fills, shadows, images, holes, effects and clips.
func CornerClipScene ¶ added in v0.1.17
CornerClipScene has clips that reach into the rounded corners of a clip around them, whose corners must cut what they hold (#1418), at the size of the reference scene (Scene): first a card as package ui draws it at scale 2, rounded and clipped, holding a column that clips too and fills the card's bottom; then a card holding a pane with a clip nested in it at its bottom, a rounded clip in its corner, and one in its middle, away from the corners.
func FillScene ¶
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 MaskedClipScene ¶ added in v0.1.17
MaskedClipScene has clips masked by gradients, linear of two colors and of stops, radial and conic, and by an image (a path's coverage), with fills, a shadow and an image inside, a clip within a masked one, rounded or not, a masked clip turned, and one only moved, by whole pixels and between them, which renderers fold; all of them again, scaled, under the reference scene's size (Scene); and part of an image over a rounded clip.
func OpaqueScene ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
TransformedScene exercises all primitives and effects under affine composition, with nested transformed clips and an inline glyph transform.
func TranslatedScenes ¶
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 ¶
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 ¶
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 ¶
NewChanging returns a maker of scenes from seed.
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 ¶
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.