forge
Explore
Log in

Don't you dare go Hollow

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

Browse files at this commit

d24d8b03554f48ed020b1744fae8e2b649e849c0Ahmet Kaan GümüşParent: 5d36862
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.rsmodified+11 -0
@@ -235,6 +235,17 @@ impl Av1Decoder {
235235
236236 fn ensure_session(&mut self, seq: &SequenceHeader, header: &FrameHeader) -> Result<()> {
237237 let bit_depth = seq.color_config.bit_depth;
238+ let color = &seq.color_config;
239+ if color.mono_chrome
240+ || bit_depth == 12
241+ || color.subsampling_x != 1
242+ || color.subsampling_y != 1
243+ {
244+ return Err(Error::unsupported(
245+ "AV1 hardware decode",
246+ "only 4:2:0 8- and 10-bit",
247+ ));
248+ }
238249 let profile = match (seq.seq_profile, bit_depth) {
239250 (0, _) => Profile::AV1Profile0,
240251 (2, _) => Profile::AV1Profile2,
crates/ec-hw/src/output.rsmodified+7 -3
@@ -282,7 +282,11 @@ impl VkPicture {
282282 }
283283
284284 fn read(&self) -> Result<(Vec<u8>, Vec<u8>)> {
285- self.surfaces.nv12(self.slot.index, self.width, self.height)
285+ self.surfaces.nv12(
286+ self.slot.index,
287+ self.width.next_multiple_of(2),
288+ self.height.next_multiple_of(2),
289+ )
286290 }
287291
288292 fn i420(&self) -> Result<I420> {
@@ -291,7 +295,7 @@ impl VkPicture {
291295 self.bit_depth,
292296 &y,
293297 &uv,
294- self.width as usize,
298+ self.width.next_multiple_of(2) as usize,
295299 (0, 0),
296300 (self.width, self.height),
297301 )?;
@@ -307,7 +311,7 @@ impl VkPicture {
307311 self.bit_depth,
308312 &y,
309313 &uv,
310- self.width as usize,
314+ self.width.next_multiple_of(2) as usize,
311315 (0, 0),
312316 (self.width, self.height),
313317 )?;
crates/ec-hw/src/vkdec_av1.rsmodified+7 -6
@@ -135,7 +135,7 @@ impl VkAv1Decoder {
135135 .sequence_header()
136136 .cloned()
137137 .ok_or_else(|| Error::config("AV1 frame before any sequence header"))?;
138- check_supported(&seq, header)?;
138+ check_supported(&seq)?;
139139 let (width, height) = (header.upscaled_width, header.frame_height);
140140 self.ensure_session(&seq, width, height)?;
141141
@@ -182,7 +182,10 @@ impl VkAv1Decoder {
182182 .ring
183183 .borrow_mut()
184184 .take(|| Ok(session.av1.borrow_mut().add_ring_slot()?))?;
185- session.av1.borrow_mut().store_output(slot.index(), (0, 0, width, height))?;
185+ session.av1.borrow_mut().store_output(
186+ slot.index(),
187+ (0, 0, width.next_multiple_of(2), height.next_multiple_of(2)),
188+ )?;
186189 let codes = Tags::from_codes(u64::from(seq.color_config.matrix_coefficients), 0, 0);
187190 let matrix = ColorDescription::resolve(Tags::default(), codes, height).matrix;
188191 let decoded = VkPicture::new(
@@ -201,6 +204,7 @@ impl VkAv1Decoder {
201204 sign_bias: sign_bias(&header.ref_frame_sign_bias),
202205 disable_frame_end_update_cdf: header.disable_frame_end_update_cdf,
203206 segmentation_enabled: header.segmentation.enabled,
207+ extent: (width, height),
204208 };
205209 if header.show_frame {
206210 let shown = decoded.with_grain(&header.film_grain, &seq);
@@ -263,7 +267,7 @@ impl VkAv1Decoder {
263267 }
264268 }
265269
266-fn check_supported(seq: &SequenceHeader, header: &FrameHeader) -> Result<()> {
270+fn check_supported(seq: &SequenceHeader) -> Result<()> {
267271 let c = &seq.color_config;
268272 if seq.seq_profile != 0
269273 || !matches!(c.bit_depth, 8 | 10)
@@ -276,9 +280,6 @@ fn check_supported(seq: &SequenceHeader, header: &FrameHeader) -> Result<()> {
276280 "only Main 8- and 10-bit 4:2:0",
277281 ));
278282 }
279- if header.upscaled_width % 2 != 0 || header.frame_height % 2 != 0 {
280- return Err(Error::unsupported("Vulkan AV1 decode", "odd frame size"));
281- }
282283 Ok(())
283284 }
284285
shims/vk-video-ffi/src/av1_decode.rsmodified+20 -3
@@ -438,6 +438,8 @@ pub struct Av1RefSlot {
438438 pub disable_frame_end_update_cdf: bool,
439439 /// segmentation_enabled of the picture in the slot.
440440 pub segmentation_enabled: bool,
441+ /// Upscaled width and frame height of the picture in the slot.
442+ pub extent: (u32, u32),
441443 }
442444
443445 /// One frame to decode, with the tile data as one buffer.
@@ -728,7 +730,18 @@ impl Av1DecodeSession {
728730 .dec
729731 .dpb
730732 .iter()
731- .map(|i| picture_resource(i.view, extent))
733+ .enumerate()
734+ .map(|(slot, i)| {
735+ let size = pic
736+ .refs
737+ .iter()
738+ .find(|r| r.slot as usize == slot)
739+ .map_or(extent, |r| vk::Extent2D {
740+ width: r.extent.0,
741+ height: r.extent.1,
742+ });
743+ picture_resource(i.view, size)
744+ })
732745 .collect();
733746
734747 let setup_std = ref_info(
@@ -1063,14 +1076,18 @@ fn std_loop_filter(l: &Av1LoopFilter) -> vk::video::StdVideoAV1LoopFilter {
10631076 }
10641077 }
10651078
1079+fn raw_sec_strength(s: [u8; 8]) -> [u8; 8] {
1080+ s.map(|v| if v == 4 { 3 } else { v })
1081+}
1082+
10661083 fn std_cdef(c: &Av1Cdef) -> vk::video::StdVideoAV1CDEF {
10671084 vk::video::StdVideoAV1CDEF {
10681085 cdef_damping_minus_3: c.damping_minus_3,
10691086 cdef_bits: c.bits,
10701087 cdef_y_pri_strength: c.y_pri,
1071- cdef_y_sec_strength: c.y_sec,
1088+ cdef_y_sec_strength: raw_sec_strength(c.y_sec),
10721089 cdef_uv_pri_strength: c.uv_pri,
1073- cdef_uv_sec_strength: c.uv_sec,
1090+ cdef_uv_sec_strength: raw_sec_strength(c.uv_sec),
10741091 }
10751092 }
10761093