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 {
261 profile_idc: sps.profile_idc,261 profile_idc: sps.profile_idc,
262 chroma_format_idc: chroma,262 chroma_format_idc: chroma,
263 },263 },
264- )?;264+ )
265+ .map_err(refused)?;
265 let ring = Ring::new(h264.ring_len());266 let ring = Ring::new(h264.ring_len());
266 self.session = Some(Session {267 self.session = Some(Session {
267 h264: Rc::new(RefCell::new(h264)),268 h264: Rc::new(RefCell::new(h264)),
@@ -347,7 +348,8 @@ impl VkH264Decoder {
347 setup_slot: current.slot,348 setup_slot: current.slot,
348 refs: &refs,349 refs: &refs,
349 slices: &slices,350 slices: &slices,
350- })?;351+ })
352+ .map_err(refused)?;
351 let (left, _, top, _) = sps.crop;353 let (left, _, top, _) = sps.crop;
352 session354 session
353 .h264355 .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 fn field_pocs(poc: i32, delta_bottom: i32) -> [i32; 2] {420 fn field_pocs(poc: i32, delta_bottom: i32) -> [i32; 2] {
412 [poc - delta_bottom.min(0), poc + delta_bottom.max(0)]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 struct Caps {163 struct Caps {
164 std_header_version: vk::ExtensionProperties,164 std_header_version: vk::ExtensionProperties,
165+ min_extent: vk::Extent2D,
165 max_extent: vk::Extent2D,166 max_extent: vk::Extent2D,
166 size_align: u64,167 size_align: u64,
167 max_dpb_slots: u32,168 max_dpb_slots: u32,
@@ -201,6 +202,7 @@ impl Profile {
201 /// An H.264 Vulkan Video decode session: NV12 DPB images per slot and a separate NV12 output image.202 /// An H.264 Vulkan Video decode session: NV12 DPB images per slot and a separate NV12 output image.
202 pub struct H264DecodeSession {203 pub struct H264DecodeSession {
203 dec: Decoder,204 dec: Decoder,
205+ min_extent: vk::Extent2D,
204 sps: Vec<H264Sps>,206 sps: Vec<H264Sps>,
205 }207 }
206 208
@@ -241,6 +243,11 @@ impl H264DecodeSession {
241 let height = align(cfg.max_height, 16);243 let height = align(cfg.max_height, 16);
242 let profile = Profile::new(cfg.profile_idc, cfg.chroma_format_idc);244 let profile = Profile::new(cfg.profile_idc, cfg.chroma_format_idc);
243 let caps = query_caps(gpu, &profile.info)?;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 if width > caps.max_extent.width251 if width > caps.max_extent.width
245 || height > caps.max_extent.height252 || height > caps.max_extent.height
246 || cfg.max_dpb_slots > caps.max_dpb_slots253 || cfg.max_dpb_slots > caps.max_dpb_slots
@@ -275,6 +282,7 @@ impl H264DecodeSession {
275 )?;282 )?;
276 Ok(H264DecodeSession {283 Ok(H264DecodeSession {
277 dec,284 dec,
285+ min_extent: caps.min_extent,
278 sps: Vec::new(),286 sps: Vec::new(),
279 })287 })
280 }288 }
@@ -347,6 +355,11 @@ impl H264DecodeSession {
347 .find(|s| s.id == pic.sps_id)355 .find(|s| s.id == pic.sps_id)
348 .ok_or_else(|| Error::Invalid(format!("unknown SPS {}", pic.sps_id)))?;356 .ok_or_else(|| Error::Invalid(format!("unknown SPS {}", pic.sps_id)))?;
349 let extent = coded_extent(sps);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 if extent.width > self.dec.max_extent.width || extent.height > self.dec.max_extent.height {363 if extent.width > self.dec.max_extent.width || extent.height > self.dec.max_extent.height {
351 return Err(Error::Invalid("picture larger than session".into()));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 let decode = decode.build();537 let decode = decode.build();
525 Ok(Caps {538 Ok(Caps {
526 std_header_version: caps.std_header_version,539 std_header_version: caps.std_header_version,
540+ min_extent: caps.min_coded_extent,
527 max_extent: caps.max_coded_extent,541 max_extent: caps.max_coded_extent,
528 size_align: caps.min_bitstream_buffer_size_alignment,542 size_align: caps.min_bitstream_buffer_size_alignment,
529 max_dpb_slots: caps.max_dpb_slots,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 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,