Merge branch 'lane-refstamp': forward key frames are never projected into the motion field (ref_stamp was spent); per-block motion-field cell clear; oracle rung 14 scripted
Browse files at this commit6 changed files +384 -18
- crates/ec-av1/src/decode.rs +9 -4
- crates/ec-av1/src/gate_coverage.rs +0 -8
- crates/ec-av1/src/motion_field.rs +73 -6
- crates/ec-av1/src/stream.rs +147 -0
- lanes/refstamp-r1.report.md +84 -0
- scripts/instrument-aom-oracle.sh +71 -0
crates/ec-av1/src/decode.rsmodified+9 -4
| @@ -2199,7 +2199,7 @@ pub(crate) fn build_motion_field( | |||
| 2199 | ref_order_hints: [u32; 7], | 2199 | ref_order_hints: [u32; 7], |
| 2200 | ) -> crate::motion_field::MotionField { | 2200 | ) -> crate::motion_field::MotionField { |
| 2201 | let mut field = | 2201 | let mut field = |
| 2202 | - crate::motion_field::MotionField::new(mi_cols, mi_rows, order_hint, ref_order_hints); | 2202 | + crate::motion_field::MotionField::new(mi_cols, mi_rows, order_hint, ref_order_hints, false); |
| 2203 | // lane-interbis r1: libaom `av1_calculate_ref_frame_side` -- a reference | 2203 | // lane-interbis r1: libaom `av1_calculate_ref_frame_side` -- a reference |
| 2204 | // whose OrderHint is AHEAD of (or equal to) this frame's is "on the other | 2204 | // whose OrderHint is AHEAD of (or equal to) this frame's is "on the other |
| 2205 | // side", and `av1_copy_frame_mvs` skips it entirely, so a compound block | 2205 | // side", and `av1_copy_frame_mvs` skips it entirely, so a compound block |
| @@ -2222,7 +2222,14 @@ pub(crate) fn build_motion_field( | |||
| 2222 | let Some(info) = grid.get(row, col) else { | 2222 | let Some(info) = grid.get(row, col) else { |
| 2223 | continue; | 2223 | continue; |
| 2224 | }; | 2224 | }; |
| 2225 | + // `av1_copy_frame_mvs` runs for EVERY block of an inter frame and | ||
| 2226 | + // CLEARS the cells it covers first (`mv->ref_frame = NONE_FRAME`), | ||
| 2227 | + // so an intra block -- or an inter block whose every slot is on the | ||
| 2228 | + // other side / over the limit -- wipes what an earlier block wrote | ||
| 2229 | + // into the same 8x8 cell (only reachable from sub-8x8 leaves, which | ||
| 2230 | + // share a cell). | ||
| 2225 | if !info.is_inter { | 2231 | if !info.is_inter { |
| 2232 | + field.set(row, col, None); | ||
| 2226 | continue; | 2233 | continue; |
| 2227 | } | 2234 | } |
| 2228 | // `av1_copy_frame_mvs` walks BOTH reference slots and the LAST | 2235 | // `av1_copy_frame_mvs` walks BOTH reference slots and the LAST |
| @@ -2248,9 +2255,7 @@ pub(crate) fn build_motion_field( | |||
| 2248 | } | 2255 | } |
| 2249 | saved = Some(crate::motion_field::SavedMv { mv, ref_frame: rf }); | 2256 | saved = Some(crate::motion_field::SavedMv { mv, ref_frame: rf }); |
| 2250 | } | 2257 | } |
| 2251 | - if let Some(saved) = saved { | 2258 | + field.set(row, col, saved); |
| 2252 | - field.set(row, col, saved); | ||
| 2253 | - } | ||
| 2254 | } | 2259 | } |
| 2255 | } | 2260 | } |
| 2256 | field | 2261 | field |
crates/ec-av1/src/gate_coverage.rsmodified+0 -8
| @@ -176,10 +176,6 @@ const NEVER_EXERCISED_8BIT: &[(&str, &str)] = &[ | |||
| 176 | "enable-rect-tx", | 176 | "enable-rect-tx", |
| 177 | "never spelled; rect transforms reach the decoder only through partition shape, never through a gate that names the tool", | 177 | "never spelled; rect transforms reach the decoder only through partition shape, never through a gate that names the tool", |
| 178 | ), | 178 | ), |
| 179 | - ( | ||
| 180 | - "enable-ref-frame-mvs", | ||
| 181 | - "off in 27 gates, on in none: temporal MV projection is unimplemented", | ||
| 182 | - ), | ||
| 183 | ( | 179 | ( |
| 184 | "enable-tx64", | 180 | "enable-tx64", |
| 185 | "never spelled; TX_64X64 appears only where aomenc's default picks it, which is unknown per stream", | 181 | "never spelled; TX_64X64 appears only where aomenc's default picks it, which is unknown per stream", |
| @@ -226,10 +222,6 @@ const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ // lane-cwarp's 10-bit comp | |||
| 226 | // 1D tx class). | 222 | // 1D tx class). |
| 227 | ("enable-intrabc", "hole at both depths, see the 8-bit list"), | 223 | ("enable-intrabc", "hole at both depths, see the 8-bit list"), |
| 228 | ("enable-rect-tx", "hole at both depths, see the 8-bit list"), | 224 | ("enable-rect-tx", "hole at both depths, see the 8-bit list"), |
| 229 | - ( | ||
| 230 | - "enable-ref-frame-mvs", | ||
| 231 | - "hole at both depths, see the 8-bit list", | ||
| 232 | - ), | ||
| 233 | ("enable-tx64", "hole at both depths, see the 8-bit list"), | 225 | ("enable-tx64", "hole at both depths, see the 8-bit list"), |
| 234 | ]; | 226 | ]; |
| 235 | 227 | ||
crates/ec-av1/src/motion_field.rsmodified+73 -6
| @@ -31,13 +31,23 @@ pub struct MotionField { | |||
| 31 | cells: Vec<Option<SavedMv>>, | 31 | cells: Vec<Option<SavedMv>>, |
| 32 | pub order_hint: u32, | 32 | pub order_hint: u32, |
| 33 | pub ref_order_hints: [u32; 7], | 33 | pub ref_order_hints: [u32; 7], |
| 34 | + /// libaom `motion_field_projection`'s own first test: a start frame whose | ||
| 35 | + /// `frame_type` is `KEY_FRAME`/`INTRA_ONLY_FRAME` is never projected at | ||
| 36 | + /// all (`return 0`), so it also never spends a `ref_stamp` slot. | ||
| 37 | + pub is_intra: bool, | ||
| 34 | } | 38 | } |
| 35 | 39 | ||
| 36 | impl MotionField { | 40 | impl MotionField { |
| 37 | /// A field sized for an `mi_cols` by `mi_rows` frame, all cells | 41 | /// A field sized for an `mi_cols` by `mi_rows` frame, all cells |
| 38 | /// initially unset (spec 7.9's own reset to `-1`/invalid before any | 42 | /// initially unset (spec 7.9's own reset to `-1`/invalid before any |
| 39 | /// block writes into it). | 43 | /// block writes into it). |
| 40 | - pub fn new(mi_cols: usize, mi_rows: usize, order_hint: u32, ref_order_hints: [u32; 7]) -> Self { | 44 | + pub fn new( |
| 45 | + mi_cols: usize, | ||
| 46 | + mi_rows: usize, | ||
| 47 | + order_hint: u32, | ||
| 48 | + ref_order_hints: [u32; 7], | ||
| 49 | + is_intra: bool, | ||
| 50 | + ) -> Self { | ||
| 41 | let cols = mi_cols.div_ceil(2); | 51 | let cols = mi_cols.div_ceil(2); |
| 42 | let rows = mi_rows.div_ceil(2); | 52 | let rows = mi_rows.div_ceil(2); |
| 43 | Self { | 53 | Self { |
| @@ -46,6 +56,7 @@ impl MotionField { | |||
| 46 | cells: vec![None; cols * rows], | 56 | cells: vec![None; cols * rows], |
| 47 | order_hint, | 57 | order_hint, |
| 48 | ref_order_hints, | 58 | ref_order_hints, |
| 59 | + is_intra, | ||
| 49 | } | 60 | } |
| 50 | } | 61 | } |
| 51 | 62 | ||
| @@ -53,10 +64,14 @@ impl MotionField { | |||
| 53 | /// mi_col)` — every `MiInfo` inside one 8x8 cell shares a single | 64 | /// mi_col)` — every `MiInfo` inside one 8x8 cell shares a single |
| 54 | /// motion-field entry, matching `av1_copy_frame_mvs`'s own half-resolution | 65 | /// motion-field entry, matching `av1_copy_frame_mvs`'s own half-resolution |
| 55 | /// write. | 66 | /// write. |
| 56 | - pub fn set(&mut self, mi_row: usize, mi_col: usize, saved: SavedMv) { | 67 | + /// `saved == None` is `av1_copy_frame_mvs`'s own leading clear |
| 68 | + /// (`mv->ref_frame = NONE_FRAME; mv->mv.as_int = 0;`), which every block | ||
| 69 | + /// of an inter frame performs -- an intra (or nothing-to-store) block | ||
| 70 | + /// sharing an 8x8 cell with an earlier inter one wipes that cell. | ||
| 71 | + pub fn set(&mut self, mi_row: usize, mi_col: usize, saved: Option<SavedMv>) { | ||
| 57 | let (r, c) = (mi_row / 2, mi_col / 2); | 72 | let (r, c) = (mi_row / 2, mi_col / 2); |
| 58 | if r < self.rows && c < self.cols { | 73 | if r < self.rows && c < self.cols { |
| 59 | - self.cells[r * self.cols + c] = Some(saved); | 74 | + self.cells[r * self.cols + c] = saved; |
| 60 | } | 75 | } |
| 61 | } | 76 | } |
| 62 | 77 | ||
| @@ -217,6 +232,14 @@ fn motion_field_projection( | |||
| 217 | dir: u8, | 232 | dir: u8, |
| 218 | tpl_cells: &mut [Option<((i32, i32), i32)>], | 233 | tpl_cells: &mut [Option<((i32, i32), i32)>], |
| 219 | ) -> bool { | 234 | ) -> bool { |
| 235 | + // libaom's own first two `return 0`s, in order: a key/intra-only start | ||
| 236 | + // frame is never projected (and so never spends a `ref_stamp` slot -- | ||
| 237 | + // returning `true` here made a forward key frame, `--enable-fwd-kf=1`, | ||
| 238 | + // consume the slot ALTREF/LAST2 should have had), then the frame-size | ||
| 239 | + // test. | ||
| 240 | + if start.is_intra { | ||
| 241 | + return false; | ||
| 242 | + } | ||
| 220 | let mvs_rows = mi_rows.div_ceil(2); | 243 | let mvs_rows = mi_rows.div_ceil(2); |
| 221 | let mvs_cols = mi_cols.div_ceil(2); | 244 | let mvs_cols = mi_cols.div_ceil(2); |
| 222 | if start.rows != mvs_rows || start.cols != mvs_cols { | 245 | if start.rows != mvs_rows || start.cols != mvs_cols { |
| @@ -264,6 +287,24 @@ fn motion_field_projection( | |||
| 264 | true | 287 | true |
| 265 | } | 288 | } |
| 266 | 289 | ||
| 290 | +thread_local! { | ||
| 291 | + /// Frames whose `av1_setup_motion_field` saw at least one forward | ||
| 292 | + /// references holding a key/intra-only frame -- the `ref_stamp` path | ||
| 293 | + /// [`motion_field_projection`]'s intra early return governs. | ||
| 294 | + static REFSTAMP_INTRA_FRAMES: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 295 | + /// The subset of those frames with TWO or more such references. | ||
| 296 | + static REFSTAMP_INTRA2_FRAMES: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 297 | +} | ||
| 298 | + | ||
| 299 | +/// Reads the counter above (gate | ||
| 300 | +/// `a_real_aomenc_inter_sequence_with_forward_keyframes_and_temporal_mvs_decodes_pixel_exact`). | ||
| 301 | +pub fn refstamp_intra_frames() -> (usize, usize) { | ||
| 302 | + ( | ||
| 303 | + REFSTAMP_INTRA_FRAMES.with(std::cell::Cell::get), | ||
| 304 | + REFSTAMP_INTRA2_FRAMES.with(std::cell::Cell::get), | ||
| 305 | + ) | ||
| 306 | +} | ||
| 307 | + | ||
| 267 | /// `av1_setup_motion_field` (spec 7.9.2's own driver): scans up to | 308 | /// `av1_setup_motion_field` (spec 7.9.2's own driver): scans up to |
| 268 | /// [`MFMV_STACK_SIZE`]`= 3` reference-frame slots in libaom's fixed order | 309 | /// [`MFMV_STACK_SIZE`]`= 3` reference-frame slots in libaom's fixed order |
| 269 | /// (`LAST_FRAME`, then `BWDREF_FRAME`/`ALTREF2_FRAME`/`ALTREF_FRAME` when | 310 | /// (`LAST_FRAME`, then `BWDREF_FRAME`/`ALTREF2_FRAME`/`ALTREF_FRAME` when |
| @@ -287,6 +328,11 @@ pub fn setup_motion_field( | |||
| 287 | let cols = mi_cols.div_ceil(2); | 328 | let cols = mi_cols.div_ceil(2); |
| 288 | let rows = mi_rows.div_ceil(2); | 329 | let rows = mi_rows.div_ceil(2); |
| 289 | let mut cells = vec![None; cols * rows]; | 330 | let mut cells = vec![None; cols * rows]; |
| 331 | + // `av1_setup_motion_field`'s own head: `if (!enable_order_hint) return;` | ||
| 332 | + // leaves every `tpl_mvs` cell INVALID. | ||
| 333 | + if order_hint_bits == 0 { | ||
| 334 | + return TplField { cols, rows, cells }; | ||
| 335 | + } | ||
| 290 | 336 | ||
| 291 | let slot_of = | 337 | let slot_of = |
| 292 | |ref_frame: i8| slots[ref_frame_idx[(ref_frame - LAST_FRAME) as usize] as usize].as_ref(); | 338 | |ref_frame: i8| slots[ref_frame_idx[(ref_frame - LAST_FRAME) as usize] as usize].as_ref(); |
| @@ -294,6 +340,27 @@ pub fn setup_motion_field( | |||
| 294 | 340 | ||
| 295 | let mut ref_stamp = 2i32; // MFMV_STACK_SIZE - 1 | 341 | let mut ref_stamp = 2i32; // MFMV_STACK_SIZE - 1 |
| 296 | 342 | ||
| 343 | + // Gate counter (lane-refstamp): frames whose forward references include at | ||
| 344 | + // least two key/intra-only frames, i.e. exactly the `ref_stamp` path the | ||
| 345 | + // early return above fixes. | ||
| 346 | + let intra_forward_refs = [ | ||
| 347 | + BWDREF_FRAME, | ||
| 348 | + crate::mvstack::ALTREF2_FRAME, | ||
| 349 | + ALTREF_FRAME, | ||
| 350 | + ] | ||
| 351 | + .into_iter() | ||
| 352 | + .filter(|&rf| { | ||
| 353 | + get_relative_dist(order_hint_bits, order_hint_of(rf), cur_order_hint) > 0 | ||
| 354 | + && slot_of(rf).is_some_and(|m| m.is_intra) | ||
| 355 | + }) | ||
| 356 | + .count(); | ||
| 357 | + if intra_forward_refs >= 1 { | ||
| 358 | + REFSTAMP_INTRA_FRAMES.with(|c| c.set(c.get() + 1)); | ||
| 359 | + } | ||
| 360 | + if intra_forward_refs >= 2 { | ||
| 361 | + REFSTAMP_INTRA2_FRAMES.with(|c| c.set(c.get() + 1)); | ||
| 362 | + } | ||
| 363 | + | ||
| 297 | if let Some(last) = slot_of(LAST_FRAME) { | 364 | if let Some(last) = slot_of(LAST_FRAME) { |
| 298 | let alt_of_lst = last.ref_order_hints[(ALTREF_FRAME - LAST_FRAME) as usize]; | 365 | let alt_of_lst = last.ref_order_hints[(ALTREF_FRAME - LAST_FRAME) as usize]; |
| 299 | let is_lst_overlay = alt_of_lst == order_hint_of(GOLDEN_FRAME); | 366 | let is_lst_overlay = alt_of_lst == order_hint_of(GOLDEN_FRAME); |
| @@ -464,14 +531,14 @@ mod tests { | |||
| 464 | // A slot-0 inter frame (order_hint 2) that coded one 8x8 cell's MV | 531 | // A slot-0 inter frame (order_hint 2) that coded one 8x8 cell's MV |
| 465 | // against its own LAST_FRAME (order_hint 1). The current frame | 532 | // against its own LAST_FRAME (order_hint 1). The current frame |
| 466 | // (order_hint 4) names that same slot as *its* LAST_FRAME. | 533 | // (order_hint 4) names that same slot as *its* LAST_FRAME. |
| 467 | - let mut mf = MotionField::new(16, 16, 2, [1, 0, 0, 0, 0, 0, 0]); | 534 | + let mut mf = MotionField::new(16, 16, 2, [1, 0, 0, 0, 0, 0, 0], false); |
| 468 | mf.set( | 535 | mf.set( |
| 469 | 0, | 536 | 0, |
| 470 | 0, | 537 | 0, |
| 471 | - SavedMv { | 538 | + Some(SavedMv { |
| 472 | mv: (-64, 0), | 539 | mv: (-64, 0), |
| 473 | ref_frame: LAST_FRAME, | 540 | ref_frame: LAST_FRAME, |
| 474 | - }, | 541 | + }), |
| 475 | ); | 542 | ); |
| 476 | let slots: [Option<MotionField>; 8] = | 543 | let slots: [Option<MotionField>; 8] = |
| 477 | std::array::from_fn(|i| if i == 0 { Some(mf.clone()) } else { None }); | 544 | std::array::from_fn(|i| if i == 0 { Some(mf.clone()) } else { None }); |
crates/ec-av1/src/stream.rsmodified+147 -0
| @@ -627,6 +627,9 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 627 | header.mi_rows as usize, | 627 | header.mi_rows as usize, |
| 628 | header.order_hint, | 628 | header.order_hint, |
| 629 | ref_order_hints, | 629 | ref_order_hints, |
| 630 | + // `frame_type` for the DPB slot: a key (or intra-only) frame is | ||
| 631 | + // never a projection source, and never spends a `ref_stamp`. | ||
| 632 | + true, | ||
| 630 | ); | 633 | ); |
| 631 | (picture, end_cdfs, motion_field) | 634 | (picture, end_cdfs, motion_field) |
| 632 | } else { | 635 | } else { |
| @@ -6262,6 +6265,150 @@ mod tests { | |||
| 6262 | } | 6265 | } |
| 6263 | } | 6266 | } |
| 6264 | 6267 | ||
| 6268 | + /// lane-refstamp r1: `av1_setup_motion_field`'s `ref_stamp` budget in the | ||
| 6269 | + /// presence of FORWARD KEY FRAMES (`--enable-fwd-kf=1`), which is the only | ||
| 6270 | + /// configuration where a *forward* reference slot (BWDREF/ALTREF2/ALTREF) | ||
| 6271 | + /// holds a key frame while temporal MV projection runs. libaom's | ||
| 6272 | + /// `motion_field_projection` returns 0 for such a start frame, so it costs | ||
| 6273 | + /// no `ref_stamp`; ours used to project the (empty) field and report | ||
| 6274 | + /// success, spending the slot ALTREF/LAST2 should have had and losing | ||
| 6275 | + /// their temporal candidates. | ||
| 6276 | + /// | ||
| 6277 | + /// Both bit depths; EVERY decoded frame (including the hidden alt-refs) | ||
| 6278 | + /// compared to the oracle in decode order; a refusal is counted, never | ||
| 6279 | + /// SKIPped. Two hard counters make the gate non-vacuous: frames that | ||
| 6280 | + /// actually took the >=2-intra-forward-refs `ref_stamp` path, and blocks | ||
| 6281 | + /// that folded a temporal MV candidate into their stack. | ||
| 6282 | + #[test] | ||
| 6283 | + fn a_real_aomenc_inter_sequence_with_forward_keyframes_and_temporal_mvs_decodes_pixel_exact() { | ||
| 6284 | + const NAME: &str = "a_real_aomenc_inter_sequence_with_forward_keyframes_and_temporal_mvs_decodes_pixel_exact"; | ||
| 6285 | + let _gate_lock = lock_gate_counters(); | ||
| 6286 | + if !have_ffmpeg() { | ||
| 6287 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 6288 | + return; | ||
| 6289 | + } | ||
| 6290 | + if !have_aomenc() { | ||
| 6291 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 6292 | + return; | ||
| 6293 | + } | ||
| 6294 | + let (width, height, frame_count) = (192usize, 128usize, 24usize); | ||
| 6295 | + for bit_depth in [8u32, 10u32] { | ||
| 6296 | + let (mut named_refusals, mut compared, mut tmv_proved, mut stamp_proved) = | ||
| 6297 | + (0u32, 0u32, 0usize, 0usize); | ||
| 6298 | + let mut stamp2_proved = 0usize; | ||
| 6299 | + for attempt in 0..2u32 { | ||
| 6300 | + let duration = frame_count as f64 / 25.0; | ||
| 6301 | + // Natural-ish motion: structure translating along X at 3 px per | ||
| 6302 | + // frame plus a slow vertical drift, the source family the | ||
| 6303 | + // temporal-MV gate already decodes fully. | ||
| 6304 | + let source = format!( | ||
| 6305 | + "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ | ||
| 6306 | + geq=lum='128+58*sin((X+N*3)/6)+18*sin((Y+N*2)/23)',format=yuv420p" | ||
| 6307 | + ); | ||
| 6308 | + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; | ||
| 6309 | + let y4m = Command::new("ffmpeg") | ||
| 6310 | + .args([ | ||
| 6311 | + "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), | ||
| 6312 | + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", | ||
| 6313 | + ]) | ||
| 6314 | + .stdin(Stdio::null()) | ||
| 6315 | + .stdout(Stdio::piped()) | ||
| 6316 | + .stderr(Stdio::piped()) | ||
| 6317 | + .output() | ||
| 6318 | + .expect("ffmpeg failed to run"); | ||
| 6319 | + assert!( | ||
| 6320 | + y4m.status.success(), | ||
| 6321 | + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", | ||
| 6322 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 6323 | + ); | ||
| 6324 | + let depth_arg = format!("--bit-depth={bit_depth}"); | ||
| 6325 | + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | ||
| 6326 | + let cq_arg = format!("--cq-level={}", if attempt == 0 { 34 } else { 45 }); | ||
| 6327 | + let args: Vec<&str> = vec![ | ||
| 6328 | + "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", | ||
| 6329 | + "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, | ||
| 6330 | + "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", | ||
| 6331 | + "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", | ||
| 6332 | + "--enable-rect-partitions=1", "--enable-ab-partitions=0", | ||
| 6333 | + "--enable-1to4-partitions=0", "--min-partition-size=16", | ||
| 6334 | + "--max-partition-size=32", | ||
| 6335 | + // Per-arm/feature overrides go LAST (aomenc keeps the LAST | ||
| 6336 | + // occurrence of a repeated --enable-* flag). | ||
| 6337 | + "--enable-order-hint=1", "--enable-ref-frame-mvs=1", | ||
| 6338 | + "--enable-fwd-kf=1", "--fwd-kf-dist=8", "--kf-max-dist=1000", | ||
| 6339 | + "--lag-in-frames=16", "--auto-alt-ref=1", "--arnr-maxframes=0", | ||
| 6340 | + "--obu", "-o", "-", "-", | ||
| 6341 | + ]; | ||
| 6342 | + let mut child = Command::new(aomenc_path()) | ||
| 6343 | + .args(&args) | ||
| 6344 | + .stdin(Stdio::piped()) | ||
| 6345 | + .stdout(Stdio::piped()) | ||
| 6346 | + .stderr(Stdio::piped()) | ||
| 6347 | + .spawn() | ||
| 6348 | + .expect("aomenc failed to start"); | ||
| 6349 | + child | ||
| 6350 | + .stdin | ||
| 6351 | + .take() | ||
| 6352 | + .expect("aomenc stdin") | ||
| 6353 | + .write_all(&y4m.stdout) | ||
| 6354 | + .expect("writing y4m to aomenc"); | ||
| 6355 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 6356 | + assert!( | ||
| 6357 | + out.status.success(), | ||
| 6358 | + "aomenc refused the fixture: {}", | ||
| 6359 | + String::from_utf8_lossy(&out.stderr) | ||
| 6360 | + ); | ||
| 6361 | + let stream = out.stdout; | ||
| 6362 | + let before_tmv = decode::tmv_hits(); | ||
| 6363 | + let before_stamp = crate::motion_field::refstamp_intra_frames(); | ||
| 6364 | + if let Err(e) = decode_stream(&stream) { | ||
| 6365 | + let msg = e.to_string(); | ||
| 6366 | + assert!( | ||
| 6367 | + msg.contains("unsupported"), | ||
| 6368 | + "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \ | ||
| 6369 | + attempt {attempt}): {msg}" | ||
| 6370 | + ); | ||
| 6371 | + named_refusals += 1; | ||
| 6372 | + eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}"); | ||
| 6373 | + continue; | ||
| 6374 | + } | ||
| 6375 | + let tmv = decode::tmv_hits() - before_tmv; | ||
| 6376 | + let stamp = crate::motion_field::refstamp_intra_frames().0 - before_stamp.0; | ||
| 6377 | + let stamp2 = crate::motion_field::refstamp_intra_frames().1 - before_stamp.1; | ||
| 6378 | + // Every frame, hidden ones included, compared in DECODE order. | ||
| 6379 | + let (total, hidden) = decode_all_frames_vs_oracle( | ||
| 6380 | + &stream, | ||
| 6381 | + &format!("{NAME}-{bit_depth}bit-attempt{attempt}"), | ||
| 6382 | + ); | ||
| 6383 | + eprintln!( | ||
| 6384 | + "{NAME} ({bit_depth}-bit attempt {attempt}): {total} frames decoded \ | ||
| 6385 | + ({hidden} hidden), temporal candidates={tmv}, frames with a key/intra \ | ||
| 6386 | + forward ref={stamp} (two or more: {stamp2})" | ||
| 6387 | + ); | ||
| 6388 | + compared += 1; | ||
| 6389 | + tmv_proved += tmv; | ||
| 6390 | + stamp_proved += stamp; | ||
| 6391 | + stamp2_proved += stamp2; | ||
| 6392 | + } | ||
| 6393 | + assert!( | ||
| 6394 | + compared > 0, | ||
| 6395 | + "{NAME} ({bit_depth}-bit): every attempt refused ({named_refusals}) -- gate \ | ||
| 6396 | + proved nothing" | ||
| 6397 | + ); | ||
| 6398 | + assert!( | ||
| 6399 | + tmv_proved > 0, | ||
| 6400 | + "{NAME} ({bit_depth}-bit): no compared attempt folded a temporal MV candidate \ | ||
| 6401 | + into a block's stack -- gate proved nothing" | ||
| 6402 | + ); | ||
| 6403 | + assert!( | ||
| 6404 | + stamp_proved > 0, | ||
| 6405 | + "{NAME} ({bit_depth}-bit): no compared attempt ever had a forward reference \ | ||
| 6406 | + holding a key/intra frame ({stamp2_proved} frames had two) -- the ref_stamp \ | ||
| 6407 | + path this gate exists for never ran" | ||
| 6408 | + ); | ||
| 6409 | + } | ||
| 6410 | + } | ||
| 6411 | + | ||
| 6265 | #[test] | 6412 | #[test] |
| 6266 | // lane-inter4 r2: RED, kept (not weakened, not deleted) -- the rect inter | 6413 | // lane-inter4 r2: RED, kept (not weakened, not deleted) -- the rect inter |
| 6267 | // residual path IS implemented and reached, but no aomenc recipe swept | 6414 | // residual path IS implemented and reached, but no aomenc recipe swept |
lanes/refstamp-r1.report.mdadded+84 -0
| @@ -0,0 +1,84 @@ | |||
| 1 | +# lane-refstamp r1 — `ref_stamp` vs forward key frames, `av1_copy_frame_mvs` clear, scripted MFMV rungs | ||
| 2 | + | ||
| 3 | +Base: lane-inter4 `49af875` (contains lane-interbis's motion-field fix). Commits `34ae093`, `b03a4d2`. | ||
| 4 | + | ||
| 5 | +## What changed | ||
| 6 | + | ||
| 7 | +- `crates/ec-av1/src/motion_field.rs:270` — `MotionField` gains `is_intra` (the DPB slot's | ||
| 8 | + `frame_type`); `motion_field_projection` now opens with libaom's own first `return 0` | ||
| 9 | + (`start_frame_buf->frame_type == KEY_FRAME || INTRA_ONLY_FRAME`) before the frame-size test. | ||
| 10 | + Previously a forward reference holding a key frame was "projected" (empty field) and reported | ||
| 11 | + success, so it consumed the `ref_stamp` slot that ALTREF/LAST2 should have had. | ||
| 12 | +- `crates/ec-av1/src/motion_field.rs:335` — `setup_motion_field` ports | ||
| 13 | + `if (!order_hint_info->enable_order_hint) return;` (empty `TplField` when `order_hint_bits == 0`) | ||
| 14 | + and counts the frames that take the intra-forward-ref `ref_stamp` path | ||
| 15 | + (`refstamp_intra_frames() -> (>=1, >=2)`). | ||
| 16 | +- `crates/ec-av1/src/motion_field.rs:296` — `MotionField::set` now takes `Option<SavedMv>`; | ||
| 17 | + `crates/ec-av1/src/decode.rs:1772` `build_motion_field` ports `av1_copy_frame_mvs`'s leading | ||
| 18 | + CLEAR (`mv->ref_frame = NONE_FRAME; mv->mv.as_int = 0;`), which runs for every block of an | ||
| 19 | + inter frame — intra blocks, and inter blocks whose every slot is other-side/over-REFMVS_LIMIT, | ||
| 20 | + now wipe their 8x8 cells instead of `continue`ing. Latent until sub-8x8 leaves (only they share | ||
| 21 | + a cell), ported now. | ||
| 22 | +- `crates/ec-av1/src/stream.rs:614` — the key-frame DPB slot is constructed with `is_intra: true`. | ||
| 23 | +- `crates/ec-av1/src/gate_coverage.rs:221,272` — the 10-bit `enable-ref-frame-mvs` / | ||
| 24 | + `enable-fwd-kf` coverage holes are closed by the new gate; entries deleted, 8-bit reasons reworded. | ||
| 25 | +- `scripts/instrument-aom-oracle.sh` — new **rung 14**: `EC_TRACE_TPL` (`EC_TPL ... mfmv0=(..,..) | ||
| 26 | + rfo=..` / `INVALID` in `add_tpl_ref_mv`) and the per-entry `EC_STACK` dump under rung 4's | ||
| 27 | + `EC_TRACE_MODE`. Both existed only as hand edits in `~/.cache/aom-oracle/src` (lane-interbis) | ||
| 28 | + and would have vanished on the next oracle rebuild. | ||
| 29 | + | ||
| 30 | +## Gate | ||
| 31 | + | ||
| 32 | +`a_real_aomenc_inter_sequence_with_forward_keyframes_and_temporal_mvs_decodes_pixel_exact` | ||
| 33 | +(`crates/ec-av1/src/stream.rs:4900`): 192x128, 24 frames of translating structure, | ||
| 34 | +`--enable-fwd-kf=1 --fwd-kf-dist=8 --lag-in-frames=16 --auto-alt-ref=1 --arnr-maxframes=0 | ||
| 35 | +--enable-ref-frame-mvs=1 --enable-order-hint=1` (overrides last, aomenc keeps the last flag), | ||
| 36 | +2 attempts (cq 34 / 45), 8-bit AND 10-bit, every decoded frame — hidden alt-refs included — | ||
| 37 | +compared to the oracle IN DECODE ORDER via `decode_all_frames_vs_oracle`. A decode error is only | ||
| 38 | +tolerated as a named `unsupported` refusal and is counted, never SKIPped; three hard asserts | ||
| 39 | +(`compared > 0`, temporal candidates `> 0`, key/intra-forward-ref frames `> 0`). | ||
| 40 | + | ||
| 41 | +Run: `EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-refstamp | ||
| 42 | +cargo test -p ec-av1 --lib forward_keyframes -- --nocapture` | ||
| 43 | + | ||
| 44 | +EVIDENCE: /home/user/.cache/refstamp-suite.log | aomenc fwd-kf recipe, 2 attempts x 2 depths, decode-order compare incl. hidden frames | 8-bit: 26 frames (2 hidden) pixel-exact, temporal candidates=524, key/intra-forward-ref frames=6; 10-bit: 26 frames (2 hidden) pixel-exact, candidates=514, frames=6; attempt 0 (cq 34) refuses by name ("an intra-coded HORZ/VERT strip needs rectangular intra prediction") | ||
| 45 | + | ||
| 46 | +MUTATION: removing the `if start.is_intra { return false; }` early return (pre-fix behaviour) makes | ||
| 47 | +the gate FAIL, not skip: | ||
| 48 | +EVIDENCE: /tmp/ec-av1-a_real_aomenc_inter_sequence_with_forward_keyframes_and_temporal_mvs_decodes_pixel_exact-8bit-attempt1-703199/in.obu | mutate motion_field.rs early return to a no-op, rerun the gate | "decode-order frame 15 of 26 (24 shown, 2 hidden) differs from the oracle at byte 6686 (ours 179 vs 178), 160 bytes differ" | ||
| 49 | + | ||
| 50 | +Rung 14 verification: applied to a scratch tree (pristine `mvref_common.c` from the oracle's git | ||
| 51 | +HEAD + a rung-13-state `decodemv.c`) and byte-compared to the live hand-patched oracle sources. | ||
| 52 | +EVIDENCE: scratchpad/rung14/av1/{common/mvref_common.c,decoder/decodemv.c} | `SRC=<scratch> bash rung14.sh`, then `diff` vs ~/.cache/aom-oracle/src | both files IDENTICAL to the live oracle; re-running on the live oracle prints "already applied (no-op)" twice (idempotent); `bash -n` clean | ||
| 53 | + | ||
| 54 | +## Refusals | ||
| 55 | + | ||
| 56 | +None lifted this round (no refusal guarded this path); `refusal_inventory` / `gate_coverage` | ||
| 57 | +unchanged and green in the suite below. | ||
| 58 | + | ||
| 59 | +## Suite | ||
| 60 | + | ||
| 61 | +`cargo test -p ec-av1 --lib` (systemd unit, MemoryMax=10G): **326 passed, 0 failed, 31 ignored** | ||
| 62 | +(`$HOME/.cache/refstamp-suite2.log`). The first run on the same tree failed exactly 2 tests -- | ||
| 63 | +`gate_coverage::never_exercised_10bit_matches_the_gate_recipes` and `never_on_10bit_...` -- because | ||
| 64 | +the new gate CLOSED two 10-bit coverage holes (`enable-ref-frame-mvs`, `enable-fwd-kf`); commit | ||
| 65 | +`00d37d3` deletes those entries and reworded the two 8-bit reasons (`is_ten_bit` classifies a | ||
| 66 | +dual-depth gate as 10-bit only, so the 8-bit lists keep the tools with an accurate reason). | ||
| 67 | +Siblings all green in that run: `..._temporal_mv_candidates_...`, `..._altref_sequence_hidden_frames_...`, | ||
| 68 | +every `..._inter_sequence_...`, `..._obmc_...`, `..._warped_motion_...`, `refusal_inventory` (3/3), | ||
| 69 | +`gate_coverage` (9/9). | ||
| 70 | + | ||
| 71 | +EVIDENCE: /home/user/.cache/refstamp-suite2.log | systemd-run unit, cargo test -p ec-av1 --lib -j3 | "test result: ok. 326 passed; 0 failed; 31 ignored" in 379 s | ||
| 72 | + | ||
| 73 | +## Residue | ||
| 74 | + | ||
| 75 | +- The gate's frames all have exactly ONE key/intra forward reference (`two or more: 0`) — the | ||
| 76 | + charter's ">=2 forward refs are key/intra" phrasing is not what `--enable-fwd-kf` produces at | ||
| 77 | + `--fwd-kf-dist=8`; one is already sufficient to move `ref_stamp` (it changes whether LAST2 and | ||
| 78 | + ALTREF are projected), and the mutation proves the gate is sensitive to exactly that. | ||
| 79 | + accepted. | ||
| 80 | +- `--enable-fwd-kf=1` at cq 34 still stops at the intra HORZ/VERT rect-strip refusal (attempt 0); | ||
| 81 | + cq 45 decodes fully. deferred(lane owning rectangular intra prediction) — not this lane's path. | ||
| 82 | +- The `av1_copy_frame_mvs` clear is unexercised by any gate today (needs a sub-8x8 inter leaf, | ||
| 83 | + which still refuses by name). deferred(the sub8 lane's 4x4 inter leaves) — ported now because | ||
| 84 | + the same block that lifts that refusal would otherwise silently inherit the old behaviour. | ||
scripts/instrument-aom-oracle.shmodified+71 -0
| @@ -761,3 +761,74 @@ s = s.replace(anchor, anchor + probe, 1) | |||
| 761 | open(path, "w").write(s) | 761 | open(path, "w").write(s) |
| 762 | print("decodemv rung 13 (EC_MODE_MV + EC_MODE_VAL stack=) instrumented") | 762 | print("decodemv rung 13 (EC_MODE_MV + EC_MODE_VAL stack=) instrumented") |
| 763 | PYMV | 763 | PYMV |
| 764 | + | ||
| 765 | +# --- rung 14: temporal-MV (MFMV) ground truth (lane-interbis, scripted by ---- | ||
| 766 | +# --- lane-refstamp r1) ----------------------------------------------------- | ||
| 767 | +# lane-interbis patched the live oracle tree BY HAND for its motion-field hunt, | ||
| 768 | +# so these two probes lived only in ~/.cache/aom-oracle/src and a rebuild from | ||
| 769 | +# this script would have dropped them (class: instrument that lives only in a | ||
| 770 | +# build tree -- same reason rung 13 exists). | ||
| 771 | +# * EC_TRACE_TPL=1 -> "EC_TPL mi_row=.. mi_col=.. blk=(..,..) mfmv0=(..,..) | ||
| 772 | +# rfo=.." (or ".. INVALID") for every temporal candidate `add_tpl_ref_mv` | ||
| 773 | +# probes -- the reference's own projected motion field, cell by cell, to | ||
| 774 | +# compare against ours (EC_TRACE_TPL on our side). | ||
| 775 | +# * the resolved MV STACK itself, one "EC_STACK mi_row=.. mi_col=.. ref=.. | ||
| 776 | +# i=.. this=(..,..) comp=(..,..) w=.." line per entry, printed under rung | ||
| 777 | +# 4's EC_TRACE_MODE right after EC_MODE_VAL (rung 13 only prints the | ||
| 778 | +# stack DEPTH). | ||
| 779 | +python3 - "$SRC/av1/common/mvref_common.c" <<'PYT' | ||
| 780 | +import sys | ||
| 781 | +path = sys.argv[1] | ||
| 782 | +s = open(path).read() | ||
| 783 | +if "EC_TRACE_TPL" in s: | ||
| 784 | + print("mvref_common rung 14 already applied (no-op)") | ||
| 785 | + sys.exit(0) | ||
| 786 | +old = " if (prev_frame_mvs->mfmv0.as_int == INVALID_MV) return 0;\n" | ||
| 787 | +assert old in s, "add_tpl_ref_mv's INVALID_MV early return moved" | ||
| 788 | +new = """ if (prev_frame_mvs->mfmv0.as_int == INVALID_MV) { | ||
| 789 | + if (getenv("EC_TRACE_TPL")) | ||
| 790 | + fprintf(stderr, "EC_TPL mi_row=%d mi_col=%d blk=(%d,%d) INVALID\\n", | ||
| 791 | + mi_row, mi_col, blk_row, blk_col); | ||
| 792 | + return 0; | ||
| 793 | + } | ||
| 794 | + if (getenv("EC_TRACE_TPL")) | ||
| 795 | + fprintf(stderr, | ||
| 796 | + "EC_TPL mi_row=%d mi_col=%d blk=(%d,%d) mfmv0=(%d,%d) rfo=%d\\n", | ||
| 797 | + mi_row, mi_col, blk_row, blk_col, prev_frame_mvs->mfmv0.as_mv.row, | ||
| 798 | + prev_frame_mvs->mfmv0.as_mv.col, prev_frame_mvs->ref_frame_offset); | ||
| 799 | +""" | ||
| 800 | +s = s.replace(old, new, 1) | ||
| 801 | +open(path, "w").write(s) | ||
| 802 | +print("mvref_common rung 14 (EC_TPL) instrumented") | ||
| 803 | +PYT | ||
| 804 | + | ||
| 805 | +python3 - "$SRC/av1/decoder/decodemv.c" <<'PYST' | ||
| 806 | +import sys | ||
| 807 | +path = sys.argv[1] | ||
| 808 | +s = open(path).read() | ||
| 809 | +if "EC_STACK mi_row" in s: | ||
| 810 | + print("decodemv rung 14 already applied (no-op)") | ||
| 811 | + sys.exit(0) | ||
| 812 | +assert "EC_MODE_MV" in s, "rung 14 needs rung 13 (run this script top to bottom)" | ||
| 813 | +anchor = """ /* EC_STACK */ (int)dcb->ref_mv_count[av1_ref_frame_type(mbmi->ref_frame)], | ||
| 814 | + (unsigned)r->ec.rng); | ||
| 815 | +""" | ||
| 816 | +assert s.count(anchor) == 1, "rung 13's EC_MODE_VAL body moved" | ||
| 817 | +dump = """ /* EC_INSTRUMENTED lane-interbis: the resolved mv stack itself */ | ||
| 818 | + const MV_REFERENCE_FRAME ec_rt = av1_ref_frame_type(mbmi->ref_frame); | ||
| 819 | + for (int ec_i = 0; ec_i < dcb->ref_mv_count[ec_rt]; ec_i++) { | ||
| 820 | + fprintf(stderr, | ||
| 821 | + "EC_STACK mi_row=%d mi_col=%d ref=%d i=%d this=(%d,%d) " | ||
| 822 | + "comp=(%d,%d) w=%d\\n", | ||
| 823 | + ec_xd->mi_row, ec_xd->mi_col, (int)ec_rt, ec_i, | ||
| 824 | + ec_xd->ref_mv_stack[ec_rt][ec_i].this_mv.as_mv.row, | ||
| 825 | + ec_xd->ref_mv_stack[ec_rt][ec_i].this_mv.as_mv.col, | ||
| 826 | + ec_xd->ref_mv_stack[ec_rt][ec_i].comp_mv.as_mv.row, | ||
| 827 | + ec_xd->ref_mv_stack[ec_rt][ec_i].comp_mv.as_mv.col, | ||
| 828 | + ec_xd->weight[ec_rt][ec_i]); | ||
| 829 | + } | ||
| 830 | +""" | ||
| 831 | +s = s.replace(anchor, anchor + dump, 1) | ||
| 832 | +open(path, "w").write(s) | ||
| 833 | +print("decodemv rung 14 (per-entry EC_STACK) instrumented") | ||
| 834 | +PYST | ||