From bacbe9fc5d63f51e658059786336e1139f827949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 13 Aug 2026 07:53:26 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(export):=20the=20GPU=20takes?= =?UTF-8?q?=20the=20HEVC=20export,=20and=20it=20is=20the=20same=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `HwEncoder::open_hevc` on the plugin's new symbol, and `hw_seat`'s HEVC arm goes from a flat `None` -- "the plugin has no HEVC encoder" was true and is not any more -- to a real probe. Unlike the AV1 seat it is **not** behind an opt-in, and what makes that safe is that both HEVC seats code intra-only: preferring the GPU changes how long an export takes and not what comes out of it, which is the whole reason AV1's `VE_HW_AV1` exists and does not apply here. `Enc::HevcHw` beside `Enc::Hevc`, and every unit it hands back is marked a sync point, because that is this encoder's configuration rather than a driver's choice. Falling back is silent and covers all of it: no entrypoint, a plugin too old to carry the symbol, a picture under the driver's 384x384 floor, `VE_SW_ENC=1`, or the export card's own "software only" -- `hw_seat` answers `None` before it probes for the last two, as it always has. The caps line stops saying HEVC is decode-only on this GPU. Measured on this box, both against the software seat's 4.30 fps at 1080p: 1440p at 74 fps, 1080p at 117 fps, output decoding frame for frame. --- crates/engine/src/caps.rs | 13 ++++++------ crates/engine/src/export.rs | 40 ++++++++++++++++++++++++++++--------- crates/engine/src/hw.rs | 26 ++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 15 deletions(-) diff --git a/crates/engine/src/caps.rs b/crates/engine/src/caps.rs index 164581c..858e16a 100644 --- a/crates/engine/src/caps.rs +++ b/crates/engine/src/caps.rs @@ -104,18 +104,19 @@ mod tests { assert!(hw_line(None).starts_with("none —")); // A driver that answers with nothing is its own sentence. assert!(hw_line(Some(VhCaps::default())).starts_with("none —")); - // This project's own GPU as `vainfo` lists it: H.264 both ways, HEVC - // and VP9 decode with their 10-bit profiles, AV1 both ways. HEVC has a - // VA encode entrypoint here and is *not* an encode seat: the plugin has - // no HEVC encoder, so the line must not offer one. + // This project's own GPU as `vainfo` lists it: H.264, HEVC and AV1 both + // ways, VP9 decode only, and the 10-bit profiles on three of the four. + // HEVC is an encode seat here as of the plugin's `vh_enc_hevc_open` -- + // the 10-bit note beside it stays a *decode* claim, that seat coding + // 8-bit Main whatever the source was. let radeonsi = VhCaps { decode: CAP_H264 | CAP_HEVC | CAP_VP9 | CAP_AV1, - encode: CAP_H264 | CAP_AV1, + encode: CAP_H264 | CAP_HEVC | CAP_AV1, decode_10bit: CAP_HEVC | CAP_VP9 | CAP_AV1, }; assert_eq!( hw_line(Some(radeonsi)), - "H.264 dec+enc · HEVC dec (10-bit) · VP9 dec (10-bit) · AV1 dec+enc (10-bit)" + "H.264 dec+enc · HEVC dec+enc (10-bit) · VP9 dec (10-bit) · AV1 dec+enc (10-bit)" ); // A codec the driver has neither seat for is left out rather than // listed as a refusal: this line is what the machine *can* do. diff --git a/crates/engine/src/export.rs b/crates/engine/src/export.rs index 8f9087d..8bc6ffe 100644 --- a/crates/engine/src/export.rs +++ b/crates/engine/src/export.rs @@ -496,11 +496,15 @@ fn hw_seat(meta: &VideoMeta, settings: &ExportSettings) -> Option { let (fps_num, fps_den) = crate::mux::frame_timing(meta.frame_rate).ok()?; let bitrate = bitrate_of(meta, settings); match settings.format { - // The HEVC pair is software only, and not for want of a GPU: the plugin - // has no HEVC *encode* entry point at all (`hw::HwEncoder` opens H.264 - // and AV1), so there is no seat to probe. Said here rather than left to - // a failed open, which would read as a driver refusal. - format if format.is_hevc() => None, + // Both HEVC formats sit on the plugin's HEVC seat, and it is the + // default: what it codes is intra-only, the very file the software seat + // writes, so preferring the GPU changes how long an export takes and + // not what comes out of it. `None` here is the plugin's own "no" -- + // no entrypoint, or a picture under the driver's 384x384 floor -- and + // the software intra encoder takes the file. + format if format.is_hevc() => { + HwEncoder::open_hevc(meta.width, meta.height, fps_num, fps_den, bitrate) + } // Opt-in only, for the reason [`Enc::open_av1`] states in full. Both // AV1 formats sit on it: the container is not the encoder's business. format if format.is_av1() && !forced("VE_HW_AV1") => None, @@ -2627,6 +2631,9 @@ enum Enc { }, /// AV1 on the GPU, through the same plugin the H.264 seat uses. Av1Hw(HwEncoder), + /// HEVC on the GPU, through that same plugin -- and intra-only there too, + /// so this and [`Enc::Hevc`] write the same kind of file. + HevcHw(HwEncoder), Av1Sw { context: rav1e::Context, /// Temporal units the encoder has finished but the caller has not @@ -2687,6 +2694,7 @@ impl Enc { Self::Sw { .. } => video_label(Format::Mp4, false), Self::Av1Hw(_) => video_label(Format::Av1, true), Self::Av1Sw { .. } => video_label(Format::Av1, false), + Self::HevcHw(_) => video_label(Format::Hevc, true), Self::Hevc(_) => video_label(Format::Hevc, false), } } @@ -2810,11 +2818,14 @@ impl Enc { }) } - /// The intra HEVC seat, software and frame-parallel. There is no hardware - /// half: the plugin encodes H.264 and AV1 and nothing else, which - /// [`hw_seat`] says by refusing to probe one. + /// The HEVC pair: the plugin's VA-API seat where the GPU has one, and the + /// frame-parallel software encoder everywhere else -- below the driver's + /// 384x384 floor, on a plugin too old to carry the symbol, on a GPU with no + /// HEVC encode entrypoint. Silent either way, because both write the same + /// kind of file. /// - /// **Intra-only, deliberately.** The vendored encoder's inter modes code + /// **Intra-only, deliberately, on both seats.** The software encoder's inter + /// modes code /// 1080p at 0.81 fps across 12 cores (measured 2026-08-11) -- a minute of /// timeline in half an hour, which is not an export anybody waits for -- /// while the intra path does 4.30 fps on the same picture and the same @@ -2839,6 +2850,10 @@ impl Enc { ) .into()); } + if let Some(hw) = hw_seat(meta, settings) { + eprintln!("export encoder: hardware HEVC intra (VA-API plugin)"); + return Ok(Self::HevcHw(hw)); + } let (width, height) = ( (meta.width as usize).next_multiple_of(CTB), (meta.height as usize).next_multiple_of(CTB), @@ -2900,6 +2915,12 @@ impl Enc { collect_av1(context, ready)?; Ok(pop_av1(ready, au)) } + // Every unit this seat hands back is an IDR carrying its own + // parameter sets (the plugin codes HEVC intra-only), so every one of + // them is a sync point -- said as a constant rather than parsed back + // out of the bitstream, because it is this encoder's configuration + // and not a driver's choice. + Self::HevcHw(hw) => Ok(hw.encode(y, u, v, width, height, true)?.map(|au| (au, true))), Self::Hevc(hevc) => { hevc.pending.push(pad_to_ctb( y, @@ -2956,6 +2977,7 @@ impl Enc { } Ok(pop_av1(ready, au)) } + Self::HevcHw(hw) => Ok(hw.drain()?.map(|au| (au, true))), Self::Hevc(hevc) => { // The tail batch: fewer frames than lanes, coded on as many // cores as there are frames left. diff --git a/crates/engine/src/hw.rs b/crates/engine/src/hw.rs index e1a465e..79852bf 100644 --- a/crates/engine/src/hw.rs +++ b/crates/engine/src/hw.rs @@ -259,6 +259,9 @@ struct EncPlugin { /// plugin keeps one session type for both codecs, so the codec is decided /// once, at the open, exactly as the H.264 seat's parameters are. open_av1: Option *mut c_void>, + /// The HEVC seat, missing from an older plugin for the same reason and at + /// the same cost: an HEVC export then runs on the software intra encoder. + open_hevc: Option *mut c_void>, frame: unsafe extern "C" fn(*mut c_void, *const VhFrame, i32, *mut *const u8, *mut usize) -> i32, drain: unsafe extern "C" fn(*mut c_void, *mut *const u8, *mut usize) -> i32, @@ -285,6 +288,7 @@ fn load_enc() -> Option { Some(EncPlugin { open: *lib.get(b"vh_enc_open\0").ok()?, open_av1: lib.get(b"vh_enc_av1_open\0").ok().map(|s| *s), + open_hevc: lib.get(b"vh_enc_hevc_open\0").ok().map(|s| *s), frame: *lib.get(b"vh_enc_frame\0").ok()?, drain: *lib.get(b"vh_enc_drain\0").ok()?, close: *lib.get(b"vh_enc_close\0").ok()?, @@ -345,6 +349,28 @@ impl HwEncoder { Self::opened(plugin, open, width, height, fps_num, fps_den, bitrate) } + /// The same, coding HEVC. Unlike the AV1 seat this is **not** behind an + /// opt-in: it is the default for an HEVC export, and what makes that safe is + /// that the pictures it codes are intra-only, which is the same file the + /// software seat writes ([`crate::export::Enc::open_hevc`]) and not the + /// GPU-resetting inter path AV1's opt-in exists for. + /// + /// `None` on everything [`HwEncoder::open`] answers `None` to, on a plugin + /// too old to export the symbol, on a GPU with no HEVC encode entrypoint, + /// and below 384x384 -- the driver's own floor, stated in the plugin. The + /// caller then takes the software intra encoder without a word about it. + pub fn open_hevc( + width: u32, + height: u32, + fps_num: u32, + fps_den: u32, + bitrate: u64, + ) -> Option { + let plugin = enc_plugin()?; + let open = plugin.open_hevc?; + Self::opened(plugin, open, width, height, fps_num, fps_den, bitrate) + } + /// The null check both opens share, which is the plugin's whole way of /// saying "no". fn opened(