metal

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 17 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

Rendered for darwin/amd64

Overview

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). Every op of a scene is an instanced quad drawn by one shader (shader.metal, compiled ahead of time into shaderlib.go), from the instances package gpu builds; clips are scissor rectangles, with the innermost rounded clip computed in the shader, as in package d3d11.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompileLibrary

func CompileLibrary(src string) ([]byte, error)

CompileLibrary compiles Metal Shading Language into a Metal library with Xcode's metal tools, for code compiled ahead of time: go generate runs it, for the renderer's shader (shaderlib.go) and effects' (EffectSource).

func EffectSource

func EffectSource(src string) string

EffectSource returns the source of an effect's library: shader.metal with EFFECT defined, the head of effect.metal, the effect's shader (see scene.Effect), and the tail, which draws its instances with it (effect_ps). Effects compile it ahead of time with CompileLibrary.

func PrecompileShader

func PrecompileShader(src string)

PrecompileShader starts making what a shader of package ui/shader draws with, whose library's source is src (ShaderSource), on a goroutine of its own, with the system's default GPU: its library, which Metal compiles from the source in about 0.1 s, and its pipeline for windows of 8-bit color, about as long again. Renderers on that GPU then draw with them, waiting for what is left, rather than make them on the shader's first draw. Metal keeps both on disk for the next launches. Package ui/shader calls it as it compiles a shader.

func RenderOffscreen

func RenderOffscreen(s *scene.Scene) ([]byte, error)

RenderOffscreen draws s with a renderer of its own into a texture, without a layer, and returns its premultiplied BGRA rows: for tests, as packages drawing effects have.

func ShaderSource

func ShaderSource(src string) string

ShaderSource returns the source of the library of a shader of package ui/shader, whose code src ends with shaderMain: as an effect's, with a tail of its own (shader_ps), which reads the shader's uniforms and images. The shader's effect holds it whole (scene.Effect's Metal), so that apps drawing no shader do not carry the tail.

Types

type Offscreen

type Offscreen struct {
	// contains filtered or unexported fields
}

Offscreen draws frames with a renderer of its own into a texture, without a layer, waiting for each and timing it on the GPU: for benchmarks, as those of package ui drawing its frames.

func NewOffscreen

func NewOffscreen(w, h int) (*Offscreen, error)

NewOffscreen returns an Offscreen drawing frames of w×h pixels.

func (*Offscreen) Encoded

func (o *Offscreen) Encoded() time.Duration

Encoded returns how long the CPU took to encode the last frame Render drew: building its instances (gpu.Builder), uploading what changed in its atlases, and encoding its passes, before committing them.

func (*Offscreen) Release

func (o *Offscreen) Release()

Release frees the texture and the renderer.

func (*Offscreen) Render

func (o *Offscreen) Render(s *scene.Scene) (gpu time.Duration, err error)

Render draws s, a texture of its size taking the place of one of another, waits for the GPU to finish it, and returns the time the GPU spent on it, by its command buffer's timestamps.

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer draws scenes into a CAMetalLayer it adds to a view's layer.

func New

func New(layer uintptr) (r *Renderer, err error)

New creates a renderer drawing into a CAMetalLayer that it adds to layer, the layer of a view, and sizes as it.

func (*Renderer) FrameInfo

func (r *Renderer) FrameInfo() string

FrameInfo describes the last frame for GOLET_FRAME_STATS.

func (*Renderer) Ready

func (r *Renderer) Ready(wake func()) bool

Ready reports whether a frame following the last one can draw at once, as none waits for its drawable (present.go); otherwise wake runs, on the main thread, once it has.

func (*Renderer) Release

func (r *Renderer) Release()

Release frees the renderer's GPU objects and takes its layer out.

func (*Renderer) Render

func (r *Renderer) Render(s *scene.Scene) (err error)

Render draws s into the layer and presents it.

func (*Renderer) SetPost

func (r *Renderer) SetPost(post func(func()))

SetPost gives the renderer post, which runs a function on the main thread from any goroutine: a frame following another builds while its drawable is being fetched, and draws once the presenter has it, through post. Without it, frames wait for their drawable.

func (*Renderer) SetWide

func (r *Renderer) SetWide(on bool) bool

SetWide has the frames drawn from now on show the colors of scenes outside the sRGB gamut (scene.Scene.Wide), into drawables of RGBA16Float in the extended sRGB color space, which keeps components beyond 0 to 1 and which the system shows in the display's gamut, or their nearest sRGB colors, into drawables of BGRA8, as without; and reports whether they do. The pipelines drawing the wide colors are made the first time.

Jump to

Keyboard shortcuts

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