ec-av1: rect intrabc r4 -- publish every block's footprint into the intrabc mv grid
Browse files at this commite9e3a487a2c56fc3e99755016ebaaa406733c9bbParent: 3b06ab74 changed files +410 -6
- crates/ec-av1/src/decode.rs +42 -0
- crates/ec-av1/src/mvstack.rs +71 -3
- crates/ec-av1/src/stream.rs +167 -0
- lanes/av1intrabc.report.md +130 -3
crates/ec-av1/src/decode.rsmodified+42 -0
| @@ -3725,6 +3725,22 @@ thread_local! { | ||
| 3725 | 3725 | static INTRABC_RECT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 3726 | 3726 | /// Of those, how many read the INTER var-tx tree (unskipped, TX_MODE_SELECT). |
| 3727 | 3727 | static INTRABC_RECT_VARTX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 3728 | + /// lane-av1-intrabc r4: rect INTRABC blocks whose reconstruction | |
| 3729 | + /// [`decode_intrabc_rect`] ran with `skip == 0` (a real residual read), | |
| 3730 | + /// split by the strip's orientation -- `bw > bh` is a HORZ strip, | |
| 3731 | + /// `bh > bw` a VERT one. The reviewer's unblock condition needs a CODED | |
| 3732 | + /// witness in BOTH orientations, and the existing `INTRABC_RECT_HITS` | |
| 3733 | + /// counts neither orientation nor the skip flag, so an arm that flipped | |
| 3734 | + /// to an all-skip stream (no residual reader at all) would stay green. | |
| 3735 | + static INTRABC_RECT_CODED_HITS: std::cell::Cell<[usize; 2]> = | |
| 3736 | + const { std::cell::Cell::new([0, 0]) }; | |
| 3737 | +} | |
| 3738 | + | |
| 3739 | +/// lane-av1-intrabc r4: coded (`skip == 0`) rect intrabc blocks reconstructed, | |
| 3740 | +/// as `[horz, vert]` -- see [`INTRABC_RECT_CODED_HITS`]. | |
| 3741 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | |
| 3742 | +pub fn intrabc_rect_coded_hits() -> [usize; 2] { | |
| 3743 | + INTRABC_RECT_CODED_HITS.with(std::cell::Cell::get) | |
| 3728 | 3744 | } |
| 3729 | 3745 | |
| 3730 | 3746 | /// Current value of [`INTRABC_RECT_HITS`]. |
| @@ -3738,6 +3754,7 @@ pub fn intrabc_rect_hits() -> usize { | ||
| 3738 | 3754 | pub(crate) fn reset_intrabc_rect_hits() { |
| 3739 | 3755 | INTRABC_RECT_HITS.with(|c| c.set(0)); |
| 3740 | 3756 | INTRABC_RECT_VARTX_HITS.with(|c| c.set(0)); |
| 3757 | + INTRABC_RECT_CODED_HITS.with(|c| c.set([0, 0])); | |
| 3741 | 3758 | } |
| 3742 | 3759 | |
| 3743 | 3760 | /// Current value of [`INTRABC_RECT_VARTX_HITS`]. |
| @@ -7652,6 +7669,22 @@ impl Neighbours { | ||
| 7652 | 7669 | fill_span(&mut self.ref_grid, start, w_mi, ref_frame); |
| 7653 | 7670 | fill_span(&mut self.delta_lf_grid, start, w_mi, snapshot); |
| 7654 | 7671 | } |
| 7672 | + // lane-av1-intrabc r4: publish this coded block's own mi footprint | |
| 7673 | + // into the intrabc MV grid's block-COVERAGE map -- every coded block, | |
| 7674 | + // not just the intrabc ones. A later intrabc block's DV predictor is | |
| 7675 | + // built by libaom's own row/col scans over `xd->mi[]`, which holds an | |
| 7676 | + // `MB_MODE_INFO` for EVERY block and steps by | |
| 7677 | + // `mi_size_wide/height[candidate->bsize]`; without this footprint a | |
| 7678 | + // non-intrabc neighbour reads as uncovered and the scan advances it | |
| 7679 | + // by one cell instead of its real width (see `MiGrid::cover`'s own | |
| 7680 | + // doc comment for the measured instance). A no-op outside an | |
| 7681 | + // `allow_intrabc` frame -- [`crate::decode::FrameCtx::intrabc_mi_grid`] | |
| 7682 | + // is `None` exactly then. | |
| 7683 | + fctx.intrabc_mi_grid.with(|g| { | |
| 7684 | + if let Some((grid, _, _)) = g.borrow_mut().as_mut() { | |
| 7685 | + grid.cover_rect(mi_r, mi_c, w_mi, h_mi); | |
| 7686 | + } | |
| 7687 | + }); | |
| 7655 | 7688 | } |
| 7656 | 7689 | |
| 7657 | 7690 | /// One var-tx / split-tx LEAF's own LUMA transform dims over its mi span. |
| @@ -10929,6 +10962,15 @@ fn decode_intrabc_rect( | ||
| 10929 | 10962 | fctx: &crate::decode::FrameCtx, |
| 10930 | 10963 | ) -> Result<()> { |
| 10931 | 10964 | hit!(INTRABC_RECT_HITS); |
| 10965 | + if !skip { | |
| 10966 | + // [horz, vert]: see `INTRABC_RECT_CODED_HITS`. | |
| 10967 | + let idx = usize::from(bh > bw); | |
| 10968 | + INTRABC_RECT_CODED_HITS.with(|c| { | |
| 10969 | + let mut seen = c.get(); | |
| 10970 | + seen[idx] += 1; | |
| 10971 | + c.set(seen); | |
| 10972 | + }); | |
| 10973 | + } | |
| 10932 | 10974 | let (px, py) = (mi_c * MI, mi_r * MI); |
| 10933 | 10975 | let (cpx, cpy) = (px / 2, py / 2); |
| 10934 | 10976 | // `av1_get_max_uv_txsize(bw x bh)`: 4:2:0 halves the footprint and the |
crates/ec-av1/src/mvstack.rsmodified+71 -3
| @@ -251,6 +251,30 @@ pub struct MiGrid { | ||
| 251 | 251 | cols: usize, |
| 252 | 252 | rows: usize, |
| 253 | 253 | cells: Vec<Option<MiInfo>>, |
| 254 | + /// lane-av1-intrabc r4: the CODED BLOCK's own `(width, height)` in mi | |
| 255 | + /// units for every cell of the frame, whatever the block is -- the | |
| 256 | + /// block-COVERAGE map a scan's run-length stepping needs. | |
| 257 | + /// | |
| 258 | + /// libaom's candidate scans walk `xd->mi[]`, which holds an | |
| 259 | + /// `MB_MODE_INFO` for EVERY coded block, and step by | |
| 260 | + /// `mi_size_wide/height[candidate->bsize]`. A decoder grid that only | |
| 261 | + /// holds the blocks with an MV (the intrabc blocks here) makes every | |
| 262 | + /// intra neighbour read as *uncovered*: the scan then advances that cell | |
| 263 | + /// by one instead of by the neighbour's real width, which walks it | |
| 264 | + /// straight into a cell libaom never probes -- and can even vote. | |
| 265 | + /// Measured on the 512x384 `testsrc2` cq45 `--enable-tx-size-search=0` | |
| 266 | + /// arm: at `mi(84,104)` the row scan's extended offset `-3` over-reached | |
| 267 | + /// from `(81,106)` (libaom's last probe, an 8x16 intrabc voting | |
| 268 | + /// `-520`) to `(81,108)` (a 16x16 intrabc voting `-512` with a 16-wide | |
| 269 | + /// weight), flipping the sorted stack so `nearestmv` became `-512` where | |
| 270 | + /// libaom's is `-520` -- one whole-pel-wrong DV predictor, identical | |
| 271 | + /// coded diff, 528 wrong luma samples. | |
| 272 | + /// | |
| 273 | + /// `[0, 0]` means "no block recorded here" and reads as uncovered, so | |
| 274 | + /// every grid that never fills this map (the tile writer's own, and | |
| 275 | + /// every synthetic test grid) keeps exactly its old `None`-per-cell | |
| 276 | + /// behaviour. | |
| 277 | + cover: Vec<[u8; 2]>, | |
| 254 | 278 | /// One `skip` flag per cell, beside `cells` rather than inside `MiInfo` |
| 255 | 279 | /// -- the mv-stack scan walks `cells` for every inter block, so the CELL |
| 256 | 280 | /// must stay 16 bytes (`mi_info_cell_stays_compact`), and nothing on the |
| @@ -287,6 +311,7 @@ impl MiGrid { | ||
| 287 | 311 | cols, |
| 288 | 312 | rows, |
| 289 | 313 | cells: vec![None; cols * rows], |
| 314 | + cover: vec![[0, 0]; cols * rows], | |
| 290 | 315 | skips: vec![false; cols * rows], |
| 291 | 316 | tile_row0: 0, |
| 292 | 317 | tile_col0: 0, |
| @@ -415,8 +440,33 @@ impl MiGrid { | ||
| 415 | 440 | } |
| 416 | 441 | } |
| 417 | 442 | |
| 443 | + /// Records the `w_mi` x `h_mi` footprint of the coded block at | |
| 444 | + /// `(row, col)` in this grid's block-coverage map (see `cover`) -- called | |
| 445 | + /// for EVERY coded block, not just the ones that carry an MV. Out-of-range | |
| 446 | + /// coordinates are a no-op, and an overhanging width is clipped to the | |
| 447 | + /// grid (the recorded width still names the block's real one, exactly as | |
| 448 | + /// `mi_size_wide[bsize]` does). | |
| 449 | + pub fn cover_rect(&mut self, row: usize, col: usize, w_mi: usize, h_mi: usize) { | |
| 450 | + if row >= self.rows || col >= self.cols || w_mi == 0 || h_mi == 0 { | |
| 451 | + return; | |
| 452 | + } | |
| 453 | + let w = w_mi.min(self.cols - col); | |
| 454 | + let cell = [w_mi as u8, h_mi as u8]; | |
| 455 | + for r in row..(row + h_mi).min(self.rows) { | |
| 456 | + let base = r * self.cols + col; | |
| 457 | + self.cover[base..base + w].fill(cell); | |
| 458 | + } | |
| 459 | + } | |
| 460 | + | |
| 418 | 461 | /// The unit at `(row, col)`, or `None` when it is outside the grid, hasn't |
| 419 | 462 | /// been coded, or sits outside the current tile's own bounds ([`Self::set_tile_bounds`]). |
| 463 | + /// | |
| 464 | + /// A cell that holds no MV but IS covered by a recorded block | |
| 465 | + /// ([`Self::cover_rect`]) reads as that block's own footprint with | |
| 466 | + /// `is_inter == false` -- libaom's `xd->mi[]` always holds an | |
| 467 | + /// `MB_MODE_INFO`, and a candidate that casts no vote still advances the | |
| 468 | + /// scan by its own width. Such an entry can never match | |
| 469 | + /// (`single_ref_match` rejects a non-inter unit) and carries a zero MV. | |
| 420 | 470 | pub fn get(&self, row: usize, col: usize) -> Option<MiInfo> { |
| 421 | 471 | if row < self.rows |
| 422 | 472 | && col < self.cols |
| @@ -425,10 +475,28 @@ impl MiGrid { | ||
| 425 | 475 | && col >= self.tile_col0 |
| 426 | 476 | && col < self.tile_col1 |
| 427 | 477 | { |
| 428 | - self.cells[row * self.cols + col] | |
| 429 | - } else { | |
| 430 | - None | |
| 478 | + let idx = row * self.cols + col; | |
| 479 | + if let Some(info) = self.cells[idx] { | |
| 480 | + return Some(info); | |
| 481 | + } | |
| 482 | + let [w, h] = self.cover[idx]; | |
| 483 | + if w == 0 { | |
| 484 | + return None; | |
| 485 | + } | |
| 486 | + return Some(MiInfo { | |
| 487 | + is_inter: false, | |
| 488 | + ref_frame: 0, | |
| 489 | + ref_frame1: NO_REF1, | |
| 490 | + mv: (0, 0), | |
| 491 | + mv1: (0, 0), | |
| 492 | + is_new_mv: false, | |
| 493 | + is_global_mv0: false, | |
| 494 | + is_global_mv1: false, | |
| 495 | + size: w, | |
| 496 | + size_h: h, | |
| 497 | + }); | |
| 431 | 498 | } |
| 499 | + None | |
| 432 | 500 | } |
| 433 | 501 | |
| 434 | 502 | /// The unit at `(row, col)` ignoring the tile window -- the frame-level |
crates/ec-av1/src/stream.rsmodified+167 -0
| @@ -6469,6 +6469,173 @@ pub(crate) mod tests { | ||
| 6469 | 6469 | ); |
| 6470 | 6470 | } |
| 6471 | 6471 | |
| 6472 | + /// lane-av1-intrabc r4: the reviewer's unblock witness for the rect-strip | |
| 6473 | + /// reconstruction -- a CODED `use_intrabc` block (so its residual reader | |
| 6474 | + /// runs, not just the prediction copy) on a 2:1 strip in BOTH | |
| 6475 | + /// orientations, plus the `TX_MODE_SELECT` (var-tx) shape, every arm | |
| 6476 | + /// byte-exact against ffmpeg. | |
| 6477 | + /// | |
| 6478 | + /// The orientation counters (`intrabc_rect_coded_hits`) are the | |
| 6479 | + /// non-vacuity instrument: [`intrabc_rect_hits`] counts neither the skip | |
| 6480 | + /// flag nor the orientation, so an arm that silently became an all-skip | |
| 6481 | + /// stream (or a stream with only one orientation) would keep the old gate | |
| 6482 | + /// green while the coded residual path went untested | |
| 6483 | + /// (class `gate-blind-to-feature`). | |
| 6484 | + /// | |
| 6485 | + /// # The VERT arm is also the DV-PREDICTOR regression witness | |
| 6486 | + /// | |
| 6487 | + /// The 512x384 arm is the stream that exposed r4's defect: 528 of 294912 | |
| 6488 | + /// luma samples were wrong, all inside one `skip == 1` intrabc copy at | |
| 6489 | + /// `mi(84,104)`. Its coded diff was identical to aomdec's and the post-read | |
| 6490 | + /// range matched exactly (`rng=33207` both), so nothing was misread -- the | |
| 6491 | + /// DV PREDICTOR differed. libaom picks `nearestmv` (`-520`) from the | |
| 6492 | + /// `INTRA_FRAME` MV stack; this decoder picked `-512`, one stack entry | |
| 6493 | + /// lower, because the scan that builds that stack walked further than | |
| 6494 | + /// libaom's. The scans step by the candidate BLOCK's own width | |
| 6495 | + /// (`mi_size_wide[bsize]`) over `xd->mi[]`, which holds an entry for every | |
| 6496 | + /// coded block; this decoder's MV grid held only the intrabc blocks, so a | |
| 6497 | + /// non-intrabc neighbour read as uncovered and the scan advanced that cell | |
| 6498 | + /// by one instead of by its real width. See `MiGrid::cover` for the | |
| 6499 | + /// measured walk. A stream that decodes the DV predictor from the wrong | |
| 6500 | + /// stack entry cannot pass this arm's pixel comparison. | |
| 6501 | + #[test] | |
| 6502 | + fn a_coded_rect_intrabc_block_reconstructs_in_both_orientations() { | |
| 6503 | + const NAME: &str = "a_coded_rect_intrabc_block_reconstructs_in_both_orientations"; | |
| 6504 | + if !have_ffmpeg() { | |
| 6505 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 6506 | + return; | |
| 6507 | + } | |
| 6508 | + if !have_aomenc() { | |
| 6509 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | |
| 6510 | + return; | |
| 6511 | + } | |
| 6512 | + const TS256: &str = "testsrc2=s=256x192:r=25"; | |
| 6513 | + const TS512: &str = "testsrc2=s=512x384:r=25"; | |
| 6514 | + // (arm, source, width, height, per-arm overrides, the coded orientation | |
| 6515 | + // this arm must exercise, and whether the frame must code | |
| 6516 | + // `TX_MODE_SELECT` with `allow_intrabc` still set) | |
| 6517 | + let arms: [(&str, &str, usize, usize, &[&str], u8, bool); 3] = [ | |
| 6518 | + // HORZ (16x8) coded strip -- the shape the in-gate witness above | |
| 6519 | + // already reconstructs, pinned here with its own orientation counter. | |
| 6520 | + ("horz-coded-256-cq45-pal0-txs0", TS256, 256, 192, &["--cq-level=45", "--enable-palette=0", "--enable-tx-size-search=0"], 0, false), | |
| 6521 | + // VERT (8x16) coded strip AND the DV-predictor regression stream. | |
| 6522 | + ("vert-coded-512-cq45-pal1-txs0", TS512, 512, 384, &["--cq-level=45", "--enable-palette=1", "--enable-tx-size-search=0"], 1, false), | |
| 6523 | + // The `TX_MODE_SELECT` (stream A) shape: `--enable-tx-size-search=1` | |
| 6524 | + // makes the frame code `tx_mode == Select`, so the intrabc block's | |
| 6525 | + // transform size comes off the INTER var-tx tree. | |
| 6526 | + ("txmode-select-256-cq45-pal0-txs1", TS256, 256, 192, &["--cq-level=45", "--enable-palette=0", "--enable-tx-size-search=1"], 0, true), | |
| 6527 | + ]; | |
| 6528 | + let mut coded_total = [0usize; 2]; | |
| 6529 | + let mut frames_compared = 0usize; | |
| 6530 | + for (arm, src, width, height, extra, want_orient, want_select) in &arms { | |
| 6531 | + let render = || { | |
| 6532 | + let out = Command::new("ffmpeg") | |
| 6533 | + .args([ | |
| 6534 | + "-v", "error", "-f", "lavfi", "-i", *src, "-t", "0.2", "-pix_fmt", | |
| 6535 | + "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-", | |
| 6536 | + ]) | |
| 6537 | + .stdin(Stdio::null()) | |
| 6538 | + .stdout(Stdio::piped()) | |
| 6539 | + .stderr(Stdio::piped()) | |
| 6540 | + .output() | |
| 6541 | + .expect("ffmpeg failed to run"); | |
| 6542 | + assert!(out.status.success(), "{NAME}: ffmpeg failed for {arm}"); | |
| 6543 | + out.stdout | |
| 6544 | + }; | |
| 6545 | + let y4m = render(); | |
| 6546 | + let mut child = Command::new(aomenc_path()) | |
| 6547 | + .args([ | |
| 6548 | + "--codec=av1", | |
| 6549 | + "--bit-depth=8", | |
| 6550 | + "--input-bit-depth=8", | |
| 6551 | + "--passes=1", | |
| 6552 | + "--end-usage=q", | |
| 6553 | + "--cpu-used=0", | |
| 6554 | + "--lag-in-frames=0", | |
| 6555 | + "--kf-max-dist=1", | |
| 6556 | + "--limit=1", | |
| 6557 | + "--threads=1", | |
| 6558 | + "--tile-columns=0", | |
| 6559 | + "--enable-rect-partitions=1", | |
| 6560 | + "--enable-1to4-partitions=1", | |
| 6561 | + "--min-partition-size=8", | |
| 6562 | + "--max-partition-size=32", | |
| 6563 | + "--sb-size=64", | |
| 6564 | + "--tune-content=screen", | |
| 6565 | + "--enable-intrabc=1", | |
| 6566 | + ]) | |
| 6567 | + // aomenc keeps the LAST occurrence of a repeated flag. | |
| 6568 | + .args(*extra) | |
| 6569 | + .args(["--obu", "-o", "-", "-"]) | |
| 6570 | + .stdin(Stdio::piped()) | |
| 6571 | + .stdout(Stdio::piped()) | |
| 6572 | + .stderr(Stdio::piped()) | |
| 6573 | + .spawn() | |
| 6574 | + .expect("aomenc failed to start"); | |
| 6575 | + child | |
| 6576 | + .stdin | |
| 6577 | + .take() | |
| 6578 | + .expect("aomenc stdin") | |
| 6579 | + .write_all(&y4m) | |
| 6580 | + .or_else(|e| match e.kind() { | |
| 6581 | + std::io::ErrorKind::BrokenPipe => Ok(()), | |
| 6582 | + _ => Err(e), | |
| 6583 | + }) | |
| 6584 | + .expect("writing y4m to aomenc"); | |
| 6585 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 6586 | + assert!( | |
| 6587 | + out.status.success(), | |
| 6588 | + "{NAME}: aomenc refused {arm}: {}", | |
| 6589 | + String::from_utf8_lossy(&out.stderr) | |
| 6590 | + ); | |
| 6591 | + let stream = out.stdout; | |
| 6592 | + if *want_select { | |
| 6593 | + let (select, premise) = tx_select_and_intrabc_frames(&stream); | |
| 6594 | + assert!( | |
| 6595 | + select > 0 && premise > 0, | |
| 6596 | + "{NAME}: {arm} no longer codes a frame with both tx_mode == Select and \ | |
| 6597 | + allow_intrabc (select={select} premise={premise}), so the TX_MODE_SELECT \ | |
| 6598 | + shape is untested here" | |
| 6599 | + ); | |
| 6600 | + } | |
| 6601 | + crate::decode::reset_intrabc_rect_hits(); | |
| 6602 | + let frames = decode_stream(&stream) | |
| 6603 | + .unwrap_or_else(|e| panic!("{NAME}: {arm} refused: {e}")); | |
| 6604 | + assert!(!frames.is_empty(), "{NAME}: {arm} decoded no frame"); | |
| 6605 | + let coded = crate::decode::intrabc_rect_coded_hits(); | |
| 6606 | + coded_total[0] += coded[0]; | |
| 6607 | + coded_total[1] += coded[1]; | |
| 6608 | + assert!( | |
| 6609 | + coded[*want_orient as usize] > 0, | |
| 6610 | + "{NAME}: {arm} reconstructed no CODED ({}) rect intrabc block -- the residual \ | |
| 6611 | + reader for this orientation is untested (coded horz/vert = {coded:?})", | |
| 6612 | + if *want_orient == 0 { "HORZ" } else { "VERT" } | |
| 6613 | + ); | |
| 6614 | + let theirs = ffmpeg_decode_sequence(&stream, *width, *height, frames.len()); | |
| 6615 | + assert_eq!(frames.len(), theirs.len(), "{NAME}: {arm} frame count"); | |
| 6616 | + for (i, (ours, ref_frame)) in frames.iter().zip(theirs.iter()).enumerate() { | |
| 6617 | + assert!( | |
| 6618 | + ours.y == ref_frame.y && ours.u == ref_frame.u && ours.v == ref_frame.v, | |
| 6619 | + "{NAME}: {arm} frame {i} does not match ffmpeg" | |
| 6620 | + ); | |
| 6621 | + frames_compared += 1; | |
| 6622 | + } | |
| 6623 | + eprintln!( | |
| 6624 | + "{NAME}: {arm} {} frame(s) exact, coded rect intrabc horz={} vert={}", | |
| 6625 | + frames.len(), | |
| 6626 | + coded[0], | |
| 6627 | + coded[1] | |
| 6628 | + ); | |
| 6629 | + } | |
| 6630 | + assert!( | |
| 6631 | + coded_total[0] > 0 && coded_total[1] > 0, | |
| 6632 | + "{NAME}: gate is vacuous -- coded rect intrabc blocks seen: horz={} vert={}", | |
| 6633 | + coded_total[0], | |
| 6634 | + coded_total[1] | |
| 6635 | + ); | |
| 6636 | + assert!(frames_compared > 0, "{NAME}: no frame was compared pixel-exact"); | |
| 6637 | + } | |
| 6638 | + | |
| 6472 | 6639 | /// lane-t900 r31: builds one `--tune-content=screen --enable-intrabc=1` |
| 6473 | 6640 | /// key frame, 256x192 8-bit, from a deterministic lavfi source. `tiled` |
| 6474 | 6641 | /// renders a 2x2 tiling of a 128x96 pattern -- exact spatial repetition, |
lanes/av1intrabc.report.mdmodified+130 -3
| @@ -31,9 +31,12 @@ In-gate (flipped pin -> witness): `stream::tests:: | ||
| 31 | 31 | a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips`. Its |
| 32 | 32 | `testsrc2-cq50-txs0` arm used to stop at the rect-strip refusal; it now decodes |
| 33 | 33 | 1 frame, **1 intrabc block on a HORZ/VERT rect strip**, pixel-exact vs ffmpeg. |
| 34 | -Gate totals (re-measured, reviewer-corrected): **2** intrabc blocks over **2** | |
| 35 | -arms -- 4 arms decode ZERO intrabc blocks (out of scope), 187 rect | |
| 36 | -`use_intrabc` reads, 8 frames compared, 0 mismatches, 0 named refusals. | |
| 34 | +Gate totals (re-measured at r4, on the committed tree): **5** intrabc blocks | |
| 35 | +over **5** arms -- 3 arms decode ZERO intrabc blocks (out of scope), 187 rect | |
| 36 | +`use_intrabc` reads, 8 frames compared, 0 mismatches, 0 named refusals, 1 | |
| 37 | +intrabc block on a HORZ/VERT rect strip. The r4 gate | |
| 38 | +`a_coded_rect_intrabc_block_reconstructs_in_both_orientations` adds 3 more | |
| 39 | +byte-exact frames (HORZ coded, VERT coded, TX_MODE_SELECT). | |
| 37 | 40 | |
| 38 | 41 | Standalone recipes (aomenc oracle at `~/.cache/aom-oracle/build/aomenc`, probe |
| 39 | 42 | `cargo run --release -p ec-av1 --example decode_probe -- <obu>`): |
| @@ -240,3 +243,127 @@ ORDER/WEIGHT, not the DV syntax. | ||
| 240 | 243 | TX_MODE_SELECT gate is still red); the batch-level suite run stays deferred. |
| 241 | 244 | |
| 242 | 245 | `deferred(DV-predictor candidate ordering at mi(84,104))` |
| 246 | + | |
| 247 | +## 4d. Round 4 (2026-09-20) -- the DV predictor's root cause is BLOCK COVERAGE, not candidate weighting; stream B is byte-exact | |
| 248 | + | |
| 249 | +The remaining defect was localized to a single wrong DV at `mi(84,104)` on the | |
| 250 | +512x384 stream, with identical coded diff and identical post-read range. The | |
| 251 | +task named candidate ORDER/WEIGHT; the order was indeed wrong, but the cause is | |
| 252 | +one level down: **our intrabc MV grid only contained the intrabc blocks.** | |
| 253 | + | |
| 254 | +### Mechanism (measured, not inferred) | |
| 255 | + | |
| 256 | +libaom's `setup_ref_mv_list` row/col scans walk `xd->mi[]`, which holds an | |
| 257 | +`MB_MODE_INFO` for EVERY coded block, and step by | |
| 258 | +`mi_size_wide/height[candidate->bsize]`. Our `MiGrid` was filled only by | |
| 259 | +`record_intrabc_mi_rect`, so every intra non-intrabc neighbour read as | |
| 260 | +`None` and the scan advanced that cell by ONE instead of by the neighbour's | |
| 261 | +real width. At `mi(84,104)` (16x16, `bsize=6`) the row scan's extended offset | |
| 262 | +`-3` therefore over-reached from libaom's last probe `(81,106)` (the 8x16 | |
| 263 | +intrabc voting `-520`) to `(81,108)` -- a 16x16 intrabc voting `-512` with a | |
| 264 | +16-wide (`len 4 * weight 4`) contribution libaom never makes. | |
| 265 | + | |
| 266 | +Instrumented oracle (`~/.cache/aom-oracle`, new `EC_TRACE_STACK` / | |
| 267 | +`EC_TRACE_STACK2` prints in `setup_ref_mv_list` + `scan_row_mbmi` / | |
| 268 | +`scan_col_mbmi` / `scan_blk_mbmi`): | |
| 269 | + | |
| 270 | +``` | |
| 271 | +O EC_STACK mi_row=84 mi_col=104 ref=0 w=4 h=4 cnt=2 near_match=1 ref_match=1 \ | |
| 272 | + [0 w=656 mv=(-520,0)] [1 w=648 mv=(-512,0)] | |
| 273 | +U EC_STACK_OURS mi_row=84 mi_col=104 ... n=2 near_match=1 ref_match=1 prows=6 pcols=0 | |
| 274 | + [0 w=648 mv=(-520,0)] [1 w=664 mv=(-512,0)] | |
| 275 | +``` | |
| 276 | + | |
| 277 | +libaom's `-520` votes: `4` (row `-1`) + `4` (row `-3`) + `8` (row `-5`) = `16` | |
| 278 | +(`640 + 16 = 656`); `-512`'s: `4` (top-right `(83,108)`) + `4` (corner | |
| 279 | +`(83,103)`) = `8` (`648`). Ours lost `-520`'s `8` (the row `-5` contribution) | |
| 280 | +and gained `-512` `+16` from the over-reach, so the weight sort flipped: | |
| 281 | +`nearestmv` became `-512` where libaom's is `-520`, and | |
| 282 | +`dv = ref + diff = -512 + 8 = -504` instead of `-520 + 8 = -512`. One whole-pel | |
| 283 | +wrong `skip == 1` copy; the 528 wrong luma samples are that copy plus the | |
| 284 | +region that inherits its 1-px shift. | |
| 285 | + | |
| 286 | +### Fix | |
| 287 | + | |
| 288 | +`MiGrid` gained a block-COVERAGE map (`cover: Vec<[u8; 2]>`, the covering | |
| 289 | +coded block's own `(width, height)` in mi units) with `MiGrid::cover_rect`; | |
| 290 | +`MiGrid::get` returns the stored `MiInfo` when there is one and otherwise | |
| 291 | +synthesizes a non-inter entry (`is_inter == false`, zero MV) from the cover, so | |
| 292 | +a candidate that casts no vote still advances the scan by its real width -- | |
| 293 | +exactly libaom's `xd->mi[]` semantics. `single_ref_match` rejects a non-inter | |
| 294 | +unit, so a synthetic entry can never vote. | |
| 295 | + | |
| 296 | +The map is published for EVERY coded block from `Neighbours::fill_lf_grid_rect` | |
| 297 | +(the one place every block's mi span already passes through, paired 1:1 with | |
| 298 | +`fill_skip_grid_rect`), and only when the frame has an MV grid at all | |
| 299 | +(`intrabc_mi_grid` is `Some` exactly when `allow_intrabc`), so an inter frame | |
| 300 | +and the tile writer's own grid are untouched: an unfilled cover reads as | |
| 301 | +uncovered and reproduces the old `None`-per-cell behaviour exactly. | |
| 302 | + | |
| 303 | +### Byte-exactness after the fix | |
| 304 | + | |
| 305 | +| stream | before | now | | |
| 306 | +|---|---|---| | |
| 307 | +| B 512x384 testsrc2 cq45 `--enable-palette=1 --enable-tx-size-search=0` | 528/294912 luma | **BYTE-EXACT** (`cmp` vs ffmpeg `-pix_fmt yuv420p`) | | |
| 308 | +| A 256x192 testsrc2 cq45 var-tx (`--enable-tx-size-search=1`) | BYTE-EXACT | **BYTE-EXACT** | | |
| 309 | + | |
| 310 | +Standalone arms re-run (all `cmp`-exact against ffmpeg): `cq50p0-txs0`, | |
| 311 | +`cq45p0-txs0`, `cq45p1-txs0`, `cq50p0-txs0`, `cq50p0-1to4-off`, `minp4` | |
| 312 | +(`--min-partition-size=4 --max-partition-size=16`), `cq50-txs1-1to4-off`. The | |
| 313 | +`(84,104)` DV trace now reads `dv_row=-512 rng=33207`, the oracle's own value. | |
| 314 | + | |
| 315 | +### New reviewer-unblock gate | |
| 316 | + | |
| 317 | +`stream::tests::a_coded_rect_intrabc_block_reconstructs_in_both_orientations` | |
| 318 | +-- three arms, ALL frames byte-exact against ffmpeg, each asserting the arm | |
| 319 | +reconstructed a CODED (`skip == 0`) rect intrabc block in the orientation it | |
| 320 | +names: | |
| 321 | + | |
| 322 | +- `horz-coded-256-cq45-pal0-txs0` -- 16x8 coded strip, HORZ. | |
| 323 | +- `vert-coded-512-cq45-pal1-txs0` -- 8x16 coded strip, VERT, **and the | |
| 324 | + DV-predictor regression stream** (this is stream B). | |
| 325 | +- `txmode-select-256-cq45-pal0-txs1` -- stream A's shape; the arm re-derives | |
| 326 | + `tx_mode == Select && allow_intrabc` out of the frame header rather than | |
| 327 | + trusting the encoder flags. | |
| 328 | + | |
| 329 | +New instrument `decode::intrabc_rect_coded_hits() -> [horz, vert]` (bumped in | |
| 330 | +`decode_intrabc_rect` when `!skip`, indexed by `bh > bw`): the old | |
| 331 | +`intrabc_rect_hits` counts neither the skip flag nor the orientation, so an arm | |
| 332 | +that quietly became all-skip or single-orientation would keep it green | |
| 333 | +(`gate-blind-to-feature`). | |
| 334 | + | |
| 335 | +**Non-vacuity (fail-pre-fix, measured):** with only the `MiGrid::get` cover | |
| 336 | +fallback neutralized (the fix's load-bearing line) and nothing else touched, | |
| 337 | +the gate fails exactly where it must -- | |
| 338 | + | |
| 339 | +``` | |
| 340 | +horz-coded-256-cq45-pal0-txs0 ... exact, coded rect intrabc horz=1 vert=0 | |
| 341 | +vert-coded-512-cq45-pal1-txs0 frame 0 does not match ffmpeg | |
| 342 | +test ... FAILED | |
| 343 | +``` | |
| 344 | + | |
| 345 | +and passes again with the line restored. | |
| 346 | + | |
| 347 | +### Gates run this round | |
| 348 | + | |
| 349 | +- `cargo check -p ec-av1 --all-targets` -> 0 warnings. | |
| 350 | +- New gate (3 arms, 3 frames, byte-exact; fail-pre-fix proven above). | |
| 351 | +- `a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips` -> ok | |
| 352 | + (187 rect reads, 5 intrabc blocks over 5 arms, 8 frames compared, 0 | |
| 353 | + refused, 0 mismatched, 1 rect-strip block). | |
| 354 | +- `an_intrabc_block_under_tx_mode_select_decodes_pixel_exact` -> ok | |
| 355 | + (cq30 16 blocks / 1 var-tx, cq45 12 blocks / 3 var-tx). | |
| 356 | +- Refusal suite `-- refusal` -> **21 passed**. `reelb` -> 3 passed. | |
| 357 | + `monochrome` -> 1 passed. `cdf` -> 13 passed. `non_420` -> 1 passed. | |
| 358 | +- Full `--lib` suite: FILLED IN BELOW by the round-4 batch run on the committed tree. | |
| 359 | + | |
| 360 | +### Deferred / open | |
| 361 | + | |
| 362 | +- 1:4 pair-strip intrabc -- unchanged, named in §3. | |
| 363 | +- The cover records the mi span its `fill_lf_grid_rect` caller passes; a | |
| 364 | + sub-8x8 leaf publishes a 4x4 (1x1 mi) or an 8x8-square span exactly as its | |
| 365 | + own `fill_skip_grid`/`fill_lf_grid` call already does, so the coverage map | |
| 366 | + inherits that convention. No gate or arm reaches a sub-8x8 neighbour of an | |
| 367 | + intrabc block today; if one ever does, the leaf's true `bsize` dims are what | |
| 368 | + libaom's `mi_size_wide/height[candidate->bsize]` would report. | |
| 369 | + |