From 8af23f053368b35d3fe825e8161c9dd9d58a6c9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 25 Nov 2026 22:48:14 +0300 Subject: [PATCH] ec-hw: Vk Unsupported falls back to VA everywhere; VP9/AV1 refuse below minCodedExtent; VA checks real picture size against driver minimum --- crates/ec-hw/src/dec/mod.rs | 5 +++-- crates/ec-hw/src/error.rs | 1 + crates/ec-hw/src/vkdec264.rs | 11 ++--------- shims/vk-video-ffi/src/av1_decode.rs | 15 +++++++++++++++ shims/vk-video-ffi/src/vp9_decode.rs | 15 +++++++++++++++ 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/crates/ec-hw/src/dec/mod.rs b/crates/ec-hw/src/dec/mod.rs index bf57c837..9ffa7058 100644 --- a/crates/ec-hw/src/dec/mod.rs +++ b/crates/ec-hw/src/dec/mod.rs @@ -322,11 +322,12 @@ impl Session { } let (w, h) = coded_size; + let (dw, dh) = display_size; if let Some(surfaces) = &entry.surfaces - && !surfaces.allows(w, h) + && !(surfaces.allows(w, h) && surfaces.allows(dw.max(1), dh.max(1))) { return Err(Error::unsupported( - format!("{w}x{h} {profile:?} decode"), + format!("{dw}x{dh} {profile:?} decode"), format!( "the driver accepts {:?}..{:?} x {:?}..{:?}", surfaces.min_width, diff --git a/crates/ec-hw/src/error.rs b/crates/ec-hw/src/error.rs index 051a720a..7318bf43 100644 --- a/crates/ec-hw/src/error.rs +++ b/crates/ec-hw/src/error.rs @@ -92,6 +92,7 @@ impl From for Error { crate::reset::report_gpu_reset(); Error::hw_reset(format!("Vulkan device lost in {call}")) } + ec_vk::Error::Unsupported(why) => Error::unsupported("Vulkan Video", why), other => Error::Vk(other.to_string()), } } diff --git a/crates/ec-hw/src/vkdec264.rs b/crates/ec-hw/src/vkdec264.rs index 83dc47bf..ce991234 100644 --- a/crates/ec-hw/src/vkdec264.rs +++ b/crates/ec-hw/src/vkdec264.rs @@ -262,7 +262,7 @@ impl VkH264Decoder { chroma_format_idc: chroma, }, ) - .map_err(refused)?; + ?; let ring = Ring::new(h264.ring_len()); self.session = Some(Session { h264: Rc::new(RefCell::new(h264)), @@ -349,7 +349,7 @@ impl VkH264Decoder { refs: &refs, slices: &slices, }) - .map_err(refused)?; + ?; let (left, _, top, _) = sps.crop; session .h264 @@ -410,13 +410,6 @@ impl VkH264Decoder { } } -fn refused(e: ec_vk::Error) -> Error { - match e { - ec_vk::Error::Unsupported(why) => Error::unsupported("Vulkan Video H.264 decode", why), - other => other.into(), - } -} - fn field_pocs(poc: i32, delta_bottom: i32) -> [i32; 2] { [poc - delta_bottom.min(0), poc + delta_bottom.max(0)] } diff --git a/shims/vk-video-ffi/src/av1_decode.rs b/shims/vk-video-ffi/src/av1_decode.rs index dc009b4e..e6d4d2b2 100644 --- a/shims/vk-video-ffi/src/av1_decode.rs +++ b/shims/vk-video-ffi/src/av1_decode.rs @@ -463,6 +463,7 @@ pub struct Av1DecodePicture<'a> { struct Caps { std_header_version: vk::ExtensionProperties, + min_extent: vk::Extent2D, max_extent: vk::Extent2D, size_align: u64, max_dpb_slots: u32, @@ -500,6 +501,7 @@ pub struct Av1DecodeSession { dec: Decoder, sequence: Option, bit_depth: u8, + min_extent: vk::Extent2D, } impl Av1DecodeSession { @@ -530,6 +532,12 @@ impl Av1DecodeSession { let height = align(cfg.max_height, 16); let profile = Profile::new(cfg.bit_depth); let caps = query_caps(gpu, &profile.info)?; + if cfg.max_width < caps.min_extent.width || cfg.max_height < caps.min_extent.height { + return Err(Error::Unsupported(format!( + "AV1 decode {}x{} below the driver minimum", + cfg.max_width, cfg.max_height + ))); + } if width > caps.max_extent.width || height > caps.max_extent.height || cfg.max_dpb_slots > caps.max_dpb_slots @@ -566,6 +574,7 @@ impl Av1DecodeSession { dec, sequence: None, bit_depth: cfg.bit_depth, + min_extent: caps.min_extent, }) } @@ -666,6 +675,11 @@ impl Av1DecodeSession { { return Err(Error::Invalid("frame size".into())); } + if extent.width < self.min_extent.width || extent.height < self.min_extent.height { + return Err(Error::Unsupported( + "AV1 frame below the driver minimum coded extent".into(), + )); + } let tiles = &h.tile_info; let cols = tiles.cols as usize; let rows = tiles.rows as usize; @@ -933,6 +947,7 @@ fn query_caps(gpu: &Gpu, profile: &vk::VideoProfileInfoKHR) -> Result { struct Caps { std_header_version: vk::ExtensionProperties, + min_extent: vk::Extent2D, max_extent: vk::Extent2D, size_align: u64, max_dpb_slots: u32, @@ -206,6 +207,7 @@ impl Profile { pub struct Vp9DecodeSession { dec: Decoder, bit_depth: u8, + min_extent: vk::Extent2D, } impl Vp9DecodeSession { @@ -236,6 +238,12 @@ impl Vp9DecodeSession { let height = align(cfg.max_height, 16); let profile = Profile::new(cfg.bit_depth); let caps = query_caps(gpu, &profile.info)?; + if cfg.max_width < caps.min_extent.width || cfg.max_height < caps.min_extent.height { + return Err(Error::Unsupported(format!( + "VP9 decode {}x{} below the driver minimum", + cfg.max_width, cfg.max_height + ))); + } if width > caps.max_extent.width || height > caps.max_extent.height || cfg.max_dpb_slots > caps.max_dpb_slots @@ -270,6 +278,7 @@ impl Vp9DecodeSession { Ok(Vp9DecodeSession { dec, bit_depth: cfg.bit_depth, + min_extent: caps.min_extent, }) } @@ -292,6 +301,11 @@ impl Vp9DecodeSession { { return Err(Error::Invalid("frame size".into())); } + if extent.width < self.min_extent.width || extent.height < self.min_extent.height { + return Err(Error::Unsupported( + "VP9 frame below the driver minimum coded extent".into(), + )); + } if pic.data.len() as u64 > self.dec.bitstream.size { return Err(Error::Invalid("frame larger than bitstream buffer".into())); } @@ -468,6 +482,7 @@ fn query_caps(gpu: &Gpu, profile: &vk::VideoProfileInfoKHR) -> Result