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
@@ -340,7 +340,8 @@ struct Sample {
|
||||
layers: Vec<(LayerId, LayerSnapshot)>,
|
||||
sent: u64,
|
||||
captured: u64,
|
||||
/// Captured frames converted on the GPU (never read by the CPU).
|
||||
/// Captured frames converted on the GPU (DMA-BUFs, or pictures in memory
|
||||
/// copied into a surface).
|
||||
gpu: u64,
|
||||
/// Frames the handoffs to the encoders dropped, per layer.
|
||||
dropped: Vec<(LayerId, u64)>,
|
||||
@@ -467,7 +468,7 @@ fn bench(args: BenchArgs) -> Result<()> {
|
||||
let ms = |d: Duration| d.as_secs_f64() * 1000.0;
|
||||
println!(
|
||||
"capture: {:.1} fps; convert + scale: CPU {} frames, {:.2} ms per frame on {} threads; \
|
||||
GPU (DMA-BUF, never read by the CPU) {gpu} frames, {:.2} ms per frame",
|
||||
GPU {gpu} frames, {:.2} ms per frame",
|
||||
captured as f64 / secs,
|
||||
captured - gpu.min(captured),
|
||||
ms(stats.convert_time),
|
||||
|
||||
Reference in new issue
Block a user