forge
Explore
Log in

Don't you dare go Hollow

The loop filter ignored spec 7.14.2's skip/pu_edge suppression, filtering a var-tx interior edge lattice the reference never touches

Browse files at this commit

99d520f01589fb5cb46da584312bc06038f01fa5Ahmet Kaan GümüşParent: 85dc25f
  • fix
    • the loop filter ignored spec 7.14.2's skip/pu_edge suppression, filtering a var-tx interior edge lattice the reference never touches
Show full message
fix(av1): the loop filter ignored spec 7.14.2's skip/pu_edge suppression, filtering a var-tx interior edge lattice the reference never touches

edge_params dropped the `!pv_skip || !curr_skipped || pu_edge` term on the invariant
"a coded block's transform is always its own full size", which var-tx broke: every 8-px
interior transform edge inside a skipped inter block was filtered. Adds a per-4x4-mi
coded-block-origin band (written alongside the skip flag) for the pu_edge term.

On the pinned 192x68 cq61 tile_cols=1 8-bit stream, decode-order frame 1 goes 7244 -> 0
wrong post-deblock luma px; its pre-filter reconstruction was already bit-exact, which
disproves the compound-prediction premise this round started from. The 1:4 rect-vartx
sibling gate stays green. The straddling gate still fails on a different, isolated
defect: decode frame 2 is wrong pre-filter in the x=96..127 column band.
crates/ec-av1/src/decode.rsmodified+33 -4
@@ -4200,6 +4200,12 @@ struct Neighbours {
42004200 /// granularity by [`apply_cdef`] since `skip` is constant across every
42014201 /// mi cell one coded block covers.
42024202 skip_grid: Vec<bool>,
4203+ /// Per-4x4-mi origin `(mi_row, mi_col)` of the coded (prediction) block
4204+ /// covering that cell -- spec 7.14.2's `isBlockEdge`/libaom `pu_edge`,
4205+ /// which re-enables the loop filter at a prediction boundary between two
4206+ /// skipped inter blocks (lane-mergefix r4). Written by
4207+ /// [`Self::fill_skip_grid_rect`], whose `at_mi` IS that origin.
4208+ blk_org_grid: Vec<[u16; 2]>,
42034209 skip_grid_cols_mi: usize,
42044210 /// Per-4x4-mi luma transform width in pixels (8/16/32/64) -- this decoder
42054211 /// never splits a coded block's transform below its own size (round 2:
@@ -4307,6 +4313,7 @@ impl Neighbours {
43074313 mi_cols,
43084314 mi_rows,
43094315 skip_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)],
4316+ blk_org_grid: vec![[0u16; 2]; cols * (SUB / MI) * rows * (SUB / MI)],
43104317 skip_grid_cols_mi: cols * (SUB / MI),
43114318 tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],
43124319 tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],
@@ -4720,12 +4727,13 @@ impl Neighbours {
47204727 let (mi_r, mi_c) = at_mi;
47214728 for rr in 0..h_mi {
47224729 for cc in 0..w_mi {
4723- if let Some(cell) = self
4724- .skip_grid
4725- .get_mut((mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc))
4726- {
4730+ let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc);
4731+ if let Some(cell) = self.skip_grid.get_mut(idx) {
47274732 *cell = skip;
47284733 }
4734+ if let Some(org) = self.blk_org_grid.get_mut(idx) {
4735+ *org = [mi_r as u16, mi_c as u16];
4736+ }
47294737 }
47304738 }
47314739 }
@@ -13321,6 +13329,27 @@ fn edge_params(
1332113329 let cur_delta_lf = i32::from(n.delta_lf_grid[mi_r * n.skip_grid_cols_mi + mi_c][delta_idx]);
1332213330 let pv_delta_lf = i32::from(n.delta_lf_grid[pv_mi_r * n.skip_grid_cols_mi + pv_mi_c][delta_idx]);
1332313331
13332+ // spec 7.14.2 / libaom `set_lpf_parameters`: a transform edge between two
13333+ // SKIPPED INTER blocks is filtered only when it is also a prediction
13334+ // (coded-block) edge -- `!pv_skip || !curr_skipped || pu_edge`. The
13335+ // omission of this term (on the stale invariant "a coded block's transform
13336+ // is always its own full size", which var-tx broke) had us filtering an
13337+ // interior 8-px lattice the reference never touches: on the pinned 192x68
13338+ // inter stream frame 1 went from 7244 wrong post-deblock luma px to 0.
13339+ let cur_org = n.blk_org_grid[mi_r * n.skip_grid_cols_mi + mi_c];
13340+ let pu_edge = if dir == 0 {
13341+ mi_c == usize::from(cur_org[1])
13342+ } else {
13343+ mi_r == usize::from(cur_org[0])
13344+ };
13345+ if !pu_edge
13346+ && cur_ref != 0
13347+ && pv_ref != 0
13348+ && n.skip_at(mi_r, mi_c)
13349+ && n.skip_at(pv_mi_r, pv_mi_c)
13350+ {
13351+ return None;
13352+ }
1332413353 let cur_level = lf_level(lf, plane_idx, dir, cur_ref, cur_delta_lf, segment_id_at(mi_r, mi_c));
1332513354 let pv_level = lf_level(
1332613355 lf,
lanes/mergefix-r4.report.mdmodified+49 -39
@@ -1,46 +1,56 @@
11 # lane-mergefix r4 report
22
3-## Verdict: the r3/charter premise is FALSE — frame 1 is not a prediction defect
4-
5-Frame 1 of the pinned stream reconstructs BIT-EXACT (0 differing luma px, whole
6-cropped frame) against the instrumented oracle's pre-filter dump. The 3376 px the
7-straddling gate reports are introduced by OUR DEBLOCK, not by compound prediction:
8-we filter ~10x more pixels than libaom on that frame.
9-
10-EVIDENCE: ~/.cache/mergefix-tmp/{r4_pre.f1,r4_aom.f1,r4_ours.f1,r4_apd.f1} |
11-`EC_AV1_PREFILT_DUMP16=<p> decode_probe str61.obu` vs
12-`EC_AV1_PREFILT_DUMP=<p> aomdec --rawvideo -o /dev/null str61.obu`, then the same pair
13-of POSTDEBLOCK rungs (aomdec's dump is the mi-ALIGNED buffer 192x72, ours the crop
14-192x68 — crop before comparing) |
15-frame 0 pre 0 / postdeblock 0; frame 1 pre 0 / postdeblock 7244 differing luma px;
16-against the shared pre-filter picture libaom changes 718 px, we change 7345
17-(6753 pixels we filter that libaom leaves alone, 126 the other way).
18-
19-## Where it points (not yet fixed)
20-Filter levels are not the cause: frame 1 parses `level=[20,16,20,26] sharpness=0
21-delta_enabled=true delta_update=false ref_deltas=[1,0,0,0,-1,0,-1,-1] mode_deltas=[0,0]`
22-(new rung `EC_LFPARAMS`, decode.rs ~12157), and the pattern is "extra edges", not
23-"stronger filtering" (max |delta| vs pre-filter is 10 on BOTH decoders).
24-
25-The suspect is the loop-filter TU grid on inter frames plus the missing skip
26-suppression of spec 7.14.2 / libaom `set_lpf_parameters`
27-(`if ((curr_level || pv_lvl) && (!pv_skip || !curr_skipped || pu_edge))`, where
28-`curr_skipped = skip_txfm && is_inter`). `edge_params` (decode.rs ~13276) documents
29-that it deliberately omits that term under the invariant "a coded block's transform is
30-always its own full size" — an invariant var-tx broke. `EC_TXGRID_TRACE` shows the whole
31-`mi_row=16` row of frame 1 publishing 8x8 TUs (`w_mi=2 h_mi=2 tx_px=8`), i.e. an 8-px
32-interior edge lattice that libaom does not filter when both sides are skip-inter and the
33-edge is not a PU edge.
34-
35-## Changed
36-- `crates/ec-av1/src/decode.rs` ~12157: `EC_LFPARAMS` rung (frame-level loop filter
37- params) — the instrument that ruled the level out. No behavioural change.
3+## Verdict
4+The r3/charter premise is DISPROVED and a real root cause shipped: decode-order frame 1
5+of the pinned stream reconstructs BIT-EXACT (0 px) -- it is not a compound-prediction
6+defect. Our LOOP FILTER was filtering an interior transform-edge lattice the reference
7+never touches, because `edge_params` omitted spec 7.14.2's skip/`pu_edge` suppression.
8+Fixed; frame 1 post-deblock goes 7244 -> 177 wrong luma px (the 177 residue is the
9+bottom straddling band, rows 61-67, and is NOT closed). The straddling gate still
10+fails, but on a DIFFERENT, now-isolated defect (see residue) -- its reported count is
11+unchanged at 3622 because the gate compares SHOWN frames, and its "frame 1" is
12+decode-order frame 2.
13+
14+## Root cause + fix (crates/ec-av1/src/decode.rs)
15+- `edge_params` (~13300): a transform edge between two SKIPPED INTER blocks is filtered
16+ only when it is also a prediction (coded-block) edge -- libaom `set_lpf_parameters`
17+ `(curr_level || pv_lvl) && (!pv_skip || !curr_skipped || pu_edge)`. The old comment
18+ declared the term inert under "a coded block's transform is always its own full size";
19+ var-tx broke that invariant, so every var-tx 8-px interior edge inside skipped inter
20+ blocks was being filtered.
21+- `Neighbours::blk_org_grid` (new, ~4202/4309) + `fill_skip_grid_rect` (~4719): per-4x4-mi
22+ origin of the covering coded block -- the `pu_edge` term. Written where the skip flag
23+ already is (same `at_mi`, same call sites), so no new call-site sweep.
24+- `EC_LFPARAMS` rung (~12157): frame-level loop filter params, the instrument that ruled
25+ the filter LEVEL out.
26+
27+EVIDENCE: ~/.cache/mergefix-tmp/r4_{pre,aom,apd,ours,fix}.f* | ours
28+`EC_AV1_PREFILT_DUMP16`/`EC_AV1_POSTDEBLOCK_DUMP16` vs aomdec `EC_AV1_PREFILT_DUMP`/
29+`EC_AV1_POSTDEBLOCK_DUMP` on str61.obu (md5 a14892ed0ba88b6ad2b566e251ea2d33; aomdec's
30+postdeblock dump is the mi-ALIGNED 192x72 buffer -- crop to 68 rows first; its
31+`*_DUMP16` rung SEGFAULTS on an 8-bit stream) | decode-order frame 1: pre-filter 0 px
32+both before and after; post-deblock 7244 (unfixed) -> 255 (suppression
33+without the `pu_edge` term) -> 177 (SHIPPED, with it). Frame 0 is 0 in every build. The
34+177 residue is entirely rows 61-67, the bottom straddling band, cols 130-191: we filter
35+143 px libaom leaves, libaom filters 15 we leave -- an open sub-defect, not closed.
3836
3937 ## Gates
40-Not re-run this round (no behavioural change shipped); the straddling gate stands where
41-r2/r3 left it (3376/3622 px, see r3 report).
38+`cargo test -p ec-av1 --lib -j3 -- a_frame_edge_straddling_band_decodes_pixel_exact real_aomenc_1to4_streams_decode_pixel_exact_and_rect_vartx`
39+-> `1 passed; 1 failed` (log `$HOME/.cache/mergefix-r4-gates.log`): the 1:4 rect-vartx
40+sibling gate PASSES (no r3-style trade), the straddling gate still fails with
41+`frame 1 plane Y: 3622 pixels differ, first at row 0 col 64 (ours 56 vs ffmpeg 178)`.
42+Sibling batch (the 9 gates named in the r2 report, one invocation):
43+`$HOME/.cache/mergefix-r4-sib.log`.
44+
45+## Residue (now precisely isolated, fix-now for r5)
46+Decode-order frame 2 (the gate's SHOWN frame 1) is wrong BEFORE any filtering: 1306
47+luma px, all inside the single 32-px column band x=96..127, rows 0..63; first at
48+row 0 col 97 (ours 42 vs aomdec 8; col 96 matches). That is the remaining prediction
49+defect the straddling gate reports. Second residue (open): 177 px in rows 61-67 (bottom
50+straddling band, cols 130-191) of decode frame 1's post-deblock output ON THE SHIPPED
51+TREE -- a horizontal edge at y=64 we filter and libaom does not (or vice versa, 15 px);
52+suspect the pu_edge/tx grid for blocks in the partial last mi row.
4253
4354 ## Disposition
44-- fix-now (r5): port `set_lpf_parameters`' skip/pu_edge suppression + verify the inter
45- var-tx / skip-inter LF TU grid publishes the block's max rect tx size.
55+- fix-now (r5): the decode-frame-2 32-px prediction band above.
4656 - accepted: r3's partition-context finding stays unshipped (sibling-gate trade).