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 {
322 }322 }
323 323
324 let (w, h) = coded_size;324 let (w, h) = coded_size;
325+ let (dw, dh) = display_size;
325 if let Some(surfaces) = &entry.surfaces326 if let Some(surfaces) = &entry.surfaces
326- && !surfaces.allows(w, h)327+ && !(surfaces.allows(w, h) && surfaces.allows(dw.max(1), dh.max(1)))
327 {328 {
328 return Err(Error::unsupported(329 return Err(Error::unsupported(
329- format!("{w}x{h} {profile:?} decode"),330+ format!("{dw}x{dh} {profile:?} decode"),
330 format!(331 format!(
331 "the driver accepts {:?}..{:?} x {:?}..{:?}",332 "the driver accepts {:?}..{:?} x {:?}..{:?}",
332 surfaces.min_width,333 surfaces.min_width,
crates/ec-hw/src/error.rsmodified+1 -0
@@ -92,6 +92,7 @@ impl From<ec_vk::Error> for Error {
92 crate::reset::report_gpu_reset();92 crate::reset::report_gpu_reset();
93 Error::hw_reset(format!("Vulkan device lost in {call}"))93 Error::hw_reset(format!("Vulkan device lost in {call}"))
94 }94 }
95+ ec_vk::Error::Unsupported(why) => Error::unsupported("Vulkan Video", why),
95 other => Error::Vk(other.to_string()),96 other => Error::Vk(other.to_string()),
96 }97 }
97 }98 }
crates/ec-hw/src/vkdec264.rsmodified+2 -9
@@ -262,7 +262,7 @@ impl VkH264Decoder {
262 chroma_format_idc: chroma,262 chroma_format_idc: chroma,
263 },263 },
264 )264 )
265- .map_err(refused)?;265+ ?;
266 let ring = Ring::new(h264.ring_len());266 let ring = Ring::new(h264.ring_len());
267 self.session = Some(Session {267 self.session = Some(Session {
268 h264: Rc::new(RefCell::new(h264)),268 h264: Rc::new(RefCell::new(h264)),
@@ -349,7 +349,7 @@ impl VkH264Decoder {
349 refs: &refs,349 refs: &refs,
350 slices: &slices,350 slices: &slices,
351 })351 })
352- .map_err(refused)?;352+ ?;
353 let (left, _, top, _) = sps.crop;353 let (left, _, top, _) = sps.crop;
354 session354 session
355 .h264355 .h264
@@ -410,13 +410,6 @@ impl VkH264Decoder {
410 }410 }
411 }411 }
412 412
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-
420 fn field_pocs(poc: i32, delta_bottom: i32) -> [i32; 2] {413 fn field_pocs(poc: i32, delta_bottom: i32) -> [i32; 2] {
421 [poc - delta_bottom.min(0), poc + delta_bottom.max(0)]414 [poc - delta_bottom.min(0), poc + delta_bottom.max(0)]
422 }415 }
shims/vk-video-ffi/src/av1_decode.rsmodified+15 -0
@@ -463,6 +463,7 @@ pub struct Av1DecodePicture<'a> {
463 463
464 struct Caps {464 struct Caps {
465 std_header_version: vk::ExtensionProperties,465 std_header_version: vk::ExtensionProperties,
466+ min_extent: vk::Extent2D,
466 max_extent: vk::Extent2D,467 max_extent: vk::Extent2D,
467 size_align: u64,468 size_align: u64,
468 max_dpb_slots: u32,469 max_dpb_slots: u32,
@@ -500,6 +501,7 @@ pub struct Av1DecodeSession {
500 dec: Decoder,501 dec: Decoder,
501 sequence: Option<Av1SequenceHeader>,502 sequence: Option<Av1SequenceHeader>,
502 bit_depth: u8,503 bit_depth: u8,
504+ min_extent: vk::Extent2D,
503 }505 }
504 506
505 impl Av1DecodeSession {507 impl Av1DecodeSession {
@@ -530,6 +532,12 @@ impl Av1DecodeSession {
530 let height = align(cfg.max_height, 16);532 let height = align(cfg.max_height, 16);
531 let profile = Profile::new(cfg.bit_depth);533 let profile = Profile::new(cfg.bit_depth);
532 let caps = query_caps(gpu, &profile.info)?;534 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+ }
533 if width > caps.max_extent.width541 if width > caps.max_extent.width
534 || height > caps.max_extent.height542 || height > caps.max_extent.height
535 || cfg.max_dpb_slots > caps.max_dpb_slots543 || cfg.max_dpb_slots > caps.max_dpb_slots
@@ -566,6 +574,7 @@ impl Av1DecodeSession {
566 dec,574 dec,
567 sequence: None,575 sequence: None,
568 bit_depth: cfg.bit_depth,576 bit_depth: cfg.bit_depth,
577+ min_extent: caps.min_extent,
569 })578 })
570 }579 }
571 580
@@ -666,6 +675,11 @@ impl Av1DecodeSession {
666 {675 {
667 return Err(Error::Invalid("frame size".into()));676 return Err(Error::Invalid("frame size".into()));
668 }677 }
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+ }
669 let tiles = &h.tile_info;683 let tiles = &h.tile_info;
670 let cols = tiles.cols as usize;684 let cols = tiles.cols as usize;
671 let rows = tiles.rows as usize;685 let rows = tiles.rows as usize;
@@ -933,6 +947,7 @@ fn query_caps(gpu: &Gpu, profile: &vk::VideoProfileInfoKHR) -> Result<Caps, Erro
933 let decode = decode.build();947 let decode = decode.build();
934 Ok(Caps {948 Ok(Caps {
935 std_header_version: caps.std_header_version,949 std_header_version: caps.std_header_version,
950+ min_extent: caps.min_coded_extent,
936 max_extent: caps.max_coded_extent,951 max_extent: caps.max_coded_extent,
937 size_align: caps.min_bitstream_buffer_size_alignment,952 size_align: caps.min_bitstream_buffer_size_alignment,
938 max_dpb_slots: caps.max_dpb_slots,953 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> {
166 166
167 struct Caps {167 struct Caps {
168 std_header_version: vk::ExtensionProperties,168 std_header_version: vk::ExtensionProperties,
169+ min_extent: vk::Extent2D,
169 max_extent: vk::Extent2D,170 max_extent: vk::Extent2D,
170 size_align: u64,171 size_align: u64,
171 max_dpb_slots: u32,172 max_dpb_slots: u32,
@@ -206,6 +207,7 @@ impl Profile {
206 pub struct Vp9DecodeSession {207 pub struct Vp9DecodeSession {
207 dec: Decoder,208 dec: Decoder,
208 bit_depth: u8,209 bit_depth: u8,
210+ min_extent: vk::Extent2D,
209 }211 }
210 212
211 impl Vp9DecodeSession {213 impl Vp9DecodeSession {
@@ -236,6 +238,12 @@ impl Vp9DecodeSession {
236 let height = align(cfg.max_height, 16);238 let height = align(cfg.max_height, 16);
237 let profile = Profile::new(cfg.bit_depth);239 let profile = Profile::new(cfg.bit_depth);
238 let caps = query_caps(gpu, &profile.info)?;240 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+ }
239 if width > caps.max_extent.width247 if width > caps.max_extent.width
240 || height > caps.max_extent.height248 || height > caps.max_extent.height
241 || cfg.max_dpb_slots > caps.max_dpb_slots249 || cfg.max_dpb_slots > caps.max_dpb_slots
@@ -270,6 +278,7 @@ impl Vp9DecodeSession {
270 Ok(Vp9DecodeSession {278 Ok(Vp9DecodeSession {
271 dec,279 dec,
272 bit_depth: cfg.bit_depth,280 bit_depth: cfg.bit_depth,
281+ min_extent: caps.min_extent,
273 })282 })
274 }283 }
275 284
@@ -292,6 +301,11 @@ impl Vp9DecodeSession {
292 {301 {
293 return Err(Error::Invalid("frame size".into()));302 return Err(Error::Invalid("frame size".into()));
294 }303 }
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+ }
295 if pic.data.len() as u64 > self.dec.bitstream.size {309 if pic.data.len() as u64 > self.dec.bitstream.size {
296 return Err(Error::Invalid("frame larger than bitstream buffer".into()));310 return Err(Error::Invalid("frame larger than bitstream buffer".into()));
297 }311 }
@@ -468,6 +482,7 @@ fn query_caps(gpu: &Gpu, profile: &vk::VideoProfileInfoKHR) -> Result<Caps, Erro
468 let decode = decode.build();482 let decode = decode.build();
469 Ok(Caps {483 Ok(Caps {
470 std_header_version: caps.std_header_version,484 std_header_version: caps.std_header_version,
485+ min_extent: caps.min_coded_extent,
471 max_extent: caps.max_coded_extent,486 max_extent: caps.max_coded_extent,
472 size_align: caps.min_bitstream_buffer_size_alignment,487 size_align: caps.min_bitstream_buffer_size_alignment,
473 max_dpb_slots: caps.max_dpb_slots,488 max_dpb_slots: caps.max_dpb_slots,