forge
Explore
Log in

Don't you dare go Hollow

Inter tile path codes a whole-superblock PARTITION_NONE (64x64 inter block)

Browse files at this commit

b7d3bdb75135b574a3c9a54acb99a379912bdd86Ahmet Kaan GümüşParent: d21774e
  • feat
    • inter tile path codes a whole-superblock PARTITION_NONE (64x64 inter block)
Show full message
feat(av1): inter tile path codes a whole-superblock PARTITION_NONE (64x64 inter block)

The inter tile path recursed a superblock only as SPLIT, so the case aomenc
picks for static content -- one 64x64 inter block -- was a named refusal. The
arm now decodes through `decode_inter_block` at side 64: size_group 3
(`size_group_lookup[BLOCK_64X64]`), luma through `TxbSet::Luma64` with the
32-point scan (TX_64X64 codes only its top-left 32x32 of frequencies, spec
5.11.40 -- `read_inter_plane` widens the coded corner back to 64x64 before the
inverse transform, mirroring `read_plane`'s own `tx_side != side` branch),
chroma as a plain 32x32 `TxbSet::Chroma32`.

`av1_is_wedge_used` is false at 64x64, so no `compound_type` symbol is written
there; the wedge arm's `unreachable!` becomes a named refusal rather than a
read that would desync.

Gates (both HARD-assert `inter_sb_none_hits` moved and every frame pixel-exact
vs ffmpeg; a decode error fails, never SKIPs):
  a_real_aomenc_inter_sequence_with_a_whole_superblock_block_decodes_pixel_exact
  a_real_aomenc_10bit_inter_sequence_with_a_whole_superblock_block_decodes_pixel_exact

cargo test -p ec-av1 --lib: 269 passed, 0 failed, 23 ignored.
crates/ec-av1/src/decode.rsmodified+105 -3
@@ -730,6 +730,19 @@ pub(crate) fn rect_partition_hits() -> usize {
730 RECT_PARTITION_HITS.with(|c| c.get())730 RECT_PARTITION_HITS.with(|c| c.get())
731 }731 }
732 732
733+// lane-inter8 r1: how many superblocks an inter tile coded as a single
734+// whole-SB `PARTITION_NONE` 64x64 inter block (the case aomenc picks for
735+// static content, previously a named refusal).
736+thread_local! {
737+ static INTER_SB_NONE_HITS: std::cell::Cell<usize> =
738+ const { std::cell::Cell::new(0) };
739+}
740+
741+/// Current value of [`INTER_SB_NONE_HITS`].
742+pub(crate) fn inter_sb_none_hits() -> usize {
743+ INTER_SB_NONE_HITS.with(|c| c.get())
744+}
745+
733 // lane-rectwire r2: how many `PARTITION_HORZ`/`VERT` strips actually decoded746 // lane-rectwire r2: how many `PARTITION_HORZ`/`VERT` strips actually decoded
734 // real (non-skip) coefficients through [`read_coeffs_rect`] -- proves the747 // real (non-skip) coefficients through [`read_coeffs_rect`] -- proves the
735 // rect coefficient reader itself fired, not just the strip-level partition748 // rect coefficient reader itself fired, not just the strip-level partition
@@ -7779,6 +7792,23 @@ fn read_inter_plane(
7779 default_tx_type,7792 default_tx_type,
7780 None,7793 None,
7781 )?;7794 )?;
7795+ // lane-inter8 r1: a 64-point transform covers the whole 64x64 area but
7796+ // codes only its top-left 32x32 of frequencies (spec 5.11.40) -- the
7797+ // caller hands the 32-point `scan` there, and the coded corner goes into
7798+ // the top-left of the true `side`-sized grid before dequantization
7799+ // (dqDenom is keyed by the true size, not the corner's), mirroring
7800+ // [`read_plane`]'s own `tx_side != side` branch. Every other transform
7801+ // this decoder codes has `tx_side == side`, so this is inert below 64.
7802+ let tx_side = side.min(32);
7803+ let grid = if tx_side == side {
7804+ grid
7805+ } else {
7806+ let mut full = vec![0i32; side * side];
7807+ for row in 0..tx_side {
7808+ full[row * side..][..tx_side].copy_from_slice(&grid[row * tx_side..][..tx_side]);
7809+ }
7810+ full
7811+ };
7782 let (dc_delta, ac_delta) = plane_q_delta(plane_idx);7812 let (dc_delta, ac_delta) = plane_q_delta(plane_idx);
7783 let residual = dequant_and_inverse_typed(&grid, side, bit_depth(), CURRENT_Q_IDX.with(|c| c.get()), dc_delta, ac_delta, tx_type);7813 let residual = dequant_and_inverse_typed(&grid, side, bit_depth(), CURRENT_Q_IDX.with(|c| c.get()), dc_delta, ac_delta, tx_type);
7784 plane.reconstruct_mc(x, y, side, prediction, &residual);7814 plane.reconstruct_mc(x, y, side, prediction, &residual);
@@ -9120,7 +9150,17 @@ fn decode_inter_block(
9120 8 => 3,9150 8 => 3,
9121 16 => 6,9151 16 => 6,
9122 32 => 9,9152 32 => 9,
9123- _ => unreachable!("decode_inter_block leaf side is 8/16/32"),9153+ // lane-inter8 r1: `av1_is_wedge_used` is false at 64x64
9154+ // (`av1_wedge_params_lookup[BLOCK_64X64].wedge_types ==
9155+ // 0`), so a real encoder writes NO `compound_type` symbol
9156+ // there -- COMPOUND_DIFFWTD is inferred. Reading one
9157+ // would desync, so refuse by name rather than guess the
9158+ // inferred-DIFFWTD blend this round.
9159+ _ => {
9160+ return Err(unsupported(
9161+ "a masked compound 64x64 inter block (compound_type is inferred, not coded, at this size)",
9162+ ))
9163+ }
9124 };9164 };
9125 let compound_type = dec.symbol(&mut cdfs.compound_type[wedge_bsize]);9165 let compound_type = dec.symbol(&mut cdfs.compound_type[wedge_bsize]);
9126 if compound_type == 0 {9166 if compound_type == 0 {
@@ -12085,10 +12125,72 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
12085 }12125 }
12086 (false, false) => PARTITION_SPLIT,12126 (false, false) => PARTITION_SPLIT,
12087 };12127 };
12128+ if part64 == PARTITION_NONE {
12129+ // lane-inter8 r1: the whole superblock as one 64x64 inter
12130+ // block. `SB`-sized syntax throughout (size_group 3, same as
12131+ // 32x32 -- `size_group_lookup[BLOCK_64X64] == 3`), luma
12132+ // coefficients through `TxbSet::Luma64` with the 32-point
12133+ // scan (TX_64X64 codes only its top-left corner, spec
12134+ // 5.11.40 -- `read_inter_plane` widens the corner back to
12135+ // 64x64 before the inverse transform), chroma as a plain
12136+ // 32x32 `TxbSet::Chroma32`. TX_64X64 carries no `tx_type`
12137+ // symbol at all, so the intra/inter luma sets coincide.
12138+ INTER_SB_NONE_HITS.with(|c| c.set(c.get() + 1));
12139+ decode_inter_block(
12140+ &mut dec,
12141+ &mut cdfs,
12142+ &mut neighbours,
12143+ &mut grid,
12144+ sb_at,
12145+ SB,
12146+ mi_cols,
12147+ mi_rows,
12148+ &mut y,
12149+ &mut u,
12150+ &mut v,
12151+ &ref_y,
12152+ &ref_u,
12153+ &ref_v,
12154+ &ref_slots,
12155+ &sign_bias_table,
12156+ &global_motion,
12157+ base_q_idx,
12158+ TxbSet::Luma64,
12159+ TxbSet::Luma64,
12160+ TxbSet::Chroma32,
12161+ TX32,
12162+ TX32,
12163+ &scan32,
12164+ &scan32,
12165+ 3,
12166+ allow_high_precision_mv,
12167+ force_integer_mv,
12168+ interp_fixed,
12169+ enable_dual_filter,
12170+ tpl_frame.as_ref(),
12171+ reference_select,
12172+ enable_masked_compound,
12173+ enable_interintra_compound,
12174+ enable_jnt_comp,
12175+ order_hint_bits,
12176+ order_hint,
12177+ ref_order_hints,
12178+ skip_mode_present,
12179+ skip_mode_frame,
12180+ switchable_motion_mode,
12181+ allow_warped_motion,
12182+ false,
12183+ SB,
12184+ SB,
12185+ allow_screen_content_tools,
12186+ frame_width as usize,
12187+ )?;
12188+ continue;
12189+ }
12088 if part64 != PARTITION_SPLIT {12190 if part64 != PARTITION_SPLIT {
12089 return Err(unsupported(12191 return Err(unsupported(
12090- "an inter SB-level partition type other than SPLIT (this decoder's \12192+ "an inter SB-level partition type other than NONE or SPLIT (this decoder's \
12091- inter tile path only recurses a superblock as SPLIT)",12193+ inter tile path recurses a superblock only as SPLIT)",
12092 ));12194 ));
12093 }12195 }
12094 12196
crates/ec-av1/src/refusal_inventory.rsmodified+2 -1
@@ -67,7 +67,8 @@ const REFUSALS: &[&str] = &[
67 "an inter frame using TxMode::Select (this decoder's inter path never reads a tx_depth symbol, so it desyncs after the first block's mode)",67 "an inter frame using TxMode::Select (this decoder's inter path never reads a tx_depth symbol, so it desyncs after the first block's mode)",
68 "an inter frame whose global motion for a single-reference frame is AFFINE (unverified this round; ROTZOOM/TRANSLATION/IDENTITY are proven)",68 "an inter frame whose global motion for a single-reference frame is AFFINE (unverified this round; ROTZOOM/TRANSLATION/IDENTITY are proven)",
69 "an inter frame with no key frame before it",69 "an inter frame with no key frame before it",
70- "an inter SB-level partition type other than SPLIT (this decoder's inter tile path only recurses a superblock as SPLIT)",70+ "an inter SB-level partition type other than NONE or SPLIT (this decoder's inter tile path recurses a superblock only as SPLIT)",
71+ "a masked compound 64x64 inter block (compound_type is inferred, not coded, at this size)",
71 "an inter partition below 16x16 (8x8 and smaller inter blocks are not coded yet)",72 "an inter partition below 16x16 (8x8 and smaller inter blocks are not coded yet)",
72 "an intra mode this decoder does not code (round 2)",73 "an intra mode this decoder does not code (round 2)",
73 "an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet",74 "an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet",
crates/ec-av1/src/stream.rsmodified+159 -0
@@ -2759,6 +2759,165 @@ mod tests {
2759 /// single-`LAST_FRAME` P frame (no alt-ref/backward reference this2759 /// single-`LAST_FRAME` P frame (no alt-ref/backward reference this
2760 /// decoder's inter path does not model), `--kf-max-dist` past the clip's2760 /// decoder's inter path does not model), `--kf-max-dist` past the clip's
2761 /// own length keeps frame 0 the only key frame.2761 /// own length keeps frame 0 the only key frame.
2762+ /// lane-inter8 r1: the inter tile path's SB-level `PARTITION_NONE` -- a
2763+ /// whole 64x64 superblock coded as ONE inter block, which is what aomenc
2764+ /// picks for static content and which this decoder refused by name
2765+ /// ("an inter SB-level partition type other than SPLIT") until this
2766+ /// round. HARD-asserts [`decode::inter_sb_none_hits`] moved (the arm
2767+ /// really fired, class refusal-lifted-without-a-gate) and every frame is
2768+ /// pixel-exact vs ffmpeg; a decode error is a FAILURE here, never a SKIP
2769+ /// (class gate-skips-on-its-own-failure).
2770+ fn inter_sb_none_gate(name: &str, ten_bit: bool) {
2771+ if !have_ffmpeg() {
2772+ eprintln!("SKIP {name}: no ffmpeg");
2773+ return;
2774+ }
2775+ if !have_aomenc() {
2776+ eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display());
2777+ return;
2778+ }
2779+ let (width, height, frame_count) = (64usize, 64usize, 4usize);
2780+ // A deterministic synthetic source with real motion (a static source
2781+ // codes every inter frame as skip and never exercises the residual
2782+ // path); bounded with `-t` (class gate-loader-slurps-whole-file).
2783+ let y4m = Command::new("ffmpeg")
2784+ .args([
2785+ "-v",
2786+ "error",
2787+ "-f",
2788+ "lavfi",
2789+ "-i",
2790+ "mandelbrot=size=64x64:rate=25",
2791+ "-t",
2792+ "0.16",
2793+ "-pix_fmt",
2794+ if ten_bit { "yuv420p10le" } else { "yuv420p" },
2795+ // y4m calls 10-bit unofficial (same as the 10-bit key-frame
2796+ // gate's own fixture).
2797+ "-strict",
2798+ "-1",
2799+ "-f",
2800+ "yuv4mpegpipe",
2801+ "-",
2802+ ])
2803+ .stdin(Stdio::null())
2804+ .stdout(Stdio::piped())
2805+ .stderr(Stdio::piped())
2806+ .output()
2807+ .expect("ffmpeg failed to run");
2808+ assert!(
2809+ y4m.status.success(),
2810+ "{name}: ffmpeg fixture: {}",
2811+ String::from_utf8_lossy(&y4m.stderr)
2812+ );
2813+ let mut args: Vec<String> = [
2814+ "--codec=av1",
2815+ "--passes=1",
2816+ "--end-usage=q",
2817+ "--cq-level=40",
2818+ "--cpu-used=0",
2819+ "--lag-in-frames=0",
2820+ "--auto-alt-ref=0",
2821+ "--kf-max-dist=1000",
2822+ // No cross-frame CDF forwarding in this fixture (see the
2823+ // deblocking gate's own note).
2824+ "--error-resilient=1",
2825+ // This gate targets the SB-level NONE arm only: rect/AB/1-to-4
2826+ // partitions and sub-16x16 splits stay off so a failure here
2827+ // cannot be another lane's missing arm.
2828+ "--enable-rect-partitions=0",
2829+ "--enable-ab-partitions=0",
2830+ "--enable-1to4-partitions=0",
2831+ "--min-partition-size=32",
2832+ "--max-partition-size=64",
2833+ "--enable-filter-intra=0",
2834+ "--enable-smooth-intra=0",
2835+ "--enable-paeth-intra=0",
2836+ "--enable-directional-intra=0",
2837+ "--enable-angle-delta=0",
2838+ "--enable-tx-size-search=0",
2839+ "--enable-cdef=0",
2840+ "--enable-restoration=0",
2841+ "--enable-palette=0",
2842+ "--enable-intrabc=0",
2843+ "--enable-cfl-intra=0",
2844+ "--enable-ref-frame-mvs=0",
2845+ "--obu",
2846+ "-o",
2847+ "-",
2848+ "-",
2849+ ]
2850+ .iter()
2851+ .map(|s| (*s).to_string())
2852+ .collect();
2853+ if ten_bit {
2854+ args.insert(1, "--input-bit-depth=10".to_string());
2855+ args.insert(1, "--bit-depth=10".to_string());
2856+ }
2857+ let mut child = Command::new(aomenc_path())
2858+ .args(&args)
2859+ .stdin(Stdio::piped())
2860+ .stdout(Stdio::piped())
2861+ .stderr(Stdio::piped())
2862+ .spawn()
2863+ .expect("aomenc failed to start");
2864+ child
2865+ .stdin
2866+ .take()
2867+ .expect("aomenc stdin")
2868+ .write_all(&y4m.stdout)
2869+ .expect("writing y4m to aomenc");
2870+ let out = child.wait_with_output().expect("aomenc failed to run");
2871+ assert!(
2872+ out.status.success(),
2873+ "{name}: aomenc refused the fixture: {}",
2874+ String::from_utf8_lossy(&out.stderr)
2875+ );
2876+ let stream = out.stdout;
2877+ let before = decode::inter_sb_none_hits();
2878+ let frames = match decode_stream(&stream) {
2879+ Ok(frames) => frames,
2880+ Err(e) => {
2881+ let pin = std::env::temp_dir().join(format!("{name}-refused.obu"));
2882+ let _ = std::fs::write(&pin, &stream);
2883+ panic!("{name}: decode_stream refused a real aomenc stream: {e} (pinned at {})", pin.display());
2884+ }
2885+ };
2886+ assert!(
2887+ decode::inter_sb_none_hits() > before,
2888+ "{name}: no whole-superblock inter PARTITION_NONE fired -- this gate proves nothing"
2889+ );
2890+ let ffmpeg_frames = if ten_bit {
2891+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
2892+ } else {
2893+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
2894+ };
2895+ assert_eq!(frames.len(), frame_count, "{name}: frame count");
2896+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
2897+ if got.y != want.y || got.u != want.u || got.v != want.v {
2898+ let pin = std::env::temp_dir().join(format!("{name}-mismatch.obu"));
2899+ let _ = std::fs::write(&pin, &stream);
2900+ panic!("{name}: frame {i} mismatch vs ffmpeg -- stream pinned at {}", pin.display());
2901+ }
2902+ }
2903+ }
2904+
2905+ #[test]
2906+ fn a_real_aomenc_inter_sequence_with_a_whole_superblock_block_decodes_pixel_exact() {
2907+ inter_sb_none_gate(
2908+ "a_real_aomenc_inter_sequence_with_a_whole_superblock_block_decodes_pixel_exact",
2909+ false,
2910+ );
2911+ }
2912+
2913+ #[test]
2914+ fn a_real_aomenc_10bit_inter_sequence_with_a_whole_superblock_block_decodes_pixel_exact() {
2915+ inter_sb_none_gate(
2916+ "a_real_aomenc_10bit_inter_sequence_with_a_whole_superblock_block_decodes_pixel_exact",
2917+ true,
2918+ );
2919+ }
2920+
2762 #[test]2921 #[test]
2763 fn a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact() {2922 fn a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact() {
2764 if !have_ffmpeg() {2923 if !have_ffmpeg() {