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>
This commit is contained in:
1 parent
c42efa5955
commit
c1cfd3d3b7
6 files changed
+383
-29
No files matched your search
@@ -71,6 +71,11 @@ struct BenchArgs {
|
||||
/// as real screen content) or `simple` (a flat background).
|
||||
#[arg(long, default_value = "desktop")]
|
||||
pattern: String,
|
||||
/// Hand the test pattern over as DMA-BUFs of ordinary memory, as the
|
||||
/// portal hands over the screen (Linux, `/dev/udmabuf`): with VA-API
|
||||
/// encoders the frames are then converted and scaled on the GPU.
|
||||
#[arg(long)]
|
||||
dmabuf: bool,
|
||||
/// Video codec: vp8, vp9, h264, av1 or h265 [default: the codec of
|
||||
/// --encoder if named, else the first the encoder choice gives].
|
||||
#[arg(long)]
|
||||
@@ -293,6 +298,8 @@ struct Sample {
|
||||
layers: Vec<(LayerId, LayerSnapshot)>,
|
||||
sent: u64,
|
||||
captured: u64,
|
||||
/// Captured frames converted on the GPU (never read by the CPU).
|
||||
gpu: u64,
|
||||
/// Frames the handoffs to the encoders dropped, per layer.
|
||||
dropped: Vec<(LayerId, u64)>,
|
||||
}
|
||||
@@ -309,6 +316,7 @@ fn sample(sink: &BenchSink, streamer: &Streamer) -> Sample {
|
||||
layers: sink.snapshot(),
|
||||
sent: stats.video_frames,
|
||||
captured: stats.captured_frames,
|
||||
gpu: stats.gpu_frames,
|
||||
dropped: stats.layers.iter().map(|l| (l.id, l.dropped)).collect(),
|
||||
}
|
||||
}
|
||||
@@ -345,6 +353,7 @@ fn bench(args: BenchArgs) -> Result<()> {
|
||||
source: source.clone(),
|
||||
synthetic_size: (width, height),
|
||||
synthetic_pattern: pattern,
|
||||
synthetic_dmabuf: args.dmabuf,
|
||||
fps: args.fps,
|
||||
bitrate_kbps: args.bitrate,
|
||||
codec,
|
||||
@@ -411,13 +420,20 @@ fn bench(args: BenchArgs) -> Result<()> {
|
||||
|
||||
let secs = (end.at - start.at).as_secs_f64();
|
||||
let captured = end.captured - start.captured;
|
||||
let gpu = end.gpu - start.gpu;
|
||||
let ms = |d: Duration| d.as_secs_f64() * 1000.0;
|
||||
println!(
|
||||
"capture: {:.1} fps; convert + scale: {:.2} ms per frame on {} threads",
|
||||
"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",
|
||||
captured as f64 / secs,
|
||||
captured - gpu.min(captured),
|
||||
ms(stats.convert_time),
|
||||
stats.convert_threads,
|
||||
ms(stats.gpu_convert_time),
|
||||
);
|
||||
if let Some(e) = &stats.gpu_error {
|
||||
println!("GPU path stopped: {e}");
|
||||
}
|
||||
let mut output_frames = 0;
|
||||
for ((id, a), (_, b)) in start.layers.iter().zip(&end.layers) {
|
||||
let frames = b.frames - a.frames;
|
||||
|
||||
Reference in new issue
Block a user