ec-av1: lane-av1-422filter -- the 4:2:2 loop-filter chroma class named and fixed: the LR boundary-band snapshot was taken on a 4:2:0 stripe grid (chroma bands hardcoded ss_y=1 at the keyframe/inter plane_snapshot calls, the pipeline's snap_band rows and pipe_run_lr's chroma dims), so 4:2:2 boundary substitution read uninitialised scratch at rows 54..57/118..121, and the CDEF chroma direction was the raw luma one where libaom remaps it through conv422 when xdec != ydec; frame 0 of the pinned t422 fixture is now byte-exact vs the instrumented aomdec at PREFILT/POSTDEBLOCK/POSTCDEF/FINAL on Y, U and V (final chroma diffs 1236/1263 -> 0/0; an 8-bit EC_AV1_POSTCDEF_DUMP rung was added to the oracle build to split CDEF from LR: post-CDEF was 251/259 first U (50,0)/V (48,0), the ticket's first final samples), chroma422_square=24 rect=96 sub8=26 non-vacuity, 4:2:0 paths bit-identical (ss_y=1 reproduces the old bands/rows/dims; the LR-symbol, skipped-8x8-aomenc and superres+CDEF+LR gates re-verified green), header refusal stays unconditional (bypass applied and reverted byte-identical), read_coeffs_rect untouched, cargo check 0 warnings, report lanes/av1422filter.report.md
Browse files at this commit2c965913960c3540707b9f2ad2ea2a50e742dda7Parent: 2cd34bf2 changed files +176 -8
- crates/ec-av1/src/decode.rs +67 -8
- lanes/av1422filter.report.md +109 -0
crates/ec-av1/src/decode.rsmodified+67 -8
| @@ -21271,6 +21271,15 @@ const CDEF_DIRECTIONS: [[(i32, i32); 2]; 8] = [ | ||
| 21271 | 21271 | const CDEF_VERY_LARGE: i32 = 0x4000; |
| 21272 | 21272 | const CDEF_PRI_TAPS: [[i32; 2]; 2] = [[4, 2], [3, 3]]; |
| 21273 | 21273 | const CDEF_SEC_TAPS: [i32; 2] = [2, 1]; |
| 21274 | +/// lane-av1422filter: libaom `av1_cdef_filter_fb` (cdef_block.c) remaps the | |
| 21275 | +/// luma direction before filtering CHROMA whenever `xdec != ydec` — the | |
| 21276 | +/// direction grid lives on the subsampled chroma grid, so a direction found | |
| 21277 | +/// on the 8x8 luma block means a different line there. `conv422` applies | |
| 21278 | +/// under 4:2:2 (`xdec` set), `conv440` under its mirror (not expressible in | |
| 21279 | +/// the profiles this decoder accepts, kept for fidelity). 4:2:0 and 4:4:4 | |
| 21280 | +/// (`xdec == ydec`) take no remap, exactly as before this lane. | |
| 21281 | +const CDEF_DIR_CONV422: [usize; 8] = [7, 0, 2, 4, 5, 6, 6, 6]; | |
| 21282 | +const CDEF_DIR_CONV440: [usize; 8] = [1, 2, 2, 2, 3, 4, 6, 0]; | |
| 21274 | 21283 | |
| 21275 | 21284 | fn cdef_msb(x: i32) -> i32 { |
| 21276 | 21285 | 31 - x.leading_zeros() as i32 |
| @@ -25843,7 +25852,19 @@ fn cdef_band( | ||
| 25843 | 25852 | |
| 25844 | 25853 | let t_uv = i32::from(cdef.uv_pri_strength[sidx]) << coeff_shift; |
| 25845 | 25854 | let uv_sec_strength = i32::from(cdef.uv_sec_strength[sidx]) << coeff_shift; |
| 25846 | - let uv_dir = if t_uv != 0 { dir } else { 0 }; | |
| 25855 | + // lane-av1422filter: the chroma direction is the luma one | |
| 25856 | + // remapped through `conv422`/`conv440` under asymmetric | |
| 25857 | + // subsampling (see [`CDEF_DIR_CONV422`]); identical to the | |
| 25858 | + // raw luma direction for 4:2:0 and 4:4:4. | |
| 25859 | + let uv_dir = if t_uv != 0 { | |
| 25860 | + match (ss_x(fctx), ss_y(fctx)) { | |
| 25861 | + (1, 0) => CDEF_DIR_CONV422[dir], | |
| 25862 | + (0, 1) => CDEF_DIR_CONV440[dir], | |
| 25863 | + _ => dir, | |
| 25864 | + } | |
| 25865 | + } else { | |
| 25866 | + 0 | |
| 25867 | + }; | |
| 25847 | 25868 | let enable_primary_uv = t_uv != 0; |
| 25848 | 25869 | let enable_secondary_uv = uv_sec_strength != 0; |
| 25849 | 25870 | if let Some(w) = wrote.as_deref_mut() { |
| @@ -26046,8 +26067,11 @@ fn pipe_run( | ||
| 26046 | 26067 | let j = k - 2; |
| 26047 | 26068 | if let Some((sy2, su2, sv2)) = snap.as_mut() { |
| 26048 | 26069 | snap_band(sy2.data.to_mut(), y, 0, j * 64, (j + 1) * 64, cfg.cdef_on); |
| 26049 | - snap_band(su2.data.to_mut(), u, 1, j * 32, (j + 1) * 32, cfg.cdef_on); | |
| 26050 | - snap_band(sv2.data.to_mut(), v, 1, j * 32, (j + 1) * 32, cfg.cdef_on); | |
| 26070 | + // lane-av1422filter: chroma band rows follow the frame's ss_y | |
| 26071 | + // (4:2:2 chroma bands the luma 64-row grid, not 32). | |
| 26072 | + let (c_lo, c_hi) = ((j * 64) >> ss_y(fctx), ((j + 1) * 64) >> ss_y(fctx)); | |
| 26073 | + snap_band(su2.data.to_mut(), u, ss_y(fctx) as u32, c_lo, c_hi, cfg.cdef_on); | |
| 26074 | + snap_band(sv2.data.to_mut(), v, ss_y(fctx) as u32, c_lo, c_hi, cfg.cdef_on); | |
| 26051 | 26075 | } |
| 26052 | 26076 | } |
| 26053 | 26077 | if cfg.cdef_on && k >= 3 && k - 3 < nb { |
| @@ -26102,8 +26126,23 @@ fn pipe_run_lr( | ||
| 26102 | 26126 | let (fw, fh) = (cfg.frame_w, cfg.frame_h); |
| 26103 | 26127 | let dims = [ |
| 26104 | 26128 | (fw, fh, 0u32, y.width, y.data.len()), |
| 26105 | - (fw.div_ceil(2), fh.div_ceil(2), 1, u.width, u.data.len()), | |
| 26106 | - (fw.div_ceil(2), fh.div_ceil(2), 1, v.width, v.data.len()), | |
| 26129 | + // lane-av1422filter: chroma plane extents and stripe geometry follow | |
| 26130 | + // the frame's own subsampling -- 4:2:2 chroma is full-height with | |
| 26131 | + // luma-grid stripes (only 4:2:0 halves both). | |
| 26132 | + ( | |
| 26133 | + round_ss(fw, ss_x(fctx)), | |
| 26134 | + round_ss(fh, ss_y(fctx)), | |
| 26135 | + ss_y(fctx) as u32, | |
| 26136 | + u.width, | |
| 26137 | + u.data.len(), | |
| 26138 | + ), | |
| 26139 | + ( | |
| 26140 | + round_ss(fw, ss_x(fctx)), | |
| 26141 | + round_ss(fh, ss_y(fctx)), | |
| 26142 | + ss_y(fctx) as u32, | |
| 26143 | + v.width, | |
| 26144 | + v.data.len(), | |
| 26145 | + ), | |
| 26107 | 26146 | ]; |
| 26108 | 26147 | let mut planes: Vec<LrPlane> = Vec::new(); |
| 26109 | 26148 | for (p, &(pw, ph, ss, stride, len)) in dims.iter().enumerate() { |
| @@ -29093,8 +29132,20 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 29093 | 29132 | lr.frame_restoration_type[p] != ec_av1_syntax::RestorationType::None |
| 29094 | 29133 | && lr.loop_restoration_size[p] != 0 |
| 29095 | 29134 | }); |
| 29096 | - let deblocked = | |
| 29097 | - lr_active.then(|| (plane_snapshot(&y, 0), plane_snapshot(&u, 1), plane_snapshot(&v, 1))); | |
| 29135 | + let deblocked = lr_active.then(|| { | |
| 29136 | + ( | |
| 29137 | + plane_snapshot(&y, 0), | |
| 29138 | + // lane-av1422filter: the bands are the LR stripe-boundary context | |
| 29139 | + // (`RESTORATION_UNIT_OFFSET >> ss_y` above/below each 64-luma-row | |
| 29140 | + // stripe). Chroma stripes are half-height ONLY under 4:2:0; a | |
| 29141 | + // 4:2:2 frame's chroma (ss_y = 0) stripes on the luma grid, so | |
| 29142 | + // the hardcoded `1` saved bands at rows 26/60/92/124 where LR | |
| 29143 | + // reads rows 54..57/118..121 -- every 4:2:2 boundary | |
| 29144 | + // substitution read uninitialised zeros (frame-0 V (48,0)). | |
| 29145 | + plane_snapshot(&u, ss_y(fctx) as u32), | |
| 29146 | + plane_snapshot(&v, ss_y(fctx) as u32), | |
| 29147 | + ) | |
| 29148 | + }); | |
| 29098 | 29149 | // lane-tiny r4: post-deblock / post-CDEF dumps mirroring aomdec's own |
| 29099 | 29150 | // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter |
| 29100 | 29151 | // dump above these bisect WHICH filter stage introduced a mismatch. |
| @@ -43264,7 +43315,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 43264 | 43315 | (false, None) => None, |
| 43265 | 43316 | } |
| 43266 | 43317 | } else { |
| 43267 | - lr_active.then(|| (plane_snapshot(&y, 0), plane_snapshot(&u, 1), plane_snapshot(&v, 1))) | |
| 43318 | + // lane-av1422filter: chroma band geometry follows the frame's own | |
| 43319 | + // ss_y (see the keyframe path's note) -- 4:2:2 stripes full-height. | |
| 43320 | + lr_active.then(|| { | |
| 43321 | + ( | |
| 43322 | + plane_snapshot(&y, 0), | |
| 43323 | + plane_snapshot(&u, ss_y(fctx) as u32), | |
| 43324 | + plane_snapshot(&v, ss_y(fctx) as u32), | |
| 43325 | + ) | |
| 43326 | + }) | |
| 43268 | 43327 | }; |
| 43269 | 43328 | // lane-tiny r4: post-deblock / post-CDEF dumps mirroring aomdec's own |
| 43270 | 43329 | // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter |
lanes/av1422filter.report.mdadded+109 -0
| @@ -0,0 +1,109 @@ | ||
| 1 | +# lane-av1-422filter — the 4:2:2 loop-filter chroma class: NAMED and FIXED | |
| 2 | + | |
| 3 | +## Outcome | |
| 4 | + | |
| 5 | +1. REMEASURED first (pinned fixture `/tmp/t422.obu` sha256 | |
| 6 | + `d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129`, | |
| 7 | + single-frame cut `/tmp/t422f0.obu` sha256 | |
| 8 | + `3dd3f768ef553c02316848c2d3184c3765030c0a6fcb95887e4719add9ded3af`, | |
| 9 | + 256x144 / chroma 128x144, local `EC_AV1_ALLOW_422_PROBE` bypass applied | |
| 10 | + and reverted byte-identical after): with `EC_AV1_PREFILT_DUMP` / | |
| 11 | + `EC_AV1_POSTDEBLOCK_DUMP` / `EC_AV1_POSTCDEF_DUMP` / `EC_AV1_FINAL_DUMP` | |
| 12 | + on both sides, the frame-0 pre-filter AND post-deblock planes are | |
| 13 | + byte-exact (deblock did identical work both sides: 797/637/727 samples | |
| 14 | + changed, same set) — the 1236/1263 final chroma diffs are introduced | |
| 15 | + AFTER deblock. Attribution ladder, ours vs the instrumented aomdec: | |
| 16 | + | |
| 17 | + | stage | Y | U | V | | |
| 18 | + |----------------------|------------|-----------------|-----------------| | |
| 19 | + | pre-filter | 0 | 0 | 0 | | |
| 20 | + | post-deblock | 0 | 0 | 0 | | |
| 21 | + | post-CDEF | 0 | **251** (50,0) | **259** (48,0) | | |
| 22 | + | final | 0 | **1236→253** | **1263→266** | | |
| 23 | + | |
| 24 | + (the pre-fix row shows the parent's numbers; the ticket's first final | |
| 25 | + sample V (48,0) is literally the first post-CDEF defect sample.) | |
| 26 | +2. The oracle had NO 8-bit post-CDEF rung (its `EC_AV1_POSTCDEF_DUMP` was | |
| 27 | + 16-bit only; the earlier `aom/pcd.f0` measurement was actually its | |
| 28 | + post-deblock output — the rung had to be re-derived to isolate CDEF from | |
| 29 | + LR). Added an 8-bit `EC_AV1_POSTCDEF_DUMP` twin to the oracle's | |
| 30 | + `decodeframe.c` (right after the `do_cdef` block, full aligned buffer, | |
| 31 | + same shape as the POSTDEBLOCK rung) and rebuilt | |
| 32 | + `$HOME/.cache/aom-oracle/build` aomdec with ninja. The CDEF verdict was | |
| 33 | + then direct: 251/259 samples, first exactly U (50,0) / V (48,0). | |
| 34 | +3. DEFECT 1 (the big one) — **the 4:2:2 LR boundary-band snapshot is taken | |
| 35 | + on a 4:2:0 stripe grid**. `plane_snapshot` copies only the 4-row bands | |
| 36 | + LR's stripe substitution reads (`stripe_h - offset` per 64 rows); the | |
| 37 | + chroma calls hardcoded `ss_y = 1`, so for 4:2:2 (chroma stripes on the | |
| 38 | + luma 64-row grid, offset 8) the bands landed at rows 26/60/92/124 while | |
| 39 | + LR read rows 54..57/118..121 — every boundary substitution read | |
| 40 | + uninitialised scratch (zeros): 999 U / 963 V samples filtered where aom | |
| 41 | + filters nothing, |delta| up to 24 at the top rows. Fixed at all three | |
| 42 | + sites of the class: the keyframe and inter non-pipelined | |
| 43 | + `plane_snapshot(&u/&v, ss_y(fctx))`, the pipeline's `snap_band` band rows | |
| 44 | + `(j*64) >> ss_y`, and `pipe_run_lr`'s chroma `dims` (plane extents | |
| 45 | + `round_ss`, ss carried, not `div_ceil(2)`+1). 4:2:0 is bit-identical | |
| 46 | + (ss_y=1 reproduces the old bands/rows/dims exactly). | |
| 47 | +4. DEFECT 2 — **the CDEF chroma direction remap was missing**. libaom | |
| 48 | + `av1_cdef_filter_fb` (cdef_block.c) remaps the luma direction through | |
| 49 | + `conv422 = [7,0,2,4,5,6,6,6]` (in place; V then inherits U's remapped | |
| 50 | + grid) whenever `xdec != ydec` — the direction grid lives on the | |
| 51 | + subsampled chroma grid. The port filtered chroma with the raw luma | |
| 52 | + direction: after the LR fix the residual was exactly the CDEF stage, | |
| 53 | + 251/259 samples all ±1/±2 (168 we-filtered-aom-doesn't, 71 | |
| 54 | + aom-filters-we-don't, 12 value diffs on shared samples; scalar and AVX2 | |
| 55 | + kernels byte-identical, so shared logic, not the SIMD path). Fixed with | |
| 56 | + `CDEF_DIR_CONV422`/`CDEF_DIR_CONV440` applied for `(ss_x, ss_y)` = | |
| 57 | + (1,0)/(0,1); 4:2:0 and 4:4:4 take `_ => dir` unchanged. | |
| 58 | +5. MEASURED after both fixes: **frame 0 of the pinned 4:2:2 fixture is | |
| 59 | + byte-exact vs the oracle at PREFILT, POSTDEBLOCK, POSTCDEF and FINAL on | |
| 60 | + Y, U and V** (0 diffs everywhere). Non-vacuity on this frame: | |
| 61 | + `chroma422_square` = 24, `chroma422_rect` = 96, `chroma422_sub8` = 26 — | |
| 62 | + the touched 422 arms provably ran. Instrument for the LR half: a python | |
| 63 | + re-computation of the stripe walk + `lr_src_row` substitution + the | |
| 64 | + port's own wiener rounding reproduced the oracle's post-LR chroma plane | |
| 65 | + EXACTLY from the oracle's post-CDEF input (0 mismatches), which pinned | |
| 66 | + the residual defect to the snapshot input, not the filter math. | |
| 67 | +6. REMAINING: none for this class. The `read_coeffs_rect` frame-9 scratch | |
| 68 | + panic (inter frames of the 22-frame stream) is untouched, as chartered. | |
| 69 | + | |
| 70 | +## Decision | |
| 71 | + | |
| 72 | +- The header refusal STAYS unconditional in `stream.rs` — the probe bypass | |
| 73 | + was local-only, applied and reverted byte-identical before the commit | |
| 74 | + (`git diff` after the revert carries only the decode.rs fix); the | |
| 75 | + refusal-by-name gate re-verified firing. | |
| 76 | +- `read_coeffs_rect` untouched. The 4:2:0 group-tail SKIP arm untouched. | |
| 77 | + `sub8_leaf_chroma422` (parent lane's three fixes) untouched. | |
| 78 | +- The 8-bit `EC_AV1_POSTCDEF_DUMP` rung was added to the ORACLE's source | |
| 79 | + tree (`$HOME/.cache/aom-oracle/src/av1/decoder/decodeframe.c`, rebuilt | |
| 80 | + with ninja), not to this repo's `scripts/instrument-aom-oracle.sh` — the | |
| 81 | + script's generator should grow the same patch if the oracle is ever | |
| 82 | + rebuilt from scratch. | |
| 83 | + | |
| 84 | +## Verification | |
| 85 | + | |
| 86 | +- `cargo check -p ec-av1` (target `~/.cache/cargo-target-av1422filter`): | |
| 87 | + 0 warnings, 0 errors. | |
| 88 | +- Frame-0 stage dumps, ours vs the instrumented aomdec (cropped | |
| 89 | + comparisons; our stage dumps are 256x160/128x160 padded, the oracle's | |
| 90 | + cropped 256x144/128x144 — the comparator crops): all four stages, all | |
| 91 | + three planes, 0 diffs. | |
| 92 | +- 420 gates green (all with the fix in place): | |
| 93 | + `stream::tests::a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_ | |
| 94 | + whose_tx_split_decodes_pixel_exact` under `EC_AV1_REQUIRE_AOMENC=1` | |
| 95 | + (1 passed), `stream::tests::a_real_aomenc_stream_with_restoration_reads_ | |
| 96 | + lr_symbols_correctly` (1 passed — the LR-snapshot regression gate), | |
| 97 | + `a_superres_key_frame_with_cdef_and_loop_restoration_decodes_pixel_exact` | |
| 98 | + (1 passed), `a_non_420_subsampled_sequence_header_is_refused_by_name` | |
| 99 | + (1 passed). | |
| 100 | +- Scalar-vs-AVX2 CDEF chroma A/B on this frame: 0 diffs between kernels | |
| 101 | + (the 4x8 chroma shape was already SIMD-faithful; the defect was the | |
| 102 | + direction input). | |
| 103 | + | |
| 104 | +## State | |
| 105 | + | |
| 106 | +- Commit on lane-av1-422filter (no push): the LR snapshot ss_y fix (three | |
| 107 | + sites) + the CDEF conv422 direction remap + this report. | |
| 108 | +- The instrumented oracle build at `$HOME/.cache/aom-oracle/build` now | |
| 109 | + carries the 8-bit `EC_AV1_POSTCDEF_DUMP` rung for future lanes. |