From a1764582a4f85f09c7d96a7e8917fbff26bb8126 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 08:55:37 +0300 Subject: [PATCH] fix(av1): a SKIP inter 128x128 block's internal TX_64X64 edges were deblocked libaom `set_one_param_for_line_luma`/`_chroma` suppress every edge that is a transform-unit edge but not a prediction-unit edge when `curr_skipped = mbmi->skip_txfm && is_inter_block(mbmi)`. `get_transform_size` still reports TX_64X64 (luma) / TX_32X32 (chroma) for a skipped 128x128 inter block, so the tu_edge at the block's own x=64 / y=64 exists -- it is simply never filtered. This decoder published those units into the lf grid unconditionally and filtered them. Two changes in `crates/ec-av1/src/decode.rs`: - the per-leaf `fill_lf_grid_rect` loop is now gated on `!(skip && is_inter)`, leaving the block-level 128 publication (no internal luma edge) in place -- the 128 root is the only block that reaches that loop skipped, because `read_block_tx_size` hands back four TX_64X64 leaves for `side > 64` regardless of `skip`. - `fill_lf_grid_rect`'s uv extent drops its `.min(32)` cap: inert for every block up to 64 wide (64/2 == 32) and wrong for a 128-sided one, where it published an internal chroma edge every 32 chroma px. A non-skip 128 block still gets uv 32 through its own per-leaf calls (`w_mi * MI == 64`). Also indexes `dump_stage`'s output per decode-order picture (`EC_AV1_POSTDEBLOCK_DUMP` overwrote `.f0` every frame, so only the last picture was comparable against aomdec's own indexed rung -- that rung is what isolated this defect). Measured on the 8-bit 256x256 sb128 inter gate stream: decode-order frames 0-4 were pre-filter exact and frame 4 diverged post-deblock (98 luma px in a 9-px band at x=64, 274 chroma); all five stages are now exact. aomdec's post-deblock dump changes ZERO pixels in columns 50..78 of that frame -- it filters nothing there. --- crates/ec-av1/src/decode.rs | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index c3940690..02655be7 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -4181,10 +4181,17 @@ impl Neighbours { ) { let (mi_r, mi_c) = at_mi; // `av1_get_max_uv_txsize` under 4:2:0: the block's chroma extent is - // half its luma one (min 4 px, the smallest transform), capped at - // TX_32X32 -- independent of this block's luma `tx_depth`. - let uv_tx_w = ((w_mi * MI / 2).max(4).min(32)) as u8; - let uv_tx_h = ((h_mi * MI / 2).max(4).min(32)) as u8; + // half its luma one (min 4 px, the smallest transform). + // lane-sb128c r4: the old `.min(32)` TX_32X32 cap was inert for every + // block up to 64 wide (64/2 == 32) and WRONG for a 128-sided one: it + // published an internal chroma TU edge every 32 chroma px inside the + // block, which libaom only filters when the block is not + // `curr_skipped` -- and a non-skip 128 block reaches here again + // through its own per-leaf calls (`w_mi * MI == 64`, uv 32), which + // publish that edge correctly. The cap is therefore redundant where + // it was right and harmful where it was not. + let uv_tx_w = (w_mi * MI / 2).max(4) as u8; + let uv_tx_h = (h_mi * MI / 2).max(4) as u8; let cur = CURRENT_DELTA_LF.with(|c| c.get()); let snapshot: [i8; 4] = if DELTA_LF_MULTI.with(|c| c.get()) { std::array::from_fn(|i| cur[i].clamp(-63, 63) as i8) @@ -8845,8 +8852,13 @@ fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize, fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) { use std::io::Write; + // lane-sb128c r4: decode-order index like `EC_AV1_PREFILT_DUMP`'s -- a + // fixed `.f0` overwrote every frame, so the only comparable stage dump + // was the last decoded picture (aomdec's own rung indexes its files). + static STAGE_IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); + let idx = STAGE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); if let Ok(path) = std::env::var(var) - && let Ok(mut f) = std::fs::File::create(format!("{path}.f0")) + && let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { for p in [y, u, v] { let narrow: Vec = p.data.iter().map(|&s| s as u8).collect(); @@ -19250,9 +19262,16 @@ fn decode_inter_block( }, ); // lane-txselect: a var-tx block's deblock edges follow its own transform - // units, not the block. Chroma still reads `tx_h_grid / 2` (the block's - // uv transform is not split) -- a known corner-cut of this round. - if let Some(leaves) = &vartx_leaves { + // units, not the block. + // lane-sb128c r4: libaom `set_one_param_for_line_luma` suppresses every + // edge that is a TU edge but not a PU edge when + // `curr_skipped = mbmi->skip_txfm && is_inter_block(mbmi)`, so a SKIP + // inter block's internal transform edges are never filtered even though + // `get_transform_size` still reports TX_64X64 for it. The only block that + // reaches here skipped is the 128 root (`read_block_tx_size` hands back + // four TX_64X64 leaves for `side > 64` regardless of `skip`); leaving its + // block-level 128 publication in place is exactly that suppression. + if let Some(leaves) = (!(skip && is_inter)).then_some(()).and(vartx_leaves.as_ref()) { for &(row, col, tx_px) in leaves { neighbours.fill_lf_grid_rect( (at_mi.0 + row, at_mi.1 + col),