The saved motion field stored a compound block's FIRST reference, not its second
Browse files at this commit72cffab7e4c77de92d91a5d880f583f2ba042dafParent: 115cb3a- fix
- the saved motion field stored a compound block's FIRST reference, not its second
4 changed files +338 -13
- crates/ec-av1/src/decode.rs +71 -12
- crates/ec-av1/src/motion_field.rs +11 -1
- crates/ec-av1/src/stream.rs +138 -0
- lanes/interbis-r1.report.md +118 -0
crates/ec-av1/src/decode.rsmodified+71 -12
| @@ -1730,24 +1730,61 @@ pub(crate) fn build_motion_field( | ||
| 1730 | 1730 | mi_cols: usize, |
| 1731 | 1731 | mi_rows: usize, |
| 1732 | 1732 | order_hint: u32, |
| 1733 | + order_hint_bits: u32, | |
| 1733 | 1734 | ref_order_hints: [u32; 7], |
| 1734 | 1735 | ) -> crate::motion_field::MotionField { |
| 1735 | 1736 | let mut field = |
| 1736 | 1737 | crate::motion_field::MotionField::new(mi_cols, mi_rows, order_hint, ref_order_hints); |
| 1738 | + // lane-interbis r1: libaom `av1_calculate_ref_frame_side` -- a reference | |
| 1739 | + // whose OrderHint is AHEAD of (or equal to) this frame's is "on the other | |
| 1740 | + // side", and `av1_copy_frame_mvs` skips it entirely, so a compound block | |
| 1741 | + // referencing one stores only its OTHER side's mv. With | |
| 1742 | + // `enable_order_hint` off (`order_hint_bits == 0`) every side is 0 and | |
| 1743 | + // nothing is skipped. | |
| 1744 | + let other_side = |rf: i8| -> bool { | |
| 1745 | + if order_hint_bits == 0 { | |
| 1746 | + return false; | |
| 1747 | + } | |
| 1748 | + let oh = ref_order_hints[(rf - LAST_FRAME) as usize]; | |
| 1749 | + crate::motion_field::get_relative_dist(order_hint_bits, oh, order_hint) > 0 | |
| 1750 | + || oh == order_hint | |
| 1751 | + }; | |
| 1752 | + // libaom `REFMVS_LIMIT` (`mvref_common.h`): a stored motion field mv is | |
| 1753 | + // capped at 12 bits per component; a longer one is not stored at all. | |
| 1754 | + const REFMVS_LIMIT: i32 = (1 << 12) - 1; | |
| 1737 | 1755 | for row in 0..mi_rows { |
| 1738 | 1756 | for col in 0..mi_cols { |
| 1739 | - if let Some(info) = grid.get(row, col) | |
| 1740 | - && info.is_inter | |
| 1741 | - && info.ref_frame > 0 | |
| 1742 | - { | |
| 1743 | - field.set( | |
| 1744 | - row, | |
| 1745 | - col, | |
| 1746 | - crate::motion_field::SavedMv { | |
| 1747 | - mv: info.mv, | |
| 1748 | - ref_frame: info.ref_frame, | |
| 1749 | - }, | |
| 1750 | - ); | |
| 1757 | + let Some(info) = grid.get(row, col) else { | |
| 1758 | + continue; | |
| 1759 | + }; | |
| 1760 | + if !info.is_inter { | |
| 1761 | + continue; | |
| 1762 | + } | |
| 1763 | + // `av1_copy_frame_mvs` walks BOTH reference slots and the LAST | |
| 1764 | + // qualifying one wins -- a compound block stores its second | |
| 1765 | + // reference's mv, never its first (unless the second is on the | |
| 1766 | + // other side or over the limit). Storing slot 0 unconditionally | |
| 1767 | + // put the wrong (mv, ref_frame_offset) pair in every compound | |
| 1768 | + // block's cell, which a later frame's temporal candidate then | |
| 1769 | + // projected with the wrong reference distance. | |
| 1770 | + let mut saved: Option<crate::motion_field::SavedMv> = None; | |
| 1771 | + for (rf, mv) in [ | |
| 1772 | + (info.ref_frame, Some(info.mv)), | |
| 1773 | + (info.ref_frame1.unwrap_or(0), info.mv1), | |
| 1774 | + ] { | |
| 1775 | + let (Some(mv), true) = (mv, rf > 0) else { | |
| 1776 | + continue; | |
| 1777 | + }; | |
| 1778 | + if other_side(rf) { | |
| 1779 | + continue; | |
| 1780 | + } | |
| 1781 | + if mv.0.abs() > REFMVS_LIMIT || mv.1.abs() > REFMVS_LIMIT { | |
| 1782 | + continue; | |
| 1783 | + } | |
| 1784 | + saved = Some(crate::motion_field::SavedMv { mv, ref_frame: rf }); | |
| 1785 | + } | |
| 1786 | + if let Some(saved) = saved { | |
| 1787 | + field.set(row, col, saved); | |
| 1751 | 1788 | } |
| 1752 | 1789 | } |
| 1753 | 1790 | } |
| @@ -14412,6 +14449,10 @@ fn decode_inter_block( | ||
| 14412 | 14449 | ); |
| 14413 | 14450 | let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1; |
| 14414 | 14451 | let mut is_globalmv = false; |
| 14452 | + // lane-interbis r1: which single-ref mode this block resolved to, | |
| 14453 | + // in the oracle's own numbering (NEARESTMV=13 .. NEWMV=16), for | |
| 14454 | + // the `EC_MODE_VAL` value ladder below. | |
| 14455 | + let mut dbg_mode = 16u32; | |
| 14415 | 14456 | let (mv, is_new_mv) = if !not_new { |
| 14416 | 14457 | // NEWMV (spec 5.11.24's `read_drl_idx`, `RefMvIdx` starting at 0): |
| 14417 | 14458 | // read at most two `drl_mode` bits, one per stack entry past the |
| @@ -14444,9 +14485,11 @@ fn decode_inter_block( | ||
| 14444 | 14485 | let mv = if !not_zero { |
| 14445 | 14486 | // GLOBALMV: `gm_get_motion_vector` (spec 7.10.2.1), already |
| 14446 | 14487 | // computed at this block's own position in `gm_table`. |
| 14488 | + dbg_mode = 15; | |
| 14447 | 14489 | gm_table[(ref_frame - LAST_FRAME) as usize] |
| 14448 | 14490 | } else { |
| 14449 | 14491 | let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0; |
| 14492 | + dbg_mode = if nearest { 13 } else { 14 }; | |
| 14450 | 14493 | if nearest { |
| 14451 | 14494 | stack.nearest_mv |
| 14452 | 14495 | } else { |
| @@ -14468,6 +14511,21 @@ fn decode_inter_block( | ||
| 14468 | 14511 | }; |
| 14469 | 14512 | (mv, false) |
| 14470 | 14513 | }; |
| 14514 | + if std::env::var_os("EC_TRACE_MODE").is_some() { | |
| 14515 | + for (i, e) in stack.entries.iter().enumerate() { | |
| 14516 | + eprintln!( | |
| 14517 | + "EC_STACK mi_row={mi_row} mi_col={mi_col} ref={ref_frame} i={i} this=({},{}) comp=(0,0) w={}", | |
| 14518 | + e.mv.0, e.mv.1, e.weight | |
| 14519 | + ); | |
| 14520 | + } | |
| 14521 | + eprintln!( | |
| 14522 | + "EC_MODE_VAL mi_row={mi_row} mi_col={mi_col} mode={dbg_mode} ref0={ref_frame} ref1=-1 mv0=({},{}) stack={} rng={}", | |
| 14523 | + mv.0, | |
| 14524 | + mv.1, | |
| 14525 | + stack.entries.len(), | |
| 14526 | + dec.debug_state().0 | |
| 14527 | + ); | |
| 14528 | + } | |
| 14471 | 14529 | // lane-gm r2: the two libaom predicates single-ref GLOBALMV |
| 14472 | 14530 | // blocks need -- `is_global_mv_block` (blockd.h:421-429, mode |
| 14473 | 14531 | // GLOBAL* AND model > TRANSLATION AND min(bw,bh) >= 8px, gating |
| @@ -18985,6 +19043,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 18985 | 19043 | mi_cols as usize, |
| 18986 | 19044 | mi_rows as usize, |
| 18987 | 19045 | order_hint, |
| 19046 | + order_hint_bits, | |
| 18988 | 19047 | ref_order_hints, |
| 18989 | 19048 | ); |
| 18990 | 19049 |
crates/ec-av1/src/motion_field.rsmodified+11 -1
| @@ -420,7 +420,17 @@ pub fn add_tpl_ref_mv( | ||
| 420 | 420 | if row8 < 0 || col8 < 0 { |
| 421 | 421 | return None; |
| 422 | 422 | } |
| 423 | - let (fwd_mv, ref_frame_offset) = tpl.get(row8 as usize / 2, col8 as usize / 2)?; | |
| 423 | + let probe = tpl.get(row8 as usize / 2, col8 as usize / 2); | |
| 424 | + if std::env::var_os("EC_TRACE_TPL").is_some() { | |
| 425 | + match probe { | |
| 426 | + None => eprintln!("EC_TPL mi_row={mi_row} mi_col={mi_col} blk=({blk_row},{blk_col}) INVALID"), | |
| 427 | + Some((m, rfo)) => eprintln!( | |
| 428 | + "EC_TPL mi_row={mi_row} mi_col={mi_col} blk=({blk_row},{blk_col}) mfmv0=({},{}) rfo={rfo}", | |
| 429 | + m.0, m.1 | |
| 430 | + ), | |
| 431 | + } | |
| 432 | + } | |
| 433 | + let (fwd_mv, ref_frame_offset) = probe?; | |
| 424 | 434 | let projected = get_mv_projection(fwd_mv, cur_offset_0, ref_frame_offset); |
| 425 | 435 | let mv = lower_mv_precision(projected, allow_high_precision_mv); |
| 426 | 436 | Some(TplCandidate { mv }) |
crates/ec-av1/src/stream.rsmodified+138 -0
| @@ -4739,6 +4739,144 @@ mod tests { | ||
| 4739 | 4739 | /// 8-bit AND 10-bit. Every decoded frame is compared to ffmpeg on Y, U and |
| 4740 | 4740 | /// V; a refusal is counted, never SKIPped; an attempt that carried no rect |
| 4741 | 4741 | /// inter residual is counted separately and still required pixel-exact. |
| 4742 | + /// Temporal (MFMV) motion-vector candidates, on a real aomenc stream | |
| 4743 | + /// whose compound blocks feed the next frame's motion field | |
| 4744 | + /// (`av1_copy_frame_mvs` -> `av1_setup_motion_field` -> `add_tpl_ref_mv`). | |
| 4745 | + /// | |
| 4746 | + /// lane-interbis r1 pinned this recipe because it is the one the rect | |
| 4747 | + /// gate's attempt 1 decoded FULLY and still mismatched ffmpeg (a | |
| 4748 | + /// 32x32 NEARESTMV block at mi (24, 40) of decode-order frame 5 took its | |
| 4749 | + /// nearest candidate from a temporal cell holding the wrong reference: | |
| 4750 | + /// `build_motion_field` stored a compound block's FIRST reference where | |
| 4751 | + /// libaom stores its second). Every fully decoded attempt is compared | |
| 4752 | + /// plane by plane; a refusal is counted, never SKIPped; the temporal | |
| 4753 | + /// candidate counter must fire on a compared attempt, or the gate proves | |
| 4754 | + /// nothing. | |
| 4755 | + #[test] | |
| 4756 | + fn a_real_aomenc_inter_sequence_with_temporal_mv_candidates_decodes_pixel_exact() { | |
| 4757 | + const NAME: &str = | |
| 4758 | + "a_real_aomenc_inter_sequence_with_temporal_mv_candidates_decodes_pixel_exact"; | |
| 4759 | + let _gate_lock = lock_gate_counters(); | |
| 4760 | + if !have_ffmpeg() { | |
| 4761 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 4762 | + return; | |
| 4763 | + } | |
| 4764 | + if !have_aomenc() { | |
| 4765 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | |
| 4766 | + return; | |
| 4767 | + } | |
| 4768 | + let (width, height, frame_count) = (192usize, 128usize, 6usize); | |
| 4769 | + for bit_depth in [8u32, 10u32] { | |
| 4770 | + let (mut named_refusals, mut compared, mut tmv_proved) = (0u32, 0u32, 0usize); | |
| 4771 | + for attempt in 0..2u32 { | |
| 4772 | + let tx_search = if attempt == 0 { "0" } else { "1" }; | |
| 4773 | + let duration = frame_count as f64 / 25.0; | |
| 4774 | + // The pinned source: horizontal structure translating along X | |
| 4775 | + // at 3 px/frame, which makes aomenc code compound LAST+GOLDEN | |
| 4776 | + // blocks whose stored motion field the last frame reads back. | |
| 4777 | + let source = format!( | |
| 4778 | + "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ | |
| 4779 | + geq=lum='128+58*sin((X+N*3)/6)+18*sin(Y/23)',format=yuv420p" | |
| 4780 | + ); | |
| 4781 | + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; | |
| 4782 | + let y4m = Command::new("ffmpeg") | |
| 4783 | + .args([ | |
| 4784 | + "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), | |
| 4785 | + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", | |
| 4786 | + ]) | |
| 4787 | + .stdin(Stdio::null()) | |
| 4788 | + .stdout(Stdio::piped()) | |
| 4789 | + .stderr(Stdio::piped()) | |
| 4790 | + .output() | |
| 4791 | + .expect("ffmpeg failed to run"); | |
| 4792 | + assert!( | |
| 4793 | + y4m.status.success(), | |
| 4794 | + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", | |
| 4795 | + String::from_utf8_lossy(&y4m.stderr) | |
| 4796 | + ); | |
| 4797 | + let depth_arg = format!("--bit-depth={bit_depth}"); | |
| 4798 | + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | |
| 4799 | + let tx_arg = format!("--enable-tx-size-search={tx_search}"); | |
| 4800 | + let args: Vec<&str> = vec![ | |
| 4801 | + "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=34", "--cpu-used=0", | |
| 4802 | + "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, | |
| 4803 | + "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", | |
| 4804 | + "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", | |
| 4805 | + "--lag-in-frames=0", | |
| 4806 | + // Per-arm overrides go LAST (aomenc keeps the last | |
| 4807 | + // occurrence of a repeated --enable-* flag). | |
| 4808 | + &tx_arg, | |
| 4809 | + "--enable-rect-partitions=1", "--enable-ab-partitions=0", | |
| 4810 | + "--enable-1to4-partitions=0", "--min-partition-size=16", | |
| 4811 | + "--max-partition-size=32", | |
| 4812 | + "--obu", "-o", "-", "-", | |
| 4813 | + ]; | |
| 4814 | + let mut child = Command::new(aomenc_path()) | |
| 4815 | + .args(&args) | |
| 4816 | + .stdin(Stdio::piped()) | |
| 4817 | + .stdout(Stdio::piped()) | |
| 4818 | + .stderr(Stdio::piped()) | |
| 4819 | + .spawn() | |
| 4820 | + .expect("aomenc failed to start"); | |
| 4821 | + child | |
| 4822 | + .stdin | |
| 4823 | + .take() | |
| 4824 | + .expect("aomenc stdin") | |
| 4825 | + .write_all(&y4m.stdout) | |
| 4826 | + .expect("writing y4m to aomenc"); | |
| 4827 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 4828 | + assert!( | |
| 4829 | + out.status.success(), | |
| 4830 | + "aomenc refused the fixture: {}", | |
| 4831 | + String::from_utf8_lossy(&out.stderr) | |
| 4832 | + ); | |
| 4833 | + let stream = out.stdout; | |
| 4834 | + let before = decode::tmv_hits(); | |
| 4835 | + let frames = match decode_stream(&stream) { | |
| 4836 | + Err(e) => { | |
| 4837 | + let msg = e.to_string(); | |
| 4838 | + assert!( | |
| 4839 | + msg.contains("unsupported"), | |
| 4840 | + "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \ | |
| 4841 | + attempt {attempt}): {msg}" | |
| 4842 | + ); | |
| 4843 | + named_refusals += 1; | |
| 4844 | + eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}"); | |
| 4845 | + continue; | |
| 4846 | + } | |
| 4847 | + Ok(frames) => frames, | |
| 4848 | + }; | |
| 4849 | + let tmv = decode::tmv_hits() - before; | |
| 4850 | + let ffmpeg_frames = if bit_depth == 10 { | |
| 4851 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | |
| 4852 | + } else { | |
| 4853 | + ffmpeg_decode_sequence(&stream, width, height, frame_count) | |
| 4854 | + }; | |
| 4855 | + assert_eq!(frames.len(), frame_count); | |
| 4856 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | |
| 4857 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); | |
| 4858 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); | |
| 4859 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); | |
| 4860 | + } | |
| 4861 | + compared += 1; | |
| 4862 | + tmv_proved += tmv; | |
| 4863 | + } | |
| 4864 | + eprintln!( | |
| 4865 | + "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {compared} \ | |
| 4866 | + pixel-exact attempts, blocks with a temporal MV candidate={tmv_proved}" | |
| 4867 | + ); | |
| 4868 | + assert!( | |
| 4869 | + compared > 0, | |
| 4870 | + "{NAME} ({bit_depth}-bit): every attempt refused -- gate proved nothing" | |
| 4871 | + ); | |
| 4872 | + assert!( | |
| 4873 | + tmv_proved > 0, | |
| 4874 | + "{NAME} ({bit_depth}-bit): no compared attempt ever folded a temporal MV \ | |
| 4875 | + candidate into a block's stack -- gate proved nothing" | |
| 4876 | + ); | |
| 4877 | + } | |
| 4878 | + } | |
| 4879 | + | |
| 4742 | 4880 | #[test] |
| 4743 | 4881 | // lane-inter4 r2: RED, kept (not weakened, not deleted) -- the rect inter |
| 4744 | 4882 | // residual path IS implemented and reached, but no aomenc recipe swept |
lanes/interbis-r1.report.mdadded+118 -0
| @@ -0,0 +1,118 @@ | ||
| 1 | +# lane-interbis r1 — the "decodes fully, still mismatches" inter defect | |
| 2 | + | |
| 3 | +Branch `lane-interbis`, worktree `edith_codecs-interbis`, off lane-inter4 `d2d7327`. | |
| 4 | +No rebase (main unchanged since that base). | |
| 5 | + | |
| 6 | +## STEP 1 — reproduced and pinned | |
| 7 | + | |
| 8 | +The rect gate's 8-bit **attempt 1** is the one that decodes fully and mismatches: | |
| 9 | +192x128, 6 frames @25, `geq=lum='128+58*sin((X+N*3)/6)+18*sin(Y/23)'`, cq 34, | |
| 10 | +`--enable-tx-size-search=1`, `--min/max-partition-size=16/32`, cpu-used=0, lag 0. | |
| 11 | +Regenerated twice, byte-identical: | |
| 12 | +`fa70b7f68d311e577e3d14a86574909e6e58cac817b5a7fae04341c41ff50260` | |
| 13 | +(script `$HOME/.cache/interbis/gen.sh`; 10-bit twin | |
| 14 | +`67cad9bd5341db897de8a5308faecaedb1b0df761e4f315f1817156d124caef7`). | |
| 15 | + | |
| 16 | +Decode order == display order (no hidden frames; `--lag-in-frames=0`). | |
| 17 | +Frames 0..4 exact; **frame 5** luma only, 646 px, bbox x160-191 y93-127, max delta 39. | |
| 18 | +`EC_AV1_PREFILT_DUMP` (ours) vs the same rung from the instrumented aomdec: | |
| 19 | +frames 0-4 byte-identical, frame 5 differs in 640 luma px at x160-191 y96-127 — | |
| 20 | +i.e. **reconstruction**, not deblock/CDEF/LR, and exactly one 32x32 block: | |
| 21 | +mi (row 24, col 40), the frame's last block. | |
| 22 | + | |
| 23 | +EVIDENCE: $HOME/.cache/interbis/{o_pre.f5,a_pre.f5} | EC_AV1_PREFILT_DUMP ours vs aomdec, per-frame byte diff | frames 0-4 identical, frame 5 640 luma px wrong in the single 32x32 block at mi(24,40) | |
| 24 | + | |
| 25 | +## STEP 2 — first divergent element | |
| 26 | + | |
| 27 | +Entropy is **exact**: the msac range ladder agrees at that block's entry | |
| 28 | +(`EC_MODE ... rng=37852` both) and at the end of its mode read | |
| 29 | +(`rng=59818` both). Both decoders read mode 13 (NEARESTMV), ref0=2 (LAST2), | |
| 30 | +stack size 3. The **VALUE** differs: | |
| 31 | + | |
| 32 | + ours EC_MODE_VAL mi_row=24 mi_col=40 mode=13 ref0=2 mv0=(0,72) | |
| 33 | + aomdec EC_MODE_VAL mi_row=24 mi_col=40 mode=13 ref0=2 mv0=(0,-230) | |
| 34 | + | |
| 35 | +New `EC_STACK` rung (added to both decoders) shows entries 1 and 2 identical | |
| 36 | +(`(0,24) w=2`, `(0,-785) w=2`, the extra-search neighbours) and entry 0 — | |
| 37 | +the temporal (MFMV) candidate — wrong: ours `(0,72) w=32`, aomdec `(0,-230) w=16`. | |
| 38 | + | |
| 39 | +New `EC_TPL` rung (per `add_tpl_ref_mv` probe, both decoders) isolates it to the | |
| 40 | +projected motion field itself: over the 16 probes of that block, aomdec reads | |
| 41 | +`INVALID` at blk_col 0/2 and `mfmv0=(0,-230) rfo=3` at blk_col 4/6; ours reads | |
| 42 | +`mfmv0=(0,24) rfo=1` at all 16. `(0,24)*3/1 = (0,72)` — our wrong stored pair | |
| 43 | +projected exactly to the wrong candidate. | |
| 44 | + | |
| 45 | +EVIDENCE: $HOME/.cache/interbis/{o_tpl.txt,a_tpl.txt} | EC_TRACE_MODE + EC_TRACE_TPL on both decoders, block mi(24,40) of frame 5 | ours mfmv0=(0,24) rfo=1 x16 vs aomdec INVALID x8 + (0,-230) rfo=3 x8; stack entry 0 (0,72) vs (0,-230) | |
| 46 | + | |
| 47 | +## Root cause (decode.rs `build_motion_field`, spec 7.19 / libaom `av1_copy_frame_mvs`) | |
| 48 | + | |
| 49 | +Our per-frame saved motion field stored **`ref_frame[0]`/`mv[0]` of every inter | |
| 50 | +block**. libaom walks **both** reference slots and the **last qualifying one | |
| 51 | +wins**, skipping a slot when | |
| 52 | + | |
| 53 | +* `cm->ref_frame_side[ref]` is non-zero — the reference's OrderHint is ahead of | |
| 54 | + (or equal to) this frame's (`av1_calculate_ref_frame_side`), or | |
| 55 | +* `|mv| > REFMVS_LIMIT` (`(1<<12)-1`). | |
| 56 | + | |
| 57 | +Every compound block in this stream is `LAST + GOLDEN` (both past), so libaom | |
| 58 | +stores GOLDEN's mv with `ref_frame_offset = 3` where we stored LAST's with | |
| 59 | +offset 1 — a wrong (mv, distance) pair in every compound block's 8x8 cell, which | |
| 60 | +the next frame's temporal candidate then projects with the wrong reference | |
| 61 | +distance. Class name: **saved-field-keeps-slot-0** — a per-frame/DPB *summary* | |
| 62 | +of a multi-slot field must replay the reference's own slot walk (order + skips), | |
| 63 | +not keep slot 0. (Sibling of `neighbour-votes-all-its-fields`: there the | |
| 64 | +consumer voted only one slot, here the producer stores only one.) | |
| 65 | + | |
| 66 | +Fix: `crates/ec-av1/src/decode.rs:1728-1800` (`build_motion_field` now takes | |
| 67 | +`order_hint_bits`, walks both slots last-wins, applies the side and | |
| 68 | +`REFMVS_LIMIT` skips); call site `decode.rs:19040`. | |
| 69 | + | |
| 70 | +## Sweep | |
| 71 | + | |
| 72 | +`build_motion_field` is the only writer of `MotionField`/`SavedMv` | |
| 73 | +(`grep -rn "SavedMv\|MotionField" crates/ec-av1/src`); the mv-stack neighbour | |
| 74 | +maps already carry both slots (`MiInfo::ref_frame1`/`mv1`), and | |
| 75 | +`motion_field_projection`/`setup_motion_field` were re-read line-for-line | |
| 76 | +against `mvref_common.c` this round and match (one known, unreached gap noted | |
| 77 | +below). | |
| 78 | + | |
| 79 | +## Gate — GREEN, and it binds | |
| 80 | + | |
| 81 | +`a_real_aomenc_inter_sequence_with_temporal_mv_candidates_decodes_pixel_exact` | |
| 82 | +(`crates/ec-av1/src/stream.rs`, next to the rect gate): the pinned recipe above, | |
| 83 | +2 tx-size-search arms x {8-bit, 10-bit}, every fully decoded attempt compared | |
| 84 | +Y/U/V against ffmpeg, refusals counted (never SKIPped), and `decode::tmv_hits()` | |
| 85 | +asserted > 0 per depth. | |
| 86 | + | |
| 87 | + cargo test -p ec-av1 --lib temporal_mv_candidates -- --nocapture | |
| 88 | + 8-bit: 1 named refusal, 1 pixel-exact attempt, temporal-MV blocks = 66 | |
| 89 | + 10-bit: 1 named refusal, 1 pixel-exact attempt, temporal-MV blocks = 67 | |
| 90 | + test result: ok. 1 passed; 0 failed | |
| 91 | + | |
| 92 | +EVIDENCE: $HOME/.cache/interbis-tmvgate.log | cargo test -p ec-av1 --lib temporal_mv_candidates | 8-bit + 10-bit pixel-exact, tmv counter 66/67 | |
| 93 | + | |
| 94 | +Negative control (gate binds): with the store put back to first-slot-wins the | |
| 95 | +same gate fails at `frame 5 luma vs ffmpeg (attempt 1, 8-bit)`. | |
| 96 | + | |
| 97 | +EVIDENCE: $HOME/.cache/interbis-tmvgate-neg.log | one-line revert to `if saved.is_none()` then re-run the gate | FAILED, frame 5 luma, restored immediately after | |
| 98 | + | |
| 99 | +## Instruments added (env-gated, both decoders) | |
| 100 | + | |
| 101 | +- ours: `EC_MODE_VAL` + `EC_STACK` on the single-ref path of `decode_inter_block` | |
| 102 | + (byte-format-identical to the oracle's rung), `EC_TPL` per `add_tpl_ref_mv` probe. | |
| 103 | +- oracle (`~/.cache/aom-oracle/src`): `EC_STACK` (stack dump at `EC_MODE_VAL`) and | |
| 104 | + `EC_TPL` (per probe, incl. the `INVALID_MV` arm); `ninja aomdec` rebuilt. | |
| 105 | + | |
| 106 | +## Residue | |
| 107 | + | |
| 108 | +- **accepted: `motion_field_projection` does not check the source frame's | |
| 109 | + frame_type.** libaom returns 0 for a KEY/INTRA_ONLY source; here an intra | |
| 110 | + frame's saved field has no cells set, so the projection is inert — but its | |
| 111 | + *return value* (which feeds `ref_stamp`) can differ. Unreached on every stream | |
| 112 | + swept; fix-now if a future stream shows a `ref_stamp` divergence. | |
| 113 | +- **deferred: the rect inter residual gate** stays `#[ignore]`d (lane-inter4's | |
| 114 | + own residue, unblocked by 16x8/8x16 rect inter leaves); its | |
| 115 | + `out_of_scope_mismatch` assert is what surfaced this defect and is now | |
| 116 | + satisfiable on the 8-bit arm. | |
| 117 | +- **deferred: film probe** — this diff lifts no refusal; both films still stop at | |
| 118 | + lane-rectchroma's intra-rect-strip refusal. |