forge
Explore
Log in

Don't you dare go Hollow

64x64 masked compound infers COMPOUND_DIFFWTD instead of refusing

Browse files at this commit

6d86b95062ae3d3062313566b89582809bcb7bddAhmet Kaan GümüşParent: 473c744
  • feat
    • 64x64 masked compound infers COMPOUND_DIFFWTD instead of refusing
Show full message
feat(av1): 64x64 masked compound infers COMPOUND_DIFFWTD instead of refusing

libaom `read_compound_type` (decodemv.c 1634-1656) only codes a
`compound_type` symbol when `is_interinter_compound_used(COMPOUND_WEDGE,
bsize)`; `av1_wedge_params_lookup[BLOCK_64X64].wedge_types == 0`, so at
64x64 the type is INFERRED as COMPOUND_DIFFWTD and only the 1-bit
`mask_type` literal follows. This decoder read the symbol nowhere and
refused the block by name instead ("a masked compound 64x64 inter
block..."), which capped every `--enable-masked-comp=1` stream whose
superblock stayed unsplit.

The DIFFWTD mask build and blend are already size- and bit-depth-generic
(`mc::diffwtd_mask` carries the `bd - 8` round term, `blend_masked_compound`
takes the block dims), so the lift is the alphabet decision plus a narrow
counter. 64x64 is the only wedge-less size this decoder's square inter path
reaches; the rect shapes (64x32/32x64/64x16/16x64) are refused one level up
by "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular
residual coding" and gain nothing from code here.

Gate: a_real_aomenc_stream_with_a_diffwtd_compound_64x64_block_decodes_pixel_exact
(+ its 10-bit arm) -- --sb-size=64 --max/min-partition-size=64 pins every
block to the inferred size, --enable-masked-comp=1 --enable-diff-wtd-comp=1
--enable-dist-wtd-comp=0 leaves the inferred arm as the only masked choice;
per-attempt hit snapshots counted on decoded+compared attempts only.
6/6 pixel-exact both depths, diffwtd_inferred_hits 79 (8-bit) / 51 (10-bit).
gate_coverage NEVER_ON_10BIT is now empty: the 10-bit arm is the first
recipe to spell --enable-diff-wtd-comp=1 and fire it.
crates/ec-av1/src/decode.rsmodified+33 -16
@@ -757,6 +757,21 @@ pub(crate) fn diffwtd_hits() -> usize {
757 DIFFWTD_HITS.with(|c| c.get())757 DIFFWTD_HITS.with(|c| c.get())
758 }758 }
759 759
760+// lane-mcomp64 r1: how many blocks took the INFERRED `COMPOUND_DIFFWTD` arm --
761+// a block size where `av1_is_wedge_used` is false (64x64 is the only such size
762+// this decoder's square inter path reaches), so no `compound_type` symbol is
763+// coded at all. Strictly narrower than `DIFFWTD_HITS`, which also counts the
764+// coded-symbol DIFFWTD blocks at 8x8/16x16/32x32.
765+thread_local! {
766+ static DIFFWTD_INFERRED_HITS: std::cell::Cell<usize> =
767+ const { std::cell::Cell::new(0) };
768+}
769+
770+/// Current value of [`DIFFWTD_INFERRED_HITS`].
771+pub(crate) fn diffwtd_inferred_hits() -> usize {
772+ DIFFWTD_INFERRED_HITS.with(|c| c.get())
773+}
774+
760 // lane-defon r1: how many FORWARD KEYFRAMES were decoded -- a KEY frame coded775 // lane-defon r1: how many FORWARD KEYFRAMES were decoded -- a KEY frame coded
761 // with `show_frame == 0`, output later by a `show_existing_frame` header776 // with `show_frame == 0`, output later by a `show_existing_frame` header
762 // (aomenc `--enable-fwd-kf=1 --fwd-kf-dist=N`). Counted from777 // (aomenc `--enable-fwd-kf=1 --fwd-kf-dist=N`). Counted from
@@ -13371,24 +13386,23 @@ fn decode_inter_block(
13371 // `wedge_types > 0`), so `compound_type` always reads a real13386 // `wedge_types > 0`), so `compound_type` always reads a real
13372 // symbol here -- no alphabet collapse to worry about at this13387 // symbol here -- no alphabet collapse to worry about at this
13373 // block-size family.13388 // block-size family.
13389+ // lane-mcomp64 r1: `av1_is_wedge_used` is false at 64x64
13390+ // (`av1_wedge_params_lookup[BLOCK_64X64].wedge_types == 0`),
13391+ // so libaom's `read_compound_type` (decodemv.c 1634-1656)
13392+ // writes NO `compound_type` symbol there and INFERS
13393+ // `COMPOUND_DIFFWTD` -- only the 1-bit `mask_type` literal
13394+ // follows. `None` here is exactly that inferred arm.
13374 let wedge_bsize = match side {13395 let wedge_bsize = match side {
13375- 8 => 3,13396+ 8 => Some(3),
13376- 16 => 6,13397+ 16 => Some(6),
13377- 32 => 9,13398+ 32 => Some(9),
13378- // lane-inter8 r1: `av1_is_wedge_used` is false at 64x6413399+ _ => None,
13379- // (`av1_wedge_params_lookup[BLOCK_64X64].wedge_types ==
13380- // 0`), so a real encoder writes NO `compound_type` symbol
13381- // there -- COMPOUND_DIFFWTD is inferred. Reading one
13382- // would desync, so refuse by name rather than guess the
13383- // inferred-DIFFWTD blend this round.
13384- _ => {
13385- return Err(unsupported(
13386- "a masked compound 64x64 inter block (compound_type is inferred, not coded, at this size)",
13387- ))
13388- }
13389 };13400 };
13390- let compound_type = dec.symbol(&mut cdfs.compound_type[wedge_bsize]);13401+ let compound_type = match wedge_bsize {
13391- if compound_type == 0 {13402+ Some(b) => dec.symbol(&mut cdfs.compound_type[b]),
13403+ None => 1,
13404+ };
13405+ if let Some(wedge_bsize) = wedge_bsize.filter(|_| compound_type == 0) {
13392 // COMPOUND_WEDGE: lane-wedge r3, codebook checksum-13406 // COMPOUND_WEDGE: lane-wedge r3, codebook checksum-
13393 // verified vs independent C dump (wedge.rs).13407 // verified vs independent C dump (wedge.rs).
13394 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);13408 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);
@@ -13403,6 +13417,9 @@ fn decode_inter_block(
13403 // COMPOUND_DIFFWTD: `mask_type`, MAX_DIFFWTD_MASK_BITS==1.13417 // COMPOUND_DIFFWTD: `mask_type`, MAX_DIFFWTD_MASK_BITS==1.
13404 let mask_type = dec.literal(1);13418 let mask_type = dec.literal(1);
13405 diffwtd_mask_type = Some(mask_type as u8);13419 diffwtd_mask_type = Some(mask_type as u8);
13420+ if wedge_bsize.is_none() {
13421+ DIFFWTD_INFERRED_HITS.with(|c| c.set(c.get() + 1));
13422+ }
13406 }13423 }
13407 MASKED_COMPOUND_HITS.with(|c| c.set(c.get() + 1));13424 MASKED_COMPOUND_HITS.with(|c| c.set(c.get() + 1));
13408 }13425 }
crates/ec-av1/src/gate_coverage.rsmodified+1 -6
@@ -249,12 +249,7 @@ const NEVER_ON_8BIT: &[(&str, &str)] = &[];
249 249
250 /// [`DEFAULT_ON_TOOLS`] entries no 10-bit gate spells on, with the reason.250 /// [`DEFAULT_ON_TOOLS`] entries no 10-bit gate spells on, with the reason.
251 #[cfg(test)]251 #[cfg(test)]
252-const NEVER_ON_10BIT: &[(&str, &str)] = &[252+const NEVER_ON_10BIT: &[(&str, &str)] = &[];
253- (
254- "enable-diff-wtd-comp",
255- "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",
256- ),
257-];
258 253
259 #[cfg(test)]254 #[cfg(test)]
260 mod tests {255 mod tests {
crates/ec-av1/src/refusal_inventory.rsmodified+0 -1
@@ -63,7 +63,6 @@ const REFUSALS: &[&str] = &[
63 "an intra block in an inter frame whose tx_depth splits its luma transform (round 1)",63 "an intra block in an inter frame whose tx_depth splits its luma transform (round 1)",
64 "an inter frame with no key frame before it",64 "an inter frame with no key frame before it",
65 "an inter SB-level partition type other than NONE or SPLIT (this decoder's inter tile path recurses a superblock only as SPLIT)",65 "an inter SB-level partition type other than NONE or SPLIT (this decoder's inter tile path recurses a superblock only as SPLIT)",
66- "a masked compound 64x64 inter block (compound_type is inferred, not coded, at this size)",
67 "an inter partition below 16x16 other than SPLIT (16x8/8x16 rect inter leaves are not coded yet)",66 "an inter partition below 16x16 other than SPLIT (16x8/8x16 rect inter leaves are not coded yet)",
68 "an intra mode this decoder does not code (round 2)",67 "an intra mode this decoder does not code (round 2)",
69 "an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet",68 "an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet",
crates/ec-av1/src/stream.rsmodified+209 -0
@@ -9680,6 +9680,215 @@ mod tests {
9680 );9680 );
9681 }9681 }
9682 9682
9683+ /// lane-mcomp64 r1: at 64x64 `av1_is_wedge_used` is false
9684+ /// (`av1_wedge_params_lookup[BLOCK_64X64].wedge_types == 0`), so libaom's
9685+ /// `read_compound_type` codes NO `compound_type` symbol and INFERS
9686+ /// `COMPOUND_DIFFWTD`; only the 1-bit `mask_type` literal follows. This
9687+ /// decoder used to refuse such a block by name ("a masked compound 64x64
9688+ /// inter block..."), because reading the symbol would have desynced.
9689+ ///
9690+ /// The recipe pins every block to 64x64 (`--sb-size=64
9691+ /// --max-partition-size=64 --min-partition-size=64`) with masked compound
9692+ /// on and distance-weighted compound off, so the only way a
9693+ /// `comp_group_idx == 1` block can be coded is through the inferred arm.
9694+ /// `diffwtd_inferred_hits` is snapshotted PER ATTEMPT and only accumulated
9695+ /// for attempts that decoded AND pixel-compared (class
9696+ /// `counter-from-refused-stream`), and is hard-asserted at the end. A
9697+ /// decode error or a pixel mismatch is a FAILURE, never a skip.
9698+ #[track_caller]
9699+ fn run_diffwtd_inferred_64x64_gate(name: &str, ten_bit: bool) {
9700+ let _gate_lock = lock_gate_counters();
9701+ assert!(have_ffmpeg(), "{name}: ffmpeg required");
9702+ assert!(have_aomenc(), "{name}: no aomenc at {}", aomenc_path().display());
9703+ let (width, height, frame_count) = (128usize, 128usize, 16usize);
9704+ let mut matched = 0u32;
9705+ let mut named_refusals = 0u32;
9706+ let mut attempts = 0u32;
9707+ let mut fired = 0usize;
9708+ let mut refusals: Vec<String> = Vec::new();
9709+ for cq in [32u32, 45, 55] {
9710+ for (i, zoom) in [0.004f64, 0.010].iter().enumerate() {
9711+ attempts += 1;
9712+ let attempt_before = crate::decode::diffwtd_inferred_hits();
9713+ let duration = frame_count as f64 / 25.0;
9714+ // Hard-edged, moving content: a difference-weighted mask only
9715+ // wins where the two references genuinely disagree over part
9716+ // of a 64x64 block (a smooth `gradients` source measured
9717+ // diffwtd_hits == 0, memory `gate-blind-to-feature`).
9718+ let source = format!(
9719+ "mandelbrot=size={width}x{height}:rate=25:start_x={sx}:start_y=-0.4:\
9720+ end_scale=0.3:maxiter=200,\
9721+ noise=alls=6:allf=t+u:all_seed={seed}",
9722+ sx = -0.6 + zoom * (i as f64 + 1.0),
9723+ seed = 1000 + cq,
9724+ );
9725+ let pix_fmt = if ten_bit { "yuv420p10le" } else { "yuv420p" };
9726+ let y4m = Command::new("ffmpeg")
9727+ .args([
9728+ "-v", "error", "-f", "lavfi", "-i", &source, "-t",
9729+ &duration.to_string(), "-pix_fmt", pix_fmt, "-strict", "-1",
9730+ "-f", "yuv4mpegpipe", "-",
9731+ ])
9732+ .stdin(Stdio::null())
9733+ .stdout(Stdio::piped())
9734+ .stderr(Stdio::piped())
9735+ .output()
9736+ .expect("ffmpeg failed to run");
9737+ assert!(
9738+ y4m.status.success(),
9739+ "ffmpeg fixture: {}",
9740+ String::from_utf8_lossy(&y4m.stderr)
9741+ );
9742+ let cq_arg = format!("--cq-level={cq}");
9743+ let mut args: Vec<&str> = vec![
9744+ "--codec=av1",
9745+ "--passes=1",
9746+ "--end-usage=q",
9747+ &cq_arg,
9748+ "--cpu-used=0",
9749+ "--kf-max-dist=1000",
9750+ "--threads=1",
9751+ "--row-mt=0",
9752+ "--auto-alt-ref=1",
9753+ "--lag-in-frames=16",
9754+ "--enable-fwd-kf=0",
9755+ "--enable-order-hint=1",
9756+ // the tools this gate exists for: masked compound on, the
9757+ // difference-weighted arm on, the distance-weighted
9758+ // competitor off so comp_group_idx==1 is the encoder's
9759+ // only masked choice at a size where wedge does not exist.
9760+ "--enable-masked-comp=1",
9761+ "--enable-diff-wtd-comp=1",
9762+ "--enable-dist-wtd-comp=0",
9763+ "--enable-onesided-comp=0",
9764+ "--enable-interintra-comp=0",
9765+ "--enable-global-motion=0",
9766+ "--enable-warped-motion=1",
9767+ "--enable-obmc=1",
9768+ "--tune-content=default",
9769+ // partition/intra tools this decoder does not code yet --
9770+ // same exclusion list every compound gate carries.
9771+ "--enable-rect-partitions=0",
9772+ "--enable-ab-partitions=0",
9773+ "--enable-1to4-partitions=0",
9774+ "--enable-filter-intra=0",
9775+ "--enable-smooth-intra=0",
9776+ "--enable-paeth-intra=0",
9777+ "--enable-directional-intra=0",
9778+ "--enable-angle-delta=0",
9779+ "--enable-tx-size-search=0",
9780+ "--enable-cdef=0",
9781+ "--enable-restoration=0",
9782+ "--enable-palette=0",
9783+ "--enable-intrabc=0",
9784+ "--enable-cfl-intra=0",
9785+ "--enable-ref-frame-mvs=0",
9786+ // every block is a whole 64x64 superblock: the ONLY size
9787+ // where compound_type is inferred rather than coded.
9788+ "--sb-size=64",
9789+ "--max-partition-size=64",
9790+ "--min-partition-size=64",
9791+ ];
9792+ if ten_bit {
9793+ args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]);
9794+ }
9795+ args.extend_from_slice(&["--obu", "-o", "-", "-"]);
9796+ let mut child = Command::new(aomenc_path())
9797+ .args(&args)
9798+ .stdin(Stdio::piped())
9799+ .stdout(Stdio::piped())
9800+ .stderr(Stdio::piped())
9801+ .spawn()
9802+ .expect("aomenc failed to start");
9803+ child
9804+ .stdin
9805+ .take()
9806+ .expect("aomenc stdin")
9807+ .write_all(&y4m.stdout)
9808+ .expect("writing y4m to aomenc");
9809+ let out = child.wait_with_output().expect("aomenc failed to run");
9810+ assert!(
9811+ out.status.success(),
9812+ "aomenc refused the fixture: {}",
9813+ String::from_utf8_lossy(&out.stderr)
9814+ );
9815+ let stream = out.stdout;
9816+ let frames = match decode_stream(&stream) {
9817+ Err(e) => {
9818+ let msg = e.to_string();
9819+ assert!(
9820+ msg.contains("unsupported"),
9821+ "{name} failed outright, not a named refusal (cq {cq}): {msg}"
9822+ );
9823+ assert!(
9824+ !msg.contains("masked compound 64x64"),
9825+ "{name} refused the inferred-DIFFWTD 64x64 block (cq {cq}) -- \
9826+ that refusal is lifted, this is forbidden: {msg}"
9827+ );
9828+ named_refusals += 1;
9829+ refusals.push(msg.clone());
9830+ eprintln!("{name} cq {cq} variant {i} refusal: {msg}");
9831+ continue;
9832+ }
9833+ Ok(frames) => frames,
9834+ };
9835+ let want = if ten_bit {
9836+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
9837+ } else {
9838+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
9839+ };
9840+ assert_eq!(frames.len(), frame_count);
9841+ if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP")
9842+ && frames
9843+ .iter()
9844+ .zip(&want)
9845+ .any(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v)
9846+ {
9847+ std::fs::write(&path, &stream).expect("writing pinned stream");
9848+ eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (cq {cq}) to {path}");
9849+ }
9850+ for (f, (got, want)) in frames.iter().zip(&want).enumerate() {
9851+ assert_eq!(got.y, want.y, "{name} frame {f} luma vs ffmpeg (cq {cq})");
9852+ assert_eq!(got.u, want.u, "{name} frame {f} U vs ffmpeg (cq {cq})");
9853+ assert_eq!(got.v, want.v, "{name} frame {f} V vs ffmpeg (cq {cq})");
9854+ }
9855+ // decoded AND compared: only now does this attempt's own
9856+ // inferred-DIFFWTD count mean anything.
9857+ fired += crate::decode::diffwtd_inferred_hits() - attempt_before;
9858+ matched += 1;
9859+ }
9860+ }
9861+ eprintln!(
9862+ "{name}: {matched}/{attempts} pixel-exact, {named_refusals} named refusals, \
9863+ diffwtd_inferred_hits (decoded+compared attempts only)={fired}"
9864+ );
9865+ assert!(matched > 0, "{name}: every attempt refused ({refusals:?}) -- no pixel compare ran");
9866+ assert!(
9867+ fired > 0,
9868+ "{name}: no inferred-DIFFWTD 64x64 block fired on a compared attempt \
9869+ ({matched} matches, {named_refusals} refusals of {attempts}) -- gate vacuous"
9870+ );
9871+ }
9872+
9873+ /// 8-bit arm of [`run_diffwtd_inferred_64x64_gate`].
9874+ #[test]
9875+ fn a_real_aomenc_stream_with_a_diffwtd_compound_64x64_block_decodes_pixel_exact() {
9876+ run_diffwtd_inferred_64x64_gate(
9877+ "a_real_aomenc_stream_with_a_diffwtd_compound_64x64_block_decodes_pixel_exact",
9878+ false,
9879+ );
9880+ }
9881+
9882+ /// 10-bit arm of [`run_diffwtd_inferred_64x64_gate`] -- both of his films
9883+ /// are `yuv420p10le`.
9884+ #[test]
9885+ fn a_real_aomenc_10bit_stream_with_a_diffwtd_compound_64x64_block_decodes_pixel_exact() {
9886+ run_diffwtd_inferred_64x64_gate(
9887+ "a_real_aomenc_10bit_stream_with_a_diffwtd_compound_64x64_block_decodes_pixel_exact",
9888+ true,
9889+ );
9890+ }
9891+
9683 /// lane-maskcomp r2 / lane-wedge r3: `--enable-masked-comp=1` streams9892 /// lane-maskcomp r2 / lane-wedge r3: `--enable-masked-comp=1` streams
9684 /// must consume `compound_type`/`wedge_idx`/`wedge_sign`/`mask_type`9893 /// must consume `compound_type`/`wedge_idx`/`wedge_sign`/`mask_type`
9685 /// entropy-exact AND build the real blend, DIFFWTD or WEDGE --9894 /// entropy-exact AND build the real blend, DIFFWTD or WEDGE --