Streamer: convert pictures in memory on the GPU too, for VA-API encoders
Measured at 7680x4320@60 with av1_vaapi at 60 Mbit/s, the CPU path made 27 fps: the pyramid converted each frame to I420 on every core (4.6 ms), then the encoder thread interleaved it to NV12 and uploaded it into a VA-API surface on one thread (`encode_with`), 20 ms of its 36.7 ms per frame, so 81 frames in 5 s were dropped. 3840x2160@120 with h264_vaapi made 84 fps the same way. While every encoder takes GPU frames, a picture in memory (shared memory from the portal, X11, wlroots, the studio's composite, the test pattern) now takes the GPU path the DMA-BUFs take: `GpuConverter::convert_memory` copies it as it is (BGRx or RGBx) into a VA-API surface of its own and converts and scales that for every layer. That copy is all the CPU does: 5.7 ms of the 11.9 a 7680x4320 frame takes (the rest is the GPU's upload and conversion), one thread, because eight copying threads saved 2 ms for four times the CPU. Not waiting for the GPU was tried and was slower (36 fps at 8K60 against 42: the encoder then waited instead). The test pattern drew a 7680x4320 frame on one thread (230 MB of copies), which alone kept the bench under 40 fps; it now draws in bands on four threads, which the memory bandwidth limits anyway. Tests: a BGRx and an RGBx picture through the GPU match the CPU's conversion (40.4 dB at full size, 48.7 at half), and a streamer on the test pattern in memory with two `h264_vaapi` layers sends every frame through the GPU and decodes in the right colours (a red-blue swap fails it). The bench's GPU count now covers both kinds of frame. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1f7c16ab27
commit
69152a8ae1
8 files changed
+349
-70
No files matched your search
+14
-7
@@ -111,13 +111,20 @@ viewer: Engine::subscribe_frames ─ VideoPipeline (thread) ─ VideoDecoder
|
||||
the buffer goes straight back to the compositor; the CPU never reads it.
|
||||
Each layer's surface reaches its encoder thread through a second
|
||||
handoff (the thread waits on both) and is encoded as it is
|
||||
(`encode_gpu`). Anything else takes the CPU path as before, and the
|
||||
capture switches between the two by itself: an encoder that needs frames
|
||||
in memory (libvpx, x264, or one made for a viewer of another codec)
|
||||
makes the sink decline the next DMA-BUF, so the portal maps it, and a
|
||||
conversion that fails turns the GPU path off for the capture
|
||||
(`StreamerStats::gpu_error`). Nothing is allocated per frame on this
|
||||
path either (the surfaces' frames are recycled).
|
||||
(`encode_gpu`). A picture in memory (shared memory from the portal, X11,
|
||||
wlroots, the studio's composite, the test pattern) takes the same path
|
||||
while the encoders do: `GpuConverter::convert_memory` copies it into a
|
||||
VA-API surface of its own (one copy on the capture thread, BGRx or RGBx
|
||||
as it is) and converts and scales that, instead of converting it to
|
||||
I420 on every core, scaling it, and uploading each layer on its encoder
|
||||
thread. At 7680x4320 that was more than a frame at 30 fps has (see [the
|
||||
measurements](#60-mbits-up-to-8k-and-320-fps-measured)). Anything else takes the
|
||||
CPU path as before, and the capture switches between the two by itself:
|
||||
an encoder that needs frames in memory (libvpx, x264, or one made for a
|
||||
viewer of another codec) makes the sink decline the next DMA-BUF, so the
|
||||
portal maps it, and a conversion that fails turns the GPU path off for
|
||||
the capture (`StreamerStats::gpu_error`). Nothing is allocated per frame
|
||||
on this path either (the surfaces' frames are recycled).
|
||||
- Simulcast: `StreamerConfig::layers` (`voelin_stream::LayerSpec`; empty:
|
||||
one layer 0 at `bitrate_kbps`) are all encoded, each with its own encoder
|
||||
at `output_size()` of the source, its own frame-rate cap (`max_fps`,
|
||||
|
||||
Reference in new issue
Block a user