forge
Explore
Log in

Don't you dare go Hollow

vk-video-ffi: pad H.265 to driver min extent, H.264 sub-min Unsupported, decode-stage init barrier

Browse files at this commit

1786477fc8b4e1dc3fe78eb7c9bde9223d0e5b38Ahmet Kaan GümüşParent: 42021c7
crates/ec-hw/src/vkdec264.rsmodified+11 -2
@@ -250,7 +250,8 @@ impl VkH264Decoder {
250 max_dpb_slots: slots,250 max_dpb_slots: slots,
251 profile_idc: sps.profile_idc,251 profile_idc: sps.profile_idc,
252 },252 },
253- )?;253+ )
254+ .map_err(refused)?;
254 let ring = Ring::new(h264.ring_len());255 let ring = Ring::new(h264.ring_len());
255 self.session = Some(Session {256 self.session = Some(Session {
256 h264: Rc::new(RefCell::new(h264)),257 h264: Rc::new(RefCell::new(h264)),
@@ -335,7 +336,8 @@ impl VkH264Decoder {
335 setup_slot: current.slot,336 setup_slot: current.slot,
336 refs: &refs,337 refs: &refs,
337 slices: &slices,338 slices: &slices,
338- })?;339+ })
340+ .map_err(refused)?;
339 let (left, _, top, _) = sps.crop;341 let (left, _, top, _) = sps.crop;
340 session342 session
341 .h264343 .h264
@@ -396,6 +398,13 @@ impl VkH264Decoder {
396 }398 }
397 }399 }
398 400
401+fn refused(e: ec_vk::Error) -> Error {
402+ match e {
403+ ec_vk::Error::Unsupported(why) => Error::unsupported("Vulkan Video H.264 decode", why),
404+ other => other.into(),
405+ }
406+}
407+
399 fn field_pocs(poc: i32, delta_bottom: i32) -> [i32; 2] {408 fn field_pocs(poc: i32, delta_bottom: i32) -> [i32; 2] {
400 [poc - delta_bottom.min(0), poc + delta_bottom.max(0)]409 [poc - delta_bottom.min(0), poc + delta_bottom.max(0)]
401 }410 }
shims/vk-video-ffi/src/h264_decode.rsmodified+14 -0
@@ -160,6 +160,7 @@ pub struct H264DecodePicture<'a> {
160 160
161 struct Caps {161 struct Caps {
162 std_header_version: vk::ExtensionProperties,162 std_header_version: vk::ExtensionProperties,
163+ min_extent: vk::Extent2D,
163 max_extent: vk::Extent2D,164 max_extent: vk::Extent2D,
164 size_align: u64,165 size_align: u64,
165 max_dpb_slots: u32,166 max_dpb_slots: u32,
@@ -194,6 +195,7 @@ impl Profile {
194 /// An H.264 Vulkan Video decode session: NV12 DPB images per slot and a separate NV12 output image.195 /// An H.264 Vulkan Video decode session: NV12 DPB images per slot and a separate NV12 output image.
195 pub struct H264DecodeSession {196 pub struct H264DecodeSession {
196 dec: Decoder,197 dec: Decoder,
198+ min_extent: vk::Extent2D,
197 sps: Vec<H264Sps>,199 sps: Vec<H264Sps>,
198 }200 }
199 201
@@ -228,6 +230,11 @@ impl H264DecodeSession {
228 let height = align(cfg.max_height, 16);230 let height = align(cfg.max_height, 16);
229 let profile = Profile::new(cfg.profile_idc);231 let profile = Profile::new(cfg.profile_idc);
230 let caps = query_caps(gpu, &profile.info)?;232 let caps = query_caps(gpu, &profile.info)?;
233+ if width < caps.min_extent.width || height < caps.min_extent.height {
234+ return Err(Error::Unsupported(format!(
235+ "H.264 decode {width}x{height} below the driver minimum"
236+ )));
237+ }
231 if width > caps.max_extent.width238 if width > caps.max_extent.width
232 || height > caps.max_extent.height239 || height > caps.max_extent.height
233 || cfg.max_dpb_slots > caps.max_dpb_slots240 || cfg.max_dpb_slots > caps.max_dpb_slots
@@ -262,6 +269,7 @@ impl H264DecodeSession {
262 )?;269 )?;
263 Ok(H264DecodeSession {270 Ok(H264DecodeSession {
264 dec,271 dec,
272+ min_extent: caps.min_extent,
265 sps: Vec::new(),273 sps: Vec::new(),
266 })274 })
267 }275 }
@@ -334,6 +342,11 @@ impl H264DecodeSession {
334 .find(|s| s.id == pic.sps_id)342 .find(|s| s.id == pic.sps_id)
335 .ok_or_else(|| Error::Invalid(format!("unknown SPS {}", pic.sps_id)))?;343 .ok_or_else(|| Error::Invalid(format!("unknown SPS {}", pic.sps_id)))?;
336 let extent = coded_extent(sps);344 let extent = coded_extent(sps);
345+ if extent.width < self.min_extent.width || extent.height < self.min_extent.height {
346+ return Err(Error::Unsupported(
347+ "H.264 picture below the driver minimum coded extent".into(),
348+ ));
349+ }
337 if extent.width > self.dec.max_extent.width || extent.height > self.dec.max_extent.height {350 if extent.width > self.dec.max_extent.width || extent.height > self.dec.max_extent.height {
338 return Err(Error::Invalid("picture larger than session".into()));351 return Err(Error::Invalid("picture larger than session".into()));
339 }352 }
@@ -511,6 +524,7 @@ fn query_caps(gpu: &Gpu, profile: &vk::VideoProfileInfoKHR) -> Result<Caps, Erro
511 let decode = decode.build();524 let decode = decode.build();
512 Ok(Caps {525 Ok(Caps {
513 std_header_version: caps.std_header_version,526 std_header_version: caps.std_header_version,
527+ min_extent: caps.min_coded_extent,
514 max_extent: caps.max_coded_extent,528 max_extent: caps.max_coded_extent,
515 size_align: caps.min_bitstream_buffer_size_alignment,529 size_align: caps.min_bitstream_buffer_size_alignment,
516 max_dpb_slots: caps.max_dpb_slots,530 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 struct Caps {312 struct Caps {
313 std_header_version: vk::ExtensionProperties,313 std_header_version: vk::ExtensionProperties,
314+ min_extent: vk::Extent2D,
314 max_extent: vk::Extent2D,315 max_extent: vk::Extent2D,
315 size_align: u64,316 size_align: u64,
316 max_dpb_slots: u32,317 max_dpb_slots: u32,
@@ -352,6 +353,7 @@ pub struct H265DecodeSession {
352 dec: Decoder,353 dec: Decoder,
353 sps: Vec<H265Sps>,354 sps: Vec<H265Sps>,
354 bit_depth: u8,355 bit_depth: u8,
356+ min_extent: vk::Extent2D,
355 }357 }
356 358
357 impl H265DecodeSession {359 impl H265DecodeSession {
@@ -378,10 +380,10 @@ impl H265DecodeSession {
378 {380 {
379 return Err(Error::Unsupported("H.265 decode".into()));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 let profile = Profile::new(cfg.bit_depth);383 let profile = Profile::new(cfg.bit_depth);
384 let caps = query_caps(gpu, &profile.info)?;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 if width > caps.max_extent.width387 if width > caps.max_extent.width
386 || height > caps.max_extent.height388 || height > caps.max_extent.height
387 || cfg.max_dpb_slots > caps.max_dpb_slots389 || cfg.max_dpb_slots > caps.max_dpb_slots
@@ -418,6 +420,7 @@ impl H265DecodeSession {
418 dec,420 dec,
419 sps: Vec::new(),421 sps: Vec::new(),
420 bit_depth: cfg.bit_depth,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 .find(|s| s.id == pic.sps_id)555 .find(|s| s.id == pic.sps_id)
553 .ok_or_else(|| Error::Invalid(format!("unknown SPS {}", pic.sps_id)))?;556 .ok_or_else(|| Error::Invalid(format!("unknown SPS {}", pic.sps_id)))?;
554 vk::Extent2D {557 vk::Extent2D {
555- width: sps.pic_width_in_luma_samples,558+ width: sps.pic_width_in_luma_samples.max(self.min_extent.width),
556- height: sps.pic_height_in_luma_samples,559+ height: sps.pic_height_in_luma_samples.max(self.min_extent.height),
557 }560 }
558 };561 };
559 if extent.width > self.dec.max_extent.width || extent.height > self.dec.max_extent.height {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 let decode = decode.build();752 let decode = decode.build();
750 Ok(Caps {753 Ok(Caps {
751 std_header_version: caps.std_header_version,754 std_header_version: caps.std_header_version,
755+ min_extent: caps.min_coded_extent,
752 max_extent: caps.max_coded_extent,756 max_extent: caps.max_coded_extent,
753 size_align: caps.min_bitstream_buffer_size_alignment,757 size_align: caps.min_bitstream_buffer_size_alignment,
754 max_dpb_slots: caps.max_dpb_slots,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 unsafe { d.cmd_pipeline_barrier2(cb, &info) };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 pub(crate) fn init_barrier(337 pub(crate) fn init_barrier(
315 d: &Device,338 d: &Device,
316 cb: vk::CommandBuffer,339 cb: vk::CommandBuffer,
@@ -1582,7 +1605,7 @@ impl Decoder {
1582 let cb = dec.decode.cb;1605 let cb = dec.decode.cb;
1583 dec.decode.begin()?;1606 dec.decode.begin()?;
1584 for img in &dec.dpb {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 dec.decode.end()?;1610 dec.decode.end()?;
1588 dec.decode.submit()?;1611 dec.decode.submit()?;
@@ -1602,7 +1625,7 @@ impl Decoder {
1602 let reset = !self.coded;1625 let reset = !self.coded;
1603 self.decode.begin()?;1626 self.decode.begin()?;
1604 unsafe {1627 unsafe {
1605- init_barrier(1628+ decode_init_barrier(
1606 d,1629 d,
1607 cb,1630 cb,
1608 self.output.image,1631 self.output.image,