From 0ef28ca1edfda61419b8809dc91946d00782667a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Sep 2026 02:25:18 +0300 Subject: [PATCH] test(av1): the last two NEVER_ON default-on tools -- forward keyframes and 10-bit interintra-wedge/one-sided compound --enable-fwd-kf=1 --fwd-kf-dist=8 on the altref hidden-frames gate (the only gate that decodes show_frame==0 frames at all, and it runs both bit depths), with a new decode::fwd_kf_hits() counter incremented in decode_stream for a KEY frame coded with show_frame == 0 -- hard-asserted per depth: 42 frames decoded, 2 hidden, 3 forward keyframes, all pixel-exact vs the oracle in decode order at both 8 and 10 bits. Two new 10-bit gates through ten_bit_tool_gate: - a_real_aomenc_10bit_stream_with_interintra_wedge_decodes_pixel_exact (--enable-interintra-wedge=1, 8/8 pixel-exact, wii_hits=3) - a_real_aomenc_10bit_stream_with_onesided_compound_decodes_pixel_exact (--enable-onesided-comp=1, 8/8 pixel-exact, uni_comp_hits=5) NEVER_ON_8BIT is now empty (0 of 10 over 45 gates); NEVER_ON_10BIT is down to enable-diff-wtd-comp (the 10-bit gradients fixture decodes 8/8 pixel-exact with diffwtd_hits == 0 -- encoder choice, it needs mandelbrot content in ten_bit_tool_gate) and multi-tile (covbd2's, not this lane's). --- crates/ec-av1/src/decode.rs | 21 ++++ crates/ec-av1/src/gate_coverage.rs | 21 +--- crates/ec-av1/src/stream.rs | 167 ++++++++++++++++++++++++++++- 3 files changed, 188 insertions(+), 21 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index c9c2926f..f6809e7b 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -755,6 +755,27 @@ pub(crate) fn diffwtd_hits() -> usize { DIFFWTD_HITS.with(|c| c.get()) } +// lane-defon r1: how many FORWARD KEYFRAMES were decoded -- a KEY frame coded +// with `show_frame == 0`, output later by a `show_existing_frame` header +// (aomenc `--enable-fwd-kf=1 --fwd-kf-dist=N`). Counted from +// `stream::decode_stream`, which is where the frame header is consumed; the +// gate's proof that the on-value really reached the bitstream rather than +// being dropped by the rate control. +thread_local! { + static FWD_KF_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`FWD_KF_HITS`]. +pub(crate) fn fwd_kf_hits() -> usize { + FWD_KF_HITS.with(|c| c.get()) +} + +/// Records one decoded forward keyframe (see [`FWD_KF_HITS`]). +pub(crate) fn note_fwd_kf() { + FWD_KF_HITS.with(|c| c.set(c.get() + 1)); +} + // How many [`read_tx_size`] reads resolved a `tx_depth` strictly less than // the block's own side, across every call on the current thread -- the same // before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream diff --git a/crates/ec-av1/src/gate_coverage.rs b/crates/ec-av1/src/gate_coverage.rs index a426cd7e..a0458cbd 100644 --- a/crates/ec-av1/src/gate_coverage.rs +++ b/crates/ec-av1/src/gate_coverage.rs @@ -236,31 +236,14 @@ const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ /// OFF in every gate that names it (a hard hole -- no stream can carry it) or /// merely defaulted (unknown, and unknown is not coverage). #[cfg(test)] -const NEVER_ON_8BIT: &[(&str, &str)] = &[ - ( - "enable-fwd-kf", - "on in no 8-bit gate: 12 pin =0, 33 default (aomenc's default is off), so forward keyframes are never coded -- lane-defon r1 left this one open: it needs --fwd-kf-dist plus a decoder counter for a KEY frame with show_frame == 0, neither of which exists yet", - ), -]; +const NEVER_ON_8BIT: &[(&str, &str)] = &[]; /// [`DEFAULT_ON_TOOLS`] entries no 10-bit gate spells on, with the reason. #[cfg(test)] const NEVER_ON_10BIT: &[(&str, &str)] = &[ ( "enable-diff-wtd-comp", - "on in no 10-bit gate: 1 pinned off, 14 defaulted -- lane-defon r1 closed the 8-bit hole on the masked-compound gate (diffwtd_hits), but that gate has no 10-bit sibling", - ), - ( - "enable-fwd-kf", - "hole at both depths, see the 8-bit list (3 pinned off, 12 defaulted)", - ), - ( - "enable-interintra-wedge", - "on in no 10-bit gate: 5 pin =0, 10 default -- wedge interintra masks are exercised at 8 bits only, the shape that cost lane-hbdinter two 10-bit-only defects", - ), - ( - "enable-onesided-comp", - "on in no 10-bit gate: 5 pinned off, 10 defaulted -- lane-defon r1 closed the 8-bit hole on the interintra gate (uni_comp_hits); the 10-bit compound gates pin it off", + "on in no 10-bit gate: 1 pinned off, 14 defaulted -- lane-defon r1 closed the 8-bit hole on the masked-compound gate (diffwtd_hits) and added a 10-bit one-sided-compound gate, but the 10-bit fixture source is `gradients`, whose smooth content never wins a difference-weighted mask (measured 8/8 pixel-exact, diffwtd_hits == 0); it needs a mandelbrot fixture in ten_bit_tool_gate", ), ( "multi-tile", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index f4d6ab2e..80a83b5a 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -789,6 +789,13 @@ pub fn decode_stream(data: &[u8]) -> Result> { order_hint_slots[i] = header.order_hint; } } + // lane-defon r1: a forward keyframe (aomenc `--enable-fwd-kf`) is a + // KEY frame coded with `show_frame == 0`, output later by a + // `show_existing_frame` header -- counted only once its tiles have + // decoded, so the gate's assert covers decoded-and-compared frames. + if header.frame_type == FrameType::Key && !header.show_frame { + decode::note_fwd_kf(); + } if header.show_frame { let output = if header.film_grain.apply_grain { let mc_identity = parser @@ -1888,6 +1895,14 @@ mod tests { let input_depth_arg = format!("--input-bit-depth={bit_depth}"); let mut child = Command::new(aomenc_path()) .args([ + // lane-defon r1: the repo's only gate that decodes hidden + // frames is also the only place a FORWARD KEYFRAME can be + // proven -- a KEY frame with `show_frame == 0`, which is + // exactly the shape this gate already compares in decode + // order. On-values go before the base list (aomenc keeps + // the FIRST occurrence of a repeated flag). + "--enable-fwd-kf=1", + "--fwd-kf-dist=8", "--codec=av1", "--passes=1", "--end-usage=q", @@ -1953,17 +1968,28 @@ mod tests { String::from_utf8_lossy(&out.stderr) ); let stream = out.stdout; + let fwd_kf_before = crate::decode::fwd_kf_hits(); let (total, hidden) = decode_all_frames_vs_oracle(&stream, &format!("altref-hidden-{bit_depth}bit")); + let fwd_kf = crate::decode::fwd_kf_hits() - fwd_kf_before; assert!( hidden >= 2, "{NAME}: the {bit_depth}-bit recipe produced only {hidden} hidden frame(s) of \ {total} decoded -- the gate would be vacuous (class \ gate-blind-to-hidden-frames)" ); + // lane-defon r1: `--enable-fwd-kf=1` is spelled on this recipe, so + // a KEY frame with `show_frame == 0` must actually have been + // decoded -- otherwise the on-value proves nothing. + assert!( + fwd_kf > 0, + "{NAME}: the {bit_depth}-bit recipe decoded {total} frames ({hidden} hidden) but \ + zero forward keyframes -- --enable-fwd-kf=1 --fwd-kf-dist=8 never reached the \ + bitstream" + ); eprintln!( - "{NAME} {bit_depth}-bit: {total} frames decoded, {hidden} hidden, all \ - pixel-exact vs the oracle in decode order" + "{NAME} {bit_depth}-bit: {total} frames decoded, {hidden} hidden, {fwd_kf} \ + forward keyframes, all pixel-exact vs the oracle in decode order" ); } } @@ -7069,6 +7095,143 @@ mod tests { } } + /// lane-defon r1: the 10-bit one-sided-compound hole -- + /// `--enable-onesided-comp` was spelled on in no 10-bit gate (5 of the 15 + /// pin it off, the rest default), so the UNIDIR_COMP_REFERENCE alphabet + /// was proven at 8 bits only while both of his films are 10-bit 4:2:0. + /// `--enable-diff-wtd-comp=1` is deliberately NOT spelled here (a flag a + /// gate turns on without asserting it fired is coverage theatre, class + /// gate-blind-to-feature): measured this round, the 10-bit `gradients` + /// fixture decodes 8/8 pixel-exact with `diffwtd_hits == 0` -- smooth + /// gradients never win + /// a difference-weighted mask (the 8-bit gate needs `mandelbrot`'s hard + /// diagonal edge, and [`ten_bit_tool_gate`] has no mandelbrot source), so + /// hard-asserting it here would fail on encoder choice, not on a decoder + /// defect. + #[test] + fn a_real_aomenc_10bit_stream_with_onesided_compound_decodes_pixel_exact() { + const NAME: &str = "a_real_aomenc_10bit_stream_with_onesided_compound_decodes_pixel_exact"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); + return; + } + ten_bit_tool_gate( + NAME, + 64, + 64, + 24, + &[ + "--enable-onesided-comp=1", + "--enable-masked-comp=1", + "--enable-dist-wtd-comp=0", + "--cq-level=45", + "--kf-max-dist=1000", + "--auto-alt-ref=1", + "--lag-in-frames=16", + "--enable-fwd-kf=0", + "--enable-order-hint=1", + "--enable-global-motion=0", + "--enable-warped-motion=1", + "--enable-obmc=1", + "--tune-content=default", + "--enable-interintra-comp=0", + "--enable-interintra-wedge=0", + "--enable-smooth-interintra=0", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-filter-intra=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-directional-intra=0", + "--enable-angle-delta=0", + "--enable-tx-size-search=0", + "--enable-cdef=0", + "--enable-restoration=0", + "--max-partition-size=32", + "--min-partition-size=32", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-cfl-intra=0", + "--enable-ref-frame-mvs=0", + ], + &[42, 43, 44, 45, 46, 47, 48, 49], + &[("uni_comp_hits", crate::decode::uni_comp_hits as fn() -> usize)], + ); + } + + /// lane-defon r1: the 10-bit sibling of + /// [`a_real_aomenc_stream_with_interintra_wedge_decodes_pixel_exact`] -- + /// `--enable-interintra-wedge=1` was spelled on in no 10-bit gate (5 of + /// the 15 pin it off), and his two films are 10-bit, so the 8-bit + /// gate alone proves nothing about the streams that matter. Same tool + /// set as the 8-bit recipe (`--enable-masked-comp=0` keeps inter blocks + /// off the COMPOUND_WEDGE path, fixed 32x32 partitions), driven through + /// [`ten_bit_tool_gate`], which hard-asserts `wii_hits` moved and + /// compares every plane against ffmpeg's own 10-bit decode. + #[test] + fn a_real_aomenc_10bit_stream_with_interintra_wedge_decodes_pixel_exact() { + const NAME: &str = "a_real_aomenc_10bit_stream_with_interintra_wedge_decodes_pixel_exact"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); + return; + } + ten_bit_tool_gate( + NAME, + 64, + 64, + 24, + &[ + "--enable-interintra-wedge=1", + "--enable-interintra-comp=1", + "--enable-smooth-interintra=1", + "--cq-level=45", + "--kf-max-dist=1000", + "--auto-alt-ref=1", + "--lag-in-frames=16", + "--enable-fwd-kf=0", + "--enable-order-hint=1", + "--enable-warped-motion=1", + "--enable-obmc=1", + "--tune-content=default", + "--enable-masked-comp=0", + "--enable-onesided-comp=0", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-filter-intra=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-directional-intra=0", + "--enable-angle-delta=0", + "--enable-tx-size-search=0", + "--enable-cdef=0", + "--enable-restoration=0", + "--max-partition-size=32", + "--min-partition-size=32", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-cfl-intra=0", + "--enable-ref-frame-mvs=0", + ], + &[42, 43, 44, 45, 46, 47, 48, 49], + &[ + ("wii_hits", crate::decode::wii_hits as fn() -> usize), + ("interintra_hits", crate::decode::interintra_hits as fn() -> usize), + ], + ); + } + /// lane-wii r2: `--enable-interintra-wedge=1` streams must DECODE /// pixel-exact -- the wedge-interintra syntax (adapting `wedge_index` /// CDF symbol, fixed sign 0) and the wedge mask blend are ported over