Merge branch 'worktree-agent-a6ee9b05f0e9c5917'
Browse files at this commit4 changed files +58 -8
- crates/ec-hw/src/vkdec264.rs +11 -2
- shims/vk-video-ffi/src/h264_decode.rs +14 -0
- shims/vk-video-ffi/src/h265_decode.rs +8 -4
- shims/vk-video-ffi/src/session.rs +25 -2
crates/ec-hw/src/vkdec264.rsmodified+11 -2
| @@ -261,7 +261,8 @@ impl VkH264Decoder { | ||
| 261 | 261 | profile_idc: sps.profile_idc, |
| 262 | 262 | chroma_format_idc: chroma, |
| 263 | 263 | }, |
| 264 | - )?; | |
| 264 | + ) | |
| 265 | + .map_err(refused)?; | |
| 265 | 266 | let ring = Ring::new(h264.ring_len()); |
| 266 | 267 | self.session = Some(Session { |
| 267 | 268 | h264: Rc::new(RefCell::new(h264)), |
| @@ -347,7 +348,8 @@ impl VkH264Decoder { | ||
| 347 | 348 | setup_slot: current.slot, |
| 348 | 349 | refs: &refs, |
| 349 | 350 | slices: &slices, |
| 350 | - })?; | |
| 351 | + }) | |
| 352 | + .map_err(refused)?; | |
| 351 | 353 | let (left, _, top, _) = sps.crop; |
| 352 | 354 | session |
| 353 | 355 | .h264 |
| @@ -408,6 +410,13 @@ impl VkH264Decoder { | ||
| 408 | 410 | } |
| 409 | 411 | } |
| 410 | 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 | + | |
| 411 | 420 | fn field_pocs(poc: i32, delta_bottom: i32) -> [i32; 2] { |
| 412 | 421 | [poc - delta_bottom.min(0), poc + delta_bottom.max(0)] |
| 413 | 422 | } |
shims/vk-video-ffi/src/h264_decode.rsmodified+14 -0
| @@ -162,6 +162,7 @@ pub struct H264DecodePicture<'a> { | ||
| 162 | 162 | |
| 163 | 163 | struct Caps { |
| 164 | 164 | std_header_version: vk::ExtensionProperties, |
| 165 | + min_extent: vk::Extent2D, | |
| 165 | 166 | max_extent: vk::Extent2D, |
| 166 | 167 | size_align: u64, |
| 167 | 168 | max_dpb_slots: u32, |
| @@ -201,6 +202,7 @@ impl Profile { | ||
| 201 | 202 | /// An H.264 Vulkan Video decode session: NV12 DPB images per slot and a separate NV12 output image. |
| 202 | 203 | pub struct H264DecodeSession { |
| 203 | 204 | dec: Decoder, |
| 205 | + min_extent: vk::Extent2D, | |
| 204 | 206 | sps: Vec<H264Sps>, |
| 205 | 207 | } |
| 206 | 208 | |
| @@ -241,6 +243,11 @@ impl H264DecodeSession { | ||
| 241 | 243 | let height = align(cfg.max_height, 16); |
| 242 | 244 | let profile = Profile::new(cfg.profile_idc, cfg.chroma_format_idc); |
| 243 | 245 | let caps = query_caps(gpu, &profile.info)?; |
| 246 | + if width < caps.min_extent.width || height < caps.min_extent.height { | |
| 247 | + return Err(Error::Unsupported(format!( | |
| 248 | + "H.264 decode {width}x{height} below the driver minimum" | |
| 249 | + ))); | |
| 250 | + } | |
| 244 | 251 | if width > caps.max_extent.width |
| 245 | 252 | || height > caps.max_extent.height |
| 246 | 253 | || cfg.max_dpb_slots > caps.max_dpb_slots |
| @@ -275,6 +282,7 @@ impl H264DecodeSession { | ||
| 275 | 282 | )?; |
| 276 | 283 | Ok(H264DecodeSession { |
| 277 | 284 | dec, |
| 285 | + min_extent: caps.min_extent, | |
| 278 | 286 | sps: Vec::new(), |
| 279 | 287 | }) |
| 280 | 288 | } |
| @@ -347,6 +355,11 @@ impl H264DecodeSession { | ||
| 347 | 355 | .find(|s| s.id == pic.sps_id) |
| 348 | 356 | .ok_or_else(|| Error::Invalid(format!("unknown SPS {}", pic.sps_id)))?; |
| 349 | 357 | let extent = coded_extent(sps); |
| 358 | + if extent.width < self.min_extent.width || extent.height < self.min_extent.height { | |
| 359 | + return Err(Error::Unsupported( | |
| 360 | + "H.264 picture below the driver minimum coded extent".into(), | |
| 361 | + )); | |
| 362 | + } | |
| 350 | 363 | if extent.width > self.dec.max_extent.width || extent.height > self.dec.max_extent.height { |
| 351 | 364 | return Err(Error::Invalid("picture larger than session".into())); |
| 352 | 365 | } |
| @@ -524,6 +537,7 @@ fn query_caps(gpu: &Gpu, profile: &vk::VideoProfileInfoKHR) -> Result<Caps, Erro | ||
| 524 | 537 | let decode = decode.build(); |
| 525 | 538 | Ok(Caps { |
| 526 | 539 | std_header_version: caps.std_header_version, |
| 540 | + min_extent: caps.min_coded_extent, | |
| 527 | 541 | max_extent: caps.max_coded_extent, |
| 528 | 542 | size_align: caps.min_bitstream_buffer_size_alignment, |
| 529 | 543 | max_dpb_slots: caps.max_dpb_slots, |
shims/vk-video-ffi/src/h265_decode.rsmodified+8 -4
| @@ -311,6 +311,7 @@ pub struct H265DecodePicture<'a> { | ||
| 311 | 311 | |
| 312 | 312 | struct Caps { |
| 313 | 313 | std_header_version: vk::ExtensionProperties, |
| 314 | + min_extent: vk::Extent2D, | |
| 314 | 315 | max_extent: vk::Extent2D, |
| 315 | 316 | size_align: u64, |
| 316 | 317 | max_dpb_slots: u32, |
| @@ -352,6 +353,7 @@ pub struct H265DecodeSession { | ||
| 352 | 353 | dec: Decoder, |
| 353 | 354 | sps: Vec<H265Sps>, |
| 354 | 355 | bit_depth: u8, |
| 356 | + min_extent: vk::Extent2D, | |
| 355 | 357 | } |
| 356 | 358 | |
| 357 | 359 | impl H265DecodeSession { |
| @@ -378,10 +380,10 @@ impl H265DecodeSession { | ||
| 378 | 380 | { |
| 379 | 381 | return Err(Error::Unsupported("H.265 decode".into())); |
| 380 | 382 | } |
| 381 | - let width = align(cfg.max_width, 16); | |
| 382 | - let height = align(cfg.max_height, 16); | |
| 383 | 383 | let profile = Profile::new(cfg.bit_depth); |
| 384 | 384 | let caps = query_caps(gpu, &profile.info)?; |
| 385 | + let width = align(cfg.max_width, 16).max(caps.min_extent.width); | |
| 386 | + let height = align(cfg.max_height, 16).max(caps.min_extent.height); | |
| 385 | 387 | if width > caps.max_extent.width |
| 386 | 388 | || height > caps.max_extent.height |
| 387 | 389 | || cfg.max_dpb_slots > caps.max_dpb_slots |
| @@ -418,6 +420,7 @@ impl H265DecodeSession { | ||
| 418 | 420 | dec, |
| 419 | 421 | sps: Vec::new(), |
| 420 | 422 | bit_depth: cfg.bit_depth, |
| 423 | + min_extent: caps.min_extent, | |
| 421 | 424 | }) |
| 422 | 425 | } |
| 423 | 426 | |
| @@ -552,8 +555,8 @@ impl H265DecodeSession { | ||
| 552 | 555 | .find(|s| s.id == pic.sps_id) |
| 553 | 556 | .ok_or_else(|| Error::Invalid(format!("unknown SPS {}", pic.sps_id)))?; |
| 554 | 557 | vk::Extent2D { |
| 555 | - width: sps.pic_width_in_luma_samples, | |
| 556 | - height: sps.pic_height_in_luma_samples, | |
| 558 | + width: sps.pic_width_in_luma_samples.max(self.min_extent.width), | |
| 559 | + height: sps.pic_height_in_luma_samples.max(self.min_extent.height), | |
| 557 | 560 | } |
| 558 | 561 | }; |
| 559 | 562 | 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<Caps, Erro | ||
| 749 | 752 | let decode = decode.build(); |
| 750 | 753 | Ok(Caps { |
| 751 | 754 | std_header_version: caps.std_header_version, |
| 755 | + min_extent: caps.min_coded_extent, | |
| 752 | 756 | max_extent: caps.max_coded_extent, |
| 753 | 757 | size_align: caps.min_bitstream_buffer_size_alignment, |
| 754 | 758 | max_dpb_slots: caps.max_dpb_slots, |
shims/vk-video-ffi/src/session.rsmodified+25 -2
| @@ -311,6 +311,29 @@ pub(crate) fn barrier(d: &Device, cb: vk::CommandBuffer, image: vk::Image, from: | ||
| 311 | 311 | unsafe { d.cmd_pipeline_barrier2(cb, &info) }; |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | +pub(crate) fn decode_init_barrier( | |
| 315 | + d: &Device, | |
| 316 | + cb: vk::CommandBuffer, | |
| 317 | + image: vk::Image, | |
| 318 | + layout: vk::ImageLayout, | |
| 319 | +) { | |
| 320 | + barrier( | |
| 321 | + d, | |
| 322 | + cb, | |
| 323 | + image, | |
| 324 | + ( | |
| 325 | + vk::ImageLayout::UNDEFINED, | |
| 326 | + vk::PipelineStageFlags2::NONE, | |
| 327 | + vk::AccessFlags2::NONE, | |
| 328 | + ), | |
| 329 | + ( | |
| 330 | + layout, | |
| 331 | + vk::PipelineStageFlags2::VIDEO_DECODE_KHR, | |
| 332 | + vk::AccessFlags2::VIDEO_DECODE_READ_KHR | vk::AccessFlags2::VIDEO_DECODE_WRITE_KHR, | |
| 333 | + ), | |
| 334 | + ); | |
| 335 | +} | |
| 336 | + | |
| 314 | 337 | pub(crate) fn init_barrier( |
| 315 | 338 | d: &Device, |
| 316 | 339 | cb: vk::CommandBuffer, |
| @@ -1582,7 +1605,7 @@ impl Decoder { | ||
| 1582 | 1605 | let cb = dec.decode.cb; |
| 1583 | 1606 | dec.decode.begin()?; |
| 1584 | 1607 | for img in &dec.dpb { |
| 1585 | - init_barrier(d, cb, img.image, vk::ImageLayout::VIDEO_DECODE_DPB_KHR); | |
| 1608 | + decode_init_barrier(d, cb, img.image, vk::ImageLayout::VIDEO_DECODE_DPB_KHR); | |
| 1586 | 1609 | } |
| 1587 | 1610 | dec.decode.end()?; |
| 1588 | 1611 | dec.decode.submit()?; |
| @@ -1602,7 +1625,7 @@ impl Decoder { | ||
| 1602 | 1625 | let reset = !self.coded; |
| 1603 | 1626 | self.decode.begin()?; |
| 1604 | 1627 | unsafe { |
| 1605 | - init_barrier( | |
| 1628 | + decode_init_barrier( | |
| 1606 | 1629 | d, |
| 1607 | 1630 | cb, |
| 1608 | 1631 | self.output.image, |