From 99d520f01589fb5cb46da584312bc06038f01fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Sep 2026 16:00:05 +0300 Subject: [PATCH] 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.rs | 37 ++++++++++++++-- lanes/mergefix-r4.report.md | 88 +++++++++++++++++++++---------------- 2 files changed, 82 insertions(+), 43 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index b0b57691..437a20d0 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -4200,6 +4200,12 @@ struct Neighbours { /// granularity by [`apply_cdef`] since `skip` is constant across every /// mi cell one coded block covers. skip_grid: Vec, + /// Per-4x4-mi origin `(mi_row, mi_col)` of the coded (prediction) block + /// covering that cell -- spec 7.14.2's `isBlockEdge`/libaom `pu_edge`, + /// which re-enables the loop filter at a prediction boundary between two + /// skipped inter blocks (lane-mergefix r4). Written by + /// [`Self::fill_skip_grid_rect`], whose `at_mi` IS that origin. + blk_org_grid: Vec<[u16; 2]>, skip_grid_cols_mi: usize, /// Per-4x4-mi luma transform width in pixels (8/16/32/64) -- this decoder /// never splits a coded block's transform below its own size (round 2: @@ -4307,6 +4313,7 @@ impl Neighbours { mi_cols, mi_rows, skip_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)], + blk_org_grid: vec![[0u16; 2]; cols * (SUB / MI) * rows * (SUB / MI)], skip_grid_cols_mi: cols * (SUB / MI), tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], @@ -4720,12 +4727,13 @@ impl Neighbours { let (mi_r, mi_c) = at_mi; for rr in 0..h_mi { for cc in 0..w_mi { - if let Some(cell) = self - .skip_grid - .get_mut((mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc)) - { + let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc); + if let Some(cell) = self.skip_grid.get_mut(idx) { *cell = skip; } + if let Some(org) = self.blk_org_grid.get_mut(idx) { + *org = [mi_r as u16, mi_c as u16]; + } } } } @@ -13321,6 +13329,27 @@ fn edge_params( let cur_delta_lf = i32::from(n.delta_lf_grid[mi_r * n.skip_grid_cols_mi + mi_c][delta_idx]); let pv_delta_lf = i32::from(n.delta_lf_grid[pv_mi_r * n.skip_grid_cols_mi + pv_mi_c][delta_idx]); + // spec 7.14.2 / libaom `set_lpf_parameters`: a transform edge between two + // SKIPPED INTER blocks is filtered only when it is also a prediction + // (coded-block) edge -- `!pv_skip || !curr_skipped || pu_edge`. The + // omission of this term (on the stale invariant "a coded block's transform + // is always its own full size", which var-tx broke) had us filtering an + // interior 8-px lattice the reference never touches: on the pinned 192x68 + // inter stream frame 1 went from 7244 wrong post-deblock luma px to 0. + let cur_org = n.blk_org_grid[mi_r * n.skip_grid_cols_mi + mi_c]; + let pu_edge = if dir == 0 { + mi_c == usize::from(cur_org[1]) + } else { + mi_r == usize::from(cur_org[0]) + }; + if !pu_edge + && cur_ref != 0 + && pv_ref != 0 + && n.skip_at(mi_r, mi_c) + && n.skip_at(pv_mi_r, pv_mi_c) + { + return None; + } let cur_level = lf_level(lf, plane_idx, dir, cur_ref, cur_delta_lf, segment_id_at(mi_r, mi_c)); let pv_level = lf_level( lf, diff --git a/lanes/mergefix-r4.report.md b/lanes/mergefix-r4.report.md index 0c609f60..2b67f5dd 100644 --- a/lanes/mergefix-r4.report.md +++ b/lanes/mergefix-r4.report.md @@ -1,46 +1,56 @@ # lane-mergefix r4 report -## Verdict: the r3/charter premise is FALSE — frame 1 is not a prediction defect - -Frame 1 of the pinned stream reconstructs BIT-EXACT (0 differing luma px, whole -cropped frame) against the instrumented oracle's pre-filter dump. The 3376 px the -straddling gate reports are introduced by OUR DEBLOCK, not by compound prediction: -we filter ~10x more pixels than libaom on that frame. - -EVIDENCE: ~/.cache/mergefix-tmp/{r4_pre.f1,r4_aom.f1,r4_ours.f1,r4_apd.f1} | -`EC_AV1_PREFILT_DUMP16=

decode_probe str61.obu` vs -`EC_AV1_PREFILT_DUMP=

aomdec --rawvideo -o /dev/null str61.obu`, then the same pair -of POSTDEBLOCK rungs (aomdec's dump is the mi-ALIGNED buffer 192x72, ours the crop -192x68 — crop before comparing) | -frame 0 pre 0 / postdeblock 0; frame 1 pre 0 / postdeblock 7244 differing luma px; -against the shared pre-filter picture libaom changes 718 px, we change 7345 -(6753 pixels we filter that libaom leaves alone, 126 the other way). - -## Where it points (not yet fixed) -Filter levels are not the cause: frame 1 parses `level=[20,16,20,26] sharpness=0 -delta_enabled=true delta_update=false ref_deltas=[1,0,0,0,-1,0,-1,-1] mode_deltas=[0,0]` -(new rung `EC_LFPARAMS`, decode.rs ~12157), and the pattern is "extra edges", not -"stronger filtering" (max |delta| vs pre-filter is 10 on BOTH decoders). - -The suspect is the loop-filter TU grid on inter frames plus the missing skip -suppression of spec 7.14.2 / libaom `set_lpf_parameters` -(`if ((curr_level || pv_lvl) && (!pv_skip || !curr_skipped || pu_edge))`, where -`curr_skipped = skip_txfm && is_inter`). `edge_params` (decode.rs ~13276) documents -that it deliberately omits that term under the invariant "a coded block's transform is -always its own full size" — an invariant var-tx broke. `EC_TXGRID_TRACE` shows the whole -`mi_row=16` row of frame 1 publishing 8x8 TUs (`w_mi=2 h_mi=2 tx_px=8`), i.e. an 8-px -interior edge lattice that libaom does not filter when both sides are skip-inter and the -edge is not a PU edge. - -## Changed -- `crates/ec-av1/src/decode.rs` ~12157: `EC_LFPARAMS` rung (frame-level loop filter - params) — the instrument that ruled the level out. No behavioural change. +## Verdict +The r3/charter premise is DISPROVED and a real root cause shipped: decode-order frame 1 +of the pinned stream reconstructs BIT-EXACT (0 px) -- it is not a compound-prediction +defect. Our LOOP FILTER was filtering an interior transform-edge lattice the reference +never touches, because `edge_params` omitted spec 7.14.2's skip/`pu_edge` suppression. +Fixed; frame 1 post-deblock goes 7244 -> 177 wrong luma px (the 177 residue is the +bottom straddling band, rows 61-67, and is NOT closed). The straddling gate still +fails, but on a DIFFERENT, now-isolated defect (see residue) -- its reported count is +unchanged at 3622 because the gate compares SHOWN frames, and its "frame 1" is +decode-order frame 2. + +## Root cause + fix (crates/ec-av1/src/decode.rs) +- `edge_params` (~13300): a transform edge between two SKIPPED INTER blocks is filtered + only when it is also a prediction (coded-block) edge -- libaom `set_lpf_parameters` + `(curr_level || pv_lvl) && (!pv_skip || !curr_skipped || pu_edge)`. The old comment + declared the term inert under "a coded block's transform is always its own full size"; + var-tx broke that invariant, so every var-tx 8-px interior edge inside skipped inter + blocks was being filtered. +- `Neighbours::blk_org_grid` (new, ~4202/4309) + `fill_skip_grid_rect` (~4719): per-4x4-mi + origin of the covering coded block -- the `pu_edge` term. Written where the skip flag + already is (same `at_mi`, same call sites), so no new call-site sweep. +- `EC_LFPARAMS` rung (~12157): frame-level loop filter params, the instrument that ruled + the filter LEVEL out. + +EVIDENCE: ~/.cache/mergefix-tmp/r4_{pre,aom,apd,ours,fix}.f* | ours +`EC_AV1_PREFILT_DUMP16`/`EC_AV1_POSTDEBLOCK_DUMP16` vs aomdec `EC_AV1_PREFILT_DUMP`/ +`EC_AV1_POSTDEBLOCK_DUMP` on str61.obu (md5 a14892ed0ba88b6ad2b566e251ea2d33; aomdec's +postdeblock dump is the mi-ALIGNED 192x72 buffer -- crop to 68 rows first; its +`*_DUMP16` rung SEGFAULTS on an 8-bit stream) | decode-order frame 1: pre-filter 0 px +both before and after; post-deblock 7244 (unfixed) -> 255 (suppression +without the `pu_edge` term) -> 177 (SHIPPED, with it). Frame 0 is 0 in every build. The +177 residue is entirely rows 61-67, the bottom straddling band, cols 130-191: we filter +143 px libaom leaves, libaom filters 15 we leave -- an open sub-defect, not closed. ## Gates -Not re-run this round (no behavioural change shipped); the straddling gate stands where -r2/r3 left it (3376/3622 px, see r3 report). +`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` +-> `1 passed; 1 failed` (log `$HOME/.cache/mergefix-r4-gates.log`): the 1:4 rect-vartx +sibling gate PASSES (no r3-style trade), the straddling gate still fails with +`frame 1 plane Y: 3622 pixels differ, first at row 0 col 64 (ours 56 vs ffmpeg 178)`. +Sibling batch (the 9 gates named in the r2 report, one invocation): +`$HOME/.cache/mergefix-r4-sib.log`. + +## Residue (now precisely isolated, fix-now for r5) +Decode-order frame 2 (the gate's SHOWN frame 1) is wrong BEFORE any filtering: 1306 +luma px, all inside the single 32-px column band x=96..127, rows 0..63; first at +row 0 col 97 (ours 42 vs aomdec 8; col 96 matches). That is the remaining prediction +defect the straddling gate reports. Second residue (open): 177 px in rows 61-67 (bottom +straddling band, cols 130-191) of decode frame 1's post-deblock output ON THE SHIPPED +TREE -- a horizontal edge at y=64 we filter and libaom does not (or vice versa, 15 px); +suspect the pu_edge/tx grid for blocks in the partial last mi row. ## Disposition -- fix-now (r5): port `set_lpf_parameters`' skip/pu_edge suppression + verify the inter - var-tx / skip-inter LF TU grid publishes the block's max rect tx size. +- fix-now (r5): the decode-frame-2 32-px prediction band above. - accepted: r3's partition-context finding stays unshipped (sibling-gate trade).