From d1400b2b64eb60f8651410ec2d00be6cc4d2c046 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 15:34:40 +0300 Subject: [PATCH] fix(av1): transform-unit top-right/bottom-left inside a block wider than 64 A block wider than 64 is coded in 64x64 "mu" chunks in raster order, so libaom's has_top_right takes the column offset MODULO the chunk (plus the one centre unit of a 128x128) and has_bottom_left grants the left edge of a right-hand chunk what the already-coded left chunk holds. Reach::of_tu applied the plain block-wide rule, so the last unit column of every chunk of a 128x64 intra block predicted from a chunk not yet reconstructed -- 375 wrong samples per 128x64 block on a 512x512 key frame with the transform split. Gate: a 512x512 arm (second 128 superblock column, high-frequency source, --enable-tx-size-search=1) joins the sb128 intra_rect_block gate: 164 128x64 + 156 64x128 blocks, 294 of them at TX_16X16, 5 frames pixel-exact. --- crates/ec-av1/src/encode.rs | 25 ++++++++++++++++++++++--- crates/ec-av1/src/stream.rs | 18 +++++++++++++++++- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 70125411..0140fb17 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -1261,13 +1261,32 @@ impl Reach { tx_h: usize, block: Self, ) -> Self { + // A block wider than 64 is coded in 64x64 "mu" chunks in raster + // order, so both libaom predicates special-case it (lane-sb128c r10); + // without this the last unit column of every chunk of a 128x64 block + // predicts from a chunk libaom has not decoded yet. + let wide = bw > 64; Self { - above_right: if col_off + tx_w < bw { + above_right: if row_off > 0 { + // `has_top_right`'s `row_off > 0` branch: the offset is taken + // modulo the 64-wide chunk, except for the one unit whose + // top-right corner is the centre of a 128x128 block. + if wide { + (row_off == 64 && col_off + tx_w == 64) || (col_off % 64) + tx_w < 64 + } else { + col_off + tx_w < bw + } + } else if col_off + tx_w < bw { true } else { - row_off == 0 && block.above_right + block.above_right }, - below_left: if col_off > 0 { + below_left: if wide && col_off > 0 && col_off % 64 == 0 { + // `has_bottom_left`: at the left edge of a right-hand chunk + // the bottom-left pixels are in the already-coded left chunk, + // provided they stay inside it. + (row_off % 64) + tx_h < bh.min(64) + } else if col_off > 0 { false } else if row_off + tx_h < bh { true diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index a22ac7c6..31b93543 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -19173,6 +19173,12 @@ mod tests { (44, "--cq-level=8", 256, 192, false, false, true), (46, "--cq-level=55", 192, 256, false, true, false), (45, "--cq-level=45", 192, 256, true, true, true), + // lane-sb128c r10: a SECOND 128 superblock column is what the + // arms above never had -- the right 64x128 half of a 128-root + // VERT at mi_col 80 read its tx-depth symbol off the wrong CDF + // row and every unit column of a 128x64 chunk predicted from the + // not-yet-decoded chunk to its right. + (47, "--cq-level=45", 512, 512, false, false, true), ]; let (mut matched, mut named_refusals, mut out_of_scope) = (0u32, 0u32, 0u32); let (mut horz_arms, mut vert_arms) = (0u32, 0u32); @@ -19189,7 +19195,17 @@ mod tests { // through `geq` instead -- same effect on the encoder's // partition choice, byte-identical across runs. &format!( - "nullsrc=size={width}x{height}:rate=25,format=yuv420p, geq=lum='128+90*sin((X+2*N)/37)+30*sin(Y/29)': cb='128+30*sin(X/23)':cr='128+30*sin((Y+N)/19)'" + "nullsrc=size={width}x{height}:rate=25,format=yuv420p, geq=lum='{lum}': cb='128+30*sin(X/23)':cr='128+30*sin((Y+N)/19)'", + // The 512x512 arm carries the r9 witness's own + // higher-frequency luma: the smooth two-term source + // gives every 128-rect block a whole-block TX_64X64 + // and no VERT root at all, which is exactly the + // combination that hid the tx-depth CDF row defect. + lum = if width == 512 { + "128+80*sin((X+3*N)/17)+50*sin(Y/29)+30*sin((X+Y)/13)" + } else { + "128+90*sin((X+2*N)/37)+30*sin(Y/29)" + } ), "-pix_fmt", pix, "-strict", "-1", "-t", "0.2", "-f", "yuv4mpegpipe", "-",