forge
Explore
Log in

Don't you dare go Hollow

Merge lane-rectsplit r1 (3627fe9): HORZ/VERT intra strips with split transforms decode per transform unit; filter intra over bw x bh; 32-level refusals lifted with gates (20/20, 40/40); SB-level split-tx arm stays refused (verifier PARTIAL: r2 owns the SB gate rewrite)

Browse files at this commit

2bfe1bb52a2008558b2f52fd6843acd6205a7196Ahmet Kaan GümüşParent: d2fe7621fce295
crates/ec-av1/src/decode.rsmodified+367 -30
@@ -776,6 +776,34 @@ pub(crate) fn horz_vert_intra_hits() -> usize {
776776 HORZ_VERT_INTRA_HITS.with(|c| c.get())
777777 }
778778
779+// How many HORZ/VERT intra strips resolved a SPLIT luma transform
780+// (`tx_depth != 0`) and decoded it per transform unit (lane-rectsplit r1) --
781+// the case every rect path here refused by name before, and the first
782+// refusal the user's ReelB extract (600s in) stops at.
783+thread_local! {
784+ static RECT_SPLIT_TX_HITS: std::cell::Cell<usize> =
785+ const { std::cell::Cell::new(0) };
786+}
787+
788+/// Current value of [`RECT_SPLIT_TX_HITS`].
789+pub(crate) fn rect_split_tx_hits() -> usize {
790+ RECT_SPLIT_TX_HITS.with(|c| c.get())
791+}
792+
793+// How many HORZ/VERT intra strips actually predicted with filter intra
794+// (lane-rectsplit r1) -- the case `decode_block_rect` refused by name
795+// ("this decoder predicts square-only") until `predict_filter_intra` took
796+// `bw`x`bh`.
797+thread_local! {
798+ static FILTER_INTRA_RECT_HITS: std::cell::Cell<usize> =
799+ const { std::cell::Cell::new(0) };
800+}
801+
802+/// Current value of [`FILTER_INTRA_RECT_HITS`].
803+pub(crate) fn filter_intra_rect_hits() -> usize {
804+ FILTER_INTRA_RECT_HITS.with(|c| c.get())
805+}
806+
779807 // How many [`read_coeffs`] reads resolved a `tx_type` outside `TX_CLASS_2D`
780808 // (`V_DCT`/`H_DCT`, spec 5.11.39's `TxClass::Horiz`/`Vert`), across every
781809 // call on the current thread -- the same before/after counter pattern as
@@ -2996,32 +3024,55 @@ impl Neighbours {
29963024 mode: usize,
29973025 uv_mode: usize,
29983026 chroma_grids: [&[i32]; 2],
3027+ ) {
3028+ self.record_split_luma_rect(at, side, side, mode, uv_mode, chroma_grids);
3029+ }
3030+
3031+ /// [`Self::record_split_luma`] with independent above (`w`)/left (`h`)
3032+ /// extents in pixels (lane-rectsplit r1), the same relationship
3033+ /// [`Self::record_rect`] has to [`Self::record`]: a HORZ/VERT strip whose
3034+ /// luma transform split into several square units needs exactly this
3035+ /// bookkeeping, at its own true rectangular extents.
3036+ fn record_split_luma_rect(
3037+ &mut self,
3038+ at: (usize, usize),
3039+ w: usize,
3040+ h: usize,
3041+ mode: usize,
3042+ uv_mode: usize,
3043+ chroma_grids: [&[i32]; 2],
29993044 ) {
30003045 let (r, c) = at;
3001- for cell in 0..side / SUB {
3046+ for cell in 0..w / SUB {
30023047 self.above_mode[c + cell] = mode;
3003- self.left_mode[r + cell] = mode;
30043048 self.above_uv_mode[c + cell] = uv_mode;
3049+ self.above_side[c + cell] = w;
3050+ }
3051+ for cell in 0..h / SUB {
3052+ self.left_mode[r + cell] = mode;
30053053 self.left_uv_mode[r + cell] = uv_mode;
3006- self.above_side[c + cell] = side;
3007- self.left_side[r + cell] = side;
3054+ self.left_side[r + cell] = h;
30083055 }
30093056 let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
3010- let side_mi = side / MI;
3011- for cell in 0..side_mi {
3012- self.left_side_mi[mi_r + cell] = side;
3013- self.above_side_mi[mi_c + cell] = side;
3057+ let (w_mi, h_mi) = (w / MI, h / MI);
3058+ for cell in 0..h_mi {
3059+ self.left_side_mi[mi_r + cell] = h;
3060+ }
3061+ for cell in 0..w_mi {
3062+ self.above_side_mi[mi_c + cell] = w;
30143063 }
30153064 let round_up_even = |n: usize| n.div_ceil(2) * 2;
30163065 let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols));
30173066 for (plane_idx, grid) in chroma_grids.into_iter().enumerate() {
30183067 let plane = plane_idx + 1;
30193068 let state = neighbour_state(grid);
3020- for cell in 0..side_mi {
3021- if cell < side_mi.min(bound_h.saturating_sub(mi_r)) {
3069+ for cell in 0..h_mi {
3070+ if cell < h_mi.min(bound_h.saturating_sub(mi_r)) {
30223071 self.left[mi_r + cell][plane] = state;
30233072 }
3024- if cell < side_mi.min(bound_w.saturating_sub(mi_c)) {
3073+ }
3074+ for cell in 0..w_mi {
3075+ if cell < w_mi.min(bound_w.saturating_sub(mi_c)) {
30253076 self.above[mi_c + cell][plane] = state;
30263077 }
30273078 }
@@ -3547,6 +3598,249 @@ fn cfl_ac_q3_rect(y: &PlaneBuf, px: usize, py: usize, bw: usize, bh: usize) -> V
35473598 ac
35483599 }
35493600
3601+/// Everything a rect strip already read out of the stream before its luma
3602+/// transform units are decoded -- [`decode_rect_split`]'s own mode bundle
3603+/// (nine values that would otherwise be nine more parameters).
3604+struct RectStripModes {
3605+ skip: bool,
3606+ mode: usize,
3607+ angle_delta_y: i32,
3608+ uv_predict_mode: usize,
3609+ angle_delta_uv: i32,
3610+ alpha: Option<(i32, i32)>,
3611+ filter_intra: Option<usize>,
3612+ smooth_neighbor: bool,
3613+ smooth_neighbor_uv: bool,
3614+}
3615+
3616+/// Decodes the planes of one `bw`x`bh` HORZ/VERT intra strip whose luma
3617+/// transform is SPLIT (`tx_depth != 0`) -- lane-rectsplit r1, the case every
3618+/// rect path here refused by name until now ("per-unit rect prediction is not
3619+/// ported").
3620+///
3621+/// `depth_to_tx_size` (libaom `blockd.h`) walks `sub_tx_size_map` `depth`
3622+/// times from the block's own `max_txsize_rect_lookup` entry, and for a 2:1
3623+/// strip the very first step already lands on a SQUARE transform
3624+/// (`sub_tx_size_map[TX_32X16] == TX_16X16`, `[TX_64X32] == TX_32X32`, and
3625+/// every further step halves a square) -- so each unit is square and reads
3626+/// through the ordinary square [`read_plane`]. What is genuinely rectangular
3627+/// here is the *tiling* (`bw/tx` by `bh/tx` units, not `n` by `n` as
3628+/// [`decode_block`]'s square split loop assumes) and the chroma plane, whose
3629+/// own transform is `av1_get_max_uv_txsize` of the whole strip and is never
3630+/// split by luma's depth.
3631+///
3632+/// Each unit predicts off whatever the earlier units of this same block
3633+/// already reconstructed (spec 5.11.36 `predict_and_reconstruct_intra_block`
3634+/// inside `av1_foreach_transformed_block`, raster order), which is exactly
3635+/// what predicting the whole strip in one shot got wrong.
3636+#[allow(clippy::too_many_arguments)]
3637+fn decode_rect_split(
3638+ dec: &mut SymbolDecoder,
3639+ cdfs: &mut Cdfs,
3640+ neighbours: &mut Neighbours,
3641+ at: (usize, usize),
3642+ bw: usize,
3643+ bh: usize,
3644+ tx: usize,
3645+ m: &RectStripModes,
3646+ y: &mut PlaneBuf,
3647+ u: &mut PlaneBuf,
3648+ v: &mut PlaneBuf,
3649+ base_q_idx: u8,
3650+ reduced_tx_set: bool,
3651+) -> Result<()> {
3652+ let (r, c) = at;
3653+ let (px, py) = (c * SUB, r * SUB);
3654+ let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
3655+ let (cpx, cpy) = (px / 2, py / 2);
3656+ let (chroma_w, chroma_h) = (bw / 2, bh / 2);
3657+ // The chroma transform is picked before any symbol is read, so an
3658+ // unsupported chroma shape refuses before this strip desyncs the tile.
3659+ let chroma: Option<(TxbSet, &[u16])> = match (chroma_w, chroma_h) {
3660+ (16, 8) => Some((TxbSet::ChromaRect16x8, &SCAN_16X8[..])),
3661+ (8, 16) => Some((TxbSet::ChromaRect16x8, &SCAN_8X16[..])),
3662+ (32, 16) => Some((TxbSet::ChromaRect32x16, &SCAN_32X16[..])),
3663+ (16, 32) => Some((TxbSet::ChromaRect32x16, &SCAN_16X32[..])),
3664+ _ => None,
3665+ };
3666+ if !m.skip && chroma.is_none() {
3667+ return Err(unsupported(
3668+ "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",
3669+ ));
3670+ }
3671+ RECT_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));
3672+ // LUMA: `bw/tx` x `bh/tx` square transform units, raster order.
3673+ let luma_set = txbset_for(tx, reduced_tx_set);
3674+ let luma_scan = default_scan(tx);
3675+ let zero_tu = vec![0i32; tx * tx];
3676+ // The strip's OWN edge availability, the fallback for a transform unit
3677+ // whose top-right/bottom-left pixels fall outside the strip.
3678+ let block_reach = Reach::of_rect(bw, bh, px, py, y.width, y.height);
3679+ for tu_row in 0..bh / tx {
3680+ for tu_col in 0..bw / tx {
3681+ let tu_mi = (mi_r + tu_row * (tx / MI), mi_c + tu_col * (tx / MI));
3682+ let (tu_px, tu_py) = (px + tu_col * tx, py + tu_row * tx);
3683+ let (col_off, row_off) = (tu_col * tx, tu_row * tx);
3684+ // `has_top_right`/`has_bottom_left` (libaom `reconintra.c`) for a
3685+ // transform unit INSIDE a block, which is a different rule from
3686+ // the standalone-block table [`Reach::of`] applies -- and the
3687+ // reason a depth-2 superblock strip came out one sample off
3688+ // before this: `Reach::of(tx, ..)` answered as if the unit were
3689+ // its own block at that superblock position.
3690+ // * top-right: if the unit's right neighbour is still inside the
3691+ // strip the pixels are already reconstructed (`col_off +
3692+ // tx_wide < plane_bw`); otherwise only the strip's own top row
3693+ // of units can reach past it, through the block-level answer.
3694+ // * bottom-left: a unit that is not in the strip's left column
3695+ // has none (`col_off > 0` returns 0); inside the strip
3696+ // (`row_off + tx_high < plane_bh`) they are the left
3697+ // neighbour's, already reconstructed; the last row falls back
3698+ // to the block-level answer.
3699+ let tu_reach = Reach {
3700+ above_right: if col_off + tx < bw {
3701+ true
3702+ } else {
3703+ row_off == 0 && block_reach.above_right
3704+ },
3705+ below_left: if col_off > 0 {
3706+ false
3707+ } else if row_off + tx < bh {
3708+ true
3709+ } else {
3710+ block_reach.below_left
3711+ },
3712+ };
3713+ if m.skip {
3714+ y.reconstruct(
3715+ tu_px,
3716+ tu_py,
3717+ tx,
3718+ m.mode,
3719+ m.angle_delta_y,
3720+ tu_reach,
3721+ &zero_tu,
3722+ None,
3723+ m.filter_intra,
3724+ m.smooth_neighbor,
3725+ );
3726+ neighbours.record_mi_luma(tu_mi, tx, &zero_tu);
3727+ } else {
3728+ let tu_around = neighbours.around_mi(tu_mi, tx)[0];
3729+ // This unit is smaller than the block it sits in, so
3730+ // `txb_skip_ctx` is the neighbour-magnitude table, not the
3731+ // lone-TU 0 (spec `get_txb_ctx_general`).
3732+ let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx / MI);
3733+ let tu_grid = read_plane(
3734+ dec,
3735+ cdfs,
3736+ luma_set,
3737+ &luma_scan,
3738+ 0,
3739+ tu_around,
3740+ m.mode,
3741+ m.mode,
3742+ m.angle_delta_y,
3743+ tu_reach,
3744+ y,
3745+ tu_px,
3746+ tu_py,
3747+ tx,
3748+ tx,
3749+ base_q_idx,
3750+ None,
3751+ m.filter_intra,
3752+ Some(tu_skip_ctx),
3753+ m.smooth_neighbor,
3754+ )?;
3755+ neighbours.record_mi_luma(tu_mi, tx, &tu_grid);
3756+ }
3757+ }
3758+ }
3759+ // CHROMA: one un-split rect transform for the whole strip.
3760+ let ac = m.alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
3761+ let reach = block_reach;
3762+ let (u_grid, v_grid) = if m.skip {
3763+ let zero = vec![0i32; chroma_w * chroma_h];
3764+ u.reconstruct_rect(
3765+ cpx, cpy, chroma_w, chroma_h, m.uv_predict_mode, m.angle_delta_uv, reach, &zero,
3766+ m.alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, m.smooth_neighbor_uv,
3767+ );
3768+ v.reconstruct_rect(
3769+ cpx, cpy, chroma_w, chroma_h, m.uv_predict_mode, m.angle_delta_uv, reach, &zero,
3770+ m.alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, m.smooth_neighbor_uv,
3771+ );
3772+ (zero.clone(), zero)
3773+ } else {
3774+ let (chroma_set, chroma_scan) = chroma.expect("refused above when None");
3775+ // `av1_get_ext_tx_set_type`: a chroma transform whose square-up size
3776+ // is TX_32X32 or bigger resolves to `EXT_TX_SET_DCTONLY` for intra,
3777+ // so only the 16x8/8x16 pair takes the mode-indexed default.
3778+ let default_tx = if chroma_w.max(chroma_h) >= 32 {
3779+ TxType::DctDct
3780+ } else {
3781+ default_intra_tx_type(m.uv_predict_mode as u8)
3782+ };
3783+ let around = neighbours.around_rect(at, bw, bh);
3784+ let mut grids: Vec<Vec<i32>> = Vec::with_capacity(2);
3785+ for plane_idx in 1..=2 {
3786+ let skip_ctx =
3787+ usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1);
3788+ let mut coding = cdfs.txb(chroma_set, m.uv_predict_mode);
3789+ let (levels, tx_type) = read_coeffs_rect(
3790+ dec,
3791+ &mut coding,
3792+ chroma_scan,
3793+ chroma_w,
3794+ chroma_h,
3795+ skip_ctx,
3796+ dc_sign_ctx(around[plane_idx].2),
3797+ default_tx,
3798+ )?;
3799+ let residual = dequant_and_inverse_typed_wh(
3800+ &levels,
3801+ chroma_w,
3802+ chroma_h,
3803+ crate::decode::bit_depth(),
3804+ CURRENT_Q_IDX.with(|c| c.get()),
3805+ plane_q_delta(plane_idx).0,
3806+ plane_q_delta(plane_idx).1,
3807+ tx_type,
3808+ );
3809+ let cfl = m
3810+ .alpha
3811+ .zip(ac.as_deref())
3812+ .map(|((au, av), ac)| (if plane_idx == 1 { au } else { av }, ac));
3813+ let plane = if plane_idx == 1 { &mut *u } else { &mut *v };
3814+ plane.reconstruct_rect(
3815+ cpx,
3816+ cpy,
3817+ chroma_w,
3818+ chroma_h,
3819+ m.uv_predict_mode,
3820+ m.angle_delta_uv,
3821+ reach,
3822+ &residual,
3823+ cfl,
3824+ None,
3825+ m.smooth_neighbor_uv,
3826+ );
3827+ grids.push(levels);
3828+ }
3829+ let mut it = grids.into_iter();
3830+ (it.next().unwrap(), it.next().unwrap())
3831+ };
3832+ neighbours.record_split_luma_rect(at, bw, bh, m.mode, m.uv_predict_mode, [&u_grid, &v_grid]);
3833+ neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, m.skip);
3834+ neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx as u8, tx as u8, 0);
3835+ if std::env::var_os("EC_AV1_TRACE").is_some() {
3836+ let (rng, _) = dec.debug_state();
3837+ eprintln!(
3838+ "TRACE_RECT_SPLIT mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} tx={tx} rng={rng}"
3839+ );
3840+ }
3841+ Ok(())
3842+}
3843+
35503844 /// Decodes one true `bw`x`bh` `PARTITION_HORZ`/`PARTITION_VERT` intra strip
35513845 /// (lane-intradisp r1, spec `decode_block` restricted to a 32x32 quadrant's
35523846 /// two rect children). Only the `skip` case is supported: `skip`/`y_mode`/
@@ -3572,6 +3866,7 @@ fn decode_block_rect(
35723866 allow_screen_content_tools: bool,
35733867 base_q_idx: u8,
35743868 tx_select: bool,
3869+ reduced_tx_set: bool,
35753870 ) -> Result<()> {
35763871 let (r, c) = at;
35773872 let (px, py) = (c * SUB, r * SUB);
@@ -3600,15 +3895,13 @@ fn decode_block_rect(
36003895 // `uv_mode`, not the luma one.
36013896 let smooth_neighbor_uv =
36023897 is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]);
3898+ // lane-rectsplit r1: `predict_filter_intra` now takes the block's own
3899+ // `bw`x`bh` (`av1_filter_intra_predictor_c` walks its 4x2 patches over a
3900+ // rectangle just as happily), so a `use_filter_intra` strip at this level
3901+ // predicts instead of refusing. The below-16x16 leaf arm
3902+ // (`decode_leaf_rect`) keeps the refusal: it has no gate of its own.
36033903 if filter_intra.is_some() {
3604- // `predict_filter_intra` (spec 7.11.2.3) is square-only in this
3605- // decoder (`assert_eq!(dst.len(), side*side)`) -- a real symbol was
3606- // already read above so the stream stays in sync, this only refuses
3607- // the *pixel* decode of a rare case (`use_filter_intra` on a rect
3608- // strip).
3609- return Err(unsupported(
3610- "filter intra on a HORZ/VERT strip (this decoder predicts square-only)",
3611- ));
3904+ FILTER_INTRA_RECT_HITS.with(|c| c.set(c.get() + 1));
36123905 }
36133906 let uv_predict_mode = if uv_mode == UV_CFL_PRED {
36143907 DC_PRED
@@ -3631,15 +3924,28 @@ fn decode_block_rect(
36313924 };
36323925 if depth != 0 {
36333926 TX_DEPTH_HITS.with(|c| c.set(c.get() + 1));
3634- // A split transform is predicted per transform unit, each taking its
3635- // edges from the previous unit's reconstruction (the square path's own
3636- // per-TU loop does exactly that). Predicting the whole strip in one
3637- // shot would silently produce different pixels, so refuse by name
3638- // until that loop is ported for rect strips.
3639- return Err(unsupported(
3640- "a HORZ/VERT intra strip with a split transform (per-unit rect \
3641- prediction is not ported)",
3642- ));
3927+ // lane-rectsplit r1: a split transform is predicted and reconstructed
3928+ // per transform unit, each unit taking its edges from the previous
3929+ // unit's reconstruction inside this same strip (spec 5.11.36) --
3930+ // [`decode_rect_split`]. `depth_to_tx_size` of a 2:1 strip is square
3931+ // from the first step on, so `bw.min(bh) >> (depth - 1)` names it.
3932+ let tx = bw.min(bh) >> (depth - 1);
3933+ let modes = RectStripModes {
3934+ skip,
3935+ mode,
3936+ angle_delta_y,
3937+ uv_predict_mode,
3938+ angle_delta_uv,
3939+ alpha,
3940+ filter_intra,
3941+ smooth_neighbor,
3942+ smooth_neighbor_uv,
3943+ };
3944+ decode_rect_split(
3945+ dec, cdfs, neighbours, at, bw, bh, tx, &modes, y, u, v, base_q_idx, reduced_tx_set,
3946+ )?;
3947+ RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1));
3948+ return Ok(());
36433949 }
36443950 let (tx_w, tx_h) = (bw, bh);
36453951 let (cpx, cpy) = (px / 2, py / 2);
@@ -3981,7 +4287,7 @@ fn decode_leaf_rect(
39814287 };
39824288 if depth != 0 {
39834289 return Err(unsupported(
3984- "a HORZ/VERT intra strip with a split transform (per-unit rect \
4290+ "a HORZ/VERT intra strip below 16x16 with a split transform (per-unit rect \
39854291 prediction is not ported)",
39864292 ));
39874293 }
@@ -4082,6 +4388,7 @@ fn decode_block_rect64(
40824388 allow_screen_content_tools: bool,
40834389 base_q_idx: u8,
40844390 tx_select: bool,
4391+ reduced_tx_set: bool,
40854392 ) -> Result<()> {
40864393 let (r, c) = at;
40874394 let (px, py) = (c * SUB, r * SUB);
@@ -4132,12 +4439,31 @@ fn decode_block_rect64(
41324439 let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
41334440 let depth = if tx_select {
41344441 let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh);
4135- dec.symbol(&mut cdfs.tx_size_cat2[ctx])
4442+ // lane-rectsplit r1: `bsize_to_tx_size_cat` (libaom `decodemv.c`)
4443+ // counts `sub_tx_size_map` steps from the block's own max rect
4444+ // transform down to TX_4X4, minus one -- BLOCK_64X32's chain
4445+ // (TX_64X32 -> TX_32X32 -> TX_16X16 -> TX_8X8 -> TX_4X4) is four
4446+ // steps, so this level's category is 3 (the same one a 64x64 square
4447+ // block uses), not the 2 a 32x16 strip uses. Reading the cat-2 CDF
4448+ // here was a wrong-table read of a real symbol.
4449+ dec.symbol(&mut cdfs.tx_size_cat3[ctx])
41364450 } else {
41374451 0
41384452 };
41394453 if depth != 0 {
41404454 TX_DEPTH_HITS.with(|c| c.set(c.get() + 1));
4455+ // lane-rectsplit r1: [`decode_rect_split`] handles this shape too
4456+ // (`sub_tx_size_map[TX_64X32]` is `TX_32X32`, so a depth-1 unit here
4457+ // is a plain square 32x32) and its 32x32-level sibling arm in
4458+ // [`decode_block_rect`] is gated pixel-exact -- but at the SUPERBLOCK
4459+ // level the gate
4460+ // (`a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact`,
4461+ // `#[ignore]`d with its measurement) still comes out ONE sample off
4462+ // (seed 50, luma (171,56) ours 147 vs ffmpeg 148, inside a 64x32
4463+ // strip whose transform resolved to depth 2 / TX_16X16). A refusal
4464+ // this lane could not lift is not a refusal it may silently ship
4465+ // wrong pixels past, so the named refusal stays until that gate is
4466+ // green.
41414467 return Err(unsupported(
41424468 "a superblock-level HORZ/VERT strip with a split transform (per-unit rect \
41434469 prediction is not ported)",
@@ -4952,6 +5278,7 @@ impl PlaneBuf {
49525278 left.as_deref(),
49535279 corner,
49545280 bw,
5281+ bh,
49555282 &mut prediction,
49565283 );
49575284 } else {
@@ -5024,6 +5351,7 @@ impl PlaneBuf {
50245351 left.as_deref(),
50255352 corner,
50265353 side,
5354+ side,
50275355 &mut prediction,
50285356 );
50295357 } else {
@@ -7493,6 +7821,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
74937821 allow_screen_content_tools,
74947822 base_q_idx,
74957823 tx_select,
7824+ reduced_tx_set,
74967825 )?;
74977826 // Two 8x8 squares stacked on the
74987827 // right, chained through
@@ -7797,6 +8126,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
77978126 allow_screen_content_tools,
77988127 base_q_idx,
77998128 tx_select,
8129+ reduced_tx_set,
78008130 )?;
78018131 decode_block_rect(
78028132 &mut dec,
@@ -7812,6 +8142,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
78128142 allow_screen_content_tools,
78138143 base_q_idx,
78148144 tx_select,
8145+ reduced_tx_set,
78158146 )?;
78168147 }
78178148 PARTITION_VERT => {
@@ -7831,6 +8162,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
78318162 allow_screen_content_tools,
78328163 base_q_idx,
78338164 tx_select,
8165+ reduced_tx_set,
78348166 )?;
78358167 decode_block_rect(
78368168 &mut dec,
@@ -7846,6 +8178,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
78468178 allow_screen_content_tools,
78478179 base_q_idx,
78488180 tx_select,
8181+ reduced_tx_set,
78498182 )?;
78508183 }
78518184 _ => {
@@ -7872,6 +8205,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
78728205 allow_screen_content_tools,
78738206 base_q_idx,
78748207 tx_select,
8208+ reduced_tx_set,
78758209 )?;
78768210 decode_block_rect64(
78778211 &mut dec,
@@ -7887,6 +8221,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
78878221 allow_screen_content_tools,
78888222 base_q_idx,
78898223 tx_select,
8224+ reduced_tx_set,
78908225 )?;
78918226 }
78928227 PARTITION_VERT => {
@@ -7906,6 +8241,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
79068241 allow_screen_content_tools,
79078242 base_q_idx,
79088243 tx_select,
8244+ reduced_tx_set,
79098245 )?;
79108246 decode_block_rect64(
79118247 &mut dec,
@@ -7921,6 +8257,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
79218257 allow_screen_content_tools,
79228258 base_q_idx,
79238259 tx_select,
8260+ reduced_tx_set,
79248261 )?;
79258262 }
79268263 _ => {
crates/ec-av1/src/intra.rsmodified+26 -18
@@ -726,37 +726,45 @@ const FILTER_INTRA_SCALE_BITS: u32 = 4;
726726 /// though this mode itself never reaches past its own `side` samples of
727727 /// either edge.
728728 ///
729+/// `bw`x`bh` is the block, not necessarily square (lane-rectsplit r1):
730+/// `av1_filter_intra_predictor_c` walks the same 4x2 patches over a
731+/// rectangular block, and `av1_filter_intra_allowed_bsize` genuinely offers
732+/// this mode on every HORZ/VERT strip whose sides are both <= 32 (16x8,
733+/// 8x16, 32x16, 16x32, ...), which the square-only assert refused before.
734+///
729735 /// # Panics
730-/// Panics when `dst` is not `side * side` long, or `side` is not a multiple
731-/// of 4 (spec `av1_filter_intra_allowed_bsize` never offers this mode past
732-/// 32x32, and only on square blocks: 4, 8, 16 or 32).
736+/// Panics when `dst` is not `bw * bh` long, or `bw` is not a multiple of 4
737+/// or `bh` not a multiple of 2 (spec `av1_filter_intra_allowed_bsize` never
738+/// offers this mode past 32x32).
733739 pub fn predict_filter_intra(
734740 mode: usize,
735741 above: Option<&[u16]>,
736742 left: Option<&[u16]>,
737743 corner: Option<u16>,
738- side: usize,
744+ bw: usize,
745+ bh: usize,
739746 dst: &mut [u16],
740747 ) {
741- assert_eq!(dst.len(), side * side, "the destination is the block");
742- assert_eq!(side % 4, 0, "filter intra only offers 4/8/16/32");
743- let edges = Edges::build(above, left, corner, side, side);
748+ assert_eq!(dst.len(), bw * bh, "the destination is the block");
749+ assert_eq!(bw % 4, 0, "filter intra patches are 4 wide");
750+ assert_eq!(bh % 2, 0, "filter intra patches are 2 high");
751+ let edges = Edges::build(above, left, corner, bw, bh);
744752 let taps = &FILTER_INTRA_TAPS[mode];
745753 // A (side+1)-square buffer: row 0 / column 0 hold the corner and the
746754 // above/left edges, `buffer[r+1][c+1]` the block's own sample at (r, c).
747- let mut buffer = vec![0i32; (side + 1) * (side + 1)];
748- let at = |buffer: &[i32], r: usize, c: usize| buffer[r * (side + 1) + c];
755+ let mut buffer = vec![0i32; (bh + 1) * (bw + 1)];
756+ let at = |buffer: &[i32], r: usize, c: usize| buffer[r * (bw + 1) + c];
749757 buffer[0] = edges.above(-1);
750- for c in 0..side {
758+ for c in 0..bw {
751759 buffer[c + 1] = edges.above(c as i32);
752760 }
753- for r in 0..side {
754- buffer[(r + 1) * (side + 1)] = edges.left(r as i32);
761+ for r in 0..bh {
762+ buffer[(r + 1) * (bw + 1)] = edges.left(r as i32);
755763 }
756764 let mut r = 1;
757- while r < side + 1 {
765+ while r < bh + 1 {
758766 let mut c = 1;
759- while c < side + 1 {
767+ while c < bw + 1 {
760768 let p0 = at(&buffer, r - 1, c - 1);
761769 let p1 = at(&buffer, r - 1, c);
762770 let p2 = at(&buffer, r - 1, c + 1);
@@ -769,16 +777,16 @@ pub fn predict_filter_intra(
769777 let (r_off, c_off) = (k >> 2, k & 3);
770778 let pr: i32 = taps[k].iter().zip(&p).map(|(t, s)| t * s).sum();
771779 let value = round2(pr, FILTER_INTRA_SCALE_BITS).clamp(0, crate::decode::sample_max());
772- let idx = (r + r_off) * (side + 1) + c + c_off;
780+ let idx = (r + r_off) * (bw + 1) + c + c_off;
773781 buffer[idx] = value;
774782 }
775783 c += 4;
776784 }
777785 r += 2;
778786 }
779- for row in 0..side {
780- for col in 0..side {
781- dst[row * side + col] = at(&buffer, row + 1, col + 1) as u16;
787+ for row in 0..bh {
788+ for col in 0..bw {
789+ dst[row * bw + col] = at(&buffer, row + 1, col + 1) as u16;
782790 }
783791 }
784792 }
crates/ec-av1/src/refusal_inventory.rsmodified+2 -1
@@ -37,6 +37,8 @@ const REFUSALS: &[&str] = &[
3737 "GLOBALMV (round 3)",
3838 "a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 (this decoder ports only the skip case at this size)",
3939 "a coded (non-skip) HORZ/VERT rect strip below 16x16 (this decoder ports only the skip case at this size)",
40+ "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",
41+ "a HORZ/VERT intra strip below 16x16 with a split transform (per-unit rect prediction is not ported)",
4042 "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)",
4143 "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
4244 "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
@@ -47,7 +49,6 @@ const REFUSALS: &[&str] = &[
4749 "an INTER 32x32 partition type this decoder does not code (value={part32})",
4850 "a superblock-level partition type other than NONE or SPLIT (this decoder's intra tile path codes only those two at 64x64)",
4951 "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)",
50- "a HORZ/VERT intra strip with a split transform (per-unit rect prediction is not ported)",
5152 "a block that actually uses a palette (UV) -- reconstruction is out of scope",
5253 "a block that actually uses a palette (Y) -- reconstruction is out of scope",
5354 "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)",
crates/ec-av1/src/stream.rsmodified+543 -0
@@ -9920,6 +9920,549 @@ mod tests {
99209920 );
99219921 }
99229922
9923+ /// lane-rectsplit r1 gate (a): a real `aomenc` key frame whose 32x32
9924+ /// quadrants split HORZ/VERT into true 32x16/16x32 strips, with the
9925+ /// tx-size search left at aomenc's own default (ON) -- every sibling
9926+ /// recipe in this file pins `--enable-tx-size-search=0`, which is exactly
9927+ /// why the split-transform strip was never exercised. RD is then free to
9928+ /// give a strip a transform smaller than its own size, the case
9929+ /// [`crate::decode::decode_block_rect`] refused by name ("a HORZ/VERT
9930+ /// intra strip with a split transform (per-unit rect prediction is not
9931+ /// ported)") until this round ported the per-transform-unit predict-and-
9932+ /// reconstruct loop. Hard-asserts a nonzero `rect_split_tx_hits()` delta:
9933+ /// without it a stream that resolved every `tx_depth` to 0 would
9934+ /// pixel-match by construction and prove nothing. A decode error that is
9935+ /// not a named refusal, and any pixel mismatch, FAIL -- only a missing
9936+ /// tool skips.
9937+ #[test]
9938+ fn a_real_aomenc_stream_with_a_split_transform_horz_vert_strip_decodes_pixel_exact() {
9939+ const NAME: &str = "a_real_aomenc_stream_with_a_split_transform_horz_vert_strip_decodes_pixel_exact";
9940+ let _gate_lock = lock_gate_counters();
9941+ if !have_ffmpeg() {
9942+ eprintln!("SKIP {NAME}: no ffmpeg");
9943+ return;
9944+ }
9945+ if !have_aomenc() {
9946+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
9947+ return;
9948+ }
9949+ let (width, height) = (192usize, 128usize);
9950+ let before = crate::decode::rect_split_tx_hits();
9951+ let mut named_refusals = 0u32;
9952+ let mut matched = 0u32;
9953+ let mut split_so_far = 0usize;
9954+ // Bounded sweep: see this gate's own doc for the seed-77 residue and
9955+ // why extending it is a diagnosis knob, not a pass/fail one.
9956+ let n_attempts: u32 = std::env::var("EC_RECTSPLIT_GATE_ATTEMPTS")
9957+ .ok()
9958+ .and_then(|s| s.parse().ok())
9959+ .unwrap_or(20);
9960+ for attempt in 0..n_attempts {
9961+ let seed = 42 + attempt;
9962+ let source = gradients_source(seed, width, height, "duration=0.04:rate=25");
9963+ let y4m = Command::new("ffmpeg")
9964+ .args([
9965+ "-v", "error", "-f", "lavfi", "-i", &source,
9966+ // Desaturated (`hue=s=0`, the same guard
9967+ // `a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact`
9968+ // uses): with the tx-size search ON, a real chroma
9969+ // gradient hits a PRE-EXISTING chroma defect on the plain
9970+ // SQUARE path -- measured this round with
9971+ // `--enable-rect-partitions=0` on this very recipe, seed
9972+ // 42, U plane, i.e. with no rect strip in the stream at
9973+ // all. Flat chroma keeps that unrelated defect out of
9974+ // this gate (gate-recipe-confound class); it is open
9975+ // residue in lanes/rectsplit-r1.report.md, not fixed here.
9976+ "-vf", "hue=s=0",
9977+ "-pix_fmt", "yuv420p", "-f",
9978+ "yuv4mpegpipe", "-",
9979+ ])
9980+ .stdin(Stdio::null())
9981+ .stdout(Stdio::piped())
9982+ .stderr(Stdio::piped())
9983+ .output()
9984+ .expect("ffmpeg failed to run");
9985+ assert!(
9986+ y4m.status.success(),
9987+ "ffmpeg fixture: {}",
9988+ String::from_utf8_lossy(&y4m.stderr)
9989+ );
9990+ // NOTE: no `--enable-tx-size-search=0` here -- leaving aomenc's
9991+ // own default (search ON) is the entire point of this gate.
9992+ let args: Vec<&str> = vec![
9993+ "--codec=av1",
9994+ "--passes=1",
9995+ "--end-usage=q",
9996+ "--cq-level=45",
9997+ "--cpu-used=0",
9998+ "--threads=1",
9999+ "--row-mt=0",
10000+ "--sb-size=64",
10001+ "--enable-rect-partitions=1",
10002+ "--enable-ab-partitions=0",
10003+ "--enable-1to4-partitions=0",
10004+ "--min-partition-size=16",
10005+ "--max-partition-size=32",
10006+ "--enable-restoration=0",
10007+ "--enable-palette=0",
10008+ "--deltaq-mode=0",
10009+ "--enable-filter-intra=0",
10010+ "--enable-cfl-intra=0",
10011+ "--enable-intrabc=0",
10012+ "--obu",
10013+ "-o",
10014+ "-",
10015+ "-",
10016+ ];
10017+ let mut child = Command::new(aomenc_path())
10018+ .args(&args)
10019+ .stdin(Stdio::piped())
10020+ .stdout(Stdio::piped())
10021+ .stderr(Stdio::piped())
10022+ .spawn()
10023+ .expect("aomenc failed to start");
10024+ child
10025+ .stdin
10026+ .take()
10027+ .expect("aomenc stdin")
10028+ .write_all(&y4m.stdout)
10029+ .expect("writing y4m to aomenc");
10030+ let out = child.wait_with_output().expect("aomenc failed to run");
10031+ assert!(
10032+ out.status.success(),
10033+ "aomenc refused the fixture: {}",
10034+ String::from_utf8_lossy(&out.stderr)
10035+ );
10036+ let stream = out.stdout;
10037+ assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})");
10038+ let frames = match decode_stream(&stream) {
10039+ Err(e) => {
10040+ let msg = e.to_string();
10041+ assert!(
10042+ msg.contains("unsupported"),
10043+ "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
10044+ );
10045+ named_refusals += 1;
10046+ continue;
10047+ }
10048+ Ok(frames) => frames,
10049+ };
10050+ let after = crate::decode::rect_split_tx_hits();
10051+ eprintln!(
10052+ "{NAME}: seed {seed} decoded, split-tx strips this stream: {}",
10053+ after - before - split_so_far
10054+ );
10055+ split_so_far = after - before;
10056+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
10057+ assert_eq!(frames.len(), 1, "{NAME}: expected one frame (seed {seed})");
10058+ if let Some(i) = frames[0]
10059+ .y
10060+ .iter()
10061+ .zip(&ffmpeg_frames[0].y)
10062+ .position(|(a, b)| a != b)
10063+ {
10064+ eprintln!(
10065+ "{NAME}: seed {seed} first luma mismatch at ({}, {}) ours={} ffmpeg={}",
10066+ i % width,
10067+ i / width,
10068+ frames[0].y[i],
10069+ ffmpeg_frames[0].y[i]
10070+ );
10071+ }
10072+ assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})");
10073+ assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})");
10074+ assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})");
10075+ matched += 1;
10076+ }
10077+ let split_hits = crate::decode::rect_split_tx_hits() - before;
10078+ assert!(
10079+ matched > 0,
10080+ "{NAME}: every attempt refused ({named_refusals} named refusals) -- gate decoded nothing"
10081+ );
10082+ assert!(
10083+ split_hits > 0,
10084+ "{NAME}: zero HORZ/VERT strips resolved a split transform ({matched} pixel-exact \
10085+ matches, {named_refusals} refusals out of {n_attempts}) -- gate proved nothing \
10086+ this run"
10087+ );
10088+ eprintln!(
10089+ "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals, \
10090+ rect_split_tx_hits delta={split_hits} out of {n_attempts} attempts"
10091+ );
10092+ }
10093+
10094+ /// lane-rectsplit r1 gate (c): gate (a)'s recipe with
10095+ /// `--enable-filter-intra=1` (every sibling gate here pins it to 0), so
10096+ /// aomenc's RD is free to pick `use_filter_intra` on a 32x16/16x32 strip
10097+ /// -- the case [`crate::decode::decode_block_rect`] refused by name
10098+ /// ("filter intra on a HORZ/VERT strip (this decoder predicts
10099+ /// square-only)") until this round gave `predict_filter_intra` its own
10100+ /// `bw`x`bh`. Hard-asserts a nonzero `filter_intra_rect_hits()` delta:
10101+ /// a stream where RD never picked filter intra on a strip would
10102+ /// pixel-match by construction and prove nothing.
10103+ #[test]
10104+ fn a_real_aomenc_stream_with_filter_intra_on_a_horz_vert_strip_decodes_pixel_exact() {
10105+ const NAME: &str =
10106+ "a_real_aomenc_stream_with_filter_intra_on_a_horz_vert_strip_decodes_pixel_exact";
10107+ let _gate_lock = lock_gate_counters();
10108+ if !have_ffmpeg() {
10109+ eprintln!("SKIP {NAME}: no ffmpeg");
10110+ return;
10111+ }
10112+ if !have_aomenc() {
10113+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
10114+ return;
10115+ }
10116+ let (width, height) = (192usize, 128usize);
10117+ let before = crate::decode::filter_intra_rect_hits();
10118+ let rect_before = crate::decode::rect_partition_hits();
10119+ let fi_square_before = crate::decode::filter_intra_hits();
10120+ let mut named_refusals = 0u32;
10121+ let mut matched = 0u32;
10122+ let n_attempts: u32 = std::env::var("EC_RECTSPLIT_GATE_ATTEMPTS")
10123+ .ok()
10124+ .and_then(|s| s.parse().ok())
10125+ .unwrap_or(40);
10126+ for attempt in 0..n_attempts {
10127+ let seed = 42 + attempt;
10128+ // Diagnosis knob: which content makes RD pick a HORZ/VERT strip
10129+ // AND filter intra on it is a search (see this round's report).
10130+ let source = match std::env::var("EC_RECTSPLIT_SRC").unwrap_or_default().as_str() {
10131+ "bars" => format!("smptebars=size={width}x{height}:duration=0.04:rate=25"),
10132+ "src2" => format!("testsrc2=size={width}x{height}:duration=0.04:rate=25"),
10133+ _ => gradients_source(seed, width, height, "duration=0.04:rate=25"),
10134+ };
10135+ let y4m = Command::new("ffmpeg")
10136+ .args([
10137+ "-v", "error", "-f", "lavfi", "-i", &source,
10138+ // Same `hue=s=0` guard as gate (a): a real chroma gradient
10139+ // under the tx-size search hits a PRE-EXISTING square-path
10140+ // chroma defect that has nothing to do with this lane.
10141+ "-vf", "hue=s=0",
10142+ "-pix_fmt", "yuv420p", "-f", "yuv4mpegpipe", "-",
10143+ ])
10144+ .stdin(Stdio::null())
10145+ .stdout(Stdio::piped())
10146+ .stderr(Stdio::piped())
10147+ .output()
10148+ .expect("ffmpeg failed to run");
10149+ assert!(
10150+ y4m.status.success(),
10151+ "ffmpeg fixture: {}",
10152+ String::from_utf8_lossy(&y4m.stderr)
10153+ );
10154+ // Diagnosis knob only (default is the gate's pinned recipe):
10155+ // which `--cq-level` makes aomenc's RD reach for filter intra on
10156+ // a strip is a search, and the sweep that found this one is in
10157+ // lanes/rectsplit-r1.report.md.
10158+ let cq = format!(
10159+ "--cq-level={}",
10160+ // Pinned by the sweep in lanes/rectsplit-r1.report.md: at
10161+ // cq 45 aomenc's RD picks a strip 18 times in 100 seeds and
10162+ // filter intra on none of them; at cq 25 strips are common
10163+ // (130/100 seeds) and filter intra lands on one every ~13
10164+ // seeds.
10165+ std::env::var("EC_RECTSPLIT_CQ").unwrap_or_else(|_| "25".into())
10166+ );
10167+ let args: Vec<&str> = vec![
10168+ "--codec=av1",
10169+ "--passes=1",
10170+ "--end-usage=q",
10171+ &cq,
10172+ "--cpu-used=0",
10173+ "--threads=1",
10174+ "--row-mt=0",
10175+ "--sb-size=64",
10176+ "--enable-rect-partitions=1",
10177+ "--enable-ab-partitions=0",
10178+ "--enable-1to4-partitions=0",
10179+ "--min-partition-size=16",
10180+ "--max-partition-size=32",
10181+ "--enable-restoration=0",
10182+ "--enable-palette=0",
10183+ "--deltaq-mode=0",
10184+ // The point of this gate.
10185+ "--enable-filter-intra=1",
10186+ // The square filter-intra gate's own way of making RD reach
10187+ // for filter intra at all: with the directional/smooth/paeth
10188+ // competitors off, DC_PRED + filter intra is what is left
10189+ // (recipe borrowed from
10190+ // `a_real_aomenc_filter_intra_stream_decodes_pixel_exact`;
10191+ // without them 20/20 streams picked filter intra zero times
10192+ // on a strip -- measured this round).
10193+ "--enable-cfl-intra=0",
10194+ "--enable-intrabc=0",
10195+ "--obu",
10196+ "-o",
10197+ "-",
10198+ "-",
10199+ ];
10200+ // Diagnosis knob (default: every intra mode on): turning the
10201+ // directional/smooth/paeth competitors off is how the square
10202+ // filter-intra gate makes RD reach for filter intra, but with all
10203+ // four off aomenc stops picking rect partitions here entirely
10204+ // (rect strips=0, filter-intra blocks=28, measured this round),
10205+ // so the firing recipe is a search over subsets.
10206+ let mut args = args;
10207+ let off = std::env::var("EC_RECTSPLIT_OFF").unwrap_or_default();
10208+ for tool in off.split(',').filter(|t| !t.is_empty()) {
10209+ args.push(match tool {
10210+ "smooth" => "--enable-smooth-intra=0",
10211+ "paeth" => "--enable-paeth-intra=0",
10212+ "dir" => "--enable-directional-intra=0",
10213+ "angle" => "--enable-angle-delta=0",
10214+ other => panic!("unknown EC_RECTSPLIT_OFF entry {other}"),
10215+ });
10216+ }
10217+ let mut child = Command::new(aomenc_path())
10218+ .args(&args)
10219+ .stdin(Stdio::piped())
10220+ .stdout(Stdio::piped())
10221+ .stderr(Stdio::piped())
10222+ .spawn()
10223+ .expect("aomenc failed to start");
10224+ child
10225+ .stdin
10226+ .take()
10227+ .expect("aomenc stdin")
10228+ .write_all(&y4m.stdout)
10229+ .expect("writing y4m to aomenc");
10230+ let out = child.wait_with_output().expect("aomenc failed to run");
10231+ assert!(
10232+ out.status.success(),
10233+ "aomenc refused the fixture: {}",
10234+ String::from_utf8_lossy(&out.stderr)
10235+ );
10236+ let stream = out.stdout;
10237+ assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})");
10238+ let frames = match decode_stream(&stream) {
10239+ Err(e) => {
10240+ let msg = e.to_string();
10241+ assert!(
10242+ msg.contains("unsupported"),
10243+ "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
10244+ );
10245+ named_refusals += 1;
10246+ continue;
10247+ }
10248+ Ok(frames) => frames,
10249+ };
10250+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
10251+ assert_eq!(frames.len(), 1, "{NAME}: expected one frame (seed {seed})");
10252+ if let Some(i) = frames[0]
10253+ .y
10254+ .iter()
10255+ .zip(&ffmpeg_frames[0].y)
10256+ .position(|(a, b)| a != b)
10257+ {
10258+ eprintln!(
10259+ "{NAME}: seed {seed} first luma mismatch at ({}, {}) ours={} ffmpeg={}",
10260+ i % width,
10261+ i / width,
10262+ frames[0].y[i],
10263+ ffmpeg_frames[0].y[i]
10264+ );
10265+ }
10266+ assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})");
10267+ assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})");
10268+ assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})");
10269+ matched += 1;
10270+ }
10271+ let fi_hits = crate::decode::filter_intra_rect_hits() - before;
10272+ eprintln!(
10273+ "{NAME}: rect strips this run={}, filter-intra blocks (any shape)={}",
10274+ crate::decode::rect_partition_hits() - rect_before,
10275+ crate::decode::filter_intra_hits() - fi_square_before
10276+ );
10277+ assert!(
10278+ matched > 0,
10279+ "{NAME}: every attempt refused ({named_refusals} named refusals) -- gate decoded nothing"
10280+ );
10281+ assert!(
10282+ fi_hits > 0,
10283+ "{NAME}: no HORZ/VERT strip used filter intra ({matched} pixel-exact matches, \
10284+ {named_refusals} refusals out of {n_attempts}) -- gate proved nothing this run"
10285+ );
10286+ eprintln!(
10287+ "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals, \
10288+ filter_intra_rect_hits delta={fi_hits} out of {n_attempts} attempts"
10289+ );
10290+ }
10291+
10292+ /// lane-rectsplit r1 gate (b): [`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`]'s
10293+ /// own recipe (`--sb-size=64`, `--min/max-partition-size=32/64`, so every
10294+ /// SB-level decision is genuinely NONE/SPLIT/HORZ/VERT) with its
10295+ /// `--enable-tx-size-search=0` DROPPED: the 64x32/32x64 strips may then
10296+ /// carry a split transform, which [`crate::decode::decode_block_rect64`]
10297+ /// refused by name ("a superblock-level HORZ/VERT strip with a split
10298+ /// transform") until this round. Same hard `rect_split_tx_hits()` delta
10299+ /// assert as gate (a).
10300+ /// lane-rectsplit r1 MEASURED RED, `#[ignore]`d with its number (the
10301+ /// `rect64q` gate's own precedent): with the per-transform-unit port
10302+ /// wired at the superblock level, seed 50 decodes one sample off --
10303+ /// luma (171, 56), ours 147 vs ffmpeg 148, inside the 64x32 strip at
10304+ /// mi=(8,32) whose transform resolved to depth 2 (TX_16X16). Seeds 42-49
10305+ /// with depth-1 (TX_32X32) units were pixel-exact. The refusal in
10306+ /// `decode_block_rect64` was therefore RESTORED rather than lifted; run
10307+ /// this gate (`--ignored`) after any fix to that arm.
10308+ #[ignore = "lane-rectsplit r1: measured RED, seed 50 luma (171,56) off by one; refusal kept"]
10309+ #[test]
10310+ fn a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact() {
10311+ const NAME: &str = "a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact";
10312+ let _gate_lock = lock_gate_counters();
10313+ if !have_ffmpeg() {
10314+ eprintln!("SKIP {NAME}: no ffmpeg");
10315+ return;
10316+ }
10317+ if !have_aomenc() {
10318+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
10319+ return;
10320+ }
10321+ let (width, height) = (192usize, 128usize);
10322+ let before = crate::decode::rect_split_tx_hits();
10323+ let mut named_refusals = 0u32;
10324+ let mut matched = 0u32;
10325+ let mut split_so_far = 0usize;
10326+ // Bounded sweep: see this gate's own doc for the seed-77 residue and
10327+ // why extending it is a diagnosis knob, not a pass/fail one.
10328+ let n_attempts: u32 = std::env::var("EC_RECTSPLIT_GATE_ATTEMPTS")
10329+ .ok()
10330+ .and_then(|s| s.parse().ok())
10331+ .unwrap_or(20);
10332+ for attempt in 0..n_attempts {
10333+ let seed = 42 + attempt;
10334+ let source = gradients_source(seed, width, height, "duration=0.04:rate=25");
10335+ let y4m = Command::new("ffmpeg")
10336+ .args([
10337+ "-v", "error", "-f", "lavfi", "-i", &source,
10338+ // Desaturated (`hue=s=0`, the same guard
10339+ // `a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact`
10340+ // uses): with the tx-size search ON, a real chroma
10341+ // gradient hits a PRE-EXISTING chroma defect on the plain
10342+ // SQUARE path -- measured this round with
10343+ // `--enable-rect-partitions=0` on this very recipe, seed
10344+ // 42, U plane, i.e. with no rect strip in the stream at
10345+ // all. Flat chroma keeps that unrelated defect out of
10346+ // this gate (gate-recipe-confound class); it is open
10347+ // residue in lanes/rectsplit-r1.report.md, not fixed here.
10348+ "-vf", "hue=s=0",
10349+ "-pix_fmt", "yuv420p", "-f",
10350+ "yuv4mpegpipe", "-",
10351+ ])
10352+ .stdin(Stdio::null())
10353+ .stdout(Stdio::piped())
10354+ .stderr(Stdio::piped())
10355+ .output()
10356+ .expect("ffmpeg failed to run");
10357+ assert!(
10358+ y4m.status.success(),
10359+ "ffmpeg fixture: {}",
10360+ String::from_utf8_lossy(&y4m.stderr)
10361+ );
10362+ // NOTE: no `--enable-tx-size-search=0` here -- leaving aomenc's
10363+ // own default (search ON) is the entire point of this gate.
10364+ let args: Vec<&str> = vec![
10365+ "--codec=av1",
10366+ "--passes=1",
10367+ "--end-usage=q",
10368+ "--cq-level=45",
10369+ "--cpu-used=0",
10370+ "--threads=1",
10371+ "--row-mt=0",
10372+ "--sb-size=64",
10373+ "--enable-rect-partitions=1",
10374+ "--enable-ab-partitions=0",
10375+ "--enable-1to4-partitions=0",
10376+ "--min-partition-size=32",
10377+ "--max-partition-size=64",
10378+ "--enable-restoration=0",
10379+ "--enable-palette=0",
10380+ "--deltaq-mode=0",
10381+ "--enable-filter-intra=0",
10382+ "--enable-cfl-intra=0",
10383+ "--enable-intrabc=0",
10384+ "--obu",
10385+ "-o",
10386+ "-",
10387+ "-",
10388+ ];
10389+ let mut child = Command::new(aomenc_path())
10390+ .args(&args)
10391+ .stdin(Stdio::piped())
10392+ .stdout(Stdio::piped())
10393+ .stderr(Stdio::piped())
10394+ .spawn()
10395+ .expect("aomenc failed to start");
10396+ child
10397+ .stdin
10398+ .take()
10399+ .expect("aomenc stdin")
10400+ .write_all(&y4m.stdout)
10401+ .expect("writing y4m to aomenc");
10402+ let out = child.wait_with_output().expect("aomenc failed to run");
10403+ assert!(
10404+ out.status.success(),
10405+ "aomenc refused the fixture: {}",
10406+ String::from_utf8_lossy(&out.stderr)
10407+ );
10408+ let stream = out.stdout;
10409+ assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})");
10410+ let frames = match decode_stream(&stream) {
10411+ Err(e) => {
10412+ let msg = e.to_string();
10413+ assert!(
10414+ msg.contains("unsupported"),
10415+ "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
10416+ );
10417+ named_refusals += 1;
10418+ continue;
10419+ }
10420+ Ok(frames) => frames,
10421+ };
10422+ let after = crate::decode::rect_split_tx_hits();
10423+ eprintln!(
10424+ "{NAME}: seed {seed} decoded, split-tx strips this stream: {}",
10425+ after - before - split_so_far
10426+ );
10427+ split_so_far = after - before;
10428+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
10429+ assert_eq!(frames.len(), 1, "{NAME}: expected one frame (seed {seed})");
10430+ if let Some(i) = frames[0]
10431+ .y
10432+ .iter()
10433+ .zip(&ffmpeg_frames[0].y)
10434+ .position(|(a, b)| a != b)
10435+ {
10436+ eprintln!(
10437+ "{NAME}: seed {seed} first luma mismatch at ({}, {}) ours={} ffmpeg={}",
10438+ i % width,
10439+ i / width,
10440+ frames[0].y[i],
10441+ ffmpeg_frames[0].y[i]
10442+ );
10443+ }
10444+ assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})");
10445+ assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})");
10446+ assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})");
10447+ matched += 1;
10448+ }
10449+ let split_hits = crate::decode::rect_split_tx_hits() - before;
10450+ assert!(
10451+ matched > 0,
10452+ "{NAME}: every attempt refused ({named_refusals} named refusals) -- gate decoded nothing"
10453+ );
10454+ assert!(
10455+ split_hits > 0,
10456+ "{NAME}: zero HORZ/VERT strips resolved a split transform ({matched} pixel-exact \
10457+ matches, {named_refusals} refusals out of {n_attempts}) -- gate proved nothing \
10458+ this run"
10459+ );
10460+ eprintln!(
10461+ "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals, \
10462+ rect_split_tx_hits delta={split_hits} out of {n_attempts} attempts"
10463+ );
10464+ }
10465+
992310466 /// lane-rect64q r1: same recipe as
992410467 /// [`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`]
992510468 /// minus `--deltaq-mode=0` -- real aomenc's non-realtime default is
lanes/rectsplit-r1.report.mdadded+93 -0
@@ -0,0 +1,93 @@
1+# lane-rectsplit r1 — HORZ/VERT strips with a split transform, and filter intra on a strip
2+
3+Branch `lane-rectsplit` off main `3808cf8`; continues the orchestrator's WIP snapshot
4+`c5de1b6` (previous builder's uncommitted state), commit `16baa0f` is this round.
5+
6+## What changed
7+
8+- `crates/ec-av1/src/decode.rs:3159` `decode_rect_split` (from the WIP snapshot, kept):
9+ a HORZ/VERT strip with `tx_depth != 0` predicts and reconstructs PER TRANSFORM UNIT in
10+ raster order (spec 5.11.36), each unit taking its edges from the units already
11+ reconstructed inside the same strip, with per-unit `has_top_right`/`has_bottom_left`
12+ (libaom `reconintra.c`) instead of the standalone-block table; chroma stays one un-split
13+ rect transform. `sub_tx_size_map[TX_32X16] == TX_16X16`, so every unit is square and reads
14+ through the ordinary square `read_plane`.
15+- `crates/ec-av1/src/decode.rs:3453` — refusal "filter intra on a HORZ/VERT strip (this
16+ decoder predicts square-only)" REMOVED from `decode_block_rect`, replaced by the
17+ `FILTER_INTRA_RECT_HITS` counter.
18+- `crates/ec-av1/src/intra.rs:733` `predict_filter_intra` now takes `bw`x`bh` instead of one
19+ square `side` (`av1_filter_intra_predictor_c` walks its 4x2 patches over a rectangle just
20+ as happily; `av1_filter_intra_allowed_bsize` genuinely allows every strip with both sides
21+ <= 32). Two call sites updated (`reconstruct_rect` passes `bw, bh`, `reconstruct` passes
22+ `side, side`).
23+- `crates/ec-av1/src/decode.rs:3833` — the below-16x16 leaf arm (`decode_leaf_rect`) keeps
24+ BOTH refusals; its split-transform one is renamed to name the size ("a HORZ/VERT intra
25+ strip below 16x16 with a split transform ...") because the 32x32-level string it shared is
26+ now lifted, and it is added to `refusal_inventory.rs:41`.
27+- `crates/ec-av1/src/stream.rs:9337` gate (a), `:9503` gate (c), `:9700` gate (b, `#[ignore]`d
28+ RED, from the WIP snapshot).
29+
30+## Refusals lifted (each with its gate)
31+
32+| refusal | gate | result |
33+| --- | --- | --- |
34+| "a HORZ/VERT intra strip with a split transform (per-unit rect prediction is not ported)" | `a_real_aomenc_stream_with_a_split_transform_horz_vert_strip_decodes_pixel_exact` | GREEN, 20/20 pixel-exact, `rect_split_tx_hits` > 0 |
35+| "filter intra on a HORZ/VERT strip (this decoder predicts square-only)" (at the 32x32 level only) | `a_real_aomenc_stream_with_filter_intra_on_a_horz_vert_strip_decodes_pixel_exact` | GREEN, 40/40 pixel-exact, `filter_intra_rect_hits`=3 |
36+
37+Not lifted:
38+- "a superblock-level HORZ/VERT strip with a split transform (per-unit rect prediction is not
39+ ported)" — the port itself is wired at that level too, but gate (b)
40+ `a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact` is
41+ MEASURED RED: seed 50 decodes one sample off, luma (171, 56) ours 147 vs ffmpeg 148, inside
42+ the 64x32 strip at mi=(8,32) whose transform resolved to depth 2 (TX_16X16). Seeds 42-49
43+ (depth 1 / TX_32X32 units) are pixel-exact. `#[ignore]`d with that number.
44+ disposition: deferred(a range-ladder/prefilt-dump bisection of that one TU's top-right edge
45+ availability) — the refusal stays, so no wrong pixels ship.
46+- "filter intra on a HORZ/VERT strip" / "a HORZ/VERT intra strip below 16x16 with a split
47+ transform" at `decode_leaf_rect` (below 16x16): that arm only ports the skip case and has no
48+ gate of its own. disposition: deferred(a below-16x16 strip gate, lane-sub8's territory).
49+
50+## Gate-recipe search (the part that cost the round)
51+
52+`--enable-filter-intra=1` alone never fires filter intra on a strip. Measured, 192x128
53+`gradients` + `hue=s=0`, `--min/max-partition-size=16/32`, `--threads=1 --row-mt=0`:
54+
55+| recipe | rect strips | filter-intra blocks (any shape) | filter intra ON a strip |
56+| --- | --- | --- | --- |
57+| cq 45, smooth/paeth/directional/angle-delta all OFF (the square filter-intra gate's recipe), 20 seeds | 0 | 23 | 0 |
58+| cq 45, every intra mode ON, 100 seeds | 18 | 136 | 0 |
59+| cq 25, every intra mode ON, 100 seeds | 130 | 61 | 5 |
60+| cq 25, every intra mode ON, 40 seeds (PINNED) | 56 | 16 | 3 |
61+
62+Disabling the directional/smooth/paeth competitors — the trick the square filter-intra gate
63+uses — makes aomenc stop choosing rect partitions altogether (class `gate-recipe-confound`).
64+The knob that actually works is the quantiser: at cq 25 strips are ~7x more common. `smptebars`
65+and `testsrc2` sources were tried and are unusable here (every attempt refused, 0 decodes).
66+`EC_RECTSPLIT_CQ` / `EC_RECTSPLIT_OFF` / `EC_RECTSPLIT_GATE_ATTEMPTS` stay as diagnosis knobs
67+with the pinned recipe as default.
68+
69+## Evidence
70+
71+EVIDENCE: `cargo test -p ec-av1 --lib -- a_real_aomenc_stream_with_a_split_transform_horz_vert_strip_decodes_pixel_exact` | aomenc `--enable-rect-partitions=1`, tx-size search ON, 20 seeds, each decoded by ours and by ffmpeg | 20 pixel-exact matches, 0 refusals, `rect_split_tx_hits` delta > 0, test ok
72+EVIDENCE: `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -- a_real_aomenc_stream_with_filter_intra_on_a_horz_vert_strip_decodes_pixel_exact` | aomenc `--enable-filter-intra=1 --cq-level=25`, 40 seeds | 40 pixel-exact matches, 0 refusals, `filter_intra_rect_hits` delta=3, test ok
73+
74+## Film check (ReelB)
75+
76+```
77+ffmpeg -v error -t 0.4 -i ".../reelb.mkv" -c:v copy -f obu hg.obu # 1817 bytes
78+cargo run -p ec-av1 --example decode_probe -- hg.obu
79+REFUSED: unsupported: AV1 tile (a partition below 8x8 (this decoder codes no leaf smaller than 8x8))
80+```
81+
82+EVIDENCE: /tmp/.../scratchpad/hg.obu | `ffmpeg -t 0.4 -c:v copy -f obu` then `decode_probe` on this branch | stops at "a partition below 8x8", NOT at any refusal this lane owns
83+
84+The charter's premise that this extract stops at a rect-split refusal is stale for the film's
85+first 0.4s: the blocker there is the below-8x8 partition refusal (lane-sub8's, still open per
86+`memory/`). "Before" was not re-measured on main — the refusal reached is upstream of every
87+line this lane touched, so the branch cannot have moved it.
88+disposition: deferred(lane-sub8's below-8x8 leaf) — nothing this lane can do about it.
89+
90+## Suite
91+
92+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j3` (crate lib only, never the workspace):
93+**269 passed, 0 failed, 24 ignored**, 1062s. `refusal_inventory` and `gate_coverage` green.