forge
Explore
Log in

Don't you dare go Hollow

ec-av1: 4:4:4 rect/1:4 chroma port (WIP) + byte-exact square witnesses

Browse files at this commit

a236cd35629353c532bfa16589e5ae1c8afbfa62Ahmet Kaan GümüşParent: 6f661bc
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.rsmodified+205 -115
@@ -10081,7 +10081,6 @@ fn decode_rect_split(
1008110081 let [ug, vg] = last;
1008210082 (ug, vg)
1008310083 } else if chroma_tiled {
10084- eprintln!("EC_TILE chroma={chroma_w}x{chroma_h}");
1008510084 let (uw, uh, set, scan): (usize, usize, TxbSet, &[u16]) = match (chroma_w, chroma_h) {
1008610085 (64, 32) | (32, 64) => (32, 32, TxbSet::Chroma32, default_scan(32)),
1008710086 (64, 16) => (32, 16, TxbSet::ChromaRect32x16, &SCAN_32X16),
@@ -12060,11 +12059,21 @@ fn decode_block_rect4(
1206012059 let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
1206112060 let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
1206212061 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
12063- let (luma_scan, chroma_scan): (&[u16], &[u16]) = if bw > bh {
12064- (&SCAN_32X8, &SCAN_16X4)
12065- } else {
12066- (&SCAN_8X32, &SCAN_4X16)
12062+ // lane-av1-444: the strip's chroma shape follows the subsampling.
12063+ // 4:2:0 codes 16x4/4x16 (`TxbSet::Chroma8`); 4:4:4 codes the strip
12064+ // itself, 32x8/8x32 (`get_txsize_entropy_ctx(TX_32X8)` =
12065+ // `(wide_log2 + high_log2 + 1) >> 1` = the 16x16 set,
12066+ // `TxbSet::Chroma16`). The caller set is closed -- this reader only
12067+ // ever sees 32x8 / 8x32 luma and the sequence header admits ss 0/0
12068+ // and 1/1 only -- so the table is exhaustive.
12069+ let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (chroma_w, chroma_h) {
12070+ (16, 4) => (TxbSet::Chroma8, &SCAN_16X4[..]),
12071+ (4, 16) => (TxbSet::Chroma8, &SCAN_4X16[..]),
12072+ (32, 8) => (TxbSet::Chroma16, &SCAN_32X8[..]),
12073+ (8, 32) => (TxbSet::Chroma16, &SCAN_8X32[..]),
12074+ _ => unreachable!("decode_block_rect4 chroma shape set is closed"),
1206712075 };
12076+ let luma_scan: &[u16] = if bw > bh { &SCAN_32X8 } else { &SCAN_8X32 };
1206812077 let (luma_levels, u_levels, v_levels) = if skip {
1206912078 (
1207012079 vec![0i32; bw * bh],
@@ -12086,9 +12095,18 @@ fn decode_block_rect4(
1208612095 )?;
1208712096 let mut planes = Vec::with_capacity(2);
1208812097 for plane in 1..3 {
12089- let default_tx = default_intra_tx_type(uv_predict_mode as u8);
12098+ // `av1_get_tx_type` (`blockd.h:1278`): the mode-indexed type
12099+ // stands only while it is a member of this tx size's set; a
12100+ // 32x8/8x32 chroma transform (4:4:4) squares up to TX_32X32,
12101+ // whose intra set is `EXT_TX_SET_DCTONLY` -- every ADST clamps
12102+ // to DCT_DCT there, and ADST is undefined at widths above 16.
12103+ let default_tx = if chroma_w.max(chroma_h) >= 32 {
12104+ TxType::DctDct
12105+ } else {
12106+ default_intra_tx_type(uv_predict_mode as u8)
12107+ };
1209012108 let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1);
12091- let mut coding = cdfs.txb(TxbSet::Chroma8, uv_predict_mode);
12109+ let mut coding = cdfs.txb(chroma_set, uv_predict_mode);
1209212110 let (levels, tx_type) = read_chroma_coeffs_rect(
1209312111 dec,
1209412112 &mut coding,
@@ -12317,7 +12335,10 @@ fn decode_rect4_16(
1231712335 } else {
1231812336 (mi_row0, mi_col0 + i)
1231912337 };
12320- let has_chroma = i % 2 == 1;
12338+ // lane-av1-444: at 4:4:4 every strip is its own chroma reference
12339+ // (no mi-parity test at ss 0/0, and the strip's own chroma block is
12340+ // already >= 4x4) -- there is no 4:2:0 pair to close.
12341+ let has_chroma = i % 2 == 1 || (ss_x(fctx) == 0 && ss_y(fctx) == 0);
1232112342 let (mode, uv, _tx) = decode_rect4_16_strip(
1232212343 dec,
1232312344 cdfs,
@@ -12382,7 +12403,6 @@ fn decode_rect4_16_strip(
1238212403 let (bw, bh) = if horz { (16usize, 4usize) } else { (4, 16) };
1238312404 let (mi_w, mi_h) = (bw / MI, bh / MI);
1238412405 let scan: &[u16] = if horz { &SCAN_16X4 } else { &SCAN_4X16 };
12385- let chroma_scan: &[u16] = if horz { &SCAN_8X4 } else { &SCAN_4X8 };
1238612406 let mut last_uv_mode: Option<usize> = None;
1238712407 // `decode_block_rect4`'s own neighbour rule: the coarse 16-px cell
1238812408 // aliases all four strips onto one entry, so the mi-exact map wins and
@@ -12663,12 +12683,17 @@ fn decode_rect4_16_strip(
1266312683 }
1266412684 if has_chroma {
1266512685 hit!(RECT4_16_CHROMA_HITS);
12666- let pair_mi = if horz {
12667- (lmi.0 - 1, lmi.1)
12686+ // lane-av1-444: at 4:4:4 there is no pair -- every strip is its
12687+ // own chroma reference and codes its own 16x4 / 4x16 chroma
12688+ // block. (`set_mi_offsets`'s chroma snap is the zero offset at
12689+ // ss 0/0, so the neighbour reads below anchor at the strip.)
12690+ let (pair_mi, pw, ph) = if ss_x(fctx) == 0 && ss_y(fctx) == 0 {
12691+ (lmi, bw, bh)
12692+ } else if horz {
12693+ ((lmi.0 - 1, lmi.1), 16, 8)
1266812694 } else {
12669- (lmi.0, lmi.1 - 1)
12695+ ((lmi.0, lmi.1 - 1), 8, 16)
1267012696 };
12671- let (pw, ph) = if horz { (16, 8) } else { (8, 16) };
1267212697 let (ppx, ppy) = (pair_mi.1 * MI, pair_mi.0 * MI);
1267312698 let (cpx, cpy) = (ppx >> ss_x(fctx), ppy >> ss_y(fctx));
1267412699 let (cw, ch) = (pw >> ss_x(fctx), ph >> ss_y(fctx));
@@ -12728,11 +12753,21 @@ fn decode_rect4_16_strip(
1272812753 (zeros.clone(), zeros)
1272912754 } else {
1273012755 let around = neighbours.around_mi_rect(pair_mi, pw, ph);
12756+ // lane-av1-444: the strip's own 16x4 / 4x16 chroma at ss 0/0
12757+ // (`TxbSet::Chroma8`, `get_txsize_entropy_ctx(TX_16X4)` =
12758+ // the 8x8 set); 4:2:0 keeps the pair's 8x4 / 4x8.
12759+ let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (cw, ch) {
12760+ (8, 4) => (TxbSet::ChromaRect8x4, &SCAN_8X4[..]),
12761+ (4, 8) => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]),
12762+ (16, 4) => (TxbSet::Chroma8, &SCAN_16X4[..]),
12763+ (4, 16) => (TxbSet::Chroma8, &SCAN_4X16[..]),
12764+ _ => unreachable!("decode_rect4_16_strip chroma shape set is closed"),
12765+ };
1273112766 let mut planes = Vec::with_capacity(2);
1273212767 for plane in 1..3 {
1273312768 let default_tx = default_intra_tx_type(uv_predict_mode as u8);
1273412769 let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1);
12735- let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode);
12770+ let mut coding = cdfs.txb(chroma_set, uv_predict_mode);
1273612771 let (levels, tx_type) = read_chroma_coeffs_rect(
1273712772 dec,
1273812773 &mut coding,
@@ -19019,6 +19054,10 @@ fn rect_inter_chroma_set(w: usize, h: usize) -> Result<TxbSet> {
1901919054 // set for TX_16X4/TX_4X16 (`get_txsize_entropy_ctx` = TX_8X8,
1902019055 // `txsize_log2_minus4` = 2, 64-coefficient `eob_pt`).
1902119056 (16, 4) | (4, 16) => TxbSet::Chroma8,
19057+ // lane-av1-444: one 32x32 unit of a 4:4:4 64x32/32x64 chroma plane
19058+ // block (`av1_get_max_uv_txsize` adjusts `TX_64X32`/`TX_32X64` to
19059+ // `TX_32X32`); `get_txsize_entropy_ctx(TX_32X32)` is the 32x32 set.
19060+ (32, 32) => TxbSet::Chroma32,
1902219061 _ => {
1902319062 return Err(unsupported(
1902419063 "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<TxbSet> {
1902719066 })
1902819067 }
1902919068
19069+
1903019070 /// libaom `size_group_lookup[bsize]` for the block shapes this decoder's
1903119071 /// inter path reaches, from the block's TRUE footprint rather than the
1903219072 /// square `side` corner-cut: 8x8/8x16/16x8 -> 1, 16x16/16x32/32x16 -> 2,
@@ -19303,6 +19343,100 @@ fn read_block_tx_size_rect(
1930319343 Ok(Some(leaves))
1930419344 }
1930519345
19346+/// The chroma half of a whole-block rectangular INTER transform unit (both
19347+/// [`decode_inter_block`] rect readers): `av1_get_max_uv_txsize(bsize)` gives
19348+/// the strip's own rect chroma size at 4:2:0 (one unit for the whole block),
19349+/// but at 4:4:4 the chroma plane block keeps the luma block's 64-px axis,
19350+/// which `av1_get_adjusted_tx_size` caps at 32 (`TX_64X16` -> `TX_32X16`),
19351+/// so it codes TWO units plane-major (every U, then every V --
19352+/// `decode_token_recon_block`'s inter branch loops `for plane` outside
19353+/// `for blk_row/blk_col` inside the one mu chunk). No unit codes a `tx_type`
19354+/// symbol: each inherits the block-wide luma one (`av1_get_tx_type`'s inter
19355+/// UV lookup at ss 0 reads the tx_type_map at its own mi, which a single-TU
19356+/// luma block fills uniformly).
19357+#[allow(clippy::too_many_arguments)]
19358+fn read_inter_rect_chroma(
19359+ dec: &mut SymbolDecoder,
19360+ cdfs: &mut Cdfs,
19361+ neighbours: &mut Neighbours,
19362+ around: [(bool, bool, i32); 3],
19363+ u: &mut PlaneBuf<'static>,
19364+ v: &mut PlaneBuf<'static>,
19365+ su: Pred<'_>,
19366+ sv: Pred<'_>,
19367+ at_mi: (usize, usize),
19368+ (cpx, cpy): (usize, usize),
19369+ (write_chroma_w, write_chroma_h): (usize, usize),
19370+ chroma_side: usize,
19371+ mode_for_tx: usize,
19372+ luma_tx_type: TxType,
19373+ fctx: &crate::decode::FrameCtx,
19374+) -> Result<(Grid, Grid)> {
19375+ let (uw, uh) = (write_chroma_w.min(32), write_chroma_h.min(32));
19376+ let (nx, ny) = (write_chroma_w / uw, write_chroma_h / uh);
19377+ let multi = nx * ny > 1;
19378+ let set = rect_inter_chroma_set(uw, uh)?;
19379+ let mut assembled: [Vec<i32>; 2] = [Vec::new(), Vec::new()];
19380+ if multi {
19381+ hit!(CHROMA_SPLIT_TX_HITS);
19382+ assembled = [
19383+ vec![0i32; chroma_side * chroma_side],
19384+ vec![0i32; chroma_side * chroma_side],
19385+ ];
19386+ }
19387+ for plane_idx in 1..=2 {
19388+ let (src, buf) = if plane_idx == 1 { (su, &mut *u) } else { (sv, &mut *v) };
19389+ for cu_row in 0..ny {
19390+ for cu_col in 0..nx {
19391+ let (span_x, span_y) = (uw << ss_x(fctx), uh << ss_y(fctx));
19392+ let cu_mi = (
19393+ at_mi.0 + cu_row * (span_y / MI),
19394+ at_mi.1 + cu_col * (span_x / MI),
19395+ );
19396+ let cu_around = if multi {
19397+ neighbours.around_mi_rect(cu_mi, span_x, span_y)
19398+ } else {
19399+ around
19400+ };
19401+ let (cu_x, cu_y) = (cpx + cu_col * uw, cpy + cu_row * uh);
19402+ let cu_pred = src.offset(cu_row * uh * chroma_side + cu_col * uw);
19403+ let cu_grid = read_inter_plane_rect(
19404+ dec,
19405+ cdfs,
19406+ set,
19407+ (uw, uh),
19408+ chroma_side,
19409+ plane_idx,
19410+ cu_around[plane_idx],
19411+ mode_for_tx,
19412+ buf,
19413+ cu_x,
19414+ cu_y,
19415+ cu_pred,
19416+ Some(luma_tx_type),
19417+ multi.then_some(3), fctx,
19418+ )?
19419+ .0;
19420+ if multi {
19421+ // Immediately, so the next unit of this block reads this
19422+ // one's coefficient context (libaom updates the chroma
19423+ // above/left contexts per unit).
19424+ neighbours.record_mi_chroma(cu_mi, span_x, span_y, plane_idx, &cu_grid);
19425+ let dst = &mut assembled[plane_idx - 1];
19426+ for rr in 0..uh {
19427+ let start = (cu_row * uh + rr) * chroma_side + cu_col * uw;
19428+ dst[start..start + uw].copy_from_slice(&cu_grid[rr * uw..][..uw]);
19429+ }
19430+ } else {
19431+ assembled[plane_idx - 1] = embed_rect_grid(&cu_grid, uw, uh, chroma_side);
19432+ }
19433+ }
19434+ }
19435+ }
19436+ let [ug, vg] = assembled;
19437+ Ok((Grid::Own(ug), Grid::Own(vg)))
19438+}
19439+
1930619440 /// [`read_inter_plane`] for a rectangular transform unit (lane-inter4 r2):
1930719441 /// the coefficients are read with the rect coefficient machinery
1930819442 /// ([`read_coeffs_rect`], whose `TxClass` handling covers the 1D `V_*`/`H_*`
@@ -19345,7 +19479,12 @@ fn read_inter_plane_rect(
1934519479 // block; a var-tx leaf passes its own neighbour-table context.
1934619480 luma_skip_ctx.unwrap_or(0)
1934719481 } else {
19348- usize::from(around.0) + usize::from(around.1)
19482+ // libaom `get_txb_ctx`: a chroma unit's context is
19483+ // `combine_entropy_contexts(above, left)` plus 7, or plus 10 when the
19484+ // plane block is bigger than the transform. Our chroma tables hold the
19485+ // offset-7 rows first, so a multi-unit caller adds 3 through
19486+ // `luma_skip_ctx` (same convention as [`read_plane`]).
19487+ usize::from(around.0) + usize::from(around.1) + luma_skip_ctx.unwrap_or(0)
1934919488 };
1935019489 let mut coding = cdfs.txb(set, tx_mode);
1935119490 // libaom `read_tx_type` (`av1/decoder/decodetxb.c`): "No need to read
@@ -27678,7 +27817,11 @@ fn decode_inter_block(
2767827817 let chroma_side = side >> ss_x(fctx);
2767927818 let (write_chroma_w, write_chroma_h) = match strip_chroma {
2768027819 Some(s) if s.has_chroma => {
27681- if s.horz {
27820+ // 4:2:0: the PAIR's 8x4 / 4x8. 4:4:4: the strip's own 16x4 /
27821+ // 4x16 (lane-av1-444; no pair at ss 0/0).
27822+ if ss_x(fctx) == 0 && ss_y(fctx) == 0 {
27823+ if s.horz { (16, 4) } else { (4, 16) }
27824+ } else if s.horz {
2768227825 (8, 4)
2768327826 } else {
2768427827 (4, 8)
@@ -29031,55 +29174,24 @@ fn decode_inter_block(
2903129174 // assembled grid (class `override-slot-on-one-arm`).
2903229175 mu_chroma = true;
2903329176 } else if rect_tu {
29034- // `av1_get_max_uv_txsize(bsize)`: the chroma transform of a
29035- // 2:1 strip is the strip's own rect chroma size (16x8 /
29036- // 8x16), one unit for the whole block, and it codes no
29037- // `tx_type` symbol -- it inherits the luma unit's.
29038- let (uw, uh) = (write_chroma_w, write_chroma_h);
29039- u_grid = Grid::Own(embed_rect_grid(
29040- &read_inter_plane_rect(
29041- dec,
29042- cdfs,
29043- rect_inter_chroma_set(write_chroma_w, write_chroma_h)?,
29044- (uw, uh),
29045- chroma_side,
29046- 1,
29047- around[1],
29048- mode_for_tx,
29049- u,
29050- cpx,
29051- cpy,
29052- su,
29053- Some(luma_tx_type),
29054- None, fctx,
29055- )?
29056- .0,
29057- uw,
29058- uh,
29059- chroma_side,
29060- ));
29061- v_grid = Grid::Own(embed_rect_grid(
29062- &read_inter_plane_rect(
29063- dec,
29064- cdfs,
29065- rect_inter_chroma_set(write_chroma_w, write_chroma_h)?,
29066- (uw, uh),
29067- chroma_side,
29068- 2,
29069- around[2],
29070- mode_for_tx,
29071- v,
29072- cpx,
29073- cpy,
29074- sv,
29075- Some(luma_tx_type),
29076- None, fctx,
29077- )?
29078- .0,
29079- uw,
29080- uh,
29177+ // One chroma read for the whole strip at 4:2:0, two
29178+ // 32-capped units at 4:4:4 -- see the helper.
29179+ (u_grid, v_grid) = read_inter_rect_chroma(
29180+ dec,
29181+ cdfs,
29182+ neighbours,
29183+ around,
29184+ u,
29185+ v,
29186+ su,
29187+ sv,
29188+ at_mi,
29189+ (cpx, cpy),
29190+ (write_chroma_w, write_chroma_h),
2908129191 chroma_side,
29082- ));
29192+ mode_for_tx,
29193+ luma_tx_type, fctx,
29194+ )?;
2908329195 } else {
2908429196 u_grid = read_inter_plane(
2908529197 dec,
@@ -30374,55 +30486,24 @@ fn decode_inter_block(
3037430486 // assembled grid (class `override-slot-on-one-arm`).
3037530487 mu_chroma = true;
3037630488 } else if rect_tu {
30377- // `av1_get_max_uv_txsize(bsize)`: the chroma transform of a
30378- // 2:1 strip is the strip's own rect chroma size (16x8 /
30379- // 8x16), one unit for the whole block, and it codes no
30380- // `tx_type` symbol -- it inherits the luma unit's.
30381- let (uw, uh) = (write_chroma_w, write_chroma_h);
30382- u_grid = Grid::Own(embed_rect_grid(
30383- &read_inter_plane_rect(
30384- dec,
30385- cdfs,
30386- rect_inter_chroma_set(write_chroma_w, write_chroma_h)?,
30387- (uw, uh),
30388- chroma_side,
30389- 1,
30390- around_c[1],
30391- mode_for_tx,
30392- u,
30393- cpx,
30394- cpy,
30395- su,
30396- Some(luma_tx_type),
30397- None, fctx,
30398- )?
30399- .0,
30400- uw,
30401- uh,
30402- chroma_side,
30403- ));
30404- v_grid = Grid::Own(embed_rect_grid(
30405- &read_inter_plane_rect(
30406- dec,
30407- cdfs,
30408- rect_inter_chroma_set(write_chroma_w, write_chroma_h)?,
30409- (uw, uh),
30410- chroma_side,
30411- 2,
30412- around_c[2],
30413- mode_for_tx,
30414- v,
30415- cpx,
30416- cpy,
30417- sv,
30418- Some(luma_tx_type),
30419- None, fctx,
30420- )?
30421- .0,
30422- uw,
30423- uh,
30489+ // One chroma read for the whole strip at 4:2:0, two
30490+ // 32-capped units at 4:4:4 -- see the helper.
30491+ (u_grid, v_grid) = read_inter_rect_chroma(
30492+ dec,
30493+ cdfs,
30494+ neighbours,
30495+ around_c,
30496+ u,
30497+ v,
30498+ su,
30499+ sv,
30500+ at_mi,
30501+ (cpx, cpy),
30502+ (write_chroma_w, write_chroma_h),
3042430503 chroma_side,
30425- ));
30504+ mode_for_tx,
30505+ luma_tx_type, fctx,
30506+ )?;
3042630507 } else {
3042730508 u_grid = read_inter_plane(
3042830509 dec,
@@ -37172,8 +37253,17 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
3717237253 {
3717337254 break;
3717437255 }
37175- let strip_has_chroma = i % 2 == 1;
37176- let pair_mi = if !strip_has_chroma {
37256+ // lane-av1-444: at 4:4:4 every strip is
37257+ // its own chroma reference
37258+ // (`is_chroma_reference`: no mi parity
37259+ // test at ss 0/0 and the strip's 16x4 /
37260+ // 4x16 chroma block is already >= 4x4),
37261+ // so there is no pair: each strip codes
37262+ // and predicts its own chroma from its
37263+ // own motion (`prev` = None).
37264+ let strip_has_chroma =
37265+ i % 2 == 1 || (ss_x(fctx) == 0 && ss_y(fctx) == 0);
37266+ let pair_mi = if !strip_has_chroma || ss_x(fctx) == 0 {
3717737267 at_mi
3717837268 } else if horz {
3717937269 (at_mi.0 - 1, at_mi.1)
@@ -37185,7 +37275,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
3718537275 has_chroma: strip_has_chroma,
3718637276 horz,
3718737277 pair_mi,
37188- prev: if strip_has_chroma {
37278+ prev: if strip_has_chroma && ss_x(fctx) == 1 {
3718937279 fctx.inter_last_mc.with(std::cell::Cell::get)
3719037280 } else {
3719137281 None
lanes/av1444.report.mdmodified+89 -83
@@ -5,95 +5,101 @@ Branch `lane-av1-444`, base `7f8d6cf6`. Worktree
55 `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1444`,
66 `TMPDIR=$HOME/.cache/av1444-tmp`. Not pushed.
77
8-Status: **WIP**. 4:4:4 is no longer refused. Luma of a square profile-1
9-keyframe is byte-exact vs aomdec and ffmpeg. Chroma is not. 4:2:2 stays a
10-named refusal. Full suite was not run.
11-
12-Commit: blocked by the global pre-commit hook
13-(`format-staged.py` runs `rustfmt <file>` with no `--edition`). That rustfmt
14-rejects the pre-existing `let` chains in `decode.rs` (`edition = "2024"`).
15-`rustfmt --edition 2024 --check` wants a wholesale reformat of `decode.rs`,
16-so the hook was not bypassed and the reformat was not applied. Changes are
17-staged, not committed. `git status` in the worktree is the source of truth.
18-
19-## What changed
20-
21-- `stream.rs`: the sequence-header refusal now fires only when
22- `subsampling_x != subsampling_y` (4:2:2). 4:4:4 (`0,0`) and 4:2:0 (`1,1`)
23- proceed. `set_subsampling` publishes the header values onto `FrameCtx`
24- once per frame, same slot as `set_mono`.
25-- `decode.rs`: chroma plane size, tx size, CFL window, loop-filter chroma
26- step, and the 8x8 leaf's chroma unit follow `ss_x`/`ss_y`. At 4:4:4 an
27- 8x8 leaf's chroma is 8x8 (`TxbSet::Chroma8`, `scans.0`), not the hardcoded
28- 4x4. A square block below 64 uses chroma tx = block side. A 64 block still
29- takes the single-TU arm (see the divergence below).
30-- `restoration.rs`: chroma restoration unit size is no longer hardcoded
31- half-res. Not witnessed (the proof stream disables restoration).
32-- `refusal_inventory.rs`: the old "any non-4:2:0" string is replaced by the
33- 4:2:2 string. Gate `a_non_420_subsampled_sequence_header_is_refused_by_name`
34- asserts that 4:2:2 string only. The gate was not re-run in this wrap-up.
35-
36-## Byte-exactness
37-
38-Oracle: `~/.cache/aom-oracle/build/aomenc` + `aomdec`, cross-checked with
39-ffmpeg 8.x raw `yuv444p` / `yuv420p`. aomdec `--rawvideo` and ffmpeg
40-`-pix_fmt yuv444p` were identical on the 444 witness, so the mismatch below
41-is ours.
42-
43-Recipe (both profiles): `testsrc2=128x128`, 2 frames, `--cpu-used=8
44---usage=2 --end-usage=q --cq-level=40 --min-partition-size=16
45---enable-rect-partitions=0 --enable-cdef=0 --enable-restoration=0
46---loopfilter-control=0 --threads=1 --obu`. Profile 1 adds `--profile=1` and
47-yuv444p input. Probe: `decode_probe` 8-bit dump (low byte of each plane).
48-
49-| stream | vs | result |
50-| --- | --- | --- |
51-| profile 0, filters off, square | ffmpeg `yuv420p` | IDENTICAL (98304 B, 2 frames) |
52-| 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 |
53-| profile 1 with rect partitions (earlier `sq8.obu`) | — | panics in `decode_rect4_16_strip` → `reconstruct_rect` (`len 64, index 64`). Not a witness |
54-
55-`av1-profile1-444.ivf` was not re-decoded. It contains the rect/1:4 shapes
56-this tree still mishandles, so it will not be byte-exact.
57-
58-## Exact divergence
59-
60-First profile-1 block is an 8x8 leaf at mi (0, 0). Before the leaf fix that
61-leaf read 4x4 chroma, under-consumed symbols, and luma diverged at pixel 8.
62-After the fix, luma of both frames matches and U/V match until x=112.
63-
64-x=112 sits inside the 64x64 block at pixel (64, 0) (`EC_BLOCK side=64
65-at=(0, 4)`, `chroma_in=32`). That block takes `decode_block`'s
66-`logical_tx == side` arm (side 64, one luma TU whose coefficient grid is
67-32). The arm then reads **one** chroma unit with reconstruct side
68-`chroma_side` (64 at 4:4:4) and coeff tx `chroma_tx` (32). libaom codes
69-**four** TX_32X32 chroma units for a 64x64 uv plane block at 4:4:4
70-(`av1_get_max_uv_txsize` of a 64x64 uv bsize is TX_32X32, 2x2). The
71-multi-TU arm already loops `cn = chroma_side / chroma_tx` units, but a
72-64 block never enters it because `logical_tx == side`. Comment is on the
73-U `read_plane` in that arm.
74-
75-Quadrant diffs inside that 64x64, U plane, frame 0: (0,0) 764/1024,
76-(1,0) 896/1024, (0,1) 973/1024, (1,1) 1024/1024. Row 0 of the block matches
77-for the first 48 samples, then goes flat-wrong. That is a wrong chroma
78-unit, not a luma desync.
8+Status: **WIP**. 4:4:4 is byte-exact on every SQUARE witness: 8-bit
9+profile 1 filters off AND on (loop filter + CDEF + restoration),
10+forced-64x64-block arms (exercises the four-TX_32X32 chroma loop),
11+10-bit profile 2 filters off AND on. 420 square arms stay IDENTICAL
12+(regression). 4:2:2 stays a named refusal. The rect/1:4 paths at 4:4:4
13+are mid-port: `av1-profile1-444.ivf` gets further every round but still
14+panics (see below). Full suite NOT run.
15+
16+## What changed (this continuation, on top of the staged WIP commit)
17+
18+1. `decode_block` single-TU arm (was the prior agent's unstaged edit,
19+ debug prints removed): at 4:4:4 a 64x64 block's chroma is coded as
20+ four TX_32X32 units plane-major — confirmed bug-for-bug against
21+ libaom `av1_get_max_uv_txsize` (`av1_get_adjusted_tx_size`,
22+ blockd.h:1361) and the plane-major unit loop in
23+ `decode_token_recon_block` (decodeframe.c:970-1010).
24+2. **Root cause of the 36k chroma diffs** (the prior agent chased a
25+ phantom 64x64 block — the stream has none): `u`/`v`
26+ `set_tile_origin` hardcoded the 4:2:0 halving (`mi * 2`). At 4:4:4
27+ the halved `tile_x1` clamped `PlaneBuf::edges`' `across` below the
28+ block's own x for every chroma block in the right half of the tile
29+ (and `tile_y1` the left edge in the bottom half), so those blocks
30+ predicted with edges missing (left-only/above-only DC). Localized by
31+ proving the entropy ladder identical (1596/1596 rng rungs vs the
32+ instrumented aomdec), then diffing `OUR_PRED`/`EC_PREDOUT8` for the
33+ first divergent CFL block: aom DC 129, ours 145, traced to
34+ `above=None` in `edges()`. Tile bounds now `mi * 4 >> ss`; identical
35+ at 4:2:0.
36+3. Loop filter: `deblock_plane_span` clipped chroma to
37+ `frame_width/2 × frame_height/2` (another hardcoded halving) — at
38+ 4:4:4 the filter never touched three quarters of each chroma plane.
39+ Crop now follows `ss`. (CDEF and restoration were already exact:
40+ isolating arms `--loopfilter-control=0` vs `--enable-cdef=0` /
41+ `--enable-restoration=0`.)
42+4. Rect/1:4 4:4:4 port (in progress):
43+ - `decode_block_rect4` (32x8/8x32 strips): chroma table was
44+ hardcoded 4:2:0 (`Chroma8`, SCAN_16X4/4X16, mode-derived tx_type
45+ with no size clamp → ADST-at-32 panic). Now shape-keyed
46+ (4:4:4: `Chroma16`, SCAN_32X8/8X32) with the
47+ `av1_get_ext_tx_set_type` DCT_ONLY clamp at square-up ≥ 32
48+ (blockd.h:1278).
49+ - Inter rect chroma: a 64-axis strip at 4:4:4 keeps its 64-px chroma
50+ axis, capped to 32-wide units (`av1_get_max_uv_txsize`), so it
51+ codes TWO units plane-major. New `read_inter_rect_chroma` helper
52+ (both `decode_inter_block` rect readers call it);
53+ `read_inter_plane_rect`'s chroma skip_ctx takes the +3 (libaom
54+ +10) offset for multi-unit blocks; `rect_inter_chroma_set` gained
55+ the (32,32) → `Chroma32` entry.
56+ - `decode_rect4_16_strip` (16x4/4x16 strips): at 4:4:4 there is no
57+ 4:2:0 chroma pair — every strip is its own chroma reference
58+ (`is_chroma_reference`: no mi-parity test at ss 0/0, strip's own
59+ chroma ≥ 4x4). `has_chroma` is now true for every strip at ss 0/0
60+ (key-frame caller `decode_rect4_16` AND the inter
61+ `inter_strip_chroma` construction), the pair origin/tables/CfL
62+ window anchor at the strip itself, and the inter `prev`
63+ (both-strips MC) is disabled at 4:4:4.
64+ - Leftover instrumentation from the staged WIP removed (EC_64*,
65+ EC_TILE); `EC_RECTCHROMA_GAP` stays (deliberate diagnostic per its
66+ comment).
67+
68+## Byte-exactness (all vs aomdec, ffmpeg cross-checked; recipes in
69+`$HOME/.cache/av1444/witness_*.sh`)
70+
71+| stream | result |
72+| --- | --- |
73+| profile 1, filters off, square 128x128 2f | IDENTICAL (98304 B) |
74+| profile 1, filters ON (LF+CDEF+LR), square | IDENTICAL |
75+| profile 1, filters off, forced 64x64 blocks (`gradients --min-partition-size=64`, 8 64x64 leaves) | IDENTICAL |
76+| profile 1, filters on, forced 64x64 blocks | IDENTICAL |
77+| profile 2 10-bit, filters off, square | IDENTICAL (196608 B yuv444p10le) |
78+| profile 2 10-bit, filters on, square | IDENTICAL |
79+| profile 0 420, filters off, square | IDENTICAL (regression) |
80+| profile 0 420, filters on, square | IDENTICAL (regression) |
81+| `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 |
7982
8083 ## Still refused or unproven
8184
8285 | shape | disposition |
8386 | --- | --- |
8487 | 4:2:2 (`ss_x != ss_y`) | refused by name. Gate re-scoped, not re-run |
85-| 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` |
86-| 1:4 strips (`decode_rect4_16`) | panic, not a named refusal. Not in the square witness |
87-| sub-8 group chroma (`Chroma4` / size 4 in the 4x4-group tails) | still hardcoded 4:2:0. Square witness did not hit this first |
88-| loop filter, CDEF, restoration on | threaded with `ss_*`, not witnessed (proof stream disables them) |
89-| 10-bit 4:4:4 | not encoded, not compared |
90-| `av1-profile1-444.ivf` | not re-run |
91-| full `cargo test -p ec-av1` | not run. Do not claim green |
88+| 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 |
89+| `av1-profile1-444.ivf` | not byte-exact (panic above). Refusal-gate flip to witness gate NOT done |
90+| 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 |
91+| full `cargo test -p ec-av1` | NOT run. Do not claim green |
92+| 0-warning parity | not measured this round |
9293
9394 ## Next
9495
95-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.
96-2. Then turn filters back on one at a time.
97-3. Then a 10-bit profile-2 444 stream (`yuv444p10le`).
98-4. Then the existing `av1-profile1-444.ivf`, after the 1:4 path no longer panics.
99-5. Full suite, `--test-threads=1`, `TMPDIR` on `$HOME`.
96+1. Fix the `decode_rect_split` 64-axis-strip chroma at 4:4:4 (the
97+ len-64 panic): trace which unit feeds `reconstruct_rect` a 64-long
98+ residual; the `chroma_tiled` arm's (32,16)/(16,32) rect units go
99+ through `read_coeffs_rect` + `dequant_and_inverse_typed_wh` — check
100+ the scratch/grid sizing against libaom's two-unit plane-major order.
101+2. Then the inter square-64 four-unit chroma (mirror the intra fix).
102+3. Then the fixture end-to-end vs ffmpeg; flip the refusal gate
103+ (`a_non_420_subsampled_sequence_header_is_refused_by_name` re-scope)
104+ to a fixture witness gate.
105+4. Full suite `--test-threads=1`, 0-warning parity, update this report.