The GPU takes the HEVC export, and it is the same file
Browse files at this commitbacbe9fc5d63f51e658059786336e1139f827949Parent: 76787eb- feat
- the GPU takes the HEVC export, and it is the same file
3 changed files +64 -15
- crates/engine/src/caps.rs +7 -6
- crates/engine/src/export.rs +31 -9
- crates/engine/src/hw.rs +26 -0
crates/engine/src/caps.rsmodified+7 -6
| @@ -104,18 +104,19 @@ mod tests { | |||
| 104 | assert!(hw_line(None).starts_with("none —")); | 104 | assert!(hw_line(None).starts_with("none —")); |
| 105 | // A driver that answers with nothing is its own sentence. | 105 | // A driver that answers with nothing is its own sentence. |
| 106 | assert!(hw_line(Some(VhCaps::default())).starts_with("none —")); | 106 | assert!(hw_line(Some(VhCaps::default())).starts_with("none —")); |
| 107 | - // This project's own GPU as `vainfo` lists it: H.264 both ways, HEVC | 107 | + // This project's own GPU as `vainfo` lists it: H.264, HEVC and AV1 both |
| 108 | - // and VP9 decode with their 10-bit profiles, AV1 both ways. HEVC has a | 108 | + // ways, VP9 decode only, and the 10-bit profiles on three of the four. |
| 109 | - // VA encode entrypoint here and is *not* an encode seat: the plugin has | 109 | + // HEVC is an encode seat here as of the plugin's `vh_enc_hevc_open` -- |
| 110 | - // no HEVC encoder, so the line must not offer one. | 110 | + // the 10-bit note beside it stays a *decode* claim, that seat coding |
| 111 | + // 8-bit Main whatever the source was. | ||
| 111 | let radeonsi = VhCaps { | 112 | let radeonsi = VhCaps { |
| 112 | decode: CAP_H264 | CAP_HEVC | CAP_VP9 | CAP_AV1, | 113 | decode: CAP_H264 | CAP_HEVC | CAP_VP9 | CAP_AV1, |
| 113 | - encode: CAP_H264 | CAP_AV1, | 114 | + encode: CAP_H264 | CAP_HEVC | CAP_AV1, |
| 114 | decode_10bit: CAP_HEVC | CAP_VP9 | CAP_AV1, | 115 | decode_10bit: CAP_HEVC | CAP_VP9 | CAP_AV1, |
| 115 | }; | 116 | }; |
| 116 | assert_eq!( | 117 | assert_eq!( |
| 117 | hw_line(Some(radeonsi)), | 118 | hw_line(Some(radeonsi)), |
| 118 | - "H.264 dec+enc · HEVC dec (10-bit) · VP9 dec (10-bit) · AV1 dec+enc (10-bit)" | 119 | + "H.264 dec+enc · HEVC dec+enc (10-bit) · VP9 dec (10-bit) · AV1 dec+enc (10-bit)" |
| 119 | ); | 120 | ); |
| 120 | // A codec the driver has neither seat for is left out rather than | 121 | // A codec the driver has neither seat for is left out rather than |
| 121 | // listed as a refusal: this line is what the machine *can* do. | 122 | // listed as a refusal: this line is what the machine *can* do. |
crates/engine/src/export.rsmodified+31 -9
| @@ -496,11 +496,15 @@ fn hw_seat(meta: &VideoMeta, settings: &ExportSettings) -> Option<HwEncoder> { | |||
| 496 | let (fps_num, fps_den) = crate::mux::frame_timing(meta.frame_rate).ok()?; | 496 | let (fps_num, fps_den) = crate::mux::frame_timing(meta.frame_rate).ok()?; |
| 497 | let bitrate = bitrate_of(meta, settings); | 497 | let bitrate = bitrate_of(meta, settings); |
| 498 | match settings.format { | 498 | match settings.format { |
| 499 | - // The HEVC pair is software only, and not for want of a GPU: the plugin | 499 | + // Both HEVC formats sit on the plugin's HEVC seat, and it is the |
| 500 | - // has no HEVC *encode* entry point at all (`hw::HwEncoder` opens H.264 | 500 | + // default: what it codes is intra-only, the very file the software seat |
| 501 | - // and AV1), so there is no seat to probe. Said here rather than left to | 501 | + // writes, so preferring the GPU changes how long an export takes and |
| 502 | - // a failed open, which would read as a driver refusal. | 502 | + // not what comes out of it. `None` here is the plugin's own "no" -- |
| 503 | - format if format.is_hevc() => None, | 503 | + // no entrypoint, or a picture under the driver's 384x384 floor -- and |
| 504 | + // the software intra encoder takes the file. | ||
| 505 | + format if format.is_hevc() => { | ||
| 506 | + HwEncoder::open_hevc(meta.width, meta.height, fps_num, fps_den, bitrate) | ||
| 507 | + } | ||
| 504 | // Opt-in only, for the reason [`Enc::open_av1`] states in full. Both | 508 | // Opt-in only, for the reason [`Enc::open_av1`] states in full. Both |
| 505 | // AV1 formats sit on it: the container is not the encoder's business. | 509 | // AV1 formats sit on it: the container is not the encoder's business. |
| 506 | format if format.is_av1() && !forced("VE_HW_AV1") => None, | 510 | format if format.is_av1() && !forced("VE_HW_AV1") => None, |
| @@ -2627,6 +2631,9 @@ enum Enc { | |||
| 2627 | }, | 2631 | }, |
| 2628 | /// AV1 on the GPU, through the same plugin the H.264 seat uses. | 2632 | /// AV1 on the GPU, through the same plugin the H.264 seat uses. |
| 2629 | Av1Hw(HwEncoder), | 2633 | Av1Hw(HwEncoder), |
| 2634 | + /// HEVC on the GPU, through that same plugin -- and intra-only there too, | ||
| 2635 | + /// so this and [`Enc::Hevc`] write the same kind of file. | ||
| 2636 | + HevcHw(HwEncoder), | ||
| 2630 | Av1Sw { | 2637 | Av1Sw { |
| 2631 | context: rav1e::Context<u8>, | 2638 | context: rav1e::Context<u8>, |
| 2632 | /// Temporal units the encoder has finished but the caller has not | 2639 | /// Temporal units the encoder has finished but the caller has not |
| @@ -2687,6 +2694,7 @@ impl Enc { | |||
| 2687 | Self::Sw { .. } => video_label(Format::Mp4, false), | 2694 | Self::Sw { .. } => video_label(Format::Mp4, false), |
| 2688 | Self::Av1Hw(_) => video_label(Format::Av1, true), | 2695 | Self::Av1Hw(_) => video_label(Format::Av1, true), |
| 2689 | Self::Av1Sw { .. } => video_label(Format::Av1, false), | 2696 | Self::Av1Sw { .. } => video_label(Format::Av1, false), |
| 2697 | + Self::HevcHw(_) => video_label(Format::Hevc, true), | ||
| 2690 | Self::Hevc(_) => video_label(Format::Hevc, false), | 2698 | Self::Hevc(_) => video_label(Format::Hevc, false), |
| 2691 | } | 2699 | } |
| 2692 | } | 2700 | } |
| @@ -2810,11 +2818,14 @@ impl Enc { | |||
| 2810 | }) | 2818 | }) |
| 2811 | } | 2819 | } |
| 2812 | 2820 | ||
| 2813 | - /// The intra HEVC seat, software and frame-parallel. There is no hardware | 2821 | + /// The HEVC pair: the plugin's VA-API seat where the GPU has one, and the |
| 2814 | - /// half: the plugin encodes H.264 and AV1 and nothing else, which | 2822 | + /// frame-parallel software encoder everywhere else -- below the driver's |
| 2815 | - /// [`hw_seat`] says by refusing to probe one. | 2823 | + /// 384x384 floor, on a plugin too old to carry the symbol, on a GPU with no |
| 2824 | + /// HEVC encode entrypoint. Silent either way, because both write the same | ||
| 2825 | + /// kind of file. | ||
| 2816 | /// | 2826 | /// |
| 2817 | - /// **Intra-only, deliberately.** The vendored encoder's inter modes code | 2827 | + /// **Intra-only, deliberately, on both seats.** The software encoder's inter |
| 2828 | + /// modes code | ||
| 2818 | /// 1080p at 0.81 fps across 12 cores (measured 2026-08-11) -- a minute of | 2829 | /// 1080p at 0.81 fps across 12 cores (measured 2026-08-11) -- a minute of |
| 2819 | /// timeline in half an hour, which is not an export anybody waits for -- | 2830 | /// timeline in half an hour, which is not an export anybody waits for -- |
| 2820 | /// while the intra path does 4.30 fps on the same picture and the same | 2831 | /// while the intra path does 4.30 fps on the same picture and the same |
| @@ -2839,6 +2850,10 @@ impl Enc { | |||
| 2839 | ) | 2850 | ) |
| 2840 | .into()); | 2851 | .into()); |
| 2841 | } | 2852 | } |
| 2853 | + if let Some(hw) = hw_seat(meta, settings) { | ||
| 2854 | + eprintln!("export encoder: hardware HEVC intra (VA-API plugin)"); | ||
| 2855 | + return Ok(Self::HevcHw(hw)); | ||
| 2856 | + } | ||
| 2842 | let (width, height) = ( | 2857 | let (width, height) = ( |
| 2843 | (meta.width as usize).next_multiple_of(CTB), | 2858 | (meta.width as usize).next_multiple_of(CTB), |
| 2844 | (meta.height as usize).next_multiple_of(CTB), | 2859 | (meta.height as usize).next_multiple_of(CTB), |
| @@ -2900,6 +2915,12 @@ impl Enc { | |||
| 2900 | collect_av1(context, ready)?; | 2915 | collect_av1(context, ready)?; |
| 2901 | Ok(pop_av1(ready, au)) | 2916 | Ok(pop_av1(ready, au)) |
| 2902 | } | 2917 | } |
| 2918 | + // Every unit this seat hands back is an IDR carrying its own | ||
| 2919 | + // parameter sets (the plugin codes HEVC intra-only), so every one of | ||
| 2920 | + // them is a sync point -- said as a constant rather than parsed back | ||
| 2921 | + // out of the bitstream, because it is this encoder's configuration | ||
| 2922 | + // and not a driver's choice. | ||
| 2923 | + Self::HevcHw(hw) => Ok(hw.encode(y, u, v, width, height, true)?.map(|au| (au, true))), | ||
| 2903 | Self::Hevc(hevc) => { | 2924 | Self::Hevc(hevc) => { |
| 2904 | hevc.pending.push(pad_to_ctb( | 2925 | hevc.pending.push(pad_to_ctb( |
| 2905 | y, | 2926 | y, |
| @@ -2956,6 +2977,7 @@ impl Enc { | |||
| 2956 | } | 2977 | } |
| 2957 | Ok(pop_av1(ready, au)) | 2978 | Ok(pop_av1(ready, au)) |
| 2958 | } | 2979 | } |
| 2980 | + Self::HevcHw(hw) => Ok(hw.drain()?.map(|au| (au, true))), | ||
| 2959 | Self::Hevc(hevc) => { | 2981 | Self::Hevc(hevc) => { |
| 2960 | // The tail batch: fewer frames than lanes, coded on as many | 2982 | // The tail batch: fewer frames than lanes, coded on as many |
| 2961 | // cores as there are frames left. | 2983 | // cores as there are frames left. |
crates/engine/src/hw.rsmodified+26 -0
| @@ -259,6 +259,9 @@ struct EncPlugin { | |||
| 259 | /// plugin keeps one session type for both codecs, so the codec is decided | 259 | /// plugin keeps one session type for both codecs, so the codec is decided |
| 260 | /// once, at the open, exactly as the H.264 seat's parameters are. | 260 | /// once, at the open, exactly as the H.264 seat's parameters are. |
| 261 | open_av1: Option<extern "C" fn(u32, u32, u32, u32, u64) -> *mut c_void>, | 261 | open_av1: Option<extern "C" fn(u32, u32, u32, u32, u64) -> *mut c_void>, |
| 262 | + /// The HEVC seat, missing from an older plugin for the same reason and at | ||
| 263 | + /// the same cost: an HEVC export then runs on the software intra encoder. | ||
| 264 | + open_hevc: Option<extern "C" fn(u32, u32, u32, u32, u64) -> *mut c_void>, | ||
| 262 | frame: | 265 | frame: |
| 263 | unsafe extern "C" fn(*mut c_void, *const VhFrame, i32, *mut *const u8, *mut usize) -> i32, | 266 | unsafe extern "C" fn(*mut c_void, *const VhFrame, i32, *mut *const u8, *mut usize) -> i32, |
| 264 | drain: unsafe extern "C" fn(*mut c_void, *mut *const u8, *mut usize) -> i32, | 267 | drain: unsafe extern "C" fn(*mut c_void, *mut *const u8, *mut usize) -> i32, |
| @@ -285,6 +288,7 @@ fn load_enc() -> Option<EncPlugin> { | |||
| 285 | Some(EncPlugin { | 288 | Some(EncPlugin { |
| 286 | open: *lib.get(b"vh_enc_open\0").ok()?, | 289 | open: *lib.get(b"vh_enc_open\0").ok()?, |
| 287 | open_av1: lib.get(b"vh_enc_av1_open\0").ok().map(|s| *s), | 290 | open_av1: lib.get(b"vh_enc_av1_open\0").ok().map(|s| *s), |
| 291 | + open_hevc: lib.get(b"vh_enc_hevc_open\0").ok().map(|s| *s), | ||
| 288 | frame: *lib.get(b"vh_enc_frame\0").ok()?, | 292 | frame: *lib.get(b"vh_enc_frame\0").ok()?, |
| 289 | drain: *lib.get(b"vh_enc_drain\0").ok()?, | 293 | drain: *lib.get(b"vh_enc_drain\0").ok()?, |
| 290 | close: *lib.get(b"vh_enc_close\0").ok()?, | 294 | close: *lib.get(b"vh_enc_close\0").ok()?, |
| @@ -345,6 +349,28 @@ impl HwEncoder { | |||
| 345 | Self::opened(plugin, open, width, height, fps_num, fps_den, bitrate) | 349 | Self::opened(plugin, open, width, height, fps_num, fps_den, bitrate) |
| 346 | } | 350 | } |
| 347 | 351 | ||
| 352 | + /// The same, coding HEVC. Unlike the AV1 seat this is **not** behind an | ||
| 353 | + /// opt-in: it is the default for an HEVC export, and what makes that safe is | ||
| 354 | + /// that the pictures it codes are intra-only, which is the same file the | ||
| 355 | + /// software seat writes ([`crate::export::Enc::open_hevc`]) and not the | ||
| 356 | + /// GPU-resetting inter path AV1's opt-in exists for. | ||
| 357 | + /// | ||
| 358 | + /// `None` on everything [`HwEncoder::open`] answers `None` to, on a plugin | ||
| 359 | + /// too old to export the symbol, on a GPU with no HEVC encode entrypoint, | ||
| 360 | + /// and below 384x384 -- the driver's own floor, stated in the plugin. The | ||
| 361 | + /// caller then takes the software intra encoder without a word about it. | ||
| 362 | + pub fn open_hevc( | ||
| 363 | + width: u32, | ||
| 364 | + height: u32, | ||
| 365 | + fps_num: u32, | ||
| 366 | + fps_den: u32, | ||
| 367 | + bitrate: u64, | ||
| 368 | + ) -> Option<Self> { | ||
| 369 | + let plugin = enc_plugin()?; | ||
| 370 | + let open = plugin.open_hevc?; | ||
| 371 | + Self::opened(plugin, open, width, height, fps_num, fps_den, bitrate) | ||
| 372 | + } | ||
| 373 | + | ||
| 348 | /// The null check both opens share, which is the plugin's whole way of | 374 | /// The null check both opens share, which is the plugin's whole way of |
| 349 | /// saying "no". | 375 | /// saying "no". |
| 350 | fn opened( | 376 | fn opened( |