forge
Explore
Log in

Don't you dare go Hollow

Deblock clips to coded frame_width/height, not the mi-aligned margin

Browse files at this commit

81df7353882c4723a04647cef0bc4fd5633aa899Ahmet Kaan GümüşParent: 23731fa
  • fix
    • deblock clips to coded frame_width/height, not the mi-aligned margin
Show full message
fix(av1): deblock clips to coded frame_width/height, not the mi-aligned margin

Charter hypothesis 1 confirmed: libaom's loop filter never visits the
padding between the coded frame_width/height and the next mi-aligned
true_width/true_height (the margin reconstruction still fills but the
filter loop skips). deblock_plane/apply_deblock now bound their x0/y0
loops by frame_width/frame_height (frame_height.div_ceil(2) for chroma),
closing the superres gate: a_real_aomenc_superres_key_frame_sequence_
decodes_pixel_exact now passes (3/3 frames, superres_hits=3). Full
ec-av1 suite: 238 passed, 0 failed, 17 ignored -- no regression.
crates/ec-av1/src/decode.rsmodified+49 -7
@@ -3755,15 +3755,17 @@ fn apply_deblock(
37553755 v: &mut PlaneBuf,
37563756 lf: &LoopFilterParams,
37573757 n: &Neighbours,
3758+ frame_width: usize,
3759+ frame_height: usize,
37583760 ) {
37593761 if lf.level[0] != 0 || lf.level[1] != 0 {
3760- deblock_plane(y, 0, lf, n);
3762+ deblock_plane(y, 0, lf, n, frame_width, frame_height);
37613763 }
37623764 if lf.level[2] != 0 {
3763- deblock_plane(u, 1, lf, n);
3765+ deblock_plane(u, 1, lf, n, frame_width, frame_height);
37643766 }
37653767 if lf.level[3] != 0 {
3766- deblock_plane(v, 2, lf, n);
3768+ deblock_plane(v, 2, lf, n, frame_width, frame_height);
37673769 }
37683770 }
37693771
@@ -4265,9 +4267,33 @@ fn filter_edge(
42654267
42664268 /// One plane's worth of spec 7.14: every vertical edge across the plane,
42674269 /// then every horizontal edge (the order the spec and libaom both use).
4268-fn deblock_plane(plane: &mut PlaneBuf, plane_idx: usize, lf: &LoopFilterParams, n: &Neighbours) {
4270+fn deblock_plane(
4271+ plane: &mut PlaneBuf,
4272+ plane_idx: usize,
4273+ lf: &LoopFilterParams,
4274+ n: &Neighbours,
4275+ frame_width: usize,
4276+ frame_height: usize,
4277+) {
42694278 let chroma = plane_idx != 0;
4270- let (tw, th, stride) = (plane.true_width, plane.true_height, plane.width);
4279+ // r7: libaom clips the deblock loop to the CODED frame's own
4280+ // width/height, not the mi-aligned `true_width`/`true_height` margin
4281+ // (the padding up to the next 8-pixel/superblock boundary that
4282+ // reconstruction still fills in but the loop filter never visits).
4283+ // Confirmed against the superres gate: with the margin included, the
4284+ // last coded mi column's horizontal edges were filtered when libaom's
4285+ // real output leaves them untouched (r6's post-deblock diff, 37 px, all
4286+ // in columns 44-47); clipping here closes it (3/3 frames pixel-exact).
4287+ let (cw, ch) = if chroma {
4288+ (frame_width.div_ceil(2), frame_height.div_ceil(2))
4289+ } else {
4290+ (frame_width, frame_height)
4291+ };
4292+ let (tw, th, stride) = (
4293+ plane.true_width.min(cw),
4294+ plane.true_height.min(ch),
4295+ plane.width,
4296+ );
42714297 let mut y0 = 0usize;
42724298 while y0 < th {
42734299 let mut x0 = 4usize;
@@ -5005,7 +5031,15 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
50055031 let _ = f.write_all(&crop_wide(&v));
50065032 }
50075033 }
5008- apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours);
5034+ apply_deblock(
5035+ &mut y,
5036+ &mut u,
5037+ &mut v,
5038+ loop_filter,
5039+ &neighbours,
5040+ frame_width as usize,
5041+ frame_height as usize,
5042+ );
50095043 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
50105044
50115045 let (fw, fh) = (frame_width as usize, frame_height as usize);
@@ -10544,7 +10578,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
1054410578 } else {
1054510579 PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
1054610580 }
10547- apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours);
10581+ apply_deblock(
10582+ &mut y,
10583+ &mut u,
10584+ &mut v,
10585+ loop_filter,
10586+ &neighbours,
10587+ frame_width as usize,
10588+ frame_height as usize,
10589+ );
1054810590 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
1054910591
1055010592 let motion_field = build_motion_field(