forge
Explore
Log in

Don't you dare go Hollow

Intra HORZ/VERT strips decode on the inter block path (gate RED)

Browse files at this commit

40b9c3770d7e5b1df7765c6460d000126a22ff4aAhmet Kaan GümüşParent: 928732c
  • feat
    • intra HORZ/VERT strips decode on the inter block path (gate RED)
Show full message
feat(av1): intra HORZ/VERT strips decode on the inter block path (gate RED)

An intra-coded rect strip in an inter frame now reads its mode info with the
inter frame's own intra syntax and decodes every pixel through decode_rect_split,
the machinery the key-frame rect paths already prove; the whole-shape refusal is
lifted, leaving only the 1:4 shape. The reject_residual gate moves past is_inter
(class refusal-short-circuits-its-own-code) so the intra arm can be reached at all.

Gate a_real_aomenc_inter_sequence_with_an_intra_rect_strip_decodes_pixel_exact
(+10bit) fires the 32x16 shape on a real aomenc stream and FAILS the pixel
compare: frame 5 Y, rows 58..95, max |diff| 3 (8-bit) / 8 (10-bit), no entropy
desync. See lanes/intrarect-r1.report.md.
crates/ec-av1/src/decode.rsmodified+245 -13
@@ -1511,6 +1511,22 @@ pub(crate) fn rect_leaf_coeff_hits() -> usize {
15111511 RECT_LEAF_COEFF_HITS.with(|c| c.get())
15121512 }
15131513
1514+// lane-intrarect r1: how many intra-coded HORZ/VERT strips decoded on the
1515+// INTER block path ([`decode_intra_rect_in_inter`]), per shape class --
1516+// [0] the superblock-level 64x32/32x64, [1] 32x16/16x32, [2] 16x8/8x16.
1517+// Every one of them was the named refusal "an intra-coded HORZ/VERT strip
1518+// needs rectangular intra prediction" before this round.
1519+thread_local! {
1520+ static INTRA_RECT_IN_INTER_HITS: std::cell::Cell<[usize; 3]> =
1521+ const { std::cell::Cell::new([0; 3]) };
1522+}
1523+
1524+/// Current value of [`INTRA_RECT_IN_INTER_HITS`] for one shape class
1525+/// (0 = 64x32/32x64, 1 = 32x16/16x32, 2 = 16x8/8x16).
1526+pub(crate) fn intra_rect_strip_in_inter_hits(class: usize) -> usize {
1527+ INTRA_RECT_IN_INTER_HITS.with(|c| c.get()[class])
1528+}
1529+
15141530 // lane-rectx r5: how many times a NON-strip `kf_y_mode` reader
15151531 // ([`decode_block`], [`decode_block_rect`], [`decode_block_rect64`]) took an
15161532 // above/left mode from the mi-exact map that DIFFERS from its coarse 16x16
@@ -5150,6 +5166,175 @@ fn decode_rect_split(
51505166 Ok(())
51515167 }
51525168
5169+/// One intra-coded HORZ/VERT strip on the INTER block path (lane-intrarect
5170+/// r1) -- the shape [`decode_inter_block`]'s intra arm refused by name
5171+/// because it predicts squares only. Every pixel here goes through the rect
5172+/// machinery the key-frame paths already prove: [`decode_rect_split`], which
5173+/// at `depth == 0` is the unsplit strip as a single transform unit and
5174+/// beyond it the per-unit walk of [`depth_to_tx_wh`].
5175+///
5176+/// What is genuinely different from [`decode_block_rect`] is the mode
5177+/// syntax: on an inter frame an intra block reads `y_mode[size_group]` and
5178+/// `uv_mode` (libaom `read_intra_block_mode_info`, decodemv.c:1065), never
5179+/// the key frame's `kf_y_mode` above/left pair. This mirrors the square
5180+/// intra-in-inter arm's own reads at the rect footprint, including its
5181+/// inherited gaps -- no `use_filter_intra` symbol (every inter gate recipe
5182+/// pins `--enable-filter-intra=0`; lane-fiinter owns that read for both the
5183+/// square and this arm) and a nonzero luma angle delta refused by name.
5184+///
5185+/// The strip's own neighbour records (luma per transform unit, chroma, skip
5186+/// grid, deblock grid) are [`decode_rect_split`]'s; the caller adds the
5187+/// inter-side bands and the mi map.
5188+#[allow(clippy::too_many_arguments)]
5189+fn decode_intra_rect_in_inter(
5190+ dec: &mut SymbolDecoder,
5191+ cdfs: &mut Cdfs,
5192+ neighbours: &mut Neighbours,
5193+ at: (usize, usize),
5194+ bw: usize,
5195+ bh: usize,
5196+ skip: bool,
5197+ allow_screen_content_tools: bool,
5198+ y: &mut PlaneBuf,
5199+ u: &mut PlaneBuf,
5200+ v: &mut PlaneBuf,
5201+ base_q_idx: u8,
5202+) -> Result<()> {
5203+ let (r, c) = at;
5204+ let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
5205+ // `size_group_lookup` (libaom common_data.h) and `bsize_to_tx_size_cat`
5206+ // (blockd.h) for the three 2:1 strip shapes: BLOCK_16X8 -> group 1 /
5207+ // cat 1, BLOCK_32X16 -> 2 / 2, BLOCK_64X32 -> 3 / 3 (the rectsplitx
5208+ // finding -- the category is NOT the same for every strip size).
5209+ // A 1:4 strip breaks that diagonal (BLOCK_32X8 is group 1 but cat 2), so
5210+ // it is refused by name rather than read from the wrong CDF row.
5211+ let (size_group, tx_cat) = match (bw.min(bh), bw.max(bh)) {
5212+ (8, 16) => (1usize, 1usize),
5213+ (16, 32) => (2, 2),
5214+ (32, 64) => (3, 3),
5215+ _ => {
5216+ return Err(unsupported(
5217+ "an intra-coded 1:4 (or other non-2:1) rect strip on the inter block path",
5218+ ))
5219+ }
5220+ };
5221+ // [`read_intra_mode_rect`]'s own refusal: palette/intrabc syntax is
5222+ // consumed for square blocks only, so a strip in a screen-content frame
5223+ // would skip symbols the encoder wrote.
5224+ if allow_screen_content_tools {
5225+ return Err(unsupported(
5226+ "a HORZ/VERT intra strip in a screen-content frame (palette syntax \
5227+ is consumed for square blocks only)",
5228+ ));
5229+ }
5230+ let mode = dec.symbol(&mut cdfs.y_mode[size_group]);
5231+ if mode >= 13 {
5232+ return Err(unsupported(
5233+ "an intra mode this decoder does not code (round 2)",
5234+ ));
5235+ }
5236+ if (V_PRED..=D67_PRED).contains(&mode) {
5237+ let angle = dec.symbol(&mut cdfs.angle_delta[mode - V_PRED]);
5238+ if angle != ANGLE_DELTA_ZERO {
5239+ return Err(unsupported(
5240+ "a nonzero angle delta (this encoder never writes one)",
5241+ ));
5242+ }
5243+ }
5244+ // `is_cfl_allowed` (spec 5.11.5) caps CFL at 32x32, so the
5245+ // superblock-level strip reads the no-CFL alphabet -- the same split
5246+ // [`read_intra_mode_rect`] makes for [`decode_block_rect64`].
5247+ let cfl_allowed = bw.max(bh) <= 32;
5248+ let uv_mode = if cfl_allowed {
5249+ dec.symbol(&mut cdfs.uv_mode_cfl[mode])
5250+ } else {
5251+ dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])
5252+ };
5253+ if (9..=12).contains(&uv_mode) {
5254+ SMOOTH_UV_HITS.with(|h| h.set(h.get() + 1));
5255+ }
5256+ let alpha = if cfl_allowed && uv_mode == UV_CFL_PRED {
5257+ Some(read_cfl_alphas(dec, cdfs))
5258+ } else {
5259+ None
5260+ };
5261+ let uv_predict_mode = if uv_mode == UV_CFL_PRED {
5262+ DC_PRED
5263+ } else {
5264+ uv_mode
5265+ };
5266+ let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) {
5267+ DIRECTIONAL_UV_HITS.with(|h| h.set(h.get() + 1));
5268+ read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED])
5269+ } else {
5270+ 0
5271+ };
5272+ if angle_delta_uv != 0 {
5273+ UV_ANGLE_DELTA_HITS.with(|h| h.set(h.get() + 1));
5274+ }
5275+ // The intra-edge filter type is the NEIGHBOUR's mode (libaom
5276+ // `get_filt_type`), luma's off the luma neighbours and chroma's off the
5277+ // chroma ones -- [`decode_block_rect`]'s own pair.
5278+ let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);
5279+ let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);
5280+ if smooth_neighbor {
5281+ SMOOTH_LUMA_HITS.with(|h| h.set(h.get() + 1));
5282+ }
5283+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c);
5284+ let depth = if TX_SELECT_INTER.with(std::cell::Cell::get) {
5285+ let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh);
5286+ match tx_cat {
5287+ 1 => dec.symbol(&mut cdfs.tx_size_cat1[ctx]),
5288+ 2 => dec.symbol(&mut cdfs.tx_size_cat2[ctx]),
5289+ _ => dec.symbol(&mut cdfs.tx_size_cat3[ctx]),
5290+ }
5291+ } else {
5292+ 0
5293+ };
5294+ if depth != 0 {
5295+ TX_DEPTH_HITS.with(|h| h.set(h.get() + 1));
5296+ }
5297+ let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth);
5298+ let modes = RectStripModes {
5299+ skip,
5300+ mode,
5301+ angle_delta_y: 0,
5302+ uv_predict_mode,
5303+ angle_delta_uv,
5304+ alpha,
5305+ filter_intra: None,
5306+ smooth_neighbor,
5307+ smooth_neighbor_uv,
5308+ };
5309+ decode_rect_split(
5310+ dec,
5311+ cdfs,
5312+ neighbours,
5313+ (mi_r, mi_c),
5314+ bw,
5315+ bh,
5316+ tx_w,
5317+ tx_h,
5318+ &modes,
5319+ y,
5320+ u,
5321+ v,
5322+ base_q_idx,
5323+ REDUCED_TX_SET_INTER.with(std::cell::Cell::get),
5324+ )?;
5325+ let class = match bw.max(bh) {
5326+ 64 => 0,
5327+ 32 => 1,
5328+ _ => 2,
5329+ };
5330+ INTRA_RECT_IN_INTER_HITS.with(|h| {
5331+ let mut v = h.get();
5332+ v[class] += 1;
5333+ h.set(v);
5334+ });
5335+ Ok(())
5336+}
5337+
51535338 /// Decodes one true `bw`x`bh` `PARTITION_HORZ`/`PARTITION_VERT` intra strip
51545339 /// (lane-intradisp r1, spec `decode_block` restricted to a 32x32 quadrant's
51555340 /// two rect children). Only the `skip` case is supported: `skip`/`y_mode`/
@@ -13458,15 +13643,6 @@ fn decode_inter_block(
1345813643 maybe_read_cdef_idx(dec, r * SUB_MI as usize, c * SUB_MI as usize, skip);
1345913644 maybe_read_delta_q(dec, cdfs, r * SUB_MI as usize, c * SUB_MI as usize, side == 64, skip);
1346013645 maybe_read_delta_lf(dec, cdfs, r * SUB_MI as usize, c * SUB_MI as usize, side == 64, skip);
13461- // lane-warp r5: see `reject_residual` -- a square-block decode of a
13462- // HORZ_B strip is symbol-exact only for `skip` (no residual, no
13463- // motion_mode/warp symbol), so gate here before any further read.
13464- if reject_residual && !skip {
13465- return Err(unsupported(
13466- "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding",
13467- ));
13468- }
13469-
1347013646 let (has_above, has_left) = (
1347113647 r > neighbours.tile_row0_mi / (SUB / MI),
1347213648 c > neighbours.tile_col0_mi / (SUB / MI),
@@ -13482,6 +13658,21 @@ fn decode_inter_block(
1348213658 dec.debug_state().0
1348313659 );
1348413660 }
13661+ // lane-warp r5: see `reject_residual` -- a square-block decode of a
13662+ // HORZ_B strip is symbol-exact only for `skip` (no residual, no
13663+ // motion_mode/warp symbol). lane-intrarect r1 MOVED this gate from just
13664+ // after the `skip` read to here, past `is_inter` (class
13665+ // [[refusal-short-circuits-its-own-code]]: at the old place it refused
13666+ // 24/24 attempts of this lane's own gate before the intra arm below
13667+ // could run). An INTRA strip with its true `write_w`x`write_h` footprint
13668+ // now codes its residual rectangularly ([`decode_intra_rect_in_inter`]);
13669+ // an INTER one, and a strip decoded with square dimensions anyway, still
13670+ // cannot.
13671+ if reject_residual && !skip && (is_inter || (write_w == side && write_h == side)) {
13672+ return Err(unsupported(
13673+ "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding",
13674+ ));
13675+ }
1348513676 if std::env::var_os("EC_AV1_TELL").is_some() {
1348613677 eprintln!(
1348713678 "TELL mi_row={} mi_col={} label=post_is_inter skip_mode={skip_mode} skip={skip} is_inter={is_inter} tell={} range={}",
@@ -15255,10 +15446,51 @@ fn decode_inter_block(
1525515446 // already-square-predicted buffer). Named refusal instead of a
1525615447 // silently wrong square-shaped intra prediction.
1525715448 if write_w != side || write_h != side {
15258- return Err(unsupported(
15259- "an intra-coded HORZ/VERT strip needs rectangular intra prediction \
15260- this decoder does not code yet",
15261- ));
15449+ // lane-intrarect r1: the strip decodes through its own rect
15450+ // machinery ([`decode_intra_rect_in_inter`] -> the key-frame
15451+ // paths' [`decode_rect_split`]) instead of refusing. That call
15452+ // already writes everything the shared tail below would for a
15453+ // square block EXCEPT the inter-side bands and the mi map, so
15454+ // this arm returns rather than falling through (a second
15455+ // `record_rect`/`fill_lf_grid_rect` at block granularity would
15456+ // overwrite the per-transform-unit records it just made).
15457+ decode_intra_rect_in_inter(
15458+ dec,
15459+ cdfs,
15460+ neighbours,
15461+ at,
15462+ write_w,
15463+ write_h,
15464+ skip,
15465+ allow_screen_content_tools,
15466+ y,
15467+ u,
15468+ v,
15469+ base_q_idx,
15470+ )?;
15471+ let (mi_r0, mi_c0) = (r * SUB_MI as usize, c * SUB_MI as usize);
15472+ for dr in 0..write_h / MI {
15473+ for dc in 0..write_w / MI {
15474+ grid.set(
15475+ mi_r0 + dr,
15476+ mi_c0 + dc,
15477+ MiInfo {
15478+ is_inter: false,
15479+ ref_frame: -1,
15480+ ref_frame1: None,
15481+ mv1: None,
15482+ mv: (0, 0),
15483+ is_new_mv: false,
15484+ size: write_w / MI,
15485+ size_h: write_h / MI,
15486+ is_global_mv0: false,
15487+ is_global_mv1: false,
15488+ },
15489+ );
15490+ }
15491+ }
15492+ neighbours.record_inter_rect(at, write_w, write_h, skip, false, 0, [3, 3], skip_mode);
15493+ return Ok(());
1526215494 }
1526315495 let mode = dec.symbol(&mut cdfs.y_mode[size_group]);
1526415496 if mode >= 13 {
crates/ec-av1/src/refusal_inventory.rsmodified+5 -1
@@ -65,7 +65,11 @@ const REFUSALS: &[&str] = &[
6565 "a masked compound 64x64 inter block (compound_type is inferred, not coded, at this size)",
6666 "an inter partition below 16x16 other than SPLIT (16x8/8x16 rect inter leaves are not coded yet)",
6767 "an intra mode this decoder does not code (round 2)",
68- "an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet",
68+ // lane-intrarect r1 lifted the whole-shape refusal that stood here (the
69+ // inter path's intra arm now routes 2:1 strips through `decode_rect_split`);
70+ // what is left is the 1:4 shape, whose `bsize_to_tx_size_cat` breaks the
71+ // size-group/category diagonal the 2:1 shapes share.
72+ "an intra-coded 1:4 (or other non-2:1) rect strip on the inter block path",
6973 // Lifted for the 16x8/8x16 leaf by lane-fistrip; still live one level
7074 // down, at the 4x8/8x4 sub-8 leaf (lane-tx4x8's `decode_leaf_rect8`).
7175 "filter intra on a HORZ/VERT strip (this decoder predicts square-only)",
crates/ec-av1/src/stream.rsmodified+318 -0
@@ -3583,6 +3583,324 @@ mod tests {
35833583 tx_select_inter_gate(10);
35843584 }
35853585
3586+ /// lane-intrarect r1's decisive gate: a real aomenc INTER sequence whose
3587+ /// hard mid-GOP content cut makes aomenc code INTRA blocks inside inter
3588+ /// frames, with rect partitions ON so those intra blocks land on
3589+ /// HORZ/VERT strip shapes. Every such block was the named refusal "an
3590+ /// intra-coded HORZ/VERT strip needs rectangular intra prediction this
3591+ /// decoder does not code yet" until this round; they now decode through
3592+ /// the same `decode_rect_split` machinery the key-frame rect paths use.
3593+ ///
3594+ /// Hard-asserts per-shape counters (`intra_rect_strip_in_inter_hits`:
3595+ /// 0 = 64x32/32x64, 1 = 32x16/16x32, 2 = 16x8/8x16) summed over the
3596+ /// attempts that were actually pixel-compared -- at least TWO of the
3597+ /// three shape classes must fire, so a green run cannot come from one
3598+ /// lucky size. A decode that succeeds is ALWAYS pixel-compared (class
3599+ /// [[gate-skips-on-its-own-failure]]); exhausting every attempt without
3600+ /// two shapes is a FAILURE, never a SKIP.
3601+ #[test]
3602+ fn a_real_aomenc_inter_sequence_with_an_intra_rect_strip_decodes_pixel_exact() {
3603+ intra_rect_in_inter_gate(8);
3604+ }
3605+
3606+ /// The 10-bit arm (both of the user's films are `yuv420p10le`).
3607+ #[test]
3608+ fn a_real_aomenc_inter_sequence_with_an_intra_rect_strip_decodes_pixel_exact_10bit() {
3609+ intra_rect_in_inter_gate(10);
3610+ }
3611+
3612+ fn intra_rect_in_inter_gate(bit_depth: u32) {
3613+ const NAME: &str = "a_real_aomenc_inter_sequence_with_an_intra_rect_strip_decodes_pixel_exact";
3614+ if !have_ffmpeg() {
3615+ eprintln!("SKIP {NAME}: no ffmpeg");
3616+ return;
3617+ }
3618+ if !have_aomenc() {
3619+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
3620+ return;
3621+ }
3622+ let (width, height, frame_count) = (96usize, 96usize, 8usize);
3623+ let mut refusals: Vec<String> = Vec::new();
3624+ let mut uncounted_exact = 0u32;
3625+ let mut compared = 0u32;
3626+ let mut shapes = [0usize; 3];
3627+ for attempt in 0..45u32 {
3628+ let seed = 42 + attempt;
3629+ // mandelbrot's fractal detail plus a HARD cut at frame 4: half
3630+ // the picture becomes a flat white box, which no motion vector
3631+ // can predict, so aomenc's RD codes those blocks INTRA inside an
3632+ // inter frame. The box's vertical edge at x=48 is what makes the
3633+ // partition search reach for HORZ/VERT strips there.
3634+ // A FAST ZOOM: `end_scale`/`end_pts` make mandelbrot rush
3635+ // through its own zoom, so consecutive frames share almost no
3636+ // content and aomenc's RD codes blocks INTRA inside INTER frames
3637+ // (`--kf-min-dist=1000` forbids a new key frame). That is the
3638+ // only way a real encoder reaches this decoder's intra-in-inter
3639+ // arm; a slowly-evolving source codes every rect strip inter.
3640+ let source = format!(
3641+ "mandelbrot=size={width}x{height}:start_scale={}:end_scale=0.004:end_pts=8:rate=25",
3642+ 5.0 - f64::from(attempt) * 0.06
3643+ );
3644+ let y4m = Command::new("ffmpeg")
3645+ .args([
3646+ "-v",
3647+ "error",
3648+ "-f",
3649+ "lavfi",
3650+ "-i",
3651+ &source,
3652+ "-vf",
3653+ "hue=s=0",
3654+ "-pix_fmt",
3655+ if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" },
3656+ "-strict",
3657+ "-1",
3658+ "-t",
3659+ "0.32",
3660+ "-f",
3661+ "yuv4mpegpipe",
3662+ "-strict",
3663+ "-1",
3664+ "-",
3665+ ])
3666+ .stdin(Stdio::null())
3667+ .stdout(Stdio::piped())
3668+ .stderr(Stdio::piped())
3669+ .output()
3670+ .expect("ffmpeg failed to run");
3671+ assert!(
3672+ y4m.status.success(),
3673+ "ffmpeg fixture: {}",
3674+ String::from_utf8_lossy(&y4m.stderr)
3675+ );
3676+ let depth_args: &[&str] = if bit_depth == 10 {
3677+ &["-b", "10", "--input-bit-depth=10"]
3678+ } else {
3679+ &[]
3680+ };
3681+ // MEASURED (r1): the speed preset gates the feature (class
3682+ // [[gate-preset-gates-the-feature]]) -- at `--cpu-used=4` this
3683+ // content produces no rect partition at all, at `--cpu-used=0`
3684+ // aomenc emits AB partitions the tile path refuses (it ignores
3685+ // `--enable-ab-partitions=0`, ledger). So the attempt sweep walks
3686+ // the preset as well as the seed.
3687+ let cpu = format!("--cpu-used={}", attempt % 5);
3688+ // The quantiser drives how finely the RD partitions: the sweep
3689+ // walks it too, so "no rect strip fired" cannot be an artefact of
3690+ // one cq.
3691+ let cq = format!("--cq-level={}", [30u32, 20, 12][(attempt / 5) as usize % 3]);
3692+ let mut child = Command::new(aomenc_path())
3693+ .args(depth_args)
3694+ .arg(&cpu)
3695+ .arg(&cq)
3696+ .args([
3697+ // class [[aomenc-first-flag-wins]]: every flag is spelled
3698+ // exactly ONCE in this recipe, so there is no override to
3699+ // order. These four are what this gate is about.
3700+ "--enable-rect-partitions=1",
3701+ // MEASURED (r1): the charter's `--min-partition-size=8`
3702+ // makes 24/24 attempts stop at a sub-16 AB-partition
3703+ // refusal ("a HORZ_A/HORZ_B/VERT_A partition below 16x16",
3704+ // "a coded (non-skip) HORZ_B/VERT_B rect strip below
3705+ // 16x16") before any intra rect strip is reached -- those
3706+ // are other lanes' surfaces. 16 keeps the 16x8/8x16 shape
3707+ // reachable (a 16x16 block's own HORZ/VERT children).
3708+ "--min-partition-size=16",
3709+ "--max-partition-size=64",
3710+ // MEASURED (r1): with tx-size search ON, 24/24 attempts stop at
3711+ // the SQUARE intra-in-inter arm's own refusal ("an intra
3712+ // block in an inter frame whose tx_depth splits its luma
3713+ // transform (round 1)", read_block_tx_size) long before a
3714+ // rect strip is reached -- that arm is another lane's
3715+ // surface. OFF, no tx-depth symbol is coded at all and
3716+ // every rect strip here is the unsplit single-transform
3717+ // case. The SPLIT rect arm (`depth_to_tx_wh` +
3718+ // decode_rect_split's per-unit walk) is wired but stays
3719+ // UNGATED on this path until that square refusal lifts.
3720+ "--enable-tx-size-search=0",
3721+ "--codec=av1",
3722+ "--passes=1",
3723+ "--end-usage=q",
3724+ "--lag-in-frames=0",
3725+ "--auto-alt-ref=0",
3726+ // One key frame at the head: the frames after the cut must
3727+ // stay INTER frames carrying intra blocks, not become a
3728+ // new key frame.
3729+ "--kf-min-dist=1000",
3730+ "--kf-max-dist=1000",
3731+ "--threads=1",
3732+ "--row-mt=0",
3733+ "--enable-order-hint=0",
3734+ "--enable-warped-motion=0",
3735+ "--enable-obmc=0",
3736+ "--enable-masked-comp=0",
3737+ "--enable-interintra-comp=0",
3738+ "--enable-dist-wtd-comp=0",
3739+ "--enable-diff-wtd-comp=0",
3740+ "--enable-onesided-comp=0",
3741+ "--enable-interintra-wedge=0",
3742+ "--enable-smooth-interintra=0",
3743+ "--enable-ab-partitions=0",
3744+ "--enable-1to4-partitions=0",
3745+ // The intra-in-inter arm reads no `use_filter_intra`
3746+ // symbol (square OR rect) -- lane-fiinter owns that read.
3747+ "--enable-filter-intra=0",
3748+ "--enable-smooth-intra=0",
3749+ "--enable-paeth-intra=0",
3750+ "--enable-directional-intra=0",
3751+ "--enable-angle-delta=0",
3752+ "--enable-cdef=0",
3753+ "--enable-restoration=0",
3754+ "--enable-palette=0",
3755+ "--enable-intrabc=0",
3756+ "--enable-cfl-intra=0",
3757+ "--enable-ref-frame-mvs=0",
3758+ "--obu",
3759+ "-o",
3760+ "-",
3761+ "-",
3762+ ])
3763+ .stdin(Stdio::piped())
3764+ .stdout(Stdio::piped())
3765+ .stderr(Stdio::piped())
3766+ .spawn()
3767+ .expect("aomenc failed to start");
3768+ child
3769+ .stdin
3770+ .take()
3771+ .expect("aomenc stdin")
3772+ .write_all(&y4m.stdout)
3773+ .expect("writing y4m to aomenc");
3774+ let out = child.wait_with_output().expect("aomenc failed to run");
3775+ assert!(
3776+ out.status.success(),
3777+ "aomenc refused the fixture: {}",
3778+ String::from_utf8_lossy(&out.stderr)
3779+ );
3780+ let stream = out.stdout;
3781+ let before = [
3782+ decode::intra_rect_strip_in_inter_hits(0),
3783+ decode::intra_rect_strip_in_inter_hits(1),
3784+ decode::intra_rect_strip_in_inter_hits(2),
3785+ ];
3786+ let kf_rect_before = decode::rect_partition_hits();
3787+ let frames = match decode_stream(&stream) {
3788+ Ok(frames) => frames,
3789+ Err(e) => {
3790+ let msg = e.to_string();
3791+ assert!(
3792+ msg.contains("unsupported"),
3793+ "intra-rect-in-inter decode failed outright (seed {seed}): {msg}"
3794+ );
3795+ refusals.push(format!("seed {seed} {cpu} {cq}: {msg}"));
3796+ continue;
3797+ }
3798+ };
3799+ let delta = [
3800+ decode::intra_rect_strip_in_inter_hits(0) - before[0],
3801+ decode::intra_rect_strip_in_inter_hits(1) - before[1],
3802+ decode::intra_rect_strip_in_inter_hits(2) - before[2],
3803+ ];
3804+ let ffmpeg_frames = if bit_depth == 10 {
3805+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
3806+ } else {
3807+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
3808+ };
3809+ assert_eq!(frames.len(), frame_count);
3810+ eprintln!(
3811+ "intrarect gate {bit_depth}-bit seed={seed} {cpu} {cq}: intra rect strips in inter frames \
3812+ 64-level={} 32-level={} 16-level={}, key-frame rect strips this stream={}",
3813+ delta[0], delta[1], delta[2],
3814+ decode::rect_partition_hits() - kf_rect_before
3815+ );
3816+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
3817+ for (plane, (g, w)) in [
3818+ ("Y", (&got.y, &want.y)),
3819+ ("U", (&got.u, &want.u)),
3820+ ("V", (&got.v, &want.v)),
3821+ ] {
3822+ let stride = if plane == "Y" { width } else { width / 2 };
3823+ if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) {
3824+ eprintln!(
3825+ "intrarect gate {bit_depth}-bit seed={seed}: frame {i} {plane} first \
3826+ diff at ({}, {}) got {} want {} ({} samples differ)",
3827+ at % stride,
3828+ at / stride,
3829+ g[at],
3830+ w[at],
3831+ g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(),
3832+ );
3833+ // Magnitude separates a deblock/prediction difference
3834+ // (all |d| == 1) from an entropy desync (large,
3835+ // arbitrary): the first thing r2 needs to know.
3836+ let maxd = g
3837+ .iter()
3838+ .zip(w.iter())
3839+ .map(|(a, b)| i32::from(*a).abs_diff(i32::from(*b)))
3840+ .max()
3841+ .unwrap_or(0);
3842+ let rows: std::collections::BTreeSet<usize> = g
3843+ .iter()
3844+ .zip(w.iter())
3845+ .enumerate()
3846+ .filter(|(_, (a, b))| a != b)
3847+ .map(|(k, _)| k / stride)
3848+ .collect();
3849+ eprintln!(
3850+ "intrarect gate {bit_depth}-bit seed={seed}: frame {i} {plane} max \
3851+ |diff|={maxd}, rows {:?}..{:?}",
3852+ rows.iter().next(),
3853+ rows.iter().next_back()
3854+ );
3855+ }
3856+ assert_eq!(g, w, "{plane} vs ffmpeg (seed {seed}, frame {i})");
3857+ }
3858+ }
3859+ compared += 1;
3860+ if delta.iter().all(|d| *d == 0) {
3861+ uncounted_exact += 1;
3862+ refusals.push(format!(
3863+ "seed {seed} {cpu} {cq}: decoded and pixel-compared, but no intra rect strip on the \
3864+ inter path"
3865+ ));
3866+ }
3867+ for k in 0..3 {
3868+ shapes[k] += delta[k];
3869+ }
3870+ if shapes.iter().filter(|n| **n > 0).count() >= 2 {
3871+ break;
3872+ }
3873+ }
3874+ gate_buckets(
3875+ NAME,
3876+ compared - uncounted_exact,
3877+ uncounted_exact,
3878+ refusals.len() - uncounted_exact as usize,
3879+ );
3880+ eprintln!(
3881+ "{NAME} ({bit_depth}-bit): compared {compared} streams, intra rect strips in inter \
3882+ frames per shape: 64x32/32x64={} 32x16/16x32={} 16x8/8x16={}; refusals:\n{}",
3883+ shapes[0],
3884+ shapes[1],
3885+ shapes[2],
3886+ refusals.join("\n")
3887+ );
3888+ assert!(
3889+ compared > 0,
3890+ "{NAME} ({bit_depth}-bit): every attempt hit a named refusal -- nothing was \
3891+ pixel-compared:\n{}",
3892+ refusals.join("\n")
3893+ );
3894+ assert!(
3895+ shapes.iter().filter(|n| **n > 0).count() >= 2,
3896+ "{NAME} ({bit_depth}-bit): fewer than two intra-rect shape classes fired over \
3897+ {compared} compared streams (64-level={} 32-level={} 16-level={})",
3898+ shapes[0],
3899+ shapes[1],
3900+ shapes[2]
3901+ );
3902+ }
3903+
35863904 fn tx_select_inter_gate(bit_depth: u32) {
35873905 if !have_ffmpeg() {
35883906 eprintln!(
lanes/intrarect-r1.report.mdmodified+73 -112
@@ -1,125 +1,86 @@
1-# lane-intrarect r1 report
1+# lane-intrarect r1 — intra rect strips on the inter block path
22
3-VERDICT: DONE -- `intra::predict`/`Edges` are rect-capable (`bw != bh`),
4-C-verified for 8 rect shapes across DC/SMOOTH/PAETH + 17 directional angles
5-x {enable_edge_filter, smooth_neighbor}; full lib suite 224/224 (was
6-223/223, +1 the new C-verify test), square behaviour unchanged; tile
7-dispatch still refuses rect/AB partitions.
3+Branch `lane-intrarect` off `lane-rectsplitx` cbf8ffd. **Result: code landed, gate RED
4+(one real residual defect, evidence below). The lane does not merge in this state.**
85
96 ## What changed
10-`crates/ec-av1/src/intra.rs`:
11-- `Edges::build`, `predict`, `directional`, `dc` all take `(bw, bh)` instead
12- of one `side`. `Edges::build`'s extension length is `bw + bh` (the reach
13- `av1_dr_prediction_z1_c`'s `max_base_x` and `z3_c`'s `max_base_y` both use,
14- libaom `reconintra.c`).
15-- `dc()`: exact `(sum + count/2) / count` stays for `bw == bh` (bit-identical
16- square path); a new `dc_rect_multiplier` ports `dc_predictor_rect`'s
17- multiply-shift approximate divide for `bw != bh` -- derived from `bw + bh`'s
18- odd factor (per libaom's own comment: shift until odd, `d == 3` for every
19- 1:2 ratio, `d == 5` for every 1:4 one), not tabulated.
20-- `SMOOTH_PRED`/`SMOOTH_V_PRED`/`SMOOTH_H_PRED`: width and height now index
21- separate `SM_WEIGHTS` rows (`smooth_weights + bw - 4` / `+ bh - 4` in the
22- source), matching `smooth_predictor`'s real per-axis split.
23-- `directional()`: `bw + bh` reach throughout (was `2 * side`); the edge
24- filter/upsample `n_px` extensions are CROSS-axis -- above's run-past
25- extension is `bh`, left's is `bw` (`reconintra.c`'s `txwpx`/`txhpx` argument
26- swap between the above and left calls). This is the same
27- scan-weights-cross-axis class the ledger already has two instances of.
28-- **Bug found and fixed in the same diff**: `intra_edge_filter_strength` was
29- missing the `blk_wh <= 12` branch present in libaom. No square block's
30- `bw + bh` ever lands in `9..=12` (sides are 4/8/16/32/64, sums are always
31- even and >= 8), so this was silently unreachable before this lane; a rect
32- block like 4x8 (`blk_wh == 12`) hits it. Ported verbatim.
33-- 21 call sites (`encode.rs` x4, `decode.rs` x2, `predict_filter_intra`'s own
34- internal `Edges::build` call) all pass `(side, side)` -- zero behaviour
35- change there, proven by the full suite staying green.
36-- `predict_filter_intra` (filter-intra) is untouched and stays square-only:
37- spec `av1_filter_intra_allowed_bsize` never offers it on a rect block, so
38- there is nothing to widen -- correctly out of scope, not a gap.
397
40-## C-verification (what's C-verified vs transcribed-only)
41-`lanes/intrarect_dump.c`: standalone C, **not linked against the built
42-oracle** (linking libaom's actual `.o`s pulled in RTCD/aom_config
43-dependencies past this lane's budget) -- an independent hand-transcription
44-of `aom_dsp/intrapred.c`'s `dc_predictor_rect`/`smooth_predictor`/
45-`paeth_predictor` and `av1/common/reconintra.c`'s
46-`av1_dr_prediction_z1/z2/z3_c` + `intra_edge_filter_strength` +
47-`av1_use_intra_edge_upsample` + `av1_filter_intra_edge_c` +
48-`av1_upsample_intra_edge_c`, read fresh from `~/.cache/aom-oracle/src` this
49-round (same independent-transcription pattern `lanes/wedge_dump.c` used,
50-per the charter's shared-oracle-blindness note).
8+- `crates/ec-av1/src/decode.rs` (`decode_intra_rect_in_inter`, new, right before
9+ `decode_block_rect`): an intra-coded HORZ/VERT strip on the inter block path reads its
10+ mode info with the INTER frame's own intra syntax (`y_mode[size_group]` /
11+ `uv_mode_cfl|uv_mode_no_cfl` / cfl alphas / uv angle delta — mirroring the square
12+ intra-in-inter arm, including its inherited gaps: no `use_filter_intra` symbol, nonzero
13+ luma angle delta refused), its tx depth from the shape's own `bsize_to_tx_size_cat`
14+ (16x8 -> cat1, 32x16 -> cat2, 64x32 -> cat3, ctx from `tx_size_context_rect`), then hands
15+ every pixel to `decode_rect_split` — the same machinery the key-frame rect paths use, which
16+ at `depth == 0` is the unsplit single-transform strip.
17+- `crates/ec-av1/src/decode.rs` (`decode_inter_block`, the `write_w != side` arm): calls it
18+ instead of refusing, then writes the mi map (`is_inter: false`, rect `size`/`size_h`) and
19+ `record_inter_rect`, and returns — `decode_rect_split` already wrote the luma per-TU,
20+ chroma, skip and deblock records the shared tail would otherwise stamp at block
21+ granularity.
22+- `crates/ec-av1/src/decode.rs`: the `reject_residual && !skip` refusal MOVED from just after
23+ the `skip` read to just after `is_inter` (class `refusal-short-circuits-its-own-code`) and
24+ narrowed to `is_inter || (write_w == side && write_h == side)`. MEASURED: at its old place
25+ it refused 24/24 attempts of this lane's own gate before the intra arm could run.
26+- `crates/ec-av1/src/refusal_inventory.rs`: lifted "an intra-coded HORZ/VERT strip needs
27+ rectangular intra prediction this decoder does not code yet"; added the residue
28+ "an intra-coded 1:4 (or other non-2:1) rect strip on the inter block path" (a 1:4 strip
29+ breaks the size-group/tx-cat diagonal the 2:1 shapes share, so it is refused rather than
30+ read from the wrong CDF row).
31+- `crates/ec-av1/src/stream.rs`: gate
32+ `a_real_aomenc_inter_sequence_with_an_intra_rect_strip_decodes_pixel_exact` (+ `_10bit`),
33+ 45 attempts sweeping seed x `--cpu-used` 0..4 x `--cq-level` {30,20,12}, per-shape counter
34+ `decode::intra_rect_strip_in_inter_hits(0|1|2)`, every frame Y/U/V compared, no SKIP on a
35+ decode error or mismatch.
5136
52-**C-verified** (checksum-matched, 568 cases, `intra::tests::rect_predictors_match_c_dump`):
53-- `DC_PRED` (both the exact-divide and `dc_predictor_rect` approximate-divide
54- paths, since the test only exercises `bw != bh` shapes here)
55-- `SMOOTH_PRED`, `PAETH_PRED`
56-- All eight directional modes (`V_PRED`, `H_PRED`, `D45`/`D67`/`D113`/`D135`/
57- `D157`/`D203_PRED`) across z1/z2/z3, both `enable_edge_filter` states, both
58- `smooth_neighbor` states, for shapes 8x4/4x8/16x8/8x16/4x16/16x4/32x16/16x32
59- (both 1:2 and 1:4 ratios, both orientations)
37+## Recipe deviations from the charter (each measured, not chosen)
6038
61-**Transcribed-only, not independently C-verified this round**:
62-- `SMOOTH_V_PRED`/`SMOOTH_H_PRED` -- same weight-split code path as
63- `SMOOTH_PRED` (which is verified), not separately dumped
64-- `filter_intra_edge_corner`'s rect gate (`reach >= 24`) -- exercised by the
65- dump's angle/shape sweep whenever it applies, but not isolated as its own
66- case
67-- The `n_top`/`n_left` < full-reach path (a block against the frame edge with
68- fewer real neighbour samples than `bw`/`bh`) -- the dump feeds full-length
69- synthetic neighbours throughout; this is unchanged pre-existing
70- `Edges::build` repeat-extension logic, not something this lane's widening
71- touches structurally, and it's exercised (for squares) by the full suite
39+- `--min-partition-size=8` -> `16`: at 8, 24/24 attempts stop at sub-16 AB refusals
40+ ("a HORZ_A/HORZ_B/VERT_A partition below 16x16", "a coded (non-skip) HORZ_B/VERT_B rect
41+ strip below 16x16") — other lanes' surfaces.
42+- `--enable-tx-size-search=1` -> `0`: with it on, 24/24 attempts stop at the SQUARE
43+ intra-in-inter arm's own refusal ("an intra block in an inter frame whose tx_depth splits
44+ its luma transform (round 1)", `read_block_tx_size`). Consequence: **the SPLIT rect arm on
45+ the inter path is wired but UNGATED**; only the unsplit strip is exercised.
46+- Content: the charter's mandelbrot + overlay cut never produced an intra rect strip (every
47+ rect strip in those streams was INTER, refused by lane-inter4's wall). The fixture that
48+ works is a FAST-ZOOM mandelbrot (`end_scale=0.004:end_pts=8`), where consecutive frames
49+ share almost no content so aomenc codes blocks intra inside inter frames.
50+- `--cpu-used` swept, not fixed: at 4 this content yields no rect partition at all
51+ (class `gate-preset-gates-the-feature`); at 0 aomenc emits AB partitions the tile path
52+ refuses (it ignores `--enable-ab-partitions=0`). Only cpu-used 1..3 both decode and produce
53+ rect strips.
7254
73-## Gate ladder run
74-(a) full lib suite: `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --release
75---lib -- --nocapture` -- 224 passed, 0 failed, 17 ignored (was 223/0/17
76-before this lane's own test; no regression, no `--skip` needed -- the
77-charter's `--skip a_real_aomenc_stream_with_interintra_wedge` workaround is
78-stale per the task's own update, whole suite runs in ~70s).
79-(b)/(c) the 14-pin default list and the named intra gates
80-(`filter_intra`/`directional_chroma`/`tx_select`/`intra_with_deblocking`) are
81-all inside that same full-suite run (test names visible in the tail output:
82-`a_real_aomenc_stream_with_...` for all of them), all green.
55+## Gate result — RED
8356
84-## Commits (this worktree, lane-intrarect branch, not pushed)
85-- `bade5c8` feat(av1): widen intra::predict/Edges to rect (bw != bh)
86-- `6813a8a` test(av1): C-verify rect intra predictors against an independent transcription
57+Command:
58+`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-intrarect EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j3`
8759
88-## Deviations from the charter
89-- Skipped the charter's stale `--skip a_real_aomenc_stream_with_interintra_wedge`
90- per the task's explicit override.
91-- Built the C harness as a standalone transcription rather than linking the
92- oracle's real `.o` files, matching `wedge_dump.c`'s existing pattern
93- (charter explicitly offers this as the "OR better" option) -- linking the
94- real oracle intrapred code would need RTCD/aom_config plumbing not worth
95- the budget for this lane.
60+EVIDENCE: $HOME/.cache/intrarect-suite.log | 45-attempt aomenc sweep, both depths, every frame Y/U/V vs ffmpeg | 8-bit seed 69 (`--cpu-used=2 --cq-level=12`) fired 1 intra rect strip at the 32x16/16x32 shape and frame 5 Y differs: first diff (88,58) got 97 want 98, 670 samples, max |diff|=3, rows 58..95. 10-bit seed 78 (`--cpu-used=1 --cq-level=20`) fired 1 strip at the same shape: frame 5 Y first diff (80,58) got 393 want 394, 533 samples, max |diff|=8, rows 58..95.
9661
97-## Next lane
98-Flip the KEY-frame tile dispatch (`decode.rs` ~3624/~3841) to accept the
99-17/40 refused rect/AB partition attempts now that the predictor underneath
100-is rect-capable -- out of scope for r1 by charter, unchanged this round.
62+Suite: `335 passed; 2 failed (this lane's two new gates); 29 ignored` — nothing else regressed,
63+`refusal_inventory` and `gate_coverage` green with the moved refusal and the lifted string.
10164
102-## Cross-provider verification (opus, 2026-08-30) — PASS, with two corrections
65+Shape coverage over the sweep: 32x16/16x32 fired (1 stream per depth); **16x8/8x16 never fired**
66+(sub-16 partitions on the inter path refuse earlier) and **64x32/32x64 is unreachable on this
67+branch at all** — the inter tile path refuses any SB-level partition other than NONE/SPLIT, so
68+a superblock-level intra strip cannot be produced. The charter's "at least two shapes" bar is
69+therefore not reachable here; the assert is left as-is (>= 2) and currently fails on the
70+pixel compare first.
10371
104-All 6 claims CONFIRMED against pinned libaom v3.13.3: square paths provably
105-bit-identical (every `side` -> `(bw,bh)` substitution audited term by term);
106-`dc_predictor_rect`'s 0x5556/0x3334 multiply-shift and the `sum + ((bw+bh)>>1)`
107-dividend exact (intrapred.c:236-279); smooth weight rows not transposed
108-(intrapred.c:89-105); directional edge filter/upsample extension correctly
109-CROSS-axis (reconintra.c:1213-1240); the C harness genuinely independent (its
110-own `+bw-4` weight layout, structurally different from our `[bw..bw*2]` spec
111-layout, so a layout error cannot cancel out) covering 568 rect cases.
72+## Residue
11273
113-CORRECTIONS to this report's earlier claims:
114-1. "Fixed a latent `intra_edge_filter_strength` bug (missing `blk_wh<=12`
115- branch)" is OVERSTATED. The branch does exist in reconintra.c:996-997, but
116- it is behaviourally IDENTICAL to its `<=16` successor (both `d >= 40 ->
117- strength 1`), so adding it changes no output for any input. It is a
118- fidelity-of-transcription improvement with zero behavioural effect, not a
119- bug fix.
120-2. The harness's uncovered modes are V_PRED and H_PRED **in addition to** the
121- SMOOTH_V/SMOOTH_H this report named. All four are transcribed-only; the
122- verifier hand-checked SMOOTH_V/H against intrapred.c:115-172 (correct), and
123- V/H are axis-free single-edge reads carrying no rect risk.
124-Also uncovered: `Edges::build`'s repeat-extension branch is never exercised at
125-rect reach (the harness always supplies a full bw+bh neighbour run).
74+- fix-now (r2): the pixel defect above. Frames 0..4 are exact and the magnitudes are small
75+ (<= 3 at 8 bit), so this is NOT an entropy desync — the tile stays in sync. The diff band
76+ starts at row 58 and runs to the frame bottom, i.e. the strip's own bottom deblock band
77+ (edge at y=64 filters rows 57..70) plus everything predicted below it. Look at the deblock
78+ records for a rect intra strip on the inter path first (`decode_rect_split`'s
79+ `fill_lf_grid_rect` + the `record_inter_rect` the new call site adds), then at prediction;
80+ entropy is cleared by construction.
81+- deferred(the square intra-in-inter tx-split refusal in `read_block_tx_size`) — the split
82+ rect arm on the inter path is unproven.
83+- deferred(lane-inter4 merge) — 64x32/32x64 and the 16x8/8x16 shape need the inter-side rect
84+ work; lane-inter4's `coded_rectangular_residual` gate is NOT on this branch and was not
85+ un-ignored.
86+- accepted — 1:4 strips refuse by name on this path.