From 2dc9fc29e78b07487ee08e264b62bf9b0a8faaa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 8 Sep 2026 13:19:11 +0300 Subject: [PATCH] fix(av1): the delta_q unit is the 128 superblock under EC_AV1_SB128 The writer gated its delta_qindex group on a hardcoded 64x64 position (tile.rs SB_MI) while decode.rs maybe_read_delta_q gates on sb_mi_cur, so with per-superblock delta_q armed (preset 0) and 128 superblocks on the writer coded four symbol groups per 128 root and the reader read one -- the first divergent symbol is the second 64 cell's delta_q_abs, surfacing frames later as the arf refusing a reference slot. The 64-root whole-block call also claimed is_whole_sb under a 128 superblock, which suppresses the read on the wrong side. The search-side grid is flattened per 128 root so the qindex a cell is quantized at is the one its root codes. Witness: a_128_superblock_clip_whose_root_search_codes_128x128_blocks... ok --- crates/ec-av1/src/encode.rs | 16 +++++++++++++++- crates/ec-av1/src/tile.rs | 9 +++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 629c8b1d..ee521b14 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -11739,7 +11739,21 @@ pub(crate) fn encode_inter_frame( let sb_q: Option> = match (&tpl_factors, deltaq_res) { (Some(f), Some(res)) => { let libaom = dq_tpl_strength(); - Some((0..sb_cols * _sb_rows).map(|sb| sb_qindex(f, res, sb, libaom)).collect()) + let mut g: Vec = + (0..sb_cols * _sb_rows).map(|sb| sb_qindex(f, res, sb, libaom)).collect(); + // lane-b128m: under 128 superblocks the delta_q syntax is coded + // ONCE per 128 root (the reader's own unit), so all four 64x64 + // cells of a root have to be searched -- and quantized -- at the + // one qindex the root's top-left cell codes. + if sb128_on() { + for sb_r in 0.._sb_rows { + for sb_c in 0..sb_cols { + let q = g[(sb_r & !1) * sb_cols + (sb_c & !1)]; + g[sb_r * sb_cols + sb_c] = q; + } + } + } + Some(g) } _ => None, }; diff --git a/crates/ec-av1/src/tile.rs b/crates/ec-av1/src/tile.rs index 11f428ff..8071ea10 100644 --- a/crates/ec-av1/src/tile.rs +++ b/crates/ec-av1/src/tile.rs @@ -1414,7 +1414,12 @@ fn write_delta_q( DELTA_Q.with(|c| { let mut plan = c.borrow_mut(); let Some(plan) = plan.as_mut() else { return }; - if mi.0 % SB_MI as usize != 0 || mi.1 % SB_MI as usize != 0 { + // lane-b128m: the delta_q unit is the SUPERBLOCK, so it is 128 wide + // under `EC_AV1_SB128` -- decode.rs `maybe_read_delta_q` gates on + // `sb_mi_cur`, and a writer gating on a hardcoded 64 codes three + // symbol groups per 128 root the reader never reads. + let sb_mi = if sb128_armed() { SB_MI as usize * 2 } else { SB_MI as usize }; + if mi.0 % sb_mi != 0 || mi.1 % sb_mi != 0 { return; } if is_whole_sb && skip { @@ -6619,7 +6624,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( + usize::from(neighbours.left_skip[mi_r]); enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]); write_cdef_idx(&mut enc, (mi_r, mi_c), block.skip); - write_delta_q(&mut enc, &mut cdfs, (mi_r, mi_c), true, block.skip); + write_delta_q(&mut enc, &mut cdfs, (mi_r, mi_c), !sb128_armed(), block.skip); let ii_ctx = intra_inter_ctx( has_above, has_left,