diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 18e3006a..06c3e511 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -818,7 +818,17 @@ fn maybe_read_delta_lf(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi /// `read_cdef_params` already forces `bits = 0` under `coded_lossless`/ /// `allow_intrabc`, so neither needs a separate check here. Reads once per /// superblock, at the first non-skip block. -fn maybe_read_cdef_idx(dec: &mut SymbolDecoder, mi_r: usize, mi_c: usize, skip: bool, fctx: &crate::decode::FrameCtx) { +fn maybe_read_cdef_idx( + dec: &mut SymbolDecoder, + mi_r: usize, + mi_c: usize, + // The reading BLOCK's own span in 4x4 mode-info units: a block wider or + // taller than one 64x64 CDEF unit is the first non-skip block of EVERY + // unit it covers, so its one literal drives all of them (lane-b128r). + (w_mi, h_mi): (usize, usize), + skip: bool, + fctx: &crate::decode::FrameCtx, +) { let bits = fctx.cdef_bits.with(|c| c.get()); if bits == 0 || skip || fctx.cdef_transmitted.with(|c| c.get()) { return; @@ -829,11 +839,26 @@ fn maybe_read_cdef_idx(dec: &mut SymbolDecoder, mi_r: usize, mi_c: usize, skip: let (sb_r, sb_c) = (mi_r / SB_MI as usize, mi_c / SB_MI as usize); let sb_cols = fctx.cdef_sb_cols.with(|c| c.get()); if sb_cols > 0 { + // lane-b128r: libaom's four CDEF units of a 128 superblock all read + // their strength off the MB_MODE_INFO of the first non-skip block in + // their own unit -- and a block that COVERS several units (the 128 + // root's own 128x128 block, the only one there is) is that block for + // every unit it covers, so one literal drives all four. This grid is + // per 64x64 unit, so the read stamps every unit the block covers; one + // that is smaller than a unit stamps exactly the cell it always did. + let (rows, cols) = ( + (h_mi / SB_MI as usize).max(1), + (w_mi / SB_MI as usize).max(1), + ); fctx.cdef_idx_grid.with(|g| { let mut g = g.borrow_mut(); - let i = sb_r * sb_cols + sb_c; - if i < g.len() { - g[i] = idx; + for dr in 0..rows { + for dc in 0..cols { + let i = (sb_r + dr) * sb_cols + sb_c + dc; + if sb_c + dc < sb_cols && i < g.len() { + g[i] = idx; + } + } } }); } @@ -9066,7 +9091,7 @@ fn read_intra_mode_rect( if !seg_id_pre_skip(fctx) { intra_segment_id(dec, cdfs, mi_r, mi_c, seg_w_mi, seg_h_mi, skip, fctx); } - maybe_read_cdef_idx(dec, mi_r, mi_c, skip, fctx); + maybe_read_cdef_idx(dec, mi_r, mi_c, (bw / MI, bh / MI), skip, fctx); istep!("cdef", 0); // A HORZ/VERT rect strip is never the whole superblock (`bw`/`bh` never // both 64 here -- see this fn's own doc), so `is_whole_sb` is always @@ -13184,7 +13209,7 @@ fn read_intra_mode( } // spec order (see the comment below on `read_intrabc_info`): `skip`, // `segment_id`, `cdef`, `delta_q` -- `cdef` lands right here. - maybe_read_cdef_idx(dec, mi_r, mi_c, skip, fctx); + maybe_read_cdef_idx(dec, mi_r, mi_c, (side / MI, side / MI), skip, fctx); istep!("cdef", 0); // lane-sb128b r1: "this leaf IS the superblock" is `side == sb_size`, not // a hardcoded 64 -- a `PARTITION_NONE` 128x128 root is the whole @@ -15919,7 +15944,7 @@ fn read_intra_mode_sub8( if !seg_id_pre_skip(fctx) { intra_segment_id(dec, cdfs, mi_r, mi_c, seg_w_mi, seg_h_mi, skip, fctx); } - maybe_read_cdef_idx(dec, mi_r, mi_c, skip, fctx); + maybe_read_cdef_idx(dec, mi_r, mi_c, (2, 2), skip, fctx); istep!("cdef", 0); maybe_read_delta_q(dec, cdfs, mi_r, mi_c, false, skip, fctx); maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, false, skip, fctx); @@ -26811,7 +26836,7 @@ fn decode_inter_block( let skip_ctx = usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]); let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; inter_segment_id(dec, cdfs, seg_mi_r, seg_mi_c, seg_w_mi, seg_h_mi, skip, false, fctx); - maybe_read_cdef_idx(dec, rmi, cmi, skip, fctx); + maybe_read_cdef_idx(dec, rmi, cmi, (write_w / MI, write_h / MI), skip, fctx); // lane-inter4 r1: spec 5.11.6's `bSize == sbSize` -- a 64x32/64x16 strip // is NOT the whole superblock, so its `skip` never suppresses the read. // lane-sb128c r7: `sbSize` is 128 under `--sb-size=128`, so the whole-block @@ -30610,7 +30635,7 @@ fn decode_inter_sub8_split4( let skip_ctx = usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]); let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; inter_segment_id(dec, cdfs, rmi, cmi, 1, 1, skip, false, fctx); - maybe_read_cdef_idx(dec, rmi, cmi, skip, fctx); + maybe_read_cdef_idx(dec, rmi, cmi, (2, 2), skip, fctx); maybe_read_delta_q(dec, cdfs, rmi, cmi, false, skip, fctx); maybe_read_delta_lf(dec, cdfs, rmi, cmi, false, skip, fctx); let (has_above, has_left) = ( @@ -31653,7 +31678,7 @@ fn decode_inter_sub8_rect2( usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]); let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; inter_segment_id(dec, cdfs, rmi, cmi, w_mi, h_mi, skip, false, fctx); - maybe_read_cdef_idx(dec, rmi, cmi, skip, fctx); + maybe_read_cdef_idx(dec, rmi, cmi, (2, 2), skip, fctx); maybe_read_delta_q(dec, cdfs, rmi, cmi, false, skip, fctx); maybe_read_delta_lf(dec, cdfs, rmi, cmi, false, skip, fctx); let (has_above, has_left) = ( @@ -32401,7 +32426,7 @@ fn decode_inter_block8( let skip_ctx = usize::from(above_skip) + usize::from(left_skip); let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, skip, false, fctx); - maybe_read_cdef_idx(dec, leaf_mi.0, leaf_mi.1, skip, fctx); + maybe_read_cdef_idx(dec, leaf_mi.0, leaf_mi.1, (2, 2), skip, fctx); // Always a `BLOCK_8X8` leaf here, never the whole superblock. maybe_read_delta_q(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip, fctx); maybe_read_delta_lf(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip, fctx); diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 0b03c6d4..26d296ac 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -733,6 +733,97 @@ fn b128_root() -> bool { *ENV } +/// lane-b128r: whether the 128 root prices a REAL residual as well as the +/// skip arm -- four TX_64X64 luma units interleaved with a TX_32X32 chroma +/// pair per 64x64 mu chunk, var-tx depth 0 (the shape +/// [`crate::tile::write_inter_block_128`] codes and `decode_inter_block` +/// reads). Written, witnessed and byte-exact through both decoders, and +/// **off by default** (`EC_AV1_B128RES=1` turns it on) for two measured +/// reasons: +/// +/// * it is INERT on content: over the native 12-frame gate the RD takes it +/// 0-2 times per frame against ~90 whole 128 roots, so the BD effect is +/// inside the noise either way; +/// * with it on, `bd_rate_screen_native`'s bars 2160p row q=90 frame 11 +/// reads 8 luma samples (rows 126..127, cols 1611..1616 -- the two rows +/// above a 128-superblock horizontal edge) where ffmpeg and this +/// encoder's own reconstruction disagree. The residual arm's own witness +/// clip is byte-exact through ffmpeg over 420 forced blocks at 1280x768, +/// so the open half is a FILTER-stage interaction (deblock/CDEF at a 128 +/// block's own edge), not the coefficient path. +/// +/// An inert candidate does not buy a live filter mismatch, so the default +/// stays off until that is root-caused; the knob is the gate for it. +fn b128_residual() -> bool { + static ENV: std::sync::LazyLock> = std::sync::LazyLock::new(|| { + crate::envflags::var("EC_AV1_B128RES").ok().map(|v| v != "0") + }); + (ENV.unwrap_or(false) || FORCE_B128_RESIDUAL.load(std::sync::atomic::Ordering::Relaxed)) + && b128_root() +} + +/// lane-b128r: whether the 128 root offers the COMPOUND candidates the 64 +/// root already does (`NEAREST_NEARESTMV`, `GLOBAL_GLOBALMV`, +/// `NEW_NEARESTMV` over the LAST+GOLDEN / LAST+ALTREF pairs), at the block's +/// own 32x32-mi window. `EC_AV1_B128COMP=0` turns it off, which is this +/// arm's attribution control; the writer has always had the path +/// (`write_inter_block_128` calls `write_compound_block` for a block that +/// names a second reference). +fn b128_compound() -> bool { + static ENV: std::sync::LazyLock> = std::sync::LazyLock::new(|| { + crate::envflags::var("EC_AV1_B128COMP").ok().map(|v| v != "0") + }); + ENV.unwrap_or(true) && b128_root() +} + +/// How many 128 roots came out COMPOUND since the last +/// [`take_b128_compound_hits`] (class `gate-blind-to-feature`). +static B128_COMPOUND_HITS: std::sync::atomic::AtomicUsize = + std::sync::atomic::AtomicUsize::new(0); + +/// The compound-128 count since the last call, and zero it. +pub fn take_b128_compound_hits() -> usize { + B128_COMPOUND_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) +} + +/// Test-only: take the 128 root's residual arm whatever it costs, so a +/// witness clip codes the shape rather than waiting for content on which the +/// RD picks it (the same role [`force_sb128`] plays for the superblock size). +/// Never read outside `#[cfg(test)]` builds. +static FORCE_B128_RESIDUAL: std::sync::atomic::AtomicBool = + std::sync::atomic::AtomicBool::new(false); + +/// Test-only twin of [`FORCE_B128_RESIDUAL`] for the PARTITION decision: take +/// the 128 root whenever it produced a candidate at all, whatever its four +/// cells cost, so a witness codes the block it is about rather than waiting +/// for content on which the root also wins its own comparison. +static FORCE_B128_ROOT: std::sync::atomic::AtomicBool = + std::sync::atomic::AtomicBool::new(false); + +/// Arms [`FORCE_B128_RESIDUAL`] -- and with it [`FORCE_B128_ROOT`], since a +/// forced residual block only reaches the writer if its root is taken. +#[cfg(test)] +pub(crate) fn force_b128_residual(on: bool) { + FORCE_B128_RESIDUAL.store(on, std::sync::atomic::Ordering::Relaxed); + force_b128_root(on); +} + +/// Arms [`FORCE_B128_ROOT`] for the rest of the process. +#[cfg(test)] +pub(crate) fn force_b128_root(on: bool) { + FORCE_B128_ROOT.store(on, std::sync::atomic::Ordering::Relaxed); +} + +/// How many 128 roots came out cheaper WITH a residual than skipped, since +/// the last [`take_b128_residual_hits`] (class `gate-blind-to-feature`). +static B128_RESIDUAL_HITS: std::sync::atomic::AtomicUsize = + std::sync::atomic::AtomicUsize::new(0); + +/// The 128-residual count since the last call, and zero it. +pub fn take_b128_residual_hits() -> usize { + B128_RESIDUAL_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) +} + /// How many 128x128 `PARTITION_NONE` roots the search took since the last /// [`take_b128_none_hits`] (class `gate-blind-to-feature`): a flat BD result /// is only attributable once the fire count is known. @@ -9393,6 +9484,11 @@ fn search_root_128( tpl_cells_x: usize, base_q_idx: u8, reference: &Picture, + // The `LAST` + extra-reference pairs at THIS ROOT's own 32x32-mi window, + // built by the caller off the same grid the tile writer rebuilds its + // stack from (empty unless the frame carries `reference_select` and + // [`b128_compound`] is on). + compound: &[(i8, &Picture, crate::mvstack::CompoundMvStack)], fctx: &crate::decode::FrameCtx, ) -> Option<(f64, f64, BlockCoeffs, [(Vec, Vec); 3])> { const SIDE: usize = SUPERBLOCK * 2; @@ -9428,7 +9524,16 @@ fn search_root_128( .map(|&(dr, dc)| cell_lambda(root_r + dr, root_c + dc)) .sum::() / 4.0; - let root_search = Search { lambda, ..search }; + // The qindex this root is really quantized at: the delta_q unit is the + // 128 superblock, so the root's own top-left cell is the one coded + // (lane-b128m), and the residual arm below has to quantize at exactly it. + let root_search = Search { + lambda, + ..match sb_q { + Some(q) => sb_q_search(q, sb_cols, base_q_idx, (root_r, root_c), search), + None => search, + } + }; let stack = find_mv_stack( grid, mi_row, @@ -9449,10 +9554,90 @@ fn search_root_128( false, reference, &stack, - &[], + compound, fctx, ); - let (cost, block) = found?; + let (mut cost, mut block) = found?; + if block.inter.is_some_and(|i| i.ref1.is_some()) { + B128_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + } + // lane-b128r: the same prediction with a REAL residual, priced against + // the skip arm the search just committed to the planes (which IS the + // winner's prediction, sample for sample). The block's residual is four + // TX_64X64 luma units, one per 64x64 mu chunk, each interleaved with its + // own TX_32X32 chroma pair -- so it is coded here as twelve trials at + // sides the forward network already reaches, never as one 128-point + // transform. Var-tx depth 0 only: the four units ARE the tree's leaves. + // + // The four `txfm_partition` symbols the writer codes for them are not + // priced, exactly as the 64 root does not price its own (their contexts + // are only known at write time); at four symbols a root this is under a + // bit against residuals of hundreds. + if b128_residual() && block.skip { + // Every unit's coded level grid is 32x32 (a 64-point transform codes + // only its top-left corner), packed per plane into one 64-wide grid + // with chunk (cr, cc) at (cr * 32, cc * 32) -- the layout + // `write_inter_block_128` slices back out in the same chunk order. + let mut packed = [vec![0i32; 64 * 64], vec![0i32; 64 * 64], vec![0i32; 64 * 64]]; + let mut chunks: Vec<((usize, usize), [Trial; 3])> = Vec::new(); + let (mut sse_skip, mut sse_res, mut coeff_bits) = (0.0f64, 0.0f64, 0.0f64); + for (cr, cc) in [(0usize, 0usize), (0, 1), (1, 0), (1, 1)] { + let (px, py) = (x128 + cc * SUPERBLOCK, y128 + cr * SUPERBLOCK); + let (cx, cy) = (px / 2, py / 2); + let half = SUPERBLOCK / 2; + let pred_y = rows_of(&luma.reconstruction, luma.width, px, py, SUPERBLOCK); + let pred_u = rows_of(&chroma[0].reconstruction, chroma[0].width, cx, cy, half); + let pred_v = rows_of(&chroma[1].reconstruction, chroma[1].width, cx, cy, half); + sse_skip += luma.block_sse(px, py, SUPERBLOCK, &pred_y) + + chroma[0].block_sse(cx, cy, half, &pred_u) + + chroma[1].block_sse(cx, cy, half, &pred_v); + let trials = [ + luma.code_from_prediction( + px, py, SUPERBLOCK, &pred_y, false, root_search.base_q_idx, + root_search.deadzone, TxbSet::Luma64, + ), + chroma[0].code_from_prediction( + cx, cy, half, &pred_u, false, root_search.base_q_idx, + root_search.deadzone, TxbSet::Chroma32, + ), + chroma[1].code_from_prediction( + cx, cy, half, &pred_v, false, root_search.base_q_idx, + root_search.deadzone, TxbSet::Chroma32, + ), + ]; + for (plane, trial) in trials.iter().enumerate() { + sse_res += trial.sse; + coeff_bits += trial.bits; + for row in 0..32 { + packed[plane][(cr * 32 + row) * 64 + cc * 32..][..32] + .copy_from_slice(&trial.levels[row * 32..][..32]); + } + } + chunks.push(((cr, cc), trials)); + } + // `cost` is the skip arm's own `sse + lambda * syntax`; the residual + // arm pays the same syntax with `skip` coded 0 instead of 1, plus its + // coefficients. + let unskip = skip_bits_at(&stack, false) - skip_bits_at(&stack, true); + let res_cost = cost - sse_skip + sse_res + lambda * (unskip + coeff_bits); + if res_cost < cost || FORCE_B128_RESIDUAL.load(std::sync::atomic::Ordering::Relaxed) { + B128_RESIDUAL_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + for ((cr, cc), trials) in &chunks { + let (px, py) = (x128 + cc * SUPERBLOCK, y128 + cr * SUPERBLOCK); + let half = SUPERBLOCK / 2; + luma.commit(px, py, SUPERBLOCK, &trials[0]); + chroma[0].commit(px / 2, py / 2, half, &trials[1]); + chroma[1].commit(px / 2, py / 2, half, &trials[2]); + } + cost = res_cost; + block.skip = false; + block.tx_depth = 0; + block.luma_tx_types = Vec::new(); + block.luma = coeffs(&packed[0], 64); + block.u = coeffs(&packed[1], 64); + block.v = coeffs(&packed[2], 64); + } + } let after = snapshot(luma, chroma, (x128, y128), SIDE); restore(luma, chroma, (x128, y128), SIDE, &base); Some(( @@ -12125,6 +12310,40 @@ pub(crate) fn encode_inter_frame( // 128x128 candidate is weighed. let mark128 = blocks.len(); let mut root_cost = 0.0f64; + // The 128 root's own compound pairs, at its 32x32-mi window (the 64 + // root builds the same list one size down, per superblock). + let root_compound: Vec<(i8, &Picture, crate::mvstack::CompoundMvStack)> = + if header.reference_select && b128_compound() && !screen && sb128_search { + [ + (crate::mvstack::GOLDEN_FRAME, golden), + (crate::mvstack::ALTREF_FRAME, altref), + ] + .into_iter() + .filter_map(|(r, pic)| { + pic.map(|p| { + ( + r, + p, + crate::mvstack::find_mv_stack_compound( + &grid, + root_r * 16, + root_c * 16, + 32, + 32, + (crate::mvstack::LAST_FRAME, r), + mi_cols, + mi_rows, + grid.sign_bias_table(), + &[(0, 0); 7], + None, + ), + ) + }) + }) + .collect() + } else { + Vec::new() + }; let root128 = (sb128_search && b128_root() && cells.len() == 4) .then(|| search_root_128( &mut luma, @@ -12140,6 +12359,7 @@ pub(crate) fn encode_inter_frame( tpl_cells_x, base_q_idx, reference, + &root_compound, fctx, )) .flatten(); @@ -12722,7 +12942,10 @@ pub(crate) fn encode_inter_frame( // cost, the same weighing the 64 root does one size down. Both sides // carry their own partition symbol, so the comparison is complete. if let Some((cost128, lambda128, block, after)) = root128 - && cost128 < root_cost + lambda128 * crate::tile::partition_bits(128, true) + && (cost128 < root_cost + lambda128 * crate::tile::partition_bits(128, true) + // The witness knob takes the root whatever it costs, so the + // forced residual block really reaches the writer. + || FORCE_B128_ROOT.load(std::sync::atomic::Ordering::Relaxed)) { B128_NONE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); let (x128, y128) = (root_c * SUPERBLOCK, root_r * SUPERBLOCK); @@ -12772,8 +12995,24 @@ pub(crate) fn encode_inter_frame( .iter() .filter(|q| !matches!(q, Quadrant::Covered)) .count(); + // lane-b128r: of those roots, how many code a REAL residual rather + // than the skip-only block lane-b128 shipped -- the fire count this + // arm's own gate row is read against. + let residual = blocks + .iter() + .filter(|q| matches!(q, Quadrant::Whole128(b) if !b.skip)) + .count(); + // lane-b128r: and how many named a second reference (the compound + // arm at the 128 root). + let compound = blocks + .iter() + .filter(|q| { + matches!(q, Quadrant::Whole128(b) if b.inter.is_some_and(|i| i.ref1.is_some())) + }) + .count(); eprintln!( - "B128 census: inter frame, {whole} whole 128x128 roots, {roots} coded blocks ({:.1}% of the frame's area at 128)", + "B128 census: inter frame, {whole} whole 128x128 roots ({residual} with a residual, \ + {compound} compound), {roots} coded blocks ({:.1}% of the frame's area at 128)", 100.0 * (whole * 16) as f64 / blocks.len().max(1) as f64, ); } @@ -16061,6 +16300,149 @@ mod tests { } } + /// lane-b128r: the 128 root's own RESIDUAL arm -- four TX_64X64 luma + /// units interleaved with a TX_32X32 chroma pair per 64x64 mu chunk. The + /// same pan the skip-only witness above uses, with the arm FORCED + /// ([`force_b128_residual`]): on synthetic bars the RD picks the residual + /// about once per frame, which witnesses the shape but not every context + /// it reads, and forcing codes all 420 roots of the clip through it. RED + /// before this lane by construction (`write_inter_block_128` refused + /// every non-skip 128 block, so no such block existed to decode), and RED + /// again on the first draft of the writer, whose neighbour band recorded + /// `skip = true` for a block that carries a residual -- the next root's + /// `skip` symbol then took CDF row 1 where the reader takes row 0. + /// + /// cargo test -p ec-av1 --release --lib -- --ignored \ + /// a_128_root_block_with_a_real_residual --nocapture + #[test] + #[ignore = "sets the process-global superblock size: run it alone"] + fn a_128_root_block_with_a_real_residual_decodes_exact_through_both_decoders() { + let _knobs = crate::speed::knob_write(); + if !have_ffmpeg() { + eprintln!("SKIP: no ffmpeg"); + return; + } + force_sb128(true); + let dir = std::env::temp_dir().join(format!("ec-av1-b128r-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let clip = dir.join("smpte-pan-1280x768.y4m"); + let ok = Command::new("ffmpeg") + .args(["-v", "error", "-y", "-f", "lavfi"]) + .args(["-i", "smptebars=size=1600x768:rate=24"]) + .args(["-vf", "crop=1280:768:'min(n*2,300)':0", "-frames:v", "8"]) + .args(["-pix_fmt", "yuv420p"]) + .arg(&clip) + .status() + .expect("ffmpeg failed to run") + .success(); + assert!(ok, "ffmpeg could not write the synthetic clip"); + let (width, height) = (1280usize, 768usize); + let pictures = + crate::probe::source(clip.to_str().unwrap(), "0", "null", width, height, 8); + let _ = take_b128_residual_hits(); + let _ = crate::tile::take_sb128_residual_hits(); + force_b128_residual(true); + let encoded = encode_sequence(&pictures, 150, 0.5).unwrap(); + let (won, coded) = + (take_b128_residual_hits(), crate::tile::take_sb128_residual_hits()); + eprintln!("128x128 blocks WITH a residual: search won {won}, writer coded {coded}"); + assert!( + coded > 0, + "no 128x128 block carried a residual on this clip, so it cannot witness the arm", + ); + let decoded = crate::stream::decode_stream(&encoded.stream).expect("our decoder"); + assert_eq!(decoded.len(), encoded.frames.len(), "frame count"); + for (i, (frame, dec)) in encoded.frames.iter().zip(&decoded).enumerate() { + let recon = &frame.reconstruction; + for (plane, got, want) in [ + ("luma", &dec.y, &recon.y), + ("U", &dec.u, &recon.u), + ("V", &dec.v, &recon.v), + ] { + let differ = got.iter().zip(want.iter()).filter(|(a, b)| a != b).count(); + assert_eq!( + differ, 0, + "frame {i}: {plane} -- {differ} of {} samples differ from the encoder's \ + own reconstruction", + got.len() + ); + } + } + let ff = ffmpeg_decode_sequence(&encoded.stream, width, height, pictures.len()); + for (i, (frame, dec)) in encoded.frames.iter().zip(&ff).enumerate() { + assert_eq!(dec.y, frame.reconstruction.y, "frame {i}: ffmpeg luma"); + assert_eq!(dec.u, frame.reconstruction.u, "frame {i}: ffmpeg U"); + assert_eq!(dec.v, frame.reconstruction.v, "frame {i}: ffmpeg V"); + } + } + + /// lane-b128r: the COMPOUND arm at the 128 root -- one 128x128 block + /// naming `LAST` plus `GOLDEN`/`ALTREF`, through the same + /// `write_compound_block` chain every smaller compound block takes, at a + /// window it had never been exercised at. RED before this lane: the + /// search passed an empty compound list at the 128 root, so the count was + /// 0 and no such block existed to decode. + /// + /// cargo test -p ec-av1 --release --lib -- --ignored \ + /// a_128_root_compound_block --nocapture + #[test] + #[ignore = "sets the process-global superblock size: run it alone"] + fn a_128_root_compound_block_decodes_exact_through_both_decoders() { + let _knobs = crate::speed::knob_write(); + if !have_ffmpeg() { + eprintln!("SKIP: no ffmpeg"); + return; + } + force_sb128(true); + let dir = std::env::temp_dir().join(format!("ec-av1-b128c-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let clip = dir.join("testsrc2-1280x768.y4m"); + // Moving objects that occlude each other: a pan is coded by one + // reference outright, and a compound pair only pays where the two + // references disagree. + let ok = Command::new("ffmpeg") + .args(["-v", "error", "-y", "-f", "lavfi"]) + .args(["-i", "testsrc2=size=1280x768:rate=24"]) + .args(["-frames:v", "12", "-pix_fmt", "yuv420p"]) + .arg(&clip) + .status() + .expect("ffmpeg failed to run") + .success(); + assert!(ok, "ffmpeg could not write the synthetic clip"); + let (width, height) = (1280usize, 768usize); + let pictures = + crate::probe::source(clip.to_str().unwrap(), "0", "null", width, height, 12); + // The compound candidate wins the 128 block's own search on this pan + // but the root then loses to its four cells, so the root is forced + // (the residual arm is left at its default, off). + force_b128_root(true); + let _ = take_b128_compound_hits(); + let _ = crate::tile::take_sb128_compound_hits(); + let encoded = encode_sequence(&pictures, 150, 0.5).unwrap(); + let (won, coded) = + (take_b128_compound_hits(), crate::tile::take_sb128_compound_hits()); + eprintln!("COMPOUND 128x128 blocks: search won {won}, writer coded {coded}"); + assert!(coded > 0, "no compound 128x128 block was coded on this clip"); + let decoded = crate::stream::decode_stream(&encoded.stream).expect("our decoder"); + assert_eq!(decoded.len(), encoded.frames.len(), "frame count"); + for (i, (frame, dec)) in encoded.frames.iter().zip(&decoded).enumerate() { + for (plane, got, want) in [ + ("luma", &dec.y, &frame.reconstruction.y), + ("U", &dec.u, &frame.reconstruction.u), + ("V", &dec.v, &frame.reconstruction.v), + ] { + let differ = got.iter().zip(want.iter()).filter(|(a, b)| a != b).count(); + assert_eq!(differ, 0, "frame {i}: {plane} -- {differ} samples differ"); + } + } + let ff = ffmpeg_decode_sequence(&encoded.stream, width, height, pictures.len()); + for (i, (frame, dec)) in encoded.frames.iter().zip(&ff).enumerate() { + assert_eq!(dec.y, frame.reconstruction.y, "frame {i}: ffmpeg luma"); + assert_eq!(dec.u, frame.reconstruction.u, "frame {i}: ffmpeg U"); + assert_eq!(dec.v, frame.reconstruction.v, "frame {i}: ffmpeg V"); + } + } + #[test] #[ignore = "sets the process-global superblock size: run it alone"] fn a_128_superblock_clip_whose_drl_index_the_write_time_stack_cannot_carry_decodes_exact() { @@ -17224,6 +17606,32 @@ mod tests { ); for (i, (d, e)) in decoded.iter().zip(&encoded.frames).enumerate() { if let Some((plane, s, got, want)) = first_plane_mismatch(d, &e.reconstruction) { + // TEMPORARY (lane-b128r bisect): the whole mismatch map. + let (l, r) = match plane { + "Y" => (&d.y, &e.reconstruction.y), + "U" => (&d.u, &e.reconstruction.u), + _ => (&d.v, &e.reconstruction.v), + }; + let w = if plane == "Y" { width } else { width / 2 }; + let bad: Vec = l + .iter() + .zip(r.iter()) + .enumerate() + .filter(|(_, (a, b))| a != b) + .map(|(i, _)| i) + .collect(); + let rows: Vec = bad.iter().map(|i| i / w).collect(); + let cols: Vec = bad.iter().map(|i| i % w).collect(); + eprintln!( + "B128R MISMATCH {name} q={q} frame {i} plane {plane}: {} samples, \ + rows {}..{}, cols {}..{}, first 8 {:?}", + bad.len(), + rows.iter().min().copied().unwrap_or(0), + rows.iter().max().copied().unwrap_or(0), + cols.iter().min().copied().unwrap_or(0), + cols.iter().max().copied().unwrap_or(0), + bad.iter().take(8).map(|i| (i / w, i % w)).collect::>(), + ); panic!( "{name} q={q} frame {i} plane {plane} sample {s}: ffmpeg decoded \ {got}, the encoder reconstructed {want}" @@ -17501,7 +17909,12 @@ mod tests { // q=150 and 33194 at q=60. `EC_AV1_SB128=0` restores 8252 / 33053. // Re-taken at the merge of lane-b128m onto main (128 superblocks on // by default, on top of the ARF temporal filter). - let pins: [(u8, usize, u64); 2] = [(150, 8354, 0x1290b8628438c6d4), (60, 33222, 0xc7f92971ab1264c3)]; + // Re-taken on lane-b128r: the 128 root now offers the COMPOUND + // candidates the 64 root already did ([`b128_compound`]), so every + // inter frame that carries `reference_select` codes different blocks + // -- 8354 -> 8364 bytes at q=150 and 33222 -> 33257 at q=60. + // `EC_AV1_B128COMP=0` restores 8354 / 33222 exactly. + let pins: [(u8, usize, u64); 2] = [(150, 8364, 0xcb2ad7936d5127c5), (60, 33257, 0x87db250ba556e5a6)]; let coded: Vec<(u8, usize, u64)> = pins .iter() .map(|&(q, _, _)| { diff --git a/crates/ec-av1/src/tile.rs b/crates/ec-av1/src/tile.rs index d8f600d0..a935fd4e 100644 --- a/crates/ec-av1/src/tile.rs +++ b/crates/ec-av1/src/tile.rs @@ -215,14 +215,20 @@ fn write_sb128_root( /// 32x32-mi window, the motion mode, and the transform syntax, with the mi /// grid and every neighbour band published over all thirty-two mi cells. /// -/// SKIP only, and refused otherwise: a 128x128 block's residual is four -/// TX_64X64 luma units interleaved with a TX_32X32 chroma pair per 64x64 mu -/// chunk (the chroma units reading the offset-10 `txb_skip` rows), which -/// this writer has no path for. A skipped block writes no `cdef_idx` and no -/// `delta_q` either, exactly as the 64 root's skip arm does. +/// lane-b128r: a block that carries a RESIDUAL codes it as the four 64x64 mu +/// chunks libaom's `decode_token_recon_block` walks -- per chunk one +/// TX_64X64 luma unit (its coded 32x32 corner, `TxbSet::Luma64`, DCT-only at +/// this size) then one TX_32X32 unit per chroma plane on the offset-10 +/// `txb_skip` rows, each publishing its own coefficient context before the +/// next unit reads it. Its transform syntax is the var-tx tree's four +/// depth-0 `txfm_partition` symbols, one per chunk. The levels arrive packed +/// per plane into a 64-wide grid, chunk (cr, cc) at (cr * 32, cc * 32) +/// ([`crate::encode::search_root_128`]). A skipped block writes no +/// `cdef_idx` and no `delta_q`, exactly as the 64 root's skip arm does. /// /// # Errors -/// A block that is intra, or carries a residual, at this size. +/// A block that is intra, that is compound with a residual, or whose var-tx +/// depth is not 0, at this size. #[allow(clippy::too_many_arguments)] fn write_inter_block_128( enc: &mut SymbolEncoder, @@ -239,13 +245,16 @@ fn write_inter_block_128( /// The block's side in samples and in 4x4 mode-info units. const SIDE: usize = 128; const SIDE_MI: usize = SIDE / MI; + /// The four 64x64 "mu" chunks, in the order libaom's + /// `decode_token_recon_block` walks them (raster). + const CHUNKS: [(usize, usize); 4] = [(0, 0), (0, 1), (1, 0), (1, 1)]; let info = block.inter.ok_or_else(|| { Error::unsupported("AV1 tile", "a 128x128 superblock root block is coded inter") })?; - if !block.skip { + if !block.skip && block.tx_depth != 0 { return Err(Error::unsupported( "AV1 tile", - "a 128x128 superblock root block carries a residual", + "a 128x128 superblock root block splits its var-tx tree below TX_64X64", )); } let (mi_r, mi_c) = (sb_at.0 * (SUB / MI), sb_at.1 * (SUB / MI)); @@ -253,9 +262,9 @@ fn write_inter_block_128( let has_left = neighbours.has_left(mi_c); let skip_ctx = usize::from(neighbours.above_skip[mi_c]) + usize::from(neighbours.left_skip[mi_r]); - enc.symbol(1, &mut cdfs.skip[skip_ctx]); - write_cdef_idx(enc, (mi_r, mi_c), true); - write_delta_q(enc, cdfs, (mi_r, mi_c), true, true); + enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]); + write_cdef_idx(enc, (mi_r, mi_c), block.skip); + write_delta_q(enc, cdfs, (mi_r, mi_c), true, block.skip); let ii_ctx = intra_inter_ctx( has_above, has_left, @@ -340,20 +349,143 @@ fn write_inter_block_128( )?; } if tx_select { - write_tx_syntax_inter(enc, cdfs, neighbours, (mi_r, mi_c), SIDE, true, true, 0); + if block.skip { + write_tx_syntax_inter(enc, cdfs, neighbours, (mi_r, mi_c), SIDE, true, true, 0); + } else { + // The var-tx tree of a 128x128 block enters at TX_64X64 once per + // mu chunk (`read_block_tx_size`'s `max_tx = side.min(64)` loop), + // so it is four depth-0 `txfm_split` flags of zero, each read + // against the bands the chunks before it published. + for (cr, cc) in CHUNKS { + let unit = (mi_r + cr * 16, mi_c + cc * 16); + let ctx = txfm_partition_ctx_rect( + neighbours.above_txfm[unit.1], + neighbours.left_txfm[unit.0], + SIDE, + 64, + 64, + ); + enc.symbol(0, &mut cdfs.txfm_partition[ctx]); + neighbours.record_txfm(unit, 64, 64, 64); + } + } } let zero_grids = [ vec![0i32; TX32 * TX32], vec![0i32; TX32 * TX32], vec![0i32; TX32 * TX32], ]; - neighbours.record(sb_at, SIDE, 0, &zero_grids); - neighbours.record_inter(sb_at, SIDE, true, true, block_ref(block)); + if !block.skip { + // The packed 64-wide level grids the search hands over, one plane + // each (see this function's doc). + let packed = [ + level_grid(&block.luma, 64)?, + level_grid(&block.u, 64)?, + level_grid(&block.v, 64)?, + ]; + let scan32 = default_scan(TX32); + let unit_of = |plane: usize, cr: usize, cc: usize| -> Vec { + (0..32) + .flat_map(|row| { + packed[plane][(cr * 32 + row) * 64 + cc * 32..][..32].to_vec() + }) + .collect() + }; + let mut chroma_units: Vec<((usize, usize), [Vec; 2])> = Vec::new(); + for (cr, cc) in CHUNKS { + let unit_mi = (mi_r + cr * 16, mi_c + cc * 16); + // The luma unit: its own `txb_skip_ctx` is the neighbour + // magnitude table (the unit is smaller than its block), and it + // publishes its context before the next chunk reads it. + let luma = unit_of(0, cr, cc); + let skip_ctx = neighbours.luma_skip_ctx(unit_mi, 64 / MI); + let around = neighbours.around_mi(unit_mi, 64); + write_coeffs( + enc, + &mut cdfs.txb(TxbSet::Luma64, 0), + &luma, + &scan32, + skip_ctx, + dc_sign_ctx(around[0].dc_vote), + Some(0), + TxType::DctDct, + ); + neighbours.record_mi_luma(unit_mi, 64, &luma); + // Then this chunk's chroma pair, before the next chunk's luma: + // libaom codes every plane of a mu chunk before moving on. The + // chroma `txb_skip_ctx` takes `get_txb_ctx`'s offset-10 rows + // (+3 here) because the uv plane block is bigger than the unit. + let mut pair = [Vec::new(), Vec::new()]; + for plane in 1..3usize { + let grid = unit_of(plane, cr, cc); + let around = neighbours.around_mi(unit_mi, 64)[plane]; + write_coeffs( + enc, + &mut cdfs.txb(TxbSet::Chroma32, 0), + &grid, + &scan32, + usize::from(around.above_coded) + usize::from(around.left_coded) + 3, + dc_sign_ctx(around.dc_vote), + Some(plane), + TxType::DctDct, + ); + neighbours.record_mi_chroma(unit_mi, 64, plane, &grid); + pair[plane - 1] = grid; + } + chroma_units.push((unit_mi, pair)); + } + // decode.rs' own tail (`record_split_luma_rect_mi` then the + // `mu_chroma_units` re-stamp): the block-level write off the WHOLE + // assembled chroma plane grid, luma kept because each unit already + // published its own, and then the per-unit chroma writes replayed + // over it -- last writer wins, so the next block reads the units. + let block_grids = [ + vec![0i32; TX32 * TX32], + packed[1].clone(), + packed[2].clone(), + ]; + neighbours.record_planes(sb_at, SIDE, 0, &block_grids, false); + for (unit_mi, pair) in &chroma_units { + neighbours.record_mi_chroma(*unit_mi, 64, 1, &pair[0]); + neighbours.record_mi_chroma(*unit_mi, 64, 2, &pair[1]); + } + } else { + neighbours.record(sb_at, SIDE, 0, &zero_grids); + } + neighbours.record_inter(sb_at, SIDE, block.skip, true, block_ref(block)); record_block_compound(neighbours, (mi_r, mi_c), SIDE, block); SB128_NONE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + if !block.skip { + SB128_RESIDUAL_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + } + if info.ref1.is_some() { + SB128_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + } Ok(()) } +/// lane-b128r: how many of those blocks carried a REAL residual (four +/// TX_64X64 luma units plus their per-chunk chroma pair) rather than being +/// skipped, since the last [`take_sb128_residual_hits`]. +static SB128_RESIDUAL_HITS: std::sync::atomic::AtomicUsize = + std::sync::atomic::AtomicUsize::new(0); + +/// The 128x128-with-residual count since the last call, and zero it. +pub fn take_sb128_residual_hits() -> usize { + SB128_RESIDUAL_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) +} + +/// lane-b128r: how many of those blocks named a SECOND reference (the +/// compound arm at the 128 root), since the last +/// [`take_sb128_compound_hits`]. +static SB128_COMPOUND_HITS: std::sync::atomic::AtomicUsize = + std::sync::atomic::AtomicUsize::new(0); + +/// The compound-128 count since the last call, and zero it. +pub fn take_sb128_compound_hits() -> usize { + SB128_COMPOUND_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) +} + /// How many 128x128 `PARTITION_NONE` blocks the inter writer has coded since /// the last [`take_sb128_none_hits`] (class `gate-blind-to-feature`). static SB128_NONE_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); @@ -2718,6 +2850,30 @@ impl Neighbours { } } + /// lane-b128r: publishes ONE chroma transform unit's coefficient context, + /// the decoder's own `record_mi_chroma` -- a 128x128 block's chroma is one + /// TX_32X32 unit per plane per 64x64 mu chunk, and the next chunk reads + /// the previous one's state (its `txb_skip_ctx` base 1 from the left + /// neighbour). `span_px` is the unit's LUMA span, which is what the + /// luma-mi-indexed bands are addressed in. + fn record_mi_chroma( + &mut self, + (mi_r, mi_c): (usize, usize), + span_px: usize, + plane: usize, + grid: &[i32], + ) { + let round_up_even = |n: usize| n.div_ceil(2) * 2; + let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols)); + let state = neighbour_state(grid); + for cell in 0..(span_px / MI).min(bound_h.saturating_sub(mi_r)) { + self.left[mi_r + cell][plane] = state; + } + for cell in 0..(span_px / MI).min(bound_w.saturating_sub(mi_c)) { + self.above[mi_c + cell][plane] = state; + } + } + /// Writes one coded block into every 16x16 column and row it covers, and, /// on the finer 4x4 grid libaom's entropy context arrays are actually /// kept on, into every unit up to the true frame edge -- the units past diff --git a/lanes/b128r.report.md b/lanes/b128r.report.md new file mode 100644 index 00000000..8b11ca60 --- /dev/null +++ b/lanes/b128r.report.md @@ -0,0 +1,165 @@ +# lane-b128r — a residual and a compound arm at the 128 root + +Two of the three arms the charter names are implemented and measured; the +third is deferred with its reason. One decoder defect was found on the way. + +| arm | state | +|---|---| +| 1. the 128 NONE block WITH a residual | written, witnessed, **opt-in** (`EC_AV1_B128RES=1`) — measured INERT and it leaves a filter-stage mismatch | +| 2. the 128 NONE **compound** arm | written, witnessed, **shipped on**: film A −0.2/−0.2, film B −0.2/−0.3 | +| 3. HORZ / VERT at the 128 root | **deferred**, untouched — see the disposition | + +## 1. The residual arm (opt-in) + +`search_root_128` now prices the winner's own prediction with a real +residual against the skip arm it just committed to the planes, and +`write_inter_block_128` codes it: per 64x64 mu chunk one TX_64X64 luma unit +(its coded 32x32 corner, `TxbSet::Luma64`, DCT-only at this size) then one +TX_32X32 unit per chroma plane on the offset-10 `txb_skip` rows, each +publishing its own coefficient context before the next unit reads it, with +the var-tx tree's four depth-0 `txfm_partition` symbols in front. Levels +travel as one 64-wide grid per plane, chunk (cr, cc) at (cr\*32, cc\*32). +Quantized at the qindex the ROOT signals (the delta_q unit is the 128 +superblock, lane-b128m), var-tx depth 0 only. + +**Witness** — `encode::tests::a_128_root_block_with_a_real_residual_decodes_exact_through_both_decoders` +(`--ignored`, the arm and the root forced so the clip codes the shape +rather than waiting for content): + + 128x128 blocks WITH a residual: search won 420, writer coded 420 + test ... ok + +420 residual 128x128 blocks over 8 frames at 1280x768, every frame +sample-exact against the encoder's own reconstruction through +`decode_stream` AND through ffmpeg. RED before the lane by construction +(the writer refused a non-skip 128 block) and RED again on the first draft: + +- **defect (writer)**: `write_inter_block_128` recorded `skip = true` in its + own neighbour band whatever the block was, so the NEXT root's `skip` + symbol took CDF row 1 (16515) where the reader takes row 0 (31739) — + first divergent symbol index 33, found with `EC_AV1_SYMTRACE`. + +**Why it ships off.** Two measurements: + +- it is INERT on content: over the native 12-frame gate the RD takes it + **0–2 times per frame** against ~90 whole 128 roots per frame + (`EC_AV1_B128_CENSUS=1`); +- switched on, `bd_rate_screen_native`'s bars 2160p row at q=90 frame 11 + has **8 luma samples** (rows 126..127, cols 1611..1616 — the two rows + above a 128-superblock horizontal edge) where ffmpeg and this encoder's + own reconstruction disagree. The arm's own witness is byte-exact through + ffmpeg over 420 blocks at 1280x768, so the open half is a FILTER-stage + interaction at a 128 block's own edge, not the coefficient path. + +An inert candidate does not buy a live filter mismatch. `EC_AV1_B128RES=1` +turns it on; the default encoder is byte-identical to the control (pins and +both 2160p gate rows reproduce the standing table to the digit). + +## 2. A decoder defect: one `cdef_idx` literal covers every unit its block spans + +libaom stores the `cdef_idx` it reads at the ORIGIN mi of the 64x64 CDEF +unit and `av1_cdef_frame` reads each unit's strength back off that origin — +so a block WIDER than one unit (the 128 root's block, the only one there +is) drives every unit it covers with its single literal. `maybe_read_cdef_idx` +stamped the reading block's own cell alone. No stream could reach it before +the 128 root carried a residual (class *branch dropped as unreachable*), and +the residual witness is its gate. Fixed with the block's own mi span, which +is a no-op for every block of one unit or less. + +## 3. The compound arm (shipped on) + +`search_root_128` passed an empty compound list, so a 128x128 block could +only ever name ONE reference — while the writer has had the path since +lane-b128 (`write_compound_block` for a block that names a second one). The +root now builds the `LAST`+`GOLDEN` / `LAST`+`ALTREF` stacks at its own +32x32-mi window, exactly as the 64 root builds them per superblock, and +offers the same three modes (`NEAREST_NEARESTMV`, `GLOBAL_GLOBALMV`, +`NEW_NEARESTMV`). `EC_AV1_B128COMP=0` is the attribution control. + +**It fires on real content** — census, compound 128x128 blocks per frame: + +| row | compound 128 blocks / frame | +|---|---| +| film B (2160p) | up to **80**, tens on most frames | +| bars 2160p | tens | +| screen capture | 0 (the screen path gates compound off) | +| synthetic bars pan | 1 per 8 frames | + +**Witness** — `encode::tests::a_128_root_compound_block_decodes_exact_through_both_decoders` +(`--ignored`, root forced): + + COMPOUND 128x128 blocks: search won 216, writer coded 432 + test ... ok + +(the writer count is the higher one because the filter search re-codes each +tile). 12 frames of `testsrc2` at 1280x768, sample-exact through +`decode_stream` and ffmpeg. RED before the lane: the count was 0. + +### The deciding gate + +`bd_rate_screen_native`, 12 frames, four quantizers, BD-rate vs libaom +`cpu-used 6` / rav1e `speed 6` (lower is better). Control = the standing +table of `lanes/table-20260908.md`, reproduced on this tree with the arm +off (both 2160p rows re-run here, to the digit): + +| row | control | + the 128 compound arm | +|---|---|---| +| bars 1080p | −3.4 / −19.0 | −3.4 / −19.0 | +| bars 2160p | +8.6 / −13.8 | +8.6 / −13.7 | +| film A (1080p) | +18.1 / −6.2 | **+17.9 / −6.4** | +| film B (2160p) | +23.8 / −2.8 | **+23.6 / −3.1** | +| screen capture | +14.4 / −33.2 | +14.4 / −33.2 | + +Both film rows are DOWN on both columns; screen is unchanged; bars 2160p +moves +0.1 on the rav1e column (inside the ±0.3 flat band). Wall on the 4K +film row 124.7s → 138.2s (+10.8%, under the +15% ceiling). + +`bd_rate_film_long_gop`, 48 frames, one key frame and 47 inter pictures +(control = the standing table): + +| row | control | + the 128 compound arm | +|---|---|---| +| film A | +22.6 / −8.1 | **+22.5 / −8.2** | +| film B | +78.4 / +2.4 | **+77.5 / +1.7** | + +Both rows down on both columns again, and film B by 0.9 / 0.7 — the long +GOP is where the compound pairs exist to be picked. + +## Suite / checks (the shipped state) + + s1 --skip stream:: 344 passed; 0 failed; 37 ignored RC=0 + s2 stream:: --skip 10bit 202 passed; 0 failed; 15 ignored RC=0 + s3 10bit 42 passed; 0 failed; 1 ignored RC=0 + --ignored every_speed_preset_decodes_sample_exact_through_both_decoders ok + --ignored a_128_superblock_clip_whose_root_search... ok (405 blocks) + --ignored a_128_root_block_with_a_real_residual... ok (420 blocks) + --ignored a_128_root_compound_block... ok (432 blocks) + the_encoders_own_streams_are_byte_identical_to_their_pins ok, and ok at EC_AV1_SPEED=6 + cargo check --workspace --all-targets -j4 0 errors, 0 ec-av1 warnings + +## Pins + +Re-taken for the compound arm, which moves every inter frame that carries +`reference_select`: `(150, 8364, 0xcb2ad7936d5127c5)`, `(60, 33257, +0x87db250ba556e5a6)` — was `(150, 8354, ...)`, `(60, 33222, ...)`. +`EC_AV1_B128COMP=0` restores 8354 / 33222 exactly, which is also the proof +that nothing else in this lane moves the shipped stream. Green at the +default and at `EC_AV1_SPEED=6`. No other byte pin moved. + +## Disposition + +- `deferred`: **HORZ / VERT at the 128 root** (two 128x64 / 64x128 blocks), + untouched. The writer has no rect neighbour recording at this size and the + search no rect trial; `write_inter_block_128` is square throughout + (`record`/`record_inter`/`record_planes` all take one side). Unblocked by + a rect `record_inter`/`record` pair plus a rect trial in + `search_root_128`. The decoder reads both already (lane-sb128c r7). + Not attempted: the residual arm's own writer/reader bisect consumed the + budget this would have needed. +- `open`: the residual arm's **8-sample filter mismatch** (bars 2160p, q=90, + frame 11, rows 126..127 / cols 1611..1616, ffmpeg vs our reconstruction). + Next step: dump the deblock/CDEF decision at that 128 superblock's own + bottom edge for a block that carries a residual, against aomdec. Until + then the arm stays behind `EC_AV1_B128RES=1`. +- `open` (inherited): search-time vs write-time mv stacks still differ + (lane-sb128b's second open item).