forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-svt1' (6ec1414a): a skipped square intra block armed its palette/intrabc override only when the transform equalled the block, so a skipped split-transform palette block predicted DC; SVT-AV1 screen stream sample-exact

Browse files at this commit

bab01c84bcbafa187a60e6b0b94e5899fd8c2377Ahmet Kaan GümüşParent: 6c45e10d09fdff
crates/ec-av1/examples/decode_probe.rsmodified+4 -0
@@ -50,6 +50,10 @@ fn main() {
50 let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters();50 let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters();
51 println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}");51 println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}");
52 println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits());52 println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits());
53+ println!(
54+ "skip_split_tx_override: {}",
55+ ec_av1::decode::skip_split_tx_override_hits()
56+ );
53 println!("interintra_rect: {}", ec_av1::decode::interintra_rect_hits());57 println!("interintra_rect: {}", ec_av1::decode::interintra_rect_hits());
54 println!("gm_nontrans_small_side: {}", ec_av1::decode::gm_nontrans_small_side_hits());58 println!("gm_nontrans_small_side: {}", ec_av1::decode::gm_nontrans_small_side_hits());
55 println!("tr_reach_longer_side: {}", ec_av1::decode::tr_reach_longer_side_hits());59 println!("tr_reach_longer_side: {}", ec_av1::decode::tr_reach_longer_side_hits());
crates/ec-av1/src/decode.rsmodified+39 -1
@@ -2131,6 +2131,24 @@ pub fn skip_split_tx_hits() -> usize {
2131 SKIP_SPLIT_TX_HITS.with(|c| c.get())2131 SKIP_SPLIT_TX_HITS.with(|c| c.get())
2132 }2132 }
2133 2133
2134+// lane-svt1: SKIPPED square blocks carrying a palette/intrabc prediction whose
2135+// `tx_depth` split the luma transform -- the arm that predicted DC off the
2136+// block edges before the fix. Like [`SKIP_SPLIT_TX_HITS`] only the pixels
2137+// witness this path, so a gate that wants it needs the counter.
2138+thread_local! {
2139+ static SKIP_SPLIT_TX_OVERRIDE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2140+}
2141+
2142+/// Current value of [`SKIP_SPLIT_TX_OVERRIDE_HITS`] (blocks).
2143+pub fn skip_split_tx_override_hits() -> usize {
2144+ SKIP_SPLIT_TX_OVERRIDE_HITS.with(|c| c.get())
2145+}
2146+
2147+/// Zeroes [`SKIP_SPLIT_TX_OVERRIDE_HITS`] before a gate's own decode attempt.
2148+pub fn reset_skip_split_tx_override_hits() {
2149+ SKIP_SPLIT_TX_OVERRIDE_HITS.with(|c| c.set(0));
2150+}
2151+
2134 /// Zeroes [`SKIP_SPLIT_TX_HITS`] before a gate's own decode attempt.2152 /// Zeroes [`SKIP_SPLIT_TX_HITS`] before a gate's own decode attempt.
2135 pub fn reset_skip_split_tx_hits() {2153 pub fn reset_skip_split_tx_hits() {
2136 SKIP_SPLIT_TX_HITS.with(|c| c.set(0));2154 SKIP_SPLIT_TX_HITS.with(|c| c.set(0));
@@ -14221,8 +14239,23 @@ fn decode_block(
14221 // `logical_tx`-sized window of that same map, set fresh inside the TU loop14239 // `logical_tx`-sized window of that same map, set fresh inside the TU loop
14222 // below (lane-palette2 r7) -- setting the full-block buffer here would be14240 // below (lane-palette2 r7) -- setting the full-block buffer here would be
14223 // taken by the FIRST unit and indexed at the wrong stride.14241 // taken by the FIRST unit and indexed at the wrong stride.
14242+ // lane-svt1: a SKIPPED block predicts the whole `side`x`side` in ONE call
14243+ // (the `else` arm below -- a palette/intrabc block never takes the per-unit
14244+ // `split_tx_skip` walk), so its map must be armed here even when the
14245+ // transform is split. Gating the arm on `logical_tx == side` alone left a
14246+ // 16x16 palette block with `tx_depth == 1` and `skip == 1` predicting DC
14247+ // off its own edges: right symbols, wrong pixels (SVT-AV1 preset-8 screen
14248+ // key frame; class override-slot-on-one-arm). Neither prediction is
14249+ // edge-derived, so the whole-block buffer at the block's own stride is
14250+ // exactly what that single call wants.
14251+ // Counted on the SHAPE, not on the arm below, so a gate can tell a stream
14252+ // that reaches this block apart from one that never does (class
14253+ // gate-blind-to-feature).
14254+ if palette_y_buf.is_some() && skip && logical_tx < side {
14255+ hit!(SKIP_SPLIT_TX_OVERRIDE_HITS);
14256+ }
14224 if let Some(buf) = &palette_y_buf14257 if let Some(buf) = &palette_y_buf
14225- && logical_tx == side14258+ && (logical_tx == side || skip)
14226 {14259 {
14227 set_palette_pred(buf.clone(), fctx);14260 set_palette_pred(buf.clone(), fctx);
14228 }14261 }
@@ -21274,6 +21307,7 @@ fn pipe_filters_ok(fctx: &crate::decode::FrameCtx, tile_cols: u32, lf_present: b
21274 || crate::envflags::is_set("EC_AV1_POSTCDEF_DUMP16")21307 || crate::envflags::is_set("EC_AV1_POSTCDEF_DUMP16")
21275 || crate::envflags::is_set("EC_AV1_DEBUG_SKIP_DEBLOCK")21308 || crate::envflags::is_set("EC_AV1_DEBUG_SKIP_DEBLOCK")
21276 || crate::envflags::is_set("EC_AV1_DEBUG_SKIP_CDEF")21309 || crate::envflags::is_set("EC_AV1_DEBUG_SKIP_CDEF")
21310+ || crate::envflags::is_set("EC_AV1_DEBUG_SKIP_LR")
21277 || crate::envflags::is_set("EC_AV1_DEBUG_CDEF_BAND")21311 || crate::envflags::is_set("EC_AV1_DEBUG_CDEF_BAND")
21278 || crate::envflags::is_set("EC_AV1_DEBLOCK_TRACE")21312 || crate::envflags::is_set("EC_AV1_DEBLOCK_TRACE")
21279 || crate::envflags::is_set("EC_AV1_DEBLOCK_TRACE_V"))21313 || crate::envflags::is_set("EC_AV1_DEBLOCK_TRACE_V"))
@@ -21538,6 +21572,10 @@ fn apply_loop_restoration(
21538 // (class av1-truesize-lane: true frame size vs mi-rounded).21572 // (class av1-truesize-lane: true frame size vs mi-rounded).
21539 (frame_w, frame_h): (usize, usize), fctx: &crate::decode::FrameCtx,21573 (frame_w, frame_h): (usize, usize), fctx: &crate::decode::FrameCtx,
21540 ) {21574 ) {
21575+ // lane-svt1 debug rung, env-gated: see `apply_cdef`/`apply_deblock`'s siblings.
21576+ if crate::envflags::env_flag!("EC_AV1_DEBUG_SKIP_LR") {
21577+ return;
21578+ }
21541 let mut out = scratch_empty();21579 let mut out = scratch_empty();
21542 crate::restoration::apply_loop_restoration_plane(21580 crate::restoration::apply_loop_restoration_plane(
21543 &y.data,21581 &y.data,
crates/ec-av1/src/stream.rsmodified+54 -0
@@ -3344,6 +3344,60 @@ pub(crate) mod tests {
3344 .collect()3344 .collect()
3345 }3345 }
3346 3346
3347+ /// lane-svt1: an SVT-AV1 (v3.1.2, `-preset 8 -crf 35`) screen key frame
3348+ /// codes 16x16 PALETTE blocks with `skip == 1` whose `tx_depth` split the
3349+ /// luma transform. [`crate::decode::decode_block`] armed the palette
3350+ /// prediction only when the transform covered the whole block, so that one
3351+ /// block predicted DC off its own edges instead: the right symbols (the
3352+ /// whole mode ladder diffs clean against an instrumented aomdec) and the
3353+ /// wrong pixels -- 812 luma samples in frame 0, carried by the V_PRED
3354+ /// blocks under it to 10122 samples over the 12-frame stream.
3355+ ///
3356+ /// No lavfi recipe witnesses it in a stream this decoder otherwise decodes:
3357+ /// 6 sources x 5 sizes x 6 crf values through `libsvtav1 -preset 8
3358+ /// -svtav1-params screen-content-mode=1` produced 8 streams that reach the
3359+ /// path, and every one of them either refuses on an unrelated Golomb tail
3360+ /// or misses by ~200k samples on unrelated inter-frame defects (both
3361+ /// recorded in `lanes/svt1.report.md`). So the gate rides the kept stream
3362+ /// named by `EC_AV1_SVT1_STREAM` and SKIPs when it is unset -- the screen
3363+ /// crop itself is never committed to `fixtures/`.
3364+ ///
3365+ /// `skip_split_tx_override_hits` is asserted non-zero so the row cannot
3366+ /// pass on a stream that never reaches the fixed arm (class
3367+ /// gate-blind-to-feature).
3368+ #[test]
3369+ fn an_svt_screen_palette_block_with_a_split_transform_decodes_exactly() {
3370+ const NAME: &str = "an_svt_screen_palette_block_with_a_split_transform_decodes_exactly";
3371+ let Ok(path) = std::env::var("EC_AV1_SVT1_STREAM") else {
3372+ eprintln!("SKIP {NAME}: EC_AV1_SVT1_STREAM names no stream");
3373+ return;
3374+ };
3375+ if !have_ffmpeg() {
3376+ eprintln!("SKIP {NAME}: no ffmpeg");
3377+ return;
3378+ }
3379+ let data = match std::fs::read(&path) {
3380+ Ok(data) => data,
3381+ Err(e) => {
3382+ eprintln!("SKIP {NAME}: {path}: {e}");
3383+ return;
3384+ }
3385+ };
3386+ crate::decode::reset_skip_split_tx_override_hits();
3387+ let decoded = decode_stream(&data).expect("the kept SVT-AV1 screen stream decodes");
3388+ assert!(
3389+ crate::decode::skip_split_tx_override_hits() > 0,
3390+ "{NAME}: no skipped split-transform palette block in {path} -- the gate would pass blind"
3391+ );
3392+ let (width, height) = (decoded[0].width, decoded[0].height);
3393+ let want = ffmpeg_decode_sequence(&data, width, height, decoded.len());
3394+ for (i, (got, want)) in decoded.iter().zip(&want).enumerate() {
3395+ assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg");
3396+ assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg");
3397+ assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg");
3398+ }
3399+ }
3400+
3347 /// `decode_stream` agrees with ffmpeg/dav1d on the same wire bytes -- an3401 /// `decode_stream` agrees with ffmpeg/dav1d on the same wire bytes -- an
3348 /// independent decoder, not just this crate checking its own tile path.3402 /// independent decoder, not just this crate checking its own tile path.
3349 #[test]3403 #[test]
lanes/svt1.report.mdadded+133 -0
@@ -0,0 +1,133 @@
1+# lane-svt1 — one SVT-AV1 screen stream, one palette block, 10122 samples
2+
3+Stream: `libsvtav1 -preset 8 -crf 35 -svtav1-params lp=1 -g 12 -f obu`, screen
4+capture crop, **1920x1024** (the charter said 1920x768; `ffprobe` says 1024 and
5+the reference yuv is 12 x 2949120 bytes, i.e. 1920x1024 4:2:0), 12 frames, kept
6+outside the repo at `$HOME/.cache/svt1/svt-p8-crf35-screen.obu`.
7+
8+## The premise was wrong, in our favour
9+
10+The charter's "ONE sample off, frame 0 Y 1471489" is a mis-read. Diffing
11+`ours.f*.yuv` (u16 LE) against ffmpeg's 8-bit `ref.yuv`:
12+
13+| frame | differing samples | plane | rows | cols |
14+|---|---|---|---|---|
15+| 0 | 812 | Y only | 766..833 | 766..786 |
16+| 1..6 | 825 each | Y only | 763..834 | 766..786 |
17+| 7..11 | 872 each | Y only | 763..834 | 765..786 |
18+
19+**10122 samples total, luma only, chroma exact in every frame.** Sample 1471489
20+is (row 766, col 769) at width 1920, not (766, 1729). Max |delta| 144.
21+
22+## First divergent stage: pre-filter reconstruction
23+
24+Bisected with the decoder's own debug rungs, not with the stage dump:
25+`EC_AV1_DEBUG_SKIP_DEBLOCK=1`, `EC_AV1_DEBUG_SKIP_CDEF=1` and a new
26+`EC_AV1_DEBUG_SKIP_LR=1` (added beside its two siblings, and to
27+`pipe_filters_ok`'s stage-flag list). With every filter off the band is still
28+wrong and still flat, so no post-filter creates it — it is reconstruction.
29+
30+`EC_TRACE_MODE_STEP=1` through both decoders then diffs **clean**: all 49080
31+mode-ladder lines of frame 0 (`skip`, `cdef`, `dq`, `mode`, `angle_y`,
32+`uv_mode`, `angle_uv`, `tx_depth`) agree with the instrumented aomdec value for
33+value AND range for range. Right symbols, wrong pixels.
34+
35+The block: `EC_PALSYN=1` says `mi=192,192 bsize=6 mode=0 uv=0 ctx=1 y=8` — a
36+16x16 **palette** block (8 colours) at pixel (768, 768), `skip=1`,
37+`tx_depth=1`. libaom prints no `EC_PRED`/`EC_PREDOUT8` for its luma (palette
38+does not predict off edges); it does print the chroma DC. Ours filled the whole
39+16x16 with 54 = the DC of its top edge, and the six 8x8 `V_PRED skip` blocks
40+below it (mi rows 196..206, col 192) then propagated that flat value down the
41+next 48 rows, which is the 64-row tall band in the table above.
42+
43+## Root cause
44+
45+`crates/ec-av1/src/decode.rs`, `decode_block` (square intra):
46+
47+```rust
48+if let Some(buf) = &palette_y_buf && logical_tx == side { set_palette_pred(...) }
49+```
50+
51+A **skipped** block predicts the whole `side`x`side` in ONE call — the skip
52+branch's per-unit walk (`split_tx_skip`) explicitly excludes palette/intrabc
53+blocks — so gating the arm on `logical_tx == side` left every skipped palette
54+(or intrabc) block whose `tx_depth` split the transform with an empty override
55+slot and an edge prediction. Fix: `&& (logical_tx == side || skip)`. Neither
56+prediction is edge-derived, so the whole-block buffer at the block's own stride
57+is exactly what that single call consumes.
58+
59+Class: **override-slot-on-one-arm** (the memory entry of that name is the same
60+shape: an override installed on the skip arm only).
61+
62+## Same-shape sweep
63+
64+`grep -n 'logical_tx == side\|split_tx_skip'` — one site, now fixed. Every
65+sibling path already arms on both arms and was checked by reading:
66+
67+* `decode_leaf8` (8x8, TX_4X4 split): arms inside the non-split `else`, and its
68+ `resolved == 4 && palette_y_buf.is_none()` guard is the same rule — correct.
69+* `decode_rect_split`: windows the map per transform unit including the skip
70+ arm — correct.
71+* `decode_block_rect`, `decode_block_rect64`: arm unconditionally before the
72+ skip branch — correct.
73+* the intra-in-inter var-tx walk (`vartx_leaves`): windows per unit, skip arm
74+ included — correct.
75+
76+## Witness
77+
78+`skip_split_tx_override_hits()` (new counter, incremented on the SHAPE, not on
79+the fixed arm, so it also counts pre-fix) fires **exactly once** in the whole
80+12-frame stream — that one block.
81+
82+No lavfi recipe witnesses the defect in a stream this decoder otherwise
83+decodes. Measured: 6 sources x 5 sizes (384x152, 320x184, 256x190, 640x366,
84+320x240) x 6 crf (25..50), all `libsvtav1 -preset 8 -svtav1-params
85+lp=1:screen-content-mode=1`, 4 frames. 8 streams reach the fixed arm
86+(`hits=1`); of those, 2 are REFUSED by this decoder ("a Golomb tail longer than
87+this decoder reads") and 6 miss by ~200k-245k samples on unrelated inter-frame
88+defects. `smptebars,drawgrid` at 384x152 is the only family that reaches the
89+arm at all; `smptebars` alone, `pal75bars`, `testsrc`, `testsrc2` and
90+`color+drawgrid` never do.
91+
92+So the gate rides the kept stream, per the charter's own fallback:
93+`stream::tests::an_svt_screen_palette_block_with_a_split_transform_decodes_exactly`,
94+gated on `EC_AV1_SVT1_STREAM` (SKIPs with a printed reason when unset, or when
95+ffmpeg is missing, or when the path does not read). It asserts the counter is
96+non-zero before comparing, so it cannot pass on a stream that never reaches the
97+path (class gate-blind-to-feature). The screen crop is NOT committed.
98+
99+* RED (fix reverted, counter kept): `assertion left == right failed: frame 0
100+ luma vs ffmpeg`, `test result: FAILED` (`$HOME/.cache/svt1/redtest2.log`).
101+* GREEN: `test result: ok. 1 passed` (`$HOME/.cache/svt1/greentest.log`), and a
102+ full 12-frame `dump_yuv` vs ffmpeg diff reads **0 differing samples in every
103+ plane of every frame**.
104+
105+## The stall finding
106+
107+Not reproduced, and not tested: the bisect never needed the stage dump. Every
108+decode here ran under `systemd-run --user` and finished in seconds (12 frames
109+of 1920x1024: `dump_yuv` ~5 s, instrumented `aomdec --limit=1` ~10 s). The two
110+prior agents ran the dump command in the FOREGROUND; nothing in this lane
111+suggests the instrument itself hangs, but nothing here exercises it either —
112+`EC_AV1_PREFILT_DUMP`/`EC_AV1_POSTDEBLOCK_DUMP` remain untested by this lane.
113+
114+## Open (not this lane's fix)
115+
116+* `unsupported: AV1 tile (a Golomb tail longer than this decoder reads)` on 2
117+ of 8 synthetic SVT-AV1 screen streams (e.g.
118+ `smptebars=s=384x152:r=12,drawgrid=w=8:h=8:t=1:c=black`, preset 8, crf 35,
119+ `screen-content-mode=1`). Streams are under `$HOME/.cache/svt1/w3/`.
120+* ~200k-sample misses on the INTER frames of those same synthetic screen
121+ streams (their frame 0 is not the only wrong frame). A separate lane: this
122+ one only closes the key-frame palette block.
123+
124+## Gates on 68c61d33
125+
126+| gate | result |
127+|---|---|
128+| `encode::tests::the_encoders_own_streams_are_byte_identical_to_their_pins` | ok, 1 passed (unchanged on this base) |
129+| s1 `--skip stream::` | ok, 335 passed, 0 failed, 32 ignored (571 s) |
130+| s2 `stream:: --skip 10bit` | ok, 200 passed, 0 failed, 15 ignored (752 s) |
131+| s3 `10bit` | ok, 42 passed, 0 failed, 1 ignored (60 s) |
132+| `cargo check --workspace --all-targets` | 0 errors, 0 ec-av1 warnings (21 pre-existing in ec-opus, 1 in ec-vorbis) |
133+| kept stream, 12 frames, all planes | 0 differing samples |