From 1edcdabbb2f086962f834fd5ac51df8943bbbdf9 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 12:30:35 +0300 Subject: [PATCH] fix(av1): a skipped palette block with a split transform predicted DC off its edges A square intra block that is SKIPPED predicts its whole side x side luma in one call; the palette (and intrabc) prediction override was armed only when the transform covered the whole block, so a 16x16 palette block with tx_depth == 1 and skip == 1 fell back to edge prediction. Right symbols -- the whole mode ladder diffs clean against an instrumented aomdec -- wrong pixels: 812 luma samples in the key frame of an SVT-AV1 preset-8 screen stream, carried by the V_PRED blocks under it to 10122 over 12 frames. Sibling paths (decode_leaf8, decode_rect_split, the intra-in-inter walk) already arm on both arms; this was the one site left. Gate rides the kept stream via EC_AV1_SVT1_STREAM (SKIP when unset), asserts the fixed arm fires, and adds EC_AV1_DEBUG_SKIP_LR beside the deblock/CDEF debug rungs for the stage bisect. --- crates/ec-av1/src/decode.rs | 11 +++++--- crates/ec-av1/src/stream.rs | 54 +++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 0aca3a45..01595580 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -14236,12 +14236,15 @@ fn decode_block( // key frame; class override-slot-on-one-arm). Neither prediction is // edge-derived, so the whole-block buffer at the block's own stride is // exactly what that single call wants. + // Counted on the SHAPE, not on the arm below, so a gate can tell a stream + // that reaches this block apart from one that never does (class + // gate-blind-to-feature). + if palette_y_buf.is_some() && skip && logical_tx < side { + hit!(SKIP_SPLIT_TX_OVERRIDE_HITS); + } if let Some(buf) = &palette_y_buf - && (logical_tx == side) + && (logical_tx == side || skip) { - if skip && logical_tx < side { - hit!(SKIP_SPLIT_TX_OVERRIDE_HITS); - } set_palette_pred(buf.clone(), fctx); } // A UV-palette block's own chroma prediction override (lane-palette2 r1), diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 3334cb24..a1cb80d3 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -3344,6 +3344,60 @@ pub(crate) mod tests { .collect() } + /// lane-svt1: an SVT-AV1 (v3.1.2, `-preset 8 -crf 35`) screen key frame + /// codes 16x16 PALETTE blocks with `skip == 1` whose `tx_depth` split the + /// luma transform. [`crate::decode::decode_block`] armed the palette + /// prediction only when the transform covered the whole block, so that one + /// block predicted DC off its own edges instead: the right symbols (the + /// whole mode ladder diffs clean against an instrumented aomdec) and the + /// wrong pixels -- 812 luma samples in frame 0, carried by the V_PRED + /// blocks under it to 10122 samples over the 12-frame stream. + /// + /// No lavfi recipe witnesses it in a stream this decoder otherwise decodes: + /// 6 sources x 5 sizes x 6 crf values through `libsvtav1 -preset 8 + /// -svtav1-params screen-content-mode=1` produced 8 streams that reach the + /// path, and every one of them either refuses on an unrelated Golomb tail + /// or misses by ~200k samples on unrelated inter-frame defects (both + /// recorded in `lanes/svt1.report.md`). So the gate rides the kept stream + /// named by `EC_AV1_SVT1_STREAM` and SKIPs when it is unset -- the screen + /// crop itself is never committed to `fixtures/`. + /// + /// `skip_split_tx_override_hits` is asserted non-zero so the row cannot + /// pass on a stream that never reaches the fixed arm (class + /// gate-blind-to-feature). + #[test] + fn an_svt_screen_palette_block_with_a_split_transform_decodes_exactly() { + const NAME: &str = "an_svt_screen_palette_block_with_a_split_transform_decodes_exactly"; + let Ok(path) = std::env::var("EC_AV1_SVT1_STREAM") else { + eprintln!("SKIP {NAME}: EC_AV1_SVT1_STREAM names no stream"); + return; + }; + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + let data = match std::fs::read(&path) { + Ok(data) => data, + Err(e) => { + eprintln!("SKIP {NAME}: {path}: {e}"); + return; + } + }; + crate::decode::reset_skip_split_tx_override_hits(); + let decoded = decode_stream(&data).expect("the kept SVT-AV1 screen stream decodes"); + assert!( + crate::decode::skip_split_tx_override_hits() > 0, + "{NAME}: no skipped split-transform palette block in {path} -- the gate would pass blind" + ); + let (width, height) = (decoded[0].width, decoded[0].height); + let want = ffmpeg_decode_sequence(&data, width, height, decoded.len()); + for (i, (got, want)) in decoded.iter().zip(&want).enumerate() { + assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg"); + assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg"); + assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg"); + } + } + /// `decode_stream` agrees with ffmpeg/dav1d on the same wire bytes -- an /// independent decoder, not just this crate checking its own tile path. #[test]