From bbcf2acafa3bdfb644e4762f19fa23c145d6f3bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 26 Sep 2026 04:54:25 +0300 Subject: [PATCH] ec-av1: lane-av1422mi24 -- the t422 inter ladder continued from the mi(24,60) first divergence: the first divergent symbol is the mi(24,56) 16x16 inter block's U dc_sign (ours dc_sign_cdf[0], oracle row 1; every level read around it matches rng-for-rng, so the SCAN placement is correct -- the codebase's row-major SCAN_8X16/SCAN_16X8 and libaom's column-major default_scan_8x16/16x8 enumerate identical (row,col) orders, verified cell by cell); root cause is the ctxgather lane's per-mi chroma gather class at ss (1,0) in three more block classes: decode_inter_block's block around (single-TU and var-tx arms, square + rect_tu), decode_rect_split's chroma_tiled else branch (the 16x8 intra-in-inter strip's (8,8) chroma unit at mi(26,60) read its U dc_sign one row high) and its unsplit single-TU arm, and decode_intrabc_rect's two chroma gathers (unreachable on the pinned fixture, gated-only verification); all edits gated ss_x==1 && ss_y==0 with the other arm verbatim; around_mi_422_chroma gains the EC_DCDUMP422 dump for diagnostic parity; frame-1 partition walk now matches the oracle rng-for-rng 300/300 and ALL frames 1-15 decode LUMA-exact at prefilt and postdeb (frame 0 stays exact at all stages); the residual is a chroma pixel-level class (entropy-identical), first site the mi(0,22) 8x8 leaf's chroma U rows 4..7 -- named for the owning lane; 4:2:0/4:4:4 identity by the 8 lossless gates (3 named) green; cargo check 0 warnings --- crates/ec-av1/src/decode.rs | 121 ++++++++++++++++++++++++++++++++++-- lanes/av1422mi24.report.md | 106 +++++++++++++++++++++++++++++++ 2 files changed, 221 insertions(+), 6 deletions(-) create mode 100644 lanes/av1422mi24.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 81432d1d..249e3049 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -8586,6 +8586,22 @@ impl Neighbours { o.2 += dc_vote(left[plane].dc); } } + if crate::envflags::env_flag!("EC_DCDUMP") { + // lane-av1422mi24: same dump [`Self::around_mi_rect`] prints, so + // a rerouted 4:2:2 chroma gather stays visible under EC_DCDUMP=1. + // The above rows are the SAMPLED (every-second) cells. + for (plane, o) in out.iter().enumerate() { + let vote = o.2; + let ab: Vec = (0..above_mi) + .step_by(2) + .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level)) + .collect(); + let lf: Vec = (0..left_mi) + .map(|k| format!("{:?}/{}", self.left[mi_r + k][plane].dc, self.left[mi_r + k][plane].level)) + .collect(); + eprintln!("EC_DCDUMP422 mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(",")); + } + } out } @@ -10755,7 +10771,16 @@ fn decode_rect_split( // rule) -- the plain rect walk samples one chroma cell // twice at ss_x 1. Every pre-existing shape keeps its own // walk. - let cu_around = if chroma_422_oob { + // lane-av1422mi24: the plain rect walk's double-count + // hits EVERY unit shape at ss (1,0), not just the (4, 8) + // one -- the (8, 8) unit of a 16x8 intra-in-inter strip + // read its above dc votes twice and its U dc_sign one + // ctx row high (t422 frame 1). Route every ss (1,0) + // unit through the every-second-above-cell sampling; + // 4:2:0/4:4:4 keep the plain walk verbatim. + let cu_around = if chroma_422_oob + || (ss_x(fctx) == 1 && ss_y(fctx) == 0) + { neighbours.around_mi_422_chroma(cu_mi, luma_span_x, luma_span_y) } else { neighbours.around_mi_rect(cu_mi, luma_span_x, luma_span_y) @@ -10844,7 +10869,19 @@ fn decode_rect_split( } else { default_intra_tx_type(m.uv_predict_mode as u8) }; - let around = neighbours.around_mi_rect(at_mi, bw, bh); + // lane-av1422mi24: at ss (1,0) the chroma above span is `bw >> 1` + // chroma cells spread over `bw` luma mi columns -- the per-mi gather + // counts every chroma column's whole-unit dc sign twice (the t422 + // frame-1 mi(26,60) intra-in-inter strip's U dc_sign read one ctx + // row high). Luma keeps the per-mi gather; the two chroma planes + // take [`Neighbours::around_mi_422_chroma`]'s every-second + // above-cell sampling, like every other 4:2:2 chroma gather. + let mut around = neighbours.around_mi_rect(at_mi, bw, bh); + if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + let c = neighbours.around_mi_422_chroma(at_mi, bw, bh); + around[1] = c[1]; + around[2] = c[2]; + } let mut grids: Vec = Vec::with_capacity(2); for plane_idx in 1..=2 { let skip_ctx = @@ -11848,7 +11885,21 @@ fn decode_intrabc_rect( match leaves.as_ref() { None => { // One whole-block rectangular transform unit. - let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); + // lane-av1422mi24: at ss (1,0) the chroma above span is + // `bw >> 1` chroma cells spread over `bw` luma mi columns -- + // the per-mi gather counts every chroma column's whole-unit + // dc sign twice (t422 frame 1, the mi(26,60) intra-in-inter + // strip's U dc_sign read ctx 1 where the oracle's cell sum + // is 0 -> ctx 0). Luma keeps the per-mi gather; the two + // chroma planes take + // [`Neighbours::around_mi_422_chroma`]'s every-second + // above-cell sampling, like every other 4:2:2 chroma gather. + let mut around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); + if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + let c = neighbours.around_mi_422_chroma((mi_r, mi_c), bw, bh); + around[1] = c[1]; + around[2] = c[2]; + } let (grid, tx_type) = read_inter_plane_rect( dec, cdfs, @@ -11973,7 +12024,15 @@ fn decode_intrabc_rect( // `av1_get_tx_type`'s chroma lookup lands on the colocated // LUMA unit, which for a split block is the top-left one. luma_tx_type = first_tx_type; - let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); + // lane-av1422mi24: same 4:2:2 chroma gather rule as the + // `None` arm above -- the per-mi rect gather double-counts + // each chroma column's whole-unit dc sign at ss (1,0). + let mut around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); + if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + let c = neighbours.around_mi_422_chroma((mi_r, mi_c), bw, bh); + around[1] = c[1]; + around[2] = c[2]; + } let (ug, _) = read_inter_plane_rect( dec, cdfs, @@ -33084,7 +33143,39 @@ fn decode_inter_block( // OWN width above and height left -- reading `side` cells both // ways indexes past the tile's last mi row for a bottom strip. let around = if rect_tu { - neighbours.around_mi_rect(at_mi, write_w, write_h) + // lane-av1422mi24: at ss (1,0) the rect strip's chroma + // above span is `write_w >> 1` chroma cells spread over + // `write_w` luma mi columns -- the per-mi gather counts + // every chroma column's whole-unit dc sign twice (the + // t422 frame-1 mi(26,60) strip's U dc_sign read one row + // high). Luma keeps the per-mi extents; chroma takes + // [`Neighbours::around_mi_422_chroma`]'s every-second- + // above-cell sampling. + let mut a = neighbours.around_mi_rect(at_mi, write_w, write_h); + if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + let c = neighbours.around_mi_422_chroma(at_mi, write_w, write_h); + a[1] = c[1]; + a[2] = c[2]; + } + a + } else if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + // lane-av1422mi24: at ss (1,0) a square block's chroma + // plane block is (side/2, side) -- `side` chroma 4-px + // above cells spread over `side` luma mi columns, one + // chroma column per PAIR of luma mi cells. The plain + // per-mi gather samples every second chroma column, and + // its dc-vote sum lands one sign row off (t422 frame 1, + // mi(24,56) U dc_sign: ours read dc_sign_cdf[0] where + // the oracle read row 1). Luma keeps the per-mi gather + // verbatim; only the two chroma planes take + // [`Neighbours::around_mi_422_chroma`]'s every-second- + // above-cell sampling (the same measured rule the strip + // and chunk arms already run). + let mut a = neighbours.around_mi(at, side); + let c = neighbours.around_mi_422_chroma(at, write_w, write_h); + a[1] = c[1]; + a[2] = c[2]; + a } else { neighbours.around_mi(at, side) }; @@ -34572,7 +34663,25 @@ fn decode_inter_block( // OWN width above and height left -- reading `side` cells both // ways indexes past the tile's last mi row for a bottom strip. let around = if rect_tu { - neighbours.around_mi_rect(at_mi, write_w, write_h) + // lane-av1422mi24: same 4:2:2 rect-strip chroma gather + // rule as the single-TU path above -- luma per-mi, + // chroma every-second above cell. + let mut a = neighbours.around_mi_rect(at_mi, write_w, write_h); + if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + let c = neighbours.around_mi_422_chroma(at_mi, write_w, write_h); + a[1] = c[1]; + a[2] = c[2]; + } + a + } else if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + // lane-av1422mi24: same 4:2:2 square-block chroma gather + // rule as the single-TU path above -- luma per-mi, chroma + // every-second above cell. + let mut a = neighbours.around_mi(at, side); + let c = neighbours.around_mi_422_chroma(at, write_w, write_h); + a[1] = c[1]; + a[2] = c[2]; + a } else { neighbours.around_mi(at, side) }; diff --git a/lanes/av1422mi24.report.md b/lanes/av1422mi24.report.md new file mode 100644 index 00000000..c050af98 --- /dev/null +++ b/lanes/av1422mi24.report.md @@ -0,0 +1,106 @@ +# lane-av1422mi24 — the t422 inter ladder continued from mi(24,60): the +# square/rect block chroma context gathers routed through the 4:2:2 +# every-second-above-cell sampling; frame-1 entropy now in FULL rng lockstep +# and ALL frames' LUMA decodes exact; the residual is a chroma pixel-level +# class (entropy-identical), first site named below + +## Outcome + +1. **Reproduction at HEAD 95408ed3.** The ctxgather lane's named residual + reproduced exactly: frame 0 exact at prefilt/postdeb/postcdef; frame 1 + prefilt first diffs Y (96,240) = mi(24,60), U chroma (2,44), V (0,44). +2. **The mi(24,60) divergence localized (rng-anchored lockstep, + EC_TRACE_PART + EC_AV1_TRACE pairing vs the oracle's EC_PART).** 293 + partition reads matched rng-for-rng; the walk first misaligned at the + NEXT 16x16 read (mi(24,60) pre-read rng 52112 vs oracle 64776). Window + diff (EC_ISTEP / EC_COEFF / EC_COEFF_STEP) pinned the first divergent + symbol: the **U dc_sign read of the mi(24,56) 16x16 inter block** — ours + `dc_sign_cdf[0]`, oracle row 1. Every level read around it matched + rng-for-rng: the coefficient scan placement is CORRECT (the codebase's + row-major SCAN_8X16/SCAN_16X8 pair and libaom's column-major + default_scan_8x16/default_scan_16x8 enumerate identical (row, col) + orders; verified cell by cell against the oracle source). +3. **Root cause, class `per-mi chroma context gather` (the ctxgather + lane's own rule, three more sites).** At ss (1,0) one chroma 4-px + column spans TWO luma mi columns; the plain + [`Neighbours::around_mi_rect`]/[`around_mi`] walk samples the above + span per luma mi and counts every chroma column's whole-unit dc sign + twice, so `dc_sign_ctx`'s vote sum lands one sign row off. Three block + classes still gathered per-mi at ss (1,0): + * `decode_inter_block`'s block `around` — single-TU arm AND the + var-tx/mu arm (square blocks: the mi(24,56) 16x16; rect_tu strips: + 16x8 pieces), previously only the strip-pair `around_c` was routed; + * `decode_rect_split`'s `chroma_tiled` arm — the else branch kept the + plain walk for every non-(4,32) unit, so a 16x8 intra-in-inter + strip's (8, 8) chroma unit (mi(26,60), the frame-1 HORZ pair's second + piece) read its U dc_sign one row high; + * `decode_rect_split`'s unsplit single-TU chroma arm (line ~10863) + and `decode_intrabc_rect`'s two chroma gathers — same class, fixed + under the same ss (1,0) gate. The intrabc arms are UNREACHABLE on the + pinned fixture (`intrabc_hits: 0`): verified by gating only, not by a + 4:2:2-intrabc witness (per the intrabc inventory discipline the + owning lane should witness them). + Every edit is gated `ss_x == 1 && ss_y == 0` with the non-4:2:2 arm the + original expression verbatim. +4. **Diagnostic parity (Main's request): [`around_mi_422_chroma`] now + prints the same env-gated `EC_DCDUMP422` block `around_mi_rect` prints** + (sampled above cells), so a rerouted 4:2:2 chroma gather stays visible + under `EC_DCDUMP=1`. +5. **Oracle ground truth used:** the instrumented aomdec's `EC_DBGCTX` + chroma context dump (cells + the built binary's `dc_sign_contexts` + table, extracted from the binary: signum semantics {neg:1, 0:0, + pos:2}, matching our `dc_sign_ctx`). The src tree's table literal + differs from the built one; the binary is authoritative. + +## Verification + +- **Partition lockstep, frame 1, post-fix (decode_probe + + EC_TRACE_PART vs oracle EC_PART, 2-frame fixture):** 300/300 oracle + partition reads match rng-for-rng in walk order (ours consumes 4 extra + gathered `EC_PARTG` prints the oracle does not emit) — **no rng + mismatch anywhere in the frame**. +- **t422 inter ladder re-measured** (decode_probe + + EC_AV1_{PREFILT,POSTDEBLOCK,POSTCDEF}_DUMP vs the oracle stage dumps, + our dumps /tmp/i422/av1422mi24/*{prefilt,postdeb,postcdef}*8): + * frame 0: exact at all three stages; + * **LUMA: 0 diffs on EVERY frame 1–15 at prefilt AND postdeb** (frame 1 + was 2146 diffs pre-lane; frame 3 was 25163). Frame 15 postcdef shows + Y=5059 — a CDEF knock-on: CDEF decisions read the (still wrong) + chroma, not a luma defect (postdeb f15 Y=0); + * chroma: frame 1 U 4346 → 4175, V 4974 → 4636; frames 3–14 chroma + improved on every plane (e.g. f3 U 12610 → 4363); first U diff moved + to chroma (4,44). +- **Frame exactness claimed ONLY where measured 0:** frame 0 all stages; + frames 1–15 LUMA at prefilt/postdeb. Frames 1+ chroma are NOT claimed. +- **The residual, site named (next lane's first diff).** With entropy in + full lockstep (luma exact everywhere proves it), the remaining chroma + diffs are a PIXEL-level class, entropy-identical: first frame-1 diffs + U chroma (4,44) → luma (88,8) — the 8x8 inter leaf mi(0,22)'s chroma: + U rows 0..3 exact, rows 4..7 wrong; V col 44,45 rows 0..15. The oracle + reads NO U residual there (no `EC_COEFF plane=1` at chroma cell + (11,0)), so this is a chroma prediction/reconstruction defect for sub-8 + 4:2:2 leaves (`chroma422_sub8` / `sub8_inter_split` territory), not a + context-gather defect. CDEF-stage luma diffs on f15 are downstream of + it. +- **4:2:0/4:4:4 identity:** every edit is ss (1,0)-gated with the other + arm verbatim; the lossless gate battery stays green — 8 passed 0 failed + including `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-av1422mi24`): + **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. +- Charter note: the s2.obu mandelbrot re-run was DONE by Agent104 (still + panics at decode.rs:3709, empty pred slice — bigblock lane's defect); + dropped from this lane per Main. + +## State + +- Commit on lane-av1-422mi24 (no push): the ss (1,0) chroma-gather fixes + in `crates/ec-av1/src/decode.rs` + this report. +- Next stop named for the owning lane: the chroma pixel-level class — + first site the frame-1 8x8 inter leaf mi(0,22)'s chroma (U rows 4..7, + V rows 0..7, chroma cols 44..47), prediction/reconstruction for sub-8 + 4:2:2 leaves with entropy in lockstep; and the f15 postcdef CDEF + knock-on disappears with it.