forge
Explore
Log in

Don't you dare go Hollow

av1: close the enable-dist-wtd-comp coverage hole with a real witness stream

Browse files at this commit

b93fec61e5b039f6222936a1f40d0ce61247913fAhmet Kaan GümüşParent: a460dca
The coverage census listed `enable-dist-wtd-comp` in NEVER_EXERCISED_8BIT
with the reason "distance-weighted compound is unimplemented". That reason
was WRONG. The combine is implemented: `compound::dist_wtd_comp_weight_assign`
(lane-av1comp) and `mc::combine_compound`'s weighted path have been in the
tree for a long time. What was missing was a stream CARRYING the tool, so
the census read the entry as open and no gate ever proved the tool fires.

STEP 0 (producibility, against aom 3.13.3): the flag maps onto the sequence
header's `enable_jnt_comp` bit -- `av1_cx_iface.c:1062` ->
`order_hint_info.enable_dist_wtd_comp`, written at `bitstream.c:2681` under
`enable_order_hint` and AND-masked by it at `av1_cx_iface.c:1491`. The
parsed header is asserted, never the flag spelling. Measured: the same recipe
parses `jnt_comp=true` with `=1` and `jnt_comp=false` with `=0`, and the arms
differ on the wire (6855 B vs 6911 B). A flag the encoder accepted but
ignored would fail both asserts.

The gate: `--enable-dist-wtd-comp=1` over rotating mandelbrot at
`--min-partition-size=32 --cq-level=30` (both load-bearing -- at min=16 the
encoder emits 8x8 inter leaves this decoder refuses BY NAME before the
`compound_idx` read runs, and at cq 45/55 the stream has no compound block at
all). Three hard asserts: the PARSED header carries `enable_jnt_comp`; the
`compound_idx == 0` arm fired (`dist_wtd_comp_hits() > 0`); and every frame is
pixel-compared against the oracle with lengths asserted first.

decode.rs is additive only -- a `DIST_WTD_COMP_HITS` counter and two `hit!`
calls inside the existing `idx == 0` arm. No blend arithmetic is touched, so
the single-reference path is unaffected (neither bump site is reachable
without a second reference) and 12-bit is unaffected (`combine_compound`
already carries the `round_delta` post-round from lane-av112bit).

Measured: 25 oracle frames, 21 distance-weighted blocks. Red-before, both
directions. Mutating `dist_wtd_comp_weight_assign` to return the (8, 8)
simple average reds the pixel compare at decode-order frame 7 (552 bytes
differ); disabling the counter reds `dist_wtd_comp_hits > 0` with the pixels
still green, which is what separates "the counter can fire" from "the pixel
compare alone would catch it".

Regression: 35/35 compound gates green (8/10/12-bit, including the 12-bit
8x8 leaf) and 15/15 4:4:4 gates green. 4:4:4 reaches the same arm
independently (22 blocks at cq 20, 21 at cq 30, pixel-exact both) and 12-bit
reaches it too (15 blocks), so the tool is not 4:2:0-only.
crates/ec-av1/src/decode.rsmodified+34 -0
@@ -4999,6 +4999,32 @@ pub(crate) fn affine_gm_hits() -> usize {
4999 AFFINE_GM_HITS.with(|c| c.get())4999 AFFINE_GM_HITS.with(|c| c.get())
5000 }5000 }
5001 5001
5002+// lane-av1distwtd: how many blocks took the DISTANCE-WEIGHTED compound
5003+// combine rather than the simple average -- `compound_idx == 0` under
5004+// `enable_jnt_comp`, whose weights come from
5005+// [`crate::compound::dist_wtd_comp_weight_assign`] instead of the constant
5006+// `(8, 8)` split. Counting the `idx == 0` arm (not merely the
5007+// `compound_idx` symbol read) is what makes this a witness of the TOOL: a
5008+// stream that carries `enable_jnt_comp = true` in its sequence header but
5009+// codes every compound block with `compound_idx == 1` leaves this at 0 and
5010+// decoded identically without the whole distance-weight path.
5011+thread_local! {
5012+ static DIST_WTD_COMP_HITS: std::cell::Cell<usize> =
5013+ const { std::cell::Cell::new(0) };
5014+}
5015+
5016+/// Current value of [`DIST_WTD_COMP_HITS`].
5017+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
5018+pub(crate) fn dist_wtd_comp_hits() -> usize {
5019+ DIST_WTD_COMP_HITS.with(|c| c.get())
5020+}
5021+
5022+/// Resets [`DIST_WTD_COMP_HITS`] to 0.
5023+#[allow(dead_code)] // test-only
5024+pub(crate) fn reset_dist_wtd_comp_hits() {
5025+ DIST_WTD_COMP_HITS.with(|c| c.set(0));
5026+}
5027+
5002 // lane-av1gwarp12: how many 16x16+ blocks built their SINGLE-reference5028 // lane-av1gwarp12: how many 16x16+ blocks built their SINGLE-reference
5003 // prediction through `crate::warp::global_warp_params` with a FOUR-parameter5029 // prediction through `crate::warp::global_warp_params` with a FOUR-parameter
5004 // (`ROTZOOM`) model. Vanilla aomenc pins its global-motion search to ROTZOOM5030 // (`ROTZOOM`) model. Vanilla aomenc pins its global-motion search to ROTZOOM
@@ -38881,6 +38907,10 @@ fn decode_inter_block(
38881 if idx == 1 {38907 if idx == 1 {
38882 (8, 8, 1u8)38908 (8, 8, 1u8)
38883 } else {38909 } else {
38910+ // lane-av1distwtd: `idx == 0` is the
38911+ // distance-weighted arm -- the only branch whose
38912+ // weights are NOT the constant (8, 8) split.
38913+ hit!(DIST_WTD_COMP_HITS);
38884 let (fwd, bck) = crate::compound::dist_wtd_comp_weight_assign(38914 let (fwd, bck) = crate::compound::dist_wtd_comp_weight_assign(
38885 order_hint_bits,38915 order_hint_bits,
38886 order_hint,38916 order_hint,
@@ -46845,6 +46875,10 @@ fn decode_inter_block8(
46845 if idx == 1 {46875 if idx == 1 {
46846 (8, 8, 1u8)46876 (8, 8, 1u8)
46847 } else {46877 } else {
46878+ // lane-av1distwtd: the 8x8 leaf's own
46879+ // distance-weighted arm, same counter as the
46880+ // 16x16+ site above.
46881+ hit!(DIST_WTD_COMP_HITS);
46848 let (fwd, bck) = crate::compound::dist_wtd_comp_weight_assign(46882 let (fwd, bck) = crate::compound::dist_wtd_comp_weight_assign(
46849 order_hint_bits,46883 order_hint_bits,
46850 order_hint,46884 order_hint,
crates/ec-av1/src/gate_coverage.rsmodified+15 -4
@@ -190,10 +190,21 @@ const NEVER_EXERCISED_8BIT: &[(&str, &str)] = &[
190 // `enable-cfl-intra` LEFT both lists on 2026-09-02 (lane-reelckf r1): the190 // `enable-cfl-intra` LEFT both lists on 2026-09-02 (lane-reelckf r1): the
191 // sb128 skipped-CfL / 1:4-chroma gate passes `--enable-cfl-intra=1` at 8191 // sb128 skipped-CfL / 1:4-chroma gate passes `--enable-cfl-intra=1` at 8
192 // AND 10 bits and pixel-compares both arms.192 // AND 10 bits and pixel-compares both arms.
193- (193+ // `enable-dist-wtd-comp` LEFT this list on 2026-09-29 (lane-av1distwtd).
194- "enable-dist-wtd-comp",194+ // The entry's stated reason was WRONG: the distance-weighted compound
195- "off in 11 gates, on in none: distance-weighted compound is unimplemented",195+ // combine is not unimplemented -- `compound::dist_wtd_comp_weight_assign`
196- ),196+ // (lane-av1comp) and `mc::combine_compound`'s weighted path have been in
197+ // the tree for a long time. What was missing was a stream CARRYING the
198+ // tool, and `a_distance_weighted_compound_stream_decodes_pixel_exact`
199+ // (stream.rs) now supplies one: it spells `--enable-dist-wtd-comp=1` and
200+ // asserts the PARSED sequence header carries `enable_jnt_comp == true`
201+ // (and `false` from the same recipe with `=0`, so the bit is proven to
202+ // move with the flag), that `dist_wtd_comp_hits() > 0` -- the
203+ // `compound_idx == 0` arm, the only branch whose blend weights are not the
204+ // constant (8, 8) -- and pixel-compares every frame against the oracle.
205+ // The existing lane-cwarp compound-warp gates already SPELLED `=1` and
206+ // the census still read this entry as open, so the hole was a missing
207+ // witness, not a missing flag.
197 (208 (
198 "enable-dual-filter",209 "enable-dual-filter",
199 "never spelled by any gate, so defaulted = unknown; no stream is proven to carry per-direction interp filters",210 "never spelled by any gate, so defaulted = unknown; no stream is proven to carry per-direction interp filters",
crates/ec-av1/src/stream.rsmodified+226 -0
@@ -43597,4 +43597,230 @@ pub(crate) mod tests {
43597 }43597 }
43598 assert!(seen, "{name}: no sequence header parsed");43598 assert!(seen, "{name}: no sequence header parsed");
43599 }43599 }
43600+
43601+ /// lane-av1distwtd: the gate that pays the `enable-dist-wtd-comp` entry in
43602+ /// `gate_coverage.rs`'s [`NEVER_EXERCISED_8BIT`], and corrects its stated
43603+ /// reason. The entry said "distance-weighted compound is unimplemented" --
43604+ /// it is NOT: [`crate::compound::dist_wtd_comp_weight_assign`] (lane-av1comp)
43605+ /// and `mc::combine_compound`'s weighted path have been in the tree since.
43606+ /// What was missing is a stream that CARRIES the tool. Proved producible
43607+ /// against aom 3.13.3: the flag maps onto the sequence header's
43608+ /// `enable_jnt_comp` bit (`av1_cx_iface.c:1062` ->
43609+ /// `order_hint_info.enable_dist_wtd_comp` -> `bitstream.c:2681` writes it
43610+ /// under `enable_order_hint`), and this recipe's parsed header prints
43611+ /// `jnt_comp=true` with `=1` and `jnt_comp=false` with `=0` -- the parsed
43612+ /// value is asserted, never the flag spelling, per the class
43613+ /// `knob-never-reached-the-tool` trap that mislabelled a cell once already.
43614+ ///
43615+ /// Three hard asserts, all load-bearing:
43616+ /// 1. the PARSED sequence header carries `enable_jnt_comp == true` (the
43617+ /// off-arm asserts `false` from the same recipe, so the bit is proven to
43618+ /// MOVE with the flag rather than to be set by something else);
43619+ /// 2. `dist_wtd_comp_hits() > 0` -- the `compound_idx == 0` arm, the only
43620+ /// branch whose blend weights are not the constant (8, 8). A stream
43621+ /// carrying the header bit while coding every compound block with
43622+ /// `compound_idx == 1` leaves this at 0 and decodes byte-identically
43623+ /// without the whole distance-weight path, so the counter -- not the
43624+ /// header bit -- is what makes this a witness of the TOOL;
43625+ /// 3. every frame pixel-compared against the oracle through
43626+ /// [`decode_all_frames_vs_oracle`], which length-asserts each
43627+ /// decode-order frame before zipping.
43628+ ///
43629+ /// `--min-partition-size=32` is what makes the arm fire: at 16 the encoder
43630+ /// emits 8x8 inter leaves this decoder refuses BY NAME, so a smaller
43631+ /// min-partition refuses before the `compound_idx` read ever runs (measured:
43632+ /// the `min=16` arm of the same recipe refuses with "an inter partition
43633+ /// below 16x16" and dumps zero `compound_idx` lines). `--cq-level=30` is
43634+ /// likewise load-bearing: at cq 45/55 the same arm encodes a single-ref
43635+ /// stream (zero `compound_idx` reads) and the counter assert would be
43636+ /// vacuous.
43637+ #[test]
43638+ fn a_distance_weighted_compound_stream_decodes_pixel_exact() {
43639+ const NAME: &str = "distwtd-comp";
43640+ let _gate_lock = lock_gate_counters();
43641+ if !have_aomenc() {
43642+ return;
43643+ }
43644+ assert!(have_ffmpeg(), "{NAME}: ffmpeg required");
43645+ assert!(
43646+ aomdec_path().is_file(),
43647+ "{NAME}: aomenc resolved to {} but no aomdec sits beside it -- a \
43648+ pixel-exactness gate that compares nothing is worse than no gate",
43649+ aomenc_path().display()
43650+ );
43651+ let (width, height, frame_count) = (64usize, 64usize, 24usize);
43652+ // mandelbrot + a slow rotation: two genuinely different references at
43653+ // different temporal distances, which is what `dist_wtd_comp_weight_
43654+ // assign` weights BY. A static or flat source has equal distances
43655+ // everywhere and every block collapses onto one weight row.
43656+ let y4m = Command::new("ffmpeg")
43657+ .args([
43658+ "-v",
43659+ "error",
43660+ "-f",
43661+ "lavfi",
43662+ "-i",
43663+ "mandelbrot=size=128x128:rate=25:start_x=-0.6:start_y=-0.4,\
43664+ rotate=a=0.01*n:ow=128:oh=128:c=black,scale=64:64",
43665+ "-t",
43666+ "0.96",
43667+ "-pix_fmt",
43668+ "yuv420p",
43669+ "-strict",
43670+ "-1",
43671+ "-f",
43672+ "yuv4mpegpipe",
43673+ "-",
43674+ ])
43675+ .stdin(Stdio::null())
43676+ .stdout(Stdio::piped())
43677+ .stderr(Stdio::piped())
43678+ .output()
43679+ .expect("ffmpeg failed to run");
43680+ assert!(
43681+ y4m.status.success(),
43682+ "{NAME}: ffmpeg fixture: {}",
43683+ String::from_utf8_lossy(&y4m.stderr)
43684+ );
43685+ // the shared recipe; the flag under test is appended per arm so the
43686+ // two arms differ in exactly one argument.
43687+ let recipe: Vec<&str> = vec![
43688+ "--codec=av1",
43689+ "--passes=1",
43690+ "--end-usage=q",
43691+ "--cq-level=30",
43692+ "--cpu-used=0",
43693+ "--kf-max-dist=1000",
43694+ "--threads=1",
43695+ "--row-mt=0",
43696+ "--auto-alt-ref=1",
43697+ "--lag-in-frames=25",
43698+ "--enable-fwd-kf=0",
43699+ // `enable_jnt_comp` is only READ when order hints are on
43700+ // (`av1_cx_iface.c:1491` ANDs the two).
43701+ "--enable-order-hint=1",
43702+ "--enable-warped-motion=1",
43703+ "--tune-content=default",
43704+ "--min-partition-size=32",
43705+ "--max-partition-size=64",
43706+ // partition/intra tools this decoder does not code -- the same
43707+ // exclusion list every compound gate in this file carries.
43708+ "--enable-rect-partitions=0",
43709+ "--enable-ab-partitions=0",
43710+ "--enable-1to4-partitions=0",
43711+ "--enable-filter-intra=0",
43712+ "--enable-smooth-intra=0",
43713+ "--enable-paeth-intra=0",
43714+ "--enable-directional-intra=0",
43715+ "--enable-angle-delta=0",
43716+ "--enable-tx-size-search=0",
43717+ "--enable-cdef=0",
43718+ "--enable-restoration=0",
43719+ "--enable-palette=0",
43720+ "--enable-intrabc=0",
43721+ "--enable-cfl-intra=0",
43722+ "--enable-ref-frame-mvs=0",
43723+ ];
43724+ let encode = |flag: &str| -> Vec<u8> {
43725+ let out = run_with_stdin(
43726+ Command::new(aomenc_path()).args(
43727+ recipe
43728+ .iter()
43729+ .copied()
43730+ .chain([flag, "--obu", "-o", "-", "-"]),
43731+ ),
43732+ &y4m.stdout,
43733+ );
43734+ assert!(
43735+ out.status.success(),
43736+ "{NAME}: aomenc refused the fixture with {flag}: {}",
43737+ String::from_utf8_lossy(&out.stderr)
43738+ );
43739+ out.stdout
43740+ };
43741+ // The PARSED header, read back off the encoded bytes -- never the
43742+ // command line. `Av1Parser` walks the real OBUs, so a flag the encoder
43743+ // ignored is caught here rather than inherited into coverage.
43744+ let parsed_jnt_comp = |stream: &[u8]| -> bool {
43745+ let mut parser = Av1Parser::new();
43746+ let mut pos = 0usize;
43747+ while pos < stream.len() {
43748+ let obu = parser.parse_obu(&stream[pos..]).expect("parsing our own OBUs");
43749+ pos += obu.total_size;
43750+ }
43751+ parser
43752+ .sequence_header()
43753+ .expect("the stream carries a sequence header")
43754+ .enable_jnt_comp
43755+ };
43756+ // NB: the OFF arm is spelled FIRST on purpose. `gate_coverage.rs`'s
43757+ // `flags_in` keeps the LAST `--enable-<tool>=<value>` it finds in a gate
43758+ // body, so a trailing `=0` would make the whole gate read as "tool
43759+ // disabled" to the census and leave the entry unretired even though
43760+ // this gate does exercise the tool. Both arms are still asserted below.
43761+ let off = encode("--enable-dist-wtd-comp=0");
43762+ let on = encode("--enable-dist-wtd-comp=1");
43763+ // the bit MOVES with the flag, and it moves the BYTES: a flag the
43764+ // encoder accepted but ignored would fail both of these.
43765+ assert!(
43766+ parsed_jnt_comp(&on),
43767+ "{NAME}: the recipe spelled --enable-dist-wtd-comp=1 but the PARSED \
43768+ sequence header carries enable_jnt_comp == false (class \
43769+ knob-never-reached-the-tool) -- the gate would be vacuous"
43770+ );
43771+ assert!(
43772+ !parsed_jnt_comp(&off),
43773+ "{NAME}: the same recipe with --enable-dist-wtd-comp=0 still parses \
43774+ enable_jnt_comp == true, so the ON arm proves nothing about the flag"
43775+ );
43776+ assert_ne!(
43777+ on.len(),
43778+ off.len(),
43779+ "{NAME}: both arms encoded {} bytes -- the flag changed nothing on \
43780+ the wire, so neither arm is evidence for anything",
43781+ on.len()
43782+ );
43783+ // shape non-vacuity, before any compare: at 4:2:0 a decoder keeping a
43784+ // subsampled extent would hand quarter-size planes to the byte compare.
43785+ let frames = decode_stream(&on).unwrap_or_else(|e| panic!("{NAME}: refused: {e}"));
43786+ assert_eq!(
43787+ frames.len(),
43788+ frame_count,
43789+ "{NAME}: expected {frame_count} shown frames"
43790+ );
43791+ for (i, f) in frames.iter().enumerate() {
43792+ assert_eq!(
43793+ (f.width, f.height),
43794+ (width, height),
43795+ "{NAME}: frame {i} is {}x{}",
43796+ f.width,
43797+ f.height
43798+ );
43799+ assert_eq!(
43800+ f.u.len(),
43801+ width * height / 4,
43802+ "{NAME}: frame {i} U plane is {} samples, not 4:2:0",
43803+ f.u.len()
43804+ );
43805+ assert_eq!(f.v.len(), f.u.len(), "{NAME}: frame {i} V plane extent");
43806+ assert_eq!(f.y.len(), width * height, "{NAME}: frame {i} luma extent");
43807+ }
43808+ crate::decode::reset_dist_wtd_comp_hits();
43809+ let hits_before = crate::decode::dist_wtd_comp_hits();
43810+ let (oracle_frames, hidden) = decode_all_frames_vs_oracle(&on, NAME);
43811+ let dist_wtd = crate::decode::dist_wtd_comp_hits() - hits_before;
43812+ eprintln!(
43813+ "{NAME}: {oracle_frames} oracle frames ({hidden} hidden), \
43814+ dist_wtd_comp_hits={dist_wtd}, on={} B off={} B",
43815+ on.len(),
43816+ off.len()
43817+ );
43818+ assert!(
43819+ dist_wtd > 0,
43820+ "{NAME}: no block took the distance-weighted compound combine \
43821+ (compound_idx == 0) across {oracle_frames} frames that carry \
43822+ enable_jnt_comp = true -- every compound block used the simple \
43823+ average, so this gate proves nothing about the tool"
43824+ );
43825+ }
43600 }43826 }