forge
Explore
Log in

Don't you dare go Hollow

⚡ engine-hw on ec_hw::HwDecoder/HwEncoder (Vulkan Video first, VA-API fallback): 4K HEVC Main10 hw export 32.9 -> 153 fps, decode bit-exact; per-picture readback or DMA-BUF export; capabilities from ec_hw

Browse files at this commit

ff99ad61bd8ccdc89c71277150f10d4ee298234aAhmet Kaan GümüşParent: 527b49c
Cargo.lockmodified+36 -1
@@ -1665,11 +1665,14 @@ dependencies = [
16651665 name = "ec-hw"
16661666 version = "0.1.0"
16671667 dependencies = [
1668+ "ec-av1",
16681669 "ec-av1-syntax",
16691670 "ec-core",
1671+ "ec-dsp",
16701672 "ec-h264-syntax",
16711673 "ec-h265-syntax",
16721674 "ec-va",
1675+ "ec-vk",
16731676 "ec-vp9-syntax",
16741677 ]
16751678
@@ -1836,6 +1839,13 @@ dependencies = [
18361839 "cros-libva",
18371840 ]
18381841
1842+[[package]]
1843+name = "ec-vk"
1844+version = "0.1.0"
1845+dependencies = [
1846+ "vk-video-ffi",
1847+]
1848+
18391849 [[package]]
18401850 name = "ec-vorbis"
18411851 version = "0.1.0"
@@ -1989,7 +1999,6 @@ version = "0.1.0"
19891999 dependencies = [
19902000 "bytemuck",
19912001 "ec-hw",
1992- "ec-va",
19932002 "ec-vp8",
19942003 "engine",
19952004 ]
@@ -6698,6 +6707,13 @@ version = "0.9.5"
66986707 source = "registry+https://github.com/rust-lang/crates.io-index"
66996708 checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
67006709
6710+[[package]]
6711+name = "vk-video-ffi"
6712+version = "0.1.0"
6713+dependencies = [
6714+ "vulkanalia",
6715+]
6716+
67016717 [[package]]
67026718 name = "vswhom"
67036719 version = "0.1.0"
@@ -6718,6 +6734,25 @@ dependencies = [
67186734 "libc",
67196735 ]
67206736
6737+[[package]]
6738+name = "vulkanalia"
6739+version = "0.35.0"
6740+source = "registry+https://github.com/rust-lang/crates.io-index"
6741+checksum = "ebd71d6c64383bbdf1c260efa22e81e1a2a7dd832a3831af34495f47d7551d7b"
6742+dependencies = [
6743+ "libloading",
6744+ "vulkanalia-sys",
6745+]
6746+
6747+[[package]]
6748+name = "vulkanalia-sys"
6749+version = "0.35.0"
6750+source = "registry+https://github.com/rust-lang/crates.io-index"
6751+checksum = "08d4da5d5e0c7377cea24358fa238b3b22a1913a7890f65dbd8ff9aa371a493a"
6752+dependencies = [
6753+ "bitflags 1.3.2",
6754+]
6755+
67216756 [[package]]
67226757 name = "waker-fn"
67236758 version = "1.2.0"
crates/engine-hw/Cargo.tomlmodified+0 -2
@@ -18,8 +18,6 @@ path = "src/bin/hw-child.rs"
1818 [dependencies]
1919 bytemuck = "1.25"
2020 engine = { path = "../engine" }
21-# The decode seat: ec-hw drives the VA-API decoders, ec-va the display under it.
2221 ec-hw = { path = "../../../edith_codecs/crates/ec-hw" }
23-ec-va = { path = "../../../edith_codecs/crates/ec-va" }
2422 # The software VP8 seat, this project's own (`ec-vp8`, RFC 6386).
2523 ec-vp8 = { path = "../../../edith_codecs/crates/ec-vp8" }
crates/engine-hw/src/child.rsmodified+1 -1
@@ -491,7 +491,7 @@ enum Seat {
491491 impl Seat {
492492 fn dma_geometry(&self) -> Option<(u32, u32)> {
493493 match self {
494- Self::Real(encoder) => Some(encoder.coded_size()),
494+ Self::Real(encoder) => encoder.coded_size(),
495495 // Nothing to import into, so the parent stages pictures instead.
496496 Self::Fake => None,
497497 }
crates/engine-hw/src/enc_ec.rsmodified+60 -125
@@ -1,21 +1,20 @@
1-//! The encode seats, on [`ec_hw::Encoder`]: H.264 (Main profile), HEVC and AV1.
1+//! The encode seats, on [`ec_hw::HwEncoder`]: H.264 (Main profile), HEVC and AV1.
22 //!
3-//! A picture reaches the encoder one of two ways. Pixels the caller holds are
4-//! packed I420 and go through [`ec_hw::Encoder::encode`], which uploads them
5-//! into a pooled surface. A picture the decoder left on the GPU arrives as a
6-//! DRM-PRIME descriptor ([`DmaFrame`]); its file descriptors are duplicated into
7-//! an [`ec_va::PrimeSurface`], imported with [`ec_va::import_prime`]
8-//! and read in place by [`ec_hw::Encoder::encode_surface`], so no copy is made.
3+//! Pixels the caller holds are packed I420 and go through [`ec_hw::EncodeInput::I420`]
4+//! (or `I420_16` for 10-bit). A picture the decoder left on the GPU arrives as a
5+//! DRM-PRIME descriptor ([`DmaFrame`]) and goes through [`ec_hw::EncodeInput::DmaBufYuv`],
6+//! which the encoder imports and caches itself. The backend, Vulkan or VA-API, is the
7+//! one [`ec_hw::HwEncoder::open`] picks.
98
109 use std::collections::VecDeque;
11-use std::os::fd::{AsFd, OwnedFd};
12-use std::rc::Rc;
10+use std::os::fd::{AsFd, BorrowedFd};
1311
14-use ec_hw::enc::{EncCodec, EncoderConfig, FrameMetadata, RateControlMode};
15-use ec_hw::{Encoder, H264Profile, I420, I420_16};
16-use ec_va::{PrimeLayer, PrimeObject, PrimeSurface};
12+use ec_hw::{
13+ Backend, DmaBufFormat, DmaBufPlane, DmaBufYuvFrame, EncCodec, EncodeInput, EncoderConfig,
14+ FrameMetadata, H264Profile, HwEncoder, I420, I420_16, RateControlMode,
15+};
1716
18-use engine::hw::{DmaFrame, VhDma};
17+use engine::hw::DmaFrame;
1918 use engine::hwproc::SeatRate;
2019
2120 /// `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");
2524
2625 /// One hardware encode session on `ec_hw`.
2726 pub(crate) struct EcEncSession {
28- display: Rc<ec_va::Display>,
29- encoder: Encoder,
27+ encoder: HwEncoder,
3028 /// Display size: what is encoded.
3129 width: usize,
3230 height: usize,
33- /// Macroblock- or block-aligned size the driver codes at.
34- coded: (u32, u32),
3531 timestamp: i64,
3632 /// Access units the encoder has finished but the caller has not taken yet,
3733 /// in encode order (which is display order: no B-frames).
3834 ready: VecDeque<Vec<u8>>,
3935 /// The access unit currently handed out, kept alive until the next call.
4036 out: Vec<u8>,
41- ten_bit: bool,
42- /// Imported decoder buffers, by the dma-buf inodes and layout they came as:
43- /// the decoder hands the same few surfaces out again and again, and a fresh
44- /// import costs the GPU a new mapping on its first use.
45- imports: VecDeque<(ImportKey, Rc<ec_va::va::Surface<ec_va::surface::PrimeImport>>)>,
4637 }
4738
48-type ImportKey = (Vec<u64>, VhDma);
49-
50-const IMPORTS_MAX: usize = 32;
51-
5239 /// The `open` arguments, for any of the three codecs.
5340 pub(crate) struct EcOpen {
5441 pub codec: EncCodec,
@@ -63,7 +50,7 @@ pub(crate) struct EcOpen {
6350 pub gop: Option<u32>,
6451 /// Colour description for the VUI as `(primaries, transfer, matrix, full)`.
6552 pub colour: Option<(u8, u8, u8, bool)>,
66- /// HEVC Main10: pictures go through [`EcEncSession::encode16`].
53+ /// HEVC Main10: pictures go through [`EcEncSession::encode16_owned`].
6754 pub ten_bit: bool,
6855 }
6956
@@ -122,20 +109,14 @@ impl EcEncSession {
122109 if ten_bit {
123110 config = config.ten_bit();
124111 }
125- let display = ec_va::open().ok()?;
126- let encoder = Encoder::new(&display, config).ok()?;
127- let coded = encoder.coded_size();
112+ let encoder = HwEncoder::open(config, None).ok()?;
128113 Some(Self {
129- display,
130114 encoder,
131115 width: width as usize,
132116 height: height as usize,
133- coded,
134117 timestamp: 0,
135118 ready: VecDeque::new(),
136- imports: VecDeque::new(),
137119 out: Vec::new(),
138- ten_bit,
139120 })
140121 }
141122
@@ -163,7 +144,11 @@ impl EcEncSession {
163144 bit_depth: 10,
164145 };
165146 let meta = self.meta(force_keyframe);
166- if let Some(coded) = self.encoder.submit_16(&picture, meta).map_err(|e| e.to_string())? {
147+ if let Some(coded) = self
148+ .encoder
149+ .submit(EncodeInput::I420_16(&picture), meta)
150+ .map_err(|e| e.to_string())?
151+ {
167152 self.ready.push_back(coded.data);
168153 }
169154 Ok(())
@@ -176,9 +161,13 @@ impl EcEncSession {
176161 Ok(())
177162 }
178163
179- /// The surface size the driver codes at, as the caller must describe it.
180- pub(crate) fn coded_size(&self) -> (u32, u32) {
181- self.coded
164+ /// The size a DMA-BUF picture must be described at, or `None` when the
165+ /// backend takes no DMA-BUF input (VA-API).
166+ pub(crate) fn coded_size(&self) -> Option<(u32, u32)> {
167+ match self.encoder.backend() {
168+ Backend::Vk => Some((self.width as u32, self.height as u32)),
169+ Backend::Va => None,
170+ }
182171 }
183172
184173 /// Codes one packed I420 picture (`y`, `u`, `v` at the session's size) and
@@ -203,7 +192,11 @@ impl EcEncSession {
203192 height: h as u32,
204193 };
205194 let meta = self.meta(force_keyframe);
206- if let Some(coded) = self.encoder.submit(&picture, meta).map_err(|e| e.to_string())? {
195+ if let Some(coded) = self
196+ .encoder
197+ .submit(EncodeInput::I420(&picture), meta)
198+ .map_err(|e| e.to_string())?
199+ {
207200 self.ready.push_back(coded.data);
208201 }
209202 Ok(())
@@ -211,55 +204,43 @@ impl EcEncSession {
211204
212205 /// Codes one picture the decoder left on the GPU, read in place.
213206 ///
214- /// The descriptors stay owned by `frame`: they are duplicated into the
215- /// imported surface, which owns its copies until it is dropped at the end
216- /// of this call.
207+ /// The descriptors stay owned by `frame`; the encoder duplicates them on import.
217208 pub(crate) fn encode_dma(&mut self, frame: &DmaFrame, force_keyframe: bool) -> Result<(), String> {
218- let inodes = frame
219- .fds
220- .iter()
221- .map(|fd| {
222- use std::os::unix::fs::MetadataExt;
223- Some(std::fs::File::from(fd.try_clone().ok()?).metadata().ok()?.ino())
224- })
225- .collect::<Option<Vec<u64>>>();
226- let key = inodes.map(|inodes| (inodes, frame.desc));
227- let cached = key
228- .as_ref()
229- .and_then(|key| self.imports.iter().find(|(k, _)| k == key))
230- .map(|(_, surface)| Rc::clone(surface));
231- let surface = match cached {
232- Some(surface) => surface,
233- None => {
234- let prime = prime_from_vhdma(&frame.desc, &frame.fds)?;
235- let surface = Rc::new(ec_va::import_prime(&self.display, &prime).map_err(|e| e.to_string())?);
236- if let Some(key) = key {
237- self.imports.push_back((key, Rc::clone(&surface)));
238- if self.imports.len() > IMPORTS_MAX {
239- self.imports.pop_front();
240- }
241- }
242- surface
243- }
209+ let format = match (frame.desc.fourcc, frame.fds.len()) {
210+ (FOURCC_NV12, 1 | 2) => DmaBufFormat::Nv12,
211+ (FOURCC_P010, 1 | 2) => DmaBufFormat::P010,
212+ _ => return Err("DMA-BUF is not an NV12 or P010 picture on the GPU".into()),
213+ };
214+ let fds: Vec<BorrowedFd> = frame.fds.iter().map(|fd| fd.as_fd()).collect();
215+ let desc = &frame.desc;
216+ let chroma_fd = if fds.len() == 2 { 1 } else { 0 };
217+ let input = DmaBufYuvFrame {
218+ fds: &fds,
219+ planes: [
220+ DmaBufPlane {
221+ fd: 0,
222+ offset: desc.offset[0],
223+ pitch: desc.stride[0],
224+ },
225+ DmaBufPlane {
226+ fd: chroma_fd,
227+ offset: desc.offset[1],
228+ pitch: desc.stride[1],
229+ },
230+ ],
231+ width: self.width as u32,
232+ height: self.height as u32,
233+ modifier: desc.modifier,
234+ format,
244235 };
245- let display = (self.width as u32, self.height as u32);
246236 let meta = self.meta(force_keyframe);
247- if self.ten_bit {
248237 if let Some(coded) = self
249238 .encoder
250- .submit_prime(surface, meta)
239+ .submit(EncodeInput::DmaBufYuv(&input), meta)
251240 .map_err(|e| e.to_string())?
252241 {
253242 self.ready.push_back(coded.data);
254243 }
255- } else {
256- self.flush()?;
257- let coded = self
258- .encoder
259- .encode_surface(&surface, display, meta)
260- .map_err(|e| e.to_string())?;
261- self.ready.push_back(coded.data);
262- }
263244 Ok(())
264245 }
265246
@@ -280,49 +261,3 @@ impl EcEncSession {
280261 Some(&self.out)
281262 }
282263 }
283-
284-/// Builds the PRIME descriptor for an NV12 or P010 picture the decoder holds.
285-///
286-/// Luma and chroma are either two objects (two descriptors) or one object
287-/// holding both at their own offsets, as the decoder's descriptor says.
288-fn prime_from_vhdma(desc: &VhDma, fds: &[OwnedFd]) -> Result<PrimeSurface, String> {
289- if fds.is_empty() || fds.len() > 2 || !matches!(desc.fourcc, FOURCC_NV12 | FOURCC_P010) {
290- return Err("DMA-BUF is not an NV12 or P010 picture on the GPU".into());
291- }
292- let (w, h) = (desc.coded_width, desc.coded_height);
293- let rows = [h, h / 2];
294- let two_objects = fds.len() == 2;
295- let mut objects = Vec::with_capacity(fds.len());
296- for fd in fds {
297- objects.push(PrimeObject {
298- fd: fd.as_fd().try_clone_to_owned().map_err(|e| e.to_string())?,
299- size: 0,
300- modifier: desc.modifier,
301- });
302- }
303- // The size each object must cover, luma rows then chroma rows.
304- for (plane, &plane_rows) in rows.iter().enumerate() {
305- let index = if two_objects { plane } else { 0 };
306- let end = desc.offset[plane] as u64 + u64::from(desc.stride[plane]) * u64::from(plane_rows);
307- let size = &mut objects[index].size;
308- *size = (*size).max(u32::try_from(end).map_err(|_| "DMA-BUF too large")?);
309- }
310- let layer = PrimeLayer {
311- drm_format: desc.fourcc,
312- planes: vec![
313- (0, desc.offset[0], desc.stride[0]),
314- (
315- if two_objects { 1 } else { 0 },
316- desc.offset[1],
317- desc.stride[1],
318- ),
319- ],
320- };
321- Ok(PrimeSurface {
322- fourcc: desc.fourcc,
323- width: w,
324- height: h,
325- objects,
326- layers: vec![layer],
327- })
328-}
crates/engine-hw/src/lib.rsmodified+78 -149
@@ -1,6 +1,6 @@
11 //! Hardware decode and encode, held in a child process. This library is the
22 //! whole world of the `hw-child` binary ([`child`]), the one process a video
3-//! driver is allowed to kill: VA-API decode (H.264, HEVC, VP9 and AV1), VP8
3+//! driver is allowed to kill: Vulkan Video or VA-API decode (H.264, HEVC, VP9 and AV1), VP8
44 //! decode on `ec-vp8` ([`vpx`], software, linked in), and the encode seats
55 //! (H.264, HEVC, and AV1 where the GPU has the entrypoint).
66 //!
@@ -18,11 +18,9 @@ mod vpx;
1818 use std::collections::VecDeque;
1919 use std::os::fd::OwnedFd;
2020 use std::path::Path;
21-use std::rc::Rc;
2221
23-use ec_hw::Frame;
2422 use ec_hw::enc::EncCodec as EcCodec;
25-use ec_va::caps::Profile;
23+use ec_hw::{CodecProfile, Direction, HwPicture};
2624 use enc_ec::{EcEncSession, EcOpen};
2725 use engine::demux::{Codec, Demuxer, VideoMeta};
2826 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 {
105103 }
106104
107105 struct Session {
108- decoder: ec_hw::Decoder,
109- /// The VA-API display the decoder's context and surfaces live on: kept
110- /// alive for as long as the session is.
111- _display: Rc<ec_va::Display>,
106+ decoder: ec_hw::HwDecoder,
112107 demuxer: Demuxer,
113108 meta: VhMeta,
114109 timestamp: i64,
@@ -145,20 +140,14 @@ struct Session {
145140 /// holds its surface out of the decoder's pool, so the decoder would write
146141 /// the next picture into the one an encoder is still reading unless this
147142 /// keeps the last [`DMA_HOLD`] of them alive.
148- held: VecDeque<Frame>,
149-}
150-
151-/// The VA-API display the decoders run on: the first render node that opens.
152-fn open_decode_display() -> Option<Rc<ec_va::Display>> {
153- ec_va::open().ok()
143+ held: VecDeque<HwPicture>,
154144 }
155145
156146 impl Session {
157- /// Assembles the VA-API half around a container that is already read --
147+ /// Assembles the hardware half around a container that is already read --
158148 /// [`OpenSession::open_at`] owns the read and routes VP8 away from here
159149 /// before any device is opened.
160150 fn opened(meta: VideoMeta, demuxer: Demuxer) -> Option<Self> {
161- let display = open_decode_display()?;
162151 let codec = match meta.codec {
163152 Codec::H264 => ec_hw::Codec::H264,
164153 Codec::Hevc => ec_hw::Codec::H265,
@@ -170,10 +159,9 @@ impl Session {
170159 // Never offered to VA-API: `decode::hw_decodes` refuses it first.
171160 Codec::Mpeg2 | Codec::ProRes | Codec::Dnxhd | Codec::Mjpeg | Codec::Dv | Codec::Mpeg4 | Codec::MsMpeg4 | Codec::Raw => return None,
172161 };
173- let decoder = ec_hw::Decoder::new(&display, codec).ok()?;
162+ let decoder = ec_hw::HwDecoder::open(codec).ok()?;
174163 Some(Self {
175164 decoder,
176- _display: display,
177165 demuxer,
178166 meta: VhMeta {
179167 width: meta.width,
@@ -246,7 +234,7 @@ impl Session {
246234 /// Pumps the decoder until one picture is ready. `Ok(false)` is clean EOF.
247235 fn pump(&mut self) -> Result<bool, String> {
248236 loop {
249- if let Some(frame) = self.decoder.next_frame() {
237+ if let Some(frame) = self.decoder.next_picture().map_err(|e| e.to_string())? {
250238 // One picture further along, shown or skipped past alike:
251239 // this is the only place [`Session::position`] walks.
252240 self.position += 1;
@@ -296,7 +284,7 @@ impl Session {
296284 /// Hands one decoded picture to the caller: as the buffer it was decoded
297285 /// into where that is what the caller asked for and the encoder on the
298286 /// other side can read it, and as read-back I420 everywhere else.
299- fn deliver(&mut self, frame: Frame) -> Result<(), String> {
287+ fn deliver(&mut self, frame: HwPicture) -> Result<(), String> {
300288 self.dma = None;
301289 if self.want.is_some()
302290 && let Some(dma) = self.export_dma(&frame)
@@ -320,68 +308,39 @@ impl Session {
320308 /// objects, the fourcc and both sizes it asked for. `None` for every other
321309 /// answer, and the caller then gets the pixels it always got rather than a
322310 /// failure.
323- fn export_dma(&self, frame: &Frame) -> Option<(VhDma, Vec<OwnedFd>)> {
311+ fn export_dma(&self, frame: &HwPicture) -> Option<(VhDma, Vec<OwnedFd>)> {
324312 let want = self.want?;
325- let (w, h) = frame.display_size;
326- if (w, h) != (want.width, want.height) {
327- return None;
328- }
329- let prime = frame.export_prime().ok()?;
330- // The driver describes the NV12 buffer as one layer per plane (R8 and
331- // GR88, each one plane into the same object), or as one composed layer
332- // holding both: either is the same two planes, in that order.
333- let planes: Vec<(u32, u32, u32)> = match prime.layers.as_slice() {
334- [layer] => layer.planes.clone(),
335- [luma, chroma] => {
336- let ([y], [uv]) = (luma.planes.as_slice(), chroma.planes.as_slice()) else {
313+ if (frame.width, frame.height) != (want.width, want.height) {
337314 return None;
338- };
339- vec![*y, *uv]
340315 }
341- _ => return None,
342- };
343- let [(obj0, off0, pitch0), (obj1, off1, pitch1)] = planes.as_slice() else {
344- return None;
345- };
346- let fits = prime.width == want.coded_width && prime.height == want.coded_height;
347- if prime.fourcc != want.fourcc
348- || !fits
349- || *obj0 != 0
350- || *obj1 > 1
351- || prime.objects.len() != *obj1 as usize + 1
316+ let pic = frame.export_dmabuf().ok()?;
317+ let [plane0, plane1] = pic.planes;
318+ if pic.fourcc != want.fourcc
319+ || pic.width < want.coded_width
320+ || pic.height < want.coded_height
321+ || plane0.fd != 0
322+ || plane1.fd > 1
323+ || pic.fds.len() != plane1.fd + 1
352324 {
353325 return None;
354326 }
355- let planes = [*obj0, *obj1];
356- let (offset, stride) = ([*off0, *off1], [*pitch0, *pitch1]);
357- // Whatever the driver says the two planes live in, said back to it
358- // unchanged on the import: radeonsi answers with an object per plane,
359- // other drivers with one for both, and neither is ours to reinterpret.
360- let modifier = prime.objects[0].modifier;
361- let mut objects = prime.objects.into_iter();
362- // Owned by the caller from here: they travel to the encoder with the
363- // descriptor, one per plane object.
364- let mut fds = vec![objects.next()?.fd];
365- if planes[1] == 1 {
366- fds.push(objects.next()?.fd);
367- }
368327 Some((
369328 VhDma {
370- fourcc: prime.fourcc,
371- modifier,
372- coded_width: prime.width,
373- coded_height: prime.height,
374- width: w,
375- height: h,
376- offset,
377- stride,
329+ fourcc: pic.fourcc,
330+ modifier: pic.modifier,
331+ coded_width: pic.width,
332+ coded_height: pic.height,
333+ width: frame.width,
334+ height: frame.height,
335+ offset: [plane0.offset, plane1.offset],
336+ stride: [plane0.pitch, plane1.pitch],
378337 },
379- fds,
338+ pic.fds,
380339 ))
381340 }
382341
383342 /// Copies a decoded picture into `self.out` as packed I420.
384- fn emit(&mut self, frame: &Frame) -> Result<(), String> {
343+ fn emit(&mut self, frame: &HwPicture) -> Result<(), String> {
385344 // The read-back goes through the driver's image copy (`vaGetImage`)
386345 // rather than a CPU map of the surface: on a discrete GPU that buffer
387346 // 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)
709668 }
710669 }
711670
712-/// One row of [`CAP_TABLE`]: the capability bit, its 8-bit and 10-bit decode profiles, and its encode profile.
713-type CapRow = (u32, &'static [Profile], &'static [Profile], Option<Profile>);
714-
715-/// What each codec needs of the driver before this plugin can claim it: the
716-/// 8-bit decode profiles, the 10-bit ones, and the profile the *encoder* here
717-/// would open -- `None` for the one this plugin has no encoder for at all, so a
718-/// GPU with a VP9 encode entrypoint is never reported as one edith can
719-/// reach. The encode profiles are the very ones the seats in [`enc_ec`] and
720-/// [`EncSession::open_seat`] ask for, which is what keeps this a description of the plugin rather than a
721-/// second opinion about it.
722-const CAP_TABLE: [CapRow; 4] = [
723- (
724- CAP_H264,
725- &[
726- Profile::H264ConstrainedBaseline,
727- Profile::H264Main,
728- Profile::H264High,
729- ],
730- &[],
731- Some(Profile::H264Main),
732- ),
671+/// This machine's decode and encode seats, as the hardware backends report
672+/// them. `None` when there are none at all, the same "software only" a missing
673+/// plugin means.
674+///
675+/// VP8 is the one bit asked of nobody: it is this plugin's own native seat
676+/// (`vpx`, `ec-vp8` linked in), lit unconditionally.
677+fn query_caps() -> Option<VhCaps> {
678+ let caps = ec_hw::capabilities();
679+ if caps.is_empty() {
680+ return None;
681+ }
682+ let decode = |profile: CodecProfile| {
683+ caps.iter()
684+ .any(|c| c.direction == Direction::Decode && c.profile == profile)
685+ };
686+ let encode = |profile: CodecProfile| {
687+ caps.iter()
688+ .any(|c| c.direction == Direction::Encode && c.profile == profile)
689+ };
690+ let h264_decode = caps
691+ .iter()
692+ .any(|c| c.direction == Direction::Decode && c.codec == ec_hw::Codec::H264);
693+ let h264_encode = caps
694+ .iter()
695+ .any(|c| c.direction == Direction::Encode && c.codec == ec_hw::Codec::H264);
696+ let table = [
697+ (CAP_H264, h264_decode, false, h264_encode),
733698 (
734699 CAP_HEVC,
735- &[Profile::HEVCMain],
736- &[Profile::HEVCMain10],
737- // 8-bit Main only: the encoder here opens Main whatever the source was,
738- // so a Main 10 entrypoint is a *decode* claim on this line and nothing
739- // more. Main 10 encode would be a second profile here and a 10-bit input
740- // buffer in `EncSession`, neither of which exists yet.
741- Some(Profile::HEVCMain),
700+ decode(CodecProfile::H265Main),
701+ decode(CodecProfile::H265Main10),
702+ encode(CodecProfile::H265Main),
742703 ),
743704 (
744705 CAP_VP9,
745- &[Profile::VP9Profile0],
746- &[Profile::VP9Profile2],
747- None,
706+ decode(CodecProfile::Vp9Profile0),
707+ decode(CodecProfile::Vp9Profile2),
708+ false,
748709 ),
749710 (
750711 CAP_AV1,
751- &[Profile::AV1Profile0],
752- // AV1 carries 8- and 10-bit in the same profile 0, so the profile bit
753- // is the same one and the P010 read-back is what decides.
754- &[Profile::AV1Profile0],
755- Some(Profile::AV1Profile0),
712+ decode(CodecProfile::Av1Main),
713+ decode(CodecProfile::Av1Main10),
714+ encode(CodecProfile::Av1Main),
756715 ),
757716 ];
758-
759-/// This machine's decode and encode seats, asked of the driver rather than
760-/// assumed: which profiles it has, which entrypoints each of those carries, and
761-/// whether a P010 image exists to read a 10-bit picture back through. Only
762-/// codecs this plugin actually implements can light up -- `CAP_TABLE` is that
763-/// half of the intersection.
764-///
765-/// VP8 is the one bit asked of nobody: it is this plugin's own native seat
766-/// (`vpx`, `ec-vp8` linked in), lit unconditionally -- no profile, no
767-/// entrypoint, no display, no library to load. It rides along only when the
768-/// display *is* answerable, because this symbol's shape says a displayless
769-/// machine has nothing to report at all; the decode path itself needs no
770-/// display for it ([`OpenSession::open_at`] routes VP8 before any device
771-/// opens).
772-///
773-/// `None` when there is no display to ask at all, which is the same "software
774-/// only" a missing plugin means.
775-fn query_caps() -> Option<VhCaps> {
776- use ec_va::caps::Entrypoint;
777- let display = open_decode_display()?;
778- let report = ec_va::CapReport::probe(&display).ok()?;
779- let p010 = report.image_formats.contains(&VA_FOURCC_P010);
780- let decodes = |list: &[Profile]| list.iter().any(|&p| report.supports(p, Entrypoint::VLD));
781- let mut caps = VhCaps::default();
782- for (bit, eight, ten, encode) in CAP_TABLE {
783- if decodes(eight) {
784- caps.decode |= bit;
785- }
786- if p010 && decodes(ten) {
787- caps.decode_10bit |= bit;
788- }
789- // Both entrypoints, exactly as the encoder's own open takes either.
790- if encode.is_some_and(|p| {
791- report.supports(p, Entrypoint::EncSlice) || report.supports(p, Entrypoint::EncSliceLP)
792- }) {
793- caps.encode |= bit;
794- }
795- }
796- // The plugin's own software decoder, on its own account rather than the
797- // driver's -- the plugin's capability, never a GPU feat. Native now, so
798- // the bit has no "when it loads" condition left: it lights on every
799- // machine this plugin runs on.
800- caps.decode |= CAP_VP8;
801- Some(caps)
717+ let mut out = VhCaps::default();
718+ for (bit, eight, ten, enc) in table {
719+ if eight {
720+ out.decode |= bit;
721+ }
722+ if ten {
723+ out.decode_10bit |= bit;
724+ }
725+ if enc {
726+ out.encode |= bit;
727+ }
728+ }
729+ out.decode |= CAP_VP8;
730+ Some(out)
802731 }
803732
804733 /// How many pictures a group of them holds -- the low-delay predictor's
crates/engine/src/export.rsmodified+1 -1
@@ -1411,7 +1411,7 @@ fn hevc_irap(au: &[u8]) -> bool {
14111411
14121412 /// What a hardware encode is called wherever one is named -- the card's line
14131413 /// before the export and the progress line during it.
1414-const HW_LABEL: &str = "HW encode (VA-API)";
1414+const HW_LABEL: &str = "HW encode (GPU)";
14151415
14161416 /// ...and what a card says instead where [`EncoderSeat::Hardware`] was picked
14171417 /// and there is no seat: the export's own refusal in the width of a card row,
crates/mcp/src/tools/export.rsmodified+2 -2
@@ -2381,7 +2381,7 @@ mod tests {
23812381
23822382 #[test]
23832383 fn picture_label_names_the_engine_seat_then_the_plan_and_skips_audio_only() {
2384- let measured = Some("HW encode (VA-API) · AAC · SW encode (ec-aac)".to_string());
2384+ let measured = Some("HW encode (GPU) · AAC · SW encode (ec-aac)".to_string());
23852385 assert_eq!(picture_label(measured, "SW encode (rav1e)", Format::Mp4), " · video: H.264 (hardware)");
23862386 assert_eq!(picture_label(None, "SW encode (ec-h264)", Format::Mp4), " · video: H.264 (software)");
23872387 assert_eq!(picture_label(Some("copy · AAC".into()), "SW encode (ec-h264)", Format::Mp4), " · video: H.264 (copy)");
@@ -2404,7 +2404,7 @@ mod tests {
24042404 assert_eq!(av_words(Format::Wav, "", "PCM · SW (hound)"), "audio: PCM, container: WAV");
24052405 assert_eq!(av_words(Format::Gif, "", ""), "no sound, container: GIF");
24062406 assert_eq!(av_words(Format::PngSequence, "", ""), "no sound, container: PNG folder");
2407- assert_eq!(measured_sound(Some("HW encode (VA-API) · AAC · SW encode (ec-aac)")).as_deref(), Some("AAC"));
2407+ assert_eq!(measured_sound(Some("HW encode (GPU) · AAC · SW encode (ec-aac)")).as_deref(), Some("AAC"));
24082408 assert_eq!(measured_sound(Some("SW encode (ec-h264)")), None);
24092409 assert_eq!(measured_sound(None), None);
24102410 assert_eq!(plain_audio("no sound to write"), "none");