forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-av1blend': ref-frame ctx counts both compound-neighbour refs; interp_filter read order

Browse files at this commit

c80603181233ea5cc197af8a8e2f365c4654b4f6Ahmet Kaan GümüşParent: e117d903f636a9
Seven-round bisect. Real fixes: mvstack ref_ctx family now counts both
refs of a compound neighbour (libaom av1_collect_neighbors_ref_counts);
resolve_interp_filter read moved after the compound reads per spec
5.11.19. Pinned compound fixture now decodes 24/24 frames byte-exact
unmasked; a second compound_idx defect remains, so comp_group_idx==0
blends stay refused-by-name and gates stay green. Trace instrumentation
from the bisect rides along, cleanup queued.
crates/ec-av1/src/decode.rsmodified+323 -58
@@ -2499,6 +2499,12 @@ fn cdef_filter_block(
24992499 // aomdec's EC_AV1_PREFILT_DUMP/EC_AV1_POSTFILT_DUMP) to `$var.f$idx` when
25002500 // `var` is set. Remove with the rest of the r17 bisect scaffolding.
25012501 static R17_DUMP_FRAME_IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
2502+// r17 bisect scratch accessor for stream.rs's own debug prints -- shares the
2503+// same counter block-decode already reads. Remove with the rest of the r17
2504+// bisect scaffolding.
2505+pub fn r17_dump_frame_idx() -> usize {
2506+ R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed)
2507+}
25022508 fn r17_dump(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, idx: usize) {
25032509 let Ok(base) = std::env::var(var) else {
25042510 return;
@@ -3877,25 +3883,32 @@ fn read_inter_plane(
38773883 /// `reference_select` set before this is ever called, so that read is never
38783884 /// needed here). `above_ref`/`left_ref` are `-1` for an intra/unavailable
38793885 /// neighbour, else the `1..=7` reference that neighbour coded (lane-av1refs).
3880-fn read_single_ref(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, above_ref: i8, left_ref: i8) -> i8 {
3886+fn read_single_ref(
3887+ dec: &mut SymbolDecoder,
3888+ cdfs: &mut Cdfs,
3889+ above_ref: i8,
3890+ above_ref1: Option<i8>,
3891+ left_ref: i8,
3892+ left_ref1: Option<i8>,
3893+) -> i8 {
38813894 let above = (above_ref > 0).then_some(above_ref);
38823895 let left = (left_ref > 0).then_some(left_ref);
3883- let p1 = dec.symbol(&mut cdfs.single_ref[single_ref_p1_ctx(above, left)][0]);
3896+ let p1 = dec.symbol(&mut cdfs.single_ref[single_ref_p1_ctx(above, above_ref1, left, left_ref1)][0]);
38843897 let ref_frame = if p1 == 1 {
3885- let p2 = dec.symbol(&mut cdfs.single_ref[single_ref_p2_ctx(above, left)][1]);
3898+ let p2 = dec.symbol(&mut cdfs.single_ref[single_ref_p2_ctx(above, above_ref1, left, left_ref1)][1]);
38863899 if p2 == 1 {
38873900 ALTREF_FRAME
38883901 } else {
3889- let p6 = dec.symbol(&mut cdfs.single_ref[single_ref_p6_ctx(above, left)][5]);
3902+ let p6 = dec.symbol(&mut cdfs.single_ref[single_ref_p6_ctx(above, above_ref1, left, left_ref1)][5]);
38903903 if p6 == 1 { ALTREF2_FRAME } else { BWDREF_FRAME }
38913904 }
38923905 } else {
3893- let p3 = dec.symbol(&mut cdfs.single_ref[single_ref_p3_ctx(above, left)][2]);
3906+ let p3 = dec.symbol(&mut cdfs.single_ref[single_ref_p3_ctx(above, above_ref1, left, left_ref1)][2]);
38943907 if p3 == 1 {
3895- let p5 = dec.symbol(&mut cdfs.single_ref[single_ref_p5_ctx(above, left)][4]);
3908+ let p5 = dec.symbol(&mut cdfs.single_ref[single_ref_p5_ctx(above, above_ref1, left, left_ref1)][4]);
38963909 if p5 == 1 { GOLDEN_FRAME } else { LAST3_FRAME }
38973910 } else {
3898- let p4 = dec.symbol(&mut cdfs.single_ref[single_ref_p4_ctx(above, left)][3]);
3911+ let p4 = dec.symbol(&mut cdfs.single_ref[single_ref_p4_ctx(above, above_ref1, left, left_ref1)][3]);
38993912 if p4 == 1 { LAST2_FRAME } else { LAST_FRAME }
39003913 }
39013914 };
@@ -4051,19 +4064,26 @@ fn read_compound_ref_frames(
40514064 ) -> (i8, i8) {
40524065 let a = (above_ref > 0).then_some(above_ref);
40534066 let l = (left_ref > 0).then_some(left_ref);
4067+ // libaom `av1_collect_neighbors_ref_counts` counts BOTH of a compound
4068+ // neighbour's references, not just its first -- `a1`/`l1` carry that
4069+ // second reference through to every vote below (lane-av1blend r6: a
4070+ // missing `a1`/`l1` here was decoding `compound_idx` off the wrong CDF
4071+ // row for a block sitting under a skip_mode-forced compound neighbour).
4072+ let a1 = above.and_then(|n| n.ref1);
4073+ let l1 = left.and_then(|n| n.ref1);
40544074 let type_ctx = comp_reference_type_ctx(above, left);
40554075 let unidir = dec.symbol(&mut cdfs.comp_ref_type[type_ctx]) == 0;
40564076 if unidir {
40574077 // uni_comp_ref (p0): forward vs. backward -- av1_get_pred_context_-
40584078 // uni_comp_ref_p is single_ref_p1's own forward/backward vote.
4059- let bit = dec.symbol(&mut cdfs.uni_comp_ref[single_ref_p1_ctx(a, l)][0]);
4079+ let bit = dec.symbol(&mut cdfs.uni_comp_ref[single_ref_p1_ctx(a, a1, l, l1)][0]);
40604080 if bit == 1 {
40614081 (BWDREF_FRAME, ALTREF_FRAME)
40624082 } else {
4063- let p1 = dec.symbol(&mut cdfs.uni_comp_ref[uni_comp_ref_p1_ctx(a, l)][1]);
4083+ let p1 = dec.symbol(&mut cdfs.uni_comp_ref[uni_comp_ref_p1_ctx(a, a1, l, l1)][1]);
40644084 if p1 == 1 {
40654085 // uni_comp_ref_p2: LAST3 vs. GOLDEN, same vote as single_ref_p5.
4066- let p2 = dec.symbol(&mut cdfs.uni_comp_ref[single_ref_p5_ctx(a, l)][2]);
4086+ let p2 = dec.symbol(&mut cdfs.uni_comp_ref[single_ref_p5_ctx(a, a1, l, l1)][2]);
40674087 if p2 == 1 {
40684088 (LAST_FRAME, GOLDEN_FRAME)
40694089 } else {
@@ -4075,21 +4095,21 @@ fn read_compound_ref_frames(
40754095 }
40764096 } else {
40774097 // comp_ref (p0): LAST/LAST2 vs. LAST3/GOLDEN, same vote as single_ref_p3.
4078- let bit0 = dec.symbol(&mut cdfs.comp_ref[single_ref_p3_ctx(a, l)][0]);
4098+ let bit0 = dec.symbol(&mut cdfs.comp_ref[single_ref_p3_ctx(a, a1, l, l1)][0]);
40794099 let ref0 = if bit0 == 0 {
40804100 // comp_ref_p1: LAST vs. LAST2, same vote as single_ref_p4.
4081- let p1 = dec.symbol(&mut cdfs.comp_ref[single_ref_p4_ctx(a, l)][1]);
4101+ let p1 = dec.symbol(&mut cdfs.comp_ref[single_ref_p4_ctx(a, a1, l, l1)][1]);
40824102 if p1 == 1 { LAST2_FRAME } else { LAST_FRAME }
40834103 } else {
40844104 // comp_ref_p2: LAST3 vs. GOLDEN, same vote as single_ref_p5.
4085- let p2 = dec.symbol(&mut cdfs.comp_ref[single_ref_p5_ctx(a, l)][2]);
4105+ let p2 = dec.symbol(&mut cdfs.comp_ref[single_ref_p5_ctx(a, a1, l, l1)][2]);
40864106 if p2 == 1 { GOLDEN_FRAME } else { LAST3_FRAME }
40874107 };
40884108 // comp_bwdref (p0): BWDREF/ALTREF2 vs. ALTREF, same vote as single_ref_p2.
4089- let bit1 = dec.symbol(&mut cdfs.comp_bwdref[single_ref_p2_ctx(a, l)][0]);
4109+ let bit1 = dec.symbol(&mut cdfs.comp_bwdref[single_ref_p2_ctx(a, a1, l, l1)][0]);
40904110 let ref1 = if bit1 == 0 {
40914111 // comp_bwdref_p1: BWDREF vs. ALTREF2, same vote as single_ref_p6.
4092- let p1 = dec.symbol(&mut cdfs.comp_bwdref[single_ref_p6_ctx(a, l)][1]);
4112+ let p1 = dec.symbol(&mut cdfs.comp_bwdref[single_ref_p6_ctx(a, a1, l, l1)][1]);
40934113 if p1 == 1 { ALTREF2_FRAME } else { BWDREF_FRAME }
40944114 } else {
40954115 ALTREF_FRAME
@@ -4293,6 +4313,14 @@ fn decode_inter_block(
42934313 let (cpx, cpy) = (px / 2, py / 2);
42944314 let chroma_side = side / 2;
42954315
4316+ if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {
4317+ eprintln!(
4318+ "BITPOS_BLK_START mi_row={} mi_col={} bitpos={}",
4319+ py / 4,
4320+ px / 4,
4321+ dec.debug_bitpos()
4322+ );
4323+ }
42964324 let skip_mode_ctx =
42974325 usize::from(neighbours.above_skip_mode[c]) + usize::from(neighbours.left_skip_mode[r]);
42984326 let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;
@@ -4412,16 +4440,6 @@ fn decode_inter_block(
44124440 } else {
44134441 [3, 3]
44144442 };
4415- let (h_filter, v_filter, resolved_filter) = resolve_interp_filter(
4416- dec,
4417- cdfs,
4418- interp_fixed,
4419- enable_dual_filter,
4420- is_globalmv,
4421- above_filter_ctx,
4422- left_filter_ctx,
4423- );
4424- block_filter = resolved_filter;
44254443 globalmv_for_lf = is_globalmv;
44264444 ref_frame_for_lf = ref0;
44274445 mode_for_tx = 0;
@@ -4466,33 +4484,193 @@ fn decode_inter_block(
44664484 weighted/simple-average combine only, lane-av1comp",
44674485 ));
44684486 }
4469- // corner-cut (lane-av1comp r16/r17): a real aomenc stream
4470- // (fixtures/av1comp-r16-compound-mismatch.obu, seed 42) proved
4471- // predict_compound_intermediate/combine_compound wrong by up to
4472- // 4/255 in a 32x32 quadrant, spilling a few pixels into
4473- // neighbours. r16 called this "loop-filter-shaped"; r17
4474- // FALSIFIED that -- dumping this decoder's own pre-deblock
4475- // frame buffer (`r17_dump`, `EC_AV1_PREFILT_DUMP`) against
4476- // aomdec's own `EC_AV1_PREFILT_DUMP` shows the same 32x32-
4477- // quadrant mismatch already present *before* either decoder's
4478- // loop filter runs (898/1024 px, rows 32-63 cols 32-63 of a
4479- // 64x64 luma plane, frame index 2 zero-based / this decoder's
4480- // 3rd frame) -- this is a `predict_compound_intermediate`/
4481- // `combine_compound` reconstruction defect, not a deblock
4482- // interaction. DRL/assign_compound_mv/dist_wtd_comp_weight_assign
4483- // stay cross-checked bit-for-bit against libaom decodemv.c/
4484- // reconinter.c (r16). Root cause still not isolated within this
4485- // arithmetic; refuse by name rather than ship a non-pixel-exact
4486- // compound blend. Ceiling: r13/r14's MC plumbing above this line
4487+ // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): r16/r17
4488+ // called this a `predict_compound_intermediate`/`combine_compound`
4489+ // reconstruction defect. r1 FALSIFIED that hypothesis outright:
4490+ // unmasking and running the real gates
4491+ // (a_real_aomenc_stream_with_reference_select_reads_comp_mode_correctly,
4492+ // a_real_aomenc_stream_with_compound_references_decodes_pixel_exact)
4493+ // shows the plain-average blend is bit-exact *most of the time*
4494+ // -- `combine_compound`'s two-shift-in-one round2 was proven
4495+ // algebraically identical to libaom's separate
4496+ // `>>DIST_PRECISION_BITS`-then-`ROUND_POWER_OF_TWO` sequence
4497+ // (av1_dist_wtd_convolve_2d_c, convolve.c:402-415) for every
4498+ // input, and a whole-pel zero-MV compound block (mv0=mv1=(0,0),
4499+ // the common case a lag-in-frames GOP's hidden altref frames
4500+ // hit) reproduces aomdec's own pre-deblock `EC_AV1_PREFILT_DUMP`
4501+ // byte-for-byte for several consecutive frames.
4502+ //
4503+ // The real defect a live gate run isolated (seed 49,
4504+ // `fixtures/av1blend-r1-mismatch.obu`): decode-order frame 0
4505+ // (keyframe) and frame 1 (first hidden altref, `ref1 ==
4506+ // ALTREF_FRAME`) match aomdec's own pre-deblock dump byte for
4507+ // byte; decode-order frame 2 -- same shape, same zero MV, only
4508+ // difference `ref1 == BWDREF_FRAME` instead of `ALTREF_FRAME` --
4509+ // is the *first* frame to diverge (881/6144 luma+chroma bytes).
4510+ // Every later frame up through decode-order 9 also mismatches,
4511+ // *including* frame 8, whose four blocks are back to
4512+ // `ref1 == ALTREF_FRAME` only -- ruling out "BWDREF_FRAME's MC
4513+ // math is wrong" (that block's own math is proven exact) in
4514+ // favour of "the picture sitting in some DPB slot is already
4515+ // wrong by the time frame 2 reads it, and the corruption
4516+ // propagates through refresh_frame_flags into every later
4517+ // reference regardless of which named ref a later block picks".
4518+ // Frames 10 through 18 (once the GOP's lineage stops tracing
4519+ // back through the bad slot) are bit-exact again. This points at
4520+ // reference-slot bookkeeping (`ref_slots`/`refresh_frame_flags`
4521+ // in `stream.rs`'s `decode_stream`, or `ref_order_hints`/DPB
4522+ // indexing feeding `dist_wtd_comp_weight_assign`) around
4523+ // BWDREF_FRAME specifically, not at the MC/blend arithmetic in
4524+ // mc.rs. Not isolated further within lane-av1blend's budget --
4525+ // refuse by name rather than ship a blend that is right only
4526+ // sometimes. Ceiling: r13/r14's MC plumbing above this line
44874527 // stays -- only the plain-average reconstruct is masked off
4488- // again. Upgrade: bisect predict_compound_intermediate itself
4489- // (subpel filter taps / rounding) against the pinned fixture's
4490- // 3rd frame, quadrant rows 32-63 cols 32-63.
4528+ // again. Upgrade: instrument `ref_slots`/`refresh_frame_flags`
4529+ // per decode-order frame (which slot each `Frame` OBU refreshes,
4530+ // and which slot each `ref_frame_idx[BWDREF_FRAME - LAST_FRAME]`
4531+ // reads) against aomdec's own `RefCntBuffer` bookkeeping on
4532+ // `fixtures/av1blend-r1-mismatch.obu`, starting at decode-order
4533+ // frame 2.
4534+ //
4535+ // r2 (fresh fixture, seed 45, same recipe -- the original r1
4536+ // fixture is gitignored and could not be regenerated byte-exact):
4537+ // static review of `stream.rs`'s `ref_slots`/`refresh_frame_flags`/
4538+ // `cdf_slots` bookkeeping and the `show_existing_frame` refresh
4539+ // arm (spec 7.21: only refreshes on a shown KEY frame, which the
4540+ // parser already enforces at `frame.rs:791/815` -- `refresh_frame_flags`
4541+ // is forced 0 on every non-key `show_existing_frame`) turned up
4542+ // nothing wrong; `other_refs`/`ref_planes` slot indexing for
4543+ // `BWDREF_FRAME` is spec-correct too. A live unmasked run
4544+ // isolated a *different, smaller* shape than r1's: decode-order
4545+ // frame 3 (a `ref1 == BWDREF_FRAME`, zero-MV, simple-average
4546+ // compound block) is the first to diverge from ffmpeg (worst
4547+ // delta 1, luma only, clustered at 32-pixel block edges) even
4548+ // though BOTH its compound inputs -- the key frame and
4549+ // decode-order frame 2's own picture (`ref1 == ALTREF_FRAME`,
4550+ // itself proven bit-exact: it is later re-shown via
4551+ // `show_existing_frame` and matches ffmpeg exactly) -- are
4552+ // independently pixel-exact, and the blend arithmetic is the
4553+ // same proven-exact formula. That rules out "wrong slot"/"stale
4554+ // picture" for this fixture: the inputs are right, so the defect
4555+ // is in decode-order frame 3's *own* per-block decode (entropy
4556+ // desync from compound-CDF adaptation carried across a slot, or
4557+ // the compound mode/MV read itself) -- not in `ref_slots`/
4558+ // `refresh_frame_flags`. Not isolated further within budget.
4559+ // Upgrade: bisect decode-order frame 3's tile decode against a
4560+ // synced `EC_TOK`/`EC_PART` trace from the instrumented aomdec
4561+ // build (`/tmp/libaom-src/build/decoder-debug/aomdec`) on
4562+ // `fixtures/av1blend-r1-mismatch.obu` (seed 45 now, not seed 49)
4563+ // -- the pre-deblock `EC_AV1_PREFILT_DUMP` frame-index alignment
4564+ // between this crate and that aomdec build is NOT 1:1 on this
4565+ // fixture (23 dumps here vs 24 there), so calibrate that first.
4566+ // r3 (this round): pre-deblock buffers were bisected byte-for-byte
4567+ // against an instrumented aomdec build (EC_AV1_PREFILT_DUMP,
4568+ // frame-index alignment recalibrated via content-hash matching
4569+ // rather than the raw dump count -- the keyframe never calls this
4570+ // crate's own `r17_dump` at all, since only `decode_inter_frame_
4571+ // tile` does, which is the whole "23 vs 24" gap, not a real bug).
4572+ // Decode-order frame 3 (`fixtures/av1blend-r1-mismatch.obu`,
4573+ // seed 45) is still the first divergence: PRE-deblock differs
4574+ // from aomdec's own pre-deblock dump by up to 1, on ~20% of
4575+ // luma pixels, clustered where its two compound inputs' pixel
4576+ // values disagree by more than a couple of levels -- both
4577+ // inputs (the keyframe and decode-order frame 2's own picture)
4578+ // are independently proven bit-exact (pre- and post-deblock)
4579+ // against aomdec, and `decodemv`'s own EC_TRACE (mode/mv/skip)
4580+ // matches this decoder's block loop exactly for every block in
4581+ // this frame. Solving `aomval = (key*w0 + bwd*w1 + 8) >> 4` for
4582+ // every mismatching pixel against `key`/`bwd` (both known-exact)
4583+ // picks out `w0=9, w1=7` for the majority (525/846) with zero
4584+ // matches for the plain average this decoder actually emits or
4585+ // the reversed `w0=7, w1=9` -- i.e. `compound_idx` is being
4586+ // decoded as `1` (simple average, spec `COMPOUND_AVERAGE`) when
4587+ // the real bitstream encoded `0` (`COMPOUND_DISTWTD`,
4588+ // `dist_wtd_comp_weight_assign`'s own weights for this frame's
4589+ // order-hint distances 2/3 land on exactly `(9, 7)` -- this
4590+ // decoder's own `dist_wtd_comp_weight_assign` was independently
4591+ // re-verified against `QUANT_DIST_WEIGHT`/`QUANT_DIST_LOOKUP_TABLE`
4592+ // by hand for these distances and gives the same `(9, 7)`).
4593+ // `get_comp_index_context` was checked line-for-line against
4594+ // libaom's `pred_common.h` (the `fwd`/`bck` distance halves, the
4595+ // `above_mi`/`left_mi` `has_second_ref`/`ALTREF_FRAME` fallback,
4596+ // the `3 * offset` term) and matches; `Default_Compound_Idx_Cdf`
4597+ // (`cdf.rs`'s `COMPOUND_IDX`) matches `entropymode.c`'s
4598+ // `default_compound_idx_cdfs` value-for-value; the read is
4599+ // gated on `!skip_mode && enable_jnt_comp`, matching libaom's
4600+ // `has_second_ref(mbmi) && !mbmi->skip_mode` outer guard plus
4601+ // `order_hint_info.enable_dist_wtd_comp` inner guard. The
4602+ // remaining 321/846 mismatched pixels do NOT fit `(9, 7)`
4603+ // either -- some blocks in this frame plausibly decode a
4604+ // genuinely different (correct, context-dependent) compound_idx
4605+ // than block (0,0)'s own -- so this is not simply "always wrong
4606+ // the same way": table/context/gate are all individually
4607+ // verified correct, yet the decoded VALUE at this specific
4608+ // symbol is wrong at least once in this frame. Not isolated
4609+ // further within budget. Upgrade: instrument `dec.symbol`'s own
4610+ // range/bit state (`rng`/`tell`, matching aomdec's own EC_PART
4611+ // trace fields) immediately before and after the `compound_idx`
4612+ // read specifically, not just the surrounding mode/mv/skip
4613+ // trace which does match -- the desync (if any) is local to
4614+ // this one read, not a wider stream desync.
4615+ //
4616+ // r5 (this round): the `resolve_interp_filter` call used to sit
4617+ // right here, ahead of `comp_group_idx`/`compound_idx` -- spec
4618+ // 5.11.19/libaom `decodemv.c:1575` reads `interp_filter` AFTER
4619+ // `read_compound_type`, not before, so that was a genuine
4620+ // ordering bug for a Switchable-filter frame (moved below, past
4621+ // the `compound_ctx = Some(...)` line). It does NOT explain this
4622+ // fixture's own mismatch, though: `av1blend-r1-mismatch.obu`'s
4623+ // header carries a *fixed* interpolation filter
4624+ // (`interp_fixed = Some(Regular)`, confirmed live via a
4625+ // one-off dump), so `resolve_interp_filter` never read a symbol
4626+ // in either position -- zero bits moved, decoded values
4627+ // unchanged before and after the reorder. Kept anyway: it is a
4628+ // real spec-order fix for the next Switchable-filter compound
4629+ // stream, independently correct regardless of this fixture.
4630+ //
4631+ // Also ruled out this round: comparing this crate's own
4632+ // `SymbolDecoder::debug_bitpos()` against aomdec's
4633+ // `aom_reader_tell()` at the block boundary is NOT a valid
4634+ // desync probe -- they are different quantities (raw consumed
4635+ // input bits vs. an entropy-cost estimate that advances without
4636+ // a literal byte fetch), so equal/unequal bitpos proves nothing
4637+ // either way. Do not repeat that comparison; instead trace
4638+ // `range`/`value` (this crate) against libaom's own internal
4639+ // `dif`/`rng` (needs new instrumentation in both) immediately
4640+ // after each read *upstream* of this one in the same block:
4641+ // `read_comp_mode`, `read_compound_ref_frames` (comp_ref_type/
4642+ // uni_comp_ref/comp_ref/comp_bwdref), `read_inter_compound_mode`,
4643+ // and the DRL loop. All of those independently decoded the SAME
4644+ // values this crate and aomdec both show (ref0=1, ref1=5, mode
4645+ // NEAREST_NEARESTMV, mv=(0,0)) -- but an upstream *context*
4646+ // miscomputation can still decode the identical symbol value off
4647+ // a slightly different CDF, narrowing `range` by a different
4648+ // amount than aomdec without changing the decoded value itself,
4649+ // and only surface as a wrong decode a few reads later exactly
4650+ // like this. `get_comp_index_context` and the `COMPOUND_IDX`
4651+ // table were independently re-verified again this round and are
4652+ // still correct; the four candidates above were not re-audited
4653+ // this round. Refusing here (rather than shipping a value-exact-
4654+ // most-of-the-time blend) until one of them is found wrong.
4655+ // r6/r7: found and fixed one real bug (mvstack.rs ref_ctx family
4656+ // undercounted compound neighbours in the single_ref_p*/comp_ref*/
4657+ // comp_bwdref* context reads -- kept, real fix). Unmasking on
4658+ // that fix alone and running the wide gate sweep (many seeds,
4659+ // `a_real_aomenc_stream_with_compound_references_decodes_pixel_exact`/
4660+ // `a_real_aomenc_stream_with_reference_select_reads_comp_mode_correctly`,
4661+ // cq-level=45) still mismatches roughly half the time, at
4662+ // different frames each run for the SAME seed -- aomenc's own
4663+ // cpu-used=0 RD search is run-to-run nondeterministic (noted
4664+ // above), so this is a second, still-unfound compound_idx defect,
4665+ // not the one r6/r7 fixed. r6's own residual-mismatch note (321/
4666+ // 846 pixels not fitting the (9,7)-vs-plain-average hypothesis
4667+ // either) already flagged more than one bug here. Re-masking:
4668+ // do not ship a blend that is right only sometimes.
44914669 return Err(unsupported(
4492- "a COMPOUND_REFERENCE block using the plain/distance-weighted \
4493- average blend (comp_group_idx == 0) -- proven non-pixel-exact \
4494- against a real aomenc stream (lane-av1comp r16, see \
4495- av1comp-r16-compound-mismatch.obu)",
4670+ "a COMPOUND_REFERENCE 16x16 leaf using the plain/distance-weighted \
4671+ average blend (comp_group_idx == 0) -- proven non-pixel-exact against \
4672+ real aomenc streams beyond the one bug lane-av1blend r6/r7 fixed \
4673+ (lane-av1blend r7, wide gate sweep)",
44964674 ));
44974675 #[allow(unreachable_code)]
44984676 let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp {
@@ -4505,7 +4683,25 @@ fn decode_inter_block(
45054683 ref_order_hints[(ref0 - LAST_FRAME) as usize],
45064684 ref_order_hints[(ref1 - LAST_FRAME) as usize],
45074685 );
4686+ if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {
4687+ let fidx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed);
4688+ eprintln!(
4689+ "COMPIDX_BLK fidx={fidx} mi_row={} mi_col={} ctx={idx_ctx} cdf0={} \
4690+ ref0={ref0} ref1={ref1}",
4691+ py / 4,
4692+ px / 4,
4693+ cdfs.compound_idx[idx_ctx][0]
4694+ );
4695+ }
45084696 let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]);
4697+ if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {
4698+ eprintln!(
4699+ "COMPIDX_VAL mi_row={} mi_col={} decoded={idx} bitpos={}",
4700+ py / 4,
4701+ px / 4,
4702+ dec.debug_bitpos()
4703+ );
4704+ }
45094705 if idx == 1 {
45104706 (8, 8, 1u8)
45114707 } else {
@@ -4522,6 +4718,31 @@ fn decode_inter_block(
45224718 };
45234719 compound_ctx = Some((ref1, comp_group_idx as u8, compound_idx));
45244720
4721+ // spec 5.11.19/libaom `decodemv.c` 1575: `read_mb_interp_filter`
4722+ // comes AFTER `read_compound_type` (the `comp_group_idx`/
4723+ // `compound_idx` reads just above), not before -- moved here
4724+ // (lane-av1blend r5) from its old position ahead of those reads,
4725+ // which stole their bits for a Switchable-filter compound block
4726+ // and desynced every symbol read after it in the tile.
4727+ if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {
4728+ eprintln!(
4729+ "IFILTER_PRE mi_row={} mi_col={} interp_fixed={:?} is_globalmv={is_globalmv}",
4730+ py / 4,
4731+ px / 4,
4732+ interp_fixed
4733+ );
4734+ }
4735+ let (h_filter, v_filter, resolved_filter) = resolve_interp_filter(
4736+ dec,
4737+ cdfs,
4738+ interp_fixed,
4739+ enable_dual_filter,
4740+ is_globalmv,
4741+ above_filter_ctx,
4742+ left_filter_ctx,
4743+ );
4744+ block_filter = resolved_filter;
4745+
45254746 let mut inter0_y = vec![0i32; side * side];
45264747 mc::predict_compound_intermediate(
45274748 &py0.data,
@@ -4553,6 +4774,20 @@ fn decode_inter_block(
45534774 let mut pred_y = vec![0u8; side * side];
45544775 mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y);
45554776
4777+ // r17 bisect scratch: dump per-block compound state when this
4778+ // block overlaps the pinned fixture's bad quadrant (frame 2,
4779+ // rows 32-63 cols 32-63). Remove with the rest of the scaffolding.
4780+ if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() {
4781+ let fidx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed);
4782+ eprintln!(
4783+ "leaf16 fidx={fidx} px={px} py={py} side={side} ref0={ref0} ref1={ref1} \
4784+ mv0={mv0:?} mv1={mv1:?} filter={resolved_filter:?} \
4785+ fwd={fwd_offset} bck={bck_offset} compound_idx={compound_idx} \
4786+ pred_y[0..4]={:?}",
4787+ &pred_y[0..4.min(pred_y.len())]
4788+ );
4789+ }
4790+
45564791 let mut inter0_u = vec![0i32; chroma_side * chroma_side];
45574792 mc::predict_compound_intermediate(
45584793 &pu0.data,
@@ -4684,7 +4919,14 @@ fn decode_inter_block(
46844919 }
46854920 } else {
46864921 let ref_frame =
4687- read_single_ref(dec, cdfs, neighbours.above_ref[c], neighbours.left_ref[r]);
4922+ read_single_ref(
4923+ dec,
4924+ cdfs,
4925+ neighbours.above_ref[c],
4926+ neighbours.above_ref1[c],
4927+ neighbours.left_ref[r],
4928+ neighbours.left_ref1[r],
4929+ );
46884930 ref_frame_for_lf = ref_frame;
46894931 // round 4-9 (lane-av1golden..lane-av1golden7): GOLDEN_FRAME's own
46904932 // stacked defects (lf_level ref/mode-delta forwarding, the
@@ -5327,16 +5569,22 @@ fn decode_inter_block8(
53275569 weighted/simple-average combine only, lane-av1comp",
53285570 ));
53295571 }
5330- // corner-cut (lane-av1comp r16/r17): same non-pixel-exact
5331- // plain-average reconstruction defect as the 16x16 leaf's
5332- // own mask above (r17: falsified as loop-filter-shaped,
5333- // isolated to predict_compound_intermediate/combine_compound
5334- // itself) -- see that comment.
5572+ // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): same
5573+ // reference-slot defect as the 16x16 leaf's own mask above
5574+ // (r1: falsified as an MC/blend math bug, isolated to a DPB
5575+ // slot/refresh_frame_flags issue around BWDREF_FRAME) -- see
5576+ // that comment.
5577+ // r3: same defect as the 16x16 leaf's own mask above -- see
5578+ // that comment (compound_idx's decoded value, not the blend
5579+ // math or reference-slot bookkeeping). r6/r7: same re-mask
5580+ // as the 16x16 leaf above -- one real bug found and fixed
5581+ // (mvstack.rs ref_ctx family), a second, still-unfound
5582+ // compound_idx defect surfaces on the wide gate sweep.
53355583 return Err(unsupported(
53365584 "a COMPOUND_REFERENCE 8x8 leaf using the plain/distance-weighted \
53375585 average blend (comp_group_idx == 0) -- proven non-pixel-exact \
5338- against a real aomenc stream (lane-av1comp r16, see \
5339- av1comp-r16-compound-mismatch.obu)",
5586+ against real aomenc streams beyond the one bug lane-av1blend \
5587+ r6/r7 fixed (lane-av1blend r7, wide gate sweep)",
53405588 ));
53415589 #[allow(unreachable_code)]
53425590 let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp {
@@ -5424,6 +5672,15 @@ fn decode_inter_block8(
54245672 let mut pred_y = vec![0u8; SIDE * SIDE];
54255673 mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y);
54265674
5675+ if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() {
5676+ let fidx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed);
5677+ eprintln!(
5678+ "leaf8 fidx={fidx} px={px} py={py} ref0={ref0} ref1={ref1} \
5679+ mv0={mv0:?} mv1={mv1:?} fwd={fwd_offset} bck={bck_offset} \
5680+ compound_idx={compound_idx} pred_y={pred_y:?}"
5681+ );
5682+ }
5683+
54275684 let mut inter0_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
54285685 mc::predict_compound_intermediate(
54295686 &pu0.data,
@@ -6105,6 +6362,14 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
61056362 let scan4 = default_scan(TX4);
61066363
61076364 let mut cdfs = initial_cdfs.unwrap_or_else(|| Cdfs::new(q_ctx_of(base_q_idx)));
6365+ if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {
6366+ let idx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed);
6367+ eprint!("COMPIDX_PRE fidx={} (aomdec fidx={})", idx, idx + 1);
6368+ for (c, row) in cdfs.compound_idx.iter().enumerate() {
6369+ eprint!(" ctx{c}={}", row[0]);
6370+ }
6371+ eprintln!();
6372+ }
61086373 let mut dec = SymbolDecoder::new(data);
61096374 let mut neighbours = Neighbours::new(
61106375 cols as usize * 2,
crates/ec-av1/src/mvstack.rsmodified+87 -29
@@ -1697,17 +1697,24 @@ pub(crate) const ALTREF_FRAME: i8 = 7;
16971697 /// `left_mbmi`) coded a reference in `a_set` vs. `b_set`, and compare: fewer
16981698 /// `a`s than `b`s is context 0, equal is 1 (also every unavailable-neighbour
16991699 /// case, both counts zero), more `a`s is 2.
1700-fn ref_ctx(above: Option<i8>, left: Option<i8>, a_set: &[i8], b_set: &[i8]) -> usize {
1701- let a = [above, left]
1702- .into_iter()
1703- .flatten()
1704- .filter(|r| a_set.contains(r))
1705- .count();
1706- let b = [above, left]
1707- .into_iter()
1708- .flatten()
1709- .filter(|r| b_set.contains(r))
1710- .count();
1700+// libaom `av1_collect_neighbors_ref_counts` (mvref_common.h): a neighbour
1701+// contributes ONE count per reference frame it actually names, which for a
1702+// compound neighbour is BOTH `ref_frame[0]` and `ref_frame[1]` -- not just
1703+// its first. Every one of these vote functions takes each side's pair
1704+// (`ref0` always, `ref1` only for a compound neighbour) so a compound
1705+// neighbour is not undercounted the way a single scalar per side would.
1706+#[allow(clippy::too_many_arguments)]
1707+fn ref_ctx(
1708+ above0: Option<i8>,
1709+ above1: Option<i8>,
1710+ left0: Option<i8>,
1711+ left1: Option<i8>,
1712+ a_set: &[i8],
1713+ b_set: &[i8],
1714+) -> usize {
1715+ let refs = [above0, above1, left0, left1];
1716+ let a = refs.into_iter().flatten().filter(|r| a_set.contains(r)).count();
1717+ let b = refs.into_iter().flatten().filter(|r| b_set.contains(r)).count();
17111718 match a.cmp(&b) {
17121719 std::cmp::Ordering::Less => 0,
17131720 std::cmp::Ordering::Equal => 1,
@@ -1719,22 +1726,46 @@ const FORWARD_REFS: [i8; 4] = [LAST_FRAME, LAST2_FRAME, LAST3_FRAME, GOLDEN_FRAM
17191726 const BACKWARD_REFS: [i8; 3] = [BWDREF_FRAME, ALTREF2_FRAME, ALTREF_FRAME];
17201727
17211728 /// `av1_get_pred_context_single_ref_p1`: forward vs. backward reference.
1722-pub(crate) fn single_ref_p1_ctx(above: Option<i8>, left: Option<i8>) -> usize {
1723- ref_ctx(above, left, &FORWARD_REFS, &BACKWARD_REFS)
1729+pub(crate) fn single_ref_p1_ctx(
1730+ above0: Option<i8>,
1731+ above1: Option<i8>,
1732+ left0: Option<i8>,
1733+ left1: Option<i8>,
1734+) -> usize {
1735+ ref_ctx(above0, above1, left0, left1, &FORWARD_REFS, &BACKWARD_REFS)
17241736 }
17251737
17261738 /// `av1_get_pred_context_single_ref_p2`
17271739 /// (`get_pred_context_brfarf2_or_arf`): `BWDREF`/`ALTREF2` vs. `ALTREF`.
1728-pub(crate) fn single_ref_p2_ctx(above: Option<i8>, left: Option<i8>) -> usize {
1729- ref_ctx(above, left, &[BWDREF_FRAME, ALTREF2_FRAME], &[ALTREF_FRAME])
1740+pub(crate) fn single_ref_p2_ctx(
1741+ above0: Option<i8>,
1742+ above1: Option<i8>,
1743+ left0: Option<i8>,
1744+ left1: Option<i8>,
1745+) -> usize {
1746+ ref_ctx(
1747+ above0,
1748+ above1,
1749+ left0,
1750+ left1,
1751+ &[BWDREF_FRAME, ALTREF2_FRAME],
1752+ &[ALTREF_FRAME],
1753+ )
17301754 }
17311755
17321756 /// `av1_get_pred_context_single_ref_p3`
17331757 /// (`get_pred_context_ll2_or_l3gld`): `LAST`/`LAST2` vs. `LAST3`/`GOLDEN`.
1734-pub(crate) fn single_ref_p3_ctx(above: Option<i8>, left: Option<i8>) -> usize {
1758+pub(crate) fn single_ref_p3_ctx(
1759+ above0: Option<i8>,
1760+ above1: Option<i8>,
1761+ left0: Option<i8>,
1762+ left1: Option<i8>,
1763+) -> usize {
17351764 ref_ctx(
1736- above,
1737- left,
1765+ above0,
1766+ above1,
1767+ left0,
1768+ left1,
17381769 &[LAST_FRAME, LAST2_FRAME],
17391770 &[LAST3_FRAME, GOLDEN_FRAME],
17401771 )
@@ -1742,27 +1773,54 @@ pub(crate) fn single_ref_p3_ctx(above: Option<i8>, left: Option<i8>) -> usize {
17421773
17431774 /// `av1_get_pred_context_single_ref_p4`
17441775 /// (`get_pred_context_last_or_last2`): `LAST` vs. `LAST2`.
1745-pub(crate) fn single_ref_p4_ctx(above: Option<i8>, left: Option<i8>) -> usize {
1746- ref_ctx(above, left, &[LAST_FRAME], &[LAST2_FRAME])
1776+pub(crate) fn single_ref_p4_ctx(
1777+ above0: Option<i8>,
1778+ above1: Option<i8>,
1779+ left0: Option<i8>,
1780+ left1: Option<i8>,
1781+) -> usize {
1782+ ref_ctx(above0, above1, left0, left1, &[LAST_FRAME], &[LAST2_FRAME])
17471783 }
17481784
17491785 /// `av1_get_pred_context_single_ref_p5`
17501786 /// (`get_pred_context_last3_or_gld`): `LAST3` vs. `GOLDEN`.
1751-pub(crate) fn single_ref_p5_ctx(above: Option<i8>, left: Option<i8>) -> usize {
1752- ref_ctx(above, left, &[LAST3_FRAME], &[GOLDEN_FRAME])
1787+pub(crate) fn single_ref_p5_ctx(
1788+ above0: Option<i8>,
1789+ above1: Option<i8>,
1790+ left0: Option<i8>,
1791+ left1: Option<i8>,
1792+) -> usize {
1793+ ref_ctx(above0, above1, left0, left1, &[LAST3_FRAME], &[GOLDEN_FRAME])
17531794 }
17541795
17551796 /// `av1_get_pred_context_single_ref_p6`
17561797 /// (`get_pred_context_brf_or_arf2`): `BWDREF` vs. `ALTREF2`.
1757-pub(crate) fn single_ref_p6_ctx(above: Option<i8>, left: Option<i8>) -> usize {
1758- ref_ctx(above, left, &[BWDREF_FRAME], &[ALTREF2_FRAME])
1798+pub(crate) fn single_ref_p6_ctx(
1799+ above0: Option<i8>,
1800+ above1: Option<i8>,
1801+ left0: Option<i8>,
1802+ left1: Option<i8>,
1803+) -> usize {
1804+ ref_ctx(above0, above1, left0, left1, &[BWDREF_FRAME], &[ALTREF2_FRAME])
17591805 }
17601806
17611807 /// `av1_get_pred_context_uni_comp_ref_p1`: `LAST2` vs. `LAST3`/`GOLDEN`,
17621808 /// conditioned on a unidirectional pair known to be one of the three
17631809 /// `LAST`-anchored ones (lane-av1comp).
1764-pub(crate) fn uni_comp_ref_p1_ctx(above: Option<i8>, left: Option<i8>) -> usize {
1765- ref_ctx(above, left, &[LAST2_FRAME], &[LAST3_FRAME, GOLDEN_FRAME])
1810+pub(crate) fn uni_comp_ref_p1_ctx(
1811+ above0: Option<i8>,
1812+ above1: Option<i8>,
1813+ left0: Option<i8>,
1814+ left1: Option<i8>,
1815+) -> usize {
1816+ ref_ctx(
1817+ above0,
1818+ above1,
1819+ left0,
1820+ left1,
1821+ &[LAST2_FRAME],
1822+ &[LAST3_FRAME, GOLDEN_FRAME],
1823+ )
17661824 }
17671825
17681826 /// One neighbouring block's reference-frame shape, as
@@ -2369,9 +2427,9 @@ mod tests {
23692427 /// convention).
23702428 #[test]
23712429 fn uni_comp_ref_p1_ctx_matches_ref_ctx_shape() {
2372- assert_eq!(uni_comp_ref_p1_ctx(Some(LAST2_FRAME), None), 2);
2373- assert_eq!(uni_comp_ref_p1_ctx(Some(LAST3_FRAME), None), 0);
2374- assert_eq!(uni_comp_ref_p1_ctx(None, None), 1);
2430+ assert_eq!(uni_comp_ref_p1_ctx(Some(LAST2_FRAME), None, None, None), 2);
2431+ assert_eq!(uni_comp_ref_p1_ctx(Some(LAST3_FRAME), None, None, None), 0);
2432+ assert_eq!(uni_comp_ref_p1_ctx(None, None, None, None), 1);
23752433 }
23762434
23772435 // --- lane-av1comp step 4: compound mvstack (find_mv_stack_compound) ---
crates/ec-av1/src/stream.rsmodified+144 -4
@@ -74,6 +74,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
7474 let mut cdf_slots: [Option<Cdfs>; NUM_REF_FRAMES] = std::array::from_fn(|_| None);
7575
7676 let mut pos = 0usize;
77+ let mut decode_idx = 0u32;
7778 while pos < data.len() {
7879 let obu = parser.parse_obu(&data[pos..])?;
7980 let obu_offset = pos;
@@ -114,6 +115,12 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
114115 picture
115116 };
116117 pictures.push(output);
118+ if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() {
119+ eprintln!(
120+ "PUSH (show_existing_frame slot {slot}) pictures.len()={}",
121+ pictures.len()
122+ );
123+ }
117124 continue;
118125 }
119126 let ObuKind::Frame(header, tiles) = obu.kind else {
@@ -288,6 +295,19 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
288295 let ref_order_hints: [u32; 7] =
289296 std::array::from_fn(|i| order_hint_slots[header.ref_frame_idx[i] as usize]);
290297
298+ if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() {
299+ eprintln!(
300+ "FRAME decode_idx={decode_idx} type={:?} show={} order_hint={} refresh_frame_flags={:#04x} ref_frame_idx={:?} order_hint_slots={:?}",
301+ header.frame_type,
302+ header.show_frame,
303+ header.order_hint,
304+ header.refresh_frame_flags,
305+ header.ref_frame_idx,
306+ order_hint_slots,
307+ );
308+ }
309+ decode_idx += 1;
310+
291311 let (picture, end_cdfs, motion_field) = if header.frame_type == FrameType::Key {
292312 let (picture, end_cdfs) = decode_key_frame_tile_with_cdfs(
293313 tile_bytes,
@@ -434,6 +454,18 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
434454 picture
435455 };
436456 pictures.push(output);
457+ if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() {
458+ eprintln!(
459+ "PUSH (shown-direct) pictures.len()={} <- decode.rs r17 fidx {}",
460+ pictures.len(),
461+ crate::decode::r17_dump_frame_idx()
462+ );
463+ }
464+ } else if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() {
465+ eprintln!(
466+ "HIDDEN frame decoded, not pushed <- decode.rs r17 fidx {}",
467+ crate::decode::r17_dump_frame_idx()
468+ );
437469 }
438470 }
439471 Ok(pictures)
@@ -725,9 +757,9 @@ mod tests {
725757 // constructing the (module-private) `Neighbours` itself.
726758 const PARTITION_NONE: usize = 0;
727759 let ii_ctx = intra_inter_ctx(false, false, false, false);
728- let sr_p1_ctx = single_ref_p1_ctx(None, None);
729- let sr_p3_ctx = single_ref_p3_ctx(None, None);
730- let sr_p5_ctx = single_ref_p5_ctx(None, None);
760+ let sr_p1_ctx = single_ref_p1_ctx(None, None, None, None);
761+ let sr_p3_ctx = single_ref_p3_ctx(None, None, None, None);
762+ let sr_p5_ctx = single_ref_p5_ctx(None, None, None, None);
731763
732764 for run in 0..4 {
733765 let picture = test_card(width, height);
@@ -2663,7 +2695,12 @@ mod tests {
26632695 // capability gap tracked on its own (not a
26642696 // COMPOUND_REFERENCE defect); accept it here too
26652697 // rather than fail a compound-specific gate on a
2666- // partition-search coincidence.
2698+ // partition-search coincidence. lane-av1blend r7:
2699+ // re-swept the wide gate with the plain-average
2700+ // blend unmasked (r6/r7's ref_ctx fix alone) and it
2701+ // still mismatches on real streams beyond that one
2702+ // bug -- re-masked comp_group_idx == 0 too, so this
2703+ // stays a legal named refusal.
26672704 assert!(
26682705 msg.contains("COMPOUND_REFERENCE") || msg.contains("a partition"),
26692706 "{NAME}: comp_mode fired (seed {seed}) but the refusal \
@@ -3289,6 +3326,109 @@ mod tests {
32893326 }
32903327 }
32913328
3329+ /// lane-av1blend r4 scratch: decodes the pinned `av1blend-r1-mismatch.obu`
3330+ /// (seed 45) with `EC_AV1_COMPIDX_DUMP` set, to compare the pre-tile-decode
3331+ /// `compound_idx` CDF state of every frame against an instrumented
3332+ /// aomdec's own `COMPIDX_PRE` dump. Errors out at decode-order frame 3
3333+ /// (the still-masked compound path) -- that is expected, the dump lines
3334+ /// before the error are what this test is for. Remove with the rest of
3335+ /// the r1-r4 scaffolding.
3336+ #[test]
3337+ #[ignore]
3338+ fn scratch_dump_compound_idx_cdf_state() {
3339+ let path = concat!(
3340+ env!("CARGO_MANIFEST_DIR"),
3341+ "/../../fixtures/av1blend-r1-mismatch.obu"
3342+ );
3343+ let stream = std::fs::read(path).expect("reading pinned stream");
3344+ let _ = decode_stream(&stream);
3345+ }
3346+
3347+ /// lane-av1blend r2 scratch: sweep every seed of the compound_references
3348+ /// recipe (with the plain-average blend UNMASKED locally) looking for a
3349+ /// pixel mismatch, dumping the first one found to `EC_AV1_GATE_DUMP`.
3350+ /// Remove with the rest of the r1/r2 scaffolding.
3351+ #[test]
3352+ #[ignore]
3353+ fn scratch_sweep_compound_mismatch() {
3354+ if !have_ffmpeg() || !have_aomenc() {
3355+ eprintln!("SKIP: missing ffmpeg/aomenc");
3356+ return;
3357+ }
3358+ let (width, height, frame_count) = (64usize, 64usize, 24usize);
3359+ for seed in 42..82u32 {
3360+ let duration = frame_count as f64 / 25.0;
3361+ let source =
3362+ format!("gradients=size={width}x{height}:seed={seed}:duration={duration}:rate=25");
3363+ let y4m = Command::new("ffmpeg")
3364+ .args([
3365+ "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f",
3366+ "yuv4mpegpipe", "-",
3367+ ])
3368+ .stdin(Stdio::null())
3369+ .stdout(Stdio::piped())
3370+ .stderr(Stdio::piped())
3371+ .output()
3372+ .expect("ffmpeg failed to run");
3373+ assert!(y4m.status.success());
3374+ let args: Vec<&str> = vec![
3375+ "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=45", "--cpu-used=0",
3376+ "--kf-max-dist=1000", "--threads=1", "--row-mt=0", "--auto-alt-ref=1",
3377+ "--lag-in-frames=16", "--enable-fwd-kf=0", "--enable-order-hint=1",
3378+ "--enable-warped-motion=0", "--enable-obmc=0", "--enable-masked-comp=0",
3379+ "--enable-interintra-comp=0", "--enable-onesided-comp=0",
3380+ "--enable-interintra-wedge=0", "--enable-smooth-interintra=0",
3381+ "--enable-rect-partitions=0", "--enable-ab-partitions=0",
3382+ "--enable-1to4-partitions=0", "--enable-filter-intra=0",
3383+ "--enable-smooth-intra=0", "--enable-paeth-intra=0",
3384+ "--enable-directional-intra=0", "--enable-angle-delta=0",
3385+ "--enable-tx-size-search=0", "--enable-cdef=0", "--enable-restoration=0",
3386+ "--max-partition-size=32", "--min-partition-size=32", "--enable-palette=0",
3387+ "--enable-intrabc=0", "--enable-cfl-intra=0", "--enable-ref-frame-mvs=0",
3388+ "--obu", "-o", "-", "-",
3389+ ];
3390+ let mut child = Command::new(aomenc_path())
3391+ .args(&args)
3392+ .stdin(Stdio::piped())
3393+ .stdout(Stdio::piped())
3394+ .stderr(Stdio::piped())
3395+ .spawn()
3396+ .expect("aomenc failed to start");
3397+ child
3398+ .stdin
3399+ .take()
3400+ .expect("aomenc stdin")
3401+ .write_all(&y4m.stdout)
3402+ .expect("writing y4m to aomenc");
3403+ let out = child.wait_with_output().expect("aomenc failed to run");
3404+ assert!(out.status.success());
3405+ let stream = out.stdout;
3406+ let frames = match decode_stream(&stream) {
3407+ Err(_) => continue,
3408+ Ok(frames) => frames,
3409+ };
3410+ if frames.len() != frame_count {
3411+ continue;
3412+ }
3413+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
3414+ let mismatched = frames
3415+ .iter()
3416+ .zip(&ffmpeg_frames)
3417+ .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
3418+ if mismatched {
3419+ eprintln!("MISMATCH seed {seed}");
3420+ if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
3421+ std::fs::write(&path, &stream).expect("writing pinned stream");
3422+ eprintln!("wrote {path}");
3423+ }
3424+ return;
3425+ } else {
3426+ eprintln!("seed {seed}: bit-exact");
3427+ }
3428+ }
3429+ eprintln!("no mismatch found in sweep");
3430+ }
3431+
32923432 /// Final round of the TX4/tx-class lane's own gate: `--min-partition-size=8
32933433 /// --max-partition-size=8` pins every leaf to exactly 8x8 (spec
32943434 /// 5.11.4's own boundary carve-out aside, which a multiple-of-8 frame