forge
Explore
Log in

Don't you dare go Hollow

Merge lane-av1-ibcrect: 128-root intrabc strips pixel-exact

Browse files at this commit

64f82ca8823091c655619d5c5553e9de8b091dacAhmet Kaan GümüşParent: c5a3cd17c12512
Reviewer PASS. Witness an_sb128_rect_strip_with_intrabc_decodes_pixel_exact
byte-exact, hits advanced on HORZ, VERT, and 10-bit. The 10-bit comment
that called that arm a coverage gap is corrected in e0bc18bd.
crates/ec-av1/examples/decode_probe.rsmodified+14 -0
@@ -63,6 +63,12 @@ fn main() {
6363 ec_av1::decode::intrabc_rect_hits(),
6464 ec_av1::decode::intrabc_rect_vartx_hits()
6565 );
66+ // lane-av1-ibcrect: `use_intrabc` on a 128-root HORZ/VERT strip --
67+ // the shape `decode_block_128rect` used to refuse.
68+ println!(
69+ "intrabc_128rect: {}",
70+ ec_av1::stream::intrabc_128rect_hits()
71+ );
6672 let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters();
6773 println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}");
6874 println!(
@@ -142,6 +148,14 @@ fn main() {
142148 "sb128_rect: edge_horz={} edge_vert={} inter_128x64={} inter_64x128={}",
143149 sb.0, sb.1, sb.2, sb.3
144150 );
151+ // lane-av1-ibcrect: the interior 128-root partition arms and the key
152+ // frame's intra 128-axis blocks, so a recipe sweep can tell "the
153+ // encoder never chose HORZ/VERT at the 128 root" from "it did".
154+ let p128 = ec_av1::stream::part128_census();
155+ println!(
156+ "part128: split={} none={} horz={} vert={} ab={:?} intra_horz={} intra_vert={}",
157+ p128.0, p128.1, p128.2, p128.3, p128.4, p128.5, p128.6
158+ );
145159 // lane-sbab r1: the superblock-level inter AB arms.
146160 let sbab = ec_av1::decode::sb_ab_inter_hits_by_arm();
147161 println!(
crates/ec-av1/src/decode.rsmodified+480 -4
@@ -3874,6 +3874,27 @@ pub fn intrabc_rect_vartx_hits() -> usize {
38743874 INTRABC_RECT_VARTX_HITS.with(|c| c.get())
38753875 }
38763876
3877+thread_local! {
3878+ /// lane-av1-ibcrect: `use_intrabc` blocks on a 128-root HORZ/VERT strip
3879+ /// (BLOCK_128X64 / BLOCK_64X128) whose reconstruction
3880+ /// [`decode_intrabc_128rect`] ran -- the shape the named refusal used to
3881+ /// guard (`decode_block_128rect`). A refused block bumps
3882+ /// [`INTRABC_HITS`] but never this one.
3883+ static INTRABC_128RECT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3884+}
3885+
3886+/// Current value of [`INTRABC_128RECT_HITS`].
3887+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3888+pub fn intrabc_128rect_hits() -> usize {
3889+ INTRABC_128RECT_HITS.with(|c| c.get())
3890+}
3891+
3892+/// Zeroes [`INTRABC_128RECT_HITS`].
3893+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3894+pub(crate) fn reset_intrabc_128rect_hits() {
3895+ INTRABC_128RECT_HITS.with(|c| c.set(0));
3896+}
3897+
38773898 /// Current value of [`INTRABC_VARTX_HITS`].
38783899 #[allow(dead_code)] // read only from the `#[cfg(test)]` gates
38793900 pub(crate) fn intrabc_vartx_hits() -> usize {
@@ -11602,6 +11623,447 @@ fn decode_intrabc_rect(
1160211623 Ok(())
1160311624 }
1160411625
11626+/// lane-av1-ibcrect: reconstruction for a `use_intrabc` block on a 128-root
11627+/// HORZ/VERT strip (`BLOCK_128X64` / `BLOCK_64X128`) -- the shape
11628+/// `decode_block_128rect` refused by name before this port. libaom decodes
11629+/// such a block through the INTER machinery (an intrabc block
11630+/// `is_inter_block`): `predict_inter_block` copies the whole block from this
11631+/// frame's own reconstruction at the integer block vector once, then
11632+/// `decode_token_recon_block`'s inter arm walks 64x64 "mu" chunks --
11633+/// per chunk every plane, luma units at the block's own resolved transform
11634+/// (`read_block_tx_size_rect`, TX_64X64 roots) and chroma at
11635+/// `av1_get_max_uv_txsize(BLOCK_128X64)` = TX_32X32, one unit per plane per
11636+/// chunk at 4:2:0. Chroma never codes its own `tx_type`; each unit inherits
11637+/// the coded type of the luma leaf covering its quadrant (`av1_get_tx_type`,
11638+/// blockd.h:1291). `mode`/`uv_mode` read as `DC_PRED`/`UV_DC_PRED` back in
11639+/// [`read_intra_mode_rect`]; no palette/filter-intra/CFL symbol exists here.
11640+#[allow(clippy::too_many_arguments)]
11641+fn decode_intrabc_128rect(
11642+ dec: &mut SymbolDecoder,
11643+ cdfs: &mut Cdfs,
11644+ neighbours: &mut Neighbours,
11645+ (mi_r, mi_c): (usize, usize),
11646+ (bw, bh): (usize, usize),
11647+ skip: bool,
11648+ (dv_row, dv_col): (i32, i32),
11649+ y: &mut PlaneBuf<'static>,
11650+ u: &mut PlaneBuf<'static>,
11651+ v: &mut PlaneBuf<'static>,
11652+ base_q_idx: u8,
11653+ fctx: &crate::decode::FrameCtx,
11654+) -> Result<()> {
11655+ hit!(INTRABC_128RECT_HITS);
11656+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
11657+ let (rng, _) = dec.debug_state();
11658+ eprintln!(
11659+ "EC_IBC128 mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} skip={skip} dv=({dv_row},{dv_col}) rng={rng}"
11660+ );
11661+ }
11662+ let (px, py) = (mi_c * MI, mi_r * MI);
11663+ let (cpx, cpy) = (px / 2, py / 2);
11664+ let (cw, ch) = (bw / 2, bh / 2);
11665+ // The square strides the proven INTER path lays its residual grids,
11666+ // prediction windows and `TxParams` at (see [`decode_intrabc_rect`]'s r2
11667+ // note): 128/64 here.
11668+ let side = bw.max(bh);
11669+ let cside = cw.max(ch);
11670+ // `av1_calc_mi_size`'s 8-px-aligned grid: units past the frame edge code
11671+ // nothing (`decode_reconstruct_tx`'s max_blocks_* early return).
11672+ let mi_cols = 2 * y.true_width.div_ceil(8);
11673+ let mi_rows = 2 * y.true_height.div_ceil(8);
11674+ // An intrabc block is is_inter_block: the tx tree is the INTER one, and
11675+ // [`read_block_tx_size_rect`]'s 128-root branch already carries the
11676+ // LARGEST (no symbol, two TX_64X64 units), TX_MODE_SELECT (var-tx tree
11677+ // rooted at TX_64X64), skip (band stamp only) and lossless (TX_4X4 grid)
11678+ // arms (lane-sb128c r7).
11679+ let leaves = read_block_tx_size_rect(
11680+ dec,
11681+ cdfs,
11682+ neighbours,
11683+ (mi_r, mi_c),
11684+ (bw, bh),
11685+ (mi_cols, mi_rows),
11686+ skip, fctx,
11687+ )?;
11688+ // Whole-block prediction, once, before any coefficient is read
11689+ // (`predict_inter_block`); the source is this frame's own
11690+ // reconstruction, including the writes this superblock has queued.
11691+ flush_recon(fctx, y, u, v);
11692+ let mut pred_y_dense = vec![0u16; bw * bh];
11693+ mc::predict_with_filter(
11694+ &y.data, y.width, y.true_width, y.true_height,
11695+ mv_to_q4(px, dv_col, true), mv_to_q4(py, dv_row, true),
11696+ bw, bh, mc::InterpFilterKind::Bilinear, &mut pred_y_dense, fctx,
11697+ );
11698+ let mut pred_y = vec![0u16; side * side];
11699+ for row in 0..bh {
11700+ pred_y[row * side..][..bw].copy_from_slice(&pred_y_dense[row * bw..][..bw]);
11701+ }
11702+ let mut pred_u_dense = vec![0u16; cw * ch];
11703+ mc::predict_with_filter(
11704+ &u.data, u.width, u.true_width, u.true_height,
11705+ mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false),
11706+ cw, ch, mc::InterpFilterKind::Bilinear, &mut pred_u_dense, fctx,
11707+ );
11708+ let mut pred_u = vec![0u16; cside * cside];
11709+ for row in 0..ch {
11710+ pred_u[row * cside..][..cw].copy_from_slice(&pred_u_dense[row * cw..][..cw]);
11711+ }
11712+ let mut pred_v_dense = vec![0u16; cw * ch];
11713+ mc::predict_with_filter(
11714+ &v.data, v.width, v.true_width, v.true_height,
11715+ mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false),
11716+ cw, ch, mc::InterpFilterKind::Bilinear, &mut pred_v_dense, fctx,
11717+ );
11718+ let mut pred_v = vec![0u16; cside * cside];
11719+ for row in 0..ch {
11720+ pred_v[row * cside..][..cw].copy_from_slice(&pred_v_dense[row * cw..][..cw]);
11721+ }
11722+ let (luma_grid, u_grid, v_grid);
11723+ // lane-av1-ibcrect: whether the coded arm stamped its CHROMA neighbour
11724+ // contexts per transform unit -- the replay after this fn's end-of-block
11725+ // record restores them (the record itself re-stamps both planes with ONE
11726+ // composed state, class `override-slot-on-one-arm`).
11727+ let mut mu_chroma = false;
11728+ if skip {
11729+ // No residual syntax at all: the prediction IS the block. Strides are
11730+ // `side`/`cside`, not `bw` -- `reconstruct_mc_rect` indexes
11731+ // `row * stride + w` for row in 0..h (the r5 VERT-strip overrun).
11732+ push_mc_rect(0, px, py, side, bw, bh, Pred::Inline(&pred_y, side), &ZERO_RESIDUAL[..side * side], fctx);
11733+ push_mc_rect(1, cpx, cpy, cside, cw, ch, Pred::Inline(&pred_u, cside), &ZERO_RESIDUAL[..cside * cside], fctx);
11734+ push_mc_rect(2, cpx, cpy, cside, cw, ch, Pred::Inline(&pred_v, cside), &ZERO_RESIDUAL[..cside * cside], fctx);
11735+ if let Some(ls) = leaves.as_ref() {
11736+ // A LOSSLESS frame's `read_block_tx_size_rect` resolves the TX_4X4
11737+ // grid before it looks at `skip`; the skipped block still zeroes
11738+ // its entropy-band footprint over every unit (libaom
11739+ // `av1_reset_entropy_context` under `if (mbmi->skip_txfm)`) --
11740+ // the same arm [`decode_intrabc_rect`]'s loss64 merge added.
11741+ hit!(SKIP_LOSSLESS_BAND_RESET_HITS);
11742+ for &(row, col, tw, th) in ls {
11743+ neighbours.record_mi_luma_rect(
11744+ (mi_r + row, mi_c + col),
11745+ tw,
11746+ th,
11747+ &ZERO_RESIDUAL[..tw * th],
11748+ );
11749+ }
11750+ }
11751+ luma_grid = Grid::Zero(side * side);
11752+ u_grid = Grid::Zero(cside * cside);
11753+ v_grid = Grid::Zero(cside * cside);
11754+ } else {
11755+ let leaves = leaves.expect(
11756+ "read_block_tx_size_rect returns None only for skip below 128 at this shape",
11757+ );
11758+ // libaom `get_transform_size`'s split override applies to LUMA only,
11759+ // per leaf -- each unit's own transform edges get filtered
11760+ // ([`decode_intrabc_rect`]'s P2, the proven inter path's step).
11761+ for &(row, col, tw, th) in leaves.iter() {
11762+ neighbours.fill_lf_grid_leaf_luma(
11763+ (mi_r + row, mi_c + col),
11764+ tw / MI,
11765+ th / MI,
11766+ tw as u8,
11767+ th as u8,
11768+ );
11769+ }
11770+ let reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get);
11771+ let mut u_units: Vec<i32> = Vec::new();
11772+ let mut v_units: Vec<i32> = Vec::new();
11773+ let mut leaf_tx_types: Vec<(usize, usize, usize, usize, TxType)> = Vec::new();
11774+ // Frame-edge clip of the mu walk (`max_block_wide/high`): a unit whose
11775+ // top-left sample is outside the frame codes nothing.
11776+ let max_w_mi = (bw / MI).min(mi_cols.saturating_sub(mi_c));
11777+ let max_h_mi = (bh / MI).min(mi_rows.saturating_sub(mi_r));
11778+ for (idx, &(row, col, tw, th)) in leaves.iter().enumerate() {
11779+ debug_assert_eq!(tw, th, "a square TX_64X64 tree root only yields square leaves");
11780+ let tu_mi = (mi_r + row, mi_c + col);
11781+ let (tu_px, tu_py) = (px + col * MI, py + row * MI);
11782+ if tu_px >= y.true_width || tu_py >= y.true_height {
11783+ continue;
11784+ }
11785+ let tu_pred = Pred::Inline(&pred_y, side).offset(row * MI * side + col * MI);
11786+ let scan = default_scan(tw.min(32));
11787+ let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tw / MI);
11788+ let (tu_grid, tu_tx_type) = read_inter_plane(
11789+ dec,
11790+ cdfs,
11791+ inter_txbset_for(tw, reduced),
11792+ &scan,
11793+ 0,
11794+ neighbours.around_mi(tu_mi, tw)[0],
11795+ 0,
11796+ y,
11797+ tu_px,
11798+ tu_py,
11799+ tw,
11800+ base_q_idx,
11801+ tu_pred,
11802+ None,
11803+ Some(tu_skip_ctx), fctx,
11804+ )?;
11805+ leaf_tx_types.push((row, col, tw, th, tu_tx_type));
11806+ neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid);
11807+ // libaom `decode_token_recon_block` codes EVERY PLANE of a 64x64
11808+ // mu chunk before the next one starts: once this chunk's leaves
11809+ // are done, its chroma is read immediately (the inter 128 path's
11810+ // interleave).
11811+ let chunk = (row / 16, col / 16);
11812+ let done = idx + 1 == leaves.len()
11813+ || (leaves[idx + 1].0 / 16, leaves[idx + 1].1 / 16) != chunk;
11814+ if done {
11815+ let (cr, cc) = chunk;
11816+ // `av1_get_max_uv_txsize(BLOCK_128X64)` = TX_32X32: one
11817+ // TX_32X32 chroma unit per plane per chunk at 4:2:0, raster
11818+ // within the chunk, plane-major inside the chunk.
11819+ let cu_tx = 32usize;
11820+ let chunk_chroma = cside * 64 / side;
11821+ let unit_luma = cu_tx * (side / cside);
11822+ let chunk_w_mi = 16.min(max_w_mi.saturating_sub(cc * 16));
11823+ let chunk_h_mi = 16.min(max_h_mi.saturating_sub(cr * 16));
11824+ let units_x = chunk_w_mi / (unit_luma / MI);
11825+ let units_y = chunk_h_mi / (unit_luma / MI);
11826+ if lossless(fctx) {
11827+ // TX_4X4 chroma units over this chunk (lane-lossless2's
11828+ // walk, shared with the inter 128 path).
11829+ read_inter_chroma_lossless(
11830+ dec, cdfs, neighbours, u, v,
11831+ Pred::Inline(&pred_u, cside), Pred::Inline(&pred_v, cside),
11832+ (mi_r, mi_c), (cpx, cpy),
11833+ (cc * chunk_chroma, cr * chunk_chroma),
11834+ (chunk_chroma, chunk_chroma),
11835+ (cw, ch),
11836+ cside, 0, base_q_idx,
11837+ &mut u_units, &mut v_units, fctx,
11838+ )?;
11839+ // lane-av1-ibcrect: read_inter_chroma_lossless stamped
11840+ // every TX_4X4 unit's own context (`record_mi_chroma`
11841+ // inside the walk) -- the end-of-block record below must
11842+ // not overwrite them with the composed grid (the inter
11843+ // 128 path sets the same flag on this arm).
11844+ mu_chroma = true;
11845+ continue;
11846+ }
11847+ let cu_scan = default_scan(cu_tx);
11848+ for plane_idx in 1..3 {
11849+ let (src, buf) = if plane_idx == 1 {
11850+ (Pred::Inline(&pred_u, cside), &mut *u)
11851+ } else {
11852+ (Pred::Inline(&pred_v, cside), &mut *v)
11853+ };
11854+ for ur in 0..units_y {
11855+ for uc in 0..units_x {
11856+ let unit_mi = (
11857+ mi_r + cr * 16 + ur * (unit_luma / MI),
11858+ mi_c + cc * 16 + uc * (unit_luma / MI),
11859+ );
11860+ // Per unit, AFTER the earlier units' stamps: this
11861+ // unit's coefficient context must see them.
11862+ let cu_around = neighbours.around_mi(unit_mi, unit_luma);
11863+ if crate::envflags::env_flag!("EC_ECDUMP") {
11864+ for p in 1..3 {
11865+ let ab: Vec<String> = (0..unit_luma / MI)
11866+ .map(|k| {
11867+ format!(
11868+ "{:?}/{}",
11869+ neighbours.above[unit_mi.1 + k][p].dc,
11870+ neighbours.above[unit_mi.1 + k][p].level
11871+ )
11872+ })
11873+ .collect();
11874+ let lf: Vec<String> = (0..unit_luma / MI)
11875+ .map(|k| {
11876+ format!(
11877+ "{:?}/{}",
11878+ neighbours.left[unit_mi.0 + k][p].dc,
11879+ neighbours.left[unit_mi.0 + k][p].level
11880+ )
11881+ })
11882+ .collect();
11883+ eprintln!(
11884+ "EC_IBC128_BANDS mi=({mi_r},{mi_c}) unit=({cr},{cc}) plane={p} ctx=({},{},{}) above=[{}] left=[{}]",
11885+ cu_around[p].0, cu_around[p].1, cu_around[p].2, ab.join(","), lf.join(",")
11886+ );
11887+ }
11888+ }
11889+ let (cu_x, cu_y) = (
11890+ cpx + cc * chunk_chroma + uc * cu_tx,
11891+ cpy + cr * chunk_chroma + ur * cu_tx,
11892+ );
11893+ // `av1_get_tx_type` (blockd.h:1291): an inter
11894+ // block's chroma unit never codes a tx_type; it
11895+ // inherits the coded type of the luma leaf
11896+ // covering its own quadrant (all of this chunk's
11897+ // leaves are read by now).
11898+ let unit_rel_mi = (
11899+ unit_mi.0 - mi_r,
11900+ unit_mi.1 - mi_c,
11901+ );
11902+ let covering = leaf_tx_types
11903+ .iter()
11904+ .copied()
11905+ .find(|&(lr, lc, lw, lh, _)| {
11906+ lr <= unit_rel_mi.0
11907+ && unit_rel_mi.0 < lr + lh / MI
11908+ && lc <= unit_rel_mi.1
11909+ && unit_rel_mi.1 < lc + lw / MI
11910+ })
11911+ .map(|(_, _, _, _, t)| t);
11912+ let cu_pred = src.offset(
11913+ (cr * chunk_chroma + ur * cu_tx) * cside
11914+ + cc * chunk_chroma
11915+ + uc * cu_tx,
11916+ );
11917+ let cu_grid = read_inter_plane(
11918+ dec,
11919+ cdfs,
11920+ TxbSet::Chroma32,
11921+ &cu_scan,
11922+ plane_idx,
11923+ cu_around[plane_idx],
11924+ 0,
11925+ buf,
11926+ cu_x,
11927+ cu_y,
11928+ cu_tx,
11929+ base_q_idx,
11930+ cu_pred,
11931+ Some(covering.unwrap_or(TxType::DctDct)),
11932+ Some(3), fctx,
11933+ )?
11934+ .0;
11935+ // Immediately, so the NEXT unit reads this one's
11936+ // coefficient context.
11937+ neighbours.record_mi_chroma(
11938+ unit_mi,
11939+ unit_luma,
11940+ unit_luma,
11941+ plane_idx,
11942+ &cu_grid,
11943+ );
11944+ if crate::envflags::env_flag!("EC_ECDUMP") {
11945+ let st = crate::decode::neighbour_state(&cu_grid);
11946+ eprintln!(
11947+ "EC_IBC128_STAMP mi=({mi_r},{mi_c}) unit=({cr},{cc}) plane={plane_idx} state=({:?},{})",
11948+ st.dc, st.level
11949+ );
11950+ }
11951+ hit!(CHROMA_SPLIT_TX_HITS);
11952+ // lane-av1-ibcrect: per-unit chroma context -- the
11953+ // end-of-block record's composed-grid re-stamp
11954+ // must not stand (replayed below).
11955+ mu_chroma = true;
11956+ let dst = mu_units(
11957+ if plane_idx == 1 { &mut u_units } else { &mut v_units },
11958+ cside * cside,
11959+ );
11960+ for rr in 0..cu_tx {
11961+ let start = (cr * chunk_chroma + ur * cu_tx + rr)
11962+ * cside
11963+ + cc * chunk_chroma
11964+ + uc * cu_tx;
11965+ dst[start..start + cu_tx]
11966+ .copy_from_slice(&cu_grid[rr * cu_tx..][..cu_tx]);
11967+ }
11968+ }
11969+ }
11970+ }
11971+ }
11972+ }
11973+ // The block-level luma bands were recorded per leaf above; the
11974+ // composed chroma grids carry every unit in place.
11975+ luma_grid = Grid::Zero(side * side);
11976+ u_grid = if u_units.is_empty() {
11977+ Grid::Zero(cside * cside)
11978+ } else {
11979+ Grid::Own(std::mem::take(&mut u_units))
11980+ };
11981+ v_grid = if v_units.is_empty() {
11982+ Grid::Zero(cside * cside)
11983+ } else {
11984+ Grid::Own(std::mem::take(&mut v_units))
11985+ };
11986+ }
11987+ // Bookkeeping (see [`decode_intrabc_rect`]): DC_PRED everywhere a
11988+ // neighbour reads a mode, zeroed palette state, the skip grid, the
11989+ // TXFM_CONTEXT bands (`read_block_tx_size_rect` already stamped them),
11990+ // and the DV into the intrabc mi grid.
11991+ if skip {
11992+ neighbours.record_rect_mi(
11993+ (mi_r, mi_c), bw, bh, DC_PRED, DC_PRED,
11994+ &[&luma_grid[..], &u_grid[..], &v_grid[..]],
11995+ );
11996+ } else {
11997+ neighbours.record_split_luma_rect_mi(
11998+ (mi_r, mi_c), bw, bh, DC_PRED, DC_PRED, [&u_grid[..], &v_grid[..]],
11999+ );
12000+ }
12001+ // lane-av1-ibcrect: the coded arm's chroma contexts were stamped PER
12002+ // TRANSFORM UNIT (libaom `av1_set_entropy_contexts` inside
12003+ // `decode_reconstruct_tx`'s mu-chunk loop), but the record above re-stamps
12004+ // both planes with ONE `neighbour_state(composed_grid)` over the whole
12005+ // span -- level = the SUM of every unit's levels and dc = the top-left
12006+ // unit's sign (lane-vert46 r1 measured the same smearing at the 64x128
12007+ // inter block: the next block read a stale `dc_sign_ctx` one row low).
12008+ // Measured on this shape: the 128x64 block at mi(64,32) of the
12009+ // `ibcrect-hunt/E2` sb128 screen stream left chunk-1 U's level 1 smeared
12010+ // into chunk-0's cells and the block below read `txb_skip` off the sum.
12011+ // Replay every coded unit's own state after the record, in mu-chunk order
12012+ // so a later unit still wins over an earlier one on the shared seam cells
12013+ // (the composed construction `mu_chroma_units` uses, transcribed here).
12014+ if mu_chroma {
12015+ let cu = if lossless(fctx) { 4usize } else { 32usize };
12016+ // The unit's own footprint on the LUMA mi grid (the chroma context
12017+ // bands are luma-mi indexed, [`Self::record_mi_chroma`]'s
12018+ // convention): 8 px x2 per TX_4X4 unit, 64 px per TX_32X32 one.
12019+ let unit_luma = cu * 2;
12020+ // Raster over the block's chroma plane, `chunk_chroma` per mu chunk
12021+ // (the same extents the read loop above laid the composed grid out
12022+ // at) -- a unit the frame edge clipped codes nothing and carries no
12023+ // composed samples beyond the clip, so it replays as the zero state
12024+ // exactly like libaom's uncoded unit.
12025+ let chunk_chroma = cside * 64 / side;
12026+ let (rows, cols) = ((ch / chunk_chroma).max(1), (cw / chunk_chroma).max(1));
12027+ for cr in 0..rows {
12028+ for cc in 0..cols {
12029+ let unit_mi = (mi_r + cr * (unit_luma / MI), mi_c + cc * (unit_luma / MI));
12030+ for (plane_idx, grid) in [(1usize, &u_grid), (2usize, &v_grid)] {
12031+ let mut unit = Vec::with_capacity(cu * cu);
12032+ for rr in 0..cu {
12033+ let start =
12034+ (cr * chunk_chroma + rr) * cside + cc * chunk_chroma;
12035+ unit.extend_from_slice(&grid[start..start + cu]);
12036+ }
12037+ neighbours.record_mi_chroma(
12038+ unit_mi, unit_luma, unit_luma, plane_idx, &unit,
12039+ );
12040+ }
12041+ }
12042+ }
12043+ }
12044+ neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, 0, [0u16; 8]);
12045+ neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, 0, [0u16; 8]);
12046+ neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip);
12047+ neighbours.fill_lf_grid_rect(
12048+ (mi_r, mi_c),
12049+ bw / MI,
12050+ bh / MI,
12051+ bw.min(64) as u8,
12052+ bh.min(64) as u8,
12053+ 0, fctx,
12054+ );
12055+ record_intrabc_mi_rect(
12056+ mi_r,
12057+ mi_c,
12058+ bw / MI,
12059+ bh / MI,
12060+ Some((dv_row, dv_col)),
12061+ neighbours,
12062+ fctx,
12063+ );
12064+ Ok(())
12065+}
12066+
1160512067 /// Decodes one true `bw`x`bh` `PARTITION_HORZ`/`PARTITION_VERT` intra strip
1160612068 /// (lane-intradisp r1, spec `decode_block` restricted to a 32x32 quadrant's
1160712069 /// two rect children). Only the `skip` case is supported: `skip`/`y_mode`/
@@ -16798,10 +17260,24 @@ fn decode_block_128rect(
1679817260 mi_r,
1679917261 mi_c, fctx,
1680017262 )?;
16801- if intrabc.is_some() {
16802- return Err(unsupported(
16803- "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)",
16804- ));
17263+ if let Some((dv_row, dv_col)) = intrabc {
17264+ // lane-av1-ibcrect: the reconstruction is ported -- an intrabc block
17265+ // is is_inter_block, so libaom predicts the whole 128x64/64x128 strip
17266+ // from this frame's own reconstruction and runs the INTER residual
17267+ // walk (`decode_token_recon_block`'s else arm) over it.
17268+ return decode_intrabc_128rect(
17269+ dec,
17270+ cdfs,
17271+ neighbours,
17272+ (mi_r, mi_c),
17273+ (bw, bh),
17274+ skip,
17275+ (dv_row, dv_col),
17276+ y,
17277+ u,
17278+ v,
17279+ base_q_idx, fctx,
17280+ );
1680517281 }
1680617282 if alpha.is_some() || filter_intra.is_some() || palette_y.is_some() || palette_uv.is_some() {
1680717283 return Err(unsupported(
crates/ec-av1/src/refusal_inventory.rsmodified+15 -10
@@ -69,7 +69,15 @@ const REFUSALS: &[&str] = &[
6969 // reader a real ctx/cache pair, so no stream could reach either (audit
7070 // `every_read_intra_mode_call_site_hands_the_reader_a_palette_cache`,
7171 // which keeps that invariant now the refusal is gone).
72- "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)",
72+ // lane-av1-ibcrect: `intra block copy on a HORZ/VERT/1:4 rect intra strip
73+ // (reconstruction is not ported at this shape)` is GONE -- lane-av1-intrabc
74+ // and lane-av1-rect14 reconstructed the 16x16/32x32-level strips, and this
75+ // lane ported the last site, `decode_block_128rect`'s 128-root HORZ/VERT
76+ // strip (`decode_intrabc_128rect`; a 128 root has no 1:4 arm at all).
77+ // Witness:
78+ // `an_sb128_rect_strip_with_intrabc_decodes_pixel_exact` (real aomenc
79+ // sb128 screen streams coding `use_intrabc` on BLOCK_128X64 strips,
80+ // pixel-exact vs ffmpeg).
7381 // lane-av1txr: `a sub-8x8 leaf that uses intrabc (…)` is GONE -- the
7482 // capability landed in this lane (4x4 / 4x8 / 8x4 intrabc leaves read the
7583 // DV and reconstruct a frame copy + the INTER residual; gates
@@ -397,15 +405,12 @@ const PROVEN: &[(&str, &str)] = &[
397405 "a frame using quantisation matrices (using_qmatrix=1): dequantisation here is base_q_idx plus the plane DC/AC deltas only, so qm_y/qm_u/qm_v would be ignored and the frame would decode silently wrong pixels",
398406 "a_frame_using_quantisation_matrices_is_refused_by_name",
399407 ),
400- // lane-av1-rect14: the 16x16- and 32x32-level strips are reconstructed
401- // (`decode_intrabc_rect` / `decode_intrabc_pair_strip`). The string remains
402- // only in `decode_block_128rect`. No sb128 screen recipe in this lane
403- // reached that arm (256x192 cq50 sb128 decoded without entering it), so
404- // the pairing still names the rect-strip gate, which no longer refuses.
405- (
406- "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)",
407- "a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips",
408- ),
408+ // lane-av1-ibcrect: the pairing for "intra block copy on a HORZ/VERT/1:4
409+ // rect intra strip (reconstruction is not ported at this shape)" is GONE
410+ // with the string -- lane-av1-intrabc/rect14 reconstructed the
411+ // 16x16/32x32-level strips and this lane ported the last site,
412+ // `decode_block_128rect`'s 128-root strip. Witness:
413+ // `an_sb128_rect_strip_with_intrabc_decodes_pixel_exact`.
409414 // lane-t900 r26, enumeration: a y_mode symbol comes from a 13-symbol CDF
410415 // and all three guards refuse 13 and above.
411416 (
crates/ec-av1/src/stream.rsmodified+200 -0
@@ -191,6 +191,30 @@ pub fn sb128_rect_counters() -> (usize, usize, usize, usize) {
191191 )
192192 }
193193
194+/// lane-av1-ibcrect: the 128 root's interior partition arms plus the key-frame
195+/// intra 128-axis blocks -- (split, none, horz, vert, ab[4], intra_horz,
196+/// intra_vert). Non-zero horz/vert mean a stream carried real PARTITION_HORZ/
197+/// VERT at the 128 root, so an intrabc-rect hunt can tell "the partition was
198+/// never chosen" from "chosen and decoded intra (or refused)".
199+pub fn part128_census() -> (usize, usize, usize, usize, [usize; 4], usize, usize) {
200+ (
201+ crate::decode::part128_split_hits(),
202+ crate::decode::part128_none_hits(),
203+ crate::decode::part128_horz_hits(),
204+ crate::decode::part128_vert_hits(),
205+ crate::decode::part128_ab_hits(),
206+ crate::decode::intra_sb128_hits().0,
207+ crate::decode::intra_sb128_hits().1,
208+ )
209+}
210+
211+/// lane-av1-ibcrect: `use_intrabc` blocks on a 128-root HORZ/VERT strip whose
212+/// reconstruction ([`crate::decode::decode_intrabc_128rect`]) ran -- the
213+/// engagement counter the sb128 intrabc-rect gate asserts on.
214+pub fn intrabc_128rect_hits() -> usize {
215+ crate::decode::intrabc_128rect_hits()
216+}
217+
194218 /// Blocks reconstructed with intra block copy at an 8x8 LEAF specifically
195219 /// (lane-kf900 r7's shape); [`crate::decode::intrabc_hits`] counts every shape.
196220 pub fn leaf8_intrabc_hits() -> usize {
@@ -7518,6 +7542,182 @@ pub(crate) mod tests {
75187542 );
75197543 }
75207544
7545+ /// lane-av1-ibcrect: `use_intrabc` on a 128-root HORZ/VERT strip
7546+ /// (BLOCK_128X64 / BLOCK_64X128) decodes PIXEL-EXACT against the
7547+ /// instrumented oracle -- the witness the refusal inventory names after
7548+ /// `decode_block_128rect`'s rect-strip intrabc refusal was lifted
7549+ /// (`decode_intrabc_128rect`). The square-block twin is
7550+ /// [`an_sb128_screen_stream_with_intrabc_decodes_pixel_exact`] above.
7551+ ///
7552+ /// The recipes are the hunt's proven arms (lanes/ibcrect r1/r2, the same
7553+ /// `--sb-size=128 --min-partition-size=64 --enable-rect-partitions=1
7554+ /// --enable-ab-partitions=0 --enable-1to4-partitions=0` partition recipe
7555+ /// [`a_real_aomenc_sb128_intra_rect_block_decodes_pixel_exact`] uses, plus
7556+ /// `--tune-content=screen --enable-intrabc=1` over the DETERMINISTIC geq
7557+ /// sinusoid sources -- lavfi `gradients` ignores its seed and re-rolls
7558+ /// every run, so a "flake" there was really this):
7559+ ///
7560+ /// * HORZ arm: 384x320 cq32, 5 all-key frames -- 14 unskipped 128x64
7561+ /// intrabc blocks (`skip=false`, real residual reads);
7562+ /// * VERT arm: 512x512 cq45, 5 all-key frames -- an unskipped 64x128
7563+ /// intrabc block at mi(64,96).
7564+ ///
7565+ /// Both arms HARD-assert `intrabc_128rect_hits() > 0` and decode-order
7566+ /// pixel-exactness of EVERY frame (hidden alt-refs included) against the
7567+ /// oracle's own dump, so a stream that stopped engaging the shape fails
7568+ /// the gate instead of passing vacuously (class `gate-blind-to-feature`).
7569+ ///
7570+ /// The 10-bit arm engages the shape. Hunt r2 and the witness re-run both
7571+ /// measured `intrabc_128rect_hits` +15 on arm 3, so aomenc does take a
7572+ /// 128-root HORZ/VERT strip at 10 bit under this recipe. There is no
7573+ /// per-depth coverage gap to print. The gate's hard asserts already
7574+ /// cover that arm.
7575+ ///
7576+ /// The chroma context this shape reads was the r2 defect: per-unit chroma
7577+ /// entropy states were stamped inside the mu-chunk loop, then the
7578+ /// end-of-block `record_split_luma_rect_mi` re-stamped BOTH planes over
7579+ /// the whole 128x64 span with ONE composed state -- level = the SUM of
7580+ /// both 64x64 chunks' units, dc = chunk-0's top-left (class
7581+ /// `override-slot-on-one-arm`; the inter-128 path fixed the same class
7582+ /// with its `mu_chroma_units` replay, decode.rs). The next block then
7583+ /// read `txb_skip` off the smeared state.
7584+ #[test]
7585+ fn an_sb128_rect_strip_with_intrabc_decodes_pixel_exact() {
7586+ const NAME: &str = "an_sb128_rect_strip_with_intrabc_decodes_pixel_exact";
7587+ let _gate_lock = lock_gate_counters();
7588+ if !have_ffmpeg() {
7589+ eprintln!("SKIP {NAME}: no ffmpeg");
7590+ return;
7591+ }
7592+ if !have_aomenc() {
7593+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
7594+ return;
7595+ }
7596+ // (tag, width, height, cq, geq luma, 10-bit)
7597+ // The geq sources are the hunt's GEO_SMOOTH / GEO_SMOOTH_512,
7598+ // byte-identical across runs (see the sb128 intra-rect gate's note).
7599+ let arms: [(u32, usize, usize, &str, &str, bool); 3] = [
7600+ (
7601+ 1,
7602+ 384,
7603+ 320,
7604+ "32",
7605+ "128+90*sin((X+2*N)/37)+30*sin(Y/29)",
7606+ false,
7607+ ),
7608+ (
7609+ 2,
7610+ 512,
7611+ 512,
7612+ "45",
7613+ "128+80*sin((X+3*N)/17)+50*sin(Y/29)+30*sin((X+Y)/13)",
7614+ false,
7615+ ),
7616+ (3, 384, 320, "32", "128+90*sin((X+2*N)/37)+30*sin(Y/29)", true),
7617+ ];
7618+ let mut engaged_arms = 0u32;
7619+ let mut vert_arms = 0u32;
7620+ for (tag, width, height, cq, lum, ten_bit) in arms {
7621+ let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" };
7622+ let y4m = Command::new("ffmpeg")
7623+ .args([
7624+ "-v",
7625+ "error",
7626+ "-f",
7627+ "lavfi",
7628+ "-i",
7629+ &format!(
7630+ "nullsrc=size={width}x{height}:rate=25,format=yuv420p,\
7631+ geq=lum='{lum}':\
7632+ cb='128+30*sin(X/23)':cr='128+30*sin((Y+N)/19)'"
7633+ ),
7634+ "-pix_fmt",
7635+ pix,
7636+ "-strict",
7637+ "-1",
7638+ "-t",
7639+ "0.2",
7640+ "-f",
7641+ "yuv4mpegpipe",
7642+ "-",
7643+ ])
7644+ .stdin(Stdio::null())
7645+ .stdout(Stdio::piped())
7646+ .stderr(Stdio::piped())
7647+ .output()
7648+ .expect("ffmpeg failed to run");
7649+ assert!(
7650+ y4m.status.success(),
7651+ "{NAME}: ffmpeg fixture: {}",
7652+ String::from_utf8_lossy(&y4m.stderr)
7653+ );
7654+ let cq_arg = format!("--cq-level={cq}");
7655+ let mut args: Vec<&str> = vec![
7656+ "--codec=av1",
7657+ "--passes=1",
7658+ "--end-usage=q",
7659+ &cq_arg,
7660+ "--cpu-used=0",
7661+ "--threads=1",
7662+ "--row-mt=0",
7663+ "--lag-in-frames=0",
7664+ "--kf-max-dist=1",
7665+ "--limit=5",
7666+ "--tile-columns=0",
7667+ "--sb-size=128",
7668+ "--min-partition-size=64",
7669+ "--enable-rect-partitions=1",
7670+ "--enable-ab-partitions=0",
7671+ "--enable-1to4-partitions=0",
7672+ "--enable-palette=0",
7673+ "--tune-content=screen",
7674+ "--enable-intrabc=1",
7675+ "--deltaq-mode=0",
7676+ "--enable-tx-size-search=0",
7677+ ];
7678+ if ten_bit {
7679+ args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]);
7680+ }
7681+ args.extend_from_slice(&["--obu", "-o", "-", "-"]);
7682+ let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
7683+ assert!(
7684+ out.status.success(),
7685+ "{NAME}: aomenc refused the arm {tag} fixture: {}",
7686+ String::from_utf8_lossy(&out.stderr)
7687+ );
7688+ let stream = out.stdout;
7689+ let before = crate::decode::intrabc_128rect_hits();
7690+ let (frames, hidden) = decode_all_frames_vs_oracle(
7691+ &stream,
7692+ &format!("ibcrect-strip-{tag}-{width}x{height}"),
7693+ );
7694+ let hits = crate::decode::intrabc_128rect_hits() - before;
7695+ eprintln!(
7696+ "{NAME}: arm {tag} {width}x{height} cq={cq} {}bit: {frames} decode-order frames \
7697+ pixel-exact ({hidden} hidden), intrabc_128rect_hits=+{hits}",
7698+ if ten_bit { 10 } else { 8 },
7699+ );
7700+ if hits > 0 {
7701+ engaged_arms += 1;
7702+ // The VERT arm is tag 2; its engagement is what proves the
7703+ // 64x128 orientation, not just 128x64.
7704+ if tag == 2 {
7705+ vert_arms += 1;
7706+ }
7707+ }
7708+ }
7709+ assert!(
7710+ engaged_arms > 0,
7711+ "{NAME}: {engaged_arms} arm(s) decoded pixel-exact but NOT ONE decoded a 128-root \
7712+ rect-strip intrabc block -- the shape this gate exists for was never engaged"
7713+ );
7714+ assert!(
7715+ vert_arms > 0,
7716+ "{NAME}: the VERT (64x128) orientation was never engaged -- only 128x64 HORZ strips \
7717+ proved the lift"
7718+ );
7719+ }
7720+
75217721 /// lane-t900 r33, CENSUS for "a sub-8x8 leaf that uses intrabc".
75227722 ///
75237723 /// The `use_intrabc` symbol IS read at that reader for every sub-8x8 leaf