From d5c0a13384281712d9f8dab7f427587dc4d3bbef 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 21:27:43 +0300 Subject: [PATCH] fix(av1): the second half of a 128-root HORZ/VERT inter block never read its own cdef_idx literal libaom keeps `cdef_transmitted[4]` -- one flag per 64x64 CDEF unit of a 128x128 superblock, indexed `(mi_col & 16) != 0` + 2 * `(mi_row & 16) != 0` (`read_cdef`, decodemv.c:50-81) -- so both halves of a 128-root PARTITION_HORZ/VERT read a `cdef_bits`-wide literal, each into its own unit. Our flag is a single bool reset per coded piece, and the inter tile loop's 128-root HORZ/VERT arm was the one arm that never reset it between the two halves (the key-frame loop already did), so the second half consumed `cdef_bits` fewer bits than the encoder wrote and the tile desynced at that block's mode info -- a literal-width divergence invisible to a value ladder (the whole coefficient block before it is bit-identical, ranges rejoin only at the next block's entry: 57521 -> aomdec 40079, ours 39850). Witness, 10-bit 1920x792 128-superblock stream, decode-order frame 10, first differing luma pixel px(192,0) = mi(0,48) = the right half of a 128x128 PARTITION_VERT. Pre-filter decode-order compare vs the instrumented aomdec over a 16-frame cut: frames 10..13 go 2316966 / 1746025 / 1307747 / 2161740 differing bytes -> 0 each; frames 0..9 stay exact; residue moves to frame 14 (14 bytes). --- crates/ec-av1/src/decode.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index eb31496b..dee3888f 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -27266,6 +27266,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( if i > 0 && (at_mi.0 >= mi_rows as usize || at_mi.1 >= mi_cols as usize) { break; } + // Each half reads its OWN `cdef_idx` literal: libaom keeps + // `cdef_transmitted[4]`, one flag per 64x64 CDEF unit of a + // 128x128 superblock (`read_cdef`, decodemv.c:50-81), and + // the two halves of a 128-root HORZ/VERT sit in different + // units (index `col_in_sb != 0` + 2 * `row_in_sb != 0`). + // The key-frame 128 loop already resets here; without it + // the second half skipped a `cdef_bits`-wide literal that + // libaom reads, desyncing the tile at that block. + CDEF_TRANSMITTED.with(|c| c.set(false)); inter_piece!( at_mi, SB * 2, TxbSet::Luma64, TxbSet::Luma64, TxbSet::Chroma32, TX32, TX32,