From 1ee7fc675f0d2ed1e31798924242976364b6f8ed 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 16:30:52 +0300 Subject: [PATCH] feat(av1): the 128 superblock root codes a real residual The 128x128 PARTITION_NONE block is no longer skip-only. Its residual is the four 64x64 mu chunks libaom's decode_token_recon_block walks: per chunk one TX_64X64 luma unit (its coded 32x32 corner, DCT-only at this size) then one TX_32X32 unit per chroma plane on the offset-10 txb_skip rows, each publishing its own coefficient context before the next unit reads it, with the var-tx tree's four depth-0 txfm_partition symbols in front. The search prices that shape against the skip arm it already committed to the planes, quantized at the qindex the root itself signals. One defect found on the way: write_inter_block_128 recorded skip = true in its own neighbour band whatever the block was, so the next root's skip symbol took CDF row 1 where the reader takes row 0. Witness (--ignored, forced arm): 420 residual 128x128 blocks, sample exact through decode_stream and ffmpeg. --- crates/ec-av1/src/encode.rs | 14 +++++++++----- crates/ec-av1/src/tile.rs | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index e4bdf8db..5cdb60c8 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -16195,11 +16195,15 @@ mod tests { /// lane-b128r: the 128 root's own RESIDUAL arm -- four TX_64X64 luma /// units interleaved with a TX_32X32 chroma pair per 64x64 mu chunk. The - /// same pan the skip-only witness above uses, coded at a quantizer where - /// the residual is worth its bits, so the counters below are non-zero; - /// RED before this lane by construction (`write_inter_block_128` refused - /// every non-skip 128 block, so the count was 0 and no such block - /// existed to decode). + /// same pan the skip-only witness above uses, with the arm FORCED + /// ([`force_b128_residual`]): on synthetic bars the RD picks the residual + /// about once per frame, which witnesses the shape but not every context + /// it reads, and forcing codes all 420 roots of the clip through it. RED + /// before this lane by construction (`write_inter_block_128` refused + /// every non-skip 128 block, so no such block existed to decode), and RED + /// again on the first draft of the writer, whose neighbour band recorded + /// `skip = true` for a block that carries a residual -- the next root's + /// `skip` symbol then took CDF row 1 where the reader takes row 0. /// /// cargo test -p ec-av1 --release --lib -- --ignored \ /// a_128_root_block_with_a_real_residual --nocapture diff --git a/crates/ec-av1/src/tile.rs b/crates/ec-av1/src/tile.rs index 6832a335..ee74ee51 100644 --- a/crates/ec-av1/src/tile.rs +++ b/crates/ec-av1/src/tile.rs @@ -452,7 +452,7 @@ fn write_inter_block_128( } else { neighbours.record(sb_at, SIDE, 0, &zero_grids); } - neighbours.record_inter(sb_at, SIDE, true, true, block_ref(block)); + neighbours.record_inter(sb_at, SIDE, block.skip, true, block_ref(block)); record_block_compound(neighbours, (mi_r, mi_c), SIDE, block); SB128_NONE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); if !block.skip {