diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index ced0d946..39fa8dfc 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -6598,6 +6598,12 @@ fn tx_size_context_rect( own_w: usize, own_h: usize, ) -> usize { + // `get_tx_size_context` compares against `max_txsize_rect_lookup[bsize]`, + // not the block's own side: no transform is wider or taller than 64, so a + // block with a 128 side resolves against 64 (the square path already caps + // this way, lane-sb128b r1). Without the cap the 64x128 half of a 128-root + // VERT reads the tx-depth symbol off row 0 where libaom uses row 1. + let (own_w, own_h) = (own_w.min(64), own_h.min(64)); let above = mi_r > n.tile_row0_mi && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w; let left = mi_c > n.tile_col0_mi && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_h; if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { @@ -15048,6 +15054,14 @@ thread_local! { /// only shape a 1080p (mi_rows = 270) stream reaches. pub(crate) static PART128_EDGE_HORZ_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; pub(crate) static PART128_EDGE_VERT_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// lane-sb128c r9: 128 roots that resolved to one of the four AB shapes, + /// in `PARTITION_HORZ_A`, `_HORZ_B`, `_VERT_A`, `_VERT_B` order. + pub(crate) static PART128_AB_HITS: std::cell::Cell<[usize; 4]> = const { std::cell::Cell::new([0; 4]) }; +} + +/// [`PART128_AB_HITS`], for a gate's own before/after delta. +pub(crate) fn part128_ab_hits() -> [usize; 4] { + PART128_AB_HITS.with(std::cell::Cell::get) } /// [`PART128_NONE_HITS`], for a gate's own before/after delta. @@ -15170,9 +15184,19 @@ fn read_sb128_root( PARTITION_NONE => PART128_NONE_HITS.with(|c| c.set(c.get() + 1)), PARTITION_HORZ => PART128_HORZ_HITS.with(|c| c.set(c.get() + 1)), PARTITION_VERT => PART128_VERT_HITS.with(|c| c.set(c.get() + 1)), + // lane-sb128c r9: the four AB shapes at the 128 root -- one + // 128x64/64x128 half plus two 64x64 quadrants, decoded by both tile + // paths below in libaom `decode_partition`'s own visit order. + p if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&p) => { + PART128_AB_HITS.with(|c| { + let mut h = c.get(); + h[p - PARTITION_HORZ_A] += 1; + c.set(h); + }); + } _ => { return Err(unsupported( - "a 128x128 superblock AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B at the 128 root)", + "a 128x128 superblock partition value outside the 8-symbol alphabet", )); } } @@ -15387,6 +15411,131 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( mi_cols, mi_rows, )?; + if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part128) { + // lane-sb128c r9: the four AB shapes at the 128 root. + // libaom `decode_partition` (decodeframe.c) codes each as + // two `bsize2` (64x64) squares plus one `subsize` + // (128x64 / 64x128) half, visited HORZ_A = TL, TR, bottom + // half; HORZ_B = top half, BL, BR; VERT_A = TL, BL, right + // half; VERT_B = left half, TR, BR. AB values only come + // from the FULL alphabet symbol, which is only read when + // both halves of the root are inside the frame, so no + // piece needs libaom's `i > 0` frame-edge break (a piece + // may still overhang the bottom/right, which + // `PlaneBuf::reconstruct`'s r8 clip handles). + sb128_none = true; + let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); + let (br, bc) = (at128.0 + 4, at128.1 + 4); + let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); + // Only the VERTICAL arms reorder the squares (TL, BL, TR, + // BR), so only they switch libaom's `has_tr_vert_*` / + // `has_bl_vert_*` tables (lane-sb128c r6 visit order). + let _vert_ab = + (part128 == PARTITION_VERT_A || part128 == PARTITION_VERT_B) + .then(crate::encode::Reach::vert_ab_partition); + // One `cdef_idx` literal per CODED BLOCK, at the first + // non-skip one of each 64x64 CDEF unit; the 128x64 / + // 64x128 half covers two units and its read lands in the + // unit holding its origin, so that value is copied to the + // other one (libaom: every mi of the block points at the + // same `MB_MODE_INFO`). + let cdef_copy = |src: (usize, usize), dst: (usize, usize)| { + CDEF_IDX_GRID.with(|g| { + let mut g = g.borrow_mut(); + let cols = CDEF_SB_COLS.with(|c| c.get()); + if cols == 0 { + return; + } + let (si, di) = ( + (q_r + src.0) * cols + q_c + src.1, + (q_r + dst.0) * cols + q_c + dst.1, + ); + if q_c + src.1 < cols + && q_c + dst.1 < cols + && si < g.len() + && di < g.len() + { + g[di] = g[si]; + } + }); + }; + macro_rules! square64 { + ($at:expr) => {{ + CDEF_TRANSMITTED.with(|c| c.set(false)); + decode_block( + &mut dec, + &mut cdfs, + &mut neighbours, + $at, + SB, + TxbSet::Luma64, + TxbSet::Chroma32, + TX32, + TX32, + (&scan32, &scan32), + false, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + &scan32, + &scan16, + &scan8, + &scan4, + tx_select, + reduced_tx_set, + )? + }}; + } + macro_rules! half128 { + ($at:expr, $bw:expr, $bh:expr, $src:expr, $dst:expr) => {{ + CDEF_TRANSMITTED.with(|c| c.set(false)); + decode_block_128rect( + &mut dec, + &mut cdfs, + &mut neighbours, + $at, + $bw, + $bh, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + tx_select, + reduced_tx_set, + )?; + cdef_copy($src, $dst); + }}; + } + match part128 { + PARTITION_HORZ_A => { + square64!(at128); + square64!((at128.0, bc)); + half128!((br, at128.1), 128, 64, (1, 0), (1, 1)); + } + PARTITION_HORZ_B => { + half128!(at128, 128, 64, (0, 0), (0, 1)); + square64!((br, at128.1)); + square64!((br, bc)); + } + PARTITION_VERT_A => { + square64!(at128); + square64!((br, at128.1)); + half128!((at128.0, bc), 64, 128, (0, 1), (1, 1)); + } + _ => { + half128!(at128, 64, 128, (0, 0), (1, 0)); + square64!((at128.0, bc)); + square64!((br, bc)); + } + } + continue; + } if matches!(part128, PARTITION_HORZ | PARTITION_VERT) { // lane-sb128c r8: libaom `decode_partition` // (decodeframe.c:1554) codes PARTITION_HORZ at the 128 @@ -25262,6 +25411,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( } { let mut sb128_rect = None; + let mut sb128_ab = None; if sb128 && sb_start { let part128 = read_sb128_root( &mut dec, @@ -25275,6 +25425,13 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( mi_cols, mi_rows, )?; + if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part128) { + // lane-sb128c r9: an AB shape at the 128 root -- one + // 128x64/64x128 half plus two 64x64 quadrants, same visit + // order as the key-frame path. + sb128_none = true; + sb128_ab = Some(part128); + } if matches!(part128, PARTITION_HORZ | PARTITION_VERT) { // Two 128x64 (HORZ) or two 64x128 (VERT) inter blocks; the // whole 128x128 root is consumed here, so the remaining @@ -25448,6 +25605,80 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( } }}; } + if let Some(part128) = sb128_ab { + // libaom `decode_partition` (decodeframe.c): HORZ_A = TL, TR, + // bottom half; HORZ_B = top half, BL, BR; VERT_A = TL, BL, + // right half; VERT_B = left half, TR, BR. AB only comes from + // the full alphabet symbol (both halves in frame), so there is + // no `i > 0` edge break to mirror. + let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); + let base_mi = sub16_to_mi(at128); + let (br_mi, bc_mi) = (base_mi.0 + 16, base_mi.1 + 16); + let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); + let _vert_ab = (part128 == PARTITION_VERT_A || part128 == PARTITION_VERT_B) + .then(crate::encode::Reach::vert_ab_partition); + let cdef_copy = |src: (usize, usize), dst: (usize, usize)| { + CDEF_IDX_GRID.with(|g| { + let mut g = g.borrow_mut(); + let cols = CDEF_SB_COLS.with(|c| c.get()); + if cols == 0 { + return; + } + let (si, di) = ( + (q_r + src.0) * cols + q_c + src.1, + (q_r + dst.0) * cols + q_c + dst.1, + ); + if q_c + src.1 < cols && q_c + dst.1 < cols && si < g.len() && di < g.len() + { + g[di] = g[si]; + } + }); + }; + macro_rules! square64_inter { + ($at_mi:expr) => {{ + CDEF_TRANSMITTED.with(|c| c.set(false)); + inter_piece!( + $at_mi, SB, + TxbSet::Luma64, TxbSet::Luma64, TxbSet::Chroma32, TX32, TX32, + &scan32, &scan32, 3, SB, SB + ); + }}; + } + macro_rules! half128_inter { + ($at_mi:expr, $bw:expr, $bh:expr, $src:expr, $dst:expr) => {{ + CDEF_TRANSMITTED.with(|c| c.set(false)); + inter_piece!( + $at_mi, SB * 2, + TxbSet::Luma64, TxbSet::Luma64, TxbSet::Chroma32, TX32, TX32, + &scan32, &scan32, 3, $bw, $bh + ); + cdef_copy($src, $dst); + }}; + } + match part128 { + PARTITION_HORZ_A => { + square64_inter!(base_mi); + square64_inter!((base_mi.0, bc_mi)); + half128_inter!((br_mi, base_mi.1), 128, 64, (1, 0), (1, 1)); + } + PARTITION_HORZ_B => { + half128_inter!(base_mi, 128, 64, (0, 0), (0, 1)); + square64_inter!((br_mi, base_mi.1)); + square64_inter!((br_mi, bc_mi)); + } + PARTITION_VERT_A => { + square64_inter!(base_mi); + square64_inter!((br_mi, base_mi.1)); + half128_inter!((base_mi.0, bc_mi), 64, 128, (0, 1), (1, 1)); + } + _ => { + half128_inter!(base_mi, 64, 128, (0, 0), (1, 0)); + square64_inter!((base_mi.0, bc_mi)); + square64_inter!((br_mi, bc_mi)); + } + } + continue; + } if let Some(part128) = sb128_rect { // lane-sb128c r7: libaom `decode_partition` (decodeframe.c:1554) // codes PARTITION_HORZ at the 128 root as `subsize = diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 70125411..0140fb17 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -1261,13 +1261,32 @@ impl Reach { tx_h: usize, block: Self, ) -> Self { + // A block wider than 64 is coded in 64x64 "mu" chunks in raster + // order, so both libaom predicates special-case it (lane-sb128c r10); + // without this the last unit column of every chunk of a 128x64 block + // predicts from a chunk libaom has not decoded yet. + let wide = bw > 64; Self { - above_right: if col_off + tx_w < bw { + above_right: if row_off > 0 { + // `has_top_right`'s `row_off > 0` branch: the offset is taken + // modulo the 64-wide chunk, except for the one unit whose + // top-right corner is the centre of a 128x128 block. + if wide { + (row_off == 64 && col_off + tx_w == 64) || (col_off % 64) + tx_w < 64 + } else { + col_off + tx_w < bw + } + } else if col_off + tx_w < bw { true } else { - row_off == 0 && block.above_right + block.above_right }, - below_left: if col_off > 0 { + below_left: if wide && col_off > 0 && col_off % 64 == 0 { + // `has_bottom_left`: at the left edge of a right-hand chunk + // the bottom-left pixels are in the already-coded left chunk, + // provided they stay inside it. + (row_off % 64) + tx_h < bh.min(64) + } else if col_off > 0 { false } else if row_off + tx_h < bh { true diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 8df04a73..6320ad0d 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -43,7 +43,7 @@ const REFUSALS: &[&str] = &[ "a tx_type symbol outside its CDF's own set: {t}", "an INTER 32x32 partition type this decoder does not code (value={part32})", "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4", - "a 128x128 superblock AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B at the 128 root)", + "a 128x128 superblock partition value outside the 8-symbol alphabet", "an inter var-tx tree with a leaf transform larger than 64x64", "CfL, filter intra or a palette on a 128-root HORZ/VERT intra block (every one of their size gates caps at 64x64 or below, so none of these symbols exists there)", "intrabc under a 128x128 superblock (libaom's av1_is_dv_valid derives the block-vector delay from sb_size, which this decoder hardcodes to 64)", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 5b1c8d0b..1f17d408 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -128,6 +128,13 @@ pub fn intra_sb128_counters() -> (usize, usize, [usize; 3]) { crate::decode::intra_sb128_hits() } +/// lane-sb128c r9: the four AB shapes at the 128 root, in `PARTITION_HORZ_A`, +/// `_HORZ_B`, `_VERT_A`, `_VERT_B` order (key and inter tile paths share the +/// counter -- it is bumped where the root symbol resolves). +pub fn sb128_ab_counters() -> [usize; 4] { + crate::decode::part128_ab_hits() +} + pub fn rect4_32_counters() -> (usize, usize, usize) { ( crate::decode::rect4_32_horz_hits(), @@ -23120,6 +23127,12 @@ mod tests { (44, "--cq-level=8", 256, 192, false, false, true), (46, "--cq-level=55", 192, 256, false, true, false), (45, "--cq-level=45", 192, 256, true, true, true), + // lane-sb128c r10: a SECOND 128 superblock column is what the + // arms above never had -- the right 64x128 half of a 128-root + // VERT at mi_col 80 read its tx-depth symbol off the wrong CDF + // row and every unit column of a 128x64 chunk predicted from the + // not-yet-decoded chunk to its right. + (47, "--cq-level=45", 512, 512, false, false, true), ]; let (mut matched, mut named_refusals, mut out_of_scope) = (0u32, 0u32, 0u32); let (mut horz_arms, mut vert_arms) = (0u32, 0u32); @@ -23136,7 +23149,17 @@ mod tests { // through `geq` instead -- same effect on the encoder's // partition choice, byte-identical across runs. &format!( - "nullsrc=size={width}x{height}:rate=25,format=yuv420p, geq=lum='128+90*sin((X+2*N)/37)+30*sin(Y/29)': cb='128+30*sin(X/23)':cr='128+30*sin((Y+N)/19)'" + "nullsrc=size={width}x{height}:rate=25,format=yuv420p, geq=lum='{lum}': cb='128+30*sin(X/23)':cr='128+30*sin((Y+N)/19)'", + // The 512x512 arm carries the r9 witness's own + // higher-frequency luma: the smooth two-term source + // gives every 128-rect block a whole-block TX_64X64 + // and no VERT root at all, which is exactly the + // combination that hid the tx-depth CDF row defect. + lum = if width == 512 { + "128+80*sin((X+3*N)/17)+50*sin(Y/29)+30*sin((X+Y)/13)" + } else { + "128+90*sin((X+2*N)/37)+30*sin(Y/29)" + } ), "-pix_fmt", pix, "-strict", "-1", "-t", "0.2", "-f", "yuv4mpegpipe", "-", @@ -23262,6 +23285,179 @@ mod tests { ); } + /// lane-sb128c r9 GATE: the four AB shapes at the 128 root + /// (`PARTITION_HORZ_A`/`_HORZ_B`/`_VERT_A`/`_VERT_B`), each one + /// 128x64/64x128 half plus two 64x64 quadrants in libaom + /// `decode_partition`'s visit order. The recipe is r8's measured one + /// (`--sb-size=128 --min-partition-size=64 --enable-ab-partitions=1` over + /// a 512x512 `geq` sinusoid), which is what made aomenc pick the shapes at + /// all; arms cover cq 18/45, 8 and 10 bit, and one INTER arm + /// (`--kf-max-dist=100`) so the shapes are exercised on both tile paths. + /// Continue-and-sweep: an arm that stops on ANOTHER lane's named refusal + /// is counted and skipped, a decode failure or a pixel mismatch is a hard + /// failure, and the end-of-sweep assert names which of the four fired. + #[test] + fn a_real_aomenc_sb128_ab_partition_at_the_128_root_decodes_pixel_exact() { + const NAME: &str = "a_real_aomenc_sb128_ab_partition_at_the_128_root_decodes_pixel_exact"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); + return; + } + // (tag, cq, width, height, 10-bit, inter) + let arms: Vec<(u32, &str, usize, usize, bool, bool)> = vec![ + (18, "--cq-level=18", 512, 512, false, false), + (45, "--cq-level=45", 512, 512, false, false), + (32, "--cq-level=32", 512, 512, true, false), + (55, "--cq-level=55", 384, 320, false, false), + (91, "--cq-level=45", 512, 512, false, true), + (92, "--cq-level=18", 512, 512, false, true), + ]; + let (mut matched, mut named_refusals, mut out_of_scope) = (0u32, 0u32, 0u32); + let mut ab_seen = [0usize; 4]; + let mut ab_inter = [0usize; 4]; + for (tag, cq, width, height, ten_bit, inter) in arms { + let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" }; + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", + // Same DETERMINISTIC sinusoid source that made aomenc pick + // the AB shapes in the r8 sweep (lavfi `gradients` ignores + // its seed and is not reproducible -- never use it here). + &format!( + "nullsrc=size={width}x{height}:rate=25,format=yuv420p,\ + geq=lum='128+80*sin((X+3*N)/17)+50*sin(Y/29)+30*sin((X+Y)/13)':\ + cb='128+30*sin(X/23)':cr='128+30*sin((Y+N)/19)'" + ), + "-pix_fmt", pix, "-strict", "-1", "-t", "0.2", + "-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 mut args: Vec<&str> = vec![ + "--codec=av1", "--passes=1", "--end-usage=q", cq, + "--cpu-used=0", "--threads=1", "--row-mt=0", + "--sb-size=128", "--min-partition-size=64", + "--enable-rect-partitions=1", "--enable-ab-partitions=1", + "--enable-1to4-partitions=0", "--enable-palette=0", + "--enable-intrabc=0", "--deltaq-mode=0", "--limit=5", + ]; + // AOMENC FLAG PRECEDENCE: last occurrence wins, so the per-arm + // key-frame cadence goes AFTER the base recipe. + args.push(if inter { "--kf-max-dist=100" } else { "--kf-max-dist=1" }); + if ten_bit { + args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); + } + args.extend_from_slice(&["--obu", "-o", "-", "-"]); + let mut child = Command::new(aomenc_path()) + .args(&args) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m.stdout) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "{NAME}: aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let before = sb128_ab_counters(); + if let Err(e) = decode_stream(&stream) { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{NAME} failed outright, not a named refusal \ + (arm {tag} {width}x{height}): {msg}" + ); + named_refusals += 1; + eprintln!("{NAME}: arm {tag} {width}x{height} refusal: {msg}"); + continue; + } + let (frames, hidden) = decode_all_frames_vs_oracle( + &stream, + &format!("sb128c-ab-{tag}-{width}x{height}"), + ); + assert!(frames > 0, "{NAME}: no frames decoded at {width}x{height}"); + let after = sb128_ab_counters(); + let ab: Vec = (0..4).map(|i| after[i] - before[i]).collect(); + eprintln!( + "{NAME}: arm {tag} cq {cq} {width}x{height} {}bit {}: {frames} frames \ + pixel-exact ({hidden} hidden), AB[HORZ_A,HORZ_B,VERT_A,VERT_B] {ab:?}", + if ten_bit { 10 } else { 8 }, + if inter { "INTER" } else { "KEY" }, + ); + if ab.iter().sum::() == 0 { + out_of_scope += 1; + } + for i in 0..4 { + ab_seen[i] += ab[i]; + if inter { + ab_inter[i] += ab[i]; + } + } + matched += 1; + } + assert!( + matched > 0, + "{NAME}: every attempt refused ({named_refusals}); the gate never \ + decoded a stream" + ); + assert!( + ab_seen.iter().sum::() > 0, + "{NAME}: {matched} stream(s) decoded pixel-exact ({out_of_scope} carried \ + no 128-root AB partition at all) but NOT ONE AB shape fired -- the \ + shapes this gate exists for" + ); + // Which of the four this sweep actually reaches, hard-asserted so a + // later change that stops reaching one of them fails here instead of + // silently narrowing the gate (class `gate-blind-to-feature`). + for (i, name) in ["HORZ_A", "HORZ_B", "VERT_A", "VERT_B"].iter().enumerate() { + if AB_ARMS_REACHED[i] { + assert!( + ab_seen[i] > 0, + "{NAME}: PARTITION_{name} at the 128 root fired in the round that \ + pinned this gate but not now: {ab_seen:?}" + ); + } else { + eprintln!( + "{NAME}: PARTITION_{name} NOT reached by this sweep (aomenc never \ + picked it): {ab_seen:?}" + ); + } + } + assert!( + ab_inter.iter().sum::() > 0, + "{NAME}: the AB shapes fired only on KEY frames -- the inter tile path's \ + own AB arm was never exercised: key {ab_seen:?} inter {ab_inter:?}" + ); + } + + /// Which of the four 128-root AB shapes the gate above MEASURED aomenc + /// picking (lane-sb128c r9). An arm that is `false` is not reachable from + /// this sweep's recipes and stays unasserted rather than weakening the + /// asserts of the ones that are. + const AB_ARMS_REACHED: [bool; 4] = [true, true, true, true]; + #[test] #[ignore = "lane-sb128 r2 diagnostic: is the frame-6 mismatch sb128-specific?"] fn sb128_r2_control_sb64() { diff --git a/lanes/sb128c-r10.report.md b/lanes/sb128c-r10.report.md new file mode 100644 index 00000000..dec03bdc --- /dev/null +++ b/lanes/sb128c-r10.report.md @@ -0,0 +1,66 @@ +# lane-sb128c r10 report + +Tip `1f6d885` on `lane-sb128c` (from `c24a2ac`). The r9 blocker is closed: two +root causes, both in code shared by every block wider or taller than 64. + +## Root cause 1 -- `tx_size_context_rect` compared against the block side + +`crates/ec-av1/src/decode.rs:5845` `tx_size_context_rect` tested the above/left +neighbour transform sizes against the block's own `bw`/`bh`. libaom's +`get_tx_size_context` tests against `max_txsize_rect_lookup[bsize]`, which tops +out at TX_64X64: a 64x128 block must compare against 64, not 128. The square +path (`read_tx_depth`, decode.rs:11838) already capped with `side.min(64)` +(lane-sb128b r1); the rect path never did. Consequence: the right 64x128 half +of a 128-root PARTITION_VERT at mi_col 80 read its tx-depth symbol off CDF row +0 where libaom uses row 1, decoded depth 0 (TX_64X64) instead of depth 2 +(TX_16X16), and the tile desynced from that block on. + +Fix: cap both dimensions at 64 inside the helper (one `min`), so all eight call +sites are covered at once. + +## Root cause 2 -- `Reach::of_tu` ignored the 64x64 "mu" chunk order + +`crates/ec-av1/src/encode.rs:1252` `Reach::of_tu` used the plain +`col_off + tx_w < bw` rule. A block wider than 64 is coded in 64x64 chunks in +raster order, so `has_top_right` (reconintra.c) takes `col_off` MODULO the +64-wide chunk in its `row_off > 0` branch (with one exception: the unit whose +top-right corner is the centre of a 128x128), and `has_bottom_left` grants the +left edge of a right-hand chunk what the already-coded left chunk holds. +Without it the last unit column of every chunk of a 128x64 intra block +predicted from a chunk libaom has not decoded yet -- 375 wrong luma samples in +the first such block of a 512x512 key frame, entropy exact. + +## Evidence + +EVIDENCE: `$HOME/.cache/sb128c-r10/{aom.trace,our.trace}` | `EC_TRACE_MODE EC_TRACE_COEFF` aomdec vs `EC_TRACE_MODE EC_TRACE_MODE_STEP EC_TRACE_COEFF` decode_probe on `$HOME/.cache/sb128c-r9/noab.obu`, both under `systemd-run --scope -p MemoryMax=6G`, all_zero rng ladder | first divergence at element 151 = the block at mi_row 0 mi_col 80 (bsize 13, 64x128): oracle reads a tx-depth symbol (rng 32968 -> 42504) and codes TX_16X16 units, ours read none and coded TX_64X64. After fix 1 the whole 5370-element ladder is IDENTICAL. + +EVIDENCE: `$HOME/.cache/sb128c-r10/pred.trace` | `EC_PRED=1 aomdec` on the same stream | the 128x64 block at mi_col 32 has `n_tr=16` for col_off 0/4/8 and `n_tr=0` for col_off 12 at every `row_off > 0` -- exactly the unit column where our recon differed (diff map: 375 samples, all in x 176..191 and 192..255's last column). + +EVIDENCE: `$HOME/.cache/sb128c-r10/{o.f*,m.f*}` | `EC_AV1_PREFILT_DUMP` both decoders over all five r9 streams (noab, ab45, ab18, abi45, ab55; recipe `$HOME/.cache/sb128c-r9/mk.sh`) | every frame of every stream byte-identical after both fixes (before: 5/5 streams DIFF on every frame, 326839/393216 bytes on noab f0). + +EVIDENCE: gate `a_real_aomenc_sb128_intra_rect_block_decodes_pixel_exact` arm 47 | `cargo test -p ec-av1 --lib a_real_aomenc_sb128_intra_rect_block_decodes_pixel_exact -- --nocapture` | `arm 47 cq --cq-level=45 512x512 8bit txsearch=1: 5 frames pixel-exact (0 hidden), intra_128x64 +164 intra_64x128 +156 depth[64/32/16] [26, 0, 294]`. + +EVIDENCE: `$HOME/.cache/reelc-head.obu` | `decode_probe` under `systemd-run --scope -p MemoryMax=6G` after both fixes | `OK: 48 frames decoded, 1920x792`, `sb128_rect: edge_horz=720 inter_128x64=720` -- no refusal, no regression. + +## Gate arm added + +`crates/ec-av1/src/stream.rs:19176` -- a 512x512 arm (tag 47) on the sb128 +intra_rect_block gate: a SECOND 128 superblock column, which no earlier arm had +(192x256 / 384x320 / 256x192 all stop at one 128 column), plus the r9 witness's +own higher-frequency luma source, because the gate's smooth two-term source +gives every 128-rect block a whole-block TX_64X64 and no VERT root -- the exact +combination that hid the defect. Counters prove the shape: 156 64x128 blocks, +294 units at TX_16X16. + +## Suite + +`cargo test -p ec-av1 --lib` (unit `sb128c-suite-r10-1788351731`, after fix 1 +only): 387 passed, 1 failed, 35 ignored -- the one failure was +`a_real_aomenc_sb128_ab_partition_at_the_128_root_decodes_pixel_exact`, which +fix 2 closes. Final run: unit `sb128c-suite-r10b-*`, log +`$HOME/.cache/sb128c-suite-r10b.log` -- **388 passed, 0 failed, 35 ignored** (475 s), including `a_real_aomenc_sb128_ab_partition_at_the_128_root_decodes_pixel_exact`, `..._intra_rect_block_...` (with the new 512x512 arm), `..._gathered_edge_horz_...` and the r7 inter gate. + +## Residue + +- No refusal string was lifted this round; the r9 gate that the AB refusal + lift needs is now green. accepted. diff --git a/lanes/sb128c-r9.handoff.md b/lanes/sb128c-r9.handoff.md new file mode 100644 index 00000000..2aa0e6c7 --- /dev/null +++ b/lanes/sb128c-r9.handoff.md @@ -0,0 +1,50 @@ +# lane-sb128c r9 -> r10 handoff + +Tip `d00a97b` (branch `lane-sb128c`). The four 128-root AB shapes are +IMPLEMENTED on both tile paths and the refusal is lifted; the new gate +`a_real_aomenc_sb128_ab_partition_at_the_128_root_decodes_pixel_exact` is RED +for a reason that is NOT the AB code. + +## The blocker, bisected (do not re-derive) + +- Stream `$HOME/.cache/sb128c-r9/ab45.obu` (512x512 cq45 8-bit key, recipe in + `$HOME/.cache/sb128c-r9/mk.sh`). Frame 0 differs from the oracle. +- `EC_AV1_PREFILT_DUMP` on BOTH decoders: first differing sample is + **byte 321 = (x=320, y=0)**, i.e. the very FIRST sample of the RIGHT 64x128 + half of the third 128 root, which is `PARTITION_VERT` (root values of frame + 0: 1,1,2,5,1,1,3,3,0,0,3,3,0,0,3,3). Post-filter the diff bleeds left to + x=317, which is a deblock artefact, not the cause. +- 326839 of 393216 bytes differ => entropy desync from that block on, not a + reconstruction rounding defect. +- CONTROL: the same stream encoded with `--enable-ab-partitions=0` + (`$HOME/.cache/sb128c-r9/noab.obu`, `mknoab.sh`) diverges at the SAME place. + The defect is r8's `decode_block_128rect` / the 128-root VERT arm, reached + only now that the AB refusal no longer short-circuits the compare (class + `refusal-hides-a-defect`). +- Frame 0 of every failing arm contains ZERO AB partitions -- the first AB in + `ab18.obu` is the 38th 128 root (frame 2). + +## Where to look first + +The right 64x128 half at (mi_row 0, mi_col 80). Suspects, cheapest first: +1. `decode_block_128rect`'s mode-info read for a block whose LEFT neighbour is + the other half of the same root (`read_intra_mode_rect` ctx / neighbour + record of the left half at 64-px granularity). +2. The left half's neighbour recording: r8 stamps the lf/skip grids with the + resolved unit size, so a 64x128 block records 2 units of 64 -- check + `record_mi_luma` / `fill_skip_grid` cover the full 64x128 footprint. +3. A cross-decoder msac RANGE ladder at that block's entry (never tell()). + +## Cheap repro + + ~/.cache/sb128c-r9/cmp.sh ~/.cache/sb128c-r9/ab45.obu # post-filter + EC_AV1_PREFILT_DUMP=... aomdec / decode_probe # pre-filter + +## Still owed + +- The full suite was never run this round (deadline). Expect 388 tests, 1 + failure (the new gate) until the above is fixed. +- `gate_coverage.rs` was NOT touched: the new gate passes + `--enable-ab-partitions=1`, which other gates already do, so its + `NEVER_EXERCISED` lists are unaffected -- CONFIRM by running + `cargo test -p ec-av1 --lib gate_coverage`. diff --git a/lanes/sb128c-r9.report.md b/lanes/sb128c-r9.report.md new file mode 100644 index 00000000..b8e916fa --- /dev/null +++ b/lanes/sb128c-r9.report.md @@ -0,0 +1,81 @@ +# lane-sb128c r9 -- the four AB shapes at the 128 root (key + inter) + +Branch `lane-sb128c`, worktree `edith_codecs-sb128c`, +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sb128c`. + +## What changed + +- `crates/ec-av1/src/decode.rs` `read_sb128_root`: the AB refusal is LIFTED. + Values 4..7 now count into `PART128_AB_HITS` (`part128_ab_hits()`), and the + `_` arm refuses only a value outside the 8-symbol alphabet. +- `crates/ec-av1/src/decode.rs` key-frame tile: a new arm decodes each AB + shape as two 64x64 squares (`decode_block`, `SB`, `Luma64`/`Chroma32`) plus + one 128x64/64x128 half (`decode_block_128rect`, r8) in libaom + `decode_partition`'s order -- HORZ_A = TL, TR, bottom half; HORZ_B = top + half, BL, BR; VERT_A = TL, BL, right half; VERT_B = left half, TR, BR -- + with `Reach::vert_ab_partition` live for the two VERT arms (r6 visit order, + class `visit-order-changes-availability`), `CDEF_TRANSMITTED` reset per + piece (one CDEF unit each, so libaom's per-unit `cdef_transmitted[index]`), + and the half's `cdef_idx` copied to the second 64x64 unit it covers. +- `crates/ec-av1/src/decode.rs` inter tile: the same four arms through + `inter_piece!` (`SB`/`SB*2` with `ww`/`wh` = the true footprint). +- `crates/ec-av1/src/stream.rs` `sb128_ab_counters()`; new gate + `a_real_aomenc_sb128_ab_partition_at_the_128_root_decodes_pixel_exact`. +- `crates/ec-av1/src/refusal_inventory.rs`: the 128-root AB string is replaced + by the alphabet-bound one. + +## Gate: RED -- and the divergence is NOT in the AB code + +`cargo test -p ec-av1 --lib ab_partition_at_the_128_root -- --nocapture` +fails on its FIRST arm: `sb128c-ab-18-512x512` decode-order frame 0 differs +from the oracle at byte 319 (ours 105 vs 107), 326839 bytes differ. + +Frame 0 of that stream contains **no AB partition at all** (`EC_AV1_TRACE` +`partition_w128` values for its 16 roots are 2,2,2,0,0,3,3,0,... ; the first +value in 4..7 is the 38th root, i.e. frame 2). The first differing sample is +(x=317..319, y=0), inside the LEFT 64x128 half of the third 128 root, which is +`PARTITION_VERT` -- r8's `decode_block_128rect`, untouched this round. + +Hand sweep of four 512x512/384x320 arms (`$HOME/.cache/sb128c-r9/cmp.sh`, +oracle `aomdec` vs our `decode_probe`, `EC_AV1_FINAL_DUMP` per frame): + +| stream | first differing byte (frame 0) | AB values in stream | +|---|---|---| +| 512x512 cq18 key | 320 (x=319,y=0) | HORZ_A x3 | +| 512x512 cq45 key | 318 | HORZ_B x1, VERT_B x1 | +| 512x512 cq45 inter (`--kf-max-dist=100`) | 319 | HORZ_A x1 | +| 384x320 cq55 key | 95531 (x=299,y=248), frame 2 exact | none | +| 512x512 cq45 key, `--enable-ab-partitions=0` | 318 | (aomenc still emitted one HORZ_B) | + +The last row is the control: the SAME byte-318 divergence with the AB flag +off, so the 512x512 defect is independent of this round's code. + +EVIDENCE: $HOME/.cache/sb128c-gate-r9.log + $HOME/.cache/sb128c-r9/{ab18,ab45,abi45,ab55,noab}.obu | cargo test ab_partition_at_the_128_root --nocapture; cmp.sh per stream | 5/5 512x512 arms differ at byte 317..320 of frame 0, a frame with zero AB partitions + +## Film (1080p 10-bit AV1) + +| stream | r9 stop | +|---|---| +| `~/.cache/reelc-head.obu` | OK, 48 frames decoded, 1920x792 | +| `-ss 900` 2 s | "an inter 16x16-level AB or 1:4 partition" (another lane) | +| `-ss 9000` 2 s | "an inter SB-level AB partition" (the 64 root, another lane) | + +Unchanged vs r8 -- the 128-root AB was not the film's next wall at these +offsets. + +EVIDENCE: $HOME/.cache/sb128c-r9/{x900,x9000}.obu | decode_probe on head + two 2 s extracts | 48/48 frames on the head, two named refusals from OTHER lanes' 16x16/64-root AB gaps + +## Suite + +NOT run this round (60-minute deadline spent on the divergence bisection). +The new gate is RED, so the suite is 388 tests with 1 failure until the +512x512 128-rect defect is fixed. + +## Residue + +- fix-now (next round): the 512x512 `decode_block_128rect` divergence at + (x~317, y=0) of a `PARTITION_VERT` 128 root. Pinned streams above; the + `--enable-ab-partitions=0` control isolates it from this round's work. Class + `refusal-hides-a-defect`: r8's gate only ran 192x256/384x320 VERT sources, + which never reached it. +- deferred: intra `tx_depth` > 0 at the 128 root (r8 residue, unchanged).