Skip to content

Renderers & fallbacks

ghostty-webgpu ships four renderers against one libghostty-vt state: WebGPU, WebGL2, Canvas 2D, and DOM. You rarely need to pick one manually. By default, the library starts fast on Canvas 2D and hands off to the fastest available GPU backend for the user’s platform.

You will learn

  • How Canvas-first startup eliminates blank startup frames while GPU pipelines compile
  • Why automatic GPU backend order differs between macOS/Windows and desktop Linux
  • When to override rendererMode, presentation, or rendererFactory

  • How WebGPU device loss and WebGL2 context loss recover without losing terminal contents

Automatic selection and Canvas-first startup

Section titled “Automatic selection and Canvas-first startup”
renderers.ts
import { Terminal } from 'ghostty-webgpu'
export async function mountRenderer(host: HTMLElement) {
const terminal = await Terminal.create({ rendererMode: 'auto' })
await terminal.open(host)
terminal.writeln(`Renderer: ${terminal.diagnostics.rendererBackend}`)
return () => terminal.dispose()
}

In the default presentation: 'frame' mode on the main entry, startup happens in three steps:

  1. open() fits the container synchronously and mounts CanvasTerminalRenderer (canvas2d-pixels) so frame one paints immediately without waiting for GPU adapter negotiation or shader compilation.
  2. Once that first Canvas frame reaches the compositor, StartupTerminalRenderer initializes the target GPU backend on a separate offscreen <canvas>.
  3. When the GPU renderer draws its first matching frame (and no pointer drag, link click, or DEC mode 2026 synchronized-output hold is active), the host swaps the painted GPU canvas into the DOM via adoptCanvas and disposes the temporary Canvas renderer.

Read terminal.diagnostics.rendererBackend ('canvas2d', 'webgl2', 'webgpu', or 'dom') to inspect which backend is active. Right after open() resolves in 'frame' mode, it reports 'canvas2d' until the background GPU handoff completes.

Automatic selection follows measured whole-browser CPU and compositor behavior (defined in src/render/shared/backend-order.ts):

  • macOS, Windows, and mobile: tries hardware WebGPU first, then WebGL2.
  • Desktop Linux, or presentation: 'immediate': tries WebGL2 first, then hardware WebGPU. Desktop Linux prefers WebGL2 because Chromium on Linux presented separate WebGPU canvases with higher CPU cost in benchmarks. presentation: 'immediate' prefers WebGL2 because only WebGL2 and Canvas 2D support desynchronized contexts.
  • Fallback chain: If neither GPU backend succeeds, the terminal stays on Canvas 2D. If Canvas 2D is unavailable, it falls back to DomTerminalRenderer.

Pass rendererMode to Terminal.create() on the main entry when you need deterministic backend behavior:

rendererModeBehavior
'auto' (default)Canvas-first startup, then platform-ordered hardware GPU, then Canvas 2D, then DOM.
'webgpu'Canvas-first startup, then WebGPU (accepts any adapter, including software). Stays on Canvas if unavailable.
'webgl2'Canvas-first startup, then WebGL2. Stays on Canvas if unavailable.
'canvas2d-pixels'Stays permanently on the WASM-composited pixel Canvas renderer (canvas-compose.wasm).
'canvas2d-fill-text'Stays permanently on the fillText Canvas 2D renderer.

For low-latency single-terminal hosts on the main entry, pass presentation: 'immediate' to skip Canvas-first startup and paint writes directly on a desynchronized context. To construct a specific renderer class yourself (for example DomTerminalRenderer), supply rendererFactory.

The worker entry (ghostty-webgpu/worker) uses its own backend option: 'auto', 'webgpu', or 'webgl' (see Run in a worker).

How device loss and context loss recover

Because all terminal state lives inside libghostty-vt rather than inside GPU textures, losing a GPU context never drops screen contents or scrollback:

  • WebGPU device loss: WebGpuTerminalRenderer listens to device.lost, acquires a fresh device lease, rebuilds atlas textures and pipelines, and repaints from the intact native state.

  • WebGL2 context loss: FallbackTerminalRenderer replaces the dead <canvas> element and advances through the remaining backend order (including hardware WebGPU on Linux when WebGL2 was picked first, then Canvas 2D).

Recap

  • Leave rendererMode: ‘auto’ for Canvas-first startup and automatic platform-ordered GPU handoff.

  • Inspect terminal.diagnostics.rendererBackend to see whether the terminal is on Canvas 2D, WebGL2, WebGPU, or DOM.

  • Use TerminalWorkerPool if your app mounts many simultaneous panes and risks hitting browser WebGL context limits.