Expand description
NVIDIA Framebuffer Capture (NvFBC): the zero-copy X11 capture path, where the NVIDIA driver composites the X screen straight into video memory and NVENC encodes it there.
The XShm path in super is the general one, and it copies once: the X server blits the
screen into a shared-memory surface, and a hardware session then uploads that surface across
PCIe. NvFBC removes both. The capture subsystem lives in the NVIDIA X driver, composites each
frame into a buffer it owns in video memory, and hands back a CUdeviceptr — which is
registered with NVENC in place, exactly as a Wayland dmabuf is, so a frame is never read,
written, or copied by the CPU between the screen and the bitstream.
Three properties follow from that, and the module is built around keeping all three:
- Zero copy. The device pointer is stable for as long as the geometry is, so it is
registered and mapped once (
NvencEncoder::encode_cuda_pitch) and every later frame reuses that registration. - Lowest latency. The session runs in push model — the driver generates a frame when an
application damages the screen rather than on a sampling timer — and each grab is issued
with
NOWAIT_IF_NEW_FRAME_READY, so a frame that already exists is taken immediately and one that does not is waited for only until the frame deadline. Direct capture is allowed, which lets the driver attach to a fullscreen unoccluded application and have it present into the capture buffer, bypassing the X server entirely. - Unrestricted frame rate. Capture and encode share one thread with no hand-off, and neither does any per-pixel CPU work: no shm round-trip, no content hashing on the host (the GPU hashes a new frame’s bands where it lies), no cursor blend. What the loop can sustain is what NVENC can sustain.
Requirements are checked rather than assumed, because none of them holds everywhere: the
session must encode on NVENC (the device pointer is meaningless to any other encoder), the X
server must be one the NVIDIA driver drives, the driver must offer NvFBC on this GPU and X
server, and a watermark keeps the XShm path since blending it would mean reading the frame
back. open reports what it found and returns None, and the caller streams through XShm
instead. The X server is asked first and over our own connection, because the library’s own
answer is the one that may never come.
The API is reached the way NVENC’s is: libnvidia-fbc.so.1 is loaded at run time and every
entry point comes from the function table NvFBCCreateInstance fills, so the build links no
NVIDIA library and one binary runs wherever a driver is installed. The structures below are
the ABI of NvFBC 1.8 (nvcodec-sys/headers/NvFBC.h); each carries a version word packing its
own size_of, which is what makes the layout assertions in abi_tests a real check.
Functions§
- run_
capture - Run the zero-copy X11 capture until
controls.stopis set, or report that it cannot start.