diff --git a/quest/m2/video-vaapi.md b/quest/m2/video-vaapi.md index da73c013229..80e88f6adb9 100644 --- a/quest/m2/video-vaapi.md +++ b/quest/m2/video-vaapi.md @@ -25,7 +25,10 @@ without NVDEC has no hardware path for it. converts them through VPP (`dmabuf`, `vpp`, `Encoder::encode_dmabuf`, `Encoder::set_bitrate`); `encode/backend/vaapi.rs` encodes a `Surface::DmaBuf` without a download, and `Surface::resize` scales one through VPP. Validated on -Intel Meteor Lake. What is left is H.265, below. +Intel Meteor Lake. `just rs gpu` also runs the ignored +`vaapi_1080p_ladder_stays_on_the_gpu` proof on Intel: 1080p decode to DMA-BUFs, +VPP to 720p/480p/360p, GPU encode of every frame, and decoded output sizes and +counts. What is left is H.265, below. **H.265.** The VAAPI backend advertises H.264 only. `moq-vaapi` 0.1.0 vendors the HEVC buffer types (`src/buffer/hevc.rs`) but its `Encoder` is hardcoded to diff --git a/rs/moq-video/src/encode/backend/vaapi.rs b/rs/moq-video/src/encode/backend/vaapi.rs index 65d68b311a2..ab9e3d36283 100644 --- a/rs/moq-video/src/encode/backend/vaapi.rs +++ b/rs/moq-video/src/encode/backend/vaapi.rs @@ -567,3 +567,105 @@ mod tests { } } } + +#[cfg(test)] +mod hardware_tests { + use super::*; + use crate::{FrameRate, Output, Size, decode, encode}; + use moq_net::Timestamp; + + /// Decode one 1080p source and scale/encode every picture at each ladder size. + /// Explicitly requested hardware must fail, never skip or accept CPU transfers. + /// The tests above check pixels with an independent software decoder; this + /// proof deliberately compiles without a software codec. + #[test] + #[ignore = "requires an Intel VA-API decode/VPP/encode device"] + fn vaapi_1080p_ladder_stays_on_the_gpu() { + const FRAMES: usize = 12; + let size = Size::new(1920, 1080); + let mut config = Config::new(size.width, size.height, FrameRate::new(30, 1).unwrap()); + config.kind = encode::Kind::Hardware; + let mut source = encode::Encoder::new(&config).expect("hardware source encoder"); + assert_eq!(source.name(), NAME, "run on a VA-API host without NVIDIA"); + let video = hang::catalog::VideoConfig::new(hang::catalog::H264 { + inline: true, + profile: 0x4d, + constraints: 0, + level: 40, + }); + let mut config = decode::Config::new(); + config.kind = decode::Kind::Hardware; + config.output = Output::Native; + let mut decoder = decode::Decoder::new(&video, &config).expect("hardware source decoder"); + assert_eq!(decoder.name(), crate::decode::backend::vaapi::NAME); + + let pixels = I420::new(size, vec![128; size.pixels() as usize * 3 / 2]).unwrap(); + let mut frames = Vec::new(); + for index in 0..FRAMES { + let timestamp = Timestamp::from_micros(index as u64 * 33_333).unwrap(); + let frame = Frame::new(Surface::I420(pixels.clone()), timestamp); + for packet in source.encode(&frame).expect("encode source") { + frames.extend( + decoder + .decode(&packet.payload, packet.timestamp, packet.keyframe) + .expect("decode source"), + ); + } + } + for packet in source.finish().expect("finish source") { + frames.extend( + decoder + .decode(&packet.payload, packet.timestamp, packet.keyframe) + .expect("decode source tail"), + ); + } + frames.extend(decoder.flush().expect("flush source decoder")); + assert_eq!(frames.len(), FRAMES); + assert!( + frames.iter().all(|frame| matches!(frame.surface, Surface::DmaBuf(_))), + "decode downloaded pixels" + ); + + for size in [Size::new(1280, 720), Size::new(852, 480), Size::new(640, 360)] { + let mut config = Config::new(size.width, size.height, FrameRate::new(30, 1).unwrap()); + config.color = frames[0].surface.color(); + let mut encoder = Vaapi::new(&config).expect("rung encoder"); + let mut output = decode::Decoder::new( + &video, + &decode::Config { + kind: decode::Kind::Hardware, + output: Output::Native, + ..decode::Config::new() + }, + ) + .expect("rung decoder"); + assert_eq!(output.name(), crate::decode::backend::vaapi::NAME); + let mut decoded = Vec::new(); + for (index, frame) in frames.iter().enumerate() { + let scaled = frame + .resize(size, &crate::resize::Config::default()) + .expect("VPP resize"); + assert!( + matches!(scaled.surface, Surface::DmaBuf(_)), + "{size}: resize downloaded pixels" + ); + assert_eq!(scaled.size(), size); + for packet in encoder.encode(&scaled, index == 0).expect("encode rung") { + decoded.extend( + output + .decode(&packet.payload, packet.timestamp, packet.keyframe) + .expect("decode rung"), + ); + } + } + decoded.extend(output.flush().expect("flush rung decoder")); + assert_eq!(encoder.gpu_frames, FRAMES as u64, "{size}: encoder used CPU transfers"); + assert!(encoder.refused.is_empty()); + assert_eq!(decoded.len(), FRAMES, "{size}: lost output pictures"); + assert!( + decoded.iter().all(|frame| frame.size() == size), + "{size}: wrong output size" + ); + } + } +} diff --git a/sh/gh/test-inventory.allow b/sh/gh/test-inventory.allow index 14e5e6f01c9..29342f1414c 100644 --- a/sh/gh/test-inventory.allow +++ b/sh/gh/test-inventory.allow @@ -6,6 +6,7 @@ ignore moq-carla-bridge::gpu_video_reaches_the_worker /quest/m2/carla-bridge.md recipe carla::bridge-gpu /quest/m2/carla-bridge.md recipe rs::gpu /quest/m2/gpu-ci.md +ignore moq-video::encode::backend::vaapi::hardware_tests::vaapi_1080p_ladder_stays_on_the_gpu /quest/m2/video-vaapi.md ignore moq-video::frame::vulkan::tests::vulkan_gpu_device /quest/m2/gpu-ci.md ignore moq-video::frame::vulkan::tests::vulkan_cuda_slot_reuse_and_teardown /quest/m2/gpu-ci.md ignore moq-video::frame::cuda::tests::vulkan_cuda_auto_external_encode /quest/m2/gpu-ci.md diff --git a/sh/rs/gpu.sh b/sh/rs/gpu.sh index ac1e7f1c740..65dfd30ccd6 100755 --- a/sh/rs/gpu.sh +++ b/sh/rs/gpu.sh @@ -52,7 +52,16 @@ for vendor in "${!vendors[@]}"; do LD_LIBRARY_PATH="$loader/lib" VK_DRIVER_FILES="${icd[0]}" \ just rs test -p moq-video --features render,openh264 --lib --run-ignored only \ -E 'test(=render::export::vulkan::tests::vulkan_export_round_trips) | test(/^render::export::tests::(choosing_passes_over|a_named_encoder)_/)' - echo "GPU $vendor: Vulkan driver verified; encoder hardware tests arrive with its backend" + if [[ "$vendor" == 0x8086 ]]; then + va=$(nix build --inputs-from . --no-link --print-out-paths nixpkgs#libva.out) + media=$(nix build --inputs-from . --no-link --print-out-paths nixpkgs#intel-media-driver) + LD_LIBRARY_PATH="$va/lib" LIBVA_DRIVERS_PATH="$media/lib/dri" LIBVA_DRIVER_NAME=iHD \ + just rs test -p moq-video --no-default-features --features vaapi --lib --run-ignored only \ + -E 'test(=encode::backend::vaapi::hardware_tests::vaapi_1080p_ladder_stays_on_the_gpu)' + else + echo 'AMD VA-API encode and VPP are not covered by this hardware selection' + fi + echo "GPU $vendor: Vulkan driver verified" ;; esac done