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 commit8af23f053368b35d3fe825e8161c9dd9d58a6c9eParent: 4343f845 changed files +36 -11
- crates/ec-hw/src/dec/mod.rs +3 -2
- crates/ec-hw/src/error.rs +1 -0
- crates/ec-hw/src/vkdec264.rs +2 -9
- shims/vk-video-ffi/src/av1_decode.rs +15 -0
- shims/vk-video-ffi/src/vp9_decode.rs +15 -0
crates/ec-hw/src/dec/mod.rsmodified+3 -2
| @@ -322,11 +322,12 @@ impl Session { | ||
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | let (w, h) = coded_size; |
| 325 | + let (dw, dh) = display_size; | |
| 325 | 326 | 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 | 329 | return Err(Error::unsupported( |
| 329 | - format!("{w}x{h} {profile:?} decode"), | |
| 330 | + format!("{dw}x{dh} {profile:?} decode"), | |
| 330 | 331 | format!( |
| 331 | 332 | "the driver accepts {:?}..{:?} x {:?}..{:?}", |
| 332 | 333 | surfaces.min_width, |
crates/ec-hw/src/error.rsmodified+1 -0
| @@ -92,6 +92,7 @@ impl From<ec_vk::Error> for Error { | ||
| 92 | 92 | crate::reset::report_gpu_reset(); |
| 93 | 93 | Error::hw_reset(format!("Vulkan device lost in {call}")) |
| 94 | 94 | } |
| 95 | + ec_vk::Error::Unsupported(why) => Error::unsupported("Vulkan Video", why), | |
| 95 | 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 | 262 | chroma_format_idc: chroma, |
| 263 | 263 | }, |
| 264 | 264 | ) |
| 265 | - .map_err(refused)?; | |
| 265 | + ?; | |
| 266 | 266 | let ring = Ring::new(h264.ring_len()); |
| 267 | 267 | self.session = Some(Session { |
| 268 | 268 | h264: Rc::new(RefCell::new(h264)), |
| @@ -349,7 +349,7 @@ impl VkH264Decoder { | ||
| 349 | 349 | refs: &refs, |
| 350 | 350 | slices: &slices, |
| 351 | 351 | }) |
| 352 | - .map_err(refused)?; | |
| 352 | + ?; | |
| 353 | 353 | let (left, _, top, _) = sps.crop; |
| 354 | 354 | session |
| 355 | 355 | .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 | 413 | fn field_pocs(poc: i32, delta_bottom: i32) -> [i32; 2] { |
| 421 | 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 | 464 | struct Caps { |
| 465 | 465 | std_header_version: vk::ExtensionProperties, |
| 466 | + min_extent: vk::Extent2D, | |
| 466 | 467 | max_extent: vk::Extent2D, |
| 467 | 468 | size_align: u64, |
| 468 | 469 | max_dpb_slots: u32, |
| @@ -500,6 +501,7 @@ pub struct Av1DecodeSession { | ||
| 500 | 501 | dec: Decoder, |
| 501 | 502 | sequence: Option<Av1SequenceHeader>, |
| 502 | 503 | bit_depth: u8, |
| 504 | + min_extent: vk::Extent2D, | |
| 503 | 505 | } |
| 504 | 506 | |
| 505 | 507 | impl Av1DecodeSession { |
| @@ -530,6 +532,12 @@ impl Av1DecodeSession { | ||
| 530 | 532 | let height = align(cfg.max_height, 16); |
| 531 | 533 | let profile = Profile::new(cfg.bit_depth); |
| 532 | 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 | 541 | if width > caps.max_extent.width |
| 534 | 542 | || height > caps.max_extent.height |
| 535 | 543 | || cfg.max_dpb_slots > caps.max_dpb_slots |
| @@ -566,6 +574,7 @@ impl Av1DecodeSession { | ||
| 566 | 574 | dec, |
| 567 | 575 | sequence: None, |
| 568 | 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 | 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 | 683 | let tiles = &h.tile_info; |
| 670 | 684 | let cols = tiles.cols as usize; |
| 671 | 685 | let rows = tiles.rows as usize; |
| @@ -933,6 +947,7 @@ fn query_caps(gpu: &Gpu, profile: &vk::VideoProfileInfoKHR) -> Result<Caps, Erro | ||
| 933 | 947 | let decode = decode.build(); |
| 934 | 948 | Ok(Caps { |
| 935 | 949 | std_header_version: caps.std_header_version, |
| 950 | + min_extent: caps.min_coded_extent, | |
| 936 | 951 | max_extent: caps.max_coded_extent, |
| 937 | 952 | size_align: caps.min_bitstream_buffer_size_alignment, |
| 938 | 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 | 167 | struct Caps { |
| 168 | 168 | std_header_version: vk::ExtensionProperties, |
| 169 | + min_extent: vk::Extent2D, | |
| 169 | 170 | max_extent: vk::Extent2D, |
| 170 | 171 | size_align: u64, |
| 171 | 172 | max_dpb_slots: u32, |
| @@ -206,6 +207,7 @@ impl Profile { | ||
| 206 | 207 | pub struct Vp9DecodeSession { |
| 207 | 208 | dec: Decoder, |
| 208 | 209 | bit_depth: u8, |
| 210 | + min_extent: vk::Extent2D, | |
| 209 | 211 | } |
| 210 | 212 | |
| 211 | 213 | impl Vp9DecodeSession { |
| @@ -236,6 +238,12 @@ impl Vp9DecodeSession { | ||
| 236 | 238 | let height = align(cfg.max_height, 16); |
| 237 | 239 | let profile = Profile::new(cfg.bit_depth); |
| 238 | 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 | 247 | if width > caps.max_extent.width |
| 240 | 248 | || height > caps.max_extent.height |
| 241 | 249 | || cfg.max_dpb_slots > caps.max_dpb_slots |
| @@ -270,6 +278,7 @@ impl Vp9DecodeSession { | ||
| 270 | 278 | Ok(Vp9DecodeSession { |
| 271 | 279 | dec, |
| 272 | 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 | 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 | 309 | if pic.data.len() as u64 > self.dec.bitstream.size { |
| 296 | 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 | 482 | let decode = decode.build(); |
| 469 | 483 | Ok(Caps { |
| 470 | 484 | std_header_version: caps.std_header_version, |
| 485 | + min_extent: caps.min_coded_extent, | |
| 471 | 486 | max_extent: caps.max_coded_extent, |
| 472 | 487 | size_align: caps.min_bitstream_buffer_size_alignment, |
| 473 | 488 | max_dpb_slots: caps.max_dpb_slots, |