Docs / Architecture

Architecture

Five stages from capture to glass, four GPU vendors, two platforms, one language, and nothing crossing the CPU.

DXGI · SCK · NVENC · AMF · oneVPL · VT · MyGo gpusurface

On this page
  1. Pure Go, no cgo
  2. The pipeline
  3. Per platform
  4. Host and client
  5. Zero copy, few allocations
  6. Multi-GPU
  7. Known gaps

Pure Go, no cgo

Planck is written in Go and built with CGO_ENABLED=0: no Rust, no C compiler, and no Swift or Objective-C shim. On Windows, COM, DXGI, D3D11 and Media Foundation are called throughsyscall vtables. On macOS, ScreenCaptureKit, VideoToolbox and CoreGraphics are called through purego, which loads system frameworks without cgo.

ModuleVersionUsed for
quic-go/quic-go0.65.0Control connection and pairing
klauspost/reedsolomon1.14.2Forward error correction
thesyncim/gopus0.2.4Opus audio, pure Go
ebitengine/oto/v33.5.1Audio playback
ebitengine/purego0.11.3cgo-free calls into macOS frameworks
egoist/mygo0.10.0Desktop UI, vendored in third_party/mygo

MyGo is vendored with a replace directive, so Planck can extend it in place. The extension that matters is third_party/mygo/gpusurface: a surface that takes a decoded GPU texture and presents it under the MyGo window, through DirectComposition on Windows and a CAMetalLayer on macOS.

The pipeline

A frame moves through five stages. The host captures, encodes, seals and shards it; the client decodes and presents it. QUIC carries control and derives the keys; the media itself rides raw UDP.

HOST · planck-hostTRANSPORTCLIENT · planck-client01 · CAPTUREDXGI Desktop DuplicationWindows · display adapterScreenCaptureKitmacOS02 · ENCODENVENCH.264 · HEVC · AV1AMFHEVConeVPLHEVCVideoToolboxHEVC03 · SEAL + SHARDAES-128-GCM25 B overheadReed-Solomon FECadaptive parity04 · DECODEMedia FoundationD3D11 · HEVC/AV1VideoToolboxHEVC/AV105 · PRESENTMyGo gpusurface · DCompWindowsMyGo gpusurface · CAMetalLayermacOSZERO COPY · GPU TEXTUREZERO COPY · GPU TEXTUREZERO COPY · GPU TEXTUREQUICcontrolALPN planck-v1TLS 1.3AEAD UDPmediaAES-128-GCM1152 B defaultRS FECadaptive128 shards/blk≤32 blocksEXPORTER-planck-media-v1SIDE CHANNELS · AEAD UDP UNLESS NOTEDOpus audio48 kHz · 10 msInputscan code · 0x13GamepadViGEmBus virtualClipboardown QUIC streamTailscaleLocalAPI · metadata
Every stage is pure Go, built with CGO_ENABLED=0. Windows COM, DXGI and Media Foundation go through syscall vtables; ScreenCaptureKit, VideoToolbox and CoreGraphics go throughpurego. Surfaces stay GPU-resident from capture to encode and from decode to present: nothing crosses the CPU.

Packages pkg/capture/dxgi, pkg/capture/sck,pkg/encode/{nvenc,amf,vpl,vt}, pkg/transport, pkg/fec,pkg/wire, pkg/decode/{d3d11,vt}, pkg/pyrowave, pkg/player,third_party/mygo/gpusurface, pkg/tailscale, pkg/audio,pkg/input, pkg/gamepad, pkg/clipboard · Depsquic-go (control), klauspost/reedsolomon (FEC), thesyncim/gopus(Opus), ebitengine/oto (playback), ebitengine/purego, vendoredegoist/mygo · Linux build and headless only: no capture, no encode, no window ·Not shipped multi-GPU offload (D3D11 cross-adapter shared handles fail withE_INVALIDARG; staging costs 2–15 ms per frame) · H.264 encodes on NVENC but has no decoder on either platform · Commit v0.1.0 (8a3c732).

Per platform

Windows host

  • Capture: DXGI Desktop Duplication on the adapter that drives the display (pkg/capture/dxgi), with the cursor captured separately.
  • Encode: NVENC, AMF (HEVC only) or oneVPL (HEVC only). Planck hands NVENC a D3D11 texture; NVENC converts BGRA and RGB10 to YUV itself.
  • Virtual display: SudoVDA, a separate optional driver. When it is installed, Planck can create a monitor at the client's size on the encoding GPU.
  • GPU power: an NVIDIA driver profile that prefers maximum performance (pkg/gpu), and D3D11 GPU thread priority.
  • Audio: WASAPI loopback. Input: SendInput with US-layout scan codes. Gamepads: virtual pads through the ViGEmBus device interface.

Windows client

  • Decode: the Media Foundation HEVC and AV1 transforms through D3D11 (pkg/decode/d3d11).
  • Present: a DXGI swap chain in DirectComposition, under the MyGo window's surface.

macOS host

  • Capture: ScreenCaptureKit for video and system audio (pkg/capture/sck, pkg/audio).
  • Encode: VideoToolbox HEVC, from NV12 or P010. VideoToolbox has no HEVC 4:4:4 encoder on Apple silicon, so 4:4:4 is refused.
  • Input: CGEvent injection, which needs Accessibility permission.

macOS client

  • Decode: VideoToolbox HEVC and AV1, decoded synchronously.
  • Present: a CAMetalLayer through gpusurface. A full-screen direct-to-display path exists behind -direct-display.

Linux

Linux builds and runs headless only. There is no capture backend, no encoder and no desktop window, so a Linux machine can neither host nor show a stream yet.

Host and client

planck-host and planck-client share one session package (internal/session). The host side owns pairing and negotiation; the client side owns the decode loop and presentation. Both Hellos carry their feature capabilities. The host resolves the stream with its own policy over the client's overrides, then answers with a SessionReadythat names the media port and the resolved profile.

Zero copy, few allocations

Surfaces stay on the GPU. DXGI Desktop Duplication copies into Planck's own texture on the same GPU; NVENC and AMF take D3D11 textures; VideoToolbox takes IOSurface-backed pixel buffers. The hot path avoids Go allocations where it can, and the repo records where it cannot:

PathGo allocsUnit
NVENC encode0per frame
AES-GCM seal and UDP send0per datagram
Present, timing callbacks off0per frame
AMF encode4per frame
DXGI capture (Phase 0 spike)6per frame
Reed-Solomon, inside the library≈2per encoded slice

With a 1080p240 stream and 4,000 input events, the host ran 20 s with no garbage collection after setup (bigboi, docs/perf/phase1-latency-audit.md).

Multi-GPU

Rendering on one GPU and encoding on another loses on the test host. D3D11 cross-adapter shared handles fail with E_INVALIDARG, and a staging copy costs 2 to 15 ms per frame: same-GPU AMF measured 3.6 ms p50 against 9.4 ms p50 for AMD to NVIDIA. Planck encodes on the GPU that owns the surface. To encode on a GPU with no monitor, give it one with a virtual display (-vdd, -vdd-gpu).

Known gaps

  • Direct-to-display presentation on macOS (the P1b work item) is not done; windowed present is the largest single stage.
  • VideoToolbox decodes whole frames, so sub-frame slices only overlap transfer on a Mac client.
  • Multi-GPU offload is not built; D3D12 cross-adapter heaps were not tried.
  • H.264 has no decoder (see the warning above).