Expand description
Linux CUDA device memory: the NV12 Frame behind Surface::Cuda, which
NVDEC or a Converter produces and NVENC scales into its own input on the
GPU.
§The GPU-only path
External producers publish Surface::Vulkan with encode::Config::input
naming their device. NVENC imports and converts those images here, caching
one full-size conversion per capture and color space, then scaling each
rendition on the GPU. Those images are never downloaded.
Native Surface::Cuda frames from NVDEC also stay on the GPU. Their portable
Surface methods permit CPU readback for software transcoding, while an
external Vulkan image refuses that fallback.
NVENC reads a registered cuMemAlloc NV12 buffer
(NV_ENC_INPUT_RESOURCE_TYPE_CUDADEVICEPTR): each session’s own Target,
which every frame is copied into, or scaled into when its size differs. The
one copy is what lets a session register once rather than per frame, and
costs microseconds of GPU time. The SDK 12.1 bindings could also register
the imported Vulkan image itself as a CUDA array in an RGB session, but NVENC
would then own the color matrix, and the smaller rendition would still need
its own conversion, so a kernel that writes NV12 straight from the image is
the one pass this path needs: no staging copy in either direction.
What the hardware says (RTX 3070 Ti, driver 595.91.07, just rs gpu):
the kernels match a CPU reference exactly, and an nsys --trace=cuda capture
of tests::vulkan_cuda_three_view_workload records no cuMemcpy in either
direction.
§Nothing per frame takes the driver’s device lock
Allocating, freeing, and registering device memory go through the
driver’s per-GPU lock, which every process on the device shares, and
cuMemFree also waits for the whole device. Paid per frame, those calls
serialize every transcode on the GPU while its engines sit idle. So every
frame’s buffer comes from a Pool and goes back to it, and each NVENC
session copies or scales its input into one Target it registered once. Scaling
and copies run on their owner’s own stream, never the legacy default
stream, which would wait for every other thread’s work in the process.
Structs§
- Frame
- A GPU NV12 frame in CUDA device memory: NVDEC’s or a
Converter’s output and NVENC’s zero-copy input. One buffer holds both planes at a shared rowpitch:heightluma rows, thenheight / 2interleaved-UV rows. Cloning bumps refcounts (no pixel copy), which keeps decode -> encode on the GPU; an encoder holds a clone until it has read the frame.