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 {
250250 max_dpb_slots: slots,
251251 profile_idc: sps.profile_idc,
252252 },
253- )?;
253+ )
254+ .map_err(refused)?;
254255 let ring = Ring::new(h264.ring_len());
255256 self.session = Some(Session {
256257 h264: Rc::new(RefCell::new(h264)),
@@ -335,7 +336,8 @@ impl VkH264Decoder {
335336 setup_slot: current.slot,
336337 refs: &refs,
337338 slices: &slices,
338- })?;
339+ })
340+ .map_err(refused)?;
339341 let (left, _, top, _) = sps.crop;
340342 session
341343 .h264
@@ -396,6 +398,13 @@ impl VkH264Decoder {
396398 }
397399 }
398400
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+
399408 fn field_pocs(poc: i32, delta_bottom: i32) -> [i32; 2] {
400409 [poc - delta_bottom.min(0), poc + delta_bottom.max(0)]
401410 }
shims/vk-video-ffi/src/h264_decode.rsmodified+14 -0
@@ -160,6 +160,7 @@ pub struct H264DecodePicture<'a> {
160160
161161 struct Caps {
162162 std_header_version: vk::ExtensionProperties,
163+ min_extent: vk::Extent2D,
163164 max_extent: vk::Extent2D,
164165 size_align: u64,
165166 max_dpb_slots: u32,
@@ -194,6 +195,7 @@ impl Profile {
194195 /// An H.264 Vulkan Video decode session: NV12 DPB images per slot and a separate NV12 output image.
195196 pub struct H264DecodeSession {
196197 dec: Decoder,
198+ min_extent: vk::Extent2D,
197199 sps: Vec<H264Sps>,
198200 }
199201
@@ -228,6 +230,11 @@ impl H264DecodeSession {
228230 let height = align(cfg.max_height, 16);
229231 let profile = Profile::new(cfg.profile_idc);
230232 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+ }
231238 if width > caps.max_extent.width
232239 || height > caps.max_extent.height
233240 || cfg.max_dpb_slots > caps.max_dpb_slots
@@ -262,6 +269,7 @@ impl H264DecodeSession {
262269 )?;
263270 Ok(H264DecodeSession {
264271 dec,
272+ min_extent: caps.min_extent,
265273 sps: Vec::new(),
266274 })
267275 }
@@ -334,6 +342,11 @@ impl H264DecodeSession {
334342 .find(|s| s.id == pic.sps_id)
335343 .ok_or_else(|| Error::Invalid(format!("unknown SPS {}", pic.sps_id)))?;
336344 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+ }
337350 if extent.width > self.dec.max_extent.width || extent.height > self.dec.max_extent.height {
338351 return Err(Error::Invalid("picture larger than session".into()));
339352 }
@@ -511,6 +524,7 @@ fn query_caps(gpu: &Gpu, profile: &vk::VideoProfileInfoKHR) -> Result<Caps, Erro
511524 let decode = decode.build();
512525 Ok(Caps {
513526 std_header_version: caps.std_header_version,
527+ min_extent: caps.min_coded_extent,
514528 max_extent: caps.max_coded_extent,
515529 size_align: caps.min_bitstream_buffer_size_alignment,
516530 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> {
311311
312312 struct Caps {
313313 std_header_version: vk::ExtensionProperties,
314+ min_extent: vk::Extent2D,
314315 max_extent: vk::Extent2D,
315316 size_align: u64,
316317 max_dpb_slots: u32,
@@ -352,6 +353,7 @@ pub struct H265DecodeSession {
352353 dec: Decoder,
353354 sps: Vec<H265Sps>,
354355 bit_depth: u8,
356+ min_extent: vk::Extent2D,
355357 }
356358
357359 impl H265DecodeSession {
@@ -378,10 +380,10 @@ impl H265DecodeSession {
378380 {
379381 return Err(Error::Unsupported("H.265 decode".into()));
380382 }
381- let width = align(cfg.max_width, 16);
382- let height = align(cfg.max_height, 16);
383383 let profile = Profile::new(cfg.bit_depth);
384384 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);
385387 if width > caps.max_extent.width
386388 || height > caps.max_extent.height
387389 || cfg.max_dpb_slots > caps.max_dpb_slots
@@ -418,6 +420,7 @@ impl H265DecodeSession {
418420 dec,
419421 sps: Vec::new(),
420422 bit_depth: cfg.bit_depth,
423+ min_extent: caps.min_extent,
421424 })
422425 }
423426
@@ -552,8 +555,8 @@ impl H265DecodeSession {
552555 .find(|s| s.id == pic.sps_id)
553556 .ok_or_else(|| Error::Invalid(format!("unknown SPS {}", pic.sps_id)))?;
554557 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),
557560 }
558561 };
559562 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
749752 let decode = decode.build();
750753 Ok(Caps {
751754 std_header_version: caps.std_header_version,
755+ min_extent: caps.min_coded_extent,
752756 max_extent: caps.max_coded_extent,
753757 size_align: caps.min_bitstream_buffer_size_alignment,
754758 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:
311311 unsafe { d.cmd_pipeline_barrier2(cb, &info) };
312312 }
313313
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+
314337 pub(crate) fn init_barrier(
315338 d: &Device,
316339 cb: vk::CommandBuffer,
@@ -1582,7 +1605,7 @@ impl Decoder {
15821605 let cb = dec.decode.cb;
15831606 dec.decode.begin()?;
15841607 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);
15861609 }
15871610 dec.decode.end()?;
15881611 dec.decode.submit()?;
@@ -1602,7 +1625,7 @@ impl Decoder {
16021625 let reset = !self.coded;
16031626 self.decode.begin()?;
16041627 unsafe {
1605- init_barrier(
1628+ decode_init_barrier(
16061629 d,
16071630 cb,
16081631 self.output.image,