diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index 92b9d394..95b81ba7 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -50,6 +50,10 @@ fn main() { let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters(); println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}"); println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits()); + println!( + "skip_split_tx_override: {}", + ec_av1::decode::skip_split_tx_override_hits() + ); println!("interintra_rect: {}", ec_av1::decode::interintra_rect_hits()); println!("gm_nontrans_small_side: {}", ec_av1::decode::gm_nontrans_small_side_hits()); println!("tr_reach_longer_side: {}", ec_av1::decode::tr_reach_longer_side_hits()); diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 0e85784a..1412f001 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2131,6 +2131,24 @@ pub fn skip_split_tx_hits() -> usize { SKIP_SPLIT_TX_HITS.with(|c| c.get()) } +// lane-svt1: SKIPPED square blocks carrying a palette/intrabc prediction whose +// `tx_depth` split the luma transform -- the arm that predicted DC off the +// block edges before the fix. Like [`SKIP_SPLIT_TX_HITS`] only the pixels +// witness this path, so a gate that wants it needs the counter. +thread_local! { + static SKIP_SPLIT_TX_OVERRIDE_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of [`SKIP_SPLIT_TX_OVERRIDE_HITS`] (blocks). +pub fn skip_split_tx_override_hits() -> usize { + SKIP_SPLIT_TX_OVERRIDE_HITS.with(|c| c.get()) +} + +/// Zeroes [`SKIP_SPLIT_TX_OVERRIDE_HITS`] before a gate's own decode attempt. +pub fn reset_skip_split_tx_override_hits() { + SKIP_SPLIT_TX_OVERRIDE_HITS.with(|c| c.set(0)); +} + /// Zeroes [`SKIP_SPLIT_TX_HITS`] before a gate's own decode attempt. pub fn reset_skip_split_tx_hits() { SKIP_SPLIT_TX_HITS.with(|c| c.set(0)); @@ -14221,8 +14239,23 @@ fn decode_block( // `logical_tx`-sized window of that same map, set fresh inside the TU loop // below (lane-palette2 r7) -- setting the full-block buffer here would be // taken by the FIRST unit and indexed at the wrong stride. + // lane-svt1: a SKIPPED block predicts the whole `side`x`side` in ONE call + // (the `else` arm below -- a palette/intrabc block never takes the per-unit + // `split_tx_skip` walk), so its map must be armed here even when the + // transform is split. Gating the arm on `logical_tx == side` alone left a + // 16x16 palette block with `tx_depth == 1` and `skip == 1` predicting DC + // off its own edges: right symbols, wrong pixels (SVT-AV1 preset-8 screen + // 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) { set_palette_pred(buf.clone(), fctx); } @@ -21274,6 +21307,7 @@ fn pipe_filters_ok(fctx: &crate::decode::FrameCtx, tile_cols: u32, lf_present: b || crate::envflags::is_set("EC_AV1_POSTCDEF_DUMP16") || crate::envflags::is_set("EC_AV1_DEBUG_SKIP_DEBLOCK") || crate::envflags::is_set("EC_AV1_DEBUG_SKIP_CDEF") + || crate::envflags::is_set("EC_AV1_DEBUG_SKIP_LR") || crate::envflags::is_set("EC_AV1_DEBUG_CDEF_BAND") || crate::envflags::is_set("EC_AV1_DEBLOCK_TRACE") || crate::envflags::is_set("EC_AV1_DEBLOCK_TRACE_V")) @@ -21538,6 +21572,10 @@ fn apply_loop_restoration( // (class av1-truesize-lane: true frame size vs mi-rounded). (frame_w, frame_h): (usize, usize), fctx: &crate::decode::FrameCtx, ) { + // lane-svt1 debug rung, env-gated: see `apply_cdef`/`apply_deblock`'s siblings. + if crate::envflags::env_flag!("EC_AV1_DEBUG_SKIP_LR") { + return; + } let mut out = scratch_empty(); crate::restoration::apply_loop_restoration_plane( &y.data, diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index a8bf1197..0c38f1eb 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] diff --git a/lanes/svt1.report.md b/lanes/svt1.report.md new file mode 100644 index 00000000..b6d052ff --- /dev/null +++ b/lanes/svt1.report.md @@ -0,0 +1,133 @@ +# lane-svt1 — one SVT-AV1 screen stream, one palette block, 10122 samples + +Stream: `libsvtav1 -preset 8 -crf 35 -svtav1-params lp=1 -g 12 -f obu`, screen +capture crop, **1920x1024** (the charter said 1920x768; `ffprobe` says 1024 and +the reference yuv is 12 x 2949120 bytes, i.e. 1920x1024 4:2:0), 12 frames, kept +outside the repo at `$HOME/.cache/svt1/svt-p8-crf35-screen.obu`. + +## The premise was wrong, in our favour + +The charter's "ONE sample off, frame 0 Y 1471489" is a mis-read. Diffing +`ours.f*.yuv` (u16 LE) against ffmpeg's 8-bit `ref.yuv`: + +| frame | differing samples | plane | rows | cols | +|---|---|---|---|---| +| 0 | 812 | Y only | 766..833 | 766..786 | +| 1..6 | 825 each | Y only | 763..834 | 766..786 | +| 7..11 | 872 each | Y only | 763..834 | 765..786 | + +**10122 samples total, luma only, chroma exact in every frame.** Sample 1471489 +is (row 766, col 769) at width 1920, not (766, 1729). Max |delta| 144. + +## First divergent stage: pre-filter reconstruction + +Bisected with the decoder's own debug rungs, not with the stage dump: +`EC_AV1_DEBUG_SKIP_DEBLOCK=1`, `EC_AV1_DEBUG_SKIP_CDEF=1` and a new +`EC_AV1_DEBUG_SKIP_LR=1` (added beside its two siblings, and to +`pipe_filters_ok`'s stage-flag list). With every filter off the band is still +wrong and still flat, so no post-filter creates it — it is reconstruction. + +`EC_TRACE_MODE_STEP=1` through both decoders then diffs **clean**: all 49080 +mode-ladder lines of frame 0 (`skip`, `cdef`, `dq`, `mode`, `angle_y`, +`uv_mode`, `angle_uv`, `tx_depth`) agree with the instrumented aomdec value for +value AND range for range. Right symbols, wrong pixels. + +The block: `EC_PALSYN=1` says `mi=192,192 bsize=6 mode=0 uv=0 ctx=1 y=8` — a +16x16 **palette** block (8 colours) at pixel (768, 768), `skip=1`, +`tx_depth=1`. libaom prints no `EC_PRED`/`EC_PREDOUT8` for its luma (palette +does not predict off edges); it does print the chroma DC. Ours filled the whole +16x16 with 54 = the DC of its top edge, and the six 8x8 `V_PRED skip` blocks +below it (mi rows 196..206, col 192) then propagated that flat value down the +next 48 rows, which is the 64-row tall band in the table above. + +## Root cause + +`crates/ec-av1/src/decode.rs`, `decode_block` (square intra): + +```rust +if let Some(buf) = &palette_y_buf && logical_tx == side { set_palette_pred(...) } +``` + +A **skipped** block predicts the whole `side`x`side` in ONE call — the skip +branch's per-unit walk (`split_tx_skip`) explicitly excludes palette/intrabc +blocks — so gating the arm on `logical_tx == side` left every skipped palette +(or intrabc) block whose `tx_depth` split the transform with an empty override +slot and an edge prediction. Fix: `&& (logical_tx == side || skip)`. Neither +prediction is edge-derived, so the whole-block buffer at the block's own stride +is exactly what that single call consumes. + +Class: **override-slot-on-one-arm** (the memory entry of that name is the same +shape: an override installed on the skip arm only). + +## Same-shape sweep + +`grep -n 'logical_tx == side\|split_tx_skip'` — one site, now fixed. Every +sibling path already arms on both arms and was checked by reading: + +* `decode_leaf8` (8x8, TX_4X4 split): arms inside the non-split `else`, and its + `resolved == 4 && palette_y_buf.is_none()` guard is the same rule — correct. +* `decode_rect_split`: windows the map per transform unit including the skip + arm — correct. +* `decode_block_rect`, `decode_block_rect64`: arm unconditionally before the + skip branch — correct. +* the intra-in-inter var-tx walk (`vartx_leaves`): windows per unit, skip arm + included — correct. + +## Witness + +`skip_split_tx_override_hits()` (new counter, incremented on the SHAPE, not on +the fixed arm, so it also counts pre-fix) fires **exactly once** in the whole +12-frame stream — that one block. + +No lavfi recipe witnesses the defect in a stream this decoder otherwise +decodes. Measured: 6 sources x 5 sizes (384x152, 320x184, 256x190, 640x366, +320x240) x 6 crf (25..50), all `libsvtav1 -preset 8 -svtav1-params +lp=1:screen-content-mode=1`, 4 frames. 8 streams reach the fixed arm +(`hits=1`); of those, 2 are REFUSED by this decoder ("a Golomb tail longer than +this decoder reads") and 6 miss by ~200k-245k samples on unrelated inter-frame +defects. `smptebars,drawgrid` at 384x152 is the only family that reaches the +arm at all; `smptebars` alone, `pal75bars`, `testsrc`, `testsrc2` and +`color+drawgrid` never do. + +So the gate rides the kept stream, per the charter's own fallback: +`stream::tests::an_svt_screen_palette_block_with_a_split_transform_decodes_exactly`, +gated on `EC_AV1_SVT1_STREAM` (SKIPs with a printed reason when unset, or when +ffmpeg is missing, or when the path does not read). It asserts the counter is +non-zero before comparing, so it cannot pass on a stream that never reaches the +path (class gate-blind-to-feature). The screen crop is NOT committed. + +* RED (fix reverted, counter kept): `assertion left == right failed: frame 0 + luma vs ffmpeg`, `test result: FAILED` (`$HOME/.cache/svt1/redtest2.log`). +* GREEN: `test result: ok. 1 passed` (`$HOME/.cache/svt1/greentest.log`), and a + full 12-frame `dump_yuv` vs ffmpeg diff reads **0 differing samples in every + plane of every frame**. + +## The stall finding + +Not reproduced, and not tested: the bisect never needed the stage dump. Every +decode here ran under `systemd-run --user` and finished in seconds (12 frames +of 1920x1024: `dump_yuv` ~5 s, instrumented `aomdec --limit=1` ~10 s). The two +prior agents ran the dump command in the FOREGROUND; nothing in this lane +suggests the instrument itself hangs, but nothing here exercises it either — +`EC_AV1_PREFILT_DUMP`/`EC_AV1_POSTDEBLOCK_DUMP` remain untested by this lane. + +## Open (not this lane's fix) + +* `unsupported: AV1 tile (a Golomb tail longer than this decoder reads)` on 2 + of 8 synthetic SVT-AV1 screen streams (e.g. + `smptebars=s=384x152:r=12,drawgrid=w=8:h=8:t=1:c=black`, preset 8, crf 35, + `screen-content-mode=1`). Streams are under `$HOME/.cache/svt1/w3/`. +* ~200k-sample misses on the INTER frames of those same synthetic screen + streams (their frame 0 is not the only wrong frame). A separate lane: this + one only closes the key-frame palette block. + +## Gates on 68c61d33 + +| gate | result | +|---|---| +| `encode::tests::the_encoders_own_streams_are_byte_identical_to_their_pins` | ok, 1 passed (unchanged on this base) | +| s1 `--skip stream::` | ok, 335 passed, 0 failed, 32 ignored (571 s) | +| s2 `stream:: --skip 10bit` | ok, 200 passed, 0 failed, 15 ignored (752 s) | +| s3 `10bit` | ok, 42 passed, 0 failed, 1 ignored (60 s) | +| `cargo check --workspace --all-targets` | 0 errors, 0 ec-av1 warnings (21 pre-existing in ec-opus, 1 in ec-vorbis) | +| kept stream, 12 frames, all planes | 0 differing samples |