A skipped 8x8 intra leaf recorded its block side, not its resolved transform, in the txfm context
Browse files at this commit94961f4b30ca2b764cd687f7e44ca434fd23f0a2Parent: c6cb99f- fix
- a skipped 8x8 intra leaf recorded its block side, not its resolved transform, in the txfm context
4 changed files +99 -5
- crates/ec-av1/examples/decode_probe.rs +1 -0
- crates/ec-av1/fixtures/reelb_ss600_key_frame.obu +0 -0
- crates/ec-av1/src/decode.rs +22 -2
- crates/ec-av1/src/stream.rs +76 -3
crates/ec-av1/examples/decode_probe.rsmodified+1 -0
| @@ -31,6 +31,7 @@ fn main() { | ||
| 31 | 31 | let report = || { |
| 32 | 32 | let (h, v, c) = ec_av1::stream::rect4_32_counters(); |
| 33 | 33 | println!("rect4_32: horz={h} vert={v} coded={c}"); |
| 34 | + println!("skip_split_tx: {}", ec_av1::decode::skip_split_tx_hits()); | |
| 34 | 35 | let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters(); |
| 35 | 36 | println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}"); |
| 36 | 37 | let ir = ec_av1::stream::inter_rect_counters(); |
crates/ec-av1/fixtures/reelb_ss600_key_frame.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+22 -2
| @@ -2652,6 +2652,12 @@ const MAX_BR_LEVEL: i32 = NUM_BASE_LEVELS + COEFF_BASE_RANGE; | ||
| 2652 | 2652 | const VERT_ALIKE: [usize; 6] = [2, PARTITION_SPLIT, 4, 6, 7, 9]; |
| 2653 | 2653 | const HORZ_ALIKE: [usize; 6] = [1, PARTITION_SPLIT, 4, 5, 6, 8]; |
| 2654 | 2654 | |
| 2655 | +fn trace_edge(mi_r: usize, mi_c: usize, bsize: u32, ctx: usize, rng: u32) { | |
| 2656 | + if std::env::var_os("EC_AV1_TRACE").is_some() { | |
| 2657 | + eprintln!("OUR_PART mi_row={mi_r} mi_col={mi_c} bsize={bsize} ctx={ctx} rng={rng}"); | |
| 2658 | + } | |
| 2659 | +} | |
| 2660 | + | |
| 2655 | 2661 | fn element_prob(cdf: &[u16], element: usize) -> u16 { |
| 2656 | 2662 | cdf[element] - if element > 0 { cdf[element - 1] } else { 0 } |
| 2657 | 2663 | } |
| @@ -10321,7 +10327,15 @@ fn decode_leaf8( | ||
| 10321 | 10327 | neighbours.record_palette_uv_rect(pal_at, 8, 8, 0, [0u16; 8]); |
| 10322 | 10328 | } |
| 10323 | 10329 | neighbours.fill_skip_grid(leaf_mi, 2, skip); |
| 10324 | - neighbours.fill_lf_grid(leaf_mi, 2, 8, 0); | |
| 10330 | + // lane-kf1200 r3: the leaf's OWN resolved transform, not its 8x8 side -- | |
| 10331 | + // an intra block reads `tx_depth` whether or not it is skipped | |
| 10332 | + // (`read_tx_size` runs above the `skip` branch), so a SKIPPED 8x8 leaf | |
| 10333 | + // that resolved to TX_4X4 recorded 8 here and the next block's | |
| 10334 | + // `get_tx_size_context` left/above term then read 8 >= 8 and picked the | |
| 10335 | + // wrong `tx_size_cdf` row (libaom `set_txfm_ctxs` writes `tx_size` for | |
| 10336 | + // every intra block; only a skipped INTER block writes its block size). | |
| 10337 | + // The non-skip TX_4X4 branch above already returns early with 4. | |
| 10338 | + neighbours.fill_lf_grid(leaf_mi, 2, resolved as u8, 0); | |
| 10325 | 10339 | neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode); |
| 10326 | 10340 | Ok(mode) |
| 10327 | 10341 | } |
| @@ -13322,11 +13336,13 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 13322 | 13336 | // the first block of that row. |
| 13323 | 13337 | match (has_cols, has_rows) { |
| 13324 | 13338 | (true, false) => { |
| 13339 | + trace_edge((sb_r * SB_MI) as usize, (sb_c * SB_MI) as usize, 12, ctx, dec.debug_state().0 as u32); | |
| 13325 | 13340 | let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE)); |
| 13326 | 13341 | bump_edge_part(b.min(1) as usize); |
| 13327 | 13342 | if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ } |
| 13328 | 13343 | } |
| 13329 | 13344 | (false, true) => { |
| 13345 | + trace_edge((sb_r * SB_MI) as usize, (sb_c * SB_MI) as usize, 12, ctx, dec.debug_state().0 as u32); | |
| 13330 | 13346 | let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE)); |
| 13331 | 13347 | bump_edge_part(b.min(1) as usize); |
| 13332 | 13348 | if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT } |
| @@ -13392,6 +13408,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 13392 | 13408 | // superblock level above). |
| 13393 | 13409 | match (has_cols32, has_rows32) { |
| 13394 | 13410 | (true, false) => { |
| 13411 | + trace_edge((r32 * BLOCK_MI) as usize, (c32 * BLOCK_MI) as usize, 9, ctx32, dec.debug_state().0 as u32); | |
| 13395 | 13412 | let b = dec.symbol_fixed(&gather( |
| 13396 | 13413 | &cdfs.partition_w32[ctx32], |
| 13397 | 13414 | VERT_ALIKE, |
| @@ -13400,6 +13417,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 13400 | 13417 | if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ } |
| 13401 | 13418 | } |
| 13402 | 13419 | (false, true) => { |
| 13420 | + trace_edge((r32 * BLOCK_MI) as usize, (c32 * BLOCK_MI) as usize, 9, ctx32, dec.debug_state().0 as u32); | |
| 13403 | 13421 | let b = dec.symbol_fixed(&gather( |
| 13404 | 13422 | &cdfs.partition_w32[ctx32], |
| 13405 | 13423 | HORZ_ALIKE, |
| @@ -13878,6 +13896,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 13878 | 13896 | // This path can only walk the four SPLIT |
| 13879 | 13897 | // leaves, so a 0 refuses by name instead |
| 13880 | 13898 | // of desyncing. |
| 13899 | + trace_edge(sr * SUB_MI as usize, sc * SUB_MI as usize, 6, ctx16, dec.debug_state().0 as u32); | |
| 13881 | 13900 | let edge_split = if has_cols16 { |
| 13882 | 13901 | dec.symbol_fixed(&gather( |
| 13883 | 13902 | &cdfs.partition_w16[ctx16], |
| @@ -13958,10 +13977,11 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 13958 | 13977 | } |
| 13959 | 13978 | } |
| 13960 | 13979 | let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); |
| 13980 | + let pre8 = dec.debug_state().0; | |
| 13961 | 13981 | let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); |
| 13962 | 13982 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 13963 | 13983 | eprintln!( |
| 13964 | - "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}" | |
| 13984 | + "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8} pre_rng={pre8}" | |
| 13965 | 13985 | ); |
| 13966 | 13986 | } |
| 13967 | 13987 | let leaf_mode = if part8 == PARTITION_NONE { |
crates/ec-av1/src/stream.rsmodified+76 -3
| @@ -3014,6 +3014,50 @@ mod tests { | ||
| 3014 | 3014 | eprintln!("{NAME}: {skipped_cfl} skipped sub-8x8 CfL chroma blocks, frame pixel-exact"); |
| 3015 | 3015 | } |
| 3016 | 3016 | |
| 3017 | + /// lane-kf1200 r3: the same film's `-ss 600` key frame (3840x1608, one | |
| 3018 | + /// 8-px partial bottom superblock row), pinned because no aomenc recipe | |
| 3019 | + /// reaches its shape -- a SKIPPED 8x8 intra leaf whose `tx_depth` resolved | |
| 3020 | + /// to TX_4X4. (80 recipes swept this round: 4 frame shapes x 2 sources x | |
| 3021 | + /// cq 32..63 x cpu-used 0/3 x 8/10-bit, all with | |
| 3022 | + /// `--enable-tx-size-search=1 --enable-filter-intra=1`; every one came | |
| 3023 | + /// back with `skip_split_tx_hits == 0`, `lanes/kf1200-r3.report.md`.) | |
| 3024 | + /// An intra block reads `tx_depth` whether or not it is skipped, so the | |
| 3025 | + /// leaf must record its resolved 4 -- not its 8x8 side -- in the txfm | |
| 3026 | + /// context; recording 8 gave the NEXT block's `tx_depth` symbol the wrong | |
| 3027 | + /// `tx_size_cdf` row (ctx 2 where libaom reads 1) and desynced the | |
| 3028 | + /// entropy stream at mi (400,46). HARD-asserts `skip_split_tx_hits` moved. | |
| 3029 | + #[test] | |
| 3030 | + fn the_reelb_ss600_key_frame_skipped_split_tx_decodes_pixel_exact() { | |
| 3031 | + const NAME: &str = "the_reelb_ss600_key_frame_skipped_split_tx_decodes_pixel_exact"; | |
| 3032 | + if !have_ffmpeg() { | |
| 3033 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 3034 | + return; | |
| 3035 | + } | |
| 3036 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | |
| 3037 | + .join("fixtures/reelb_ss600_key_frame.obu"); | |
| 3038 | + let stream = std::fs::read(&path) | |
| 3039 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); | |
| 3040 | + let (width, height) = (3840usize, 1608usize); | |
| 3041 | + crate::decode::reset_skip_split_tx_hits(); | |
| 3042 | + let frames = match decode_stream(&stream) { | |
| 3043 | + Ok(frames) => frames, | |
| 3044 | + Err(e) => panic!("{NAME}: decode_stream refused: {e}"), | |
| 3045 | + }; | |
| 3046 | + let skipped_split_tx = crate::decode::skip_split_tx_hits(); | |
| 3047 | + assert!( | |
| 3048 | + skipped_split_tx > 0, | |
| 3049 | + "{NAME}: zero skipped 8x8 leaves with a split transform -- the fixture no longer \ | |
| 3050 | + exercises the arm this test exists for" | |
| 3051 | + ); | |
| 3052 | + assert_eq!(frames.len(), 1, "{NAME}: one key frame"); | |
| 3053 | + assert_eq!((frames[0].width, frames[0].height), (width, height)); | |
| 3054 | + let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, width, height, 1); | |
| 3055 | + assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg"); | |
| 3056 | + assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg"); | |
| 3057 | + assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg"); | |
| 3058 | + eprintln!("{NAME}: {skipped_split_tx} skipped 8x8 TX_4X4 leaves, frame pixel-exact"); | |
| 3059 | + } | |
| 3060 | + | |
| 3017 | 3061 | /// lane-hbd10 r1: a real `aomenc --bit-depth=10 --superres-mode=1 |
| 3018 | 3062 | /// --superres-denominator=12` key frame, decoded pixel-exact against |
| 3019 | 3063 | /// ffmpeg's own 10-bit decode. Proves `superres::upscale_row`'s |
| @@ -22728,16 +22772,29 @@ mod tests { | ||
| 22728 | 22772 | let mut compared = 0usize; |
| 22729 | 22773 | let mut edge_horz_total = 0usize; |
| 22730 | 22774 | let mut edge_sub_total = 0usize; |
| 22775 | + let mut skip_split_tx_total = 0usize; | |
| 22731 | 22776 | // The last two shapes are the ledger-measured 64-level pair: on a |
| 22732 | 22777 | // flat band (192x80 / 80x192) real aomenc answers the bottom-edge |
| 22733 | 22778 | // superblock with the 64-level HORZ/VERT, which the 136 shapes above |
| 22734 | 22779 | // never produce (their SBs always split down to the 32/16 levels). |
| 22780 | + // lane-kf1200 r3: the 2-/4-/6-mi partial bottom rows (h mod 64 == 8, | |
| 22781 | + // 16, 24) with partial RIGHT columns as well (w mod 64 == 8), the | |
| 22782 | + // geometry of the film key frames this lane chases. | |
| 22735 | 22783 | for (width, height, flat) in [ |
| 22736 | 22784 | (192usize, 136usize, false), |
| 22737 | 22785 | (136usize, 192usize, false), |
| 22738 | 22786 | (192usize, 80usize, true), |
| 22739 | 22787 | (80usize, 192usize, true), |
| 22788 | + (200usize, 72usize, false), | |
| 22789 | + (136usize, 88usize, false), | |
| 22790 | + (264usize, 104usize, false), | |
| 22740 | 22791 | ] { |
| 22792 | + // lane-kf1200 r3 (class `tool-disabled-in-every-gate`): the whole | |
| 22793 | + // recipe ran with `--enable-tx-size-search=0`, so no block ever | |
| 22794 | + // carried a nonzero `tx_depth` and the SKIPPED 8x8 leaf that | |
| 22795 | + // resolves to TX_4X4 -- whose txfm context this round fixed -- | |
| 22796 | + // was unreachable by construction. The second arm turns it on. | |
| 22797 | + for tx_search in [0usize, 1] { | |
| 22741 | 22798 | for depth in [8usize, 10] { |
| 22742 | 22799 | let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; |
| 22743 | 22800 | let y4m = Command::new("ffmpeg") |
| @@ -22768,7 +22825,8 @@ mod tests { | ||
| 22768 | 22825 | "--cpu-used=3", "--threads=1", "--row-mt=0", "--sb-size=64", |
| 22769 | 22826 | "--kf-max-dist=0", "--enable-rect-partitions=1", |
| 22770 | 22827 | "--enable-ab-partitions=0", "--enable-1to4-partitions=0", |
| 22771 | - "--enable-tx-size-search=0", "--reduced-tx-type-set=1", | |
| 22828 | + &format!("--enable-tx-size-search={tx_search}"), | |
| 22829 | + "--reduced-tx-type-set=1", | |
| 22772 | 22830 | "--min-partition-size=8", "--max-partition-size=64", |
| 22773 | 22831 | &format!("--input-bit-depth={depth}"), |
| 22774 | 22832 | &format!("--bit-depth={depth}"), |
| @@ -22800,6 +22858,7 @@ mod tests { | ||
| 22800 | 22858 | "{NAME}: aomenc output is not reproducible ({width}x{height}, depth={depth})" |
| 22801 | 22859 | ); |
| 22802 | 22860 | crate::decode::reset_edge_part_hits(); |
| 22861 | + crate::decode::reset_skip_split_tx_hits(); | |
| 22803 | 22862 | let frames = match decode_stream(&stream) { |
| 22804 | 22863 | Ok(frames) => frames, |
| 22805 | 22864 | Err(e) => { |
| @@ -22815,6 +22874,7 @@ mod tests { | ||
| 22815 | 22874 | } |
| 22816 | 22875 | }; |
| 22817 | 22876 | let hits = crate::decode::edge_part_hits(); |
| 22877 | + let skip_split_tx = crate::decode::skip_split_tx_hits(); | |
| 22818 | 22878 | let ffmpeg_frames = if depth == 10 { |
| 22819 | 22879 | ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len()) |
| 22820 | 22880 | } else { |
| @@ -22840,12 +22900,15 @@ mod tests { | ||
| 22840 | 22900 | compared += 1; |
| 22841 | 22901 | edge_horz_total += hits[0]; |
| 22842 | 22902 | edge_sub_total += hits[2]; |
| 22903 | + skip_split_tx_total += skip_split_tx; | |
| 22843 | 22904 | eprintln!( |
| 22844 | - "{NAME}: pixel-exact {width}x{height} at {depth}-bit, edge bits \ | |
| 22845 | - 64-level horz/vert={} split={} sub-level horz/vert={} split={}", | |
| 22905 | + "{NAME}: pixel-exact {width}x{height} at {depth}-bit tx_search={tx_search}, \ | |
| 22906 | + edge bits 64-level horz/vert={} split={} sub-level horz/vert={} split={}, \ | |
| 22907 | + skipped 8x8 leaves with TX_4X4 {skip_split_tx}", | |
| 22846 | 22908 | hits[0], hits[1], hits[2], hits[3] |
| 22847 | 22909 | ); |
| 22848 | 22910 | } |
| 22911 | + } | |
| 22849 | 22912 | } |
| 22850 | 22913 | assert!( |
| 22851 | 22914 | compared > 0, |
| @@ -22860,5 +22923,15 @@ mod tests { | ||
| 22860 | 22923 | edge_sub_total > 0, |
| 22861 | 22924 | "{NAME}: no 32/16-level frame-edge bit was ever answered HORZ/VERT" |
| 22862 | 22925 | ); |
| 22926 | + // lane-kf1200 r3: the `--enable-tx-size-search=1` half of the window | |
| 22927 | + // exists so a partial-row block can carry a nonzero `tx_depth` at all | |
| 22928 | + // (the whole recipe ran with it OFF before -- class | |
| 22929 | + // `tool-disabled-in-every-gate`). The SKIPPED 8x8 leaf that resolves | |
| 22930 | + // to TX_4X4 -- whose txfm context this round fixed -- is NOT reachable | |
| 22931 | + // from any synthetic source measured here (80 recipes, all zero), so | |
| 22932 | + // that arm is asserted by the pinned film fixture | |
| 22933 | + // `the_reelb_ss600_key_frame_skipped_split_tx_decodes_pixel_exact` | |
| 22934 | + // instead; this counter is reported, not gated. | |
| 22935 | + eprintln!("{NAME}: {skip_split_tx_total} skipped 8x8 TX_4X4 leaves across compared attempts"); | |
| 22863 | 22936 | } |
| 22864 | 22937 | } |