forge
Explore
Log in

Don't you dare go Hollow

A same-size reference at a height that is not a multiple of 8 was refused, and loop restoration ran over the mi-rounded plane instead of the cropped one

Browse files at this commit

570d0991b35d3db5ee965dbe9293343bdffc76b8Ahmet Kaan GümüşParent: 733770a
  • fix
    • a same-size reference at a height that is not a multiple of 8 was refused, and loop restoration ran over the mi-rounded plane instead of the cropped one
Show full message
fix(av1): a same-size reference at a height that is not a multiple of 8 was refused, and loop restoration ran over the mi-rounded plane instead of the cropped one

Two true-size-vs-mi-rounded defects (class av1-truesize-lane), both found by
the (192,68)/(68,192) straddling arms lane-golomb r7 measured but could not add.

1. decode.rs `decode_inter_frame_tile_with_cdfs` compared the reference
   picture's height against `true_height = mi_rows * 4` (the mi-rounded
   size). A decoded `Picture` is cropped to the header's `fh`, so for any
   height that is not a multiple of 8 (68 -> mi_rows 18 -> 72) this compared
   68 against 72 and refused EVERY same-size reference by name ("a reference
   picture whose height does not match this frame's own true size"). libaom
   compares references on the CROPPED dimensions --
   `av1_setup_scale_factors_for_frame(&sf, ref->y_crop_width,
   ref->y_crop_height, cm->width, cm->height)` -- and calls a reference
   scaled only when those differ. Height must still match: AV1 superres never
   scales height. MEASURED: with `arms.push((192, 68, 5, false))` all eight cq
   attempts refused before this commit; after it none do (they now stop at
   another lane's inter SB-level AB partition, or reach a compare).

2. `apply_loop_restoration` passed each plane's `true_width`/`true_height`.
   LR is the one post-decode filter that does NOT walk the mi grid: libaom
   sizes every plane with `av1_get_upsampled_plane_size`
   (av1/common/restoration.c:47), asserts it equals the buffer's crop width
   (restoration.c:1106) and extends the border from that cropped edge
   (restoration.c:1109) before filtering. Deblock and CDEF do walk the mi
   grid, which is why this went unnoticed until a non-multiple-of-8 size.
   NOT exercised by any gate here: every straddle gate recipe runs
   `--enable-restoration=0`. Source-cited only.

edge32 gate stays green on the merged tree: 38 pixel-exact attempts, 64-level
edge bits [horz_or_vert=7 split=197] right-VERT=7, 2 named refusals, all eight
cq levels at both depths.
crates/ec-av1/src/decode.rsmodified+43 -9
@@ -12798,13 +12798,30 @@ fn apply_loop_restoration(
12798 deblocked_v: &PlaneBuf,12798 deblocked_v: &PlaneBuf,
12799 lr: &LoopRestorationParams,12799 lr: &LoopRestorationParams,
12800 grid: &crate::restoration::RestorationGrid,12800 grid: &crate::restoration::RestorationGrid,
12801+ // lane-golomb r8: this frame header's own (cropped) luma size. Loop
12802+ // restoration is the ONE post-decode filter that does NOT run over the
12803+ // mi-rounded plane: libaom's `av1_loop_restoration_filter_frame` sizes
12804+ // every plane with `av1_get_upsampled_plane_size` -- `plane_w =
12805+ // ROUND_POWER_OF_TWO(cm->superres_upscaled_width, ss_x)`, `plane_h =
12806+ // ROUND_POWER_OF_TWO(cm->height, ss_y)` (`av1/common/restoration.c:47`)
12807+ // -- and asserts it equals the buffer's CROP width
12808+ // (`restoration.c:1106`), then `av1_extend_frame(..., plane_w, plane_h,
12809+ // ...)` (`restoration.c:1109`) replicates the right/bottom border from
12810+ // that cropped edge before any unit is filtered. Deblock and CDEF DO
12811+ // walk the mi grid, which is why passing `true_width`/`true_height`
12812+ // here went unnoticed until a frame whose size is not a multiple of 8
12813+ // (68 -> mi-rounded 72): the LR taps at the last four real columns then
12814+ // read this decoder's own decoded samples at columns 68..71 where
12815+ // libaom reads column 67 replicated -- +-1 over the straddling band
12816+ // (class av1-truesize-lane: true frame size vs mi-rounded).
12817+ (frame_w, frame_h): (usize, usize),
12801 ) {12818 ) {
12802 y.data = crate::restoration::apply_loop_restoration_plane(12819 y.data = crate::restoration::apply_loop_restoration_plane(
12803 &y.data,12820 &y.data,
12804 &deblocked_y.data,12821 &deblocked_y.data,
12805 y.width,12822 y.width,
12806- y.true_width,12823+ frame_w,
12807- y.true_height,12824+ frame_h,
12808 0,12825 0,
12809 lr.frame_restoration_type[0],12826 lr.frame_restoration_type[0],
12810 lr.loop_restoration_size[0],12827 lr.loop_restoration_size[0],
@@ -12815,8 +12832,8 @@ fn apply_loop_restoration(
12815 &u.data,12832 &u.data,
12816 &deblocked_u.data,12833 &deblocked_u.data,
12817 u.width,12834 u.width,
12818- u.true_width,12835+ frame_w.div_ceil(2),
12819- u.true_height,12836+ frame_h.div_ceil(2),
12820 1,12837 1,
12821 lr.frame_restoration_type[1],12838 lr.frame_restoration_type[1],
12822 lr.loop_restoration_size[1],12839 lr.loop_restoration_size[1],
@@ -12827,8 +12844,8 @@ fn apply_loop_restoration(
12827 &v.data,12844 &v.data,
12828 &deblocked_v.data,12845 &deblocked_v.data,
12829 v.width,12846 v.width,
12830- v.true_width,12847+ frame_w.div_ceil(2),
12831- v.true_height,12848+ frame_h.div_ceil(2),
12832 1,12849 1,
12833 lr.frame_restoration_type[2],12850 lr.frame_restoration_type[2],
12834 lr.loop_restoration_size[2],12851 lr.loop_restoration_size[2],
@@ -14837,7 +14854,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
14837 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);14854 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
14838 dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);14855 dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);
14839 dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);14856 dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
14840- apply_loop_restoration(&mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid);14857+ apply_loop_restoration(
14858+ &mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid,
14859+ (frame_width as usize, frame_height as usize),
14860+ );
14841 14861
14842 let (fw, fh) = (frame_width as usize, frame_height as usize);14862 let (fw, fh) = (frame_width as usize, frame_height as usize);
14843 if fw == width && fh == height {14863 if fw == width && fh == height {
@@ -20713,7 +20733,18 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
20713 // true size. Height must still match: AV1 superres never scales height20733 // true size. Height must still match: AV1 superres never scales height
20714 // (r8's derivation, `mc.rs`'s own doc), and nothing in this decode path20734 // (r8's derivation, `mc.rs`'s own doc), and nothing in this decode path
20715 // has a vertical scaling pass.20735 // has a vertical scaling pass.
20716- if reference.height != true_height {20736+ // lane-golomb r8: the comparison is against the header's own frame
20737+ // height, NOT the mi-rounded `true_height`. libaom compares references
20738+ // on the CROPPED dimensions -- `av1_setup_scale_factors_for_frame(&sf,
20739+ // ref->y_crop_width, ref->y_crop_height, cm->width, cm->height)`
20740+ // (`av1/common/reconinter.c`), and a reference is "scaled" only when
20741+ // those differ (`av1_is_scaled`). A decoded `Picture` is cropped to
20742+ // `fw`/`fh`, so for any height that is not a multiple of 8 (68 ->
20743+ // mi_rows 18 -> `true_height` 72) this test compared 68 against 72 and
20744+ // refused every same-size reference (class av1-truesize-lane: true
20745+ // frame size vs mi-rounded). Height must still MATCH: AV1 superres
20746+ // never scales height, and no path here has a vertical scaling pass.
20747+ if reference.height != frame_height as usize {
20717 return Err(unsupported(20748 return Err(unsupported(
20718 "a reference picture whose height does not match this frame's own true size",20749 "a reference picture whose height does not match this frame's own true size",
20719 ));20750 ));
@@ -22663,7 +22694,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
22663 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);22694 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
22664 dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);22695 dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);
22665 dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);22696 dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
22666- apply_loop_restoration(&mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid);22697+ apply_loop_restoration(
22698+ &mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid,
22699+ (frame_width as usize, frame_height as usize),
22700+ );
22667 22701
22668 let motion_field = build_motion_field(22702 let motion_field = build_motion_field(
22669 &grid,22703 &grid,
crates/ec-av1/src/stream.rsmodified+28 -0
@@ -18888,6 +18888,28 @@ mod tests {
18888 // The inter arm: >= 4 frames so the 32-level edge path in the INTER18888 // The inter arm: >= 4 frames so the 32-level edge path in the INTER
18889 // tile walk is exercised too.18889 // tile walk is exercised too.
18890 arms.push((192, 80, 5, false));18890 arms.push((192, 80, 5, false));
18891+ // lane-golomb r8 MEASURED, arm STILL NOT added (every cq level is
18892+ // vacuous, panicking or red -- each measured this round with
18893+ // `arms.push((192, 68, 5, false))`, log
18894+ // `$HOME/.cache/golomb-gate-r8{b,e,f,g}.log`):
18895+ // * the r7 blocker IS fixed -- no attempt refuses "a reference
18896+ // picture whose height does not match this frame's own true
18897+ // size" any more (`decode.rs`'s comparison now uses the header's
18898+ // frame height, per libaom's crop-dimension reference test).
18899+ // * cq35 now refuses LATER, by another lane's name: "an inter
18900+ // SB-level AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B)" -- so the
18901+ // arm compares nothing (class `counter-from-refused-stream`).
18902+ // * cq40 PANICS in `decode_inter_block8`
18903+ // (`from_switchable_symbol` handed a 4th symbol, `mc.rs:203`) =
18904+ // lane-sub8's own open below-8x8 desync; a panic cannot be
18905+ // tolerated as a named refusal.
18906+ // * cq59 8-bit is RED: `frame 1 plane Y: 217 pixels differ, first
18907+ // at row 60 col 170 (ours 172 vs ffmpeg 173)`, and the cq35
18908+ // 10-bit twin is RED at `row 56 col 48 (ours 530 vs ffmpeg
18909+ // 531)`. Both are +-1 bands in rows 56..63, i.e. the deblock/CDEF
18910+ // bleed ABOVE the 4-px straddling row band (64..67) -- the same
18911+ // shape as the `(68, 192, 5, false)` column defect below, so the
18912+ // two are very likely ONE straddling-band reconstruction defect.
18891 // lane-golomb r7 MEASURED, arm NOT added (it would be vacuous or red):18913 // lane-golomb r7 MEASURED, arm NOT added (it would be vacuous or red):
18892 // a 68-px axis leaves the last superblock straddling by 4 px, the18914 // a 68-px axis leaves the last superblock straddling by 4 px, the
18893 // shape `read_var_tx_size`'s `blk_row >= max_h_mi || blk_col >=18915 // shape `read_var_tx_size`'s `blk_row >= max_h_mi || blk_col >=
@@ -19010,6 +19032,12 @@ mod tests {
19010 }19032 }
19011 let tag = format!("{width}x{height} cq{cq} frames={frame_count} 10bit={ten_bit}");19033 let tag = format!("{width}x{height} cq{cq} frames={frame_count} 10bit={ten_bit}");
19012 let before = crate::decode::edge32_hits();19034 let before = crate::decode::edge32_hits();
19035+ // lane-golomb r8: name the attempt BEFORE decoding it -- a
19036+ // desync surfaces as a panic deep in mc.rs with no arm in the
19037+ // message, and r8 spent a run bisecting arms by hand.
19038+ if std::env::var_os("EC_GATE_VERBOSE").is_some() {
19039+ eprintln!("{NAME}: attempting {tag}");
19040+ }
19013 let decoded = match decode_stream(&stream) {19041 let decoded = match decode_stream(&stream) {
19014 Ok(frames) => frames,19042 Ok(frames) => frames,
19015 Err(e) => {19043 Err(e) => {