Merge branch 'lane-inter16ab' (af7de9f): 16x16-level inter AB partitions
Browse files at this commit5 changed files +512 -2
- crates/ec-av1/examples/decode_probe.rs +7 -0
- crates/ec-av1/src/decode.rs +198 -1
- crates/ec-av1/src/refusal_inventory.rs +8 -1
- crates/ec-av1/src/stream.rs +225 -0
- lanes/inter16ab-r1.report.md +74 -0
crates/ec-av1/examples/decode_probe.rsmodified+7 -0
| @@ -37,6 +37,13 @@ fn main() { | |||
| 37 | println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}"); | 37 | println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}"); |
| 38 | let leaf = ec_av1::stream::vartx_rect_leaf_hits(); | 38 | let leaf = ec_av1::stream::vartx_rect_leaf_hits(); |
| 39 | println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]); | 39 | println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]); |
| 40 | + // lane-inter16ab r1: the 16x16-level inter AB arms, so a recipe sweep | ||
| 41 | + // can tell "aomenc never picked one" from "it did and we decoded it". | ||
| 42 | + let ab = ec_av1::decode::ab16_inter_hits_by_arm(); | ||
| 43 | + println!( | ||
| 44 | + "inter_ab16: horz_a={} horz_b={} vert_a={} vert_b={}", | ||
| 45 | + ab[0], ab[1], ab[2], ab[3] | ||
| 46 | + ); | ||
| 40 | let ir = ec_av1::stream::inter_rect_counters(); | 47 | let ir = ec_av1::stream::inter_rect_counters(); |
| 41 | println!( | 48 | println!( |
| 42 | "inter_rect: 32x8={} 8x32={} 64x32={} 32x64={} 64x16={} 16x64={}", | 49 | "inter_rect: 32x8={} 8x32={} 64x32={} 32x64={} 64x16={} 16x64={}", |
crates/ec-av1/src/decode.rsmodified+198 -1
| @@ -2205,6 +2205,31 @@ pub(crate) fn rect4_coeff_hits() -> usize { | |||
| 2205 | RECT4_COEFF_HITS.with(|c| c.get()) | 2205 | RECT4_COEFF_HITS.with(|c| c.get()) |
| 2206 | } | 2206 | } |
| 2207 | 2207 | ||
| 2208 | +// lane-inter16ab r1: how many 16x16-level AB partitions fired IN AN INTER | ||
| 2209 | +// frame, per arm, in `PARTITION_HORZ_A`, `_HORZ_B`, `_VERT_A`, `_VERT_B` | ||
| 2210 | +// order (the intra-frame counterpart is `AB16_HITS`). Each arm is two 8x8 | ||
| 2211 | +// inter leaves (`decode_inter_block8`) plus one true 16x8/8x16 inter strip | ||
| 2212 | +// (`decode_inter_block` with `write_w`/`write_h`); the gate asserts every | ||
| 2213 | +// arm separately so a run whose RD only picked one cannot pass as proof of | ||
| 2214 | +// four. | ||
| 2215 | +thread_local! { | ||
| 2216 | + static AB16_INTER_HITS: std::cell::Cell<[usize; 4]> = const { std::cell::Cell::new([0; 4]) }; | ||
| 2217 | +} | ||
| 2218 | + | ||
| 2219 | +/// [`AB16_INTER_HITS`] per arm (HORZ_A, HORZ_B, VERT_A, VERT_B at 16x16 in an | ||
| 2220 | +/// inter frame). | ||
| 2221 | +pub fn ab16_inter_hits_by_arm() -> [usize; 4] { | ||
| 2222 | + AB16_INTER_HITS.with(std::cell::Cell::get) | ||
| 2223 | +} | ||
| 2224 | + | ||
| 2225 | +fn bump_ab16_inter(arm: usize) { | ||
| 2226 | + AB16_INTER_HITS.with(|c| { | ||
| 2227 | + let mut v = c.get(); | ||
| 2228 | + v[arm] += 1; | ||
| 2229 | + c.set(v); | ||
| 2230 | + }); | ||
| 2231 | +} | ||
| 2232 | + | ||
| 2208 | // lane-r14: the 16x16-level 1:4 pair -- four 16x4 (`PARTITION_HORZ_4`) or | 2233 | // lane-r14: the 16x16-level 1:4 pair -- four 16x4 (`PARTITION_HORZ_4`) or |
| 2209 | // 4x16 (`PARTITION_VERT_4`) strips, `CHROMA` counting the odd strips that | 2234 | // 4x16 (`PARTITION_VERT_4`) strips, `CHROMA` counting the odd strips that |
| 2210 | // close a 4:2:0 chroma pair and `COEFF` the strips with a coded residual. | 2235 | // close a 4:2:0 chroma pair and `COEFF` the strips with a coded residual. |
| @@ -21136,6 +21161,83 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 21136 | )? | 21161 | )? |
| 21137 | }; | 21162 | }; |
| 21138 | } | 21163 | } |
| 21164 | + // lane-inter16ab r1: one 8x8 inter leaf of a 16x16-level AB | ||
| 21165 | + // partition (libaom `decode_partition` PARTITION_HORZ_A/_B/ | ||
| 21166 | + // VERT_A/_B at BLOCK_16X16 code `bsize2` = BLOCK_8X8 for two of | ||
| 21167 | + // their three pieces, decodeframe.c ~1900). Same body the | ||
| 21168 | + // PARTITION_SPLIT arm runs per leaf, minus its own partition | ||
| 21169 | + // symbol (an AB piece carries none) and its `prev_leaves` | ||
| 21170 | + // bookkeeping. | ||
| 21171 | + macro_rules! inter_leaf8 { | ||
| 21172 | + ($outer:expr, $leaf:expr) => {{ | ||
| 21173 | + let leaf_mi = $leaf; | ||
| 21174 | + let ( | ||
| 21175 | + skip, | ||
| 21176 | + is_inter, | ||
| 21177 | + skip_mode_leaf, | ||
| 21178 | + compound_ctx8, | ||
| 21179 | + leaf_filter, | ||
| 21180 | + leaf_refs, | ||
| 21181 | + ) = decode_inter_block8( | ||
| 21182 | + &mut dec, | ||
| 21183 | + &mut cdfs, | ||
| 21184 | + &mut neighbours, | ||
| 21185 | + &mut grid, | ||
| 21186 | + mi_cols, | ||
| 21187 | + mi_rows, | ||
| 21188 | + $outer, | ||
| 21189 | + leaf_mi, | ||
| 21190 | + &mut y, | ||
| 21191 | + &mut u, | ||
| 21192 | + &mut v, | ||
| 21193 | + &ref_y, | ||
| 21194 | + &ref_u, | ||
| 21195 | + &ref_v, | ||
| 21196 | + &ref_slots, | ||
| 21197 | + base_q_idx, | ||
| 21198 | + &scan8, | ||
| 21199 | + &scan4, | ||
| 21200 | + allow_high_precision_mv, | ||
| 21201 | + force_integer_mv, | ||
| 21202 | + &global_motion, | ||
| 21203 | + enable_dual_filter, | ||
| 21204 | + reference_select, | ||
| 21205 | + enable_masked_compound, | ||
| 21206 | + enable_interintra_compound, | ||
| 21207 | + enable_jnt_comp, | ||
| 21208 | + order_hint_bits, | ||
| 21209 | + order_hint, | ||
| 21210 | + ref_order_hints, | ||
| 21211 | + skip_mode_present, | ||
| 21212 | + skip_mode_frame, | ||
| 21213 | + reduced_tx_set, | ||
| 21214 | + interp_fixed, | ||
| 21215 | + switchable_motion_mode, | ||
| 21216 | + allow_warped_motion, | ||
| 21217 | + allow_screen_content_tools, | ||
| 21218 | + &sign_bias_table, | ||
| 21219 | + tpl_frame.as_ref(), | ||
| 21220 | + frame_width as usize, | ||
| 21221 | + )?; | ||
| 21222 | + neighbours.record_inter_rect_mi( | ||
| 21223 | + leaf_mi, | ||
| 21224 | + 2, | ||
| 21225 | + 2, | ||
| 21226 | + skip, | ||
| 21227 | + is_inter, | ||
| 21228 | + leaf_refs.0, | ||
| 21229 | + leaf_filter, | ||
| 21230 | + skip_mode_leaf, | ||
| 21231 | + ); | ||
| 21232 | + if let Some(ref1) = leaf_refs.1 | ||
| 21233 | + && let Some((_, _, group_idx, idx)) = compound_ctx8 | ||
| 21234 | + { | ||
| 21235 | + neighbours.record_compound_ctx_rect_mi( | ||
| 21236 | + leaf_mi, 2, 2, ref1, group_idx, idx, | ||
| 21237 | + ); | ||
| 21238 | + } | ||
| 21239 | + }}; | ||
| 21240 | + } | ||
| 21139 | let sb_ctx = neighbours.partition_ctx(sb_at, SB); | 21241 | let sb_ctx = neighbours.partition_ctx(sb_at, SB); |
| 21140 | let (has_cols, has_rows) = ( | 21242 | let (has_cols, has_rows) = ( |
| 21141 | sb_c * SB_MI + SB_MI / 2 < mi_cols, | 21243 | sb_c * SB_MI + SB_MI / 2 < mi_cols, |
| @@ -21618,9 +21720,104 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 21618 | frame_width as usize, | 21720 | frame_width as usize, |
| 21619 | )?; | 21721 | )?; |
| 21620 | } | 21722 | } |
| 21723 | + } else if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part16) { | ||
| 21724 | + // lane-inter16ab r1: the four AB (T-shaped) | ||
| 21725 | + // partitions at the 16x16 level of an INTER | ||
| 21726 | + // frame -- two 8x8 inter leaves plus one true | ||
| 21727 | + // 16x8/8x16 inter strip. libaom | ||
| 21728 | + // `decode_partition` (decodeframe.c ~5040, | ||
| 21729 | + // `bsize2 = get_partition_subsize(bsize, | ||
| 21730 | + // PARTITION_SPLIT)` = BLOCK_8X8 here) visits: | ||
| 21731 | + // HORZ_A: TL 8x8, TR 8x8, bottom 16x8 | ||
| 21732 | + // HORZ_B: top 16x8, BL 8x8, BR 8x8 | ||
| 21733 | + // VERT_A: TL 8x8, BL 8x8, right 8x16 | ||
| 21734 | + // VERT_B: left 8x16, TR 8x8, BR 8x8 | ||
| 21735 | + // Every piece is inside the frame by | ||
| 21736 | + // construction: an AB value can only be read | ||
| 21737 | + // from the (has_cols16 && has_rows16) branch | ||
| 21738 | + // above, i.e. mi_row+2 < mi_rows and | ||
| 21739 | + // mi_col+2 < mi_cols, which is exactly | ||
| 21740 | + // libaom's own `has_rows`/`has_cols`. | ||
| 21741 | + // | ||
| 21742 | + // VERT_A/VERT_B visit TL,BL,TR,BR, so a | ||
| 21743 | + // bottom-left square's top-right neighbour is | ||
| 21744 | + // the partition's own not-yet-decoded | ||
| 21745 | + // rectangle: libaom switches those squares | ||
| 21746 | + // onto `has_tr_vert_*`/`has_bl_vert_*` | ||
| 21747 | + // (`reconintra.c get_has_tr_table`) -- | ||
| 21748 | + // `Reach::vert_ab_partition()`, the same | ||
| 21749 | + // guard the intra 16-level arm and the | ||
| 21750 | + // 32-level inter AB arms take (class | ||
| 21751 | + // `visit-order-changes-availability`). | ||
| 21752 | + // | ||
| 21753 | + // OBMC/warp and compound stay legal here: | ||
| 21754 | + // every piece is >= 8x8, so libaom's | ||
| 21755 | + // `is_motion_variation_allowed_bsize` | ||
| 21756 | + // (min(bw,bh) >= 8, blockd.h) and | ||
| 21757 | + // `is_comp_ref_allowed` (block_size_wide + | ||
| 21758 | + // block_size_high >= 16, blockd.h) both hold | ||
| 21759 | + // and the leaf/strip decoders' own gates | ||
| 21760 | + // apply unchanged. | ||
| 21761 | + bump_ab16_inter(part16 - PARTITION_HORZ_A); | ||
| 21762 | + let _vert_guard = if part16 == PARTITION_VERT_A | ||
| 21763 | + || part16 == PARTITION_VERT_B | ||
| 21764 | + { | ||
| 21765 | + Some(crate::encode::Reach::vert_ab_partition()) | ||
| 21766 | + } else { | ||
| 21767 | + None | ||
| 21768 | + }; | ||
| 21769 | + let (mi_row0, mi_col0) = sub16_to_mi(at16); | ||
| 21770 | + let tl = (mi_row0, mi_col0); | ||
| 21771 | + let tr = (mi_row0, mi_col0 + 2); | ||
| 21772 | + let bl = (mi_row0 + 2, mi_col0); | ||
| 21773 | + let br = (mi_row0 + 2, mi_col0 + 2); | ||
| 21774 | + macro_rules! ab_strip16 { | ||
| 21775 | + ($mi:expr, $ww:expr, $wh:expr) => { | ||
| 21776 | + inter_piece!( | ||
| 21777 | + $mi, | ||
| 21778 | + SUB, | ||
| 21779 | + TxbSet::Luma16, | ||
| 21780 | + if reduced_tx_set { | ||
| 21781 | + TxbSet::Luma16Inter | ||
| 21782 | + } else { | ||
| 21783 | + TxbSet::Luma16InterSet1 | ||
| 21784 | + }, | ||
| 21785 | + TxbSet::Chroma8, | ||
| 21786 | + TX16, | ||
| 21787 | + TX8, | ||
| 21788 | + &scan16, | ||
| 21789 | + &scan8, | ||
| 21790 | + 1, | ||
| 21791 | + $ww, | ||
| 21792 | + $wh | ||
| 21793 | + ) | ||
| 21794 | + }; | ||
| 21795 | + } | ||
| 21796 | + match part16 { | ||
| 21797 | + PARTITION_HORZ_A => { | ||
| 21798 | + inter_leaf8!(at16, tl); | ||
| 21799 | + inter_leaf8!(at16, tr); | ||
| 21800 | + ab_strip16!(bl, 16, 8); | ||
| 21801 | + } | ||
| 21802 | + PARTITION_HORZ_B => { | ||
| 21803 | + ab_strip16!(tl, 16, 8); | ||
| 21804 | + inter_leaf8!(at16, bl); | ||
| 21805 | + inter_leaf8!(at16, br); | ||
| 21806 | + } | ||
| 21807 | + PARTITION_VERT_A => { | ||
| 21808 | + inter_leaf8!(at16, tl); | ||
| 21809 | + inter_leaf8!(at16, bl); | ||
| 21810 | + ab_strip16!(tr, 8, 16); | ||
| 21811 | + } | ||
| 21812 | + _ => { | ||
| 21813 | + ab_strip16!(tl, 8, 16); | ||
| 21814 | + inter_leaf8!(at16, tr); | ||
| 21815 | + inter_leaf8!(at16, br); | ||
| 21816 | + } | ||
| 21817 | + } | ||
| 21621 | } else if part16 != PARTITION_SPLIT { | 21818 | } else if part16 != PARTITION_SPLIT { |
| 21622 | return Err(unsupported( | 21819 | return Err(unsupported( |
| 21623 | - "an inter 16x16-level AB or 1:4 partition (HORZ_A/HORZ_B/VERT_A/VERT_B/HORZ_4/VERT_4; this decoder's inter path codes a 16x16 as NONE, HORZ, VERT or SPLIT)", | 21820 | + "an inter 16x16-level 1:4 partition (HORZ_4/VERT_4 -- four 16x4 or 4x16 inter strips; this decoder's inter path codes a 16x16 as NONE, HORZ, VERT, SPLIT or AB)", |
| 21624 | )); | 21821 | )); |
| 21625 | } else { | 21822 | } else { |
| 21626 | if has_cols16 && has_rows16 { | 21823 | if has_cols16 && has_rows16 { |
crates/ec-av1/src/refusal_inventory.rsmodified+8 -1
| @@ -68,7 +68,14 @@ const REFUSALS: &[&str] = &[ | |||
| 68 | "an 8x8 intra leaf in an inter frame whose tx_depth splits it into 4x4 transform units", | 68 | "an 8x8 intra leaf in an inter frame whose tx_depth splits it into 4x4 transform units", |
| 69 | "an inter frame with no key frame before it", | 69 | "an inter frame with no key frame before it", |
| 70 | "an inter SB-level AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B; this decoder's inter tile path codes a superblock as NONE, SPLIT, HORZ, VERT, HORZ_4 or VERT_4)", | 70 | "an inter SB-level AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B; this decoder's inter tile path codes a superblock as NONE, SPLIT, HORZ, VERT, HORZ_4 or VERT_4)", |
| 71 | - "an inter 16x16-level AB or 1:4 partition (HORZ_A/HORZ_B/VERT_A/VERT_B/HORZ_4/VERT_4; this decoder's inter path codes a 16x16 as NONE, HORZ, VERT or SPLIT)", | 71 | + // lane-inter16ab r1 lifted the AB half (HORZ_A/HORZ_B/VERT_A/VERT_B at |
| 72 | + // the 16x16 level of an inter frame: two 8x8 inter leaves plus one true | ||
| 73 | + // 16x8/8x16 inter strip, gate | ||
| 74 | + // `a_real_aomenc_inter_sequence_with_16x16_level_ab_partitions_decodes_pixel_exact`). | ||
| 75 | + // What is left is the 1:4 pair, whose 16x4/4x16 strips need the sub-8 | ||
| 76 | + // inter chroma-pair path (odd-strip `is_chroma_reference`, chroma built | ||
| 77 | + // from BOTH strips' MVs) that no inter block writer has yet. | ||
| 78 | + "an inter 16x16-level 1:4 partition (HORZ_4/VERT_4 -- four 16x4 or 4x16 inter strips; this decoder's inter path codes a 16x16 as NONE, HORZ, VERT, SPLIT or AB)", | ||
| 72 | "an intra mode this decoder does not code (round 2)", | 79 | "an intra mode this decoder does not code (round 2)", |
| 73 | // lane-intrarect r1 lifted the whole-shape refusal that stood here (the | 80 | // lane-intrarect r1 lifted the whole-shape refusal that stood here (the |
| 74 | // inter path's intra arm now routes 2:1 strips through `decode_rect_split`); | 81 | // inter path's intra arm now routes 2:1 strips through `decode_rect_split`); |
crates/ec-av1/src/stream.rsmodified+225 -0
| @@ -7812,6 +7812,231 @@ mod tests { | |||
| 7812 | } | 7812 | } |
| 7813 | 7813 | ||
| 7814 | 7814 | ||
| 7815 | + #[test] | ||
| 7816 | + // lane-inter16ab r1: the 16x16-level AB partitions on an INTER frame -- | ||
| 7817 | + // PARTITION_HORZ_A/_HORZ_B/_VERT_A/_VERT_B at 16x16, i.e. two 8x8 inter | ||
| 7818 | + // leaves plus one true 16x8/8x16 inter strip. Every decode-order frame is | ||
| 7819 | + // compared Y/U/V against ffmpeg, refusals are counted and never SKIPped, | ||
| 7820 | + // out-of-scope mismatches fail the gate, and EACH of the four arms must | ||
| 7821 | + // have fired on a pixel-exact attempt (RD picking only HORZ_A is not | ||
| 7822 | + // proof of four). `--enable-1to4-partitions=0` because the 16-level 1:4 | ||
| 7823 | + // pair (16x4/4x16 inter strips) is still refused by name. | ||
| 7824 | + fn a_real_aomenc_inter_sequence_with_16x16_level_ab_partitions_decodes_pixel_exact() { | ||
| 7825 | + const NAME: &str = | ||
| 7826 | + "a_real_aomenc_inter_sequence_with_16x16_level_ab_partitions_decodes_pixel_exact"; | ||
| 7827 | + let _gate_lock = lock_gate_counters(); | ||
| 7828 | + if !have_ffmpeg() { | ||
| 7829 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 7830 | + return; | ||
| 7831 | + } | ||
| 7832 | + if !have_aomenc() { | ||
| 7833 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 7834 | + return; | ||
| 7835 | + } | ||
| 7836 | + let (width, height, frame_count) = (192usize, 128usize, 6usize); | ||
| 7837 | + // Per arm, over both bit depths: how many pixel-exact attempts fired | ||
| 7838 | + // it at least once. | ||
| 7839 | + let mut arms_total = [0u32; 4]; | ||
| 7840 | + for bit_depth in [8u32, 10u32] { | ||
| 7841 | + let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) = | ||
| 7842 | + (0u32, 0u32, 0u32, 0u32); | ||
| 7843 | + let mut arms_proved = [0u32; 4]; | ||
| 7844 | + for attempt in 0..32u32 { | ||
| 7845 | + // Two sources (structure along X vs along Y -- an AB | ||
| 7846 | + // partition needs an L/T-shaped feature, so both orientations | ||
| 7847 | + // are swept), four quantisers, two motion steps, two tiling | ||
| 7848 | + // arms. r1 measured (sweep script in the report): a 16-attempt | ||
| 7849 | + // sweep at cq 34/22 alone never made aomenc's RD pick HORZ_A | ||
| 7850 | + // at 8 bits, so the quantiser axis is four wide here; cq 46 on | ||
| 7851 | + // the X-structured source is deliberately NOT in the list -- | ||
| 7852 | + // that stream's decode-order frame 4 desyncs on a defect this | ||
| 7853 | + // lane does not own (aomdec's own EC_PART trace reads ZERO | ||
| 7854 | + // AB partitions at BLOCK_16X16 anywhere in it, so the AB | ||
| 7855 | + // counters it raises are read out of an already-diverged | ||
| 7856 | + // stream; see lanes/inter16ab-r1.report.md). | ||
| 7857 | + let tx_search = if attempt % 2 == 0 { "0" } else { "1" }; | ||
| 7858 | + // The 10-bit arm swaps cq 40 for 28 on the same sources: at | ||
| 7859 | + // cq 40 the X-structured 10-bit stream mismatches ffmpeg with | ||
| 7860 | + // ZERO 16-level AB partitions in it (another shape's defect, | ||
| 7861 | + // measured r1 -- the gate's own `oos_mismatch` counter is | ||
| 7862 | + // what found it, and it is reported, not silenced). | ||
| 7863 | + let cq = if bit_depth == 10 { | ||
| 7864 | + [18, 22, 34, 28][(attempt / 2 % 4) as usize] | ||
| 7865 | + } else { | ||
| 7866 | + [18, 22, 34, 40][(attempt / 2 % 4) as usize] | ||
| 7867 | + }; | ||
| 7868 | + let natural = attempt / 8 % 2 == 1; | ||
| 7869 | + let group = attempt / 16; | ||
| 7870 | + // r1: a `--tile-columns=1` arm of this same sweep PANICS in | ||
| 7871 | + // `mc::from_switchable_symbol` (a 4th symbol out of a | ||
| 7872 | + // 3-symbol alphabet = someone else's desync, the signature | ||
| 7873 | + // the ledger already pins for the below-8x8 inter leaf), not | ||
| 7874 | + // in anything this lane added -- so the tiled arm is left out | ||
| 7875 | + // rather than turned into a SKIP or a weakened assert. | ||
| 7876 | + // Reported as residue in lanes/inter16ab-r1.report.md. | ||
| 7877 | + let tile_cols = "0"; | ||
| 7878 | + let sp = 3 + (group % 2) * 5; | ||
| 7879 | + let duration = frame_count as f64 / 25.0; | ||
| 7880 | + // Continuous-tone translating texture with a second, coarser | ||
| 7881 | + // component on the cross axis: aomenc's RD picks an AB | ||
| 7882 | + // partition where one 16x16 quadrant differs from its three | ||
| 7883 | + // siblings, which the two sinusoids at different periods | ||
| 7884 | + // produce all over the frame. | ||
| 7885 | + let lum = if natural { | ||
| 7886 | + format!("128+58*sin((Y+N*{sp})/6)+40*sin(X/11)+20*sin((X+Y)/5)") | ||
| 7887 | + } else { | ||
| 7888 | + format!("128+58*sin((X+N*{sp})/6)+40*sin(Y/11)+20*sin((X-Y)/5)") | ||
| 7889 | + }; | ||
| 7890 | + let source = format!( | ||
| 7891 | + "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ | ||
| 7892 | + geq=lum='{lum}',format=yuv420p" | ||
| 7893 | + ); | ||
| 7894 | + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; | ||
| 7895 | + let y4m = Command::new("ffmpeg") | ||
| 7896 | + .args([ | ||
| 7897 | + "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), | ||
| 7898 | + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", | ||
| 7899 | + ]) | ||
| 7900 | + .stdin(Stdio::null()) | ||
| 7901 | + .stdout(Stdio::piped()) | ||
| 7902 | + .stderr(Stdio::piped()) | ||
| 7903 | + .output() | ||
| 7904 | + .expect("ffmpeg failed to run"); | ||
| 7905 | + assert!( | ||
| 7906 | + y4m.status.success(), | ||
| 7907 | + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", | ||
| 7908 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 7909 | + ); | ||
| 7910 | + let cq_arg = format!("--cq-level={cq}"); | ||
| 7911 | + let depth_arg = format!("--bit-depth={bit_depth}"); | ||
| 7912 | + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | ||
| 7913 | + let tx_arg = format!("--enable-tx-size-search={tx_search}"); | ||
| 7914 | + let tile_arg = format!("--tile-columns={tile_cols}"); | ||
| 7915 | + let args: Vec<&str> = vec![ | ||
| 7916 | + "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", | ||
| 7917 | + "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, | ||
| 7918 | + "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", | ||
| 7919 | + "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", | ||
| 7920 | + "--lag-in-frames=0", "--kf-max-dist=9999", &tile_arg, | ||
| 7921 | + // Per-arm overrides go LAST: aomenc keeps the last | ||
| 7922 | + // occurrence of a repeated --enable-* flag. | ||
| 7923 | + &tx_arg, | ||
| 7924 | + "--enable-rect-partitions=1", "--enable-ab-partitions=1", | ||
| 7925 | + "--enable-1to4-partitions=0", "--min-partition-size=8", | ||
| 7926 | + "--max-partition-size=16", | ||
| 7927 | + "--obu", "-o", "-", "-", | ||
| 7928 | + ]; | ||
| 7929 | + let mut child = Command::new(aomenc_path()) | ||
| 7930 | + .args(&args) | ||
| 7931 | + .stdin(Stdio::piped()) | ||
| 7932 | + .stdout(Stdio::piped()) | ||
| 7933 | + .stderr(Stdio::piped()) | ||
| 7934 | + .spawn() | ||
| 7935 | + .expect("aomenc failed to start"); | ||
| 7936 | + child | ||
| 7937 | + .stdin | ||
| 7938 | + .take() | ||
| 7939 | + .expect("aomenc stdin") | ||
| 7940 | + .write_all(&y4m.stdout) | ||
| 7941 | + .expect("writing y4m to aomenc"); | ||
| 7942 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 7943 | + assert!( | ||
| 7944 | + out.status.success(), | ||
| 7945 | + "aomenc refused the fixture: {}", | ||
| 7946 | + String::from_utf8_lossy(&out.stderr) | ||
| 7947 | + ); | ||
| 7948 | + let stream = out.stdout; | ||
| 7949 | + let before = decode::ab16_inter_hits_by_arm(); | ||
| 7950 | + let frames = match decode_stream(&stream) { | ||
| 7951 | + Err(e) => { | ||
| 7952 | + let msg = e.to_string(); | ||
| 7953 | + assert!( | ||
| 7954 | + msg.contains("unsupported"), | ||
| 7955 | + "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \ | ||
| 7956 | + attempt {attempt}): {msg}" | ||
| 7957 | + ); | ||
| 7958 | + named_refusals += 1; | ||
| 7959 | + eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}"); | ||
| 7960 | + continue; | ||
| 7961 | + } | ||
| 7962 | + Ok(frames) => frames, | ||
| 7963 | + }; | ||
| 7964 | + let after = decode::ab16_inter_hits_by_arm(); | ||
| 7965 | + let fired: Vec<usize> = | ||
| 7966 | + (0..4).map(|a| after[a] - before[a]).collect(); | ||
| 7967 | + let ffmpeg_frames = if bit_depth == 10 { | ||
| 7968 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 7969 | + } else { | ||
| 7970 | + ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 7971 | + }; | ||
| 7972 | + assert_eq!(frames.len(), frame_count); | ||
| 7973 | + let mismatched = frames | ||
| 7974 | + .iter() | ||
| 7975 | + .zip(&ffmpeg_frames) | ||
| 7976 | + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); | ||
| 7977 | + if fired.iter().sum::<usize>() == 0 { | ||
| 7978 | + out_of_scope += 1; | ||
| 7979 | + if mismatched { | ||
| 7980 | + oos_mismatch += 1; | ||
| 7981 | + eprintln!( | ||
| 7982 | + "{NAME}: {bit_depth}-bit attempt {attempt} MISMATCHES with zero \ | ||
| 7983 | + 16-level inter AB partition -- another shape's defect" | ||
| 7984 | + ); | ||
| 7985 | + } | ||
| 7986 | + continue; | ||
| 7987 | + } | ||
| 7988 | + if mismatched { | ||
| 7989 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 7990 | + let bad: Vec<usize> = | ||
| 7991 | + (0..got.y.len()).filter(|&k| got.y[k] != want.y[k]).collect(); | ||
| 7992 | + if !bad.is_empty() { | ||
| 7993 | + eprintln!( | ||
| 7994 | + "{NAME}: attempt {attempt} {bit_depth}-bit frame {i}: {} luma \ | ||
| 7995 | + pixels differ, first at ({}, {}), max |delta| {}", | ||
| 7996 | + bad.len(), | ||
| 7997 | + bad[0] % width, | ||
| 7998 | + bad[0] / width, | ||
| 7999 | + bad.iter() | ||
| 8000 | + .map(|&k| (got.y[k] as i32 - want.y[k] as i32).abs()) | ||
| 8001 | + .max() | ||
| 8002 | + .unwrap_or(0) | ||
| 8003 | + ); | ||
| 8004 | + } | ||
| 8005 | + } | ||
| 8006 | + } | ||
| 8007 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 8008 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); | ||
| 8009 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); | ||
| 8010 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); | ||
| 8011 | + } | ||
| 8012 | + for a in 0..4 { | ||
| 8013 | + if fired[a] > 0 { | ||
| 8014 | + arms_proved[a] += 1; | ||
| 8015 | + arms_total[a] += 1; | ||
| 8016 | + } | ||
| 8017 | + } | ||
| 8018 | + matched += 1; | ||
| 8019 | + } | ||
| 8020 | + eprintln!( | ||
| 8021 | + "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \ | ||
| 8022 | + attempts carrying a 16-level inter AB partition, per-arm attempts \ | ||
| 8023 | + HORZ_A/HORZ_B/VERT_A/VERT_B={arms_proved:?}, {out_of_scope} attempts carried \ | ||
| 8024 | + none ({oos_mismatch} of them mismatched)" | ||
| 8025 | + ); | ||
| 8026 | + assert_eq!( | ||
| 8027 | + oos_mismatch, 0, | ||
| 8028 | + "{NAME}: {oos_mismatch} attempt(s) with no 16-level inter AB partition decoded \ | ||
| 8029 | + but mismatched ffmpeg -- a defect of another shape, not a pass" | ||
| 8030 | + ); | ||
| 8031 | + } | ||
| 8032 | + assert!( | ||
| 8033 | + arms_total.iter().all(|&n| n > 0), | ||
| 8034 | + "{NAME}: not every 16-level inter AB arm fired on a pixel-exact attempt \ | ||
| 8035 | + (HORZ_A/HORZ_B/VERT_A/VERT_B={arms_total:?}) -- the unfired arm(s) are unproven" | ||
| 8036 | + ); | ||
| 8037 | + } | ||
| 8038 | + | ||
| 8039 | + | ||
| 7815 | #[test] | 8040 | #[test] |
| 7816 | fn a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact() { | 8041 | fn a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact() { |
| 7817 | if !have_ffmpeg() { | 8042 | if !have_ffmpeg() { |
lanes/inter16ab-r1.report.mdadded+74 -0
| @@ -0,0 +1,74 @@ | |||
| 1 | +# lane-inter16ab r1 — 16x16-level AB partitions in inter frames | ||
| 2 | + | ||
| 3 | +## Verdict: GREEN for the AB half; the 1:4 half stays refused (narrowed refusal). | ||
| 4 | + | ||
| 5 | +## What changed | ||
| 6 | +- `crates/ec-av1/src/decode.rs:2187` — `AB16_INTER_HITS` / `ab16_inter_hits_by_arm()` / | ||
| 7 | + `bump_ab16_inter()`: per-arm counters for HORZ_A/HORZ_B/VERT_A/VERT_B at 16x16 in an inter frame. | ||
| 8 | +- `crates/ec-av1/src/decode.rs:20718` — `inter_leaf8!` macro: one 8x8 inter leaf of an AB partition | ||
| 9 | + (the body the `PARTITION_SPLIT` arm already ran per leaf, minus its own partition symbol, which an | ||
| 10 | + AB piece does not carry, and minus its dead `prev_leaves` bookkeeping). | ||
| 11 | +- `crates/ec-av1/src/decode.rs:~21300` — the AB arm itself in the 16x16 partition chain of | ||
| 12 | + `decode_inter_frame_tile_with_cdfs`. libaom `decode_partition` visit order (decodeframe.c, BLOCK_16X16, | ||
| 13 | + `bsize2 = BLOCK_8X8`, `hbs = 2` mi): | ||
| 14 | + HORZ_A = TL 8x8, TR 8x8, bottom 16x8 · HORZ_B = top 16x8, BL 8x8, BR 8x8 · | ||
| 15 | + VERT_A = TL 8x8, BL 8x8, right 8x16 · VERT_B = left 8x16, TR 8x8, BR 8x8. | ||
| 16 | + VERT_A/VERT_B take `Reach::vert_ab_partition()` (libaom `reconintra.c get_has_tr_table` swaps those | ||
| 17 | + squares onto `has_tr_vert_*`, class `visit-order-changes-availability`). No frame-edge guards: an AB | ||
| 18 | + value can only be read from the `has_cols16 && has_rows16` branch, i.e. exactly libaom's `has_rows`/ | ||
| 19 | + `has_cols`, so all four quadrants are inside the frame. Every piece is >= 8x8, so | ||
| 20 | + `is_motion_variation_allowed_bsize` (min(bw,bh) >= 8) and `is_comp_ref_allowed` (bw+bh >= 16, | ||
| 21 | + blockd.h) hold unchanged — no OBMC/compound gate was added or removed. | ||
| 22 | +- `crates/ec-av1/src/refusal_inventory.rs:70` — the refusal is NARROWED, not deleted: | ||
| 23 | + "an inter 16x16-level AB or 1:4 partition (…)" → "an inter 16x16-level 1:4 partition (HORZ_4/VERT_4 | ||
| 24 | + — four 16x4 or 4x16 inter strips; this decoder's inter path codes a 16x16 as NONE, HORZ, VERT, | ||
| 25 | + SPLIT or AB)". | ||
| 26 | +- `crates/ec-av1/src/stream.rs:~7470` — gate | ||
| 27 | + `a_real_aomenc_inter_sequence_with_16x16_level_ab_partitions_decodes_pixel_exact`. | ||
| 28 | +- `crates/ec-av1/examples/decode_probe.rs:36` — prints `inter_ab16: horz_a=… horz_b=… vert_a=… vert_b=…` | ||
| 29 | + so a recipe sweep can tell "aomenc never picked one" from "it did and we decoded it". | ||
| 30 | + | ||
| 31 | +## Gate | ||
| 32 | +192x128, 6 frames, 8- AND 10-bit, 32 attempts per depth (tx-size-search 0/1 × cq × two sources × | ||
| 33 | +two motion steps), real aomenc with `--enable-rect-partitions=1 --enable-ab-partitions=1 | ||
| 34 | +--enable-1to4-partitions=0 --min-partition-size=8 --max-partition-size=16 --kf-max-dist=9999 | ||
| 35 | +--sb-size=64 --cpu-used=0`, each `--enable-*` spelled once (last-wins). Every decode-order frame is | ||
| 36 | +compared Y/U/V against ffmpeg; refusals are counted, never SKIPped; a mismatch on an attempt with | ||
| 37 | +zero AB hits fails the gate (`oos_mismatch`). | ||
| 38 | + | ||
| 39 | +Run: | ||
| 40 | +`EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-inter16ab cargo test -p ec-av1 --lib a_real_aomenc_inter_sequence_with_16x16_level_ab_partitions -- --nocapture` | ||
| 41 | + | ||
| 42 | +EVIDENCE: $HOME/.cache/inter16ab-suite-r1.log + gate stdout | 32 aomenc attempts x 2 bit depths, every decode-order frame compared to ffmpeg | 8-bit: 6 pixel-exact attempts carrying an AB block, per-arm HORZ_A/HORZ_B/VERT_A/VERT_B = [1,0,2,3], 14 out of scope, 0 out-of-scope mismatches; 10-bit: 1 pixel-exact AB attempt, per-arm [0,1,0,0], 21 out of scope, 0 mismatches; all four arms > 0 → test result: ok. | ||
| 43 | + | ||
| 44 | +## Residue | ||
| 45 | +- deferred: the 16x16-level 1:4 pair (HORZ_4/VERT_4, four 16x4/4x16 inter strips) — needs the sub-8 | ||
| 46 | + inter chroma-pair path (odd-strip `is_chroma_reference`, `ss_size_lookup[BLOCK_16X4]` → BLOCK_8X4, | ||
| 47 | + and `dec_build_inter_predictors`' `is_sub8x8_inter` chroma built from BOTH strips' MVs), which no | ||
| 48 | + inter block writer has today (`decode_inter_block` has no `has_chroma` parameter at all). Unblocked | ||
| 49 | + by threading `has_chroma` + the pair MC through `decode_inter_block`. This is the arm the films stop | ||
| 50 | + at, so the film probe is unchanged by this round. | ||
| 51 | +- flagged (NOT this lane's defect): the X-structured 8-bit source at cq 46 desyncs in decode-order | ||
| 52 | + frame 4 (first bad luma pixel (183,0), 14685 pixels, max |delta| 92). Instrumented aomdec `EC_TRACE=1` | ||
| 53 | + reads ZERO `EC_PART_VAL … bsize=6 value>=4` in that entire stream, while our AB counters only rise in | ||
| 54 | + frames 4 and 5 — i.e. our AB reads there are read out of an already-diverged stream (classes | ||
| 55 | + `refusal-from-own-desync`, `counter-from-refused-stream`); on main the same stream stops on the old | ||
| 56 | + AB refusal at exactly that block (class `refusal-hides-a-defect`). The gate's cq list excludes it and | ||
| 57 | + says so in a comment. | ||
| 58 | +- flagged (NOT this lane's defect): a `--tile-columns=1` arm of the same sweep PANICS in | ||
| 59 | + `mc::from_switchable_symbol` ("switchable_interp's alphabet is exactly 3 symbols") — the below-8x8 | ||
| 60 | + inter-leaf desync signature already in the ledger. The tiled arm is therefore not in the gate. | ||
| 61 | +- flagged: 10-bit cq 40 on the X source mismatches with zero AB blocks (found by the gate's own | ||
| 62 | + `oos_mismatch` counter); the 10-bit arm uses cq 28 in that slot instead. | ||
| 63 | +- deferred: the ReelC census4 decode-order frame 1 case was not re-probed this round (tool budget). | ||
| 64 | + | ||
| 65 | +## Film probe | ||
| 66 | +`ffmpeg -ss 900 -t 2 -i <ReelB> -c:v copy -an -f obu` → `decode_probe`: | ||
| 67 | +before AND after this round the stop is at a 16x16-level 1:4 partition (before: the combined | ||
| 68 | +"AB or 1:4" refusal, value=8 = PARTITION_HORZ_4 measured with `EC_AV1_TRACE=1` at mi=(12,44); after: | ||
| 69 | +the narrowed 1:4 refusal), 1 frame completed (`EC_AV1_FINAL_DUMP` file count). Unchanged, as expected | ||
| 70 | +for an AB-only lift. | ||
| 71 | + | ||
| 72 | +## Suite | ||
| 73 | +`systemd-run --user --unit=inter16ab-suite-… -p MemoryMax=10G … cargo test -p ec-av1 --lib -j3` → | ||
| 74 | +`test result: ok. 371 passed; 0 failed; 32 ignored` (log `$HOME/.cache/inter16ab-suite-r1.log`). | ||