diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 8168bad1..588a35a3 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -376,6 +376,40 @@ fn split_inter_blocks() -> bool { } } +/// Whether the inter search offers the whole superblock as ONE 64x64 block +/// (`PARTITION_NONE` at `BLOCK_64X64`), coded SKIP, against the four 32x32 +/// quadrants it would otherwise always split into. +/// +/// The census (`lanes/census-filmB.md`) is what points here: rav1e speed 6 +/// codes 45.2% of its blocks at 64x64 -- 73.8% of its LEAF blocks, 99.2% of +/// them skip at 328 bytes a frame -- while every block this encoder wrote was +/// 32x32 or smaller, which put our mode+mv+partition+tx_size spend at 162,669 +/// bits against rav1e's 61,988, about 46% of the film B gap. +/// +/// SKIP-only: a 64x64 residual needs a forward TX_64X64 the encoder does not +/// have (`transform.rs` tops out at 32x32), and the writer refuses any other +/// shape (`crate::tile::Quadrant::Whole64`). Switched off by `EC_AV1_B64=0` +/// in any build. +pub(crate) const B64_ROOT: bool = true; + +/// How many superblocks took the 64x64 root since the last +/// [`take_b64_root_hits`], so a gate reports how often it fires rather than +/// assuming it does (class `gate-blind-to-feature`). +static B64_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); + +/// The 64x64-root count since the last call, and zero it. +pub fn take_b64_root_hits() -> usize { + B64_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) +} + +/// [`B64_ROOT`], or what `EC_AV1_B64` names. +fn b64_root() -> bool { + static ENV: std::sync::LazyLock> = std::sync::LazyLock::new(|| { + crate::envflags::var("EC_AV1_B64").ok().map(|v| v != "0") + }); + ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::B64_ROOT)) +} + /// Whether the encoder searches loop restoration at all (spec 7.17): one /// Wiener filter per 64x64 luma restoration unit, picked from /// [`crate::filter_search::WIENER_CANDIDATES`]. Swept by `EC_AV1_LR` in a @@ -7135,6 +7169,180 @@ fn mc_trial_compound( /// [`find_mv_stack`] is public and this function is handed the same `MvStack` /// the tile writer derives from the same grid state. #[allow(clippy::too_many_arguments)] +/// One prediction of `side` x `side` samples from `reference`, as `u8` -- +/// [`mc_trial`]'s prediction half, on the heap because a 64x64 luma block is +/// four times the stack scratch that function sizes for [`BLOCK`]. +fn predict_u8( + reference: &[u16], + stride: usize, + ref_width: usize, + ref_height: usize, + (x, y): (usize, usize), + side: usize, + mv: (i32, i32), + luma: bool, + fctx: &crate::decode::FrameCtx, +) -> Vec { + let mut prediction = vec![0u16; side * side]; + mc::predict( + reference, + stride, + ref_width, + ref_height, + mv_to_q4(x, mv.1, luma), + mv_to_q4(y, mv.0, luma), + side, + side, + &mut prediction, + fctx, + ); + prediction.iter().map(|&v| v as u8).collect() +} + +/// The 64x64 `PARTITION_NONE` candidate for a whole superblock ([`B64_ROOT`]): +/// single-reference LAST at `NEARESTMV`/`GLOBALMV`/`NEARMV`/`NEWMV`, coded +/// SKIP, priced through the same `symbol_bits` path every other candidate +/// uses. The winner's prediction is committed to the planes (it IS the +/// reconstruction -- a skip block has no residual); the caller restores them +/// if the four quadrants come out cheaper. +/// +/// `None` when no candidate could be coded at all (a `NEWMV` residual the +/// writer cannot name is simply not offered, and the other modes always are, +/// so this only happens if every candidate is refused). +fn search_skip_64( + luma: &mut Plane, + chroma: &mut [Plane; 2], + (x, y): (usize, usize), + search: &Search, + reference: &Picture, + stack: &MvStack, + fctx: &crate::decode::FrameCtx, +) -> Option<(f64, BlockCoeffs)> { + let side = SUPERBLOCK; + let not_new = symbol_bits(&cdf::NEW_MV[stack.new_mv_ctx], 1); + let not_zero = symbol_bits(&cdf::ZERO_MV[stack.zero_mv_ctx], 1); + let ref_bits = symbol_bits(&cdf::SINGLE_REF[0][0], 0) + + symbol_bits(&cdf::SINGLE_REF[0][2], 0) + + symbol_bits(&cdf::SINGLE_REF[0][3], 0); + // What every candidate pays whatever its vector: `skip` coded 1, then + // `is_inter` coded 1, then the LAST chain above. + let fixed = symbol_bits(&cdf::SKIP[0], 1) + symbol_bits(&cdf::INTRA_INTER[0], 1) + ref_bits; + let info_of = |mode: InterMode, mv: (i32, i32), ref_mv_idx: u8| InterInfo { + ref1: None, + mv1: (0, 0), + ref_frame: crate::mvstack::LAST_FRAME, + mode, + mv, + ref_mv_idx, + }; + let mut cands: Vec<(f64, InterInfo)> = vec![ + ( + not_new + not_zero + symbol_bits(&cdf::REF_MV[stack.ref_mv_ctx], 0), + info_of(InterMode::NearestMv, stack.nearest_mv, 0), + ), + ( + not_new + symbol_bits(&cdf::ZERO_MV[stack.zero_mv_ctx], 0), + info_of(InterMode::GlobalMv, (0, 0), 0), + ), + ]; + let near_bits = not_new + not_zero + symbol_bits(&cdf::REF_MV[stack.ref_mv_ctx], 1); + for idx in 1..=2usize { + if let Some(e) = stack.entries.get(idx) { + cands.push(( + near_bits + drl_bits_for(stack, 1, idx), + info_of(InterMode::NearMv, e.mv, idx as u8), + )); + } + } + if leaf_new_mv() { + let source_block = luma.source_block(x, y, side); + let (seeds, seed_n) = mv_seeds(stack); + let found = motion::search( + &reference.y, + reference.width, + luma.true_width, + luma.true_height, + &source_block, + x, + y, + side, + side, + stack.pred_mv, + &seeds[..seed_n], + search.lambda, + fctx, + 1, + ); + let mv = round_to_valid_mv(found.mv, stack.pred_mv); + if let Some((bits, ref_mv_idx)) = best_new_mv_syntax(stack, mv) { + cands.push(( + symbol_bits(&cdf::NEW_MV[stack.new_mv_ctx], 0) + bits, + info_of(InterMode::NewMv, mv, ref_mv_idx), + )); + } + } + + let mut best: Option<(f64, InterInfo, [Trial; 3])> = None; + for (bits, info) in cands { + let trials = [ + (0usize, x, y, side, true), + (1, x / 2, y / 2, side / 2, false), + (2, x / 2, y / 2, side / 2, false), + ] + .map(|(plane, px, py, s, is_luma)| { + let (samples, stride, w, h) = match plane { + 0 => (&reference.y, reference.width, luma.true_width, luma.true_height), + 1 => ( + &reference.u, + reference.width / 2, + chroma[0].true_width, + chroma[0].true_height, + ), + _ => ( + &reference.v, + reference.width / 2, + chroma[1].true_width, + chroma[1].true_height, + ), + }; + let prediction = predict_u8(samples, stride, w, h, (px, py), s, info.mv, is_luma, fctx); + let target: &Plane = if plane == 0 { luma } else { &chroma[plane - 1] }; + // `skip` true: the trial is the prediction itself plus its SSE, + // so no transform of any size is involved (the reason a 64x64 + // root can be coded at all before a forward TX_64X64 exists). + target.code_from_prediction( + px, + py, + s, + &prediction, + true, + search.base_q_idx, + search.deadzone, + TxbSet::Luma32Inter, + ) + }); + let cost = trials[0].sse + + trials[1].sse + + trials[2].sse + + search.lambda * (fixed + bits); + if best.as_ref().is_none_or(|b| cost < b.0) { + best = Some((cost, info, trials)); + } + } + let (cost, info, trials) = best?; + luma.commit(x, y, side, &trials[0]); + chroma[0].commit(x / 2, y / 2, side / 2, &trials[1]); + chroma[1].commit(x / 2, y / 2, side / 2, &trials[2]); + Some(( + cost, + BlockCoeffs { + skip: true, + inter: Some(info), + ..BlockCoeffs::default() + }, + )) +} + fn search_inter_block( luma: &mut Plane, chroma: &mut [Plane; 2], @@ -8776,7 +8984,68 @@ pub(crate) fn encode_inter_frame( let mut blocks: Vec<(usize, Quadrant)> = Vec::new(); for sb_r in rect.sb_row0 as usize..rect.sb_row1 as usize { for sb_c in rect.sb_col0 as usize..rect.sb_col1 as usize { - for quadrant in 0..4 { + // lane-b64: the whole superblock as ONE 64x64 block, tried before + // its quadrants are (`search_skip_64`) and compared against the + // four of them below. Only a superblock wholly inside the true + // frame is offered it: a 64x64 root whose right or bottom part + // hangs over the edge is legal AV1 (`has_cols`/`has_rows` only + // ask for half), but its trial would score prediction the frame + // does not have -- corner-cut, ceiling = the edge superblocks of + // a frame whose size is not a multiple of 64, which stay split. + let (x64, y64) = (sb_c * SUPERBLOCK, sb_r * SUPERBLOCK); + let sb64_legal = b64_root() + && sb_r * 2 + 1 < rows + && sb_c * 2 + 1 < cols + && (sb_c as u32 + 1) * crate::tile::SB_MI <= header.mi_cols + && (sb_r as u32 + 1) * crate::tile::SB_MI <= header.mi_rows + && x64 + SUPERBLOCK <= luma.true_width + && y64 + SUPERBLOCK <= luma.true_height; + // One lambda for the whole superblock, the same mean the 32x32 + // level takes over its own four tpl cells: the 64-vs-four-32 + // comparison below weighs one cost against four, so both sides + // have to be priced at the same lambda. + let sb_search = match &tpl_factors { + Some(f) if sb64_legal => { + let mean = (0..16) + .map(|i| f[(sb_r * 4 + i / 4) * tpl_cells_x + sb_c * 4 + i % 4]) + .sum::() + / 16.0; + Search { lambda: search.lambda * mean, ..search } + } + _ => search, + }; + let mark = blocks.len(); + let mut sb64: Option<(f64, BlockCoeffs, [(Vec, Vec); 3])> = None; + let mut sb_cost = 0.0f64; + if sb64_legal { + let base = snapshot(&luma, &chroma, (x64, y64), SUPERBLOCK); + let (mi_row, mi_col) = (sb_r * 16, sb_c * 16); + let stack = + find_mv_stack(&grid, mi_row, mi_col, 16, 16, LAST_FRAME, mi_cols, mi_rows); + if let Some((cost, block)) = search_skip_64( + &mut luma, + &mut chroma, + (x64, y64), + &sb_search, + reference, + &stack, + fctx, + ) { + let after = snapshot(&luma, &chroma, (x64, y64), SUPERBLOCK); + restore(&mut luma, &mut chroma, (x64, y64), SUPERBLOCK, &base); + let cost = cost + + sb_search.lambda * crate::tile::partition_bits(SUPERBLOCK, false); + sb64 = Some((cost, block, after)); + } + } + // A superblock whose 64x64 trial already codes almost nothing per + // pixel is taken outright and its quadrants are never searched -- + // the same `split_rd_breakout` shape the 32x32 level uses one + // size up, and where this lever BUYS wall instead of spending it. + let early64 = sb64 + .as_ref() + .is_some_and(|(c, _, _)| split_rd_breakout(*c, SUPERBLOCK, sb_search.lambda)); + for quadrant in 0..if early64 { 0 } else { 4 } { let (r32, c32) = (sb_r * 2 + quadrant / 2, sb_c * 2 + quadrant % 2); // lane-av1tpl2: this 32x32 block's own lambda -- every RD // decision under it (partition, mode, tx, motion) reads @@ -9061,12 +9330,14 @@ pub(crate) fn encode_inter_frame( // grid, and their reconstruction is what the // planes hold. partition_hit(1); + sb_cost += cost; blocks.push((r32 * cols + c32, Quadrant::Split(leaves))); continue; } restore(&mut luma, &mut chroma, (x, y), BLOCK, &after_whole); } partition_hit(0); + sb_cost += cost_whole; record_mi(&mut grid, mi_row, mi_col, 8, block.inter); blocks.push((r32 * cols + c32, Quadrant::Whole(block))); } else { @@ -9185,6 +9456,26 @@ pub(crate) fn encode_inter_frame( blocks.push((r32 * cols + c32, Quadrant::Split(leaves))); } } + // The 64x64 root against what its four quadrants really cost. + if let Some((cost64, block, after)) = sb64 + && (early64 + || cost64 + < sb_cost + + sb_search.lambda * crate::tile::partition_bits(SUPERBLOCK, true)) + { + B64_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + blocks.truncate(mark); + restore(&mut luma, &mut chroma, (x64, y64), SUPERBLOCK, &after); + // Overwrites every 16x16 mi cell the quadrant searches + // published under this superblock, so the next block's stack + // is built off the block that was really coded. + record_mi(&mut grid, sb_r * 16, sb_c * 16, 16, block.inter); + blocks.push(((sb_r * 2) * cols + sb_c * 2, Quadrant::Whole64(block))); + for q in 1..4 { + let (r32, c32) = (sb_r * 2 + q / 2, sb_c * 2 + q % 2); + blocks.push((r32 * cols + c32, Quadrant::Covered)); + } + } } } let (x0, y0) = (rect.mi_col0 as usize * 4, rect.mi_row0 as usize * 4); diff --git a/crates/ec-av1/src/encoder.rs b/crates/ec-av1/src/encoder.rs index 2dc98f1d..a63cae93 100644 --- a/crates/ec-av1/src/encoder.rs +++ b/crates/ec-av1/src/encoder.rs @@ -2222,6 +2222,65 @@ mod tests { /// with each other and disagree with nothing -- so the ffmpeg half is /// the one that catches a tile boundary the writer respected and the /// spec does not, and the parser half catches the reverse. + + /// A STATIC clip: every inter frame predicts perfectly from the last, so + /// the search takes the 64x64 root ([`crate::encode::B64_ROOT`]) instead + /// of coding four 32x32 quadrants, and the stream both decoders + /// reconstruct is still sample-exact against the encoder's own + /// reconstruction. The counter is the point (class + /// `gate-blind-to-feature`): without it a green three-way compare says + /// nothing about whether a single 64x64 block was ever written. + #[test] + fn a_static_clip_codes_64x64_roots_and_decodes_sample_exact() { + let _gate_lock = crate::stream::tests::lock_gate_counters(); + let (width, height) = (256usize, 128usize); + let still = test_card(width, height, 0); + let sources: Vec = (0..3).map(|_| still.clone()).collect(); + let config = EncoderConfig { + width, + height, + base_q_idx: 120, + gop: 8, + colour: Colour::Bt709Limited, + tile_cols_log2: 0, + tile_rows_log2: 0, + }; + let mut enc = Av1Encoder::new(config).unwrap(); + let mut stream = Vec::new(); + let _ = crate::encode::take_b64_root_hits(); + for packet in encode_all(&mut enc, &sources) { + stream.extend_from_slice(&packet.data); + } + let roots = crate::encode::take_b64_root_hits(); + // 8 superblocks per frame, two inter frames. + assert!( + roots > 0, + "a static clip coded no 64x64 root at all (of 16 inter superblocks)" + ); + eprintln!("64x64 roots on a static clip: {roots} of 16 inter superblocks"); + + let ours = crate::stream::decode_stream(&stream).expect("our decoder"); + assert_eq!(ours.len(), sources.len(), "our decoder's frames"); + if !have_ffmpeg() { + eprintln!("SKIP the ffmpeg half: no ffmpeg"); + return; + } + let theirs = ffmpeg_decode_luma(&stream, width, height); + assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); + for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { + let got: Vec = a.y.iter().map(|&v| v as u8).collect(); + if let Some(at) = got.iter().zip(b).position(|(x, y)| x != y) { + panic!( + "frame {i}: luma differs first at ({}, {}): ours {} vs ffmpeg {}", + at % width, + at / width, + got[at], + b[at], + ); + } + } + } + #[test] fn every_tile_layout_decodes_sample_exact_through_both_decoders() { let (width, height) = (640usize, 384usize); diff --git a/crates/ec-av1/src/speed.rs b/crates/ec-av1/src/speed.rs index 3022bb27..fa85c707 100644 --- a/crates/ec-av1/src/speed.rs +++ b/crates/ec-av1/src/speed.rs @@ -143,6 +143,12 @@ pub(crate) fn at(table: &[T; 11]) -> T { // table for what each step measured). // --------------------------------------------------------------------------- +/// `encode::B64_ROOT`: the 64x64 `PARTITION_NONE` skip trial at the +/// superblock root. On at every preset -- it is a wall SAVER as well as a bit +/// saver, since a superblock the trial takes is never searched at 32x32 (see +/// the lane report for the measured wall at preset 0 and 6). +pub(crate) const B64_ROOT: [bool; 11] = [crate::encode::B64_ROOT; 11]; + /// `encode::SPLIT_RD_THRESHOLD`: how cheap a block has to be before its split /// trial is withheld. The single biggest wall lever in the tile search. pub(crate) const SPLIT_RD: [f64; 11] = [ diff --git a/crates/ec-av1/src/tile.rs b/crates/ec-av1/src/tile.rs index f9ef0eab..00fe1130 100644 --- a/crates/ec-av1/src/tile.rs +++ b/crates/ec-av1/src/tile.rs @@ -1131,7 +1131,7 @@ pub(crate) const INTRA_MODE_CTX: [usize; INTRA_MODES] = [0, 1, 2, 3, 4, 4, 4, 4, /// +3, so `MAX_ANGLE_DELTA` is the middle of it. pub(crate) const ANGLE_DELTA_ZERO: usize = 3; /// Side of a superblock in 4x4 mode-info units when 128x128 superblocks are off. -const SB_MI: u32 = 16; +pub(crate) const SB_MI: u32 = 16; /// `NUM_BASE_LEVELS` (spec 3): levels above this carry a base-range tail. const NUM_BASE_LEVELS: i32 = 2; @@ -1764,14 +1764,28 @@ pub enum Quadrant { /// The four 16x16 blocks it is split into, in raster order, each with a /// 16x16 luma transform and an 8x8 transform per chroma plane. Split(Vec), + /// lane-b64: not a quadrant at all -- the whole 64x64 superblock this + /// quadrant is the TOP-LEFT of, coded as one block (`PARTITION_NONE` at + /// `BLOCK_64X64`). Only the top-left quadrant of a superblock carries it + /// and the other three carry [`Covered`](Quadrant::Covered), so the + /// per-32x32-entry shape the inter writer takes is unchanged. + /// + /// The block is coded SKIP and single-reference: a 64x64 residual needs + /// the forward TX_64X64 the encoder does not have (`transform.rs` tops + /// out at 32x32), and the writer refuses anything else. + Whole64(BlockCoeffs), + /// A quadrant a [`Whole64`](Quadrant::Whole64) at its superblock's + /// top-left already coded; it carries no block of its own. + Covered, } impl Quadrant { /// The blocks it carries, in the order they are coded. pub(crate) fn blocks(&self) -> &[BlockCoeffs] { match self { - Quadrant::Whole(block) => std::slice::from_ref(block), + Quadrant::Whole(block) | Quadrant::Whole64(block) => std::slice::from_ref(block), Quadrant::Split(blocks) => blocks.as_slice(), + Quadrant::Covered => &[], } } } @@ -2746,6 +2760,14 @@ pub(crate) fn sb_coeff_key_frame_tile_cdfs( ) }); match quadrant { + // A 64x64 root is an INTER-frame partition; a + // key frame codes one as `Superblock::Whole`. + Quadrant::Whole64(_) | Quadrant::Covered => { + return Err(Error::unsupported( + "AV1 tile", + "a key frame codes a 64x64 block as `Superblock::Whole`", + )); + } Quadrant::Whole(block) => { if !has_cols32 || !has_rows32 { return Err(Error::unsupported( @@ -4343,6 +4365,9 @@ pub(crate) fn predicted_coeff_bits(blocks: &[Quadrant], base_q_idx: u8) -> f64 { let side = match q { Quadrant::Whole(_) => 32, Quadrant::Split(_) => 16, + // A 64x64 root is skip-only, so it carries no coefficient + // bits to predict at all (`Quadrant::Whole64`). + Quadrant::Whole64(_) | Quadrant::Covered => return 0.0, }; q.blocks().iter().map(|b| block_bits(b, side, q_ctx)).sum::() }) @@ -5559,15 +5584,133 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( let sb_ctx = neighbours.partition_ctx(sb_at, SB); // spec `decode_partition`'s hasRows/hasCols (5.11.4): a superblock // whose bottom or right half falls outside the true frame cannot - // be left whole, but this writer only ever splits a superblock - // into its four 32x32 quadrants (never `PARTITION_NONE` at 64x64), - // so the only question is which of the three partition symbols - // that split takes — same three-way signaling as + // be left whole, so the only question there is which of the three + // partition symbols the split takes — same three-way signaling as // `sb_coeff_key_frame_tile`'s superblock level. let (has_cols, has_rows) = ( sb_c * SB_MI + SB_MI / 2 < mi_cols, sb_r * SB_MI + SB_MI / 2 < mi_rows, ); + // lane-b64: a superblock the search left WHOLE — one 64x64 block + // at `PARTITION_NONE`, carried by its top-left quadrant's entry + // ([`Quadrant::Whole64`]). Coded skip and single-reference: no + // residual, so no TX_64X64 coefficients and no `cdef_idx`. + let sb64 = ((sb_r * 2) < rows && (sb_c * 2) < cols) + .then(|| &blocks[((sb_r * 2) * cols + sb_c * 2) as usize]) + .and_then(|q| match q { + Quadrant::Whole64(block) => Some(block), + _ => None, + }); + if let Some(block) = sb64 { + if !has_cols || !has_rows { + return Err(Error::unsupported( + "AV1 tile", + "a superblock that is half outside the true frame cannot be left whole", + )); + } + let info = block.inter.ok_or_else(|| { + Error::unsupported("AV1 tile", "a 64x64 root block is coded inter") + })?; + if !block.skip || info.ref1.is_some() { + return Err(Error::unsupported( + "AV1 tile", + "a 64x64 root block is coded skip and single-reference \ + (a 64x64 residual needs a forward TX_64X64)", + )); + } + enc.symbol(PARTITION_NONE, &mut cdfs.partition_w64[sb_ctx]); + let (mi_r, mi_c) = (sb_at.0 * (SUB / MI), sb_at.1 * (SUB / MI)); + let has_above = neighbours.has_above(mi_r); + 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(&mut enc, (mi_r, mi_c), true); + let ii_ctx = intra_inter_ctx( + has_above, + has_left, + neighbours.above_inter[mi_c], + neighbours.left_inter[mi_r], + ); + enc.symbol(1, &mut cdfs.intra_inter[ii_ctx]); + write_comp_mode( + &mut enc, + &mut cdfs, + &neighbours, + (mi_r, mi_c), + (has_above, has_left), + false, + ); + write_single_ref( + &mut enc, + &mut cdfs, + info.ref_frame, + neighbours.above_ref[mi_c], + neighbours.above_ref1[mi_c], + neighbours.left_ref[mi_r], + neighbours.left_ref1[mi_r], + ); + let stack = find_mv_stack( + &grid, + mi_r, + mi_c, + SB_MI as usize, + SB_MI as usize, + info.ref_frame, + mi_cols as usize, + mi_rows as usize, + ); + let (mv, is_new_mv) = write_inter_mode(&mut enc, &mut cdfs, info, &stack)?; + for dr in 0..SB_MI as usize { + for dc in 0..SB_MI as usize { + grid.set( + mi_r + dr, + mi_c + dc, + MiInfo { + is_inter: true, + ref_frame: info.ref_frame, + ref_frame1: NO_REF1, + mv1: (0, 0), + mv: mv16(mv), + is_new_mv, + size: SB_MI as u8, + size_h: SB_MI as u8, + is_global_mv0: false, + is_global_mv1: false, + }, + ); + } + } + write_motion_mode( + &mut enc, + &mut cdfs, + &grid, + (mi_r, mi_c), + (SB_MI as usize, SB_MI as usize), + (SB, SB), + (mi_cols as usize, mi_rows as usize), + info.ref_frame, + block.motion_mode, + )?; + if tx_select { + // A skipped inter block writes no `txfm_split` at all -- + // this only publishes the max transform size the reader + // infers for it (`write_tx_syntax_inter`). + write_tx_syntax_inter( + &mut enc, + &mut cdfs, + &mut neighbours, + (mi_r, mi_c), + SB, + true, + true, + 0, + ); + } + neighbours.record(sb_at, SB, 0, &zero_grids); + neighbours.record_inter(sb_at, SB, true, true, block_ref(block)); + continue; + } match (has_cols, has_rows) { (true, true) => enc.symbol(PARTITION_SPLIT, &mut cdfs.partition_w64[sb_ctx]), (true, false) => { @@ -5600,6 +5743,15 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows), ); let block = match site { + // Already coded by the `Whole64` above -- but only inside + // a superblock that really carried one. + Quadrant::Whole64(_) | Quadrant::Covered => { + return Err(Error::unsupported( + "AV1 tile", + "a `Whole64`/`Covered` quadrant needs its superblock's \ + top-left entry to be the `Whole64`", + )); + } Quadrant::Whole(block) => { if !has_cols32 || !has_rows32 { return Err(Error::unsupported(