forge
Explore
Log in

Don't you dare go Hollow

ec-hw: Vk Unsupported falls back to VA everywhere; VP9/AV1 refuse below minCodedExtent; VA checks real picture size against driver minimum

Browse files at this commit

8af23f053368b35d3fe825e8161c9dd9d58a6c9eAhmet Kaan GümüşParent: 4343f84
crates/ec-hw/src/dec/mod.rsmodified+3 -2
@@ -322,11 +322,12 @@ impl Session {
322322 }
323323
324324 let (w, h) = coded_size;
325+ let (dw, dh) = display_size;
325326 if let Some(surfaces) = &entry.surfaces
326- && !surfaces.allows(w, h)
327+ && !(surfaces.allows(w, h) && surfaces.allows(dw.max(1), dh.max(1)))
327328 {
328329 return Err(Error::unsupported(
329- format!("{w}x{h} {profile:?} decode"),
330+ format!("{dw}x{dh} {profile:?} decode"),
330331 format!(
331332 "the driver accepts {:?}..{:?} x {:?}..{:?}",
332333 surfaces.min_width,
crates/ec-hw/src/error.rsmodified+1 -0
@@ -92,6 +92,7 @@ impl From<ec_vk::Error> for Error {
9292 crate::reset::report_gpu_reset();
9393 Error::hw_reset(format!("Vulkan device lost in {call}"))
9494 }
95+ ec_vk::Error::Unsupported(why) => Error::unsupported("Vulkan Video", why),
9596 other => Error::Vk(other.to_string()),
9697 }
9798 }
crates/ec-hw/src/vkdec264.rsmodified+2 -9
@@ -262,7 +262,7 @@ impl VkH264Decoder {
262262 chroma_format_idc: chroma,
263263 },
264264 )
265- .map_err(refused)?;
265+ ?;
266266 let ring = Ring::new(h264.ring_len());
267267 self.session = Some(Session {
268268 h264: Rc::new(RefCell::new(h264)),
@@ -349,7 +349,7 @@ impl VkH264Decoder {
349349 refs: &refs,
350350 slices: &slices,
351351 })
352- .map_err(refused)?;
352+ ?;
353353 let (left, _, top, _) = sps.crop;
354354 session
355355 .h264
@@ -410,13 +410,6 @@ impl VkH264Decoder {
410410 }
411411 }
412412
413-fn refused(e: ec_vk::Error) -> Error {
414- match e {
415- ec_vk::Error::Unsupported(why) => Error::unsupported("Vulkan Video H.264 decode", why),
416- other => other.into(),
417- }
418-}
419-
420413 fn field_pocs(poc: i32, delta_bottom: i32) -> [i32; 2] {
421414 [poc - delta_bottom.min(0), poc + delta_bottom.max(0)]
422415 }
shims/vk-video-ffi/src/av1_decode.rsmodified+15 -0
@@ -463,6 +463,7 @@ pub struct Av1DecodePicture<'a> {
463463
464464 struct Caps {
465465 std_header_version: vk::ExtensionProperties,
466+ min_extent: vk::Extent2D,
466467 max_extent: vk::Extent2D,
467468 size_align: u64,
468469 max_dpb_slots: u32,
@@ -500,6 +501,7 @@ pub struct Av1DecodeSession {
500501 dec: Decoder,
501502 sequence: Option<Av1SequenceHeader>,
502503 bit_depth: u8,
504+ min_extent: vk::Extent2D,
503505 }
504506
505507 impl Av1DecodeSession {
@@ -530,6 +532,12 @@ impl Av1DecodeSession {
530532 let height = align(cfg.max_height, 16);
531533 let profile = Profile::new(cfg.bit_depth);
532534 let caps = query_caps(gpu, &profile.info)?;
535+ if cfg.max_width < caps.min_extent.width || cfg.max_height < caps.min_extent.height {
536+ return Err(Error::Unsupported(format!(
537+ "AV1 decode {}x{} below the driver minimum",
538+ cfg.max_width, cfg.max_height
539+ )));
540+ }
533541 if width > caps.max_extent.width
534542 || height > caps.max_extent.height
535543 || cfg.max_dpb_slots > caps.max_dpb_slots
@@ -566,6 +574,7 @@ impl Av1DecodeSession {
566574 dec,
567575 sequence: None,
568576 bit_depth: cfg.bit_depth,
577+ min_extent: caps.min_extent,
569578 })
570579 }
571580
@@ -666,6 +675,11 @@ impl Av1DecodeSession {
666675 {
667676 return Err(Error::Invalid("frame size".into()));
668677 }
678+ if extent.width < self.min_extent.width || extent.height < self.min_extent.height {
679+ return Err(Error::Unsupported(
680+ "AV1 frame below the driver minimum coded extent".into(),
681+ ));
682+ }
669683 let tiles = &h.tile_info;
670684 let cols = tiles.cols as usize;
671685 let rows = tiles.rows as usize;
@@ -933,6 +947,7 @@ fn query_caps(gpu: &Gpu, profile: &vk::VideoProfileInfoKHR) -> Result<Caps, Erro
933947 let decode = decode.build();
934948 Ok(Caps {
935949 std_header_version: caps.std_header_version,
950+ min_extent: caps.min_coded_extent,
936951 max_extent: caps.max_coded_extent,
937952 size_align: caps.min_bitstream_buffer_size_alignment,
938953 max_dpb_slots: caps.max_dpb_slots,
shims/vk-video-ffi/src/vp9_decode.rsmodified+15 -0
@@ -166,6 +166,7 @@ pub struct Vp9DecodePicture<'a> {
166166
167167 struct Caps {
168168 std_header_version: vk::ExtensionProperties,
169+ min_extent: vk::Extent2D,
169170 max_extent: vk::Extent2D,
170171 size_align: u64,
171172 max_dpb_slots: u32,
@@ -206,6 +207,7 @@ impl Profile {
206207 pub struct Vp9DecodeSession {
207208 dec: Decoder,
208209 bit_depth: u8,
210+ min_extent: vk::Extent2D,
209211 }
210212
211213 impl Vp9DecodeSession {
@@ -236,6 +238,12 @@ impl Vp9DecodeSession {
236238 let height = align(cfg.max_height, 16);
237239 let profile = Profile::new(cfg.bit_depth);
238240 let caps = query_caps(gpu, &profile.info)?;
241+ if cfg.max_width < caps.min_extent.width || cfg.max_height < caps.min_extent.height {
242+ return Err(Error::Unsupported(format!(
243+ "VP9 decode {}x{} below the driver minimum",
244+ cfg.max_width, cfg.max_height
245+ )));
246+ }
239247 if width > caps.max_extent.width
240248 || height > caps.max_extent.height
241249 || cfg.max_dpb_slots > caps.max_dpb_slots
@@ -270,6 +278,7 @@ impl Vp9DecodeSession {
270278 Ok(Vp9DecodeSession {
271279 dec,
272280 bit_depth: cfg.bit_depth,
281+ min_extent: caps.min_extent,
273282 })
274283 }
275284
@@ -292,6 +301,11 @@ impl Vp9DecodeSession {
292301 {
293302 return Err(Error::Invalid("frame size".into()));
294303 }
304+ if extent.width < self.min_extent.width || extent.height < self.min_extent.height {
305+ return Err(Error::Unsupported(
306+ "VP9 frame below the driver minimum coded extent".into(),
307+ ));
308+ }
295309 if pic.data.len() as u64 > self.dec.bitstream.size {
296310 return Err(Error::Invalid("frame larger than bitstream buffer".into()));
297311 }
@@ -468,6 +482,7 @@ fn query_caps(gpu: &Gpu, profile: &vk::VideoProfileInfoKHR) -> Result<Caps, Erro
468482 let decode = decode.build();
469483 Ok(Caps {
470484 std_header_version: caps.std_header_version,
485+ min_extent: caps.min_coded_extent,
471486 max_extent: caps.max_coded_extent,
472487 size_align: caps.min_bitstream_buffer_size_alignment,
473488 max_dpb_slots: caps.max_dpb_slots,