From bc895cb0962ca874d263731e05261eb66fac5552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Sep 2026 07:59:33 +0300 Subject: [PATCH] feat(av1): decode a 128x128 PARTITION_NONE root on the INTER path (gate still red) The inter tile loop now codes one whole 128x128 inter block instead of refusing it: four TX_64X64 luma units (max_txsize_rect_lookup[BLOCK_128X128]) whether the tx mode is SELECT or LARGEST, four TX_32X32 chroma units (av1_get_max_uv_txsize) read INSIDE the luma leaf loop one per 64x64 mu chunk (libaom decode_token_recon_block codes every plane of a chunk before the next), the chroma txb_skip offset-10 rows, cdef_idx replicated over the block's four quadrants, and OBMC's overlap capped at min(block, 64)/2 (reconinter.c:860/899) -- without that cap obmc_mask(64) panicked, which is the first thing ReelC hit. ReelC's 2 s head now stops at "a 128x128 superblock HORZ/VERT or AB partition" instead of "a 128x128 superblock PARTITION_NONE root on an inter frame". The new gate a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact is #[ignore]d and RED: the recipe fires four partition_w128 value=0 roots and the key frame decodes alone, but the 8-frame stream refuses at a 32x64 intra strip --enable-rect-partitions=0 forbids, i.e. our own desync. lanes/sb128c-r1.report.md has the triage and r2's ladder. --- crates/ec-av1/src/decode.rs | 280 +++++++++++++++++++++++-- crates/ec-av1/src/refusal_inventory.rs | 2 +- crates/ec-av1/src/stream.rs | 164 +++++++++++++++ lanes/sb128c-r1.report.md | 101 +++++++++ 4 files changed, 533 insertions(+), 14 deletions(-) create mode 100644 lanes/sb128c-r1.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index a614323b..2524a497 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1901,6 +1901,17 @@ pub(crate) fn rect_partition_hits() -> usize { // lane-inter8 r1: how many superblocks an inter tile coded as a single // whole-SB `PARTITION_NONE` 64x64 inter block (the case aomenc picks for // static content, previously a named refusal). +thread_local! { + /// lane-sb128c r1: how many 128x128 `PARTITION_NONE` roots this INTER tile + /// path decoded as one whole block (its gate's own witness). + pub(crate) static INTER_SB128_NONE_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of [`INTER_SB128_NONE_HITS`], for a gate's before/after delta. +pub fn inter_sb128_none_hits() -> usize { + INTER_SB128_NONE_HITS.with(std::cell::Cell::get) +} + thread_local! { static INTER_SB_NONE_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; @@ -11460,6 +11471,19 @@ fn read_block_tx_size( skip: bool, ) -> Result<(usize, Option>)> { if !TX_SELECT_INTER.with(std::cell::Cell::get) { + // lane-sb128c r1: `max_txsize_rect_lookup[BLOCK_128X128]` is TX_64X64, + // so a 128x128 inter block is FOUR luma units even with `tx_mode == + // TX_MODE_LARGEST` -- the same leaf shape the var-tx tree hands back. + if is_inter && side > 64 { + let step = 64 / MI; + let mut leaves = Vec::new(); + for row in (0..side / MI).step_by(step) { + for col in (0..side / MI).step_by(step) { + leaves.push((row, col, 64)); + } + } + return Ok((64, Some(leaves))); + } return Ok((side, None)); } let side_mi = side / MI; @@ -11487,7 +11511,7 @@ fn read_block_tx_size( } } let single = leaves.len() == 1 && leaves[0].2 == side; - if !single && leaves.iter().any(|leaf| leaf.2 > 32) { + if !single && leaves.iter().any(|leaf| leaf.2 > 64) { // Only a block wider than a superblock's own 64x64 max transform // reaches here; this crate has no 64-point *inter* coefficient // table set ([`inter_txbset_for`] stops at 32). @@ -11960,6 +11984,12 @@ fn read_inter_luma8( /// coefficient tables from -- the inter counterpart of [`txbset_for`]. fn inter_txbset_for(tx_px: usize, reduced_tx_set: bool) -> TxbSet { match tx_px { + // lane-sb128c r1: a 128x128 inter block's own luma unit + // (`max_txsize_rect_lookup[BLOCK_128X128] == TX_64X64`). + // `av1_get_ext_tx_set_type` is `DCT_ONLY` at `tx_size_sqr_up == + // TX_64X64`, so no `tx_type` symbol is coded and the intra/inter sets + // coincide -- exactly the set the whole-64x64 inter block already uses. + 64 => TxbSet::Luma64, 32 => TxbSet::Luma32Inter, 16 if reduced_tx_set => TxbSet::Luma16Inter, 16 => TxbSet::Luma16InterSet1, @@ -15109,7 +15139,13 @@ fn read_inter_plane( let skip_ctx = if plane_idx == 0 { luma_skip_ctx.unwrap_or(0) } else { - usize::from(around.0) + usize::from(around.1) + // lane-sb128c r1: on a CHROMA plane this same parameter carries + // `get_txb_ctx`'s own offset instead -- `combine_entropy_contexts(..)` + // is +7 normally and +10 when the plane block is LARGER than the + // transform (a 128x128 block's 64x64 uv plane block with TX_32X32 + // units, AV1's only such case), and the `txb_skip_chroma_32` table + // carries the offset-10 rows at +3 (lane-sb128b r3). + usize::from(around.0) + usize::from(around.1) + luma_skip_ctx.unwrap_or(0) }; let mut coding = cdfs.txb(set, tx_mode); let default_tx_type = match inherited_luma_tx_type { @@ -15777,8 +15813,13 @@ fn obmc_blend( if matches!((write_w, write_h), (16, 8) | (8, 16)) { OBMC_RECT_LEAF_HITS.with(|c| c.set(c.get() + 1)); } - let overlap_above = write_h / 2; - let overlap_left = write_w / 2; + // lane-sb128c r1: libaom caps the overlap strip at a 64x64 block's own + // half (`reconinter.c` 860/899: `AOMMIN(block_size_high[bsize], + // block_size_high[BLOCK_64X64]) >> 1`, and the `block_size_wide` mirror) -- + // inert below 128, where a 128x128 block would otherwise blend a 64-row + // strip `obmc_mask` has no table for. + let overlap_above = write_h.min(64) / 2; + let overlap_left = write_w.min(64) / 2; // lane-inter8 r1 / lane-scaledref r1: `av1_skip_u4x4_pred_in_obmc` // (`reconinter.c` 820, `DISABLE_CHROMA_U8X8_OBMC == 0` -- "one-sided // obmc") returns `dir == 0` when the chroma plane's own block is @@ -16346,6 +16387,16 @@ fn decode_inter_block( let (above_inter, left_inter) = (neighbours.above_inter[cmi], neighbours.left_inter[rmi]); let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; + // lane-sb128c r1: this round wires the INTER half of a 128x128 block (four + // TX_64X64 luma units and four TX_32X32 chroma units interleaved per mu + // chunk). An INTRA block at that size inside an inter frame takes the + // intra tail below, which still codes one whole-block chroma unit and one + // `read_tx_size` at 128 -- refuse by name instead of mis-decoding it. + if side > 64 && !is_inter { + return Err(unsupported( + "an INTRA-coded 128x128 block inside an inter frame (only the inter half of a 128x128 root is decoded here)", + )); + } if std::env::var_os("EC_TRACE_MODE").is_some() { eprintln!( "EC_MODE mi_row={} mi_col={} rng={}", @@ -17246,6 +17297,11 @@ 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. + let mut u_units = vec![0i32; chroma_side * chroma_side]; + let mut v_units = vec![0i32; chroma_side * chroma_side]; if let Some(leaves) = vartx_leaves.clone() { // spec 5.11.17's transform tree, leaf by leaf in the order // `read_var_tx_size` coded it: each unit reads its own @@ -17262,7 +17318,7 @@ fn decode_inter_block( let start = (row * MI + rr) * side + col * MI; tu_pred.extend_from_slice(&pred_y[start..start + tx_px]); } - let scan = default_scan(tx_px); + let scan = default_scan(tx_px.min(32)); let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI); let (tu_grid, tu_tx_type) = read_inter_plane( dec, @@ -17285,6 +17341,79 @@ fn decode_inter_block( first_tx_type = tu_tx_type; } neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid); + // lane-sb128c r1: libaom's `decode_token_recon_block` + // walks 64x64 "mu" chunks (`mu_blocks_wide/high = + // mi_size_wide[BLOCK_64X64]`) and codes EVERY PLANE of + // a chunk before the next one, so a 128x128 block + // interleaves Y,U,V per quadrant -- the same order the + // intra 128 path reads (lane-sb128b r3, measured + // against aomdec's `EC_TRACE_COEFF`). Below 128 a block + // is a single chunk and this never fires. + if side > 64 { + let chunk = (row / 16, col / 16); + let done = idx + 1 == leaves.len() + || (leaves[idx + 1].0 / 16, leaves[idx + 1].1 / 16) != chunk; + if done { + 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. + 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 cu_scan = default_scan(cu_tx); + for plane_idx in 1..3 { + let (src, buf) = if plane_idx == 1 { + (&pred_u, &mut *u) + } else { + (&pred_v, &mut *v) + }; + let mut cu_pred = Vec::with_capacity(cu_tx * cu_tx); + for rr in 0..cu_tx { + let start = + (cr * cu_tx + rr) * chroma_side + cc * cu_tx; + cu_pred.extend_from_slice(&src[start..start + 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), + )? + .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, + ); + CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); + let dst = if plane_idx == 1 { + &mut u_units + } else { + &mut v_units + }; + 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]); + } + } + } + } } // `av1_get_tx_type`'s chroma lookup scales the chroma // position back to luma, so an inter block's chroma @@ -17378,6 +17507,10 @@ fn decode_inter_block( uh, chroma_side, ); + } else if side > 64 { + // Already read inside the mu-chunk loop above. + u_grid = std::mem::take(&mut u_units); + v_grid = std::mem::take(&mut v_units); } else { u_grid = read_inter_plane( dec, @@ -18224,6 +18357,11 @@ 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. + let mut u_units = vec![0i32; chroma_side * chroma_side]; + let mut v_units = vec![0i32; chroma_side * chroma_side]; if let Some(leaves) = vartx_leaves.clone() { // spec 5.11.17's transform tree, leaf by leaf in the order // `read_var_tx_size` coded it: each unit reads its own @@ -18240,7 +18378,7 @@ fn decode_inter_block( let start = (row * MI + rr) * side + col * MI; tu_pred.extend_from_slice(&pred_y[start..start + tx_px]); } - let scan = default_scan(tx_px); + let scan = default_scan(tx_px.min(32)); let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI); let (tu_grid, tu_tx_type) = read_inter_plane( dec, @@ -18263,6 +18401,79 @@ fn decode_inter_block( first_tx_type = tu_tx_type; } neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid); + // lane-sb128c r1: libaom's `decode_token_recon_block` + // walks 64x64 "mu" chunks (`mu_blocks_wide/high = + // mi_size_wide[BLOCK_64X64]`) and codes EVERY PLANE of + // a chunk before the next one, so a 128x128 block + // interleaves Y,U,V per quadrant -- the same order the + // intra 128 path reads (lane-sb128b r3, measured + // against aomdec's `EC_TRACE_COEFF`). Below 128 a block + // is a single chunk and this never fires. + if side > 64 { + let chunk = (row / 16, col / 16); + let done = idx + 1 == leaves.len() + || (leaves[idx + 1].0 / 16, leaves[idx + 1].1 / 16) != chunk; + if done { + 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. + 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 cu_scan = default_scan(cu_tx); + for plane_idx in 1..3 { + let (src, buf) = if plane_idx == 1 { + (&pred_u, &mut *u) + } else { + (&pred_v, &mut *v) + }; + let mut cu_pred = Vec::with_capacity(cu_tx * cu_tx); + for rr in 0..cu_tx { + let start = + (cr * cu_tx + rr) * chroma_side + cc * cu_tx; + cu_pred.extend_from_slice(&src[start..start + 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), + )? + .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, + ); + CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); + let dst = if plane_idx == 1 { + &mut u_units + } else { + &mut v_units + }; + 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]); + } + } + } + } } // `av1_get_tx_type`'s chroma lookup scales the chroma // position back to luma, so an inter block's chroma @@ -18356,6 +18567,10 @@ fn decode_inter_block( uh, chroma_side, ); + } else if side > 64 { + // Already read inside the mu-chunk loop above. + u_grid = std::mem::take(&mut u_units); + v_grid = std::mem::take(&mut v_units); } else { u_grid = read_inter_plane( dec, @@ -20816,10 +21031,21 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // loop does; the 64-level body below is unchanged, `read_cdef`'s // per-64x64-quadrant reset (`CDEF_TRANSMITTED`) already matches libaom's // `cdef_idx[(mi_row & 16) >> 4 * 2 + (mi_col & 16) >> 4]` slot per quadrant. + // lane-sb128c r1: set when the 128 root resolved to `PARTITION_NONE` -- its + // one 128x128 inter block covers all four 64x64 quadrants, so the remaining + // three items of this superblock carry no syntax at all (same skip the + // key-frame tile loop runs). + let mut sb128_none = false; for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) { if row_start { neighbours.start_row(); } + if sb_start { + sb128_none = false; + } + if sb128_none { + continue; + } { if sb128 && sb_start { if read_sb128_root( @@ -20833,14 +21059,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( sb_c, mi_cols, mi_rows, - )? != PARTITION_SPLIT + )? == PARTITION_NONE { - // lane-sb128b r1 decodes a `PARTITION_NONE` 128 root on - // KEY frames only; an inter 128x128 leaf needs whole-block - // MC, OBMC and compound at a size this path has never run. - return Err(unsupported( - "a 128x128 superblock PARTITION_NONE root on an inter frame (only the key-frame path codes a whole 128x128 block)", - )); + // One 128x128 inter block. Its luma transform is + // `max_txsize_rect_lookup[BLOCK_128X128]` = TX_64X64 (four + // units, read as var-tx leaves), its uv plane block is + // 64x64 with TX_32X32 units (`av1_get_max_uv_txsize`), and + // `size_group_lookup[BLOCK_128X128]` is 3, same as 64x64. + sb128_none = true; + CDEF_TRANSMITTED.with(|c| c.set(false)); } } if !sb128 { @@ -20915,6 +21142,33 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( )? }; } + if sb128_none { + INTER_SB128_NONE_HITS.with(|c| c.set(c.get() + 1)); + let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); + inter_piece!( + at128, SB * 2, + TxbSet::Luma64, TxbSet::Luma64, TxbSet::Chroma32, TX32, TX32, + &scan32, &scan32, 3, SB * 2, SB * 2 + ); + // libaom writes one `cdef_strength` into the block's own + // `MB_MODE_INFO`, which all four 64x64 CDEF units point at + // (mirrors the key-frame 128 NONE block). + let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); + CDEF_IDX_GRID.with(|g| { + let mut g = g.borrow_mut(); + let cols = CDEF_SB_COLS.with(|c| c.get()); + if cols > 0 && q_r * cols + q_c < g.len() { + let idx = g[q_r * cols + q_c]; + for (dr, dc) in [(0, 1), (1, 0), (1, 1)] { + let i = (q_r + dr) * cols + q_c + dc; + if q_c + dc < cols && i < g.len() { + g[i] = idx; + } + } + } + }); + continue; + } let sb_ctx = neighbours.partition_ctx(sb_at, SB); let (has_cols, has_rows) = ( sb_c * SB_MI + SB_MI / 2 < mi_cols, diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 4ab1f2c6..b6f36803 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -43,7 +43,7 @@ const REFUSALS: &[&str] = &[ "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 HORZ/VERT or AB partition (only SPLIT and NONE are decoded at the 128 root)", - "a 128x128 superblock PARTITION_NONE root on an inter frame (only the key-frame path codes a whole 128x128 block)", + "an INTRA-coded 128x128 block inside an inter frame (only the inter half of a 128x128 root is decoded here)", "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)", "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)", "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 15ad6113..85155cd0 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -18366,6 +18366,170 @@ mod tests { } } + /// lane-sb128c r1: an INTER frame whose 128x128 superblock root really + /// resolves `PARTITION_NONE` -- one whole 128x128 inter block, the shape + /// ReelC's first inter frame stops this decoder on. r1 wired it: four + /// TX_64X64 luma units (`max_txsize_rect_lookup[BLOCK_128X128]`), four + /// TX_32X32 chroma units (`av1_get_max_uv_txsize`), interleaved Y,U,V per + /// 64x64 "mu" chunk (libaom `decode_token_recon_block`) with the chroma + /// `txb_skip_ctx` offset-10 rows, and OBMC's overlap capped at a 64x64 + /// block's half (`reconinter.c` 860/899). + /// + /// `--max-partition-size=128` is what lets the root be NONE at all (the + /// sibling gate above pins 64, so its roots always SPLIT). Every arm hard + /// asserts its own `inter_sb128_none_hits` delta, so a recipe that stops + /// choosing the shape fails instead of passing vacuously; every decode + /// order frame is compared by [`decode_all_frames_vs_oracle`], which + /// panics on a refusal or any differing byte. Arms: 8-bit and 10-bit (his + /// films are 10-bit) with `tx-size-search=0` (TX_MODE_LARGEST, the block's + /// four TX_64X64 units come straight from `max_txsize_rect_lookup`) and an + /// 8-bit `tx-size-search=1` arm (the var-tx tree at 128). + #[test] + // lane-sb128c r1 leaves this gate RED: the recipe really fires the shape + // (`partition_w128 value=0` four times, traced), the key frame alone + // decodes, but the 8-frame stream stops on "a split intra strip whose + // transform unit is 32x64" -- an intra rect strip aomenc cannot have coded + // with `--enable-rect-partitions=0`, so our own 128 inter block desyncs + // first (class refusal-from-own-desync). r2 owns the range ladder. + #[ignore = "lane-sb128c r1: the 128 inter NONE block still desyncs; see lanes/sb128c-r1.report.md"] + fn a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact() { + const NAME: &str = "a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() || !have_aomenc() { + eprintln!("SKIP {NAME}: no ffmpeg/aomenc/aomdec"); + return; + } + let (width, height) = (256usize, 256usize); + for (ten_bit, tx_search, seed) in [(false, false, 61u32), (true, false, 61), (false, true, 62)] { + let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" }; + let y4m = Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + &format!( + "{},noise=all_seed={seed}:alls=6:allf=t", + gradients_source(seed, width, height, "duration=0.32:rate=25") + ), + "-pix_fmt", + pix, + "-strict", + "-1", + "-t", + "0.32", + "-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-level=62", + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=128", + "--max-partition-size=128", + "--min-partition-size=32", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-palette=0", + "--enable-intrabc=0", + "--deltaq-mode=0", + "--limit=8", + ]; + // Spelled ONCE per invocation (a repeated `--enable-*` keeps its + // LAST occurrence, measured 2026-09-02). + args.push(if tx_search { + "--enable-tx-size-search=1" + } else { + "--enable-tx-size-search=0" + }); + 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 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, if ten_bit { 10 } else { 8 })), + "{NAME}: the encoder did not write a 128x128-superblock sequence header at \ + the requested bit depth -- the flag 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, + &format!("sb128c-inter-none-{}-{}", if ten_bit { 10 } else { 8 }, tx_search), + ); + let (none128, chroma_units) = ( + crate::decode::inter_sb128_none_hits() - before.0, + crate::decode::chroma_split_tx_hits() - before.1, + ); + assert!( + frames >= 6, + "{NAME} ({pix} tx_search={tx_search}): only {frames} decode-order frames" + ); + assert!( + none128 >= 1, + "{NAME} ({pix} tx_search={tx_search}): no 128x128 PARTITION_NONE root on an \ + inter frame -- the recipe stopped exercising the shape this gate names" + ); + eprintln!( + "{NAME} ({pix} tx_search={tx_search}): {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/sb128c-r1.report.md b/lanes/sb128c-r1.report.md new file mode 100644 index 00000000..26345d8d --- /dev/null +++ b/lanes/sb128c-r1.report.md @@ -0,0 +1,101 @@ +# lane-sb128c r1 — the 128x128 INTER block is wired (ReelC advances one refusal), its gate is RED + +Branch `lane-sb128c` (worktree `edith_codecs-sb128c`), base `e8e64a6` (= lane-sb128b r3, contains main `18bf7dc`). +VERDICT: **RED** — the code lands and ReelC moves past its old stop, but no pixel-exact gate proves it yet. + +## MEASURED first (never assumed) + +`ffmpeg -t 2 -i ReelC... -c:v copy -an -f obu` -> `$HOME/.cache/sb128c-work/reelc2s.obu` (1428 bytes; the +film's first 2 s are near-black, that size is real), `decode_probe`: + +- BEFORE (base e8e64a6): `REFUSED: unsupported: AV1 tile (a 128x128 superblock PARTITION_NONE root on an + inter frame (only the key-frame path codes a whole 128x128 block))`, after the key frame decoded. + `SEQ: use_128x128_superblock=true bit_depth=10 max_frame=1920x792`, 72 frame headers, 1 tile. +- AFTER this round: `REFUSED: ... (a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are + decoded at the 128 root))` — the next 128-level refusal in line. +- Mid-film (`-ss 600 -t 2`, `reelc60.obu`, 1.58 MB): stops on another lane's gap, + `an intra-coded 1:4 (or other non-2:1) rect strip on the inter block path`. + +EVIDENCE: `$HOME/.cache/sb128c-work/{reelc2s.obu,reelc60.obu}` | `decode_probe` under `systemd-run --scope -p MemoryMax=6G`, before and after the change | **stop string moved from "PARTITION_NONE root on an inter frame" to "HORZ/VERT or AB partition"** + +## Every remaining 128 refusal (grep of decode.rs + refusal_inventory.rs), after this round + +1. `a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are decoded at the 128 root)` — `decode.rs` `read_sb128_root`. **ReelC's new stop.** +2. `intrabc under a 128x128 superblock (...)` — key-frame path, `allow_intrabc` only. +3. `an INTRA-coded 128x128 block inside an inter frame (...)` — NEW this round, deliberately narrow. +(The old `a 128x128 superblock PARTITION_NONE root on an inter frame` is gone from both files.) + +## What changed + +- `decode.rs` `read_sb128_root` call site in the inter tile loop (~20826): `PARTITION_NONE` now sets + `sb128_none` and decodes one 128x128 block through the existing `inter_piece!` macro + (`TxbSet::Luma64/Luma64/Chroma32`, `TX32`, `scan32`, size group 3 — `size_group_lookup[BLOCK_128X128] == 3`), + then replicates the block's `cdef_idx` across its four 64x64 units and skips the superblock's other three + quadrant items (same skip the key-frame loop runs). +- `decode.rs` `inter_txbset_for`: `64 => TxbSet::Luma64` — `av1_get_ext_tx_set_type` is `DCT_ONLY` at + `tx_size_sqr_up == TX_64X64`, so no `tx_type` symbol is coded and the intra/inter sets coincide. +- `decode.rs` `read_block_tx_size`: with `tx_mode == TX_MODE_LARGEST` a 128x128 inter block is still FOUR + TX_64X64 units (`max_txsize_rect_lookup[BLOCK_128X128]`), returned as leaves; the var-tx leaf refusal + moves from `> 32` to `> 64`. +- `decode.rs` `decode_inter_block` (both identical coefficient regions, compound and single-ref): the leaf + loop's scan is `default_scan(tx_px.min(32))` (a 64-point transform codes only its 32x32 corner), and at + `side > 64` each 64x64 mu chunk's U and V units are read INSIDE the leaf loop right after that chunk's + luma leaves (libaom `decode_token_recon_block` codes every plane of a chunk before the next chunk — + sb128b r3 measured this against aomdec), recorded per unit, and collected for the block-level write-back. +- `decode.rs` `read_inter_plane`: on a chroma plane the `luma_skip_ctx` parameter now carries + `get_txb_ctx`'s offset (+3 selects `txb_skip_chroma_32`'s offset-10 rows, the uv-plane-block-larger-than- + the-transform case). All existing chroma callers pass `None` — inert. +- `decode.rs` OBMC: `overlap_above/left` capped at `min(write_h|write_w, 64) / 2`, libaom + `reconinter.c:860` / `:899` (`AOMMIN(block_size_high[bsize], block_size_high[BLOCK_64X64]) >> 1`). + Without it a 128 block asked `obmc_mask(64)`, which panicked `unreachable!` — the first thing ReelC hit. +- `stream.rs`: new gate `a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact` (currently `#[ignore]`d, + see below). `refusal_inventory.rs`: one line replaced. + +## CHARTER PREMISE CORRECTED (cited) + +The charter states `max_neighbor_obmc[...] = {0,1,2,3,4,8}` so "128 blocks get 8 neighbours". The oracle +source says otherwise: `$HOME/.cache/aom-oracle/src/av1/common/blockd.h:1466` +`static const int max_neighbor_obmc[6] = { 0, 1, 2, 3, 4, 4 };`. Our existing `max_nb` (`_ => 4`) is already +right at 128; **no change was made**. What DID need changing is the overlap cap above. + +## The gate, and why it is RED + +`a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact` — real aomenc `--sb-size=128 --cpu-used=0 +--max-partition-size=128 --min-partition-size=32 --cq-level=62 --limit=8`, 256x256 (both dims > 128, so +NONE/HORZ/VERT at 128 are real choices), 3 arms (8-bit tx-size-search=0, 10-bit tx-size-search=0, 8-bit +tx-size-search=1), sequence-header assert on `use_128x128_superblock` + bit depth, hard +`inter_sb128_none_hits >= 1` per arm, every decode-order frame through `decode_all_frames_vs_oracle` +(panics on refusal or any differing byte, so out-of-scope mismatches are structurally 0), flags spelled once. + +It FAILS on arm 1: `sb128c-inter-none-8-false: this decoder refused the stream: unsupported: AV1 tile +(a split intra strip whose transform unit is 32x64 ...)`. + +Triage done this round: +- The recipe genuinely fires the shape: `EC_AV1_TRACE=1 decode_probe g8.obu` shows + `partition_w128 value=0` (PARTITION_NONE) **4 times** and `value=3` (SPLIT) 10 times. +- The KEY frame alone (`--limit=1`, `k1.obu`) decodes: `OK: 1 frames decoded, 256x256`. +- The stream is encoded with `--enable-rect-partitions=0`, so a 64x128/32x64 intra strip cannot be in it: + the 32x64 refusal is OUR desync talking (class `refusal-from-own-desync`) somewhere at or after the first + inter 128 NONE block. +- An INTRA block at 128 inside an inter frame was ruled out as the cause by adding a named refusal for it + (it is not what the stream stops on). + +EVIDENCE: `$HOME/.cache/sb128c-work/{g8.obu,k1.obu}` | aomenc recipe above at `--limit=8` and `--limit=1`, `EC_AV1_TRACE=1 decode_probe` | **4 `partition_w128 value=0` roots; key-frame-only stream OK; 8-frame stream refuses at a 32x64 strip the encoder never coded** + +## Suite + +`$HOME/.cache/sb128c-suite-r1.log` (unit `sb128c-suite-r1-1788325119.service`) — result in the handoff line +of the commit message / see the log; the new gate is `#[ignore]`d so the suite measures the untouched paths. + +## Residue + +- fix-now(r2): the 128 inter NONE desync. Next step is the range ladder (instrumented aomdec + `EC_TRACE_COEFF` vs ours) on `g8.obu`'s FIRST inter frame, first 128 NONE block — compare msac RANGE + element by element, never `tell()`. Prime suspects in order: (1) `read_cdef`'s per-quadrant index/ + `CDEF_TRANSMITTED` for a NONE 128 block on the inter path; (2) `maybe_read_delta_q`/delta_lf granularity + at a 128 root; (3) the mvstack at bw4=bh4=32 (`has_top_right` at 128, tpl sample positions); + (4) my mu-chunk chroma interleave (offset `Some(3)` row choice / per-unit `record_mi_chroma`). +- deferred: 128-level HORZ/VERT/AB on both the key and inter paths (ReelC's new stop) — unblocked by the + NONE block being exact first. +- deferred: `--enable-tx-size-search=1` arm at 128 and a `--tile-columns=1` arm — same blocker. +- accepted: `an INTRA-coded 128x128 block inside an inter frame` stays refused by name.