forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-kf900' (fc7fca2): an 8x8 intra leaf ignored the use_intrabc it had just read

Browse files at this commit

c1efa28f86ccb0f1832d2fa02a69e5f2d7653a62Ahmet Kaan GümüşParent: a2877a368ca7c5
crates/ec-av1/examples/decode_probe.rsmodified+1 -0
@@ -34,6 +34,7 @@ fn main() {
3434 let (h, v, c) = ec_av1::stream::rect4_32_counters();
3535 println!("rect4_32: horz={h} vert={v} coded={c}");
3636 println!("rect_intrabc_reads: {}", ec_av1::stream::rect_intrabc_reads());
37+ println!("leaf8_intrabc_hits: {}", ec_av1::stream::leaf8_intrabc_hits());
3738 let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters();
3839 println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}");
3940 println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits());
crates/ec-av1/src/decode.rsmodified+102 -3
@@ -1715,6 +1715,22 @@ pub(crate) fn reset_rect_intrabc_reads() {
17151715 RECT_INTRABC_READS.with(|c| c.set(0));
17161716 }
17171717
1718+thread_local! {
1719+ /// Blocks that USED intrabc at an 8x8 LEAF (`decode_leaf8`) specifically
1720+ /// -- the shape lane-kf900 r7 fixed; [`INTRABC_HITS`] counts every shape.
1721+ static LEAF8_INTRABC_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1722+}
1723+
1724+/// Current value of [`LEAF8_INTRABC_HITS`].
1725+pub(crate) fn leaf8_intrabc_hits() -> usize {
1726+ LEAF8_INTRABC_HITS.with(|c| c.get())
1727+}
1728+
1729+/// Zeroes [`LEAF8_INTRABC_HITS`] (gate tests call this before a decode).
1730+pub(crate) fn reset_leaf8_intrabc_hits() {
1731+ LEAF8_INTRABC_HITS.with(|c| c.set(0));
1732+}
1733+
17181734 /// Current value of [`INTRABC_HITS`].
17191735 pub(crate) fn intrabc_hits() -> usize {
17201736 INTRABC_HITS.with(|c| c.get())
@@ -3822,7 +3838,7 @@ fn read_coeffs(
38223838 let t = dec.symbol(tx_type_cdf);
38233839 if std::env::var_os("EC_TRACE_COEFF").is_some() {
38243840 let (rng, _) = dec.debug_state();
3825- eprintln!("EC_COEFF_STEP tag=tx_type rng={rng}");
3841+ eprintln!("EC_COEFF_STEP tag=tx_type len={len} rng={rng}");
38263842 }
38273843 if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() {
38283844 let (range, value) = dec.debug_state();
@@ -10951,6 +10967,24 @@ fn decode_leaf8(
1095110967 leaf_mi.0,
1095210968 leaf_mi.1,
1095310969 )?;
10970+ // lane-kf900 r7: an 8x8 leaf consumed `use_intrabc` (and its DV) through
10971+ // `read_intra_mode` and then decoded the block as if it were ordinary
10972+ // intra. libaom's `is_inter_block` counts an intrabc block
10973+ // (`blockd.h:373`), so its luma `tx_type` comes off the INTER ext-tx set
10974+ // (`av1_get_ext_tx_set_type(TX_8X8, is_inter=1, 0)` = `EXT_TX_SET_ALL16`,
10975+ // a 16-symbol CDF) while we read the 7-symbol `TX_SET_INTRA_1` row: the
10976+ // same value with a different interval, so the tile desynced at the very
10977+ // next symbol (class `wrong-alphabet-same-value`). Everything below
10978+ // mirrors `decode_block`'s own intrabc handling at 16x16 and up.
10979+ let intrabc_dv = INTRABC_DV.with(|c| c.take());
10980+ if intrabc_dv.is_some() {
10981+ LEAF8_INTRABC_HITS.with(|c| c.set(c.get() + 1));
10982+ }
10983+ if intrabc_dv.is_some() && tx_select && !skip {
10984+ return Err(unsupported(
10985+ "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)",
10986+ ));
10987+ }
1095410988 let uv_predict_mode = if uv_mode == UV_CFL_PRED {
1095510989 DC_PRED
1095610990 } else {
@@ -10964,7 +10998,11 @@ fn decode_leaf8(
1096410998 // which splits the leaf's own 8x8 prediction into a 2x2 grid of 4x4
1096510999 // transform units, same raster-order per-TU pattern `decode_block`'s
1096611000 // multi-TU branch runs).
10967- let resolved = if tx_select {
11001+ // ... and an intrabc leaf reads no intra `tx_depth` symbol at all: under
11002+ // `TX_MODE_SELECT` a skipped inter block takes the largest transform
11003+ // (`read_tx_size(.., is_inter=1, ..)`), and the unskipped case is refused
11004+ // above.
11005+ let resolved = if tx_select && intrabc_dv.is_none() {
1096811006 read_tx_size(dec, cdfs, neighbours, leaf_mi, 8, None)
1096911007 } else {
1097011008 8
@@ -10972,6 +11010,37 @@ fn decode_leaf8(
1097211010 let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
1097311011 let reach = Reach::of(8, px, py, y.width, y.height);
1097411012 let (cpx, cpy) = (px / 2, py / 2);
11013+ // spec 7.11.3.4 with `use_intrabc`, same as `decode_block`: predict from
11014+ // the CURRENT frame's own pre-loop-filter reconstruction (every loop
11015+ // filter is off whenever `allow_intrabc`, frame.rs:194/210/252/272) at
11016+ // the full-pel block vector, with the BILINEAR kernel libaom forces.
11017+ let intrabc_bufs = intrabc_dv.map(|(dv_row, dv_col)| {
11018+ let mut yb = vec![0u16; 8 * 8];
11019+ mc::predict_with_filter(
11020+ &y.data, y.width, y.true_width, y.true_height,
11021+ mv_to_q4(px, dv_col, true), mv_to_q4(py, dv_row, true),
11022+ 8, 8, mc::InterpFilterKind::Bilinear, &mut yb,
11023+ );
11024+ let mut ub = vec![0u16; 4 * 4];
11025+ mc::predict_with_filter(
11026+ &u.data, u.width, u.true_width, u.true_height,
11027+ mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false),
11028+ 4, 4, mc::InterpFilterKind::Bilinear, &mut ub,
11029+ );
11030+ let mut vb = vec![0u16; 4 * 4];
11031+ mc::predict_with_filter(
11032+ &v.data, v.width, v.true_width, v.true_height,
11033+ mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false),
11034+ 4, 4, mc::InterpFilterKind::Bilinear, &mut vb,
11035+ );
11036+ (yb, ub, vb)
11037+ });
11038+ // The per-plane prediction override rides the same [`PALETTE_PRED`] slot
11039+ // `decode_block` uses: set fresh right before each plane's own
11040+ // `reconstruct`/`read_plane` call (the slot is taken, not copied).
11041+ if let Some((yb, _, _)) = &intrabc_bufs {
11042+ set_palette_pred(yb.clone());
11043+ }
1097511044 let (luma_grid, u_grid, v_grid);
1097611045 if skip {
1097711046 // lane-hgkf r2 (same shape as `decode_block`'s own skip branch): an
@@ -11028,6 +11097,9 @@ fn decode_leaf8(
1102811097 );
1102911098 }
1103011099 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));
11100+ if let Some((_, ub, _)) = &intrabc_bufs {
11101+ set_palette_pred(ub.clone());
11102+ }
1103111103 u.reconstruct(
1103211104 cpx,
1103311105 cpy,
@@ -11040,6 +11112,9 @@ fn decode_leaf8(
1104011112 None,
1104111113 smooth_neighbor_uv,
1104211114 );
11115+ if let Some((_, _, vb)) = &intrabc_bufs {
11116+ set_palette_pred(vb.clone());
11117+ }
1104311118 v.reconstruct(
1104411119 cpx,
1104511120 cpy,
@@ -11060,7 +11135,9 @@ fn decode_leaf8(
1106011135 luma_grid = read_plane(
1106111136 dec,
1106211137 cdfs,
11063- if reduced_tx_set {
11138+ if intrabc_dv.is_some() {
11139+ txbset_for_inter(8, reduced_tx_set)
11140+ } else if reduced_tx_set {
1106411141 TxbSet::Luma8
1106511142 } else {
1106611143 TxbSet::Luma8Set1
@@ -11083,7 +11160,16 @@ fn decode_leaf8(
1108311160 None,
1108411161 smooth_neighbor,
1108511162 )?;
11163+ // `av1_get_tx_type` branches `PLANE_TYPE_UV` on `is_inter_block`, so
11164+ // an intrabc block's chroma tx_type is the colocated LUMA transform's
11165+ // coded type (lane-kf900 r6's own fix, `decode_block`'s line).
11166+ if intrabc_dv.is_some() {
11167+ INTRABC_CHROMA_TX.with(|c| c.set(Some(LUMA_TX_TYPE.with(std::cell::Cell::get))));
11168+ }
1108611169 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));
11170+ if let Some((_, ub, _)) = &intrabc_bufs {
11171+ set_palette_pred(ub.clone());
11172+ }
1108711173 u_grid = read_plane(
1108811174 dec,
1108911175 cdfs,
@@ -11106,6 +11192,9 @@ fn decode_leaf8(
1110611192 None,
1110711193 smooth_neighbor_uv,
1110811194 )?;
11195+ if let Some((_, _, vb)) = &intrabc_bufs {
11196+ set_palette_pred(vb.clone());
11197+ }
1110911198 v_grid = read_plane(
1111011199 dec,
1111111200 cdfs,
@@ -11128,6 +11217,11 @@ fn decode_leaf8(
1112811217 None,
1112911218 smooth_neighbor_uv,
1113011219 )?;
11220+ // Disarm: `INTRABC_CHROMA_TX` is `Some` across exactly this block's
11221+ // two chroma reads (`decode_block`'s own tail does the same) -- left
11222+ // set, every later chroma block would inherit this luma tx_type,
11223+ // which picks the scan and the inverse transform.
11224+ INTRABC_CHROMA_TX.with(|c| c.set(None));
1113111225 } else {
1113211226 // `tx_depth` resolved this leaf's luma to `TX4`: a 2x2 raster-order
1113311227 // grid of 4x4 transform units, each predicted from the leaf's own
@@ -11278,6 +11372,7 @@ fn decode_leaf8(
1127811372 neighbours.fill_skip_grid(leaf_mi, 2, skip);
1127911373 neighbours.fill_lf_grid(leaf_mi, 2, 4, 0);
1128011374 neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode);
11375+ record_intrabc_mi(leaf_mi.0, leaf_mi.1, 2, intrabc_dv);
1128111376 return Ok(mode);
1128211377 }
1128311378 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);
@@ -11302,6 +11397,10 @@ fn decode_leaf8(
1130211397 // -ss 900, first bad luma sample row 186 col 1803).
1130311398 neighbours.fill_lf_grid(leaf_mi, 2, resolved as u8, 0);
1130411399 neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode);
11400+ // The DV predictor of a LATER intrabc block is the ordinary `INTRA_FRAME`
11401+ // MV stack over this grid (`av1_find_mv_refs`), so an 8x8 leaf has to
11402+ // publish its own cells exactly like `decode_block` does.
11403+ record_intrabc_mi(leaf_mi.0, leaf_mi.1, 2, intrabc_dv);
1130511404 Ok(mode)
1130611405 }
1130711406
crates/ec-av1/src/stream.rsmodified+32 -1
@@ -116,6 +116,12 @@ pub fn sb128_rect_counters() -> (usize, usize, usize, usize) {
116116 )
117117 }
118118
119+/// Blocks reconstructed with intra block copy at an 8x8 LEAF specifically
120+/// (lane-kf900 r7's shape); [`crate::decode::intrabc_hits`] counts every shape.
121+pub fn leaf8_intrabc_hits() -> usize {
122+ crate::decode::leaf8_intrabc_hits()
123+}
124+
119125 pub fn rect4_32_counters() -> (usize, usize, usize) {
120126 (
121127 crate::decode::rect4_32_horz_hits(),
@@ -2875,7 +2881,7 @@ mod tests {
28752881 const SB: &str = "smptebars=size=256x192:rate=25";
28762882 // (arm, source, per-arm overrides AFTER the base recipe, expect_refusal,
28772883 // must_read_use_intrabc_on_a_rect_strip)
2878- let arms: [(&str, &str, &[&str], bool, bool); 7] = [
2884+ let arms: [(&str, &str, &[&str], bool, bool); 8] = [
28792885 ("testsrc2-cq50-txs0", TS, &["--cq-level=50", "--enable-palette=0", "--enable-tx-size-search=0"], true, true),
28802886 ("smptebars-cq40-txs0", SB, &["--cq-level=40", "--enable-palette=0", "--enable-tx-size-search=0"], false, false),
28812887 ("smptebars-cq45-txs0", SB, &["--cq-level=45", "--enable-palette=0", "--enable-tx-size-search=0"], false, true),
@@ -2883,10 +2889,17 @@ mod tests {
28832889 ("smptebars-cq50-txs1", SB, &["--cq-level=50", "--enable-palette=0", "--enable-tx-size-search=1"], false, false),
28842890 ("smptebars-cq55-txs0", SB, &["--cq-level=55", "--enable-palette=0", "--enable-tx-size-search=0"], false, false),
28852891 ("testsrc2-cq63-txs1", TS, &["--cq-level=63", "--enable-palette=0", "--enable-tx-size-search=1"], false, false),
2892+ // lane-kf900 r7: the 8x8-LEAF intrabc arm. Rect and 1:4
2893+ // partitions off (so no rect strip refuses first), palette on,
2894+ // `TxMode::Largest`: aomenc puts exactly one `use_intrabc` block
2895+ // on a `BLOCK_8X8` leaf here, the shape `decode_leaf8` decoded as
2896+ // ordinary intra before this round.
2897+ ("testsrc2-cq55-leaf8", TS, &["--cq-level=55", "--enable-palette=1", "--enable-tx-size-search=0", "--enable-rect-partitions=0", "--enable-1to4-partitions=0"], false, false),
28862898 ];
28872899 let (mut reads_total, mut refused, mut frames_compared) = (0usize, 0u32, 0usize);
28882900 let (mut blocks_total, mut fired_arms, mut out_of_scope, mut out_of_scope_mismatch) =
28892901 (0usize, 0u32, 0u32, 0u32);
2902+ let mut leaf8_total = 0usize;
28902903 for (arm, src, extra, expect_refusal, must_read) in &arms {
28912904 let render = || {
28922905 let out = Command::new("ffmpeg")
@@ -2958,6 +2971,7 @@ mod tests {
29582971 let stream = out.stdout;
29592972 decode::reset_rect_intrabc_reads();
29602973 crate::decode::reset_intrabc_hits();
2974+ crate::decode::reset_leaf8_intrabc_hits();
29612975 let decoded = decode_stream(&stream);
29622976 let reads = decode::rect_intrabc_reads();
29632977 // Blocks that decoded `use_intrabc == 1` (square path), i.e. that
@@ -2966,6 +2980,18 @@ mod tests {
29662980 let blocks = crate::decode::intrabc_hits();
29672981 reads_total += reads;
29682982 blocks_total += blocks;
2983+ // The 8x8-leaf shape has its own counter: without it this gate's
2984+ // other arms (all rect/32x32 intrabc) would stay green while the
2985+ // leaf path decoded an intrabc block as ordinary intra (class
2986+ // `gate-blind-to-feature`).
2987+ let leaf8 = crate::decode::leaf8_intrabc_hits();
2988+ leaf8_total += leaf8;
2989+ if *arm == "testsrc2-cq55-leaf8" {
2990+ assert!(
2991+ leaf8 > 0,
2992+ "{NAME}: {arm} decoded no intrabc block at an 8x8 leaf -- the arm no longer exercises `decode_leaf8`'s intrabc path"
2993+ );
2994+ }
29692995 if *must_read {
29702996 assert!(
29712997 reads > 0,
@@ -3036,7 +3062,12 @@ mod tests {
30363062 {refused} refused by name, {frames_compared} frames compared, \
30373063 {out_of_scope} out of scope ({out_of_scope_mismatch} mismatched)"
30383064 );
3065+ eprintln!("{NAME}: {leaf8_total} intrabc block(s) at an 8x8 leaf");
30393066 assert!(reads_total > 0, "{NAME}: gate is vacuous -- no arm read the symbol");
3067+ assert!(
3068+ leaf8_total > 0,
3069+ "{NAME}: no arm decoded an intrabc block at an 8x8 leaf -- lane-kf900 r7's fix is untested"
3070+ );
30403071 assert!(
30413072 blocks_total > 0 && fired_arms > 0,
30423073 "{NAME}: gate is vacuous -- no compared arm actually decoded an intrabc block"
lanes/kf900-r7.handoff.mdadded+67 -0
@@ -0,0 +1,67 @@
1+# lane-kf900 r7 HANDOFF -- 8x8-leaf intrabc decoded as ordinary intra
2+
3+## Merge state
4+`git merge --no-commit main` (main `3566501`) auto-merged clean (decode.rs, stream.rs,
5+gate_coverage.rs), committed as `6c22a5f`. The r6 palette-at-mi-granularity hunks and the
6+intrabc chroma tx_type fix survive untouched (Neighbours palette fns re-read after the merge).
7+
8+## Root cause of the r6 "last superblock" residue (found, fixed)
9+Stream `$HOME/.cache/kf900-r6/DIFF_55_0_1_test.obu` (testsrc2 256x192 cq55 txs=0 palette=1
10+screen 8-bit). The r6 report's "entropy stays in sync, reconstruction defect, deltas ~4" was
11+WRONG on both counts: deltas run to +-171 and it is an ENTROPY desync -- invisible because the
12+bad block sits in the LAST superblock, so nothing after it could disagree.
13+
14+* Stage: mode info -> first coefficient TU. Cross-decoder `EC_TRACE_MODE_STEP` ladder diverges
15+ at mi(34,52) (luma 136,208): both decoders read skip/cdef/dq at rng=42705, then the next
16+ block starts at oracle rng=52073 vs ours 33144.
17+* Block: an 8x8 **leaf** (`decode_leaf8`) that decoded `use_intrabc=1`, DV `(-512,-1360)`
18+ (identical on both sides -- `EC_TRACE_IBC`, so the DV read is exonerated for the 3rd time).
19+* Element: the luma `tx_type`. `EC_TRACE_COEFF` (our trace now prints the CDF width, `len=`):
20+ ours read an 8-slot row (`TX_SET_INTRA_1`, 7 symbols), libaom reads
21+ `av1_get_ext_tx_set_type(TX_8X8, is_inter=1, 0)` = `EXT_TX_SET_ALL16` (16 symbols), because
22+ `is_inter_block(mbmi)` counts `is_intrabc_block` (`av1/common/blockd.h:373`, set chooser
23+ `av1/common/blockd.h` `av1_get_tx_type`). Same value, different interval -- class
24+ `wrong-alphabet-same-value`.
25+* Why only there: `decode_leaf8` consumed `use_intrabc` + the DV through `read_intra_mode` and
26+ then ignored the result entirely -- no inter ext-tx set, no chroma tx_type inheritance, no
27+ prediction from the current frame, no `record_intrabc_mi`. `decode_block` (16x16 and up) had
28+ all four since r6.
29+
30+## Fix (crates/ec-av1/src/decode.rs, `decode_leaf8`)
31+1. take `INTRABC_DV`; refuse under `TxMode::Select && !skip` with `decode_block`'s EXISTING
32+ refusal string (no new inventory entry); a skipped intrabc leaf reads no intra `tx_depth`.
33+2. luma set `txbset_for_inter(8, reduced_tx_set)`.
34+3. BILINEAR prediction from the current frame at the DV (8x8 luma, 4x4 chroma) through the
35+ `PALETTE_PRED` override slot, in both the skip and non-skip branches.
36+4. `INTRABC_CHROMA_TX` armed after the luma read and **disarmed** after the V read (leaving it
37+ armed leaked the luma tx_type into every later chroma block: 320 chroma samples wrong,
38+ luma exact -- second bug, found by re-measuring).
39+5. `record_intrabc_mi(leaf_mi, 2, intrabc_dv)` on both exits (a later DV's MV stack).
40+Plus counter `LEAF8_INTRABC_HITS` + `stream::leaf8_intrabc_hits()` + a `decode_probe` line.
41+
42+Measured, 8-bit `$HOME/.cache/kf900-r7/S_DIFF_test_55_r0_d8.obu` (same source/cq, rect+1:4 off
43+so no rect-strip refusal fires first): before 320 chroma samples wrong / entropy desync at the
44+leaf; after **0 bytes differ vs ffmpeg** (`cmp -l` = 0), `leaf8_intrabc_hits=1`, and the
45+`all_zero`/`eob` range ladder is identical for all 499 steps.
46+The ORIGINAL r6 stream now stops earlier at the pre-existing named refusal
47+"intra block copy on a HORZ/VERT/1:4 rect intra strip" instead of decoding wrong pixels.
48+
49+## Gate state
50+`a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips` gained arm 8
51+`testsrc2-cq55-leaf8` (`--cq-level=55 --enable-palette=1 --enable-tx-size-search=0
52+--enable-rect-partitions=0 --enable-1to4-partitions=0` after the base recipe), a hard per-arm
53+`leaf8 > 0` assert and a gate-wide `leaf8_total > 0` vacuity assert.
54+`cargo test -p ec-av1 --lib -j3 -- intrabc palette --nocapture` = **8 passed, 0 failed** (45s).
55+
56+## Exact next steps
57+1. FULL SUITE NOT RUN this round (turn cap). Run:
58+ `systemd-run --user --unit=kf900-suite-r7-$(date +%s) -p MemoryMax=10G --same-dir bash -lc
59+ 'EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-kf900
60+ nice -n 10 cargo test -p ec-av1 --lib -j3 > $HOME/.cache/kf900-suite-r7.log 2>&1'`
61+ then `grep -E "^test result|FAILED" $HOME/.cache/kf900-suite-r7.log`. r6 baseline 385/0/33.
62+2. 10-bit leaf8 arm: the r7 sweep (`$HOME/.cache/kf900-r7/sweep.sh`, 3 sources x 5 cq x rect
63+ on/off x 8/10 bit) produced NO decoding 10-bit stream at all (every 10-bit arm refuses on
64+ another lane's gap), so the 8x8-leaf intrabc fix is 8-bit-proven only. Widen the sweep
65+ (other sources / `--max-partition-size=16`) or wait for the sibling lanes.
66+3. Still open (unchanged from r6): rect-strip intrabc reconstruction refusal -- now the FIRST
67+ thing `DIFF_55_0_1_test.obu` hits; porting BILINEAR prediction at rect shapes closes it.