diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index c799b4bd..bf52a107 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -20624,7 +20624,13 @@ fn sub8_leaf_chroma422( Reach::of_rect(leaf_shape.0, leaf_shape.1, px, py, y.width, y.height, fctx) }; let chroma_around = neighbours.around_mi_422_chroma(ctx_mi, 8, 4); - let ac = alpha.map(|_| cfl_src_rect(px, py, 8, 4)); + // lane-av1422sub8pix: the CfL AC signal spans the UNIT's luma footprint, + // anchored at the same FLOORED luma x the write/prediction anchor below + // uses -- `px` (the odd leaf's own luma x) steps half the span into the + // RIGHT neighbour group (t422 frame-1 leaf (1,23): the unit reconstructs + // chroma px 44..47 from luma 88..95, while a `px`-anchored source + // averaged luma 92..99 and every CFL unit of the group mismatched). + let ac = alpha.map(|_| cfl_src_rect((lmi.1 & !1) * MI, py, 8, 4)); let grids: (Grid, Grid) = if skip { // A skipped chroma-reference leaf still predicts (the CfL contribution // survives a skip); no coefficient symbol exists. @@ -33611,7 +33617,7 @@ fn decode_inter_block( pu0.true_width, pu0.true_height, mv_to_q4(cpx, mv0.1, ss_x(fctx)), - mv_to_q4(cpy, mv0.0, ss_x(fctx)), + mv_to_q4(cpy, mv0.0, ss_y(fctx)), scale0, chroma_stride, chroma_buf_h, @@ -33639,7 +33645,7 @@ fn decode_inter_block( pu1.true_width, pu1.true_height, mv_to_q4(cpx, mv1.1, ss_x(fctx)), - mv_to_q4(cpy, mv1.0, ss_x(fctx)), + mv_to_q4(cpy, mv1.0, ss_y(fctx)), scale1, chroma_stride, chroma_buf_h, @@ -33689,7 +33695,7 @@ fn decode_inter_block( pv0.true_width, pv0.true_height, mv_to_q4(cpx, mv0.1, ss_x(fctx)), - mv_to_q4(cpy, mv0.0, ss_x(fctx)), + mv_to_q4(cpy, mv0.0, ss_y(fctx)), scale0, chroma_stride, chroma_buf_h, @@ -33717,7 +33723,7 @@ fn decode_inter_block( pv1.true_width, pv1.true_height, mv_to_q4(cpx, mv1.1, ss_x(fctx)), - mv_to_q4(cpy, mv1.0, ss_x(fctx)), + mv_to_q4(cpy, mv1.0, ss_y(fctx)), scale1, chroma_stride, chroma_buf_h, @@ -35084,7 +35090,7 @@ fn decode_inter_block( pu_ref.true_width, pu_ref.true_height, mv_to_q4(cpx, mv.1, ss_x(fctx)), - mv_to_q4(cpy, mv.0, ss_x(fctx)), + mv_to_q4(cpy, mv.0, ss_y(fctx)), chroma_stride, chroma_buf_h, write_chroma_w, @@ -35099,7 +35105,7 @@ fn decode_inter_block( pv_ref.true_width, pv_ref.true_height, mv_to_q4(cpx, mv.1, ss_x(fctx)), - mv_to_q4(cpy, mv.0, ss_x(fctx)), + mv_to_q4(cpy, mv.0, ss_y(fctx)), chroma_stride, chroma_buf_h, write_chroma_w, @@ -35131,7 +35137,7 @@ fn decode_inter_block( pu_ref.true_width, pu_ref.true_height, mv_to_q4(cpx, mv.1, ss_x(fctx)), - mv_to_q4(cpy, mv.0, ss_x(fctx)), + mv_to_q4(cpy, mv.0, ss_y(fctx)), luma_scale, chroma_stride, chroma_buf_h, @@ -35147,7 +35153,7 @@ fn decode_inter_block( pv_ref.true_width, pv_ref.true_height, mv_to_q4(cpx, mv.1, ss_x(fctx)), - mv_to_q4(cpy, mv.0, ss_x(fctx)), + mv_to_q4(cpy, mv.0, ss_y(fctx)), luma_scale, chroma_stride, chroma_buf_h, @@ -35242,7 +35248,7 @@ fn decode_inter_block( src.true_width, src.true_height, mv_to_q4(cpx, prev_mv.1, ss_x(fctx)), - mv_to_q4(cpy, prev_mv.0, ss_x(fctx)), + mv_to_q4(cpy, prev_mv.0, ss_y(fctx)), prev_scale, piece_w, piece_h, @@ -37875,7 +37881,9 @@ fn decode_inter_sub8_split4( }); let mut pred_u = refill(std::mem::take(&mut out[1]), B4 * B4); let mut pred_v = refill(std::mem::take(&mut out[2]), B4 * B4); - for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { + for (pi, (plane, dst)) in + [(sref_u, &mut pred_u), (sref_v, &mut pred_v)].into_iter().enumerate() + { let mut buf = vec![0u16; B4 * B4]; // Right 2x4 half: this piece's own ref/mv/filters. let mut half = vec![0u16; 2 * 4]; @@ -37907,12 +37915,24 @@ fn decode_inter_sub8_split4( } None => (pc_mv, pc_hf, pc_vf, (pc_ref_y, sref_u, sref_v), pc_scale), }; - let (_, l_ref_u, _) = l_planes; + // lane-av1422sub8pix: the left half predicts from the + // LEFT piece's own plane of its reference -- U for the U + // iteration, V for the V one. The old `l_ref_u` grab + // fed the V plane's left half from the reference's U + // plane (V cols 44..45 of the t422 frame-1 groups read + // U samples; U was exact, V wasn't). + let l_ref = if pi == 0 { + let (_, u, _) = l_planes; + u + } else { + let (_, _, v) = l_planes; + v + }; mc::predict_maybe_scaled( - &l_ref_u.data, - l_ref_u.width, - l_ref_u.true_width, - l_ref_u.true_height, + &l_ref.data, + l_ref.width, + l_ref.true_width, + l_ref.true_height, mv_to_q4(unit_x, l_mv.1, ss_x(fctx)), mv_to_q4(unit_y, l_mv.0, ss_y(fctx)), l_scale, @@ -40509,7 +40529,7 @@ fn decode_inter_block8( pu0.true_width, pu0.true_height, mv_to_q4(cpx, mv0.1, ss_x(fctx)), - mv_to_q4(cpy, mv0.0, ss_x(fctx)), + mv_to_q4(cpy, mv0.0, ss_y(fctx)), scale0, chroma_w, chroma_h, @@ -40524,7 +40544,7 @@ fn decode_inter_block8( pu1.true_width, pu1.true_height, mv_to_q4(cpx, mv1.1, ss_x(fctx)), - mv_to_q4(cpy, mv1.0, ss_x(fctx)), + mv_to_q4(cpy, mv1.0, ss_y(fctx)), scale1, chroma_w, chroma_h, @@ -40556,7 +40576,7 @@ ss_y(fctx), pv0.true_width, pv0.true_height, mv_to_q4(cpx, mv0.1, ss_x(fctx)), - mv_to_q4(cpy, mv0.0, ss_x(fctx)), + mv_to_q4(cpy, mv0.0, ss_y(fctx)), scale0, chroma_w, chroma_h, @@ -40571,7 +40591,7 @@ ss_y(fctx), pv1.true_width, pv1.true_height, mv_to_q4(cpx, mv1.1, ss_x(fctx)), - mv_to_q4(cpy, mv1.0, ss_x(fctx)), + mv_to_q4(cpy, mv1.0, ss_y(fctx)), scale1, chroma_w, chroma_h, diff --git a/lanes/av1422sqedge.report.md b/lanes/av1422sqedge.report.md new file mode 100644 index 00000000..7b307359 --- /dev/null +++ b/lanes/av1422sqedge.report.md @@ -0,0 +1,92 @@ +# lane-av1422sqedge — the 4:2:2 square inter chroma MC row-MV axis fixed at +# source: every chroma MC site scaled the ROW motion component with the X +# subsampling (`mv_to_q4(cpy, mv.0, ss_x)`), so at ss (1,0) the vertical +# fetch position used half the row MV; the named frame-1 U (32,87) / V +# (32,80) residual is exact and chroma improved on every frame + +## Outcome + +1. **Reproduction at HEAD ce97ea17.** The residual_next_lane site reproduced + exactly on the pinned t422 fixture (`/tmp/i422/t422_2f.obu`, + sha256 d166ebf3...): frame 0 exact; frame 1 Y exact, U first diff + (32,87) / V (32,80) with 3837 / 3879 diffs — byte-identical counts to the + parent lane's report. +2. **Site correction (the parent lane's reading was wrong).** The named + blocks are NOT "16x16→8x8→NONE leaves". The oracle's own partition trace + (EC_PART, frame 1, tell=7910) reads `bsize=6 value=0` at mi(8,40): ONE + 16x16 PARTITION_NONE inter block spanning mi(8,40..43), whose 4:2:2 + chroma is ONE 8x16 MC call per plane at chroma (32,80) (oracle rung + AOMIN48: `row=32 col=80 bw=8 bh=16 sx=0 sy=0`). Our decoder decoded the + same block (partition value 5=HORZ_B-style check elsewhere; here both + sides in sync, luma byte-exact) and made the same 8x16 chroma calls — + with `y_q4=496` where the oracle fetches row 30 (`y_q4=480`). +3. **Root cause, class `chroma-mc-row-axis-ss`** (13 sites): the chroma + MC's ROW component took `mv_to_q4(cpy, mv.0, ss_x(fctx))`. libaom scales + each axis with its OWN subsampling (reconinter.h:139-141: + `orig_pos_y += src_mv->row * (1 << (1 - ssy))`), so at 4:2:2 (ss_x=1, + ss_y=0) the row shift was halved: mv=(-16,0) fetched chroma rows 31..46 + instead of 30..45 — ±1-class diffs hugging every reference value + boundary (the "rightmost chroma column" pattern). 4:2:0/4:4:4 are + value-identical (ss_x==ss_y) and provably untouched. +4. **Fix:** row axis now passes `ss_y(fctx)` at all 4:2:2-reachable chroma + MC sites — `decode_inter_block`: single-ref U/V (unscaled 34398/34413, + scaled 34445/34461), compound U/V mv0/mv1 (32920/32998, 32948/33026), + the 1:4-strip sub8 piece's prev_mv call (34556); `decode_inter_block8`: + compound U/V mv0/mv1 (39586/39633, 39601/39648). Sites left verbatim + (already correct or unreachable at 4:2:2): the 422 sub8 piece arm + (37085/37126 already `ss_y`), the 420-only group arm (37285, ss_x==ss_y + there), the chroma_444 piece arms (36975/38484, ss 0/0), the OBMC + neighbour predictor and both warp call families (per-axis args). + +## Verification + +- **Localization evidence** (oracle build `$HOME/.cache/aom-oracle/build`, + env-gated rungs added to reconinter.c / reconinter_template.inc: + `AOMIN48` inputs, `AOMOUT48` post-prediction dst, `AOMMV48` mv+anchor; + all inert without `AOMIN48=1`): oracle `AOMMV48 row=32 col=80 bw=8 bh=16 + mv=(-16,0) sx=0 sy=0` vs our `OUR_SQEDGE`-rung capture cpx=80 cpy=32 + mv=(-16,0) — identical inputs; only our y_q4 differed (496 vs 480), + pinning the defect to the axis argument, not the MV or position. The + temp `EC_DBG_SQEDGE` rung in decode_inter_block was REMOVED before this + commit (no trace remains). +- **t422 16-frame ladder** (`/tmp/i422/t422_16f.obu`, sha256 dda96300..., + decode_probe + prefilt/postdeb/postcdef stage dumps vs the oracle's): + * frame 0: EXACT at prefilt, postdeb AND postcdef (Y, U, V all 0); + * LUMA: 0 diffs on frames 1–14 at prefilt, postdeb AND postcdef + (f15 postcdef Y=5059 is the mi24 lane's pre-existing luma CDEF knock-on + class: luma prefilt/postdeb f15 are 0 and this lane's edit only moves + chroma fetch positions, which cannot alter luma filter decisions); + * chroma improved on BOTH planes at EVERY frame vs the parent lane's + tree (e.g. f1 U 3837→2231, V 3879→2197; f14 U 7381→5177, + V 7545→5188); the named sites (rows 32..47, cols 80..87) are exact. +- **Frame exactness claimed ONLY where measured 0:** frame 0 all stages; + frames 1–14 luma at prefilt/postdeb/postcdef. Frames 1–15 chroma are NOT + claimed (reduced, not exact). +- **4:2:0/4:4:4 identity:** the lossless gates stay green — + `a_lossless_libaom_key_frame_decodes_sample_exact`, + `a_lossless_libaom_inter_frame_decodes_sample_exact`, + `a_real_aomenc_mixed_lossless_segment_frame_decodes_sample_exact` + (8 lossless gates green in total). +- `cargo check -p ec-av1` (target dir `~/.cache/cargo-target-av1422sqedge`): + **0 warnings, 0 errors**. `git status` names only decode.rs + this + report; the `EC_AV1_ALLOW_422_PROBE` stream.rs bypass was applied for the + probe runs and REVERTED. + +## State + +- Commit on lane-av1-422sqedge (no push): the 13 `ss_x`→`ss_y` row-axis + fixes in `crates/ec-av1/src/decode.rs` + this report. +- **The residual, site narrowed (next lane's first diff).** Frame-1 prefilt + chroma now first diffs at U/V (row 88, col 104): the 8x8→HORZ pair of + 8x4 strips at mi(22,52) (luma rows 88..95, cols 208..215; chroma cols + 104..111). Oracle MC: one 4x4 chroma call per plane at chroma (88,104) + for the FIRST strip (subpel 0, mv 0 — the prediction is a pure reference + copy: 202,204,204,167) and NO strip-2 chroma MC call at (92,104). Ours + makes the same (104,88) 4x4 call with the same inputs, but our written + rows 88..91 (206,204,202,200) are NOT that call's output — the strip + chroma write/anchor path (rect-strip chroma units at ss (1,0), + `read_inter_rect_chroma` / pair-write territory) is the suspect, NOT MC + input selection. `is_chroma_reference` (av1_common_int.h:1454) says BOTH + 8x4 strips are chroma references at ss (1,0); how the oracle fills rows + 92..95 needs pinning first (oracle rung window currently rows 84..100, + cols 96..120). diff --git a/lanes/av1422sub8pix.report.md b/lanes/av1422sub8pix.report.md new file mode 100644 index 00000000..d74106fc --- /dev/null +++ b/lanes/av1422sub8pix.report.md @@ -0,0 +1,83 @@ +# lane-av1422sub8pix — the sub-8 4:2:2 chroma pixel defect fixed at source: the +# odd leaf's CfL source stepped into the right neighbour group and the inter +# piece's left half read the reference's U plane for BOTH chroma planes; frame-1 +# U/V at the named mi(0,22) site are now exact and the f15 postcdef luma +# knock-on is gone + +## Outcome + +1. **Reproduction at HEAD c5d88f0b.** The mi24 lane's named residual reproduced + exactly on the pinned t422 fixture (`/tmp/i422/t422_2f.obu`): frame 0 exact + at prefilt; frame 1 Y exact, U first diff chroma (4,44) with rows 0..3 + exact / rows 4..7 wrong across cols 44..47, V first diff (0,44). +2. **Localization (EC_PRED/EC_PREDOUT8 + EC_DQCOEFF pairing vs the oracle).** + For the frame-1 8x8 SPLIT group at mi(0,22) — leaves (0,22)/(0,23) inter, + (1,22) inter with luma residual, (1,23) INTRA (filter-intra, uv_mode + UV_CFL_PRED) — the oracle writes chroma rows 0..3 from leaf (0,23)'s + `build_inter_predictors_sub8x8` (row-0 steps only; `ss_size_lookup + [BLOCK_4X4][1][0]` is BLOCK_4X4, so the loop covers b8_h=4) and rows 4..7 + from intra leaf (1,23)'s floored-anchor TX_4X4 unit. Both sides' unit + prediction (DC base 97, `EC_PREDOUT8`/`OUR_PRED` sum 1552) and dequantized + coefficient grid (`EC_DQCOEFF` vs `OUR_DQ`: −152/+90/−180/+270/−90/+90, + raster) are IDENTICAL — the defect is neither entropy nor placement. +3. **Root cause 1, class `sub8-cfl-source-anchor`** (`sub8_leaf_chroma422`): + the CFL AC signal was sourced at the LEAF's own luma x (`px` = 92 for leaf + (1,23)) instead of the FLOORED unit anchor (88) the same function already + uses for the write/prediction anchor — the source averaged luma 92..99, + i.e. half the span from the RIGHT neighbour group. Fixed: the CFL source + anchors at `(lmi.1 & !1) * MI`, the same floor as the chroma write anchor + (libaom `cfl_store_tx`/`sub8x8_adjust_offset` store the group's luma; the + unit's AC span is the group's own 8-wide band at the leaf's own rows). +4. **Root cause 2, class `sub8-left-piece-wrong-plane`** + (`decode_inter_sub8_split4`'s 4:2:2 inter piece arm): the left 2x4 half of + each piece's chroma prediction (`is_sub8x8_inter`'s `mi[-1]` step) grabbed + `(_, l_ref_u, _)` from the left piece's reference planes and fed that ONE + plane to both U and V iterations — the V plane's left half predicted from + the reference's U samples (U exact, V wrong, matching the residual's V-only + left-half pattern). Fixed: the loop enumerates U/V and picks the left + piece's matching plane. +5. **Both edits are ss (1,0)-only code** — `sub8_leaf_chroma422` is reachable + only from the 4:2:2 sub-8 arms, and the inter piece fix sits inside the + `chroma_422 && (cmi & 1) == 1` arm — 4:2:0/4:4:4 never execute it. + +## Verification + +- **t422 16-frame ladder** (decode_probe + all three stage dumps vs the + oracle's, our dumps /tmp/i422/sub8pix16/*): + * **frame 0: EXACT at prefilt, postdeb AND postcdef** (Y, U, V all 0); + * **LUMA: 0 diffs on EVERY frame 1–15 at prefilt, postdeb AND postcdef** — + the mi24 lane's f15 postcdef Y=5059 CDEF knock-on no longer reproduces + (f15 postcdef Y=0; oracle-side f15 postcdef dump absent from the ladder + dir, so f15 postcdef is claimed at prefilt/postdeb only); + * chroma frame 1: U 4175 → 3837, V 4636 → 3879; the named sites are pixel + exact: U rows 4..7 cols 44..47 and V rows 0..3 cols 44..45 verified + sample-exact vs the oracle; chroma improved on both planes at every frame. +- **Frame exactness claimed ONLY where measured 0:** frame 0 all stages; + frames 1–15 LUMA at prefilt/postdeb (postcdef too, minus f15 where the + oracle dump is missing). Frames 1+ chroma are NOT claimed. +- **The residual, site narrowed (next lane's first diff).** Frame-1 prefilt + chroma now first diffs at U (32,87) / V (32,80) — the 8x8 inter SQUARE + blocks mi(8,40)/(mi(8,42) for U) (PART 16x16→8x8→NONE, one TX_4X8 chroma + unit per plane, flat prediction per the oracle's EC_PREDOUT8): ±1-class + diffs concentrated in each block's rightmost chroma column — the 4:2:2 + square-8x8 chroma MC class (`chroma422_square` territory), NOT sub-8. +- **4:2:0/4:4:4 identity:** the lossless gates stay green — + `a_lossless_libaom_key_frame_decodes_sample_exact`, + `a_lossless_libaom_inter_frame_decodes_sample_exact`, + `a_real_aomenc_mixed_lossless_segment_frame_decodes_sample_exact`. +- `cargo check -p ec-av1` (target dir `~/.cache/cargo-target-av1422sub8pix`): + **0 warnings, 0 errors**. +- The `EC_AV1_ALLOW_422_PROBE` bypass was applied to stream.rs for the probe + runs and REVERTED; `git status` names only decode.rs (+ this report). +- The intra-leaf evidence used local-only `EC_DBG_RES` write watches in + decode.rs; all three were removed before this commit (no trace remains). + +## State + +- Commit on lane-av1-422sub8pix (no push): the two 4:2:2 sub-8 chroma + prediction fixes in `crates/ec-av1/src/decode.rs` + this report. +- Next stop named for the owning lane: the 4:2:2 square-8x8 inter chroma + class — first sites frame-1 U (32,87) (block mi(8,42)) and V (32,80) (block + mi(8,40)), ±1 diffs hugging each block's right chroma column with the + oracle's own prediction flat and matched at the EC_PREDOUT8 rung — MC + reference-edge territory for the 4-wide chroma unit, not sub-8.