ec-av1: rect intrabc r5 -- skipped-strip residual stride is side, not bw*bh
Browse files at this commit226d2c8fdfd5227e8075f47ef35034ef33f26888Parent: 18f1d152 changed files +148 -6
- crates/ec-av1/src/decode.rs +30 -6
- crates/ec-av1/src/stream.rs +118 -0
crates/ec-av1/src/decode.rsmodified+30 -6
| @@ -3734,6 +3734,13 @@ thread_local! { | ||
| 3734 | 3734 | /// to an all-skip stream (no residual reader at all) would stay green. |
| 3735 | 3735 | static INTRABC_RECT_CODED_HITS: std::cell::Cell<[usize; 2]> = |
| 3736 | 3736 | const { std::cell::Cell::new([0, 0]) }; |
| 3737 | + /// lane-av1-intrabc r5: the `skip == 1` twin of [`INTRABC_RECT_CODED_HITS`] | |
| 3738 | + /// -- rect INTRABC blocks reconstructed as a bare prediction copy, split | |
| 3739 | + /// by orientation. The r5 panic (residual stride `bw * bh` underrunning | |
| 3740 | + /// `reconstruct_mc_rect`'s `row * side + w` index on a VERT strip) was | |
| 3741 | + /// invisible to every gate because they only counted CODED strips. | |
| 3742 | + static INTRABC_RECT_SKIPPED_HITS: std::cell::Cell<[usize; 2]> = | |
| 3743 | + const { std::cell::Cell::new([0, 0]) }; | |
| 3737 | 3744 | } |
| 3738 | 3745 | |
| 3739 | 3746 | /// lane-av1-intrabc r4: coded (`skip == 0`) rect intrabc blocks reconstructed, |
| @@ -3743,6 +3750,13 @@ pub fn intrabc_rect_coded_hits() -> [usize; 2] { | ||
| 3743 | 3750 | INTRABC_RECT_CODED_HITS.with(std::cell::Cell::get) |
| 3744 | 3751 | } |
| 3745 | 3752 | |
| 3753 | +/// lane-av1-intrabc r5: skipped (`skip == 1`) rect intrabc blocks | |
| 3754 | +/// reconstructed, as `[horz, vert]` -- see [`INTRABC_RECT_SKIPPED_HITS`]. | |
| 3755 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | |
| 3756 | +pub fn intrabc_rect_skipped_hits() -> [usize; 2] { | |
| 3757 | + INTRABC_RECT_SKIPPED_HITS.with(std::cell::Cell::get) | |
| 3758 | +} | |
| 3759 | + | |
| 3746 | 3760 | /// Current value of [`INTRABC_RECT_HITS`]. |
| 3747 | 3761 | #[allow(dead_code)] // read only from the `#[cfg(test)]` gates |
| 3748 | 3762 | pub fn intrabc_rect_hits() -> usize { |
| @@ -3755,6 +3769,7 @@ pub(crate) fn reset_intrabc_rect_hits() { | ||
| 3755 | 3769 | INTRABC_RECT_HITS.with(|c| c.set(0)); |
| 3756 | 3770 | INTRABC_RECT_VARTX_HITS.with(|c| c.set(0)); |
| 3757 | 3771 | INTRABC_RECT_CODED_HITS.with(|c| c.set([0, 0])); |
| 3772 | + INTRABC_RECT_SKIPPED_HITS.with(|c| c.set([0, 0])); | |
| 3758 | 3773 | } |
| 3759 | 3774 | |
| 3760 | 3775 | /// Current value of [`INTRABC_RECT_VARTX_HITS`]. |
| @@ -10962,9 +10977,15 @@ fn decode_intrabc_rect( | ||
| 10962 | 10977 | fctx: &crate::decode::FrameCtx, |
| 10963 | 10978 | ) -> Result<()> { |
| 10964 | 10979 | hit!(INTRABC_RECT_HITS); |
| 10965 | - if !skip { | |
| 10966 | - // [horz, vert]: see `INTRABC_RECT_CODED_HITS`. | |
| 10967 | - let idx = usize::from(bh > bw); | |
| 10980 | + // [horz, vert]: see `INTRABC_RECT_CODED_HITS` / `INTRABC_RECT_SKIPPED_HITS`. | |
| 10981 | + let idx = usize::from(bh > bw); | |
| 10982 | + if skip { | |
| 10983 | + INTRABC_RECT_SKIPPED_HITS.with(|c| { | |
| 10984 | + let mut seen = c.get(); | |
| 10985 | + seen[idx] += 1; | |
| 10986 | + c.set(seen); | |
| 10987 | + }); | |
| 10988 | + } else { | |
| 10968 | 10989 | INTRABC_RECT_CODED_HITS.with(|c| { |
| 10969 | 10990 | let mut seen = c.get(); |
| 10970 | 10991 | seen[idx] += 1; |
| @@ -11044,9 +11065,12 @@ fn decode_intrabc_rect( | ||
| 11044 | 11065 | let (luma_grid, u_grid, v_grid); |
| 11045 | 11066 | if skip { |
| 11046 | 11067 | // No residual syntax at all: the prediction IS the block. |
| 11047 | - push_mc_rect(0, px, py, side, bw, bh, Pred::Inline(&pred_y, side), &ZERO_RESIDUAL[..bw * bh], fctx); | |
| 11048 | - push_mc_rect(1, cpx, cpy, cside, cw, ch, Pred::Inline(&pred_u, cside), &ZERO_RESIDUAL[..cw * ch], fctx); | |
| 11049 | - push_mc_rect(2, cpx, cpy, cside, cw, ch, Pred::Inline(&pred_v, cside), &ZERO_RESIDUAL[..cw * ch], fctx); | |
| 11068 | + // Residual stride is `side` (and `cside`), not `bw`: reconstruct_mc_rect indexes | |
| 11069 | + // `residual[row * side .. row*side + w]` for row in 0..h, so a skipped VERT strip | |
| 11070 | + // (bh > bw) overruns a `bw * bh` slice. Bug-for-bug with the inter skip arm. | |
| 11071 | + push_mc_rect(0, px, py, side, bw, bh, Pred::Inline(&pred_y, side), &ZERO_RESIDUAL[..side * side], fctx); | |
| 11072 | + push_mc_rect(1, cpx, cpy, cside, cw, ch, Pred::Inline(&pred_u, cside), &ZERO_RESIDUAL[..cside * cside], fctx); | |
| 11073 | + push_mc_rect(2, cpx, cpy, cside, cw, ch, Pred::Inline(&pred_v, cside), &ZERO_RESIDUAL[..cside * cside], fctx); | |
| 11050 | 11074 | luma_tx_type = TxType::DctDct; |
| 11051 | 11075 | luma_grid = Grid::Zero(side * side); |
| 11052 | 11076 | u_grid = Grid::Zero(cside * cside); |
crates/ec-av1/src/stream.rsmodified+118 -0
| @@ -6634,6 +6634,124 @@ pub(crate) mod tests { | ||
| 6634 | 6634 | coded_total[1] |
| 6635 | 6635 | ); |
| 6636 | 6636 | assert!(frames_compared > 0, "{NAME}: no frame was compared pixel-exact"); |
| 6637 | + | |
| 6638 | + // lane-av1-intrabc r5: the SKIPPED VERT 2:1 strip -- the arm the | |
| 6639 | + // reviewer's sweep panicked on (a skipped 8x32 strip passed a | |
| 6640 | + // `bw * bh`-sized ZERO_RESIDUAL slice at stride `side`, and | |
| 6641 | + // `reconstruct_mc_rect` indexed `row * side + w` past its end). | |
| 6642 | + // Skip-heavy recipes (low cq, palette off AND on), each decoded | |
| 6643 | + // byte-exact vs ffmpeg on BOTH the default single-threaded path | |
| 6644 | + // (`EC_AV1_RECON_THREADS == 1`, the inline ReconPlanes arm that | |
| 6645 | + // panicked pre-fix) AND the wavefront path. The skipped-orientation | |
| 6646 | + // counter is asserted per arm (`gate-blind-to-feature`): a recipe | |
| 6647 | + // that stops producing a skipped VERT strip fails instead of passing | |
| 6648 | + // vacuously. `lock_gate_counters` because `set_recon_threads` is a | |
| 6649 | + // process-wide knob. | |
| 6650 | + let _par_lock = lock_gate_counters(); | |
| 6651 | + let skip_arms: [(&str, &str, usize, usize, &[&str]); 2] = [ | |
| 6652 | + ("vert-skip-512-cq30-pal0-txs0", TS512, 512, 384, &["--cq-level=30", "--enable-palette=0", "--enable-tx-size-search=0"]), | |
| 6653 | + ("vert-skip-512-cq30-pal1-txs0", TS512, 512, 384, &["--cq-level=30", "--enable-palette=1", "--enable-tx-size-search=0"]), | |
| 6654 | + ]; | |
| 6655 | + for (arm, src, width, height, extra) in &skip_arms { | |
| 6656 | + let y4m = { | |
| 6657 | + let out = Command::new("ffmpeg") | |
| 6658 | + .args([ | |
| 6659 | + "-v", "error", "-f", "lavfi", "-i", *src, "-t", "0.2", "-pix_fmt", | |
| 6660 | + "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-", | |
| 6661 | + ]) | |
| 6662 | + .stdin(Stdio::null()) | |
| 6663 | + .stdout(Stdio::piped()) | |
| 6664 | + .stderr(Stdio::piped()) | |
| 6665 | + .output() | |
| 6666 | + .expect("ffmpeg failed to run"); | |
| 6667 | + assert!(out.status.success(), "{NAME}: ffmpeg failed for {arm}"); | |
| 6668 | + out.stdout | |
| 6669 | + }; | |
| 6670 | + let mut child = Command::new(aomenc_path()) | |
| 6671 | + .args([ | |
| 6672 | + "--codec=av1", "--bit-depth=8", "--input-bit-depth=8", "--passes=1", | |
| 6673 | + "--end-usage=q", "--cpu-used=0", "--lag-in-frames=0", "--kf-max-dist=1", | |
| 6674 | + "--limit=1", "--threads=1", "--tile-columns=0", | |
| 6675 | + "--enable-rect-partitions=1", "--enable-1to4-partitions=1", | |
| 6676 | + "--min-partition-size=8", "--max-partition-size=32", "--sb-size=64", | |
| 6677 | + "--tune-content=screen", "--enable-intrabc=1", | |
| 6678 | + ]) | |
| 6679 | + // aomenc keeps the LAST occurrence of a repeated flag. | |
| 6680 | + .args(*extra) | |
| 6681 | + .args(["--obu", "-o", "-", "-"]) | |
| 6682 | + .stdin(Stdio::piped()) | |
| 6683 | + .stdout(Stdio::piped()) | |
| 6684 | + .stderr(Stdio::piped()) | |
| 6685 | + .spawn() | |
| 6686 | + .expect("aomenc failed to start"); | |
| 6687 | + child | |
| 6688 | + .stdin | |
| 6689 | + .take() | |
| 6690 | + .expect("aomenc stdin") | |
| 6691 | + .write_all(&y4m) | |
| 6692 | + .or_else(|e| match e.kind() { | |
| 6693 | + std::io::ErrorKind::BrokenPipe => Ok(()), | |
| 6694 | + _ => Err(e), | |
| 6695 | + }) | |
| 6696 | + .expect("writing y4m to aomenc"); | |
| 6697 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 6698 | + assert!( | |
| 6699 | + out.status.success(), | |
| 6700 | + "{NAME}: aomenc refused {arm}: {}", | |
| 6701 | + String::from_utf8_lossy(&out.stderr) | |
| 6702 | + ); | |
| 6703 | + let stream = out.stdout; | |
| 6704 | + // Default single-threaded path first (the arm that panicked | |
| 6705 | + // pre-fix), then the wavefront path; both must match ffmpeg. | |
| 6706 | + let mut skipped_vert = 0usize; | |
| 6707 | + for threads in [1usize, 4] { | |
| 6708 | + crate::par::set_recon_threads(threads); | |
| 6709 | + crate::decode::reset_intrabc_rect_hits(); | |
| 6710 | + let frames = match decode_stream(&stream) { | |
| 6711 | + Ok(frames) => frames, | |
| 6712 | + Err(e) => { | |
| 6713 | + crate::par::set_recon_threads(1); | |
| 6714 | + panic!("{NAME}: {arm} refused at {threads} recon thread(s): {e}") | |
| 6715 | + } | |
| 6716 | + }; | |
| 6717 | + let skipped = crate::decode::intrabc_rect_skipped_hits(); | |
| 6718 | + assert!( | |
| 6719 | + !frames.is_empty(), | |
| 6720 | + "{NAME}: {arm} decoded no frame at {threads} recon thread(s)" | |
| 6721 | + ); | |
| 6722 | + let theirs = ffmpeg_decode_sequence(&stream, *width, *height, frames.len()); | |
| 6723 | + assert_eq!( | |
| 6724 | + frames.len(), | |
| 6725 | + theirs.len(), | |
| 6726 | + "{NAME}: {arm} frame count at {threads} recon thread(s)" | |
| 6727 | + ); | |
| 6728 | + for (i, (ours, ref_frame)) in frames.iter().zip(theirs.iter()).enumerate() { | |
| 6729 | + assert!( | |
| 6730 | + ours.y == ref_frame.y && ours.u == ref_frame.u && ours.v == ref_frame.v, | |
| 6731 | + "{NAME}: {arm} frame {i} does not match ffmpeg at {threads} recon thread(s)" | |
| 6732 | + ); | |
| 6733 | + } | |
| 6734 | + if threads == 1 { | |
| 6735 | + skipped_vert = skipped[1]; | |
| 6736 | + } else { | |
| 6737 | + assert_eq!( | |
| 6738 | + skipped[1], skipped_vert, | |
| 6739 | + "{NAME}: {arm} skipped VERT strip count changed across recon paths" | |
| 6740 | + ); | |
| 6741 | + } | |
| 6742 | + eprintln!( | |
| 6743 | + "{NAME}: {arm} {} frame(s) exact at {threads} recon thread(s), skipped rect intrabc horz={} vert={}", | |
| 6744 | + frames.len(), | |
| 6745 | + skipped[0], | |
| 6746 | + skipped[1] | |
| 6747 | + ); | |
| 6748 | + } | |
| 6749 | + crate::par::set_recon_threads(1); | |
| 6750 | + assert!( | |
| 6751 | + skipped_vert > 0, | |
| 6752 | + "{NAME}: {arm} reconstructed no SKIPPED VERT rect intrabc strip -- the r5 stride arm is untested" | |
| 6753 | + ); | |
| 6754 | + } | |
| 6637 | 6755 | } |
| 6638 | 6756 | |
| 6639 | 6757 | /// lane-t900 r31: builds one `--tune-content=screen --enable-intrabc=1` |