From e9f1fa85c2fda7f0e94ad5bfa42288e5c350f28d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 15:45:57 +0300 Subject: [PATCH] wip(av1): superres stage-3 gate flags + chroma crop rounding fix Gate a_real_aomenc_superres_key_frame_sequence_decodes_pixel_exact: - add the restrictive aomenc flag set (charter's list) to get past the pre-existing "AV1 tile: partition type this encoder never writes" capability gap, plus --superres-kf-denominator=12 (the missing piece: --superres-denominator only controls non-key frames; with --kf-max-dist=0 every frame is a key frame and AOM_SUPERRES_FIXED reads superres_kf_scale_denominator for those, which defaults to 8/ no-scale -- header.use_superres was parsing false). - decode.rs: both decode_key_frame_tile_with_cdfs and decode_inter_frame_tile_with_cdfs cropped chroma to fw/2 (floor) when fw != the mi-aligned decode width; the real AV1 chroma-plane width formula is ROUND_POWER_OF_TWO(fw, ss_x) i.e. div_ceil for 4:2:0. Odd downscaled superres widths (43 here) exposed it as a length-mismatch panic in superres.rs; fixed both sites (general decoder bug, not superres-specific, swept repo-wide -- only these two call it). Gate still fails: 5/4096 luma pixels off by 1 near the right edge (columns 59-62 of 64) after the flag+crop fixes. Not bounds/kernel -- superres.rs's pinned upscale_row/upscale_plane already matched libaom bit-exact via the C harness for symmetric in8->out12/16 cases. Likely candidate: our edge-replication padding in upscale_row synthesizes the right border from the already-cropped fw-wide row, while libaom's av1_extend_plane may extend from real reconstructed pixels still present in the mi-aligned buffer beyond fw before any crop -- untested theory, not confirmed this round. Next: thread the pre-crop plane width/margin into upscale_picture instead of cropping to fw first. --- crates/ec-av1/src/decode.rs | 8 ++++---- crates/ec-av1/src/stream.rs | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index fc53c539..44090bbe 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -4990,8 +4990,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( width: fw, height: fh, y: crop(&y, fw, fh), - u: crop(&u, fw / 2, fh / 2), - v: crop(&v, fw / 2, fh / 2), + u: crop(&u, fw.div_ceil(2), fh.div_ceil(2)), + v: crop(&v, fw.div_ceil(2), fh.div_ceil(2)), }, cdfs, )) @@ -10501,8 +10501,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( width: fw, height: fh, y: crop(&y, fw, fh), - u: crop(&u, fw / 2, fh / 2), - v: crop(&v, fw / 2, fh / 2), + u: crop(&u, fw.div_ceil(2), fh.div_ceil(2)), + v: crop(&v, fw.div_ceil(2), fh.div_ceil(2)), }, cdfs, motion_field, diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index ea69cbac..02cb041c 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -3868,6 +3868,23 @@ mod tests { "--row-mt=0", "--superres-mode=1", "--superres-denominator=12", + "--superres-kf-denominator=12", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-filter-intra=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-directional-intra=0", + "--enable-angle-delta=0", + "--enable-tx-size-search=0", + "--enable-cdef=0", + "--enable-restoration=0", + "--max-partition-size=32", + "--min-partition-size=32", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-cfl-intra=0", "--obu", "-o", "-",