From d0f01ab516795d31e3563f3321c20f7da9c90ffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Sep 2026 18:11:59 +0300 Subject: [PATCH] fix(av1): compound 8x8 leaf's early return clobbered its own per-TU luma coefficient context `decode_leaf8`'s COMPOUND arm returns before the fall-through tail, and that tail is where the `split8` plane-0 save/restore around `record_mi` lives. A compound var-tx 8x8 leaf therefore published the whole-block luma grid (all-zero when the transform is split into 4x4 units, since `read_inter_luma8`'s `record_mi_luma` already wrote the per-unit state) to `above[..][0]`/`left[..][0]`, so the NEXT block's first transform unit read `get_txb_ctx`'s `skip_contexts[4][0] = 3` where aomdec reads `[4][4] = 6` (txb_common.h:330). Class early-return-skips-tail. Witness (8-bit 192x128 inter stream, aomdec ladder): frame 2 mi(14,12) first luma TU, ours ctx=3 rng=43376 vs reference ctx=6 rng=61310; the block left of it, mi(14,10), is a compound 8x8 whose four TX_4X4 units all read ctx=6 correctly and then had their published levels zeroed. A 12-stream sub-8x8-intra probe sweep keeps its 10/12 pixel-EXACT rows and one refusing stream now decodes all 6 frames. --- crates/ec-av1/src/decode.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 63d17057..730ca9ba 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -5396,7 +5396,8 @@ impl Neighbours { let ctx = SKIP_CONTEXTS[(top as usize).min(4)][(left as usize).min(4)]; if std::env::var_os("EC_AV1_TRACE").is_some() { eprintln!( - "TRACE luma_skip_ctx mi=({mi_r},{mi_c}) side_mi={side_mi} top={top} left={left} ctx={ctx}" + "TRACE luma_skip_ctx mi=({mi_r},{mi_c}) side_mi={side_mi} top={top} left={left} ctx={ctx} band={:?}", + self.left.iter().map(|e| e[0].level).collect::>() ); } ctx @@ -24941,7 +24942,36 @@ fn decode_inter_block8( // there before. Every leaf of the gate's stream is compound, // so the 16x16 below a split block read partition ctx 0 // instead of 1 and mis-read PARTITION_SPLIT as NONE. + // lane-sub8x4 r1: the same plane-0 save/restore the fall-through + // (single-ref) path runs below -- a `split8` leaf's plane-0 + // neighbour context is per 4x4 transform unit (written by + // `record_mi_luma` inside `read_inter_luma8`), and `record_mi` + // rewrites all three planes from the whole-block grid, which is + // all-zero in the split case. Missing here, a compound var-tx 8x8 + // leaf published level 0 to its right/below neighbours: the next + // block's first TU read `skip_contexts[4][0] = 3` where aomdec + // reads `[4][4] = 6` (class early-return-skips-tail). + let saved_luma_ctx = split8.then(|| { + ( + [ + neighbours.left[leaf_mi.0][0], + neighbours.left[leaf_mi.0 + 1][0], + ], + [ + neighbours.above[leaf_mi.1][0], + neighbours.above[leaf_mi.1 + 1][0], + ], + ) + }); neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); + if let Some((left, above)) = saved_luma_ctx { + for (cell, state) in left.into_iter().enumerate() { + neighbours.left[leaf_mi.0 + cell][0] = state; + } + for (cell, state) in above.into_iter().enumerate() { + neighbours.above[leaf_mi.1 + cell][0] = state; + } + } // lane-cdef r1: ... and the CDEF skip band too. `apply_cdef`'s // `is_8x8_block_skip` (libaom `cdef.c:29-38`) reads all four mi // cells of the 8x8; this leaf wrote none of them, so a 64x64