forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-reelckf2' (6fc8bab): loop-restoration stripe counters and their gates

Browse files at this commit

e0d4def5aa3658fb81793fbd8cf12bfe29ea7983Ahmet Kaan GümüşParent: ec3d7923975c54
Clean merge, no conflicts.

Gates: partial_bottom_stripe / restoration / refusal_inventory /
gate_coverage / base_ctx_rect_offsets -- 21 passed. The two known
cross-product reds carried from the sb128c merge are unchanged
(a_frame_edge_straddling_band, 10bit split_transform_intra_block).
crates/ec-av1/src/restoration.rsmodified+28 -0
@@ -366,6 +366,26 @@ thread_local! {
366 static SWITCHABLE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };366 static SWITCHABLE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
367 }367 }
368 368
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+
369 /// Current value of [`WIENER_HITS`].389 /// Current value of [`WIENER_HITS`].
370 pub(crate) fn wiener_hits() -> usize {390 pub(crate) fn wiener_hits() -> usize {
371 WIENER_HITS.with(|c| c.get())391 WIENER_HITS.with(|c| c.get())
@@ -868,6 +888,14 @@ fn filter_restoration_unit(
868 let nominal_h = full_stripe_height - if frame_stripe == 0 { runit_offset } else { 0 };888 let nominal_h = full_stripe_height - if frame_stripe == 0 { runit_offset } else { 0 };
869 let h = nominal_h.min(unit_h - i);889 let h = nominal_h.min(unit_h - i);
870 let stripe_v_end = stripe_v_start + h;890 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+ }
871 match filter {899 match filter {
872 UnitFilter::Wiener(info) => apply_wiener_stripe(900 UnitFilter::Wiener(info) => apply_wiener_stripe(
873 out, cdef, deblocked, stride, plane_w, plane_h, h_start, h_end, stripe_v_start, stripe_v_end, &info,901 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
@@ -4116,6 +4116,72 @@ mod tests {
4116 + crate::restoration::switchable_hits()4116 + crate::restoration::switchable_hits()
4117 }4117 }
4118 4118
4119+ /// lane-reelckf2 r1: loop restoration on frame sizes whose LAST stripe is
4120+ /// partial, with 128-sample superblocks -- the two stripe shapes whose
4121+ /// boundary substitution is special (`filter_restoration_unit`: the first
4122+ /// stripe is 8 rows short and takes its above boundary from the frame's
4123+ /// own top rows, the last one is truncated and takes its below boundary
4124+ /// from the frame's own bottom row) had no gate at all: every earlier LR
4125+ /// size (192x128, 160x96) is a whole multiple of 64 rows and ran at
4126+ /// `--sb-size=64`. 152 = 2*64+24 and 216 = 3*64+24 both leave a 32-row
4127+ /// tail stripe, mirroring the 792-row 10-bit film that made this lane.
4128+ /// `lr_stripe0_hits`/`lr_last_stripe_hits` are hard-asserted per attempt
4129+ /// by [`ten_bit_tool_gate`], so an RD that picked RESTORE_NONE on either
4130+ /// stripe cannot pass.
4131+ #[test]
4132+ fn a_real_aomenc_10bit_partial_bottom_stripe_restoration_decodes_pixel_exact() {
4133+ const NAME: &str =
4134+ "a_real_aomenc_10bit_partial_bottom_stripe_restoration_decodes_pixel_exact";
4135+ if !have_ffmpeg() {
4136+ eprintln!("SKIP {NAME}: no ffmpeg");
4137+ return;
4138+ }
4139+ if !have_aomenc() {
4140+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
4141+ return;
4142+ }
4143+ // `--sb-size=128` goes in `extra`, which the helper appends AFTER its
4144+ // own `--sb-size=64` (aomenc keeps the LAST occurrence of a repeated
4145+ // flag, measured 2026-09-02); `--max-partition-size=32` keeps the 128
4146+ // root on SPLIT, the only 128-root partition decoded today.
4147+ for (width, height, cq) in [(256usize, 152usize, "15"), (384, 216, "15"), (256, 152, "25")]
4148+ {
4149+ ten_bit_tool_gate(
4150+ &format!("{NAME} {width}x{height} cq{cq}"),
4151+ width,
4152+ height,
4153+ 1,
4154+ &[
4155+ "--limit=1",
4156+ "--kf-max-dist=0",
4157+ &format!("--cq-level={cq}"),
4158+ "--sb-size=128",
4159+ "--enable-restoration=1",
4160+ "--enable-cdef=0",
4161+ "--enable-rect-partitions=0",
4162+ "--enable-ab-partitions=0",
4163+ "--enable-1to4-partitions=0",
4164+ "--enable-filter-intra=0",
4165+ "--enable-smooth-intra=0",
4166+ "--enable-paeth-intra=0",
4167+ "--enable-tx-size-search=0",
4168+ "--max-partition-size=32",
4169+ "--min-partition-size=16",
4170+ "--enable-palette=0",
4171+ "--enable-intrabc=0",
4172+ "--enable-cfl-intra=0",
4173+ "--enable-ref-frame-mvs=0",
4174+ ],
4175+ &LR_SEEDS,
4176+ &[
4177+ ("lr_hits", ten_bit_lr_hits),
4178+ ("lr_stripe0_hits", crate::restoration::lr_stripe0_hits),
4179+ ("lr_last_stripe_hits", crate::restoration::lr_last_stripe_hits),
4180+ ],
4181+ );
4182+ }
4183+ }
4184+
4119 /// lane-hbdgates r1: `--enable-rect-partitions=1 --enable-ab-partitions=1`4185 /// lane-hbdgates r1: `--enable-rect-partitions=1 --enable-ab-partitions=1`
4120 /// at 10 bits, one intra stream, one counter per tool4186 /// at 10 bits, one intra stream, one counter per tool
4121 /// (`rect_partition_hits`, `partab_hits`) so a stream that only fired the4187 /// (`rect_partition_hits`, `partab_hits`) so a stream that only fired the
@@ -16031,13 +16097,20 @@ mod tests {
16031 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());16097 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
16032 return;16098 return;
16033 }16099 }
16034- let (width, height) = (192usize, 128usize);16100+ // lane-reelckf2 r1: 152 = 2*64+24, not 128 -- the 8-bit twin of the
16101+ // partial-bottom-stripe LR gate below. Stripe shapes at 128 rows are
16102+ // a strict subset of those at 152 (56, 64, then the 32-row tail whose
16103+ // below boundary is the frame's own last row).
16104+ let (width, height) = (192usize, 152usize);
16035 let n_attempts: u32 = std::env::var("EC_LR_GATE_ATTEMPTS")16105 let n_attempts: u32 = std::env::var("EC_LR_GATE_ATTEMPTS")
16036 .ok()16106 .ok()
16037 .and_then(|s| s.parse().ok())16107 .and_then(|s| s.parse().ok())
16038 .unwrap_or(40);16108 .unwrap_or(40);
16039 let mut lr_refusals = 0u32;16109 let mut lr_refusals = 0u32;
16040 let mut other_refusals = Vec::new();16110 let mut other_refusals = Vec::new();
16111+ // lane-reelckf2 r1: the two special stripe shapes this size now has.
16112+ let stripe0_before = crate::restoration::lr_stripe0_hits();
16113+ let last_stripe_before = crate::restoration::lr_last_stripe_hits();
16041 for attempt in 0..n_attempts {16114 for attempt in 0..n_attempts {
16042 let seed = 42 + attempt;16115 let seed = 42 + attempt;
16043 // Diagnosis knob: which content makes RD pick an 8x16/16x8 strip16116 // Diagnosis knob: which content makes RD pick an 8x16/16x8 strip
@@ -16182,6 +16255,17 @@ mod tests {
16182 "{NAME}: {lr_refusals} LR refusals fired but read_lr_unit never decoded a real \16255 "{NAME}: {lr_refusals} LR refusals fired but read_lr_unit never decoded a real \
16183 (non-None) filter -- gate proved nothing about the symbol path"16256 (non-None) filter -- gate proved nothing about the symbol path"
16184 );16257 );
16258+ // lane-reelckf2 r1: a size with a partial bottom stripe proves nothing
16259+ // about the two frame-edge stripe shapes unless a real filter actually
16260+ // ran on them (`filter_restoration_unit`).
16261+ assert!(
16262+ crate::restoration::lr_stripe0_hits() > stripe0_before
16263+ && crate::restoration::lr_last_stripe_hits() > last_stripe_before,
16264+ "{NAME}: no filtered stripe took the frame's own top/bottom row as its boundary \
16265+ (stripe0 +{}, last +{})",
16266+ crate::restoration::lr_stripe0_hits() - stripe0_before,
16267+ crate::restoration::lr_last_stripe_hits() - last_stripe_before
16268+ );
16185 eprintln!(16269 eprintln!(
16186 "{NAME}: {lr_refusals} LR refusals, {} other refusals out of {n_attempts}, \16270 "{NAME}: {lr_refusals} LR refusals, {} other refusals out of {n_attempts}, \
16187 wiener_hits={} sgrproj_hits={} switchable_hits={}",16271 wiener_hits={} sgrproj_hits={} switchable_hits={}",
lanes/reelckf2-r1.report.mdadded+88 -0
@@ -0,0 +1,88 @@
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.
84+
85+## 4. Suite
86+
87+`cargo test -p ec-av1 --lib` (systemd user unit, MemoryMax=10G, log `$HOME/.cache/reelckf2-suite-r1.log`):
88+**386 passed; 0 failed; 35 ignored**, 1578 s.