forge
Explore
Log in

Don't you dare go Hollow

A partition node the true frame edge cuts on BOTH axes is a forced SPLIT with no symbol, at the 16 level too

Browse files at this commit

f3c311a95494a2f51dfa4466efd0077e2f6b280cAhmet Kaan GümüşParent: fcf808d
  • fix
    • a partition node the true frame edge cuts on BOTH axes is a forced SPLIT with no symbol, at the 16 level too
Show full message
fix(av1): a partition node the true frame edge cuts on BOTH axes is a forced SPLIT with no symbol, at the 16 level too

libaom `decode_partition` reads no partition symbol at all when
`!has_rows && !has_cols` (`else if (!has_rows && !has_cols) partition =
PARTITION_SPLIT;`) and then drops the out-of-frame children on its
`if (mi_row >= mi_rows || mi_col >= mi_cols) return;` early return, so no
neighbour or tx-grid write happens for them. The 128/64/32 levels already
inferred that split; the 16 level refused by name on both the intra and the
inter path, which made every frame whose width AND height are 8 mod 16
(200x72, 136x104, 264x136, 72x200, 104x136) undecodable -- the bottom-right
16x16 is cut on both axes there.

The existing SPLIT leaf loop at that level already filters its four 8x8
children by `mr < mi_rows && mc < mi_cols`, i.e. libaom's own early return,
so the lift is the forced value plus a per-level hit counter
(EDGE_BOTH_CUT_HITS, [16,32,64,128]) proving the case fires.

GATE a_real_aomenc_both_axes_cut_corner_block_decodes_pixel_exact: real
aomenc, 5 both-cut frame sizes x 8/10-bit x cq 32/45, every frame compared
against ffmpeg: 20/20 attempts pixel-exact, out_of_scope_mismatch=0, both-cut
hits [16,32,64,128]=[20,20,12,0], 0 refusals. The inter half of the same
sweep is a second, #[ignore]d gate: measured, its corner block decodes
exactly (200x72 luma diff bbox rows 64..=71 cols 15..=186, corner cols
192..=199 clean) but the bottom 8-row one-axis frame-edge BAND of an inter
frame is wrong, and the control 192x72 -- zero both-cut nodes, hits
[0,0,0,0] -- mismatches identically, so that band defect is lane-oddh's
inter half-strip arm, not this lift.
crates/ec-av1/src/decode.rsmodified+70 -17
@@ -1162,6 +1162,34 @@ pub(crate) fn edge_rect_strip_hits() -> usize {
11621162 EDGE_RECT_STRIP_HITS.with(|c| c.get())
11631163 }
11641164
1165+// lane-edgeboth r1: how many partition nodes were coded as the BOTH-AXES-CUT
1166+// forced split -- libaom `decode_partition` (decodeframe.c):
1167+// `else if (!has_rows && !has_cols) partition = PARTITION_SPLIT;`, the one
1168+// straddle case that reads NO symbol at all. Indexed by level:
1169+// 0 = 16x16, 1 = 32x32, 2 = 64x64, 3 = 128x128; intra and inter share it.
1170+thread_local! {
1171+ static EDGE_BOTH_CUT_HITS: std::cell::Cell<[usize; 4]> =
1172+ const { std::cell::Cell::new([0; 4]) };
1173+}
1174+
1175+fn bump_edge_both_cut(level: usize) {
1176+ EDGE_BOTH_CUT_HITS.with(|c| {
1177+ let mut v = c.get();
1178+ v[level] += 1;
1179+ c.set(v);
1180+ });
1181+}
1182+
1183+/// Current value of [`EDGE_BOTH_CUT_HITS`] (`[16, 32, 64, 128]` levels).
1184+pub(crate) fn edge_both_cut_hits() -> [usize; 4] {
1185+ EDGE_BOTH_CUT_HITS.with(|c| c.get())
1186+}
1187+
1188+/// Zeroes [`EDGE_BOTH_CUT_HITS`] so a gate can measure a per-attempt delta.
1189+pub(crate) fn reset_edge_both_cut_hits() {
1190+ EDGE_BOTH_CUT_HITS.with(|c| c.set([0; 4]));
1191+}
1192+
11651193 // How many HORZ/VERT intra strips resolved a SPLIT luma transform
11661194 // (`tx_depth != 0`) and decoded it per transform unit (lane-rectsplit r1) --
11671195 // the case every rect path here refused by name before, and the first
@@ -13095,6 +13123,7 @@ fn read_sb128_root(
1309513123 }
1309613124 _ => {
1309713125 PART128_GATHERED_SYMBOLS.with(|c| c.set(c.get() - 1));
13126+ bump_edge_both_cut(3);
1309813127 PARTITION_SPLIT
1309913128 }
1310013129 }
@@ -13431,7 +13460,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1343113460 bump_edge_part(b.min(1) as usize);
1343213461 if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT }
1343313462 }
13434- _ => PARTITION_SPLIT,
13463+ _ => {
13464+ bump_edge_both_cut(2);
13465+ PARTITION_SPLIT
13466+ }
1343513467 }
1343613468 };
1343713469 match part {
@@ -13507,7 +13539,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1350713539 bump_edge_part(2 + b.min(1) as usize);
1350813540 if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT }
1350913541 }
13510- _ => PARTITION_SPLIT,
13542+ _ => {
13543+ bump_edge_both_cut(1);
13544+ PARTITION_SPLIT
13545+ }
1351113546 }
1351213547 };
1351313548 match part32 {
@@ -13963,13 +13998,23 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1396313998 // leaf never itself straddles, so the
1396413999 // block splits cleanly along whichever
1396514000 // axis is short.
14001+ // lane-edgeboth r1: when the true frame
14002+ // edge cuts BOTH axes libaom's
14003+ // `decode_partition` takes
14004+ // `else if (!has_rows && !has_cols)
14005+ // partition = PARTITION_SPLIT;` -- no
14006+ // symbol of any kind is read, and the four
14007+ // 8x8 children are then visited by the
14008+ // same loop below, whose
14009+ // `mr < mi_rows && mc < mi_cols` filter IS
14010+ // libaom's own
14011+ // `if (mi_row >= mi_rows || mi_col >= mi_cols) return;`
14012+ // early return, so the three out-of-frame
14013+ // quadrants get no neighbour or tx-grid
14014+ // write.
1396614015 if !has_cols16 && !has_rows16 {
13967- return Err(unsupported(
13968- "a 16x16 block whose true edge cuts through both \
13969- axes needs a rectangular transform this decoder \
13970- does not code yet",
13971- ));
13972- }
14016+ bump_edge_both_cut(0);
14017+ } else {
1397314018 // lane-golomb r1 (class
1397414019 // `parsed-then-discarded`): the gathered
1397514020 // bit IS the partition -- 0 names
@@ -14032,6 +14077,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1403214077 neighbours.left_mode[sr] = mode;
1403314078 continue;
1403414079 }
14080+ }
1403514081 let (mi_row0, mi_col0) =
1403614082 (sr as u32 * SUB_MI, sc as u32 * SUB_MI);
1403714083 let leaf_positions: Vec<(u32, u32)> = (0..4)
@@ -21180,7 +21226,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2118021226 PARTITION_VERT
2118121227 }
2118221228 }
21183- (false, false) => PARTITION_SPLIT,
21229+ (false, false) => {
21230+ bump_edge_both_cut(2);
21231+ PARTITION_SPLIT
21232+ }
2118421233 };
2118521234 if part64 == PARTITION_NONE {
2118621235 // lane-inter8 r1: the whole superblock as one 64x64 inter
@@ -21365,7 +21414,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2136521414 PARTITION_VERT
2136621415 }
2136721416 }
21368- _ => PARTITION_SPLIT,
21417+ _ => {
21418+ bump_edge_both_cut(1);
21419+ PARTITION_SPLIT
21420+ }
2136921421 }
2137021422 };
2137121423 match part32 {
@@ -21430,13 +21482,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2143021482 has_half(sc as u32 * SUB_MI, SUB_MI, mi_cols),
2143121483 has_half(sr as u32 * SUB_MI, SUB_MI, mi_rows),
2143221484 );
21433- if !has_cols16 && !has_rows16 {
21434- return Err(unsupported(
21435- "a 16x16 inter block whose true edge cuts through both \
21436- axes needs a rectangular transform this decoder does \
21437- not code yet",
21438- ));
21439- }
2144021485 let at16 = (sr, sc);
2144121486 let ctx16 = neighbours.partition_ctx(at16, SUB);
2144221487 // lane-inter8 r1: a straddling 16x16 cannot name a
@@ -21456,6 +21501,14 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2145621501 );
2145721502 }
2145821503 p
21504+ } else if !has_cols16 && !has_rows16 {
21505+ // lane-edgeboth r1: both axes cut by the true
21506+ // frame edge -- libaom `decode_partition`
21507+ // forces PARTITION_SPLIT and reads NO symbol;
21508+ // the leaf loop below already drops the
21509+ // out-of-frame quadrants.
21510+ bump_edge_both_cut(0);
21511+ PARTITION_SPLIT
2145921512 } else {
2146021513 if has_cols16 {
2146121514 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
crates/ec-av1/src/refusal_inventory.rsmodified+0 -2
@@ -35,8 +35,6 @@ const REFUSALS: &[&str] = &[
3535 "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)",
3636 "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)",
3737 "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)",
38- "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
39- "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
4038 "a 32x32 partition type this decoder does not code (value={part32})",
4139 "a Golomb tail longer than this decoder reads",
4240 "a tx_type symbol outside its CDF's own set: {t}",
crates/ec-av1/src/stream.rsmodified+262 -0
@@ -14274,6 +14274,268 @@ mod tests {
1427414274 crate::decode::cdef_idx_hits()
1427514275 );
1427614276 }
14277+ /// lane-edgeboth r1 GATE: frame sizes whose width AND height are both
14278+ /// 8 mod 16, so the bottom-right corner of the frame is a partition node
14279+ /// with `has_rows == false && has_cols == false` at every level it
14280+ /// reaches -- libaom `decode_partition` forces PARTITION_SPLIT there and
14281+ /// reads NO symbol (`else if (!has_rows && !has_cols) partition =
14282+ /// PARTITION_SPLIT;`), then drops the out-of-frame children on its
14283+ /// `if (mi_row >= mi_rows || mi_col >= mi_cols) return;` early return.
14284+ /// The 64 and 32 levels already inferred that split; the 16 level refused
14285+ /// by name until r1, on both the intra (key) and the inter path -- so both
14286+ /// arms are swept here. Every compared attempt must show a 16-level
14287+ /// both-cut hit, and the sweep must show 32- and 64-level hits too (200x72
14288+ /// puts all three levels in that state: mi_cols 50, mi_rows 18, so the
14289+ /// nodes at mi (16,48) of size 64, 32 and 16 are all cut on both axes).
14290+ #[test]
14291+ fn a_real_aomenc_both_axes_cut_corner_block_decodes_pixel_exact() {
14292+ both_axes_cut_sweep(
14293+ "a_real_aomenc_both_axes_cut_corner_block_decodes_pixel_exact",
14294+ ("key", 1, "--kf-max-dist=0", "--limit=1"),
14295+ );
14296+ }
14297+
14298+ /// lane-edgeboth r1, INTER half of the same lift. `#[ignore]`d, and the
14299+ /// reason is MEASURED, not assumed: the inter path's both-cut corner block
14300+ /// itself decodes exactly (200x72 inter cq 32, luma diff bounding box rows
14301+ /// 64..=71 cols 15..=186 -- the corner at cols 192..=199 is clean), but the
14302+ /// bottom 8-row frame-edge BAND of an inter frame is wrong, and the
14303+ /// control 192x72 (width a multiple of 16, so zero both-cut nodes: hits
14304+ /// [0,0,0,0]) fails identically at rows 64..=71 cols 8..=188. That band is
14305+ /// the forced one-axis HORZ half strip on the inter path -- lane-oddh's
14306+ /// own inter gate is `#[ignore]`d for the same arm -- so this gate turns
14307+ /// green with that defect, not with anything this lane changed.
14308+ #[test]
14309+ #[ignore = "2026-09-02 lane-edgeboth r1: blocked by the pre-existing inter frame-edge half-strip band defect, not by the both-cut corner -- control 192x72 (zero both-cut hits) mismatches identically at rows 64..=71"]
14310+ fn a_real_aomenc_both_axes_cut_corner_inter_frames_decode_pixel_exact() {
14311+ both_axes_cut_sweep(
14312+ "a_real_aomenc_both_axes_cut_corner_inter_frames_decode_pixel_exact",
14313+ ("inter", 6, "--kf-max-dist=9999", "--limit=6"),
14314+ );
14315+ }
14316+
14317+ fn both_axes_cut_sweep(
14318+ name: &'static str,
14319+ (arm, frames, kf_arg, limit_arg): (&str, usize, &str, &str),
14320+ ) {
14321+ // Kept upper-case so every message string below reads the same as in
14322+ // the sibling gates.
14323+ #[allow(non_snake_case)]
14324+ let NAME = name;
14325+ let _gate_lock = lock_gate_counters();
14326+ if !have_ffmpeg() || !have_aomenc() {
14327+ eprintln!("SKIP {NAME}: no ffmpeg/aomenc");
14328+ return;
14329+ }
14330+ let sizes: &[(usize, usize)] = &[(200, 72), (136, 104), (264, 136), (72, 200), (104, 136)];
14331+ let mut compared = 0u32;
14332+ let mut refusals: Vec<String> = Vec::new();
14333+ let mut totals = [0usize; 4];
14334+ for &(width, height) in sizes {
14335+ let mut size_compared = 0u32;
14336+ {
14337+ for bit_depth in [8u32, 10u32] {
14338+ // cq 58 is left out on purpose: measured r1, it is where
14339+ // libaom starts answering the frame-edge gathered symbol
14340+ // with a rect strip and other lanes' refusals fire first
14341+ // ("a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs
14342+ // rectangular residual coding").
14343+ for cq in [32u32, 45] {
14344+ let source = format!("mandelbrot=size={width}x{height}:rate=25");
14345+ // Feed exactly `frames` frames: --limit=1 makes
14346+ // aomenc stop reading after the first one and the
14347+ // y4m write then dies on a broken pipe.
14348+ let dur = format!("{}", frames as f64 / 25.0);
14349+ let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" };
14350+ let y4m = Command::new("ffmpeg")
14351+ .args([
14352+ "-v", "error", "-f", "lavfi", "-i", &source, "-t", &dur,
14353+ "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-",
14354+ ])
14355+ .stdin(Stdio::null())
14356+ .stdout(Stdio::piped())
14357+ .stderr(Stdio::piped())
14358+ .output()
14359+ .expect("ffmpeg failed to run");
14360+ assert!(
14361+ y4m.status.success(),
14362+ "{NAME}: ffmpeg refused the {width}x{height} {bit_depth}-bit \
14363+ fixture: {}",
14364+ String::from_utf8_lossy(&y4m.stderr)
14365+ );
14366+ let depth_arg = format!("--bit-depth={bit_depth}");
14367+ let input_depth_arg = format!("--input-bit-depth={bit_depth}");
14368+ let cq_arg = format!("--cq-level={cq}");
14369+ let mut child = Command::new(aomenc_path())
14370+ .args([
14371+ "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg,
14372+ // cpu-used >= 1 keeps libaom on 64x64
14373+ // superblocks at these sizes
14374+ // (`av1_select_sb_size`).
14375+ "--cpu-used=4", "--threads=1", "--row-mt=0",
14376+ // --lag-in-frames=0: no hidden alt-ref, so
14377+ // decode order == display order and the
14378+ // compare below covers every frame the stream
14379+ // carries (class gate-blind-to-hidden-frames).
14380+ kf_arg, limit_arg, "--lag-in-frames=0",
14381+ &depth_arg, &input_depth_arg,
14382+ // Other lanes' named refusals this recipe must
14383+ // not trip. The both-cut corner is FORCED down
14384+ // to 8x8 leaves, which is exactly where the
14385+ // 8x8-intra-leaf-in-an-inter-frame gaps live,
14386+ // so the intra tool set and tx-size search are
14387+ // pinned off: without them 30/30 inter
14388+ // attempts refused (measured r1) on "a nonzero
14389+ // angle delta on an 8x8 intra leaf in an inter
14390+ // frame", "a non-DC chroma mode on an 8x8
14391+ // inter-frame leaf" and "an 8x8 intra leaf in
14392+ // an inter frame whose tx_depth splits it into
14393+ // 4x4 transform units".
14394+ "--enable-rect-partitions=0", "--enable-ab-partitions=0",
14395+ "--enable-1to4-partitions=0",
14396+ "--min-partition-size=8", "--max-partition-size=64",
14397+ "--enable-palette=0", "--enable-intrabc=0",
14398+ "--enable-warped-motion=0", "--enable-obmc=0",
14399+ "--enable-masked-comp=0", "--enable-interintra-comp=0",
14400+ "--enable-onesided-comp=0", "--enable-interintra-wedge=0",
14401+ "--enable-smooth-interintra=0", "--enable-ref-frame-mvs=0",
14402+ "--enable-angle-delta=0", "--enable-cfl-intra=0",
14403+ "--enable-directional-intra=0", "--enable-smooth-intra=0",
14404+ "--enable-paeth-intra=0", "--enable-filter-intra=0",
14405+ "--enable-tx-size-search=0",
14406+ "--obu", "-o", "-", "-",
14407+ ])
14408+ .stdin(Stdio::piped())
14409+ .stdout(Stdio::piped())
14410+ .stderr(Stdio::piped())
14411+ .spawn()
14412+ .expect("aomenc failed to start");
14413+ child
14414+ .stdin
14415+ .take()
14416+ .expect("aomenc stdin")
14417+ .write_all(&y4m.stdout)
14418+ .expect("write y4m");
14419+ let out = child.wait_with_output().expect("aomenc failed to run");
14420+ assert!(
14421+ out.status.success(),
14422+ "aomenc refused: {}",
14423+ String::from_utf8_lossy(&out.stderr)
14424+ );
14425+ let stream = out.stdout;
14426+
14427+ // Reset, never a delta across attempts: a refused
14428+ // attempt's hits must not count (class
14429+ // counter-from-refused-stream).
14430+ crate::decode::reset_edge_both_cut_hits();
14431+ let decoded = match decode_stream(&stream) {
14432+ Ok(f) => f,
14433+ Err(e) => {
14434+ let msg = e.to_string();
14435+ assert!(
14436+ msg.contains("unsupported"),
14437+ "{NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} \
14438+ failed outright, not a named refusal: {msg}"
14439+ );
14440+ eprintln!(
14441+ " {NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} \
14442+ REFUSED {msg}"
14443+ );
14444+ refusals.push(msg);
14445+ continue;
14446+ }
14447+ };
14448+ let hits = crate::decode::edge_both_cut_hits();
14449+ let reference = if bit_depth == 10 {
14450+ ffmpeg_decode_sequence_10bit(&stream, width, height, frames)
14451+ } else {
14452+ ffmpeg_decode_sequence(&stream, width, height, frames)
14453+ };
14454+ assert_eq!(
14455+ decoded.len(),
14456+ frames,
14457+ "{NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} decoded {} \
14458+ frames, expected {frames}",
14459+ decoded.len()
14460+ );
14461+ assert_eq!(
14462+ reference.len(),
14463+ frames,
14464+ "{NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} reference \
14465+ frame count"
14466+ );
14467+ for (i, (ours, theirs)) in decoded.iter().zip(&reference).enumerate() {
14468+ let nd =
14469+ |a: &[u16], b: &[u16]| a.iter().zip(b).filter(|(x, y)| x != y).count();
14470+ // Where a mismatch lands is the whole diagnosis
14471+ // here (corner block vs elsewhere), so print the
14472+ // luma bounding box before the assert kills the run.
14473+ if nd(&ours.y, &theirs.y) > 0 {
14474+ let (mut r0, mut c0, mut r1, mut c1) =
14475+ (usize::MAX, usize::MAX, 0usize, 0usize);
14476+ for row in 0..height {
14477+ for col in 0..width {
14478+ if ours.y[row * width + col] != theirs.y[row * width + col] {
14479+ r0 = r0.min(row);
14480+ c0 = c0.min(col);
14481+ r1 = r1.max(row);
14482+ c1 = c1.max(col);
14483+ }
14484+ }
14485+ }
14486+ eprintln!(
14487+ " {NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} \
14488+ frame {i} luma diff bbox rows {r0}..={r1} cols {c0}..={c1}"
14489+ );
14490+ }
14491+ assert_eq!(
14492+ (
14493+ nd(&ours.y, &theirs.y),
14494+ nd(&ours.u, &theirs.u),
14495+ nd(&ours.v, &theirs.v)
14496+ ),
14497+ (0, 0, 0),
14498+ "{NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} frame \
14499+ {i} differs from ffmpeg"
14500+ );
14501+ }
14502+ // Every compared attempt must carry the case, so no
14503+ // compared attempt is out of scope and
14504+ // out_of_scope_mismatch is 0 by construction.
14505+ assert!(
14506+ hits[0] > 0,
14507+ "{NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} decoded \
14508+ pixel-exact but no 16-level both-axes-cut block fired \
14509+ (hits={hits:?}) -- the recipe no longer reaches the lifted arm"
14510+ );
14511+ for l in 0..4 {
14512+ totals[l] += hits[l];
14513+ }
14514+ compared += 1;
14515+ size_compared += 1;
14516+ }
14517+ }
14518+ }
14519+ assert!(
14520+ size_compared > 0,
14521+ "{NAME}: every {width}x{height} attempt refused -- that size proved nothing"
14522+ );
14523+ }
14524+ assert!(
14525+ totals[1] > 0 && totals[2] > 0,
14526+ "{NAME}: no 32-level ({}) or 64-level ({}) both-axes-cut node fired -- 200x72 puts \
14527+ both in that state, so the sweep stopped reaching them",
14528+ totals[1],
14529+ totals[2]
14530+ );
14531+ eprintln!(
14532+ "{NAME}: {compared} attempts pixel-exact over {} sizes ({arm} arm), \
14533+ out_of_scope_mismatch=0, both_cut hits [16,32,64,128]={totals:?}, {} named refusals",
14534+ sizes.len(),
14535+ refusals.len()
14536+ );
14537+ }
14538+
1427714539 /// lane-tiny r4 GATE (was r1's `#[ignore]`d probe): every tiny key-frame
1427814540 /// size real aomenc will encode, decoded pixel-exact against ffmpeg.
1427914541 /// Tiny frames are where every edge/partial-superblock corner case is