diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index ea4a8fc4..132726fe 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -29843,11 +29843,18 @@ fn decode_inter_block( neighbours.around_mi(at, side) }; let luma_tx_type; - // lane-sb128c r1: a 128x128 inter block's four chroma units - // are read INSIDE the luma leaf loop (one per 64x64 mu chunk); - // these collect them for the block-level neighbour write-back. + // lane-sb128c r1: a 128x128 inter block's chroma is read + // INSIDE the luma leaf loop (each 64x64 mu chunk's own units: + // one per chunk at 4:2:0, FOUR TX_32X32 at ss 0/0); these + // collect them for the block-level neighbour write-back. let mut u_units: Vec = Vec::new(); let mut v_units: Vec = Vec::new(); + // lane-av1-444-128: every luma leaf's coded tx_type, so the + // chunk tail's chroma units can each inherit the type of the + // leaf covering their own quadrant (`av1_get_tx_type`, + // blockd.h:1291, scales the CHROMA 4x4 position back to luma). + let mut leaf_tx_types: Vec<(usize, usize, usize, usize, TxType)> = + Vec::new(); if let Some(leaves) = vartx_leaves.as_ref() { // spec 5.11.17's transform tree, leaf by leaf in the order // `read_var_tx_size` coded it: each unit reads its own @@ -29913,6 +29920,12 @@ fn decode_inter_block( if idx == 0 { first_tx_type = tu_tx_type; } + // lane-av1-444-128: the per-unit chroma inheritance in + // the chunk tail resolves each unit's own tx_type from + // the luma leaf covering its quadrant. + if side > 64 { + leaf_tx_types.push((row, col, tw, th, tu_tx_type)); + } neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid); // lane-sb128c r1: libaom's `decode_token_recon_block` // walks 64x64 "mu" chunks (`mu_blocks_wide/high = @@ -29930,21 +29943,37 @@ fn decode_inter_block( let (cr, cc) = chunk; // `av1_get_max_uv_txsize(BLOCK_128X128)` = // `av1_get_adjusted_tx_size(TX_64X64)` = - // TX_32X32: one 32x32 chroma unit per chunk. + // TX_32X32. The mu walk + // (`decode_token_recon_block`, decodeframe.c) + // then enumerates, per plane, EVERY TX_32X32 + // unit of the chunk's chroma in raster order: + // at ss 0/0 the chunk's chroma is 64x64 and + // that is FOUR units; at 4:2:0 it is 32x32 + // and the loop degenerates to the one unit + // this arm has always coded. `chroma_side` + // already carries the subsampling. let cu_tx = 32usize; - let luma_span = cu_tx * 2; - let cu_mi = (at_mi.0 + cr * 16, at_mi.1 + cc * 16); - let cu_around = neighbours.around_mi(cu_mi, luma_span); - let (cu_x, cu_y) = (cpx + cc * cu_tx, cpy + cr * cu_tx); + let chunk_chroma = chroma_side * 64 / side; + let units = chunk_chroma / cu_tx; + // The unit's own footprint on the LUMA mi + // grid: 64 px (16 mi) at 4:2:0, 32 px (8 mi) + // at ss 0/0. `around_mi` reads and + // `record_mi_chroma` stamps span exactly the + // unit's own cells -- `get_txb_ctx` reads the + // 8 context cells of the TX_32X32 itself, and + // `av1_set_entropy_contexts` memsets the same + // 8, so the unit over never sees this unit's + // state and the unit below always does. + let unit_luma = cu_tx * (side / chroma_side); let cu_scan = default_scan(cu_tx); if lossless(fctx) { - // lane-lossless2: this chunk's chroma is - // 8x8 TX_4X4 units per plane, not one - // TX_32X32 unit. + // lane-lossless2: TX_4X4 units over this + // chunk's chroma, not one TX_32X32 unit. read_inter_chroma_lossless( dec, cdfs, neighbours, u, v, su, sv, at_mi, (cpx, cpy), - (cc * cu_tx, cr * cu_tx), (cu_tx, cu_tx), + (cc * chunk_chroma, cr * chunk_chroma), + (chunk_chroma, chunk_chroma), (write_chroma_w, write_chroma_h), chroma_side, mode_for_tx, base_q_idx, &mut u_units, &mut v_units, fctx, @@ -29958,50 +29987,131 @@ fn decode_inter_block( } else { (sv, &mut *v) }; - let cu_pred = - src.offset(cr * cu_tx * chroma_side + cc * cu_tx); - let cu_grid = read_inter_plane( - dec, - cdfs, - chroma_set, - &cu_scan, - plane_idx, - cu_around[plane_idx], - mode_for_tx, - buf, - cu_x, - cu_y, - cu_tx, - base_q_idx, - cu_pred, - Some(first_tx_type), - Some(3), fctx, - )? - .0; - // Immediately, so the NEXT chunk's unit - // reads this one's coefficient context. - neighbours.record_mi_chroma( - cu_mi, luma_span, luma_span, plane_idx, &cu_grid, - ); - hit!(CHROMA_SPLIT_TX_HITS); - mu_chroma = true; - let dst = mu_units( - if plane_idx == 1 { &mut u_units } else { &mut v_units }, - chroma_side * chroma_side, - ); - for rr in 0..cu_tx { - let start = - (cr * cu_tx + rr) * chroma_side + cc * cu_tx; - dst[start..start + cu_tx] - .copy_from_slice(&cu_grid[rr * cu_tx..][..cu_tx]); + // Plane-major per chunk (libaom's plane + // loop is outermost inside the mu walk); + // within a plane the units walk raster. + for ur in 0..units { + for uc in 0..units { + let unit_mi = ( + at_mi.0 + cr * 16 + + ur * (unit_luma / MI), + at_mi.1 + cc * 16 + + uc * (unit_luma / MI), + ); + // Per unit, AFTER the earlier + // units' stamps: this unit's + // coefficient context must see + // them. + let cu_around = neighbours + .around_mi(unit_mi, unit_luma); + let (cu_x, cu_y) = ( + cpx + cc * chunk_chroma + + uc * cu_tx, + cpy + cr * chunk_chroma + + ur * cu_tx, + ); + // `av1_get_tx_type` (blockd.h: + // 1291): an inter block's chroma + // unit never codes a tx_type; it + // inherits the coded type of the + // luma leaf covering its own + // quadrant (all of this chunk's + // leaves are read by now). + let unit_rel_mi = ( + unit_mi.0 - at_mi.0, + unit_mi.1 - at_mi.1, + ); + let covering = leaf_tx_types + .iter() + .copied() + // leaf (row, col) are mi but + // (tw, th) are px (the rect + // leaf path divides by MI too) + .find( + |&(lr, lc, lw, lh, _)| { + lr <= unit_rel_mi.0 + && unit_rel_mi.0 + < lr + lh / MI + && lc <= unit_rel_mi.1 + && unit_rel_mi.1 + < lc + lw / MI + }, + ) + .map(|(_, _, _, _, t)| t); + let cu_pred = src.offset( + (cr * chunk_chroma + + ur * cu_tx) + * chroma_side + + cc * chunk_chroma + + uc * cu_tx, + ); + let cu_grid = read_inter_plane( + dec, + cdfs, + chroma_set, + &cu_scan, + plane_idx, + cu_around[plane_idx], + mode_for_tx, + buf, + cu_x, + cu_y, + cu_tx, + base_q_idx, + cu_pred, + Some( + covering.unwrap_or( + TxType::DctDct + ), + ), + Some(3), fctx, + )? + .0; + // Immediately, so the NEXT unit + // reads this one's coefficient + // context. + neighbours.record_mi_chroma( + unit_mi, + unit_luma, + unit_luma, + plane_idx, + &cu_grid, + ); + hit!(CHROMA_SPLIT_TX_HITS); + mu_chroma = true; + let dst = mu_units( + if plane_idx == 1 { + &mut u_units + } else { + &mut v_units + }, + chroma_side * chroma_side, + ); + for rr in 0..cu_tx { + let start = (cr * chunk_chroma + + ur * cu_tx + + rr) + * chroma_side + + cc * chunk_chroma + + uc * cu_tx; + dst[start..start + cu_tx] + .copy_from_slice( + &cu_grid + [rr * cu_tx..] + [..cu_tx], + ); + } + } } } } } } - // `av1_get_tx_type`'s chroma lookup scales the chroma - // position back to luma, so an inter block's chroma - // inherits the *first* (top-left) luma unit's coded type. + // The block-level `luma_tx_type` stays the first + // (top-left) luma unit's coded type; the PER-UNIT chroma + // inheritance in the chunk tail above resolves each unit's + // own covering leaf instead (`av1_get_tx_type`, + // blockd.h:1291). luma_tx_type = first_tx_type; luma_grid = Grid::Zero(side * side); } else if rect_tu { @@ -31177,11 +31287,18 @@ fn decode_inter_block( _ => around, }; let luma_tx_type; - // lane-sb128c r1: a 128x128 inter block's four chroma units - // are read INSIDE the luma leaf loop (one per 64x64 mu chunk); - // these collect them for the block-level neighbour write-back. + // lane-sb128c r1: a 128x128 inter block's chroma is read + // INSIDE the luma leaf loop (each 64x64 mu chunk's own units: + // one per chunk at 4:2:0, FOUR TX_32X32 at ss 0/0); these + // collect them for the block-level neighbour write-back. let mut u_units: Vec = Vec::new(); let mut v_units: Vec = Vec::new(); + // lane-av1-444-128: every luma leaf's coded tx_type, so the + // chunk tail's chroma units can each inherit the type of the + // leaf covering their own quadrant (`av1_get_tx_type`, + // blockd.h:1291, scales the CHROMA 4x4 position back to luma). + let mut leaf_tx_types: Vec<(usize, usize, usize, usize, TxType)> = + Vec::new(); if let Some(leaves) = vartx_leaves.as_ref() { // spec 5.11.17's transform tree, leaf by leaf in the order // `read_var_tx_size` coded it: each unit reads its own @@ -31247,6 +31364,12 @@ fn decode_inter_block( if idx == 0 { first_tx_type = tu_tx_type; } + // lane-av1-444-128: the per-unit chroma inheritance in + // the chunk tail resolves each unit's own tx_type from + // the luma leaf covering its quadrant. + if side > 64 { + leaf_tx_types.push((row, col, tw, th, tu_tx_type)); + } neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid); // lane-sb128c r1: libaom's `decode_token_recon_block` // walks 64x64 "mu" chunks (`mu_blocks_wide/high = @@ -31264,21 +31387,37 @@ fn decode_inter_block( let (cr, cc) = chunk; // `av1_get_max_uv_txsize(BLOCK_128X128)` = // `av1_get_adjusted_tx_size(TX_64X64)` = - // TX_32X32: one 32x32 chroma unit per chunk. + // TX_32X32. The mu walk + // (`decode_token_recon_block`, decodeframe.c) + // then enumerates, per plane, EVERY TX_32X32 + // unit of the chunk's chroma in raster order: + // at ss 0/0 the chunk's chroma is 64x64 and + // that is FOUR units; at 4:2:0 it is 32x32 + // and the loop degenerates to the one unit + // this arm has always coded. `chroma_side` + // already carries the subsampling. let cu_tx = 32usize; - let luma_span = cu_tx * 2; - let cu_mi = (at_mi.0 + cr * 16, at_mi.1 + cc * 16); - let cu_around = neighbours.around_mi(cu_mi, luma_span); - let (cu_x, cu_y) = (cpx + cc * cu_tx, cpy + cr * cu_tx); + let chunk_chroma = chroma_side * 64 / side; + let units = chunk_chroma / cu_tx; + // The unit's own footprint on the LUMA mi + // grid: 64 px (16 mi) at 4:2:0, 32 px (8 mi) + // at ss 0/0. `around_mi` reads and + // `record_mi_chroma` stamps span exactly the + // unit's own cells -- `get_txb_ctx` reads the + // 8 context cells of the TX_32X32 itself, and + // `av1_set_entropy_contexts` memsets the same + // 8, so the unit over never sees this unit's + // state and the unit below always does. + let unit_luma = cu_tx * (side / chroma_side); let cu_scan = default_scan(cu_tx); if lossless(fctx) { - // lane-lossless2: this chunk's chroma is - // 8x8 TX_4X4 units per plane, not one - // TX_32X32 unit. + // lane-lossless2: TX_4X4 units over this + // chunk's chroma, not one TX_32X32 unit. read_inter_chroma_lossless( dec, cdfs, neighbours, u, v, su, sv, at_mi, (cpx, cpy), - (cc * cu_tx, cr * cu_tx), (cu_tx, cu_tx), + (cc * chunk_chroma, cr * chunk_chroma), + (chunk_chroma, chunk_chroma), (write_chroma_w, write_chroma_h), chroma_side, mode_for_tx, base_q_idx, &mut u_units, &mut v_units, fctx, @@ -31292,50 +31431,131 @@ fn decode_inter_block( } else { (sv, &mut *v) }; - let cu_pred = - src.offset(cr * cu_tx * chroma_side + cc * cu_tx); - let cu_grid = read_inter_plane( - dec, - cdfs, - chroma_set, - &cu_scan, - plane_idx, - cu_around[plane_idx], - mode_for_tx, - buf, - cu_x, - cu_y, - cu_tx, - base_q_idx, - cu_pred, - Some(first_tx_type), - Some(3), fctx, - )? - .0; - // Immediately, so the NEXT chunk's unit - // reads this one's coefficient context. - neighbours.record_mi_chroma( - cu_mi, luma_span, luma_span, plane_idx, &cu_grid, - ); - hit!(CHROMA_SPLIT_TX_HITS); - mu_chroma = true; - let dst = mu_units( - if plane_idx == 1 { &mut u_units } else { &mut v_units }, - chroma_side * chroma_side, - ); - for rr in 0..cu_tx { - let start = - (cr * cu_tx + rr) * chroma_side + cc * cu_tx; - dst[start..start + cu_tx] - .copy_from_slice(&cu_grid[rr * cu_tx..][..cu_tx]); + // Plane-major per chunk (libaom's plane + // loop is outermost inside the mu walk); + // within a plane the units walk raster. + for ur in 0..units { + for uc in 0..units { + let unit_mi = ( + at_mi.0 + cr * 16 + + ur * (unit_luma / MI), + at_mi.1 + cc * 16 + + uc * (unit_luma / MI), + ); + // Per unit, AFTER the earlier + // units' stamps: this unit's + // coefficient context must see + // them. + let cu_around = neighbours + .around_mi(unit_mi, unit_luma); + let (cu_x, cu_y) = ( + cpx + cc * chunk_chroma + + uc * cu_tx, + cpy + cr * chunk_chroma + + ur * cu_tx, + ); + // `av1_get_tx_type` (blockd.h: + // 1291): an inter block's chroma + // unit never codes a tx_type; it + // inherits the coded type of the + // luma leaf covering its own + // quadrant (all of this chunk's + // leaves are read by now). + let unit_rel_mi = ( + unit_mi.0 - at_mi.0, + unit_mi.1 - at_mi.1, + ); + let covering = leaf_tx_types + .iter() + .copied() + // leaf (row, col) are mi but + // (tw, th) are px (the rect + // leaf path divides by MI too) + .find( + |&(lr, lc, lw, lh, _)| { + lr <= unit_rel_mi.0 + && unit_rel_mi.0 + < lr + lh / MI + && lc <= unit_rel_mi.1 + && unit_rel_mi.1 + < lc + lw / MI + }, + ) + .map(|(_, _, _, _, t)| t); + let cu_pred = src.offset( + (cr * chunk_chroma + + ur * cu_tx) + * chroma_side + + cc * chunk_chroma + + uc * cu_tx, + ); + let cu_grid = read_inter_plane( + dec, + cdfs, + chroma_set, + &cu_scan, + plane_idx, + cu_around[plane_idx], + mode_for_tx, + buf, + cu_x, + cu_y, + cu_tx, + base_q_idx, + cu_pred, + Some( + covering.unwrap_or( + TxType::DctDct + ), + ), + Some(3), fctx, + )? + .0; + // Immediately, so the NEXT unit + // reads this one's coefficient + // context. + neighbours.record_mi_chroma( + unit_mi, + unit_luma, + unit_luma, + plane_idx, + &cu_grid, + ); + hit!(CHROMA_SPLIT_TX_HITS); + mu_chroma = true; + let dst = mu_units( + if plane_idx == 1 { + &mut u_units + } else { + &mut v_units + }, + chroma_side * chroma_side, + ); + for rr in 0..cu_tx { + let start = (cr * chunk_chroma + + ur * cu_tx + + rr) + * chroma_side + + cc * chunk_chroma + + uc * cu_tx; + dst[start..start + cu_tx] + .copy_from_slice( + &cu_grid + [rr * cu_tx..] + [..cu_tx], + ); + } + } } } } } } - // `av1_get_tx_type`'s chroma lookup scales the chroma - // position back to luma, so an inter block's chroma - // inherits the *first* (top-left) luma unit's coded type. + // The block-level `luma_tx_type` stays the first + // (top-left) luma unit's coded type; the PER-UNIT chroma + // inheritance in the chunk tail above resolves each unit's + // own covering leaf instead (`av1_get_tx_type`, + // blockd.h:1291). luma_tx_type = first_tx_type; luma_grid = Grid::Zero(side * side); } else if rect_tu { diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 1dcca8c2..756cd549 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -28055,6 +28055,141 @@ pub(crate) mod tests { ); } + /// lane-av1-444-128: a real `aomenc` stream whose inter frames are ONE + /// 128x128 PARTITION_NONE block each, non-skip, must walk that block's + /// chroma through the mu-chunk loop -- one TX_32X32 unit per 64x64 mu + /// chunk per plane at 4:2:0 (`decode_token_recon_block`'s mu walk with + /// `av1_get_max_uv_txsize(BLOCK_128X128)` = `TX_32X32`), each unit read + /// at its own origin against its own entropy-cell span and stamped + /// immediately (`av1_set_entropy_contexts`). The census asserts the walk + /// actually ran (four units per plane per coded 128-none block); the key + /// frame splits to 64x64 (detailed testsrc2 content), so the whole + /// stream stays inside the 4:2:0 paths this tree decodes. The 4:4:4 twin + /// of this shape (FOUR TX_32X32 units per chunk per plane) is witnessed + /// in `lanes/av1444128.report.md` against the merged 444 tree -- this + /// tree still refuses non-4:2:0 sequences by name. + #[test] + fn a_real_aomenc_128x128_none_inter_blocks_coded_chroma_per_mu_chunk_decodes_pixel_exact() { + const NAME: &str = + "a_real_aomenc_128x128_none_inter_blocks_coded_chroma_per_mu_chunk_decodes_pixel_exact"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() || !have_aomenc() { + eprintln!("SKIP {NAME}: no ffmpeg/aomenc/aomdec"); + return; + } + let y4m = Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + "testsrc2=size=128x128:rate=30", + "-frames:v", + "12", + "-pix_fmt", + "yuv420p", + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "{NAME}: ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let args: Vec<&str> = vec![ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=8", + "--cpu-used=2", + "--threads=1", + "--row-mt=0", + "--lag-in-frames=0", + "--kf-max-dist=100", + "--enable-fwd-kf=0", + "--sb-size=128", + "--max-partition-size=128", + "--min-partition-size=64", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-cdef=0", + "--enable-restoration=0", + "--loopfilter-control=0", + "--enable-obmc=0", + "--enable-warped-motion=0", + "--enable-interintra-comp=0", + "--enable-interintra-wedge=0", + "--enable-smooth-interintra=0", + "--enable-ref-frame-mvs=0", + "--deltaq-mode=0", + "--tile-columns=0", + "--limit=12", + "--obu", + "-o", + "-", + "-", + ]; + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); + assert!( + out.status.success(), + "{NAME}: aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let header = { + let mut parser = ec_av1_syntax::Av1Parser::new(); + let mut pos = 0usize; + while let Ok(obu) = parser.parse_obu(&stream[pos..]) { + pos += obu.total_size; + if pos >= stream.len() { + break; + } + } + parser + .sequence_header() + .map(|q| (q.use_128x128_superblock, q.color_config.bit_depth)) + }; + assert_eq!( + header, + Some((true, 8)), + "{NAME}: the encoder did not write a 128x128-superblock 8-bit sequence header -- \ + the flags never arrived" + ); + let before = (crate::decode::inter_sb128_none_hits(), crate::decode::chroma_split_tx_hits()); + let (frames, hidden) = decode_all_frames_vs_oracle(&stream, "av1444128-128none-mu-chroma"); + let (none128, chroma_units) = ( + crate::decode::inter_sb128_none_hits() - before.0, + crate::decode::chroma_split_tx_hits() - before.1, + ); + assert!( + frames >= 11, + "{NAME}: only {frames} decode-order frames" + ); + assert!( + none128 >= 8, + "{NAME}: only {none128} inter 128x128 PARTITION_NONE roots -- the recipe stopped \ + exercising the shape this gate names" + ); + assert!( + chroma_units >= 8 * 8, + "{NAME}: only {chroma_units} mu-chunk chroma units read -- the per-unit walk this \ + gate names never fired (four units per plane per coded 128-none inter block)" + ); + eprintln!( + "{NAME}: {frames} decode-order frames pixel-exact ({hidden} hidden), \ + inter_sb128_none_hits={none128} chroma_units={chroma_units}" + ); + } + /// lane-sbpart r2: a real `aomenc` stream whose superblock-level /// partition decision is genuinely HORZ/VERT (not NONE/SPLIT) must /// decode pixel-exact through [`crate::decode::decode_block_rect64`] -- diff --git a/lanes/av1444128.report.md b/lanes/av1444128.report.md new file mode 100644 index 00000000..ba22033a --- /dev/null +++ b/lanes/av1444128.report.md @@ -0,0 +1,147 @@ +# Lane av1444128: AV1 4:4:4 inter 128x128 mu-chunk chroma port (side>64 arm) + +Base: main `73f3ac64`. Branch `lane-av1-444-128`, worktree +`/home/user/Documents/Code/Rust/edith_codecs-av1444128`. Closes the named gap +in `lanes/av1444.report.md` continuation 8 item 5: "an inter 128x128 block at +4:4:4 still codes ONE chroma unit per mu chunk where libaom codes four +(`side > 64` arm)". + +## What changed (decode.rs, both inter arms -- compound and single-ref; the two +arms' text was byte-identical, the patch asserts that and rewrites both) + +1. **The chunk tail's chroma read is now a per-unit walk** (libaom + `decode_token_recon_block`, decodeframe.c mu loop + `av1_get_max_uv_txsize` + blockd.h:1361): `av1_get_max_uv_txsize(BLOCK_128X128)` = TX_32X32, and the mu + walk enumerates EVERY TX_32X32 unit of the chunk's chroma per plane in raster + order. At ss 0/0 the chunk's chroma is 64x64 -> FOUR units; at 4:2:0 it is + 32x32 -> the loop degenerates to the one unit the arm always coded + (`chunk_chroma = chroma_side * 64 / side`, `units = chunk_chroma / 32` -- + derived from the existing `chroma_side`, so the patch composes with the 444 + lane's `chroma_side = side >> ss_x` threading without touching it). +2. **Per-unit geometry and stamps** (the 444 lane's continuation-8 lesson): + each unit reads `around_mi` at its own mi origin over its own entropy-cell + span (64 px at 4:2:0, 32 px = 8 mi cells at ss 0/0; `get_txb_ctx` reads 8 + chroma context cells either way) and `record_mi_chroma`s the unit's own grid + immediately, so the next unit over reads this one's state. Offsets + (`cu_x/cu_y`, the MC predictor slice, the assembled `u_units`/`v_units` + grid placement) are all generalized off `chunk_chroma`; at 4:2:0 every + generalized expression equals the old literal (byte-identical degenerate + case, witnessed below). +3. **Per-unit chroma tx_type inheritance** (`av1_get_tx_type`, blockd.h:1291): + an inter block's chroma unit inherits the coded type of the luma leaf + covering its own quadrant (the map is read at the chroma 4x4 position scaled + back to luma), not the block's first leaf. The arms now collect each luma + leaf's `(row, col, tw, th, tx_type)` and resolve the cover per unit. At + 4:2:0 with unsplit TX_64X64 leaves every type is DCT_DCT and this equals the + old `first_tx_type` pass-through (byte-identical); with split leaves the old + code was wrong and the new code is libaom-exact. `reduce_inherited_chroma_tx_type` + (the chroma ext-tx narrowing) is unchanged. +4. The lossless sub-arm's call now passes the generalized chunk offset/size; + its internal per-unit walk is unchanged. +5. New regression gate + `a_real_aomenc_128x128_none_inter_blocks_coded_chroma_per_mu_chunk_decodes_pixel_exact` + (stream.rs): testsrc2 128x128, `--sb-size=128 --min-partition-size=64 + --max-partition-size=128 --cq-level=8 --cpu-used=2`, 12 frames; the key + frame splits to 64x64 (detailed content) and ALL 11 inter frames are + non-skip 128x128 PARTITION_NONE blocks. Hard census asserts + (`inter_sb128_none_hits >= 8`, `chroma_split_tx_hits >= 64` = two units per + plane per coded block -- measured 11 and 88) + pixel-exact via + `decode_all_frames_vs_oracle`. + +## Reproduce (ticket step 1) + +Recipe: `ffmpeg testsrc2=size=128x128` 12f y4m | `aomenc --profile=1 +--sb-size=128 --min-partition-size=64 --max-partition-size=128 --cq-level=8 +--cpu-used=2 --enable-obmc=0 --enable-warped-motion=0 --enable-interintra-comp=0 +--enable-interintra-wedge=0 --enable-smooth-interintra=0 --enable-ref-frame-mvs=0 +--kf-max-dist=100 --enable-fwd-kf=0 --enable-palette=0 --enable-intrabc=0 +--enable-cdef=0 --enable-restoration=0 --loopfilter-control=0 --obu` (`w128_444.obu`, +scripts in `$HOME/.cache/av1444128/`). Partition census (instrumented aomdec +`EC_TRACE`): frame 0 = 128 root SPLIT (four 64x64 NONE -- no 128x128 INTRA +block anywhere, which matters because the 444 tree's INTRA 128 arm is still +one-unit-per-chunk, see gaps); frames 1..11 = 128x128 PARTITION_NONE, all +non-skip. Pre-port confirmation (probe built from lane-av1-444 `1ad7e0fc`): +frame 0 decodes byte-exact; every inter frame is garbage (~40k differing +samples of 49152) with the entropy ladder still consuming the same symbol +count -- our side reads 24 coefficient units per inter frame where libaom reads +48, and the oracle trace shows the FOUR TX_32X32 chroma units per chunk per +plane (`EC_COEFF plane=1 rows/cols 0,0 0,8 8,0 8,8` per chunk) that the old arm +never read. Note the encoder split the LUMA var-tx tree to TX_32X32 leaves +here, so the one DctDct leaf in the stream also exercised inheritance (below). + +## Defect found and fixed during verification (class mixed-unit-tuple) + +The vartx leaf tuple `(row, col, tw, th)` mixes units: `(row, col)` are MI, +`(tw, th)` are PIXELS (the rect-leaf path already divides by `MI`). The first +cut of the covering-leaf lookup compared the px extents as mi, so the one +non-Idtx leaf in the witness stream (DctDct at luma (64,96)) mapped its chroma +unit to the wrong type (Idtx) -- reconstruction-only corruption of exactly that +unit (~1.2k chroma samples/frame, entropy in sync, Y exact). Fixed by dividing +the leaf extents by `MI` in the predicate (`EC_LEAFDBG` scratch instrumentation +pinned it; instrument removed after). + +## Byte-exactness (probe `decode_probe`; `EC_PROBE_OUT` raw planes vs +`aomdec --rawvideo` and `ffmpeg -pix_fmt` rawvideo; all fresh runs, `-y`) + +| tree | stream | result | +| --- | --- | --- | +| scratch = lane-av1-444 `1ad7e0fc` + this patch | `w128_444.obu` (11 non-skip 128-none inter, 444) | **IDENTICAL three-way**, sha256 `6cd1ded4ffa94ff7538704fe57e4e4ca40853f45eaab0eb5f5ba7dd879c03e8e` (589824 B) | +| this tree (main + patch) | `w128_420.obu` (same recipe, profile 0) | **IDENTICAL three-way**, sha256 `e1072eb0b6484da8d75cb6f587299ffe029cc4c0b12f7a510f0699ddbb2bbaf9` (294912 B) | +| scratch | the 444 lane's full 60-frame fixture `full.obu` | **IDENTICAL**, sha256 `c3f95bca00f0ba5ea9f7071f5645edd910b590efebea2d73398017d10dc272d7` -- the same sha continuation 8 quoted; zero regression | +| scratch | `f_nolf.obu`, `f444_64.obu`, `sq444.obu` | decode, no refusal | +| scratch | `w128c_444.obu` (lag-in-frames=3: ARF exists; 7 non-skip 128-none inter frames, `EC_MODE_VAL mode=23/24` = real COMPOUND_REFERENCE picks, ref1=4/7) | **IDENTICAL** vs aomdec, sha256 `bdc3da9f1c8ec75cd7315606b0d260da955996ae86fbd85bb7d3c33e9e0cedd8` -- the compound arm's copy of the patch is exercised and exact | +| this tree | new census gate (above) | ok (11 none-roots, 88 units, pixel-exact) | + +The committed diff is main-only; the 444 witness necessarily rides the scratch +merge with the 444 lane because this tree still refuses non-4:2:0 sequences by +name (that refusal lift is lane-av1-444's, in review). The two arms' pre-patch +text was byte-identical across both trees (asserted by the patch script, +`$HOME/.cache/av1444128/patch_128.py`), so the same patch applied to both. + +## Still refused or unproven (named gaps, unchanged by this lane) + +| shape | disposition | +| --- | --- | +| INTRA 128x128 chroma at ss 0/0 (one unit per chunk, libaom codes four) | exists only on lane-av1-444's tree (main refuses 444); same class one arm over -- flagged for the 444 lane's next continuation | +| `read_inter_chroma_lossless` indexes chroma units at `ox / 2` (4:2:0 mi math) | 444-lossless inter chroma unported upstream; offsets passed in are now generalized, internals are the 444 lane's | +| 128x128 block overhanging the frame edge: the mu walk does not clip unit origins past `mi_cols`/`mi_rows` (libaom `max_block_wide/high`) | pre-existing at 4:2:0 (unexercised by every byte-exact fixture); left untouched so the 4:2:0 degenerate case stays byte-identical | +| a committed suite test for the 444 twin | impossible on this tree (444 refused); recipe + scratch-tree witness above are ready for the post-merge tree | + +## Build + +`cargo build --release -p ec-av1 --example decode_probe`: 0 warnings (release +target recompiled after touching decode.rs; grep -ci warning = 0). + +## Full suite + +Handed to Main per the batch standing order (full suites run on the server, not +locally; the locally started run was stopped at ~10 min). Main staged the clean +worktree at commit `5bc108bc` to server-3 (user@host-b, unit +`av1444128-suite`) with `EC_AV1_REQUIRE_AOMENC=1 EC_AV1_REQUIRE_FFMPEG=1`, +command `cargo test -p ec-av1 -- --test-threads=1`. The literal final +`test result:` line is appended to this section (and the commit amended) when +the run lands. + +PENDING (server-3 run in flight) + +LANDED (server-3, payload 5bc108bc, code bytes identical to 6a670aa0): + +`test result: FAILED. 603 passed; 4 failed; 60 ignored; 0 measured; 0 filtered out; finished in 23908.50s` + +All four failures are server-staging absences (Main's triage of the bodies: the +tarball excludes `lanes/`, and only the oracle aomenc was installed), not lane +regressions -- this lane's new census gate passed: + +- `intra::tests::rect_predictors_match_c_dump` -- missing + `lanes/intrarect_dump.c` (tarball excludes `lanes/`) +- `stream::tests::a_real_affine_global_motion_stream_decodes_pixel_exact` -- + no aomenc at `~/.cache/aom-affine/build/aomenc` on that host (only the + oracle aomenc was installed); the same test is also the 444 lane's known + live-aomenc infra race (continuation 8), green in isolated re-runs +- `stream::tests::a_real_aomenc_stream_with_film_grain_decodes_pixel_exact` -- + NotFound (fixture or tool path), not a pixel diff +- `wedge::tests::wedge_codebook_matches_libaom_dump` -- missing + `lanes/wedge_libaom.expected.txt` + +Main is filling the missing paths for the next suite on that host. +