From d24d8b03554f48ed020b1744fae8e2b649e849c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 25 Nov 2026 22:44:33 +0300 Subject: [PATCH] ec-hw AV1 Vulkan: raw CDEF secondary strength, per-slot reference extents, odd frame sizes; VA refuses mono, 12-bit and non-4:2:0 Vulkan std CDEF takes the coded 2-bit secondary strength (3 means 4), so the parser's adjusted value is mapped back before upload. This fixes the SVT-AV1 mismatches (lag0, hier3, grain, superres, resize). Reference picture resources carry each slot's own size, clearing the DPB association validation error on resized streams. Odd frame sizes decode at their real size; readback and I420 use the even-rounded pitch. The VA AV1 path refuses monochrome, 12-bit and 4:2:2/4:4:4 cleanly. --- crates/ec-hw/src/dec/av1.rs | 11 +++++++++++ crates/ec-hw/src/output.rs | 10 +++++++--- crates/ec-hw/src/vkdec_av1.rs | 13 +++++++------ shims/vk-video-ffi/src/av1_decode.rs | 23 ++++++++++++++++++++--- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/crates/ec-hw/src/dec/av1.rs b/crates/ec-hw/src/dec/av1.rs index dbbbfdf9..931ae93f 100644 --- a/crates/ec-hw/src/dec/av1.rs +++ b/crates/ec-hw/src/dec/av1.rs @@ -235,6 +235,17 @@ impl Av1Decoder { fn ensure_session(&mut self, seq: &SequenceHeader, header: &FrameHeader) -> Result<()> { let bit_depth = seq.color_config.bit_depth; + let color = &seq.color_config; + if color.mono_chrome + || bit_depth == 12 + || color.subsampling_x != 1 + || color.subsampling_y != 1 + { + return Err(Error::unsupported( + "AV1 hardware decode", + "only 4:2:0 8- and 10-bit", + )); + } let profile = match (seq.seq_profile, bit_depth) { (0, _) => Profile::AV1Profile0, (2, _) => Profile::AV1Profile2, diff --git a/crates/ec-hw/src/output.rs b/crates/ec-hw/src/output.rs index c285afc7..6f49c7ff 100644 --- a/crates/ec-hw/src/output.rs +++ b/crates/ec-hw/src/output.rs @@ -282,7 +282,11 @@ impl VkPicture { } fn read(&self) -> Result<(Vec, Vec)> { - self.surfaces.nv12(self.slot.index, self.width, self.height) + self.surfaces.nv12( + self.slot.index, + self.width.next_multiple_of(2), + self.height.next_multiple_of(2), + ) } fn i420(&self) -> Result { @@ -291,7 +295,7 @@ impl VkPicture { self.bit_depth, &y, &uv, - self.width as usize, + self.width.next_multiple_of(2) as usize, (0, 0), (self.width, self.height), )?; @@ -307,7 +311,7 @@ impl VkPicture { self.bit_depth, &y, &uv, - self.width as usize, + self.width.next_multiple_of(2) as usize, (0, 0), (self.width, self.height), )?; diff --git a/crates/ec-hw/src/vkdec_av1.rs b/crates/ec-hw/src/vkdec_av1.rs index 2305652b..d24ef8b0 100644 --- a/crates/ec-hw/src/vkdec_av1.rs +++ b/crates/ec-hw/src/vkdec_av1.rs @@ -135,7 +135,7 @@ impl VkAv1Decoder { .sequence_header() .cloned() .ok_or_else(|| Error::config("AV1 frame before any sequence header"))?; - check_supported(&seq, header)?; + check_supported(&seq)?; let (width, height) = (header.upscaled_width, header.frame_height); self.ensure_session(&seq, width, height)?; @@ -182,7 +182,10 @@ impl VkAv1Decoder { .ring .borrow_mut() .take(|| Ok(session.av1.borrow_mut().add_ring_slot()?))?; - session.av1.borrow_mut().store_output(slot.index(), (0, 0, width, height))?; + session.av1.borrow_mut().store_output( + slot.index(), + (0, 0, width.next_multiple_of(2), height.next_multiple_of(2)), + )?; let codes = Tags::from_codes(u64::from(seq.color_config.matrix_coefficients), 0, 0); let matrix = ColorDescription::resolve(Tags::default(), codes, height).matrix; let decoded = VkPicture::new( @@ -201,6 +204,7 @@ impl VkAv1Decoder { sign_bias: sign_bias(&header.ref_frame_sign_bias), disable_frame_end_update_cdf: header.disable_frame_end_update_cdf, segmentation_enabled: header.segmentation.enabled, + extent: (width, height), }; if header.show_frame { let shown = decoded.with_grain(&header.film_grain, &seq); @@ -263,7 +267,7 @@ impl VkAv1Decoder { } } -fn check_supported(seq: &SequenceHeader, header: &FrameHeader) -> Result<()> { +fn check_supported(seq: &SequenceHeader) -> Result<()> { let c = &seq.color_config; if seq.seq_profile != 0 || !matches!(c.bit_depth, 8 | 10) @@ -276,9 +280,6 @@ fn check_supported(seq: &SequenceHeader, header: &FrameHeader) -> Result<()> { "only Main 8- and 10-bit 4:2:0", )); } - if header.upscaled_width % 2 != 0 || header.frame_height % 2 != 0 { - return Err(Error::unsupported("Vulkan AV1 decode", "odd frame size")); - } Ok(()) } diff --git a/shims/vk-video-ffi/src/av1_decode.rs b/shims/vk-video-ffi/src/av1_decode.rs index cb34f992..dc009b4e 100644 --- a/shims/vk-video-ffi/src/av1_decode.rs +++ b/shims/vk-video-ffi/src/av1_decode.rs @@ -438,6 +438,8 @@ pub struct Av1RefSlot { pub disable_frame_end_update_cdf: bool, /// segmentation_enabled of the picture in the slot. pub segmentation_enabled: bool, + /// Upscaled width and frame height of the picture in the slot. + pub extent: (u32, u32), } /// One frame to decode, with the tile data as one buffer. @@ -728,7 +730,18 @@ impl Av1DecodeSession { .dec .dpb .iter() - .map(|i| picture_resource(i.view, extent)) + .enumerate() + .map(|(slot, i)| { + let size = pic + .refs + .iter() + .find(|r| r.slot as usize == slot) + .map_or(extent, |r| vk::Extent2D { + width: r.extent.0, + height: r.extent.1, + }); + picture_resource(i.view, size) + }) .collect(); let setup_std = ref_info( @@ -1063,14 +1076,18 @@ fn std_loop_filter(l: &Av1LoopFilter) -> vk::video::StdVideoAV1LoopFilter { } } +fn raw_sec_strength(s: [u8; 8]) -> [u8; 8] { + s.map(|v| if v == 4 { 3 } else { v }) +} + fn std_cdef(c: &Av1Cdef) -> vk::video::StdVideoAV1CDEF { vk::video::StdVideoAV1CDEF { cdef_damping_minus_3: c.damping_minus_3, cdef_bits: c.bits, cdef_y_pri_strength: c.y_pri, - cdef_y_sec_strength: c.y_sec, + cdef_y_sec_strength: raw_sec_strength(c.y_sec), cdef_uv_pri_strength: c.uv_pri, - cdef_uv_sec_strength: c.uv_sec, + cdef_uv_sec_strength: raw_sec_strength(c.uv_sec), } }