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 commit99d520f01589fb5cb46da584312bc06038f01fa5Parent: 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
2 changed files +82 -43
- crates/ec-av1/src/decode.rs +33 -4
- lanes/mergefix-r4.report.md +49 -39
crates/ec-av1/src/decode.rsmodified+33 -4
| @@ -4200,6 +4200,12 @@ struct Neighbours { | |||
| 4200 | /// granularity by [`apply_cdef`] since `skip` is constant across every | 4200 | /// granularity by [`apply_cdef`] since `skip` is constant across every |
| 4201 | /// mi cell one coded block covers. | 4201 | /// mi cell one coded block covers. |
| 4202 | skip_grid: Vec<bool>, | 4202 | 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]>, | ||
| 4203 | skip_grid_cols_mi: usize, | 4209 | skip_grid_cols_mi: usize, |
| 4204 | /// Per-4x4-mi luma transform width in pixels (8/16/32/64) -- this decoder | 4210 | /// Per-4x4-mi luma transform width in pixels (8/16/32/64) -- this decoder |
| 4205 | /// never splits a coded block's transform below its own size (round 2: | 4211 | /// never splits a coded block's transform below its own size (round 2: |
| @@ -4307,6 +4313,7 @@ impl Neighbours { | |||
| 4307 | mi_cols, | 4313 | mi_cols, |
| 4308 | mi_rows, | 4314 | mi_rows, |
| 4309 | skip_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)], | 4315 | skip_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)], |
| 4316 | + blk_org_grid: vec![[0u16; 2]; cols * (SUB / MI) * rows * (SUB / MI)], | ||
| 4310 | skip_grid_cols_mi: cols * (SUB / MI), | 4317 | skip_grid_cols_mi: cols * (SUB / MI), |
| 4311 | tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], | 4318 | tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], |
| 4312 | tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], | 4319 | tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], |
| @@ -4720,12 +4727,13 @@ impl Neighbours { | |||
| 4720 | let (mi_r, mi_c) = at_mi; | 4727 | let (mi_r, mi_c) = at_mi; |
| 4721 | for rr in 0..h_mi { | 4728 | for rr in 0..h_mi { |
| 4722 | for cc in 0..w_mi { | 4729 | for cc in 0..w_mi { |
| 4723 | - if let Some(cell) = self | 4730 | + let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc); |
| 4724 | - .skip_grid | 4731 | + if let Some(cell) = self.skip_grid.get_mut(idx) { |
| 4725 | - .get_mut((mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc)) | ||
| 4726 | - { | ||
| 4727 | *cell = skip; | 4732 | *cell = skip; |
| 4728 | } | 4733 | } |
| 4734 | + if let Some(org) = self.blk_org_grid.get_mut(idx) { | ||
| 4735 | + *org = [mi_r as u16, mi_c as u16]; | ||
| 4736 | + } | ||
| 4729 | } | 4737 | } |
| 4730 | } | 4738 | } |
| 4731 | } | 4739 | } |
| @@ -13321,6 +13329,27 @@ fn edge_params( | |||
| 13321 | let cur_delta_lf = i32::from(n.delta_lf_grid[mi_r * n.skip_grid_cols_mi + mi_c][delta_idx]); | 13329 | let cur_delta_lf = i32::from(n.delta_lf_grid[mi_r * n.skip_grid_cols_mi + mi_c][delta_idx]); |
| 13322 | let pv_delta_lf = i32::from(n.delta_lf_grid[pv_mi_r * n.skip_grid_cols_mi + pv_mi_c][delta_idx]); | 13330 | let pv_delta_lf = i32::from(n.delta_lf_grid[pv_mi_r * n.skip_grid_cols_mi + pv_mi_c][delta_idx]); |
| 13323 | 13331 | ||
| 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 | + } | ||
| 13324 | let cur_level = lf_level(lf, plane_idx, dir, cur_ref, cur_delta_lf, segment_id_at(mi_r, mi_c)); | 13353 | let cur_level = lf_level(lf, plane_idx, dir, cur_ref, cur_delta_lf, segment_id_at(mi_r, mi_c)); |
| 13325 | let pv_level = lf_level( | 13354 | let pv_level = lf_level( |
| 13326 | lf, | 13355 | lf, |
lanes/mergefix-r4.report.mdmodified+49 -39
| @@ -1,46 +1,56 @@ | |||
| 1 | # lane-mergefix r4 report | 1 | # lane-mergefix r4 report |
| 2 | 2 | ||
| 3 | -## Verdict: the r3/charter premise is FALSE — frame 1 is not a prediction defect | 3 | +## Verdict |
| 4 | - | 4 | +The r3/charter premise is DISPROVED and a real root cause shipped: decode-order frame 1 |
| 5 | -Frame 1 of the pinned stream reconstructs BIT-EXACT (0 differing luma px, whole | 5 | +of the pinned stream reconstructs BIT-EXACT (0 px) -- it is not a compound-prediction |
| 6 | -cropped frame) against the instrumented oracle's pre-filter dump. The 3376 px the | 6 | +defect. Our LOOP FILTER was filtering an interior transform-edge lattice the reference |
| 7 | -straddling gate reports are introduced by OUR DEBLOCK, not by compound prediction: | 7 | +never touches, because `edge_params` omitted spec 7.14.2's skip/`pu_edge` suppression. |
| 8 | -we filter ~10x more pixels than libaom on that frame. | 8 | +Fixed; frame 1 post-deblock goes 7244 -> 177 wrong luma px (the 177 residue is the |
| 9 | - | 9 | +bottom straddling band, rows 61-67, and is NOT closed). The straddling gate still |
| 10 | -EVIDENCE: ~/.cache/mergefix-tmp/{r4_pre.f1,r4_aom.f1,r4_ours.f1,r4_apd.f1} | | 10 | +fails, but on a DIFFERENT, now-isolated defect (see residue) -- its reported count is |
| 11 | -`EC_AV1_PREFILT_DUMP16=<p> decode_probe str61.obu` vs | 11 | +unchanged at 3622 because the gate compares SHOWN frames, and its "frame 1" is |
| 12 | -`EC_AV1_PREFILT_DUMP=<p> aomdec --rawvideo -o /dev/null str61.obu`, then the same pair | 12 | +decode-order frame 2. |
| 13 | -of POSTDEBLOCK rungs (aomdec's dump is the mi-ALIGNED buffer 192x72, ours the crop | 13 | + |
| 14 | -192x68 — crop before comparing) | | 14 | +## Root cause + fix (crates/ec-av1/src/decode.rs) |
| 15 | -frame 0 pre 0 / postdeblock 0; frame 1 pre 0 / postdeblock 7244 differing luma px; | 15 | +- `edge_params` (~13300): a transform edge between two SKIPPED INTER blocks is filtered |
| 16 | -against the shared pre-filter picture libaom changes 718 px, we change 7345 | 16 | + only when it is also a prediction (coded-block) edge -- libaom `set_lpf_parameters` |
| 17 | -(6753 pixels we filter that libaom leaves alone, 126 the other way). | 17 | + `(curr_level || pv_lvl) && (!pv_skip || !curr_skipped || pu_edge)`. The old comment |
| 18 | - | 18 | + declared the term inert under "a coded block's transform is always its own full size"; |
| 19 | -## Where it points (not yet fixed) | 19 | + var-tx broke that invariant, so every var-tx 8-px interior edge inside skipped inter |
| 20 | -Filter levels are not the cause: frame 1 parses `level=[20,16,20,26] sharpness=0 | 20 | + blocks was being filtered. |
| 21 | -delta_enabled=true delta_update=false ref_deltas=[1,0,0,0,-1,0,-1,-1] mode_deltas=[0,0]` | 21 | +- `Neighbours::blk_org_grid` (new, ~4202/4309) + `fill_skip_grid_rect` (~4719): per-4x4-mi |
| 22 | -(new rung `EC_LFPARAMS`, decode.rs ~12157), and the pattern is "extra edges", not | 22 | + origin of the covering coded block -- the `pu_edge` term. Written where the skip flag |
| 23 | -"stronger filtering" (max |delta| vs pre-filter is 10 on BOTH decoders). | 23 | + already is (same `at_mi`, same call sites), so no new call-site sweep. |
| 24 | - | 24 | +- `EC_LFPARAMS` rung (~12157): frame-level loop filter params, the instrument that ruled |
| 25 | -The suspect is the loop-filter TU grid on inter frames plus the missing skip | 25 | + the filter LEVEL out. |
| 26 | -suppression of spec 7.14.2 / libaom `set_lpf_parameters` | 26 | + |
| 27 | -(`if ((curr_level || pv_lvl) && (!pv_skip || !curr_skipped || pu_edge))`, where | 27 | +EVIDENCE: ~/.cache/mergefix-tmp/r4_{pre,aom,apd,ours,fix}.f* | ours |
| 28 | -`curr_skipped = skip_txfm && is_inter`). `edge_params` (decode.rs ~13276) documents | 28 | +`EC_AV1_PREFILT_DUMP16`/`EC_AV1_POSTDEBLOCK_DUMP16` vs aomdec `EC_AV1_PREFILT_DUMP`/ |
| 29 | -that it deliberately omits that term under the invariant "a coded block's transform is | 29 | +`EC_AV1_POSTDEBLOCK_DUMP` on str61.obu (md5 a14892ed0ba88b6ad2b566e251ea2d33; aomdec's |
| 30 | -always its own full size" — an invariant var-tx broke. `EC_TXGRID_TRACE` shows the whole | 30 | +postdeblock dump is the mi-ALIGNED 192x72 buffer -- crop to 68 rows first; its |
| 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 | 31 | +`*_DUMP16` rung SEGFAULTS on an 8-bit stream) | decode-order frame 1: pre-filter 0 px |
| 32 | -interior edge lattice that libaom does not filter when both sides are skip-inter and the | 32 | +both before and after; post-deblock 7244 (unfixed) -> 255 (suppression |
| 33 | -edge is not a PU edge. | 33 | +without the `pu_edge` term) -> 177 (SHIPPED, with it). Frame 0 is 0 in every build. The |
| 34 | - | 34 | +177 residue is entirely rows 61-67, the bottom straddling band, cols 130-191: we filter |
| 35 | -## Changed | 35 | +143 px libaom leaves, libaom filters 15 we leave -- an open sub-defect, not closed. |
| 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. | ||
| 38 | 36 | ||
| 39 | ## Gates | 37 | ## Gates |
| 40 | -Not re-run this round (no behavioural change shipped); the straddling gate stands where | 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` |
| 41 | -r2/r3 left it (3376/3622 px, see r3 report). | 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. | ||
| 42 | 53 | ||
| 43 | ## Disposition | 54 | ## Disposition |
| 44 | -- fix-now (r5): port `set_lpf_parameters`' skip/pu_edge suppression + verify the inter | 55 | +- fix-now (r5): the decode-frame-2 32-px prediction band above. |
| 45 | - var-tx / skip-inter LF TU grid publishes the block's max rect tx size. | ||
| 46 | - accepted: r3's partition-context finding stays unshipped (sibling-gate trade). | 56 | - accepted: r3's partition-context finding stays unshipped (sibling-gate trade). |