From 9fbdab4f85e57fda9942544d4b649d33349dc898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Sep 2026 10:21:20 +0300 Subject: [PATCH] fix(av1): get_tx_size_context's inter-neighbour override read a SUB-cell index into two mi-granular bands `tx_size_context_txfm`/`_rect` implement libaom `get_tx_size_context` (pred_common.h): when the above/left neighbour is an INTER block its BLOCK size, not its transform-context band, decides the `tx_depth` CDF row. Both copies indexed `above_inter`/`left_inter` with `mi_c / (SUB / MI)` / `mi_r / (SUB / MI)`, but those two bands are mi-granular everywhere else they are written (`record_inter_rect_mi`) and read (`intra_inter_ctx`) -- so the override consulted a neighbour four mi columns/rows away and, at the first intra block right of an inter one, read tx_depth off ctx 0 where libaom has ctx 1. Same value, different interval: the tile desynced from there. MEASURED on the r2 handoff's pinned stream (10-bit 192x128, md5 50ea2b42423f1c8b4eed9fa48c4775a6): the aomdec `EC_ISTEP name=tx_depth` ladder was 85 of 147 elements and first diverged at mi(24,24) ctx 0 vs 1; it is now 147/147 identical and the stream decodes pixel-exact. Consequence for the gate: with a correct decode that stream contains ZERO intra HORZ/VERT strips in an inter frame -- r1/r2's "firing" counters were read off our own desynced decode (class counter-from-refused-stream). 90 probe encodes over the old 192x128 / min=max=32 geometry produce no strip at all, so the gate moves to the merged unsplit-strip gate's geometry (96x96, min 16 / max 64, cq sweep down to 4) where aomenc does split intra strips. Both arms are now GREEN with zero named refusals: 8-bit 6 counted-exact attempts (depth1=9, depth2=1), 10-bit 2 counted-exact. `EC_SPLITSTRIP` now prints EVERY intra strip with its depth, not only the split ones -- a source that codes no strip at all and one that codes only unsplit strips were indistinguishable through it. --- crates/ec-av1/src/decode.rs | 25 ++++++++++++++++--------- crates/ec-av1/src/stream.rs | 17 +++++++++++++---- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index f5d72eea..7ddd5ecb 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -6555,11 +6555,12 @@ fn decode_intra_rect_in_inter( v[depth.min(2)] += 1; h.set(v); }); - if std::env::var_os("EC_SPLITSTRIP").is_some() { - eprintln!( - "EC_SPLITSTRIP mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} depth={depth}" - ); - } + } + // lane-intrasplit r3: print EVERY intra strip with its depth, not only the + // split ones -- a `depth=0`-only stream is a witness gap in the SOURCE, and + // the two are indistinguishable when the diagnostic fires on splits alone. + if std::env::var_os("EC_SPLITSTRIP").is_some() { + eprintln!("EC_SPLITSTRIP mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} depth={depth}"); } let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth); let modes = RectStripModes { @@ -11584,10 +11585,10 @@ fn tx_size_context_txfm_rect( let has_left = mi_c > n.tile_col0_mi; let mut above = usize::from(n.above_txfm[mi_c]) >= own_w; let mut left = usize::from(n.left_txfm[mi_r]) >= own_h; - if has_above && n.above_inter[mi_c / (SUB / MI)] { + if has_above && n.above_inter[mi_c] { above = n.above_side_mi[mi_c] >= own_w; } - if has_left && n.left_inter[mi_r / (SUB / MI)] { + if has_left && n.left_inter[mi_r] { left = n.left_side_mi[mi_r] >= own_h; } match (has_above, has_left) { @@ -11598,15 +11599,21 @@ fn tx_size_context_txfm_rect( } } +/// lane-intrasplit r3: `above_inter`/`left_inter` are mi-granular bands (they +/// are written and read everywhere else with a raw mi index); the SUB-cell +/// division this pair used read a cell four blocks away, so the inter-neighbour +/// override above fired on the wrong neighbour -- the first divergence of the +/// 10-bit gate's stream was exactly this (`tx_depth` ctx 0 where libaom has 1, +/// at the intra block right of an inter one). fn tx_size_context_txfm(n: &Neighbours, (mi_r, mi_c): (usize, usize), side: usize) -> usize { let has_above = mi_r > n.tile_row0_mi; let has_left = mi_c > n.tile_col0_mi; let mut above = usize::from(n.above_txfm[mi_c]) >= side; let mut left = usize::from(n.left_txfm[mi_r]) >= side; - if has_above && n.above_inter[mi_c / (SUB / MI)] { + if has_above && n.above_inter[mi_c] { above = n.above_side_mi[mi_c] >= side; } - if has_left && n.left_inter[mi_r / (SUB / MI)] { + if has_left && n.left_inter[mi_r] { left = n.left_side_mi[mi_r] >= side; } match (has_above, has_left) { diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index fd286162..1f8615a9 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -5533,7 +5533,16 @@ mod tests { eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); return; } - let (width, height, frame_count) = (192usize, 128usize, 8usize); + // lane-intrasplit r3, MEASURED (probe3, 20 attempts x 2 depths): at + // 192x128 with `--min/--max-partition-size=32` a correctly decoded + // stream contains ZERO intra HORZ/VERT strips in an inter frame -- the + // r1/r2 "firing" counters were read off our own desynced decode (class + // counter-from-refused-stream). The merged unsplit-strip gate's own + // geometry (96x96, min 16 / max 64) is the one that makes aomenc's RD + // pick intra strips here, and at `--enable-tx-size-search=1` it splits + // their transforms: 10-bit attempt 0 = 8 strips, 3 split; 8-bit + // attempt 0 = 5 strips, 1 split. + let (width, height, frame_count) = (96usize, 96usize, 8usize); let mut refusals = Vec::new(); let mut uncounted_exact = 0u32; let mut counted_exact = 0u32; @@ -5547,7 +5556,7 @@ mod tests { // 1..4, and the quantiser with it (a hard-cut overlay source at // cpu-used=0 stopped 38/40 attempts on other lanes' refusals). let cpu = attempt % 5; - let cq = [30u32, 20, 12, 63][((attempt / 5) % 4) as usize]; + let cq = [30u32, 20, 12, 4][((attempt / 5) % 4) as usize]; // A FAST ZOOM: consecutive frames share almost no content, so // aomenc's RD codes blocks INTRA inside INTER frames // (`--kf-min-dist` forbids a new key frame) -- the only way a @@ -5636,8 +5645,8 @@ mod tests { "--enable-intrabc=0", "--enable-cfl-intra=0", "--enable-ref-frame-mvs=0", - "--min-partition-size=32", - "--max-partition-size=32", + "--min-partition-size=16", + "--max-partition-size=64", // Per-arm overrides go LAST (aomenc keeps the last // occurrence of a repeated --enable-* flag): this gate // needs the rect partitions the strip lives in and the