Files
VoelinClient/tools
selikhovandClaude Opus 5.5 c1cfd3d3b7 voelin-core: screen capture DMA-BUFs go to VA-API encoders on the GPU
The streamer's sink never took DMA-BUFs, so every captured frame was
read by the CPU, converted to I420 on every core and uploaded again for
a VA-API encoder; on a discrete GPU reading the buffer alone cost 19.5
cores at 1440p60 until the portal fell back to shared memory.

Ingest now takes DMA-BUFs whenever every encoder of every layer takes
GPU frames: on the capture thread one GpuConverter call converts the
buffer to NV12 and scales it for each layer that is due, straight into
surfaces of our own, and returns once the GPU is done, so the buffer goes
back to the compositor at once. Each layer's frame travels through a
second handoff to its encoder thread, which waits on both inboxes and
encodes the surface as it is (encode_gpu). The CPU path stays as it was
for everything else, and the capture switches to it by itself:

- an encoder that needs frames in memory (libvpx, x264, or an encoder
  made for a viewer of another codec) sets its layer's GPU alignment to
  0, so Ingest declines the next DMA-BUF and the portal maps it; until
  then such an encoder skips GPU frames and starts with a keyframe;
- a conversion that fails turns the GPU stage off for the capture, with
  the reason in StreamerStats::gpu_error.

Each layer's encoders publish the largest alignment they need, so the
GPU makes frames at sizes they encode exactly (AV1 on RDNA3 included).
A still screen's last GPU picture is sent again with a new timestamp
through another reference to its surface (GpuFrame::at).

StreamerStats gains gpu_frames, gpu_convert_time and gpu_error, and
`voelinctl stream bench` prints both paths; its new --dmabuf hands the
test pattern over as DMA-BUFs (StreamerConfig::synthetic_dmabuf), which
drives this path without a portal. Measured there (debug build, 720p30,
h264_vaapi): every frame on the GPU, 0.90 ms per frame on the capture
thread, 0.02 cores for the whole process.

Test: two simulcast layers through h264_vaapi take the GPU path for every
frame at their own sizes; a switch to libvpx takes the CPU path again
and the stream decodes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 07:47:47 +03:00
..