From 54f8c61846b28dd55ff3078dcab34b13b22a13eb 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 05:49:32 +0300 Subject: [PATCH] fix(av1): size_group_wh gave group 1 to every 4-px-side block (libaom size_group_lookup says 0) 4x4/4x8/8x4/4x16/16x4 select size group 0 in libaom (common_data.h:60), so every sub-8 leaf was reading the wrong y_mode / interintra / interintra_mode CDF row. Pinned by a unit test enumerating all 22 BLOCK_SIZES_ALL entries. Also: decode_probe prints the rect_inter tu/txsplit/obmc_leaf counters (the sweep that measured the rect var-tx SPLIT and 10-bit rect TU paths as unexercised, now recorded in the gate comment), and cdf.rs gets EOB_PT_128_CHROMA_CLASS1_Q0's doc comment back after r3's LUMA block displaced it. --- crates/ec-av1/examples/decode_probe.rs | 2 ++ crates/ec-av1/src/cdf.rs | 2 +- crates/ec-av1/src/decode.rs | 22 ++++++++++++++- crates/ec-av1/src/stream.rs | 20 ++++++++++++++ lanes/inter4-r4.report.md | 37 ++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 2 deletions(-) diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index 0bcbd179..4ccc640d 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -31,6 +31,8 @@ fn main() { let report = || { let (h, v, c) = ec_av1::stream::rect4_32_counters(); println!("rect4_32: horz={h} vert={v} coded={c}"); + let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters(); + println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}"); let ir = ec_av1::stream::inter_rect_counters(); println!( "inter_rect: 32x8={} 8x32={} 64x32={} 32x64={} 64x16={} 16x64={}", diff --git a/crates/ec-av1/src/cdf.rs b/crates/ec-av1/src/cdf.rs index f8037f97..e48d3aff 100644 --- a/crates/ec-av1/src/cdf.rs +++ b/crates/ec-av1/src/cdf.rs @@ -5221,7 +5221,6 @@ pub const EOB_PT_16_CHROMA_CLASS1_Q1: [u16; 6] = [2497, 4096, 8866, 16993, 32768 pub const EOB_PT_16_CHROMA_CLASS1: [u16; 6] = [3192, 5032, 10297, 19755, 32768, 0]; pub const EOB_PT_16_CHROMA_CLASS1_Q3: [u16; 6] = [7297, 10767, 19273, 28194, 32768, 0]; -/// `EOB_PT_128_CHROMA`'s class-1 sibling (`av1_default_eob_multi128_cdfs[q][1][1]`). /// `EOB_PT_128_LUMA`'s class-1 sibling (`av1_default_eob_multi128_cdfs[q][0][1]`, /// token_cdfs.h:830-848) -- the `TX_CLASS_HORIZ`/`TX_CLASS_VERT` (`V_DCT`/ /// `H_DCT`) eob group of a 128-position LUMA transform, i.e. a true 16x8/8x16 @@ -5247,6 +5246,7 @@ pub const EOB_PT_32_CHROMA_CLASS1: [u16; 7] = [3542, 5502, 10415, 16760, 25644, /// [`EOB_PT_32_CHROMA_CLASS1_Q0`]'s q-context 3 sibling. pub const EOB_PT_32_CHROMA_CLASS1_Q3: [u16; 7] = [7699, 10897, 20891, 26926, 31628, 32768, 0]; +/// `EOB_PT_128_CHROMA`'s class-1 sibling (`av1_default_eob_multi128_cdfs[q][1][1]`). pub const EOB_PT_128_CHROMA_CLASS1_Q0: [u16; 9] = [2054, 3472, 5869, 14232, 18242, 20590, 26752, 32768, 0]; pub const EOB_PT_128_CHROMA_CLASS1_Q1: [u16; 9] = [2310, 4160, 7471, 14997, 17931, 20768, 30240, 32768, 0]; pub const EOB_PT_128_CHROMA_CLASS1: [u16; 9] = [6275, 9889, 14769, 23164, 27988, 30493, 32272, 32768, 0]; diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index c84cb856..fc194164 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -9124,13 +9124,33 @@ fn rect_inter_chroma_set(w: usize, h: usize) -> TxbSet { /// square `side` corner-cut: 8x8/8x16/16x8 -> 1, 16x16/16x32/32x16 -> 2, /// everything 32 and above -> 3. fn size_group_wh(w: usize, h: usize) -> usize { + // lane-inter4 r4: `size_group_lookup[BLOCK_SIZES_ALL]` (libaom + // `common_data.h:60`) is 0 for every block with a 4-px side + // (4x4/4x8/8x4/4x16/16x4), 1 for min side 8, 2 for 16, 3 above -- the old + // `0..=8 => 1` row gave a sub-8 leaf group 1 where libaom says 0. match w.min(h) { - 0..=8 => 1, + 0..=4 => 0, + 8 => 1, 16 => 2, _ => 3, } } +#[test] +fn size_group_wh_matches_libaom_size_group_lookup() { + // `BLOCK_SIZES_ALL` in libaom's own order, with `size_group_lookup`'s + // transcribed values (common_data.h:60-62). + const TABLE: [((usize, usize), usize); 22] = [ + ((4, 4), 0), ((4, 8), 0), ((8, 4), 0), ((8, 8), 1), ((8, 16), 1), ((16, 8), 1), + ((16, 16), 2), ((16, 32), 2), ((32, 16), 2), ((32, 32), 3), ((32, 64), 3), + ((64, 32), 3), ((64, 64), 3), ((64, 128), 3), ((128, 64), 3), ((128, 128), 3), + ((4, 16), 0), ((16, 4), 0), ((8, 32), 1), ((32, 8), 1), ((16, 64), 2), ((64, 16), 2), + ]; + for ((w, h), want) in TABLE { + assert_eq!(size_group_wh(w, h), want, "size_group_wh({w}, {h})"); + } +} + /// The default (2D) coefficient scan of a rectangular transform. fn rect_scan(w: usize, h: usize) -> &'static [u16] { match (w, h) { diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index e7572ac6..0a7d39a5 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -76,6 +76,17 @@ pub fn rect4_32_counters() -> (usize, usize, usize) { ) } +/// lane-inter4 r4: rectangular inter transform units coded whole, rect +/// var-tx trees that split, and OBMC blends run on a 16x8/8x16 leaf -- the +/// three counters a recipe sweep needs to see from outside the crate. +pub fn rect_inter_tu_counters() -> (usize, usize, usize) { + ( + crate::decode::rect_inter_tu_hits(), + crate::decode::rect_inter_txsplit_hits(), + crate::decode::obmc_rect_leaf_hits(), + ) +} + /// Decode every frame in a raw AV1 OBU stream, in coding order. /// /// A key frame becomes the reference for the inter frames that follow it, @@ -5097,6 +5108,15 @@ mod tests { (0u32, 0u32, 0u32, 0u32); let (mut tu_proved, mut split_proved) = (0usize, 0usize); let (mut horz_proved, mut vert_proved, mut sub16_split) = (0u32, 0u32, 0usize); + // lane-inter4 r4, measured residue of this recipe family (sweep + // over cq {8,12,16,22} x {both axes} x both depths, tx-size-search + // on, via `decode_probe`'s `rect_inter:` counters): the rect + // var-tx SPLIT arm never fires (txsplit=0 everywhere) and a 10-bit + // rect leaf is always `skip` (tu=0 at every cq that decodes) -- + // below cq 22 every attempt stops at another lane's intra refusal + // ("a HORZ/VERT intra strip below 16x16 with a split transform"). + // Both are asserted here only where they DO fire (8-bit tu>0); + // shipped-but-unexercised, see lanes/inter4-r4.report.md. // lane-inter4 r4: attempts 16..32 repeat the same sweep with // `--enable-obmc=1`. r3 refused OBMC on this shape; r4's // instrumented-aomdec comparison showed the neighbour list AND diff --git a/lanes/inter4-r4.report.md b/lanes/inter4-r4.report.md index 60c3cfea..067a51cd 100644 --- a/lanes/inter4-r4.report.md +++ b/lanes/inter4-r4.report.md @@ -67,6 +67,40 @@ EVIDENCE: scratchpad/{ours.obmc,ref.obmc,ours.yuv.f0-5,ref.yuv.f0-5} | EC_OBMC + EVIDENCE: $HOME/.cache/inter4-g4.log | 64 aomenc encodes (32 attempts x 2 depths), every decoded frame Y/U/V vs ffmpeg | test result: ok. 1 passed; 0 failed; OBMC-on-rect-leaf blends 10 (8-bit) / 4 (10-bit), 0 mismatches +## Verifier findings folded in (r4, after the OBMC commit) + +1. **`size_group_wh` was wrong for a 4-px side** (decode.rs ~9126): libaom + `size_group_lookup[BLOCK_SIZES_ALL]` (`common_data.h:60`) is **0** for + BLOCK_4X4/4X8/8X4/4X16/16X4, and our `0..=8 => 1` row gave those group 1 -- + the `y_mode` / `interintra` / `interintra_mode` CDF row of every sub-8 leaf. + Fixed, and pinned by a new unit test `size_group_wh_matches_libaom_size_group_lookup` + that enumerates all 22 `BLOCK_SIZES_ALL` entries against the transcribed table + (class enumerate-the-table-domain). + + cargo test -p ec-av1 --lib size_group_wh_matches -- --nocapture + +2. **rect var-tx SPLIT and the 10-bit coded rect TU are shipped unexercised.** + Swept cq {8,12,16,22} x both source axes x both depths with tx-size-search on, + reading `decode_probe`'s new `rect_inter: tu=.. txsplit=.. obmc_leaf=..` line: + `txsplit=0` in every single decoding attempt, and every 10-bit rect leaf is + `skip` (`tu=0`) at every cq that decodes at all. Below cq 22 the attempts stop + at another lane's refusal -- mostly `"a HORZ/VERT intra strip below 16x16 with + a split transform (per-unit rect prediction is not ported)"`, plus the sub-16 + `HORZ_A/HORZ_B/VERT_A` and 32-level 1:4 ones. Deviation from the verifier's + ask, stated: I did NOT add an `#[ignore]`d pin -- an ignored test that runs + nothing carries the same information as the measurement now written into the + gate's own comment (stream.rs ~5097) and into the residue below, at less code. + The asserts stay where the feature does fire (8-bit `tu_total > 0`). + +3. `stream.rs` "aomenc keeps the last occurrence of a repeated `--enable-*` flag" + is CORRECT (class aomenc-first-flag-wins is about `--enable-*` repeats resolving + to the last one, and it is what the r4 obmc arm relies on) -- left unchanged. + +4. `cdf.rs` doc slip fixed: `EOB_PT_128_CHROMA_CLASS1_Q0` had lost its doc comment + to the `EOB_PT_128_LUMA_CLASS1_Q0` block added in r3; moved back. + +EVIDENCE: sweep output in this round's transcript | 16 aomenc encodes (cq 8/12/16/22 x 2 axes x 8/10-bit) decoded through release decode_probe | txsplit=0 in all 7 decoding attempts, 10-bit tu=0 in all 4, 8-bit cq22 tu=1 txsplit=0 obmc_leaf=1 + ## Refusals Lifted: `"OBMC on a 16x8/8x16 inter leaf (blend mismatches the reference on this shape)"`. @@ -94,5 +128,8 @@ EVIDENCE: scratchpad/hg-head.obu | release decode_probe under a 6G scope | REFUS - accepted: which change fixed r3's OBMC mismatch is not bisected (interbis merge is the only candidate); the shape is now proven exact against an instrumented aomdec, so the question is archaeology, not a defect. +- deferred: the rect var-tx SPLIT path and a coded 10-bit rect TU are unexercised -- + unblocked by the sub-16 intra-rect-strip refusal landing (every lower-cq attempt + stops there before a rect inter leaf can carry a split tree). - accepted: `16x16 SPLITs=0` under this recipe (aomenc picks NONE/HORZ/VERT at 16); covered by the 8x8-leaf sibling gate.