diff --git a/crates/ec-hw/src/vkdec264.rs b/crates/ec-hw/src/vkdec264.rs index 5ef3eb88..83dc47bf 100644 --- a/crates/ec-hw/src/vkdec264.rs +++ b/crates/ec-hw/src/vkdec264.rs @@ -261,7 +261,8 @@ impl VkH264Decoder { profile_idc: sps.profile_idc, chroma_format_idc: chroma, }, - )?; + ) + .map_err(refused)?; let ring = Ring::new(h264.ring_len()); self.session = Some(Session { h264: Rc::new(RefCell::new(h264)), @@ -347,7 +348,8 @@ impl VkH264Decoder { setup_slot: current.slot, refs: &refs, slices: &slices, - })?; + }) + .map_err(refused)?; let (left, _, top, _) = sps.crop; session .h264 @@ -408,6 +410,13 @@ 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/h264_decode.rs b/shims/vk-video-ffi/src/h264_decode.rs index a7492415..a0ba53f4 100644 --- a/shims/vk-video-ffi/src/h264_decode.rs +++ b/shims/vk-video-ffi/src/h264_decode.rs @@ -162,6 +162,7 @@ pub struct H264DecodePicture<'a> { struct Caps { std_header_version: vk::ExtensionProperties, + min_extent: vk::Extent2D, max_extent: vk::Extent2D, size_align: u64, max_dpb_slots: u32, @@ -201,6 +202,7 @@ impl Profile { /// An H.264 Vulkan Video decode session: NV12 DPB images per slot and a separate NV12 output image. pub struct H264DecodeSession { dec: Decoder, + min_extent: vk::Extent2D, sps: Vec, } @@ -241,6 +243,11 @@ impl H264DecodeSession { let height = align(cfg.max_height, 16); let profile = Profile::new(cfg.profile_idc, cfg.chroma_format_idc); let caps = query_caps(gpu, &profile.info)?; + if width < caps.min_extent.width || height < caps.min_extent.height { + return Err(Error::Unsupported(format!( + "H.264 decode {width}x{height} below the driver minimum" + ))); + } if width > caps.max_extent.width || height > caps.max_extent.height || cfg.max_dpb_slots > caps.max_dpb_slots @@ -275,6 +282,7 @@ impl H264DecodeSession { )?; Ok(H264DecodeSession { dec, + min_extent: caps.min_extent, sps: Vec::new(), }) } @@ -347,6 +355,11 @@ impl H264DecodeSession { .find(|s| s.id == pic.sps_id) .ok_or_else(|| Error::Invalid(format!("unknown SPS {}", pic.sps_id)))?; let extent = coded_extent(sps); + if extent.width < self.min_extent.width || extent.height < self.min_extent.height { + return Err(Error::Unsupported( + "H.264 picture below the driver minimum coded extent".into(), + )); + } if extent.width > self.dec.max_extent.width || extent.height > self.dec.max_extent.height { return Err(Error::Invalid("picture larger than session".into())); } @@ -524,6 +537,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, @@ -352,6 +353,7 @@ pub struct H265DecodeSession { dec: Decoder, sps: Vec, bit_depth: u8, + min_extent: vk::Extent2D, } impl H265DecodeSession { @@ -378,10 +380,10 @@ impl H265DecodeSession { { return Err(Error::Unsupported("H.265 decode".into())); } - let width = align(cfg.max_width, 16); - let height = align(cfg.max_height, 16); let profile = Profile::new(cfg.bit_depth); let caps = query_caps(gpu, &profile.info)?; + let width = align(cfg.max_width, 16).max(caps.min_extent.width); + let height = align(cfg.max_height, 16).max(caps.min_extent.height); if width > caps.max_extent.width || height > caps.max_extent.height || cfg.max_dpb_slots > caps.max_dpb_slots @@ -418,6 +420,7 @@ impl H265DecodeSession { dec, sps: Vec::new(), bit_depth: cfg.bit_depth, + min_extent: caps.min_extent, }) } @@ -552,8 +555,8 @@ impl H265DecodeSession { .find(|s| s.id == pic.sps_id) .ok_or_else(|| Error::Invalid(format!("unknown SPS {}", pic.sps_id)))?; vk::Extent2D { - width: sps.pic_width_in_luma_samples, - height: sps.pic_height_in_luma_samples, + width: sps.pic_width_in_luma_samples.max(self.min_extent.width), + height: sps.pic_height_in_luma_samples.max(self.min_extent.height), } }; if extent.width > self.dec.max_extent.width || extent.height > self.dec.max_extent.height { @@ -749,6 +752,7 @@ fn query_caps(gpu: &Gpu, profile: &vk::VideoProfileInfoKHR) -> Result