forge
Explore
Log in

Don't you dare go Hollow

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 commit

40e7f038420b46953211c3127a306dc781b6774bAhmet Kaan GümüşParent: f487a7a
crates/ec-av1/src/decode.rsmodified+67 -8
@@ -20277,6 +20277,15 @@ const CDEF_DIRECTIONS: [[(i32, i32); 2]; 8] = [
2027720277 const CDEF_VERY_LARGE: i32 = 0x4000;
2027820278 const CDEF_PRI_TAPS: [[i32; 2]; 2] = [[4, 2], [3, 3]];
2027920279 const CDEF_SEC_TAPS: [i32; 2] = [2, 1];
20280+/// lane-av1422filter: libaom `av1_cdef_filter_fb` (cdef_block.c) remaps the
20281+/// luma direction before filtering CHROMA whenever `xdec != ydec` — the
20282+/// direction grid lives on the subsampled chroma grid, so a direction found
20283+/// on the 8x8 luma block means a different line there. `conv422` applies
20284+/// under 4:2:2 (`xdec` set), `conv440` under its mirror (not expressible in
20285+/// the profiles this decoder accepts, kept for fidelity). 4:2:0 and 4:4:4
20286+/// (`xdec == ydec`) take no remap, exactly as before this lane.
20287+const CDEF_DIR_CONV422: [usize; 8] = [7, 0, 2, 4, 5, 6, 6, 6];
20288+const CDEF_DIR_CONV440: [usize; 8] = [1, 2, 2, 2, 3, 4, 6, 0];
2028020289
2028120290 fn cdef_msb(x: i32) -> i32 {
2028220291 31 - x.leading_zeros() as i32
@@ -24802,7 +24811,19 @@ fn cdef_band(
2480224811
2480324812 let t_uv = i32::from(cdef.uv_pri_strength[sidx]) << coeff_shift;
2480424813 let uv_sec_strength = i32::from(cdef.uv_sec_strength[sidx]) << coeff_shift;
24805- let uv_dir = if t_uv != 0 { dir } else { 0 };
24814+ // lane-av1422filter: the chroma direction is the luma one
24815+ // remapped through `conv422`/`conv440` under asymmetric
24816+ // subsampling (see [`CDEF_DIR_CONV422`]); identical to the
24817+ // raw luma direction for 4:2:0 and 4:4:4.
24818+ let uv_dir = if t_uv != 0 {
24819+ match (ss_x(fctx), ss_y(fctx)) {
24820+ (1, 0) => CDEF_DIR_CONV422[dir],
24821+ (0, 1) => CDEF_DIR_CONV440[dir],
24822+ _ => dir,
24823+ }
24824+ } else {
24825+ 0
24826+ };
2480624827 let enable_primary_uv = t_uv != 0;
2480724828 let enable_secondary_uv = uv_sec_strength != 0;
2480824829 if let Some(w) = wrote.as_deref_mut() {
@@ -25005,8 +25026,11 @@ fn pipe_run(
2500525026 let j = k - 2;
2500625027 if let Some((sy2, su2, sv2)) = snap.as_mut() {
2500725028 snap_band(sy2.data.to_mut(), y, 0, j * 64, (j + 1) * 64, cfg.cdef_on);
25008- snap_band(su2.data.to_mut(), u, 1, j * 32, (j + 1) * 32, cfg.cdef_on);
25009- snap_band(sv2.data.to_mut(), v, 1, j * 32, (j + 1) * 32, cfg.cdef_on);
25029+ // lane-av1422filter: chroma band rows follow the frame's ss_y
25030+ // (4:2:2 chroma bands the luma 64-row grid, not 32).
25031+ let (c_lo, c_hi) = ((j * 64) >> ss_y(fctx), ((j + 1) * 64) >> ss_y(fctx));
25032+ snap_band(su2.data.to_mut(), u, ss_y(fctx) as u32, c_lo, c_hi, cfg.cdef_on);
25033+ snap_band(sv2.data.to_mut(), v, ss_y(fctx) as u32, c_lo, c_hi, cfg.cdef_on);
2501025034 }
2501125035 }
2501225036 if cfg.cdef_on && k >= 3 && k - 3 < nb {
@@ -25061,8 +25085,23 @@ fn pipe_run_lr(
2506125085 let (fw, fh) = (cfg.frame_w, cfg.frame_h);
2506225086 let dims = [
2506325087 (fw, fh, 0u32, y.width, y.data.len()),
25064- (fw.div_ceil(2), fh.div_ceil(2), 1, u.width, u.data.len()),
25065- (fw.div_ceil(2), fh.div_ceil(2), 1, v.width, v.data.len()),
25088+ // lane-av1422filter: chroma plane extents and stripe geometry follow
25089+ // the frame's own subsampling -- 4:2:2 chroma is full-height with
25090+ // luma-grid stripes (only 4:2:0 halves both).
25091+ (
25092+ round_ss(fw, ss_x(fctx)),
25093+ round_ss(fh, ss_y(fctx)),
25094+ ss_y(fctx) as u32,
25095+ u.width,
25096+ u.data.len(),
25097+ ),
25098+ (
25099+ round_ss(fw, ss_x(fctx)),
25100+ round_ss(fh, ss_y(fctx)),
25101+ ss_y(fctx) as u32,
25102+ v.width,
25103+ v.data.len(),
25104+ ),
2506625105 ];
2506725106 let mut planes: Vec<LrPlane> = Vec::new();
2506825107 for (p, &(pw, ph, ss, stride, len)) in dims.iter().enumerate() {
@@ -28043,8 +28082,20 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
2804328082 lr.frame_restoration_type[p] != ec_av1_syntax::RestorationType::None
2804428083 && lr.loop_restoration_size[p] != 0
2804528084 });
28046- let deblocked =
28047- lr_active.then(|| (plane_snapshot(&y, 0), plane_snapshot(&u, 1), plane_snapshot(&v, 1)));
28085+ let deblocked = lr_active.then(|| {
28086+ (
28087+ plane_snapshot(&y, 0),
28088+ // lane-av1422filter: the bands are the LR stripe-boundary context
28089+ // (`RESTORATION_UNIT_OFFSET >> ss_y` above/below each 64-luma-row
28090+ // stripe). Chroma stripes are half-height ONLY under 4:2:0; a
28091+ // 4:2:2 frame's chroma (ss_y = 0) stripes on the luma grid, so
28092+ // the hardcoded `1` saved bands at rows 26/60/92/124 where LR
28093+ // reads rows 54..57/118..121 -- every 4:2:2 boundary
28094+ // substitution read uninitialised zeros (frame-0 V (48,0)).
28095+ plane_snapshot(&u, ss_y(fctx) as u32),
28096+ plane_snapshot(&v, ss_y(fctx) as u32),
28097+ )
28098+ });
2804828099 // lane-tiny r4: post-deblock / post-CDEF dumps mirroring aomdec's own
2804928100 // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter
2805028101 // dump above these bisect WHICH filter stage introduced a mismatch.
@@ -42387,7 +42438,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
4238742438 (false, None) => None,
4238842439 }
4238942440 } else {
42390- lr_active.then(|| (plane_snapshot(&y, 0), plane_snapshot(&u, 1), plane_snapshot(&v, 1)))
42441+ // lane-av1422filter: chroma band geometry follows the frame's own
42442+ // ss_y (see the keyframe path's note) -- 4:2:2 stripes full-height.
42443+ lr_active.then(|| {
42444+ (
42445+ plane_snapshot(&y, 0),
42446+ plane_snapshot(&u, ss_y(fctx) as u32),
42447+ plane_snapshot(&v, ss_y(fctx) as u32),
42448+ )
42449+ })
4239142450 };
4239242451 // lane-tiny r4: post-deblock / post-CDEF dumps mirroring aomdec's own
4239342452 // 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.