gpu

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 8 Imported by: ? 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

Overview

Package gpu names graphics adapters across platforms so that capture and encode backends can agree on which device owns a frame.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	LUID      LUID
	Vendor    Vendor
	DeviceID  uint32
	Name      string
	VRAMBytes uint64
	Software  bool
}

type Device

type Device struct {
	Adapter Adapter
	// Handle is the ID3D11Device* on Windows. It is 0 on macOS, where
	// IOSurfaces move between Metal, VideoToolbox and ScreenCaptureKit on
	// their own, and on Linux, where frames are DMA-BUFs or memory and
	// each encoder opens its own context on the adapter.
	Handle uintptr
}

Device is a GPU device that frames live on, shared by capture, encode, decode and presentation so a frame never leaves its GPU.

type LUID

type LUID uint64

LUID identifies an adapter for the lifetime of a boot on Windows (DXGI adapter LUID). On macOS it is the Metal registry ID; on Linux the device number of its DRM render node (see RenderNodes).

type PowerGuard

type PowerGuard struct {
	Adapter Adapter
	Mode    PowerMode
	Reason  error
	// Executable is the program name the policy is bound to.
	Executable string
	// contains filtered or unexported fields
}

PowerGuard holds a GPU power policy until Close. It never fails to acquire: when the policy cannot be applied (no NVIDIA driver, no rights to write driver settings) Mode is PowerUnchanged and Reason holds the cause, and the encoder runs at the driver's default clocks.

func AcquireHighPerf

func AcquireHighPerf(adapter Adapter) *PowerGuard

AcquireHighPerf keeps an AMD GPU at its highest clocks while the process runs, through amdgpu's power_dpm_force_performance_level, where this user may write it (root, or a udev rule granting it). Elsewhere it changes nothing: NVIDIA's Linux driver has no per-application power policy (locking clocks with nvidia-smi needs root and holds for every process), and Intel's has none to set.

func (*PowerGuard) Close

func (g *PowerGuard) Close() error

Close restores what AcquireHighPerf changed. It is safe to call twice.

type PowerMode

type PowerMode uint8

PowerMode is what AcquireHighPerf achieved on an adapter.

const (
	// PowerUnchanged: no policy was applied; Reason says why.
	PowerUnchanged PowerMode = iota
	// PowerNotNeeded: the vendor's encoder does not drop to an idle clock
	// under a paced load, so there is nothing to change.
	PowerNotNeeded
	// PowerMaxPerformance: the driver keeps the adapter at its highest
	// performance state while this process runs.
	PowerMaxPerformance
)

func (PowerMode) String

func (m PowerMode) String() string

type RenderNode added in v0.2.0

type RenderNode struct {
	Path    string
	Driver  string
	Adapter Adapter
}

RenderNode is a DRM render node, /dev/dri/renderD*, which decoders, encoders and presenting surfaces open without a display's master rights.

func RenderNodeFor added in v0.2.0

func RenderNodeFor(vendor Vendor) (RenderNode, error)

RenderNodeFor is the first render node of vendor, or of any vendor for VendorUnknown.

func RenderNodes added in v0.2.0

func RenderNodes() ([]RenderNode, error)

RenderNodes lists the system's render nodes in number order. On Linux an Adapter's LUID is its render node's device number (st_rdev), the same for every process during a boot; its vendor and device come from sysfs.

type Vendor

type Vendor uint32
const (
	VendorUnknown Vendor = 0
	VendorNVIDIA  Vendor = 0x10de
	VendorAMD     Vendor = 0x1002
	VendorIntel   Vendor = 0x8086
	VendorApple   Vendor = 0x106b
)

PCI vendor IDs, plus Apple's ID for Apple silicon.

func (Vendor) String

func (v Vendor) String() string

Jump to

Keyboard shortcuts

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