forge
Explore
Log in

Don't you dare go Hollow

Gate loop restoration's frame-edge stripe shapes -- stripe 0 and the partial bottom stripe

Browse files at this commit

8c352b6ad63a51bdee83d4510910652d8c75778eAhmet Kaan GümüşParent: 3355529
  • test
    • gate loop restoration's frame-edge stripe shapes -- stripe 0 and the partial bottom stripe
Show full message
test(av1): gate loop restoration's frame-edge stripe shapes -- stripe 0 and the partial bottom stripe

The chartered defect (a 1920x792 10-bit AV1 key frame wrong in rows 0..7) does
not reproduce at this base: 11/11 decodable key frames of that stream decode
0-sample-exact against ffmpeg, so no fix was needed. What was missing was the
gate: every LR gate size so far was a whole multiple of 64 rows at --sb-size=64,
so the 56-row first stripe (RESTORATION_UNIT_OFFSET==8) and the truncated last
stripe -- the only two stripes whose boundary rows come from the frame's own
top/bottom row instead of the deblocked plane -- were never asserted to have run.

- restoration.rs: LR_STRIPE0_HITS / LR_LAST_STRIPE_HITS counters, bumped in
  filter_restoration_unit for a non-None filter on a stripe starting at plane
  row 0, resp. a truncated stripe ending at plane_h.
- stream.rs: new 10-bit gate, real aomenc --sb-size=128 --enable-restoration=1
  --cpu-used=0, 256x152 cq15 / 384x216 cq15 / 256x152 cq25, 16 seeds each, all
  frames vs ffmpeg, both counters hard-asserted per compared attempt: 48/48
  pixel-exact, stripe0 108, last-stripe 108.
- stream.rs: the 8-bit LR gate moves 192x128 -> 192x152 (128's stripe shapes are
  a subset) and asserts the same two counters: 40/40 pixel-exact.
crates/ec-av1/src/restoration.rsmodified+28 -0
@@ -366,6 +366,26 @@ thread_local! {
366366 static SWITCHABLE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
367367 }
368368
369+/// lane-reelckf2 r1: how many *stripes* a real filter ran on with the frame's
370+/// own top row as their above boundary (`stripe_v_start == 0`, the 56-row
371+/// first stripe of `RESTORATION_UNIT_OFFSET == 8`), and how many ran on a
372+/// short LAST stripe (`stripe_v_end == plane_h` with a partial height). Those
373+/// are the two stripe shapes whose boundary substitution differs from every
374+/// interior stripe, and no gate size before this one had either.
375+thread_local! {
376+ static LR_STRIPE0_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
377+ static LR_LAST_STRIPE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
378+}
379+
380+/// Current value of [`LR_STRIPE0_HITS`].
381+pub(crate) fn lr_stripe0_hits() -> usize {
382+ LR_STRIPE0_HITS.with(|c| c.get())
383+}
384+/// Current value of [`LR_LAST_STRIPE_HITS`].
385+pub(crate) fn lr_last_stripe_hits() -> usize {
386+ LR_LAST_STRIPE_HITS.with(|c| c.get())
387+}
388+
369389 /// Current value of [`WIENER_HITS`].
370390 pub(crate) fn wiener_hits() -> usize {
371391 WIENER_HITS.with(|c| c.get())
@@ -868,6 +888,14 @@ fn filter_restoration_unit(
868888 let nominal_h = full_stripe_height - if frame_stripe == 0 { runit_offset } else { 0 };
869889 let h = nominal_h.min(unit_h - i);
870890 let stripe_v_end = stripe_v_start + h;
891+ if !matches!(filter, UnitFilter::None) {
892+ if stripe_v_start == 0 {
893+ LR_STRIPE0_HITS.with(|c| c.set(c.get() + 1));
894+ }
895+ if stripe_v_end == plane_h && h < nominal_h {
896+ LR_LAST_STRIPE_HITS.with(|c| c.set(c.get() + 1));
897+ }
898+ }
871899 match filter {
872900 UnitFilter::Wiener(info) => apply_wiener_stripe(
873901 out, cdef, deblocked, stride, plane_w, plane_h, h_start, h_end, stripe_v_start, stripe_v_end, &info,
crates/ec-av1/src/stream.rsmodified+85 -1
@@ -3379,6 +3379,72 @@ mod tests {
33793379 + crate::restoration::switchable_hits()
33803380 }
33813381
3382+ /// lane-reelckf2 r1: loop restoration on frame sizes whose LAST stripe is
3383+ /// partial, with 128-sample superblocks -- the two stripe shapes whose
3384+ /// boundary substitution is special (`filter_restoration_unit`: the first
3385+ /// stripe is 8 rows short and takes its above boundary from the frame's
3386+ /// own top rows, the last one is truncated and takes its below boundary
3387+ /// from the frame's own bottom row) had no gate at all: every earlier LR
3388+ /// size (192x128, 160x96) is a whole multiple of 64 rows and ran at
3389+ /// `--sb-size=64`. 152 = 2*64+24 and 216 = 3*64+24 both leave a 32-row
3390+ /// tail stripe, mirroring the 792-row 10-bit film that made this lane.
3391+ /// `lr_stripe0_hits`/`lr_last_stripe_hits` are hard-asserted per attempt
3392+ /// by [`ten_bit_tool_gate`], so an RD that picked RESTORE_NONE on either
3393+ /// stripe cannot pass.
3394+ #[test]
3395+ fn a_real_aomenc_10bit_partial_bottom_stripe_restoration_decodes_pixel_exact() {
3396+ const NAME: &str =
3397+ "a_real_aomenc_10bit_partial_bottom_stripe_restoration_decodes_pixel_exact";
3398+ if !have_ffmpeg() {
3399+ eprintln!("SKIP {NAME}: no ffmpeg");
3400+ return;
3401+ }
3402+ if !have_aomenc() {
3403+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
3404+ return;
3405+ }
3406+ // `--sb-size=128` goes in `extra`, which the helper appends AFTER its
3407+ // own `--sb-size=64` (aomenc keeps the LAST occurrence of a repeated
3408+ // flag, measured 2026-09-02); `--max-partition-size=32` keeps the 128
3409+ // root on SPLIT, the only 128-root partition decoded today.
3410+ for (width, height, cq) in [(256usize, 152usize, "15"), (384, 216, "15"), (256, 152, "25")]
3411+ {
3412+ ten_bit_tool_gate(
3413+ &format!("{NAME} {width}x{height} cq{cq}"),
3414+ width,
3415+ height,
3416+ 1,
3417+ &[
3418+ "--limit=1",
3419+ "--kf-max-dist=0",
3420+ &format!("--cq-level={cq}"),
3421+ "--sb-size=128",
3422+ "--enable-restoration=1",
3423+ "--enable-cdef=0",
3424+ "--enable-rect-partitions=0",
3425+ "--enable-ab-partitions=0",
3426+ "--enable-1to4-partitions=0",
3427+ "--enable-filter-intra=0",
3428+ "--enable-smooth-intra=0",
3429+ "--enable-paeth-intra=0",
3430+ "--enable-tx-size-search=0",
3431+ "--max-partition-size=32",
3432+ "--min-partition-size=16",
3433+ "--enable-palette=0",
3434+ "--enable-intrabc=0",
3435+ "--enable-cfl-intra=0",
3436+ "--enable-ref-frame-mvs=0",
3437+ ],
3438+ &LR_SEEDS,
3439+ &[
3440+ ("lr_hits", ten_bit_lr_hits),
3441+ ("lr_stripe0_hits", crate::restoration::lr_stripe0_hits),
3442+ ("lr_last_stripe_hits", crate::restoration::lr_last_stripe_hits),
3443+ ],
3444+ );
3445+ }
3446+ }
3447+
33823448 /// lane-hbdgates r1: `--enable-rect-partitions=1 --enable-ab-partitions=1`
33833449 /// at 10 bits, one intra stream, one counter per tool
33843450 /// (`rect_partition_hits`, `partab_hits`) so a stream that only fired the
@@ -13859,13 +13925,20 @@ mod tests {
1385913925 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
1386013926 return;
1386113927 }
13862- let (width, height) = (192usize, 128usize);
13928+ // lane-reelckf2 r1: 152 = 2*64+24, not 128 -- the 8-bit twin of the
13929+ // partial-bottom-stripe LR gate below. Stripe shapes at 128 rows are
13930+ // a strict subset of those at 152 (56, 64, then the 32-row tail whose
13931+ // below boundary is the frame's own last row).
13932+ let (width, height) = (192usize, 152usize);
1386313933 let n_attempts: u32 = std::env::var("EC_LR_GATE_ATTEMPTS")
1386413934 .ok()
1386513935 .and_then(|s| s.parse().ok())
1386613936 .unwrap_or(40);
1386713937 let mut lr_refusals = 0u32;
1386813938 let mut other_refusals = Vec::new();
13939+ // lane-reelckf2 r1: the two special stripe shapes this size now has.
13940+ let stripe0_before = crate::restoration::lr_stripe0_hits();
13941+ let last_stripe_before = crate::restoration::lr_last_stripe_hits();
1386913942 for attempt in 0..n_attempts {
1387013943 let seed = 42 + attempt;
1387113944 // Diagnosis knob: which content makes RD pick an 8x16/16x8 strip
@@ -14010,6 +14083,17 @@ mod tests {
1401014083 "{NAME}: {lr_refusals} LR refusals fired but read_lr_unit never decoded a real \
1401114084 (non-None) filter -- gate proved nothing about the symbol path"
1401214085 );
14086+ // lane-reelckf2 r1: a size with a partial bottom stripe proves nothing
14087+ // about the two frame-edge stripe shapes unless a real filter actually
14088+ // ran on them (`filter_restoration_unit`).
14089+ assert!(
14090+ crate::restoration::lr_stripe0_hits() > stripe0_before
14091+ && crate::restoration::lr_last_stripe_hits() > last_stripe_before,
14092+ "{NAME}: no filtered stripe took the frame's own top/bottom row as its boundary \
14093+ (stripe0 +{}, last +{})",
14094+ crate::restoration::lr_stripe0_hits() - stripe0_before,
14095+ crate::restoration::lr_last_stripe_hits() - last_stripe_before
14096+ );
1401314097 eprintln!(
1401414098 "{NAME}: {lr_refusals} LR refusals, {} other refusals out of {n_attempts}, \
1401514099 wiener_hits={} sgrproj_hits={} switchable_hits={}",
lanes/reelckf2-r1.report.mdadded+83 -0
@@ -0,0 +1,83 @@
1+# lane-reelckf2 r1 — the "-ss 300 key frame is not pixel-exact" premise is STALE; LR stripe-0 / partial-bottom-stripe now gated
2+
3+Base: `fedb7fe` (lane-sb128c r6 tip = main 85887c7 + 128-superblock support). Branch `lane-reelckf2`.
4+
5+## 1. The chartered defect does not reproduce (premise stale)
6+
7+lane-interedge r1 reported the 1920x792 10-bit film's key frame at `-ss 300` wrong in rows 0..7
8+(max luma delta 12, 13710/15360 samples). Re-measured at this base, first thing, per COMMON:
9+
10+ ffmpeg -ss 300 -t 2 -i <film> -c:v copy -an -f obu s300.obu # bounded, under systemd-run --scope MemoryMax=6G
11+ python3 census4/trunc.py s300.obu 1 t300.obu # first temporal unit, 206172 bytes
12+ sha256 t300.obu (twice) = 9734f645854a9cc657040b7e6d7937a18aade34559610f62e7df4eb67bc3d993
13+ EC_PROBE_OUT16=o300.raw decode_probe t300.obu ; ffmpeg -i t300.obu -pix_fmt yuv420p10le -f rawvideo r300.raw
14+
15+Result: **0 wrong samples in Y, U and V** (max delta 0), rows 0..7 included.
16+
17+Whole key-frame table (`~/.cache/reelckf2-tmp/kf.sh`, one truncated key frame per offset, ours
18+vs ffmpeg yuv420p10le, all three planes):
19+
20+| -ss | stream sha (12) | result | wrong samples (all planes) |
21+|-----|-----------------|--------|-----|
22+| 0 | 9746d3df3bbf | OK | 0 |
23+| 300 | 9734f645854a | OK | 0 |
24+| 900 | b205be5ade93 | OK | 0 |
25+| 1800 | d514ad0d9397 | OK | 0 |
26+| 2700 | 16981094eaab | OK | 0 |
27+| 3600 | 66d309bcc22d | OK | 0 |
28+| 4500 | b40563ecd03f | OK | 0 |
29+| 5400 | c7a924ed7e86 | OK | 0 |
30+| 6300 | 3b9a4b380393 | OK | 0 |
31+| 7200 | 80e36a4cde45 | OK | 0 |
32+| 8100 | 23ce4869ccdb | REFUSED: 128x128 superblock HORZ/VERT or AB partition | n/a |
33+| 9000 | 26b410f82657 | REFUSED: 128x128 superblock HORZ/VERT or AB partition | n/a |
34+| 9900 | 748605ef91ac | OK | 0 |
35+
36+11/11 decodable key frames pixel-exact; the 2 refusals are the residue lane-sb128c r6 already
37+named (128-root HORZ/VERT/AB), not this lane's.
38+
39+EVIDENCE: ~/.cache/reelckf2-tmp/kf.sh output above | extract -t 2 at 13 offsets, trunc to 1 frame, decode with EC_PROBE_OUT16, ffmpeg yuv420p10le reference | 11/11 decoded frames 0 wrong samples, 2 named refusals
40+
41+## 2. What the round did instead: gate the stripe shapes nobody had gated
42+
43+The charter's prime suspect (LR stripe 0, `RESTORATION_UNIT_OFFSET==8`) is correct code but was
44+untested: every LR gate size before this round (192x128, 160x96) is a whole multiple of 64 rows
45+and ran `--sb-size=64`, so no gate ever exercised the *partial* last stripe, and none asserted
46+that a real filter ran on stripe 0 at all (class `tool-disabled-in-every-gate`).
47+
48+- `crates/ec-av1/src/restoration.rs:368` — new `LR_STRIPE0_HITS` / `LR_LAST_STRIPE_HITS`
49+ thread-locals + `lr_stripe0_hits()` / `lr_last_stripe_hits()`, bumped in
50+ `filter_restoration_unit` when a non-`None` filter runs on a stripe starting at plane row 0,
51+ resp. on a truncated stripe ending at `plane_h`.
52+- `crates/ec-av1/src/stream.rs:3395` — new gate
53+ `a_real_aomenc_10bit_partial_bottom_stripe_restoration_decodes_pixel_exact`: real aomenc,
54+ `--sb-size=128 --enable-restoration=1 --cpu-used=0`, 10-bit, three arms
55+ (256x152 cq15, 384x216 cq15, 256x152 cq25 — 152 = 2*64+24, 216 = 3*64+24, both leaving the same
56+ 32-row tail stripe shape as the film's 792 rows), 16 seeds each, every decode-order frame
57+ compared against ffmpeg, `lr_hits` + `lr_stripe0_hits` + `lr_last_stripe_hits` hard-asserted
58+ per compared attempt by `ten_bit_tool_gate` (a refused attempt contributes no counts).
59+- `crates/ec-av1/src/stream.rs:13929` — the 8-bit LR gate's size moved 192x128 -> 192x152 (its
60+ stripe shapes at 128 are a strict subset) and it now hard-asserts the same two counters.
61+
62+Results:
63+
64+ a_real_aomenc_10bit_partial_bottom_stripe_..._exact 256x152 cq15: 16/16 attempts pixel-exact, lr_hits=33 lr_stripe0_hits=33 lr_last_stripe_hits=33
65+ a_real_aomenc_10bit_partial_bottom_stripe_..._exact 384x216 cq15: 16/16 attempts pixel-exact, lr_hits=54 lr_stripe0_hits=51 lr_last_stripe_hits=51
66+ a_real_aomenc_10bit_partial_bottom_stripe_..._exact 256x152 cq25: 16/16 attempts pixel-exact, lr_hits=24 lr_stripe0_hits=24 lr_last_stripe_hits=24
67+ a_real_aomenc_stream_with_restoration_reads_lr_symbols_correctly (8-bit, 192x152): 40/40 decoded and compared pixel-exact, wiener_hits=23 sgrproj_hits=78
68+
69+EVIDENCE: cargo test -p ec-av1 --lib partial_bottom_stripe -- --nocapture | 48 real aomenc 10-bit sb128 streams over 3 sizes/cq, every shown frame vs ffmpeg | 48/48 pixel-exact, stripe0 108 / last-stripe 108 filtered stripes, 0 mismatches
70+
71+No refusal was lifted (`refusal_inventory.rs` / `gate_coverage.rs` untouched — this round adds
72+coverage, it does not widen capability).
73+
74+## 3. Open residue / dispositions
75+
76+- deferred: a dedicated 8-bit arm of the *new* gate — accepted instead by moving the existing
77+ 8-bit LR gate to 192x152 (same stripe shapes, 40/40 pixel-exact) — unblocked by a seeded 8-bit
78+ twin of `ten_bit_tool_gate`, which does not exist and would be a ~90-line duplicate.
79+- deferred: the 2 refusing film key frames (8100, 9000) — 128-root HORZ/VERT/AB partitions,
80+ lane-sb128c's named residue — unblocked by that lane.
81+- deviation: the branch is NOT rebased onto today's main (`cc323d0`); its base is the charter's
82+ `fedb7fe`, which is main 85887c7 + the 128-SB work the film needs. It merges into main after
83+ lane-sb128c.