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(
1279812798 deblocked_v: &PlaneBuf,
1279912799 lr: &LoopRestorationParams,
1280012800 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),
1280112818 ) {
1280212819 y.data = crate::restoration::apply_loop_restoration_plane(
1280312820 &y.data,
1280412821 &deblocked_y.data,
1280512822 y.width,
12806- y.true_width,
12807- y.true_height,
12823+ frame_w,
12824+ frame_h,
1280812825 0,
1280912826 lr.frame_restoration_type[0],
1281012827 lr.loop_restoration_size[0],
@@ -12815,8 +12832,8 @@ fn apply_loop_restoration(
1281512832 &u.data,
1281612833 &deblocked_u.data,
1281712834 u.width,
12818- u.true_width,
12819- u.true_height,
12835+ frame_w.div_ceil(2),
12836+ frame_h.div_ceil(2),
1282012837 1,
1282112838 lr.frame_restoration_type[1],
1282212839 lr.loop_restoration_size[1],
@@ -12827,8 +12844,8 @@ fn apply_loop_restoration(
1282712844 &v.data,
1282812845 &deblocked_v.data,
1282912846 v.width,
12830- v.true_width,
12831- v.true_height,
12847+ frame_w.div_ceil(2),
12848+ frame_h.div_ceil(2),
1283212849 1,
1283312850 lr.frame_restoration_type[2],
1283412851 lr.loop_restoration_size[2],
@@ -14837,7 +14854,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1483714854 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
1483814855 dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);
1483914856 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+ );
1484114861
1484214862 let (fw, fh) = (frame_width as usize, frame_height as usize);
1484314863 if fw == width && fh == height {
@@ -20713,7 +20733,18 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2071320733 // true size. Height must still match: AV1 superres never scales height
2071420734 // (r8's derivation, `mc.rs`'s own doc), and nothing in this decode path
2071520735 // 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 {
2071720748 return Err(unsupported(
2071820749 "a reference picture whose height does not match this frame's own true size",
2071920750 ));
@@ -22663,7 +22694,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2266322694 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
2266422695 dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);
2266522696 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+ );
2266722701
2266822702 let motion_field = build_motion_field(
2266922703 &grid,
crates/ec-av1/src/stream.rsmodified+28 -0
@@ -18888,6 +18888,28 @@ mod tests {
1888818888 // The inter arm: >= 4 frames so the 32-level edge path in the INTER
1888918889 // tile walk is exercised too.
1889018890 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.
1889118913 // lane-golomb r7 MEASURED, arm NOT added (it would be vacuous or red):
1889218914 // a 68-px axis leaves the last superblock straddling by 4 px, the
1889318915 // shape `read_var_tx_size`'s `blk_row >= max_h_mi || blk_col >=
@@ -19010,6 +19032,12 @@ mod tests {
1901019032 }
1901119033 let tag = format!("{width}x{height} cq{cq} frames={frame_count} 10bit={ten_bit}");
1901219034 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+ }
1901319041 let decoded = match decode_stream(&stream) {
1901419042 Ok(frames) => frames,
1901519043 Err(e) => {