diff --git a/Cargo.lock b/Cargo.lock index a6de0ee..d804ad4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1665,11 +1665,14 @@ dependencies = [ name = "ec-hw" version = "0.1.0" dependencies = [ + "ec-av1", "ec-av1-syntax", "ec-core", + "ec-dsp", "ec-h264-syntax", "ec-h265-syntax", "ec-va", + "ec-vk", "ec-vp9-syntax", ] @@ -1836,6 +1839,13 @@ dependencies = [ "cros-libva", ] +[[package]] +name = "ec-vk" +version = "0.1.0" +dependencies = [ + "vk-video-ffi", +] + [[package]] name = "ec-vorbis" version = "0.1.0" @@ -1989,7 +1999,6 @@ version = "0.1.0" dependencies = [ "bytemuck", "ec-hw", - "ec-va", "ec-vp8", "engine", ] @@ -6698,6 +6707,13 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "vk-video-ffi" +version = "0.1.0" +dependencies = [ + "vulkanalia", +] + [[package]] name = "vswhom" version = "0.1.0" @@ -6718,6 +6734,25 @@ dependencies = [ "libc", ] +[[package]] +name = "vulkanalia" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebd71d6c64383bbdf1c260efa22e81e1a2a7dd832a3831af34495f47d7551d7b" +dependencies = [ + "libloading", + "vulkanalia-sys", +] + +[[package]] +name = "vulkanalia-sys" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d4da5d5e0c7377cea24358fa238b3b22a1913a7890f65dbd8ff9aa371a493a" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "waker-fn" version = "1.2.0" diff --git a/crates/engine-hw/Cargo.toml b/crates/engine-hw/Cargo.toml index 5bb3bfe..4e8e682 100644 --- a/crates/engine-hw/Cargo.toml +++ b/crates/engine-hw/Cargo.toml @@ -18,8 +18,6 @@ path = "src/bin/hw-child.rs" [dependencies] bytemuck = "1.25" engine = { path = "../engine" } -# The decode seat: ec-hw drives the VA-API decoders, ec-va the display under it. ec-hw = { path = "../../../edith_codecs/crates/ec-hw" } -ec-va = { path = "../../../edith_codecs/crates/ec-va" } # The software VP8 seat, this project's own (`ec-vp8`, RFC 6386). ec-vp8 = { path = "../../../edith_codecs/crates/ec-vp8" } diff --git a/crates/engine-hw/src/child.rs b/crates/engine-hw/src/child.rs index fade0b4..9185fa2 100644 --- a/crates/engine-hw/src/child.rs +++ b/crates/engine-hw/src/child.rs @@ -491,7 +491,7 @@ enum Seat { impl Seat { fn dma_geometry(&self) -> Option<(u32, u32)> { match self { - Self::Real(encoder) => Some(encoder.coded_size()), + Self::Real(encoder) => encoder.coded_size(), // Nothing to import into, so the parent stages pictures instead. Self::Fake => None, } diff --git a/crates/engine-hw/src/enc_ec.rs b/crates/engine-hw/src/enc_ec.rs index 40fbee8..54c1055 100644 --- a/crates/engine-hw/src/enc_ec.rs +++ b/crates/engine-hw/src/enc_ec.rs @@ -1,21 +1,20 @@ -//! The encode seats, on [`ec_hw::Encoder`]: H.264 (Main profile), HEVC and AV1. +//! The encode seats, on [`ec_hw::HwEncoder`]: H.264 (Main profile), HEVC and AV1. //! -//! A picture reaches the encoder one of two ways. Pixels the caller holds are -//! packed I420 and go through [`ec_hw::Encoder::encode`], which uploads them -//! into a pooled surface. A picture the decoder left on the GPU arrives as a -//! DRM-PRIME descriptor ([`DmaFrame`]); its file descriptors are duplicated into -//! an [`ec_va::PrimeSurface`], imported with [`ec_va::import_prime`] -//! and read in place by [`ec_hw::Encoder::encode_surface`], so no copy is made. +//! Pixels the caller holds are packed I420 and go through [`ec_hw::EncodeInput::I420`] +//! (or `I420_16` for 10-bit). A picture the decoder left on the GPU arrives as a +//! DRM-PRIME descriptor ([`DmaFrame`]) and goes through [`ec_hw::EncodeInput::DmaBufYuv`], +//! which the encoder imports and caches itself. The backend, Vulkan or VA-API, is the +//! one [`ec_hw::HwEncoder::open`] picks. use std::collections::VecDeque; -use std::os::fd::{AsFd, OwnedFd}; -use std::rc::Rc; +use std::os::fd::{AsFd, BorrowedFd}; -use ec_hw::enc::{EncCodec, EncoderConfig, FrameMetadata, RateControlMode}; -use ec_hw::{Encoder, H264Profile, I420, I420_16}; -use ec_va::{PrimeLayer, PrimeObject, PrimeSurface}; +use ec_hw::{ + Backend, DmaBufFormat, DmaBufPlane, DmaBufYuvFrame, EncCodec, EncodeInput, EncoderConfig, + FrameMetadata, H264Profile, HwEncoder, I420, I420_16, RateControlMode, +}; -use engine::hw::{DmaFrame, VhDma}; +use engine::hw::DmaFrame; use engine::hwproc::SeatRate; /// `DRM_FORMAT_NV12`, which is also `VA_FOURCC_NV12`: the four characters. @@ -25,30 +24,18 @@ const FOURCC_P010: u32 = u32::from_le_bytes(*b"P010"); /// One hardware encode session on `ec_hw`. pub(crate) struct EcEncSession { - display: Rc, - encoder: Encoder, + encoder: HwEncoder, /// Display size: what is encoded. width: usize, height: usize, - /// Macroblock- or block-aligned size the driver codes at. - coded: (u32, u32), timestamp: i64, /// Access units the encoder has finished but the caller has not taken yet, /// in encode order (which is display order: no B-frames). ready: VecDeque>, /// The access unit currently handed out, kept alive until the next call. out: Vec, - ten_bit: bool, - /// Imported decoder buffers, by the dma-buf inodes and layout they came as: - /// the decoder hands the same few surfaces out again and again, and a fresh - /// import costs the GPU a new mapping on its first use. - imports: VecDeque<(ImportKey, Rc>)>, } -type ImportKey = (Vec, VhDma); - -const IMPORTS_MAX: usize = 32; - /// The `open` arguments, for any of the three codecs. pub(crate) struct EcOpen { pub codec: EncCodec, @@ -63,7 +50,7 @@ pub(crate) struct EcOpen { pub gop: Option, /// Colour description for the VUI as `(primaries, transfer, matrix, full)`. pub colour: Option<(u8, u8, u8, bool)>, - /// HEVC Main10: pictures go through [`EcEncSession::encode16`]. + /// HEVC Main10: pictures go through [`EcEncSession::encode16_owned`]. pub ten_bit: bool, } @@ -122,20 +109,14 @@ impl EcEncSession { if ten_bit { config = config.ten_bit(); } - let display = ec_va::open().ok()?; - let encoder = Encoder::new(&display, config).ok()?; - let coded = encoder.coded_size(); + let encoder = HwEncoder::open(config, None).ok()?; Some(Self { - display, encoder, width: width as usize, height: height as usize, - coded, timestamp: 0, ready: VecDeque::new(), - imports: VecDeque::new(), out: Vec::new(), - ten_bit, }) } @@ -163,7 +144,11 @@ impl EcEncSession { bit_depth: 10, }; let meta = self.meta(force_keyframe); - if let Some(coded) = self.encoder.submit_16(&picture, meta).map_err(|e| e.to_string())? { + if let Some(coded) = self + .encoder + .submit(EncodeInput::I420_16(&picture), meta) + .map_err(|e| e.to_string())? + { self.ready.push_back(coded.data); } Ok(()) @@ -176,9 +161,13 @@ impl EcEncSession { Ok(()) } - /// The surface size the driver codes at, as the caller must describe it. - pub(crate) fn coded_size(&self) -> (u32, u32) { - self.coded + /// The size a DMA-BUF picture must be described at, or `None` when the + /// backend takes no DMA-BUF input (VA-API). + pub(crate) fn coded_size(&self) -> Option<(u32, u32)> { + match self.encoder.backend() { + Backend::Vk => Some((self.width as u32, self.height as u32)), + Backend::Va => None, + } } /// Codes one packed I420 picture (`y`, `u`, `v` at the session's size) and @@ -203,7 +192,11 @@ impl EcEncSession { height: h as u32, }; let meta = self.meta(force_keyframe); - if let Some(coded) = self.encoder.submit(&picture, meta).map_err(|e| e.to_string())? { + if let Some(coded) = self + .encoder + .submit(EncodeInput::I420(&picture), meta) + .map_err(|e| e.to_string())? + { self.ready.push_back(coded.data); } Ok(()) @@ -211,53 +204,41 @@ impl EcEncSession { /// Codes one picture the decoder left on the GPU, read in place. /// - /// The descriptors stay owned by `frame`: they are duplicated into the - /// imported surface, which owns its copies until it is dropped at the end - /// of this call. + /// The descriptors stay owned by `frame`; the encoder duplicates them on import. pub(crate) fn encode_dma(&mut self, frame: &DmaFrame, force_keyframe: bool) -> Result<(), String> { - let inodes = frame - .fds - .iter() - .map(|fd| { - use std::os::unix::fs::MetadataExt; - Some(std::fs::File::from(fd.try_clone().ok()?).metadata().ok()?.ino()) - }) - .collect::>>(); - let key = inodes.map(|inodes| (inodes, frame.desc)); - let cached = key - .as_ref() - .and_then(|key| self.imports.iter().find(|(k, _)| k == key)) - .map(|(_, surface)| Rc::clone(surface)); - let surface = match cached { - Some(surface) => surface, - None => { - let prime = prime_from_vhdma(&frame.desc, &frame.fds)?; - let surface = Rc::new(ec_va::import_prime(&self.display, &prime).map_err(|e| e.to_string())?); - if let Some(key) = key { - self.imports.push_back((key, Rc::clone(&surface))); - if self.imports.len() > IMPORTS_MAX { - self.imports.pop_front(); - } - } - surface - } + let format = match (frame.desc.fourcc, frame.fds.len()) { + (FOURCC_NV12, 1 | 2) => DmaBufFormat::Nv12, + (FOURCC_P010, 1 | 2) => DmaBufFormat::P010, + _ => return Err("DMA-BUF is not an NV12 or P010 picture on the GPU".into()), + }; + let fds: Vec = frame.fds.iter().map(|fd| fd.as_fd()).collect(); + let desc = &frame.desc; + let chroma_fd = if fds.len() == 2 { 1 } else { 0 }; + let input = DmaBufYuvFrame { + fds: &fds, + planes: [ + DmaBufPlane { + fd: 0, + offset: desc.offset[0], + pitch: desc.stride[0], + }, + DmaBufPlane { + fd: chroma_fd, + offset: desc.offset[1], + pitch: desc.stride[1], + }, + ], + width: self.width as u32, + height: self.height as u32, + modifier: desc.modifier, + format, }; - let display = (self.width as u32, self.height as u32); let meta = self.meta(force_keyframe); - if self.ten_bit { - if let Some(coded) = self - .encoder - .submit_prime(surface, meta) - .map_err(|e| e.to_string())? - { - self.ready.push_back(coded.data); - } - } else { - self.flush()?; - let coded = self - .encoder - .encode_surface(&surface, display, meta) - .map_err(|e| e.to_string())?; + if let Some(coded) = self + .encoder + .submit(EncodeInput::DmaBufYuv(&input), meta) + .map_err(|e| e.to_string())? + { self.ready.push_back(coded.data); } Ok(()) @@ -280,49 +261,3 @@ impl EcEncSession { Some(&self.out) } } - -/// Builds the PRIME descriptor for an NV12 or P010 picture the decoder holds. -/// -/// Luma and chroma are either two objects (two descriptors) or one object -/// holding both at their own offsets, as the decoder's descriptor says. -fn prime_from_vhdma(desc: &VhDma, fds: &[OwnedFd]) -> Result { - if fds.is_empty() || fds.len() > 2 || !matches!(desc.fourcc, FOURCC_NV12 | FOURCC_P010) { - return Err("DMA-BUF is not an NV12 or P010 picture on the GPU".into()); - } - let (w, h) = (desc.coded_width, desc.coded_height); - let rows = [h, h / 2]; - let two_objects = fds.len() == 2; - let mut objects = Vec::with_capacity(fds.len()); - for fd in fds { - objects.push(PrimeObject { - fd: fd.as_fd().try_clone_to_owned().map_err(|e| e.to_string())?, - size: 0, - modifier: desc.modifier, - }); - } - // The size each object must cover, luma rows then chroma rows. - for (plane, &plane_rows) in rows.iter().enumerate() { - let index = if two_objects { plane } else { 0 }; - let end = desc.offset[plane] as u64 + u64::from(desc.stride[plane]) * u64::from(plane_rows); - let size = &mut objects[index].size; - *size = (*size).max(u32::try_from(end).map_err(|_| "DMA-BUF too large")?); - } - let layer = PrimeLayer { - drm_format: desc.fourcc, - planes: vec![ - (0, desc.offset[0], desc.stride[0]), - ( - if two_objects { 1 } else { 0 }, - desc.offset[1], - desc.stride[1], - ), - ], - }; - Ok(PrimeSurface { - fourcc: desc.fourcc, - width: w, - height: h, - objects, - layers: vec![layer], - }) -} diff --git a/crates/engine-hw/src/lib.rs b/crates/engine-hw/src/lib.rs index 4f68e7c..2babb2d 100644 --- a/crates/engine-hw/src/lib.rs +++ b/crates/engine-hw/src/lib.rs @@ -1,6 +1,6 @@ //! Hardware decode and encode, held in a child process. This library is the //! whole world of the `hw-child` binary ([`child`]), the one process a video -//! driver is allowed to kill: VA-API decode (H.264, HEVC, VP9 and AV1), VP8 +//! driver is allowed to kill: Vulkan Video or VA-API decode (H.264, HEVC, VP9 and AV1), VP8 //! decode on `ec-vp8` ([`vpx`], software, linked in), and the encode seats //! (H.264, HEVC, and AV1 where the GPU has the entrypoint). //! @@ -18,11 +18,9 @@ mod vpx; use std::collections::VecDeque; use std::os::fd::OwnedFd; use std::path::Path; -use std::rc::Rc; -use ec_hw::Frame; use ec_hw::enc::EncCodec as EcCodec; -use ec_va::caps::Profile; +use ec_hw::{CodecProfile, Direction, HwPicture}; use enc_ec::{EcEncSession, EcOpen}; use engine::demux::{Codec, Demuxer, VideoMeta}; use engine::hw::{CAP_AV1, CAP_H264, CAP_HEVC, CAP_VP8, CAP_VP9, VhCaps, VhDma, VhMeta}; @@ -105,10 +103,7 @@ fn forward_skip(_standing: u32, ahead: u32) -> u32 { } struct Session { - decoder: ec_hw::Decoder, - /// The VA-API display the decoder's context and surfaces live on: kept - /// alive for as long as the session is. - _display: Rc, + decoder: ec_hw::HwDecoder, demuxer: Demuxer, meta: VhMeta, timestamp: i64, @@ -145,20 +140,14 @@ struct Session { /// holds its surface out of the decoder's pool, so the decoder would write /// the next picture into the one an encoder is still reading unless this /// keeps the last [`DMA_HOLD`] of them alive. - held: VecDeque, -} - -/// The VA-API display the decoders run on: the first render node that opens. -fn open_decode_display() -> Option> { - ec_va::open().ok() + held: VecDeque, } impl Session { - /// Assembles the VA-API half around a container that is already read -- + /// Assembles the hardware half around a container that is already read -- /// [`OpenSession::open_at`] owns the read and routes VP8 away from here /// before any device is opened. fn opened(meta: VideoMeta, demuxer: Demuxer) -> Option { - let display = open_decode_display()?; let codec = match meta.codec { Codec::H264 => ec_hw::Codec::H264, Codec::Hevc => ec_hw::Codec::H265, @@ -170,10 +159,9 @@ impl Session { // Never offered to VA-API: `decode::hw_decodes` refuses it first. Codec::Mpeg2 | Codec::ProRes | Codec::Dnxhd | Codec::Mjpeg | Codec::Dv | Codec::Mpeg4 | Codec::MsMpeg4 | Codec::Raw => return None, }; - let decoder = ec_hw::Decoder::new(&display, codec).ok()?; + let decoder = ec_hw::HwDecoder::open(codec).ok()?; Some(Self { decoder, - _display: display, demuxer, meta: VhMeta { width: meta.width, @@ -246,7 +234,7 @@ impl Session { /// Pumps the decoder until one picture is ready. `Ok(false)` is clean EOF. fn pump(&mut self) -> Result { loop { - if let Some(frame) = self.decoder.next_frame() { + if let Some(frame) = self.decoder.next_picture().map_err(|e| e.to_string())? { // One picture further along, shown or skipped past alike: // this is the only place [`Session::position`] walks. self.position += 1; @@ -296,7 +284,7 @@ impl Session { /// Hands one decoded picture to the caller: as the buffer it was decoded /// into where that is what the caller asked for and the encoder on the /// other side can read it, and as read-back I420 everywhere else. - fn deliver(&mut self, frame: Frame) -> Result<(), String> { + fn deliver(&mut self, frame: HwPicture) -> Result<(), String> { self.dma = None; if self.want.is_some() && let Some(dma) = self.export_dma(&frame) @@ -320,68 +308,39 @@ impl Session { /// objects, the fourcc and both sizes it asked for. `None` for every other /// answer, and the caller then gets the pixels it always got rather than a /// failure. - fn export_dma(&self, frame: &Frame) -> Option<(VhDma, Vec)> { + fn export_dma(&self, frame: &HwPicture) -> Option<(VhDma, Vec)> { let want = self.want?; - let (w, h) = frame.display_size; - if (w, h) != (want.width, want.height) { + if (frame.width, frame.height) != (want.width, want.height) { return None; } - let prime = frame.export_prime().ok()?; - // The driver describes the NV12 buffer as one layer per plane (R8 and - // GR88, each one plane into the same object), or as one composed layer - // holding both: either is the same two planes, in that order. - let planes: Vec<(u32, u32, u32)> = match prime.layers.as_slice() { - [layer] => layer.planes.clone(), - [luma, chroma] => { - let ([y], [uv]) = (luma.planes.as_slice(), chroma.planes.as_slice()) else { - return None; - }; - vec![*y, *uv] - } - _ => return None, - }; - let [(obj0, off0, pitch0), (obj1, off1, pitch1)] = planes.as_slice() else { - return None; - }; - let fits = prime.width == want.coded_width && prime.height == want.coded_height; - if prime.fourcc != want.fourcc - || !fits - || *obj0 != 0 - || *obj1 > 1 - || prime.objects.len() != *obj1 as usize + 1 + let pic = frame.export_dmabuf().ok()?; + let [plane0, plane1] = pic.planes; + if pic.fourcc != want.fourcc + || pic.width < want.coded_width + || pic.height < want.coded_height + || plane0.fd != 0 + || plane1.fd > 1 + || pic.fds.len() != plane1.fd + 1 { return None; } - let planes = [*obj0, *obj1]; - let (offset, stride) = ([*off0, *off1], [*pitch0, *pitch1]); - // Whatever the driver says the two planes live in, said back to it - // unchanged on the import: radeonsi answers with an object per plane, - // other drivers with one for both, and neither is ours to reinterpret. - let modifier = prime.objects[0].modifier; - let mut objects = prime.objects.into_iter(); - // Owned by the caller from here: they travel to the encoder with the - // descriptor, one per plane object. - let mut fds = vec![objects.next()?.fd]; - if planes[1] == 1 { - fds.push(objects.next()?.fd); - } Some(( VhDma { - fourcc: prime.fourcc, - modifier, - coded_width: prime.width, - coded_height: prime.height, - width: w, - height: h, - offset, - stride, + fourcc: pic.fourcc, + modifier: pic.modifier, + coded_width: pic.width, + coded_height: pic.height, + width: frame.width, + height: frame.height, + offset: [plane0.offset, plane1.offset], + stride: [plane0.pitch, plane1.pitch], }, - fds, + pic.fds, )) } /// Copies a decoded picture into `self.out` as packed I420. - fn emit(&mut self, frame: &Frame) -> Result<(), String> { + fn emit(&mut self, frame: &HwPicture) -> Result<(), String> { // The read-back goes through the driver's image copy (`vaGetImage`) // rather than a CPU map of the surface: on a discrete GPU that buffer // lives in VRAM, and a CPU read of it runs over the PCIe BAR. @@ -709,96 +668,66 @@ fn copy_plane(src: &[u8], src_stride: usize, dst: &mut [u8], w: usize, h: usize) } } -/// One row of [`CAP_TABLE`]: the capability bit, its 8-bit and 10-bit decode profiles, and its encode profile. -type CapRow = (u32, &'static [Profile], &'static [Profile], Option); - -/// What each codec needs of the driver before this plugin can claim it: the -/// 8-bit decode profiles, the 10-bit ones, and the profile the *encoder* here -/// would open -- `None` for the one this plugin has no encoder for at all, so a -/// GPU with a VP9 encode entrypoint is never reported as one edith can -/// reach. The encode profiles are the very ones the seats in [`enc_ec`] and -/// [`EncSession::open_seat`] ask for, which is what keeps this a description of the plugin rather than a -/// second opinion about it. -const CAP_TABLE: [CapRow; 4] = [ - ( - CAP_H264, - &[ - Profile::H264ConstrainedBaseline, - Profile::H264Main, - Profile::H264High, - ], - &[], - Some(Profile::H264Main), - ), - ( - CAP_HEVC, - &[Profile::HEVCMain], - &[Profile::HEVCMain10], - // 8-bit Main only: the encoder here opens Main whatever the source was, - // so a Main 10 entrypoint is a *decode* claim on this line and nothing - // more. Main 10 encode would be a second profile here and a 10-bit input - // buffer in `EncSession`, neither of which exists yet. - Some(Profile::HEVCMain), - ), - ( - CAP_VP9, - &[Profile::VP9Profile0], - &[Profile::VP9Profile2], - None, - ), - ( - CAP_AV1, - &[Profile::AV1Profile0], - // AV1 carries 8- and 10-bit in the same profile 0, so the profile bit - // is the same one and the P010 read-back is what decides. - &[Profile::AV1Profile0], - Some(Profile::AV1Profile0), - ), -]; - -/// This machine's decode and encode seats, asked of the driver rather than -/// assumed: which profiles it has, which entrypoints each of those carries, and -/// whether a P010 image exists to read a 10-bit picture back through. Only -/// codecs this plugin actually implements can light up -- `CAP_TABLE` is that -/// half of the intersection. +/// This machine's decode and encode seats, as the hardware backends report +/// them. `None` when there are none at all, the same "software only" a missing +/// plugin means. /// /// VP8 is the one bit asked of nobody: it is this plugin's own native seat -/// (`vpx`, `ec-vp8` linked in), lit unconditionally -- no profile, no -/// entrypoint, no display, no library to load. It rides along only when the -/// display *is* answerable, because this symbol's shape says a displayless -/// machine has nothing to report at all; the decode path itself needs no -/// display for it ([`OpenSession::open_at`] routes VP8 before any device -/// opens). -/// -/// `None` when there is no display to ask at all, which is the same "software -/// only" a missing plugin means. +/// (`vpx`, `ec-vp8` linked in), lit unconditionally. fn query_caps() -> Option { - use ec_va::caps::Entrypoint; - let display = open_decode_display()?; - let report = ec_va::CapReport::probe(&display).ok()?; - let p010 = report.image_formats.contains(&VA_FOURCC_P010); - let decodes = |list: &[Profile]| list.iter().any(|&p| report.supports(p, Entrypoint::VLD)); - let mut caps = VhCaps::default(); - for (bit, eight, ten, encode) in CAP_TABLE { - if decodes(eight) { - caps.decode |= bit; + let caps = ec_hw::capabilities(); + if caps.is_empty() { + return None; + } + let decode = |profile: CodecProfile| { + caps.iter() + .any(|c| c.direction == Direction::Decode && c.profile == profile) + }; + let encode = |profile: CodecProfile| { + caps.iter() + .any(|c| c.direction == Direction::Encode && c.profile == profile) + }; + let h264_decode = caps + .iter() + .any(|c| c.direction == Direction::Decode && c.codec == ec_hw::Codec::H264); + let h264_encode = caps + .iter() + .any(|c| c.direction == Direction::Encode && c.codec == ec_hw::Codec::H264); + let table = [ + (CAP_H264, h264_decode, false, h264_encode), + ( + CAP_HEVC, + decode(CodecProfile::H265Main), + decode(CodecProfile::H265Main10), + encode(CodecProfile::H265Main), + ), + ( + CAP_VP9, + decode(CodecProfile::Vp9Profile0), + decode(CodecProfile::Vp9Profile2), + false, + ), + ( + CAP_AV1, + decode(CodecProfile::Av1Main), + decode(CodecProfile::Av1Main10), + encode(CodecProfile::Av1Main), + ), + ]; + let mut out = VhCaps::default(); + for (bit, eight, ten, enc) in table { + if eight { + out.decode |= bit; } - if p010 && decodes(ten) { - caps.decode_10bit |= bit; + if ten { + out.decode_10bit |= bit; } - // Both entrypoints, exactly as the encoder's own open takes either. - if encode.is_some_and(|p| { - report.supports(p, Entrypoint::EncSlice) || report.supports(p, Entrypoint::EncSliceLP) - }) { - caps.encode |= bit; + if enc { + out.encode |= bit; } } - // The plugin's own software decoder, on its own account rather than the - // driver's -- the plugin's capability, never a GPU feat. Native now, so - // the bit has no "when it loads" condition left: it lights on every - // machine this plugin runs on. - caps.decode |= CAP_VP8; - Some(caps) + out.decode |= CAP_VP8; + Some(out) } /// How many pictures a group of them holds -- the low-delay predictor's diff --git a/crates/engine/src/export.rs b/crates/engine/src/export.rs index e4ddeef..8335908 100644 --- a/crates/engine/src/export.rs +++ b/crates/engine/src/export.rs @@ -1411,7 +1411,7 @@ fn hevc_irap(au: &[u8]) -> bool { /// What a hardware encode is called wherever one is named -- the card's line /// before the export and the progress line during it. -const HW_LABEL: &str = "HW encode (VA-API)"; +const HW_LABEL: &str = "HW encode (GPU)"; /// ...and what a card says instead where [`EncoderSeat::Hardware`] was picked /// and there is no seat: the export's own refusal in the width of a card row, diff --git a/crates/mcp/src/tools/export.rs b/crates/mcp/src/tools/export.rs index 0a563e8..77e2314 100644 --- a/crates/mcp/src/tools/export.rs +++ b/crates/mcp/src/tools/export.rs @@ -2381,7 +2381,7 @@ mod tests { #[test] fn picture_label_names_the_engine_seat_then_the_plan_and_skips_audio_only() { - let measured = Some("HW encode (VA-API) · AAC · SW encode (ec-aac)".to_string()); + let measured = Some("HW encode (GPU) · AAC · SW encode (ec-aac)".to_string()); assert_eq!(picture_label(measured, "SW encode (rav1e)", Format::Mp4), " · video: H.264 (hardware)"); assert_eq!(picture_label(None, "SW encode (ec-h264)", Format::Mp4), " · video: H.264 (software)"); assert_eq!(picture_label(Some("copy · AAC".into()), "SW encode (ec-h264)", Format::Mp4), " · video: H.264 (copy)"); @@ -2404,7 +2404,7 @@ mod tests { assert_eq!(av_words(Format::Wav, "", "PCM · SW (hound)"), "audio: PCM, container: WAV"); assert_eq!(av_words(Format::Gif, "", ""), "no sound, container: GIF"); assert_eq!(av_words(Format::PngSequence, "", ""), "no sound, container: PNG folder"); - assert_eq!(measured_sound(Some("HW encode (VA-API) · AAC · SW encode (ec-aac)")).as_deref(), Some("AAC")); + assert_eq!(measured_sound(Some("HW encode (GPU) · AAC · SW encode (ec-aac)")).as_deref(), Some("AAC")); assert_eq!(measured_sound(Some("SW encode (ec-h264)")), None); assert_eq!(measured_sound(None), None); assert_eq!(plain_audio("no sound to write"), "none");