forge
Explore
Log in

Don't you dare go Hollow

Compound 8x8 leaf's early return clobbered its own per-TU luma coefficient context

Browse files at this commit

d0f01ab516795d31e3563f3321c20f7da9c90ffeAhmet Kaan GümüşParent: 35461bb
  • fix
    • compound 8x8 leaf's early return clobbered its own per-TU luma coefficient context
Show full message
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.rsmodified+31 -1
@@ -5396,7 +5396,8 @@ impl Neighbours {
5396 let ctx = SKIP_CONTEXTS[(top as usize).min(4)][(left as usize).min(4)];5396 let ctx = SKIP_CONTEXTS[(top as usize).min(4)][(left as usize).min(4)];
5397 if std::env::var_os("EC_AV1_TRACE").is_some() {5397 if std::env::var_os("EC_AV1_TRACE").is_some() {
5398 eprintln!(5398 eprintln!(
5399- "TRACE luma_skip_ctx mi=({mi_r},{mi_c}) side_mi={side_mi} top={top} left={left} ctx={ctx}"5399+ "TRACE luma_skip_ctx mi=({mi_r},{mi_c}) side_mi={side_mi} top={top} left={left} ctx={ctx} band={:?}",
5400+ self.left.iter().map(|e| e[0].level).collect::<Vec<_>>()
5400 );5401 );
5401 }5402 }
5402 ctx5403 ctx
@@ -24941,7 +24942,36 @@ fn decode_inter_block8(
24941 // there before. Every leaf of the gate's stream is compound,24942 // there before. Every leaf of the gate's stream is compound,
24942 // so the 16x16 below a split block read partition ctx 024943 // so the 16x16 below a split block read partition ctx 0
24943 // instead of 1 and mis-read PARTITION_SPLIT as NONE.24944 // instead of 1 and mis-read PARTITION_SPLIT as NONE.
24945+ // lane-sub8x4 r1: the same plane-0 save/restore the fall-through
24946+ // (single-ref) path runs below -- a `split8` leaf's plane-0
24947+ // neighbour context is per 4x4 transform unit (written by
24948+ // `record_mi_luma` inside `read_inter_luma8`), and `record_mi`
24949+ // rewrites all three planes from the whole-block grid, which is
24950+ // all-zero in the split case. Missing here, a compound var-tx 8x8
24951+ // leaf published level 0 to its right/below neighbours: the next
24952+ // block's first TU read `skip_contexts[4][0] = 3` where aomdec
24953+ // reads `[4][4] = 6` (class early-return-skips-tail).
24954+ let saved_luma_ctx = split8.then(|| {
24955+ (
24956+ [
24957+ neighbours.left[leaf_mi.0][0],
24958+ neighbours.left[leaf_mi.0 + 1][0],
24959+ ],
24960+ [
24961+ neighbours.above[leaf_mi.1][0],
24962+ neighbours.above[leaf_mi.1 + 1][0],
24963+ ],
24964+ )
24965+ });
24944 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);24966 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);
24967+ if let Some((left, above)) = saved_luma_ctx {
24968+ for (cell, state) in left.into_iter().enumerate() {
24969+ neighbours.left[leaf_mi.0 + cell][0] = state;
24970+ }
24971+ for (cell, state) in above.into_iter().enumerate() {
24972+ neighbours.above[leaf_mi.1 + cell][0] = state;
24973+ }
24974+ }
24945 // lane-cdef r1: ... and the CDEF skip band too. `apply_cdef`'s24975 // lane-cdef r1: ... and the CDEF skip band too. `apply_cdef`'s
24946 // `is_8x8_block_skip` (libaom `cdef.c:29-38`) reads all four mi24976 // `is_8x8_block_skip` (libaom `cdef.c:29-38`) reads all four mi
24947 // cells of the 8x8; this leaf wrote none of them, so a 64x6424977 // cells of the 8x8; this leaf wrote none of them, so a 64x64