forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'worktree-agent-a6ee9b05f0e9c5917'

Browse files at this commit

7dc186e7b0798639e6ff04aa85af30fac12ab393Ahmet Kaan GümüşParent: c2562061786477
crates/ec-hw/src/vkdec264.rsmodified+11 -2
@@ -261,7 +261,8 @@ impl VkH264Decoder {
261261 profile_idc: sps.profile_idc,
262262 chroma_format_idc: chroma,
263263 },
264- )?;
264+ )
265+ .map_err(refused)?;
265266 let ring = Ring::new(h264.ring_len());
266267 self.session = Some(Session {
267268 h264: Rc::new(RefCell::new(h264)),
@@ -347,7 +348,8 @@ impl VkH264Decoder {
347348 setup_slot: current.slot,
348349 refs: &refs,
349350 slices: &slices,
350- })?;
351+ })
352+ .map_err(refused)?;
351353 let (left, _, top, _) = sps.crop;
352354 session
353355 .h264
@@ -408,6 +410,13 @@ impl VkH264Decoder {
408410 }
409411 }
410412
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+
411420 fn field_pocs(poc: i32, delta_bottom: i32) -> [i32; 2] {
412421 [poc - delta_bottom.min(0), poc + delta_bottom.max(0)]
413422 }
shims/vk-video-ffi/src/h264_decode.rsmodified+14 -0
@@ -162,6 +162,7 @@ pub struct H264DecodePicture<'a> {
162162
163163 struct Caps {
164164 std_header_version: vk::ExtensionProperties,
165+ min_extent: vk::Extent2D,
165166 max_extent: vk::Extent2D,
166167 size_align: u64,
167168 max_dpb_slots: u32,
@@ -201,6 +202,7 @@ impl Profile {
201202 /// An H.264 Vulkan Video decode session: NV12 DPB images per slot and a separate NV12 output image.
202203 pub struct H264DecodeSession {
203204 dec: Decoder,
205+ min_extent: vk::Extent2D,
204206 sps: Vec<H264Sps>,
205207 }
206208
@@ -241,6 +243,11 @@ impl H264DecodeSession {
241243 let height = align(cfg.max_height, 16);
242244 let profile = Profile::new(cfg.profile_idc, cfg.chroma_format_idc);
243245 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+ }
244251 if width > caps.max_extent.width
245252 || height > caps.max_extent.height
246253 || cfg.max_dpb_slots > caps.max_dpb_slots
@@ -275,6 +282,7 @@ impl H264DecodeSession {
275282 )?;
276283 Ok(H264DecodeSession {
277284 dec,
285+ min_extent: caps.min_extent,
278286 sps: Vec::new(),
279287 })
280288 }
@@ -347,6 +355,11 @@ impl H264DecodeSession {
347355 .find(|s| s.id == pic.sps_id)
348356 .ok_or_else(|| Error::Invalid(format!("unknown SPS {}", pic.sps_id)))?;
349357 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+ }
350363 if extent.width > self.dec.max_extent.width || extent.height > self.dec.max_extent.height {
351364 return Err(Error::Invalid("picture larger than session".into()));
352365 }
@@ -524,6 +537,7 @@ fn query_caps(gpu: &Gpu, profile: &vk::VideoProfileInfoKHR) -> Result<Caps, Erro
524537 let decode = decode.build();
525538 Ok(Caps {
526539 std_header_version: caps.std_header_version,
540+ min_extent: caps.min_coded_extent,
527541 max_extent: caps.max_coded_extent,
528542 size_align: caps.min_bitstream_buffer_size_alignment,
529543 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,