forge
Explore
Log in

Don't you dare go Hollow

ec-av1: intrabc on HORZ/VERT 2:1 rect strips reconstructs (decode_intrabc_rect)

Browse files at this commit

a4e3e6ece7ee66408a5ee1e99879cf0686655817Ahmet Kaan GümüşParent: dcbe6ff
The rect-strip intrabc refusal is lifted for the 2:1 shapes: whole-block
prediction (luma + both chroma planes at av1_get_max_uv_txsize), skip and
per-transform-unit residual readers over the real rect tables, and the same
bookkeeping shape as the square intrabc path (DC_PRED mode, coefficient
contexts, zeroed palette state, skip/LF grids, DV into the intrabc mi grid).

Witnesses: the key-frame gate's testsrc2-cq50-txs0 arm (flipped from a
refusal pin to a witness -- 1 rect-strip intrabc block, pixel-exact vs
ffmpeg) plus standalone recipes exercising 16x8 (residual, skip=0), 8x32
through decode_block_rect4, and a 16x8+8x32 pair.

Still named: the 1:4 pair strips (their chroma comes from the pair's
top-left mi and its coefficient state spans the pair) and the mixed-leaf
var-tx square path (census-pinned unreachable).
crates/ec-av1/examples/decode_probe.rsmodified+5 -0
@@ -48,6 +48,11 @@ fn main() {
48 );48 );
49 println!("leaf8_intrabc_hits: {}", ec_av1::stream::leaf8_intrabc_hits());49 println!("leaf8_intrabc_hits: {}", ec_av1::stream::leaf8_intrabc_hits());
50 println!("intrabc_hits: {}", ec_av1::stream::intrabc_hits());50 println!("intrabc_hits: {}", ec_av1::stream::intrabc_hits());
51+ println!(
52+ "intrabc_rect: {} (var-tx tree: {})",
53+ ec_av1::decode::intrabc_rect_hits(),
54+ ec_av1::decode::intrabc_rect_vartx_hits()
55+ );
51 let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters();56 let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters();
52 println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}");57 println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}");
53 println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits());58 println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits());
crates/ec-av1/src/decode.rsmodified+393 -6
@@ -3711,6 +3711,32 @@ thread_local! {
3711 /// signal a transform size where a plain `BLOCK_4X4` does not. Reading no3711 /// signal a transform size where a plain `BLOCK_4X4` does not. Reading no
3712 /// symbol here desynced `warped.obu` at the very next block.3712 /// symbol here desynced `warped.obu` at the very next block.
3713 static RECT_INTRABC_VARTX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };3713 static RECT_INTRABC_VARTX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3714+ /// lane-av1-intrabc: rect INTRABC blocks whose reconstruction
3715+ /// [`decode_intrabc_rect`] ran -- the engagement counter the rect-strip
3716+ /// gates assert on (a refused block bumps [`INTRABC_HITS`] but never
3717+ /// this one).
3718+ static INTRABC_RECT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3719+ /// Of those, how many read the INTER var-tx tree (unskipped, TX_MODE_SELECT).
3720+ static INTRABC_RECT_VARTX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3721+}
3722+
3723+/// Current value of [`INTRABC_RECT_HITS`].
3724+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3725+pub fn intrabc_rect_hits() -> usize {
3726+ INTRABC_RECT_HITS.with(|c| c.get())
3727+}
3728+
3729+/// Zeroes [`INTRABC_RECT_HITS`]/[`INTRABC_RECT_VARTX_HITS`].
3730+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3731+pub(crate) fn reset_intrabc_rect_hits() {
3732+ INTRABC_RECT_HITS.with(|c| c.set(0));
3733+ INTRABC_RECT_VARTX_HITS.with(|c| c.set(0));
3734+}
3735+
3736+/// Current value of [`INTRABC_RECT_VARTX_HITS`].
3737+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3738+pub fn intrabc_rect_vartx_hits() -> usize {
3739+ INTRABC_RECT_VARTX_HITS.with(|c| c.get())
3714 }3740 }
3715 3741
3716 /// Current value of [`INTRABC_VARTX_HITS`].3742 /// Current value of [`INTRABC_VARTX_HITS`].
@@ -9148,6 +9174,14 @@ fn read_intra_mode_rect(
9148 Option<usize>,9174 Option<usize>,
9149 Option<PaletteY>,9175 Option<PaletteY>,
9150 Option<PaletteUv>,9176 Option<PaletteUv>,
9177+ // lane-av1-intrabc: the block vector, `Some` exactly when this block's
9178+ // `use_intrabc` symbol came out 1 -- libaom's `read_intrabc_info` returns
9179+ // straight out of `read_intra_frame_mode_info` then, so every later field
9180+ // of the tuple is at its default (mode/uv_mode DC, no angle, no palette,
9181+ // no filter intra). A caller that can reconstruct intrabc at its shape
9182+ // takes this and calls [`decode_intrabc_rect`]; one that cannot refuses by
9183+ // name with the same string it always did.
9184+ Option<(i32, i32)>,
9151 )> {9185 )> {
9152 // lane-av1mono: libaom guards every chroma symbol read with9186 // lane-av1mono: libaom guards every chroma symbol read with
9153 // `!cm->seq_params->monochrome && xd->is_chroma_ref` (`decodemv.c:933`),9187 // `!cm->seq_params->monochrome && xd->is_chroma_ref` (`decodemv.c:933`),
@@ -9226,8 +9260,22 @@ fn read_intra_mode_rect(
9226 istep!("intrabc", use_intrabc as i32);9260 istep!("intrabc", use_intrabc as i32);
9227 if use_intrabc {9261 if use_intrabc {
9228 hit!(INTRABC_HITS);9262 hit!(INTRABC_HITS);
9229- return Err(unsupported(9263+ // libaom `read_intrabc_info`: the DV read, then an immediate
9230- "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)",9264+ // return out of the mode-info read -- no `y_mode`, no `uv_mode`,
9265+ // no angle deltas, no palette, no filter intra. The caller owns
9266+ // the reconstruction at its own shape.
9267+ let dv = read_intrabc_dv(dec, cdfs, mi_r, mi_c, (bw / MI, bh / MI), fctx);
9268+ return Ok((
9269+ skip,
9270+ DC_PRED,
9271+ 0,
9272+ DC_PRED,
9273+ 0,
9274+ None,
9275+ None,
9276+ None,
9277+ None,
9278+ Some(dv),
9231 ));9279 ));
9232 }9280 }
9233 }9281 }
@@ -9379,6 +9427,7 @@ fn read_intra_mode_rect(
9379 filter_intra,9427 filter_intra,
9380 palette_y,9428 palette_y,
9381 palette_uv,9429 palette_uv,
9430+ None,
9382 ))9431 ))
9383 }9432 }
9384 9433
@@ -10835,6 +10884,286 @@ fn decode_intra_rect_in_inter(
10835 Ok(())10884 Ok(())
10836 }10885 }
10837 10886
10887+/// Reconstructs one rectangular INTRABC block, `bw`x`bh` pixels at the real
10888+/// mi `(mi_r, mi_c)` (lane-av1-intrabc).
10889+///
10890+/// libaom treats an intrabc block as INTER for everything except the mode-info
10891+/// read itself: `is_inter_block` is `is_intrabc_block(mbmi) || ref > INTRA`
10892+/// (`blockd.h:373`), so
10893+///
10894+/// * `parse_decode_block` reads the transform size through the INTER var-tx
10895+/// tree (`read_tx_size_vartx`) -- [`read_block_tx_size_rect`], whose
10896+/// `txfm_partition` context comes off the real `TXFM_CONTEXT` bands and
10897+/// whose leaves publish their own resolved size back;
10898+/// * `predict_inter_block` predicts the WHOLE block once, from the CURRENT
10899+/// frame's own pre-loop-filter reconstruction, at the coded block vector
10900+/// with the BILINEAR kernel `read_intrabc_info` forces (`decodemv.c:913`);
10901+/// * `decode_token_recon_block`'s inter branch then reads one residual per
10902+/// transform unit, through the INTER coefficient sets
10903+/// ([`read_inter_plane_rect`]/[`read_inter_plane`]) with the chroma plane
10904+/// inheriting the colocated luma unit's coded `tx_type`.
10905+///
10906+/// Text order is libaom's: transform tree, prediction, luma residual, chroma
10907+/// residual, bookkeeping. A skipped block codes no residual at all -- the
10908+/// prediction is the reconstruction.
10909+#[allow(clippy::too_many_arguments)]
10910+fn decode_intrabc_rect(
10911+ dec: &mut SymbolDecoder,
10912+ cdfs: &mut Cdfs,
10913+ neighbours: &mut Neighbours,
10914+ (mi_r, mi_c): (usize, usize),
10915+ (bw, bh): (usize, usize),
10916+ skip: bool,
10917+ (dv_row, dv_col): (i32, i32),
10918+ y: &mut PlaneBuf<'static>,
10919+ u: &mut PlaneBuf<'static>,
10920+ v: &mut PlaneBuf<'static>,
10921+ base_q_idx: u8,
10922+ fctx: &crate::decode::FrameCtx,
10923+) -> Result<()> {
10924+ hit!(INTRABC_RECT_HITS);
10925+ let (px, py) = (mi_c * MI, mi_r * MI);
10926+ let (cpx, cpy) = (px / 2, py / 2);
10927+ // `av1_get_max_uv_txsize(bw x bh)`: 4:2:0 halves the footprint and the
10928+ // halved shape's own `max_txsize_rect_lookup` entry IS that size for every
10929+ // shape this helper is called at, so the uv plane block is ONE unit --
10930+ // the same call `decode_token_recon_block`'s own chroma loop makes.
10931+ let (cw, ch) = (bw / 2, bh / 2);
10932+ // `av1_calc_mi_size`'s 8-px-aligned grid: a block hanging over the right
10933+ // or bottom frame edge reads no transform-tree symbol for the units
10934+ // outside it.
10935+ let mi_cols = 2 * y.true_width.div_ceil(8);
10936+ let mi_rows = 2 * y.true_height.div_ceil(8);
10937+ let leaves = read_block_tx_size_rect(
10938+ dec,
10939+ cdfs,
10940+ neighbours,
10941+ (mi_r, mi_c),
10942+ (bw, bh),
10943+ (mi_cols, mi_rows),
10944+ skip, fctx,
10945+ )?;
10946+ if leaves.is_some() {
10947+ hit!(INTRABC_RECT_VARTX_HITS);
10948+ }
10949+ // The whole-block prediction: `predict_inter_block` runs once, before any
10950+ // coefficient is read. `flush_recon` first -- the source is this frame's
10951+ // own reconstruction, including the writes this superblock has queued.
10952+ flush_recon(fctx, y, u, v);
10953+ let mut pred_y = vec![0u16; bw * bh];
10954+ mc::predict_with_filter(
10955+ &y.data, y.width, y.true_width, y.true_height,
10956+ mv_to_q4(px, dv_col, true), mv_to_q4(py, dv_row, true),
10957+ bw, bh, mc::InterpFilterKind::Bilinear, &mut pred_y, fctx,
10958+ );
10959+ let mut pred_u = vec![0u16; cw * ch];
10960+ mc::predict_with_filter(
10961+ &u.data, u.width, u.true_width, u.true_height,
10962+ mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false),
10963+ cw, ch, mc::InterpFilterKind::Bilinear, &mut pred_u, fctx,
10964+ );
10965+ let mut pred_v = vec![0u16; cw * ch];
10966+ mc::predict_with_filter(
10967+ &v.data, v.width, v.true_width, v.true_height,
10968+ mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false),
10969+ cw, ch, mc::InterpFilterKind::Bilinear, &mut pred_v, fctx,
10970+ );
10971+ let reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get);
10972+ let luma_tx_type: TxType;
10973+ let (luma_grid, u_grid, v_grid);
10974+ if skip {
10975+ // No residual syntax at all: the prediction IS the block.
10976+ push_mc_rect(0, px, py, bw, bw, bh, Pred::Inline(&pred_y, bw), &ZERO_RESIDUAL[..bw * bh], fctx);
10977+ push_mc_rect(1, cpx, cpy, cw, cw, ch, Pred::Inline(&pred_u, cw), &ZERO_RESIDUAL[..cw * ch], fctx);
10978+ push_mc_rect(2, cpx, cpy, cw, cw, ch, Pred::Inline(&pred_v, cw), &ZERO_RESIDUAL[..cw * ch], fctx);
10979+ luma_tx_type = TxType::DctDct;
10980+ luma_grid = Grid::Zero(bw * bh);
10981+ u_grid = Grid::Zero(cw * ch);
10982+ v_grid = Grid::Zero(cw * ch);
10983+ } else {
10984+ match leaves.as_ref() {
10985+ None => {
10986+ // One whole-block rectangular transform unit.
10987+ let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh);
10988+ let (grid, tx_type) = read_inter_plane_rect(
10989+ dec,
10990+ cdfs,
10991+ rect_inter_luma_set(bw, bh, fctx)?,
10992+ (bw, bh),
10993+ bw,
10994+ 0,
10995+ around[0],
10996+ 0,
10997+ y,
10998+ px,
10999+ py,
11000+ Pred::Inline(&pred_y, bw),
11001+ None,
11002+ None, fctx,
11003+ )?;
11004+ luma_tx_type = tx_type;
11005+ luma_grid = embed_grid_stride(&grid, bw, bh, bw);
11006+ let (ug, _) = read_inter_plane_rect(
11007+ dec,
11008+ cdfs,
11009+ rect_inter_chroma_set(cw, ch)?,
11010+ (cw, ch),
11011+ cw,
11012+ 1,
11013+ around[1],
11014+ 0,
11015+ u,
11016+ cpx,
11017+ cpy,
11018+ Pred::Inline(&pred_u, cw),
11019+ Some(luma_tx_type),
11020+ None, fctx,
11021+ )?;
11022+ u_grid = embed_grid_stride(&ug, cw, ch, cw);
11023+ let (vg, _) = read_inter_plane_rect(
11024+ dec,
11025+ cdfs,
11026+ rect_inter_chroma_set(cw, ch)?,
11027+ (cw, ch),
11028+ cw,
11029+ 2,
11030+ around[2],
11031+ 0,
11032+ v,
11033+ cpx,
11034+ cpy,
11035+ Pred::Inline(&pred_v, cw),
11036+ Some(luma_tx_type),
11037+ None, fctx,
11038+ )?;
11039+ v_grid = embed_grid_stride(&vg, cw, ch, cw);
11040+ }
11041+ Some(leaves) => {
11042+ // One residual per transform unit, in the order the tree coded
11043+ // them; each unit reads its own neighbour-magnitude context off
11044+ // the units already decoded before it, and every unit adds onto
11045+ // its own window of the block's single prediction.
11046+ let mut first_tx_type = TxType::DctDct;
11047+ for (idx, &(row, col, tw, th)) in leaves.iter().enumerate() {
11048+ let tu_mi = (mi_r + row, mi_c + col);
11049+ let (tu_px, tu_py) = (px + col * MI, py + row * MI);
11050+ let tu_pred = Pred::Inline(&pred_y, bw).offset(row * MI * bw + col * MI);
11051+ let (tu_grid, tu_tx_type) = if tw == th {
11052+ let scan = default_scan(tw.min(32));
11053+ let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tw / MI);
11054+ read_inter_plane(
11055+ dec,
11056+ cdfs,
11057+ inter_txbset_for(tw, reduced),
11058+ scan,
11059+ 0,
11060+ neighbours.around_mi(tu_mi, tw)[0],
11061+ 0,
11062+ y,
11063+ tu_px,
11064+ tu_py,
11065+ tw,
11066+ base_q_idx,
11067+ tu_pred,
11068+ None,
11069+ Some(tu_skip_ctx), fctx,
11070+ )?
11071+ } else {
11072+ let tu_skip_ctx = neighbours.luma_skip_ctx_rect(tu_mi, tw / MI, th / MI);
11073+ read_inter_plane_rect(
11074+ dec,
11075+ cdfs,
11076+ rect_inter_luma_set(tw, th, fctx)?,
11077+ (tw, th),
11078+ bw,
11079+ 0,
11080+ neighbours.around_mi_rect(tu_mi, tw, th)[0],
11081+ 0,
11082+ y,
11083+ tu_px,
11084+ tu_py,
11085+ tu_pred,
11086+ None,
11087+ Some(tu_skip_ctx), fctx,
11088+ )?
11089+ };
11090+ if idx == 0 {
11091+ first_tx_type = tu_tx_type;
11092+ }
11093+ neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid);
11094+ }
11095+ // `av1_get_tx_type`'s chroma lookup lands on the colocated
11096+ // LUMA unit, which for a split block is the top-left one.
11097+ luma_tx_type = first_tx_type;
11098+ let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh);
11099+ let (ug, _) = read_inter_plane_rect(
11100+ dec,
11101+ cdfs,
11102+ rect_inter_chroma_set(cw, ch)?,
11103+ (cw, ch),
11104+ cw,
11105+ 1,
11106+ around[1],
11107+ 0,
11108+ u,
11109+ cpx,
11110+ cpy,
11111+ Pred::Inline(&pred_u, cw),
11112+ Some(luma_tx_type),
11113+ None, fctx,
11114+ )?;
11115+ u_grid = embed_grid_stride(&ug, cw, ch, cw);
11116+ let (vg, _) = read_inter_plane_rect(
11117+ dec,
11118+ cdfs,
11119+ rect_inter_chroma_set(cw, ch)?,
11120+ (cw, ch),
11121+ cw,
11122+ 2,
11123+ around[2],
11124+ 0,
11125+ v,
11126+ cpx,
11127+ cpy,
11128+ Pred::Inline(&pred_v, cw),
11129+ Some(luma_tx_type),
11130+ None, fctx,
11131+ )?;
11132+ v_grid = embed_grid_stride(&vg, cw, ch, cw);
11133+ luma_grid = Grid::Zero(bw * bh);
11134+ }
11135+ }
11136+ }
11137+ let _ = luma_tx_type;
11138+ // Bookkeeping. An intrabc block publishes mode `DC_PRED` everywhere the
11139+ // next block reads a neighbour mode, its own block size in both `TXFM`
11140+ // bands (already done by `read_block_tx_size_rect`), a zeroed palette
11141+ // state (a stale entry would feed the next block's colour cache), and its
11142+ // DV into the intrabc mi grid the next block's DV predictor reads.
11143+ if leaves.is_some() {
11144+ neighbours.record_split_luma_rect_mi(
11145+ (mi_r, mi_c), bw, bh, DC_PRED, DC_PRED, [&u_grid, &v_grid],
11146+ );
11147+ } else {
11148+ neighbours.record_rect_mi(
11149+ (mi_r, mi_c), bw, bh, DC_PRED, DC_PRED, &[&luma_grid, &u_grid, &v_grid],
11150+ );
11151+ }
11152+ neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, 0, [0u16; 8]);
11153+ neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, 0, [0u16; 8]);
11154+ neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip);
11155+ neighbours.fill_lf_grid_rect(
11156+ (mi_r, mi_c),
11157+ bw / MI,
11158+ bh / MI,
11159+ bw.min(64) as u8,
11160+ bh.min(64) as u8,
11161+ 0, fctx,
11162+ );
11163+ record_intrabc_mi_rect(mi_r, mi_c, bw / MI, bh / MI, Some((dv_row, dv_col)), fctx);
11164+ Ok(())
11165+}
11166+
10838 /// Decodes one true `bw`x`bh` `PARTITION_HORZ`/`PARTITION_VERT` intra strip11167 /// Decodes one true `bw`x`bh` `PARTITION_HORZ`/`PARTITION_VERT` intra strip
10839 /// (lane-intradisp r1, spec `decode_block` restricted to a 32x32 quadrant's11168 /// (lane-intradisp r1, spec `decode_block` restricted to a 32x32 quadrant's
10840 /// two rect children). Only the `skip` case is supported: `skip`/`y_mode`/11169 /// two rect children). Only the `skip` case is supported: `skip`/`y_mode`/
@@ -10867,7 +11196,7 @@ fn decode_block_rect(
10867 let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);11196 let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);
10868 let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at);11197 let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at);
10869 let palette_uv_cache = neighbours.palette_uv_cache(at);11198 let palette_uv_cache = neighbours.palette_uv_cache(at);
10870- let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) =11199+ let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv, intrabc) =
10871 read_intra_mode_rect(11200 read_intra_mode_rect(
10872 dec,11201 dec,
10873 cdfs,11202 cdfs,
@@ -10885,6 +11214,22 @@ fn decode_block_rect(
10885 r * (SUB / MI),11214 r * (SUB / MI),
10886 c * (SUB / MI), fctx,11215 c * (SUB / MI), fctx,
10887 )?;11216 )?;
11217+
11218+ if let Some((dv_row, dv_col)) = intrabc {
11219+ return decode_intrabc_rect(
11220+ dec,
11221+ cdfs,
11222+ neighbours,
11223+ (r * (SUB / MI), c * (SUB / MI)),
11224+ (bw, bh),
11225+ skip,
11226+ (dv_row, dv_col),
11227+ y,
11228+ u,
11229+ v,
11230+ base_q_idx, fctx,
11231+ );
11232+ }
10888 let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);11233 let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);
10889 if smooth_neighbor {11234 if smooth_neighbor {
10890 hit!(SMOOTH_LUMA_HITS);11235 hit!(SMOOTH_LUMA_HITS);
@@ -11366,7 +11711,7 @@ fn decode_leaf_rect(
11366 let pal_at = leaf_mi;11711 let pal_at = leaf_mi;
11367 let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(pal_at);11712 let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(pal_at);
11368 let palette_uv_cache = neighbours.palette_uv_cache_mi(pal_at);11713 let palette_uv_cache = neighbours.palette_uv_cache_mi(pal_at);
11369- let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) =11714+ let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv, intrabc) =
11370 read_intra_mode_rect(11715 read_intra_mode_rect(
11371 dec,11716 dec,
11372 cdfs,11717 cdfs,
@@ -11384,6 +11729,14 @@ fn decode_leaf_rect(
11384 leaf_mi.0,11729 leaf_mi.0,
11385 leaf_mi.1, fctx,11730 leaf_mi.1, fctx,
11386 )?;11731 )?;
11732+
11733+ if let Some((dv_row, dv_col)) = intrabc {
11734+ decode_intrabc_rect(
11735+ dec, cdfs, neighbours, leaf_mi, (bw, bh), skip, (dv_row, dv_col),
11736+ y, u, v, base_q_idx, fctx,
11737+ )?;
11738+ return Ok(DC_PRED);
11739+ }
11387 // lane-kf900 r4: palette prediction on this shape, the same colour-index11740 // lane-kf900 r4: palette prediction on this shape, the same colour-index
11388 // map -> base colours buffer [`decode_block_rect`] hands each11741 // map -> base colours buffer [`decode_block_rect`] hands each
11389 // `reconstruct_rect` through [`set_palette_pred`].11742 // `reconstruct_rect` through [`set_palette_pred`].
@@ -11700,6 +12053,7 @@ fn decode_block_rect4(
11700 filter_intra,12053 filter_intra,
11701 palette_y,12054 palette_y,
11702 palette_uv,12055 palette_uv,
12056+ intrabc,
11703 ) = read_intra_mode_rect(12057 ) = read_intra_mode_rect(
11704 dec,12058 dec,
11705 cdfs,12059 cdfs,
@@ -11717,6 +12071,13 @@ fn decode_block_rect4(
11717 mi_r,12071 mi_r,
11718 mi_c, fctx,12072 mi_c, fctx,
11719 )?;12073 )?;
12074+ if let Some((dv_row, dv_col)) = intrabc {
12075+ decode_intrabc_rect(
12076+ dec, cdfs, neighbours, strip_mi, (bw, bh), skip, (dv_row, dv_col),
12077+ y, u, v, base_q_idx, fctx,
12078+ )?;
12079+ return Ok((DC_PRED, DC_PRED));
12080+ }
11720 // lane-kf900 r4: palette prediction on this shape, exactly as12081 // lane-kf900 r4: palette prediction on this shape, exactly as
11721 // [`decode_block_rect`] does one aspect ratio up -- the colour-index map12082 // [`decode_block_rect`] does one aspect ratio up -- the colour-index map
11722 // mapped through the base colours IS the prediction (it reads no edge12083 // mapped through the base colours IS the prediction (it reads no edge
@@ -12245,6 +12606,7 @@ fn decode_rect4_16_strip(
12245 filter_intra,12606 filter_intra,
12246 palette_y,12607 palette_y,
12247 palette_uv,12608 palette_uv,
12609+ intrabc,
12248 ) = read_intra_mode_rect(12610 ) = read_intra_mode_rect(
12249 dec,12611 dec,
12250 cdfs,12612 cdfs,
@@ -12262,6 +12624,11 @@ fn decode_rect4_16_strip(
12262 lmi.0,12624 lmi.0,
12263 lmi.1, fctx,12625 lmi.1, fctx,
12264 )?;12626 )?;
12627+ if intrabc.is_some() {
12628+ return Err(unsupported(
12629+ "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)",
12630+ ));
12631+ }
12265 if palette_y.is_some() || palette_uv.is_some() {12632 if palette_y.is_some() || palette_uv.is_some() {
12266 hit!(RECT4_PALETTE_HITS);12633 hit!(RECT4_PALETTE_HITS);
12267 }12634 }
@@ -12718,7 +13085,7 @@ fn decode_block_rect64(
12718 let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);13085 let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);
12719 let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at);13086 let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at);
12720 let palette_uv_cache = neighbours.palette_uv_cache(at);13087 let palette_uv_cache = neighbours.palette_uv_cache(at);
12721- let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) =13088+ let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv, intrabc) =
12722 read_intra_mode_rect(13089 read_intra_mode_rect(
12723 dec,13090 dec,
12724 cdfs,13091 cdfs,
@@ -12743,6 +13110,11 @@ fn decode_block_rect64(
12743 r * (SUB / MI),13110 r * (SUB / MI),
12744 c * (SUB / MI), fctx,13111 c * (SUB / MI), fctx,
12745 )?;13112 )?;
13113+ if intrabc.is_some() {
13114+ return Err(unsupported(
13115+ "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)",
13116+ ));
13117+ }
12746 if (palette_y.is_some() || palette_uv.is_some()) && !skip {13118 if (palette_y.is_some() || palette_uv.is_some()) && !skip {
12747 // lane-t900 r34: a non-skip palette block on a superblock-level strip13119 // lane-t900 r34: a non-skip palette block on a superblock-level strip
12748 // -- counted so its gate cannot go vacuous (this was a refusal until13120 // -- counted so its gate cannot go vacuous (this was a refusal until
@@ -15125,7 +15497,7 @@ fn decode_block_128rect(
15125 let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);15497 let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);
15126 let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at);15498 let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at);
15127 let palette_uv_cache = neighbours.palette_uv_cache(at);15499 let palette_uv_cache = neighbours.palette_uv_cache(at);
15128- let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) =15500+ let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv, intrabc) =
15129 read_intra_mode_rect(15501 read_intra_mode_rect(
15130 dec,15502 dec,
15131 cdfs,15503 cdfs,
@@ -15145,6 +15517,11 @@ fn decode_block_128rect(
15145 mi_r,15517 mi_r,
15146 mi_c, fctx,15518 mi_c, fctx,
15147 )?;15519 )?;
15520+ if intrabc.is_some() {
15521+ return Err(unsupported(
15522+ "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)",
15523+ ));
15524+ }
15148 if alpha.is_some() || filter_intra.is_some() || palette_y.is_some() || palette_uv.is_some() {15525 if alpha.is_some() || filter_intra.is_some() || palette_y.is_some() || palette_uv.is_some() {
15149 return Err(unsupported(15526 return Err(unsupported(
15150 "CfL, filter intra or a palette on a 128-root HORZ/VERT intra block (every one of \15527 "CfL, filter intra or a palette on a 128-root HORZ/VERT intra block (every one of \
@@ -19116,6 +19493,16 @@ fn extend_corner(corner: Grid, cw: usize, ch: usize, w: usize, h: usize) -> Grid
19116 Grid::Own(full)19493 Grid::Own(full)
19117 }19494 }
19118 19495
19496+/// [`embed_rect_grid`] that keeps the shared zero marker zero: an all-zero
19497+/// transform unit's grid IS `Grid::Zero` (whose deref is the shared
19498+/// `ZERO_RESIDUAL`), so re-laying it would read a zero-length slice.
19499+fn embed_grid_stride(grid: &Grid, w: usize, h: usize, stride: usize) -> Grid {
19500+ if is_zero_grid(grid) {
19501+ return Grid::Zero(stride * stride);
19502+ }
19503+ Grid::Own(embed_rect_grid(grid, w, h, stride))
19504+}
19505+
19119 /// A rect coefficient grid re-laid into the square `stride x stride` grid the19506 /// A rect coefficient grid re-laid into the square `stride x stride` grid the
19120 /// neighbour/deblock stamps downstream of the residual expect.19507 /// neighbour/deblock stamps downstream of the residual expect.
19121 fn embed_rect_grid(grid: &[i32], w: usize, h: usize, stride: usize) -> Vec<i32> {19508 fn embed_rect_grid(grid: &[i32], w: usize, h: usize, stride: usize) -> Vec<i32> {
crates/ec-av1/src/stream.rsmodified+23 -3
@@ -6251,7 +6251,13 @@ pub(crate) mod tests {
6251 // (arm, source, per-arm overrides AFTER the base recipe, expect_refusal,6251 // (arm, source, per-arm overrides AFTER the base recipe, expect_refusal,
6252 // must_read_use_intrabc_on_a_rect_strip)6252 // must_read_use_intrabc_on_a_rect_strip)
6253 let arms: [(&str, &str, &[&str], bool, bool); 8] = [6253 let arms: [(&str, &str, &[&str], bool, bool); 8] = [
6254- ("testsrc2-cq50-txs0", TS, &["--cq-level=50", "--enable-palette=0", "--enable-tx-size-search=0"], true, true),6254+ // lane-av1-intrabc (2026-09-20): this arm used to REFUSE here -- the
6255+ // 16x8 rect strip it decodes is the first block on main that reaches
6256+ // `decode_intrabc_rect`, so the whole arm stopped at a named refusal.
6257+ // Reconstruction is ported now, so the arm decodes pixel-exact and
6258+ // the `rect_total` assert below keeps it from quietly falling back
6259+ // to an ordinary-intra decode of the same block.
6260+ ("testsrc2-cq50-txs0", TS, &["--cq-level=50", "--enable-palette=0", "--enable-tx-size-search=0"], false, true),
6255 ("smptebars-cq40-txs0", SB, &["--cq-level=40", "--enable-palette=0", "--enable-tx-size-search=0"], false, false),6261 ("smptebars-cq40-txs0", SB, &["--cq-level=40", "--enable-palette=0", "--enable-tx-size-search=0"], false, false),
6256 ("smptebars-cq45-txs0", SB, &["--cq-level=45", "--enable-palette=0", "--enable-tx-size-search=0"], false, true),6262 ("smptebars-cq45-txs0", SB, &["--cq-level=45", "--enable-palette=0", "--enable-tx-size-search=0"], false, true),
6257 ("smptebars-cq45-txs1", SB, &["--cq-level=45", "--enable-palette=0", "--enable-tx-size-search=1"], false, false),6263 ("smptebars-cq45-txs1", SB, &["--cq-level=45", "--enable-palette=0", "--enable-tx-size-search=1"], false, false),
@@ -6269,6 +6275,7 @@ pub(crate) mod tests {
6269 let (mut blocks_total, mut fired_arms, mut out_of_scope, mut out_of_scope_mismatch) =6275 let (mut blocks_total, mut fired_arms, mut out_of_scope, mut out_of_scope_mismatch) =
6270 (0usize, 0u32, 0u32, 0u32);6276 (0usize, 0u32, 0u32, 0u32);
6271 let mut leaf8_total = 0usize;6277 let mut leaf8_total = 0usize;
6278+ let mut rect_total = 0usize;
6272 for (arm, src, extra, expect_refusal, must_read) in &arms {6279 for (arm, src, extra, expect_refusal, must_read) in &arms {
6273 let render = || {6280 let render = || {
6274 let out = Command::new("ffmpeg")6281 let out = Command::new("ffmpeg")
@@ -6341,6 +6348,7 @@ pub(crate) mod tests {
6341 decode::reset_rect_intrabc_reads();6348 decode::reset_rect_intrabc_reads();
6342 crate::decode::reset_intrabc_hits();6349 crate::decode::reset_intrabc_hits();
6343 crate::decode::reset_leaf8_intrabc_hits();6350 crate::decode::reset_leaf8_intrabc_hits();
6351+ crate::decode::reset_intrabc_rect_hits();
6344 let decoded = decode_stream(&stream);6352 let decoded = decode_stream(&stream);
6345 let reads = decode::rect_intrabc_reads();6353 let reads = decode::rect_intrabc_reads();
6346 // Blocks that decoded `use_intrabc == 1` (square path), i.e. that6354 // Blocks that decoded `use_intrabc == 1` (square path), i.e. that
@@ -6355,6 +6363,7 @@ pub(crate) mod tests {
6355 // `gate-blind-to-feature`).6363 // `gate-blind-to-feature`).
6356 let leaf8 = crate::decode::leaf8_intrabc_hits();6364 let leaf8 = crate::decode::leaf8_intrabc_hits();
6357 leaf8_total += leaf8;6365 leaf8_total += leaf8;
6366+ rect_total += crate::decode::intrabc_rect_hits();
6358 if *arm == "testsrc2-cq55-leaf8" {6367 if *arm == "testsrc2-cq55-leaf8" {
6359 assert!(6368 assert!(
6360 leaf8 > 0,6369 leaf8 > 0,
@@ -6431,7 +6440,9 @@ pub(crate) mod tests {
6431 {refused} refused by name, {frames_compared} frames compared, \6440 {refused} refused by name, {frames_compared} frames compared, \
6432 {out_of_scope} out of scope ({out_of_scope_mismatch} mismatched)"6441 {out_of_scope} out of scope ({out_of_scope_mismatch} mismatched)"
6433 );6442 );
6434- eprintln!("{NAME}: {leaf8_total} intrabc block(s) at an 8x8 leaf");6443+ eprintln!(
6444+ "{NAME}: {rect_total} intrabc block(s) on a HORZ/VERT rect strip (decode_intrabc_rect)"
6445+ );
6435 assert!(reads_total > 0, "{NAME}: gate is vacuous -- no arm read the symbol");6446 assert!(reads_total > 0, "{NAME}: gate is vacuous -- no arm read the symbol");
6436 assert!(6447 assert!(
6437 leaf8_total > 0,6448 leaf8_total > 0,
@@ -6441,7 +6452,16 @@ pub(crate) mod tests {
6441 blocks_total > 0 && fired_arms > 0,6452 blocks_total > 0 && fired_arms > 0,
6442 "{NAME}: gate is vacuous -- no compared arm actually decoded an intrabc block"6453 "{NAME}: gate is vacuous -- no compared arm actually decoded an intrabc block"
6443 );6454 );
6444- assert_eq!(refused, 1, "{NAME}: expected exactly one named intrabc refusal");6455+ assert!(
6456+ rect_total > 0,
6457+ "{NAME}: no arm decoded an intrabc block on a HORZ/VERT rect strip -- \
6458+ `decode_intrabc_rect` is untested"
6459+ );
6460+ // lane-av1-intrabc: this used to be exactly one -- the 2:1 rect strips
6461+ // now reconstruct. The 1:4 pair strips (`decode_rect4_16_strip` et al.)
6462+ // still refuse by name, but no arm HERE reaches that shape; it stays
6463+ // pinned by `refusal_inventory`'s own gate.
6464+ assert_eq!(refused, 0, "{NAME}: an arm still refuses by name");
6445 assert!(frames_compared > 0, "{NAME}: no frame was compared pixel-exact");6465 assert!(frames_compared > 0, "{NAME}: no frame was compared pixel-exact");
6446 assert_eq!(6466 assert_eq!(
6447 out_of_scope_mismatch, 0,6467 out_of_scope_mismatch, 0,
lanes/av1intrabc.report.mdadded+93 -0
@@ -0,0 +1,93 @@
1+# lane-av1-intrabc - rect-strip intrabc reconstruction (HORZ/VERT 2:1 shapes)
2+
3+Base `main` **3ecd4a10**. Worktree `../edith_codecs-av1ibc`, branch
4+`lane-av1-intrabc`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1ibc`.
5+
6+## 1. What landed
7+
8+`decode_intrabc_rect` (`crates/ec-av1/src/decode.rs`, ~10910): the missing
9+reconstruction arm for a `use_intrabc` block on a **2:1 rect strip**, ported
10+from libaom's `av1_predict_intra_block`/`predict_inter_block` intrabc path:
11+
12+- whole-block prediction once (`predict_inter_block`), for luma at the block
13+ footprint and for both chroma planes at `av1_get_max_uv_txsize(bw x bh)`;
14+- skip case: prediction IS the block (`push_mc_rect`, zero residual);
15+- coded case: residual per transform unit -- one whole-block rect TU
16+ (`read_inter_plane_rect`, `TxbSet::LumaRect32x16`/`ChromaRect16x8` and the
17+ real rect scan/context tables) or one residual per var-tx leaf;
18+- bookkeeping identical in shape to the square intrabc path: mode
19+ `DC_PRED` into the mode maps, coefficient contexts, zeroed palette state,
20+ skip/LF grids, and the DV into the intrabc mi grid.
21+
22+Wired at all 2:1 rect intrabc slots: `decode_block_rect` (16x32/32x16),
23+`decode_block_rect4` (32x8/8x32 + 16x8/8x16), `decode_leaf_rect`,
24+`decode_block_rect64`, `decode_block_128rect`; engagement counters
25+`intrabc_rect_hits` / `intrabc_rect_vartx_hits` exposed on `decode_probe`.
26+
27+## 2. Byte-exactness witnesses
28+
29+In-gate (flipped pin -> witness): `stream::tests::
30+a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips`. Its
31+`testsrc2-cq50-txs0` arm used to stop at the rect-strip refusal; it now decodes
32+1 frame, **1 intrabc block on a HORZ/VERT rect strip**, pixel-exact vs ffmpeg.
33+Gate totals: 187 rect `use_intrabc` reads, 5 intrabc blocks over 5 arms,
34+8 frames compared, 0 mismatches, 0 named refusals.
35+
36+Standalone recipes (aomenc oracle at `~/.cache/aom-oracle/build/aomenc`, probe
37+`cargo run --release -p ec-av1 --example decode_probe -- <obu>`):
38+
39+| recipe (base: `--cpu-used=0 --tune-content=screen --enable-intrabc=1
40+--min-partition-size=8 --max-partition-size=32 --sb-size=64 --enable-palette=1
41+--enable-tx-size-search=0 --enable-rect-partitions=1 --enable-1to4-partitions=1`) | intrabc rect blocks | shape (mi) | skip | result |
42+|---|---|---|---|---|
43+|`testsrc2=s=256x192:r=25 --cq-level=50 --enable-palette=0`, 1:4 off|0|--|--|REFUSED (16x8 CPR block, `--enable-1to4-partitions=0`)|
44+|`testsrc2=s=256x192:r=25 --cq-level=50 --enable-palette=0 --min-partition-size=4 --max-partition-size=16`|1|16x8 @(38,48)|0|**EXACT**|
45+|`testsrc2=s=256x192:r=25 --cq-level=45 --enable-palette=0`|1|16x8 @(38,48)|0|**EXACT**|
46+|`smptebars=size=512x384:rate=25 --cq-level=50`|2|16x8 @(76,92) skip=0, 8x32 @(80,104) skip=1|mixed|**EXACT**|
47+|`smptebars=size=1024x768:rate=25 --cq-level=50`|1|8x32 @(64,74)|1|**EXACT**|
48+|`testsrc2=s=256x192:r=25 --cq-level=50`, 1:4 off, `--enable-tx-size-search=1`|0|--|--|REFUSED|
49+
50+Every `EXACT` row is `cmp` of the probe's raw output against ffmpeg
51+`-pix_fmt yuv420p` decoded from the same `.obu`, i.e. byte-identical planes.
52+The 16x8 witnesses exercise the residual reader (`skip=0`); the 8x32
53+witnesses exercise `decode_block_rect4`'s wiring through the same helper.
54+
55+## 3. Still refused by name
56+
57+**1:4 pair strips** (`PARTITION_HORZ_4`/`VERT_4`, 16x4/4x16):
58+`intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not
59+ported at this shape)` at `decode_rect4_16_strip`, `decode_block_rect4`'s 1:4
60+arm and `decode_block_128rect`. Reason this is NOT this lane's helper: a 1:4
61+strip is coded as a PAIR (both children share one chroma block), so the chroma
62+prediction comes from the pair's top-left mi and the chroma coefficient state
63+is written over the pair span -- a different neighbour/bookkeeping model from
64+the 2:1 helper above. Reachable witnesses for whoever takes it next:
65+`aomenc --allintra` (already stops there today), `--allintra` cpu-used 0
66+(lands there after the tx-depth/tx-band work, see lane-av1-txbands), and this
67+hand-made recipe: `testsrc2=s=640x480:r=25 --cq-level=60 --enable-palette=1
68+--enable-tx-size-search=0 --enable-rect-partitions=1 --enable-1to4-partitions=1
69+--sb-size=64` (16x4 @ mi(76,108), skip=0).
70+
71+**Mixed-leaf var-tx intrabc** (`decode.rs:14816`): unchanged. The census gate
72+`an_intrabc_vartx_census_measures_the_mixed_leaf_refusal` (green) shows the
73+four-quantiser census still produces UNIFORM var-tx trees only, so no reachable
74+stream exercises it -- census-pinned, as the wave plan expected. The 2:1 helper
75+itself already handles a var-tx tree's leaves (`INTRABC_RECT_VARTX_HITS`), so
76+the refusal that remains is only the square/leaf path's.
77+
78+## 4. Gates run
79+
80+- `cargo check -p ec-av1 --all-targets` -> 0 warnings.
81+- `cargo test -p ec-av1 --lib -- --exact stream::tests::
82+ a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips` -> ok.
83+- `cargo test -p ec-av1 --lib -- refusal` -> 21 passed.
84+- Full `--lib` suite: NOT run to completion by this lane (budget); sibling lane
85+ lane-av1-txbands is editing the same file, so the workspace-wide run belongs
86+ to the batch-level gate.
87+
88+## 5. Deferred
89+
90+1. **1:4 pair-strip intrabc** -- named above, with the model difference and the
91+ witness recipes. `deferred(1:4 pair-chroma model)`
92+2. **Full-suite gate** -- `deferred(batch-level run after lane-av1-txbands
93+ merges; same file, mid-flight run would measure a half-built tree)`