From a236cd35629353c532bfa16589e5ae1c8afbfa62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 23 Sep 2026 08:24:10 +0300 Subject: [PATCH] ec-av1: 4:4:4 rect/1:4 chroma port (WIP) + byte-exact square witnesses Square witnesses all byte-exact vs aomdec+ffmpeg (recipes under $HOME/.cache/av1444/witness_*.sh): 8-bit profile-1 filters off and on, forced-64x64-block arms (four-TX_32X32 chroma loop), 10-bit profile-2 filters off and on; 420 square arms unchanged (IDENTICAL). Root causes fixed this round: - u/v set_tile_origin hardcoded the 4:2:0 halving; at 4:4:4 the clamp hid the above/left edges from every chroma block in the right/bottom half of a tile (the 36k-diff chroma defect; entropy ladder was fully synced, 1596/1596 rng rungs vs instrumented aomdec). - deblock_plane_span clipped the chroma loop filter to a quarter of the plane at 4:4:4 (CDEF/restoration were already exact). - decode_block single-TU arm codes a 64x64 block's 4:4:4 chroma as four plane-major TX_32X32 units (av1_get_max_uv_txsize). Rect/1:4 4:4:4 port (in progress): - decode_block_rect4: shape-keyed chroma tables + the av1_get_ext_tx_set_type DCT_ONLY clamp (was ADST-at-32 panic). - read_inter_rect_chroma helper: 64-axis inter strips code two plane-major 32-capped chroma units at 4:4:4; both inter rect readers use it; read_inter_plane_rect chroma skip_ctx takes the +3 offset. - decode_rect4_16_strip: no 4:2:0 chroma pair at 4:4:4 -- every strip is its own chroma reference (key and inter paths), tables/CfL/edges anchor at the strip. Still open: av1-profile1-444.ivf decodes 24+ frames then panics (reconstruct_rect len 64 index 64) on a 64x16 intra strip with split transform -- decode_rect_split's 64-axis chroma at 4:4:4 is next. Full suite not run. --- crates/ec-av1/src/decode.rs | 320 +++++++++++++++++++++++------------- lanes/av1444.report.md | 172 +++++++++---------- 2 files changed, 294 insertions(+), 198 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 0575affd..5e90282d 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -10081,7 +10081,6 @@ fn decode_rect_split( let [ug, vg] = last; (ug, vg) } else if chroma_tiled { - eprintln!("EC_TILE chroma={chroma_w}x{chroma_h}"); let (uw, uh, set, scan): (usize, usize, TxbSet, &[u16]) = match (chroma_w, chroma_h) { (64, 32) | (32, 64) => (32, 32, TxbSet::Chroma32, default_scan(32)), (64, 16) => (32, 16, TxbSet::ChromaRect32x16, &SCAN_32X16), @@ -12060,11 +12059,21 @@ fn decode_block_rect4( let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx)); let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx)); let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx); - let (luma_scan, chroma_scan): (&[u16], &[u16]) = if bw > bh { - (&SCAN_32X8, &SCAN_16X4) - } else { - (&SCAN_8X32, &SCAN_4X16) + // lane-av1-444: the strip's chroma shape follows the subsampling. + // 4:2:0 codes 16x4/4x16 (`TxbSet::Chroma8`); 4:4:4 codes the strip + // itself, 32x8/8x32 (`get_txsize_entropy_ctx(TX_32X8)` = + // `(wide_log2 + high_log2 + 1) >> 1` = the 16x16 set, + // `TxbSet::Chroma16`). The caller set is closed -- this reader only + // ever sees 32x8 / 8x32 luma and the sequence header admits ss 0/0 + // and 1/1 only -- so the table is exhaustive. + let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (chroma_w, chroma_h) { + (16, 4) => (TxbSet::Chroma8, &SCAN_16X4[..]), + (4, 16) => (TxbSet::Chroma8, &SCAN_4X16[..]), + (32, 8) => (TxbSet::Chroma16, &SCAN_32X8[..]), + (8, 32) => (TxbSet::Chroma16, &SCAN_8X32[..]), + _ => unreachable!("decode_block_rect4 chroma shape set is closed"), }; + let luma_scan: &[u16] = if bw > bh { &SCAN_32X8 } else { &SCAN_8X32 }; let (luma_levels, u_levels, v_levels) = if skip { ( vec![0i32; bw * bh], @@ -12086,9 +12095,18 @@ fn decode_block_rect4( )?; let mut planes = Vec::with_capacity(2); for plane in 1..3 { - let default_tx = default_intra_tx_type(uv_predict_mode as u8); + // `av1_get_tx_type` (`blockd.h:1278`): the mode-indexed type + // stands only while it is a member of this tx size's set; a + // 32x8/8x32 chroma transform (4:4:4) squares up to TX_32X32, + // whose intra set is `EXT_TX_SET_DCTONLY` -- every ADST clamps + // to DCT_DCT there, and ADST is undefined at widths above 16. + let default_tx = if chroma_w.max(chroma_h) >= 32 { + TxType::DctDct + } else { + default_intra_tx_type(uv_predict_mode as u8) + }; let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1); - let mut coding = cdfs.txb(TxbSet::Chroma8, uv_predict_mode); + let mut coding = cdfs.txb(chroma_set, uv_predict_mode); let (levels, tx_type) = read_chroma_coeffs_rect( dec, &mut coding, @@ -12317,7 +12335,10 @@ fn decode_rect4_16( } else { (mi_row0, mi_col0 + i) }; - let has_chroma = i % 2 == 1; + // lane-av1-444: at 4:4:4 every strip is its own chroma reference + // (no mi-parity test at ss 0/0, and the strip's own chroma block is + // already >= 4x4) -- there is no 4:2:0 pair to close. + let has_chroma = i % 2 == 1 || (ss_x(fctx) == 0 && ss_y(fctx) == 0); let (mode, uv, _tx) = decode_rect4_16_strip( dec, cdfs, @@ -12382,7 +12403,6 @@ fn decode_rect4_16_strip( let (bw, bh) = if horz { (16usize, 4usize) } else { (4, 16) }; let (mi_w, mi_h) = (bw / MI, bh / MI); let scan: &[u16] = if horz { &SCAN_16X4 } else { &SCAN_4X16 }; - let chroma_scan: &[u16] = if horz { &SCAN_8X4 } else { &SCAN_4X8 }; let mut last_uv_mode: Option = None; // `decode_block_rect4`'s own neighbour rule: the coarse 16-px cell // aliases all four strips onto one entry, so the mi-exact map wins and @@ -12663,12 +12683,17 @@ fn decode_rect4_16_strip( } if has_chroma { hit!(RECT4_16_CHROMA_HITS); - let pair_mi = if horz { - (lmi.0 - 1, lmi.1) + // lane-av1-444: at 4:4:4 there is no pair -- every strip is its + // own chroma reference and codes its own 16x4 / 4x16 chroma + // block. (`set_mi_offsets`'s chroma snap is the zero offset at + // ss 0/0, so the neighbour reads below anchor at the strip.) + let (pair_mi, pw, ph) = if ss_x(fctx) == 0 && ss_y(fctx) == 0 { + (lmi, bw, bh) + } else if horz { + ((lmi.0 - 1, lmi.1), 16, 8) } else { - (lmi.0, lmi.1 - 1) + ((lmi.0, lmi.1 - 1), 8, 16) }; - let (pw, ph) = if horz { (16, 8) } else { (8, 16) }; let (ppx, ppy) = (pair_mi.1 * MI, pair_mi.0 * MI); let (cpx, cpy) = (ppx >> ss_x(fctx), ppy >> ss_y(fctx)); let (cw, ch) = (pw >> ss_x(fctx), ph >> ss_y(fctx)); @@ -12728,11 +12753,21 @@ fn decode_rect4_16_strip( (zeros.clone(), zeros) } else { let around = neighbours.around_mi_rect(pair_mi, pw, ph); + // lane-av1-444: the strip's own 16x4 / 4x16 chroma at ss 0/0 + // (`TxbSet::Chroma8`, `get_txsize_entropy_ctx(TX_16X4)` = + // the 8x8 set); 4:2:0 keeps the pair's 8x4 / 4x8. + let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (cw, ch) { + (8, 4) => (TxbSet::ChromaRect8x4, &SCAN_8X4[..]), + (4, 8) => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]), + (16, 4) => (TxbSet::Chroma8, &SCAN_16X4[..]), + (4, 16) => (TxbSet::Chroma8, &SCAN_4X16[..]), + _ => unreachable!("decode_rect4_16_strip chroma shape set is closed"), + }; let mut planes = Vec::with_capacity(2); for plane in 1..3 { let default_tx = default_intra_tx_type(uv_predict_mode as u8); let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1); - let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode); + let mut coding = cdfs.txb(chroma_set, uv_predict_mode); let (levels, tx_type) = read_chroma_coeffs_rect( dec, &mut coding, @@ -19019,6 +19054,10 @@ fn rect_inter_chroma_set(w: usize, h: usize) -> Result { // set for TX_16X4/TX_4X16 (`get_txsize_entropy_ctx` = TX_8X8, // `txsize_log2_minus4` = 2, 64-coefficient `eob_pt`). (16, 4) | (4, 16) => TxbSet::Chroma8, + // lane-av1-444: one 32x32 unit of a 4:4:4 64x32/32x64 chroma plane + // block (`av1_get_max_uv_txsize` adjusts `TX_64X32`/`TX_32X64` to + // `TX_32X32`); `get_txsize_entropy_ctx(TX_32X32)` is the 32x32 set. + (32, 32) => TxbSet::Chroma32, _ => { return Err(unsupported( "a rectangular inter chroma transform unit whose shape has no coefficient table set here", @@ -19027,6 +19066,7 @@ fn rect_inter_chroma_set(w: usize, h: usize) -> Result { }) } + /// libaom `size_group_lookup[bsize]` for the block shapes this decoder's /// inter path reaches, from the block's TRUE footprint rather than the /// square `side` corner-cut: 8x8/8x16/16x8 -> 1, 16x16/16x32/32x16 -> 2, @@ -19303,6 +19343,100 @@ fn read_block_tx_size_rect( Ok(Some(leaves)) } +/// The chroma half of a whole-block rectangular INTER transform unit (both +/// [`decode_inter_block`] rect readers): `av1_get_max_uv_txsize(bsize)` gives +/// the strip's own rect chroma size at 4:2:0 (one unit for the whole block), +/// but at 4:4:4 the chroma plane block keeps the luma block's 64-px axis, +/// which `av1_get_adjusted_tx_size` caps at 32 (`TX_64X16` -> `TX_32X16`), +/// so it codes TWO units plane-major (every U, then every V -- +/// `decode_token_recon_block`'s inter branch loops `for plane` outside +/// `for blk_row/blk_col` inside the one mu chunk). No unit codes a `tx_type` +/// symbol: each inherits the block-wide luma one (`av1_get_tx_type`'s inter +/// UV lookup at ss 0 reads the tx_type_map at its own mi, which a single-TU +/// luma block fills uniformly). +#[allow(clippy::too_many_arguments)] +fn read_inter_rect_chroma( + dec: &mut SymbolDecoder, + cdfs: &mut Cdfs, + neighbours: &mut Neighbours, + around: [(bool, bool, i32); 3], + u: &mut PlaneBuf<'static>, + v: &mut PlaneBuf<'static>, + su: Pred<'_>, + sv: Pred<'_>, + at_mi: (usize, usize), + (cpx, cpy): (usize, usize), + (write_chroma_w, write_chroma_h): (usize, usize), + chroma_side: usize, + mode_for_tx: usize, + luma_tx_type: TxType, + fctx: &crate::decode::FrameCtx, +) -> Result<(Grid, Grid)> { + let (uw, uh) = (write_chroma_w.min(32), write_chroma_h.min(32)); + let (nx, ny) = (write_chroma_w / uw, write_chroma_h / uh); + let multi = nx * ny > 1; + let set = rect_inter_chroma_set(uw, uh)?; + let mut assembled: [Vec; 2] = [Vec::new(), Vec::new()]; + if multi { + hit!(CHROMA_SPLIT_TX_HITS); + assembled = [ + vec![0i32; chroma_side * chroma_side], + vec![0i32; chroma_side * chroma_side], + ]; + } + for plane_idx in 1..=2 { + let (src, buf) = if plane_idx == 1 { (su, &mut *u) } else { (sv, &mut *v) }; + for cu_row in 0..ny { + for cu_col in 0..nx { + let (span_x, span_y) = (uw << ss_x(fctx), uh << ss_y(fctx)); + let cu_mi = ( + at_mi.0 + cu_row * (span_y / MI), + at_mi.1 + cu_col * (span_x / MI), + ); + let cu_around = if multi { + neighbours.around_mi_rect(cu_mi, span_x, span_y) + } else { + around + }; + let (cu_x, cu_y) = (cpx + cu_col * uw, cpy + cu_row * uh); + let cu_pred = src.offset(cu_row * uh * chroma_side + cu_col * uw); + let cu_grid = read_inter_plane_rect( + dec, + cdfs, + set, + (uw, uh), + chroma_side, + plane_idx, + cu_around[plane_idx], + mode_for_tx, + buf, + cu_x, + cu_y, + cu_pred, + Some(luma_tx_type), + multi.then_some(3), fctx, + )? + .0; + if multi { + // Immediately, so the next unit of this block reads this + // one's coefficient context (libaom updates the chroma + // above/left contexts per unit). + neighbours.record_mi_chroma(cu_mi, span_x, span_y, plane_idx, &cu_grid); + let dst = &mut assembled[plane_idx - 1]; + for rr in 0..uh { + let start = (cu_row * uh + rr) * chroma_side + cu_col * uw; + dst[start..start + uw].copy_from_slice(&cu_grid[rr * uw..][..uw]); + } + } else { + assembled[plane_idx - 1] = embed_rect_grid(&cu_grid, uw, uh, chroma_side); + } + } + } + } + let [ug, vg] = assembled; + Ok((Grid::Own(ug), Grid::Own(vg))) +} + /// [`read_inter_plane`] for a rectangular transform unit (lane-inter4 r2): /// the coefficients are read with the rect coefficient machinery /// ([`read_coeffs_rect`], whose `TxClass` handling covers the 1D `V_*`/`H_*` @@ -19345,7 +19479,12 @@ fn read_inter_plane_rect( // block; a var-tx leaf passes its own neighbour-table context. luma_skip_ctx.unwrap_or(0) } else { - usize::from(around.0) + usize::from(around.1) + // libaom `get_txb_ctx`: a chroma unit's context is + // `combine_entropy_contexts(above, left)` plus 7, or plus 10 when the + // plane block is bigger than the transform. Our chroma tables hold the + // offset-7 rows first, so a multi-unit caller adds 3 through + // `luma_skip_ctx` (same convention as [`read_plane`]). + usize::from(around.0) + usize::from(around.1) + luma_skip_ctx.unwrap_or(0) }; let mut coding = cdfs.txb(set, tx_mode); // libaom `read_tx_type` (`av1/decoder/decodetxb.c`): "No need to read @@ -27678,7 +27817,11 @@ fn decode_inter_block( let chroma_side = side >> ss_x(fctx); let (write_chroma_w, write_chroma_h) = match strip_chroma { Some(s) if s.has_chroma => { - if s.horz { + // 4:2:0: the PAIR's 8x4 / 4x8. 4:4:4: the strip's own 16x4 / + // 4x16 (lane-av1-444; no pair at ss 0/0). + if ss_x(fctx) == 0 && ss_y(fctx) == 0 { + if s.horz { (16, 4) } else { (4, 16) } + } else if s.horz { (8, 4) } else { (4, 8) @@ -29031,55 +29174,24 @@ fn decode_inter_block( // assembled grid (class `override-slot-on-one-arm`). mu_chroma = true; } else if rect_tu { - // `av1_get_max_uv_txsize(bsize)`: the chroma transform of a - // 2:1 strip is the strip's own rect chroma size (16x8 / - // 8x16), one unit for the whole block, and it codes no - // `tx_type` symbol -- it inherits the luma unit's. - let (uw, uh) = (write_chroma_w, write_chroma_h); - u_grid = Grid::Own(embed_rect_grid( - &read_inter_plane_rect( - dec, - cdfs, - rect_inter_chroma_set(write_chroma_w, write_chroma_h)?, - (uw, uh), - chroma_side, - 1, - around[1], - mode_for_tx, - u, - cpx, - cpy, - su, - Some(luma_tx_type), - None, fctx, - )? - .0, - uw, - uh, - chroma_side, - )); - v_grid = Grid::Own(embed_rect_grid( - &read_inter_plane_rect( - dec, - cdfs, - rect_inter_chroma_set(write_chroma_w, write_chroma_h)?, - (uw, uh), - chroma_side, - 2, - around[2], - mode_for_tx, - v, - cpx, - cpy, - sv, - Some(luma_tx_type), - None, fctx, - )? - .0, - uw, - uh, + // One chroma read for the whole strip at 4:2:0, two + // 32-capped units at 4:4:4 -- see the helper. + (u_grid, v_grid) = read_inter_rect_chroma( + dec, + cdfs, + neighbours, + around, + u, + v, + su, + sv, + at_mi, + (cpx, cpy), + (write_chroma_w, write_chroma_h), chroma_side, - )); + mode_for_tx, + luma_tx_type, fctx, + )?; } else { u_grid = read_inter_plane( dec, @@ -30374,55 +30486,24 @@ fn decode_inter_block( // assembled grid (class `override-slot-on-one-arm`). mu_chroma = true; } else if rect_tu { - // `av1_get_max_uv_txsize(bsize)`: the chroma transform of a - // 2:1 strip is the strip's own rect chroma size (16x8 / - // 8x16), one unit for the whole block, and it codes no - // `tx_type` symbol -- it inherits the luma unit's. - let (uw, uh) = (write_chroma_w, write_chroma_h); - u_grid = Grid::Own(embed_rect_grid( - &read_inter_plane_rect( - dec, - cdfs, - rect_inter_chroma_set(write_chroma_w, write_chroma_h)?, - (uw, uh), - chroma_side, - 1, - around_c[1], - mode_for_tx, - u, - cpx, - cpy, - su, - Some(luma_tx_type), - None, fctx, - )? - .0, - uw, - uh, - chroma_side, - )); - v_grid = Grid::Own(embed_rect_grid( - &read_inter_plane_rect( - dec, - cdfs, - rect_inter_chroma_set(write_chroma_w, write_chroma_h)?, - (uw, uh), - chroma_side, - 2, - around_c[2], - mode_for_tx, - v, - cpx, - cpy, - sv, - Some(luma_tx_type), - None, fctx, - )? - .0, - uw, - uh, + // One chroma read for the whole strip at 4:2:0, two + // 32-capped units at 4:4:4 -- see the helper. + (u_grid, v_grid) = read_inter_rect_chroma( + dec, + cdfs, + neighbours, + around_c, + u, + v, + su, + sv, + at_mi, + (cpx, cpy), + (write_chroma_w, write_chroma_h), chroma_side, - )); + mode_for_tx, + luma_tx_type, fctx, + )?; } else { u_grid = read_inter_plane( dec, @@ -37172,8 +37253,17 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( { break; } - let strip_has_chroma = i % 2 == 1; - let pair_mi = if !strip_has_chroma { + // lane-av1-444: at 4:4:4 every strip is + // its own chroma reference + // (`is_chroma_reference`: no mi parity + // test at ss 0/0 and the strip's 16x4 / + // 4x16 chroma block is already >= 4x4), + // so there is no pair: each strip codes + // and predicts its own chroma from its + // own motion (`prev` = None). + let strip_has_chroma = + i % 2 == 1 || (ss_x(fctx) == 0 && ss_y(fctx) == 0); + let pair_mi = if !strip_has_chroma || ss_x(fctx) == 0 { at_mi } else if horz { (at_mi.0 - 1, at_mi.1) @@ -37185,7 +37275,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( has_chroma: strip_has_chroma, horz, pair_mi, - prev: if strip_has_chroma { + prev: if strip_has_chroma && ss_x(fctx) == 1 { fctx.inter_last_mc.with(std::cell::Cell::get) } else { None diff --git a/lanes/av1444.report.md b/lanes/av1444.report.md index f07c703f..0c5cd18a 100644 --- a/lanes/av1444.report.md +++ b/lanes/av1444.report.md @@ -5,95 +5,101 @@ Branch `lane-av1-444`, base `7f8d6cf6`. Worktree `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1444`, `TMPDIR=$HOME/.cache/av1444-tmp`. Not pushed. -Status: **WIP**. 4:4:4 is no longer refused. Luma of a square profile-1 -keyframe is byte-exact vs aomdec and ffmpeg. Chroma is not. 4:2:2 stays a -named refusal. Full suite was not run. - -Commit: blocked by the global pre-commit hook -(`format-staged.py` runs `rustfmt ` with no `--edition`). That rustfmt -rejects the pre-existing `let` chains in `decode.rs` (`edition = "2024"`). -`rustfmt --edition 2024 --check` wants a wholesale reformat of `decode.rs`, -so the hook was not bypassed and the reformat was not applied. Changes are -staged, not committed. `git status` in the worktree is the source of truth. - -## What changed - -- `stream.rs`: the sequence-header refusal now fires only when - `subsampling_x != subsampling_y` (4:2:2). 4:4:4 (`0,0`) and 4:2:0 (`1,1`) - proceed. `set_subsampling` publishes the header values onto `FrameCtx` - once per frame, same slot as `set_mono`. -- `decode.rs`: chroma plane size, tx size, CFL window, loop-filter chroma - step, and the 8x8 leaf's chroma unit follow `ss_x`/`ss_y`. At 4:4:4 an - 8x8 leaf's chroma is 8x8 (`TxbSet::Chroma8`, `scans.0`), not the hardcoded - 4x4. A square block below 64 uses chroma tx = block side. A 64 block still - takes the single-TU arm (see the divergence below). -- `restoration.rs`: chroma restoration unit size is no longer hardcoded - half-res. Not witnessed (the proof stream disables restoration). -- `refusal_inventory.rs`: the old "any non-4:2:0" string is replaced by the - 4:2:2 string. Gate `a_non_420_subsampled_sequence_header_is_refused_by_name` - asserts that 4:2:2 string only. The gate was not re-run in this wrap-up. - -## Byte-exactness - -Oracle: `~/.cache/aom-oracle/build/aomenc` + `aomdec`, cross-checked with -ffmpeg 8.x raw `yuv444p` / `yuv420p`. aomdec `--rawvideo` and ffmpeg -`-pix_fmt yuv444p` were identical on the 444 witness, so the mismatch below -is ours. - -Recipe (both profiles): `testsrc2=128x128`, 2 frames, `--cpu-used=8 ---usage=2 --end-usage=q --cq-level=40 --min-partition-size=16 ---enable-rect-partitions=0 --enable-cdef=0 --enable-restoration=0 ---loopfilter-control=0 --threads=1 --obu`. Profile 1 adds `--profile=1` and -yuv444p input. Probe: `decode_probe` 8-bit dump (low byte of each plane). - -| stream | vs | result | -| --- | --- | --- | -| profile 0, filters off, square | ffmpeg `yuv420p` | IDENTICAL (98304 B, 2 frames) | -| profile 1, filters off, square | aomdec and ffmpeg `yuv444p` | luma IDENTICAL both frames (0 diffs / 16384). chroma NOT. 37389 diffs / 98304. First chroma mismatch: frame 0 U (112, 0), ours 192 vs oracle 167 | -| profile 1 with rect partitions (earlier `sq8.obu`) | — | panics in `decode_rect4_16_strip` → `reconstruct_rect` (`len 64, index 64`). Not a witness | - -`av1-profile1-444.ivf` was not re-decoded. It contains the rect/1:4 shapes -this tree still mishandles, so it will not be byte-exact. - -## Exact divergence - -First profile-1 block is an 8x8 leaf at mi (0, 0). Before the leaf fix that -leaf read 4x4 chroma, under-consumed symbols, and luma diverged at pixel 8. -After the fix, luma of both frames matches and U/V match until x=112. - -x=112 sits inside the 64x64 block at pixel (64, 0) (`EC_BLOCK side=64 -at=(0, 4)`, `chroma_in=32`). That block takes `decode_block`'s -`logical_tx == side` arm (side 64, one luma TU whose coefficient grid is -32). The arm then reads **one** chroma unit with reconstruct side -`chroma_side` (64 at 4:4:4) and coeff tx `chroma_tx` (32). libaom codes -**four** TX_32X32 chroma units for a 64x64 uv plane block at 4:4:4 -(`av1_get_max_uv_txsize` of a 64x64 uv bsize is TX_32X32, 2x2). The -multi-TU arm already loops `cn = chroma_side / chroma_tx` units, but a -64 block never enters it because `logical_tx == side`. Comment is on the -U `read_plane` in that arm. - -Quadrant diffs inside that 64x64, U plane, frame 0: (0,0) 764/1024, -(1,0) 896/1024, (0,1) 973/1024, (1,1) 1024/1024. Row 0 of the block matches -for the first 48 samples, then goes flat-wrong. That is a wrong chroma -unit, not a luma desync. +Status: **WIP**. 4:4:4 is byte-exact on every SQUARE witness: 8-bit +profile 1 filters off AND on (loop filter + CDEF + restoration), +forced-64x64-block arms (exercises the four-TX_32X32 chroma loop), +10-bit profile 2 filters off AND on. 420 square arms stay IDENTICAL +(regression). 4:2:2 stays a named refusal. The rect/1:4 paths at 4:4:4 +are mid-port: `av1-profile1-444.ivf` gets further every round but still +panics (see below). Full suite NOT run. + +## What changed (this continuation, on top of the staged WIP commit) + +1. `decode_block` single-TU arm (was the prior agent's unstaged edit, + debug prints removed): at 4:4:4 a 64x64 block's chroma is coded as + four TX_32X32 units plane-major — confirmed bug-for-bug against + libaom `av1_get_max_uv_txsize` (`av1_get_adjusted_tx_size`, + blockd.h:1361) and the plane-major unit loop in + `decode_token_recon_block` (decodeframe.c:970-1010). +2. **Root cause of the 36k chroma diffs** (the prior agent chased a + phantom 64x64 block — the stream has none): `u`/`v` + `set_tile_origin` hardcoded the 4:2:0 halving (`mi * 2`). At 4:4:4 + the halved `tile_x1` clamped `PlaneBuf::edges`' `across` below the + block's own x for every chroma block in the right half of the tile + (and `tile_y1` the left edge in the bottom half), so those blocks + predicted with edges missing (left-only/above-only DC). Localized by + proving the entropy ladder identical (1596/1596 rng rungs vs the + instrumented aomdec), then diffing `OUR_PRED`/`EC_PREDOUT8` for the + first divergent CFL block: aom DC 129, ours 145, traced to + `above=None` in `edges()`. Tile bounds now `mi * 4 >> ss`; identical + at 4:2:0. +3. Loop filter: `deblock_plane_span` clipped chroma to + `frame_width/2 × frame_height/2` (another hardcoded halving) — at + 4:4:4 the filter never touched three quarters of each chroma plane. + Crop now follows `ss`. (CDEF and restoration were already exact: + isolating arms `--loopfilter-control=0` vs `--enable-cdef=0` / + `--enable-restoration=0`.) +4. Rect/1:4 4:4:4 port (in progress): + - `decode_block_rect4` (32x8/8x32 strips): chroma table was + hardcoded 4:2:0 (`Chroma8`, SCAN_16X4/4X16, mode-derived tx_type + with no size clamp → ADST-at-32 panic). Now shape-keyed + (4:4:4: `Chroma16`, SCAN_32X8/8X32) with the + `av1_get_ext_tx_set_type` DCT_ONLY clamp at square-up ≥ 32 + (blockd.h:1278). + - Inter rect chroma: a 64-axis strip at 4:4:4 keeps its 64-px chroma + axis, capped to 32-wide units (`av1_get_max_uv_txsize`), so it + codes TWO units plane-major. New `read_inter_rect_chroma` helper + (both `decode_inter_block` rect readers call it); + `read_inter_plane_rect`'s chroma skip_ctx takes the +3 (libaom + +10) offset for multi-unit blocks; `rect_inter_chroma_set` gained + the (32,32) → `Chroma32` entry. + - `decode_rect4_16_strip` (16x4/4x16 strips): at 4:4:4 there is no + 4:2:0 chroma pair — every strip is its own chroma reference + (`is_chroma_reference`: no mi-parity test at ss 0/0, strip's own + chroma ≥ 4x4). `has_chroma` is now true for every strip at ss 0/0 + (key-frame caller `decode_rect4_16` AND the inter + `inter_strip_chroma` construction), the pair origin/tables/CfL + window anchor at the strip itself, and the inter `prev` + (both-strips MC) is disabled at 4:4:4. + - Leftover instrumentation from the staged WIP removed (EC_64*, + EC_TILE); `EC_RECTCHROMA_GAP` stays (deliberate diagnostic per its + comment). + +## Byte-exactness (all vs aomdec, ffmpeg cross-checked; recipes in +`$HOME/.cache/av1444/witness_*.sh`) + +| stream | result | +| --- | --- | +| profile 1, filters off, square 128x128 2f | IDENTICAL (98304 B) | +| profile 1, filters ON (LF+CDEF+LR), square | IDENTICAL | +| profile 1, filters off, forced 64x64 blocks (`gradients --min-partition-size=64`, 8 64x64 leaves) | IDENTICAL | +| profile 1, filters on, forced 64x64 blocks | IDENTICAL | +| profile 2 10-bit, filters off, square | IDENTICAL (196608 B yuv444p10le) | +| profile 2 10-bit, filters on, square | IDENTICAL | +| profile 0 420, filters off, square | IDENTICAL (regression) | +| profile 0 420, filters on, square | IDENTICAL (regression) | +| `av1-profile1-444.ivf` (320x240, rect/1:4 shapes) | decodes 24+ frames, then **panics** `reconstruct_rect len 64 index 64` (decode.rs:3619, `exec_intra` track-caller) after `EC_RECTCHROMA_GAP luma=64x16 tx=16x16` — the 64-axis intra strip's split-transform chroma path is the next defect | ## Still refused or unproven | shape | disposition | | --- | --- | | 4:2:2 (`ss_x != ss_y`) | refused by name. Gate re-scoped, not re-run | -| 4:4:4 64x64 chroma (and any block that takes the single-TU arm with `chroma_side != chroma_tx`) | decodes, not byte-exact. Next edit: when `ss==0` and `chroma_side > chroma_tx`, use the existing `cn` loop instead of one `read_plane` | -| 1:4 strips (`decode_rect4_16`) | panic, not a named refusal. Not in the square witness | -| sub-8 group chroma (`Chroma4` / size 4 in the 4x4-group tails) | still hardcoded 4:2:0. Square witness did not hit this first | -| loop filter, CDEF, restoration on | threaded with `ss_*`, not witnessed (proof stream disables them) | -| 10-bit 4:4:4 | not encoded, not compared | -| `av1-profile1-444.ivf` | not re-run | -| full `cargo test -p ec-av1` | not run. Do not claim green | +| 64-axis intra strips with split luma transforms at 4:4:4 (`decode_rect_split` chroma (64,16)/(64,32)/(16,64) with tx < block) | panics, not a named refusal. The `chroma_tiled` unit loop exists but the residual reaching `reconstruct_rect` is sized for a 4:2:0 unit somewhere in this path | +| `av1-profile1-444.ivf` | not byte-exact (panic above). Refusal-gate flip to witness gate NOT done | +| inter square 64x64 at 4:4:4 (var-tx and single-TU) | unwitnessed — the square inter chroma path codes one unit; libaom codes four TX_32X32. No stream has exercised it yet | +| full `cargo test -p ec-av1` | NOT run. Do not claim green | +| 0-warning parity | not measured this round | ## Next -1. In `decode_block`, when `logical_tx == side` but `chroma_side > chroma_tx`, code chroma as `cn` x `cn` units (the multi-TU loop already does this). Re-run the square profile-1 recipe. Luma must stay identical; chroma must go to 0 diffs. -2. Then turn filters back on one at a time. -3. Then a 10-bit profile-2 444 stream (`yuv444p10le`). -4. Then the existing `av1-profile1-444.ivf`, after the 1:4 path no longer panics. -5. Full suite, `--test-threads=1`, `TMPDIR` on `$HOME`. +1. Fix the `decode_rect_split` 64-axis-strip chroma at 4:4:4 (the + len-64 panic): trace which unit feeds `reconstruct_rect` a 64-long + residual; the `chroma_tiled` arm's (32,16)/(16,32) rect units go + through `read_coeffs_rect` + `dequant_and_inverse_typed_wh` — check + the scratch/grid sizing against libaom's two-unit plane-major order. +2. Then the inter square-64 four-unit chroma (mirror the intra fix). +3. Then the fixture end-to-end vs ffmpeg; flip the refusal gate + (`a_non_420_subsampled_sequence_header_is_refused_by_name` re-scope) + to a fixture witness gate. +4. Full suite `--test-threads=1`, 0-warning parity, update this report.