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
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.
| Module | Version | Used for |
|---|---|---|
quic-go/quic-go | 0.65.0 | Control connection and pairing |
klauspost/reedsolomon | 1.14.2 | Forward error correction |
thesyncim/gopus | 0.2.4 | Opus audio, pure Go |
ebitengine/oto/v3 | 3.5.1 | Audio playback |
ebitengine/purego | 0.11.3 | cgo-free calls into macOS frameworks |
egoist/mygo | 0.10.0 | Desktop 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.
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:
SendInputwith 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
CAMetalLayerthrough 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:
| Path | Go allocs | Unit |
|---|---|---|
| NVENC encode | 0 | per frame |
| AES-GCM seal and UDP send | 0 | per datagram |
| Present, timing callbacks off | 0 | per frame |
| AMF encode | 4 | per frame |
| DXGI capture (Phase 0 spike) | 6 | per frame |
| Reed-Solomon, inside the library | ≈2 | per 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).