forge
Explore
Log in

Don't you dare go Hollow

ec-av1: lane-av1lrflush -- r2's RU-row-0 flush defect refuted by measurement

Browse files at this commit

3274825a1205d31d74669e8bd875e82892badfb0Ahmet Kaan GümüşParent: 14fead3
The pipelined LR band release provably flushes RU row 0: with the filter
pipeline engaged (EC_AV1_FILTER_THREADS=4, recon serial, pipe_on witnessed
by a new unconditional PIPELINE_TAKEN counter) the witness decodes
byte-identical to the whole-frame path on all three frames, including the
128-root-rect inter frame; r2's stop-with-site was a stage-ladder mixup
(its FINAL numbers are today's POSTCDEF numbers; f2 already diverges at
PREFILT). The real f2 residual re-enters at column 128 inside the inter
64x128 at (128,0) -- the entropy lane's inter rect-strip site, untouched
here. New defect named for its own lane: wavefront recon (recon threads>1)
loses chroma writes at PREFILT on the inter frames (Y exact).

Lands the refutation as a doubly non-vacuous gate (PIPELINE_TAKEN delta +
LR_STRIPE0_HITS delta + pipeline==serial byte-exact + frames 0/1 vs
aomdec and ffmpeg through the pipeline), mutation-verified red by
disabling the RU-row-0 band release. cargo check 0 warnings; restoration
battery (EC_AV1_REQUIRE_AOMENC=1) 10/10 green.
crates/ec-av1/src/decode.rsmodified+19 -0
@@ -25255,6 +25255,19 @@ fn wave_rows_complete(fctx: &crate::decode::FrameCtx) -> usize {
2525525255 static PIPE_FRAMES: AtomicU64 = AtomicU64::new(0);
2525625256 static PIPE_WHOLE: AtomicU64 = AtomicU64::new(0);
2525725257
25258+/// lane-av1lrflush: frames that CONSTRUCTED the filter pipeline, counted
25259+/// unconditionally. Read by gates through [`pipeline_taken_frames`] as a
25260+/// before/after delta -- the non-vacuity witness that a "pipelined" gate arm
25261+/// really ran `pipe_run`/`pipe_run_lr` rather than silently falling back to
25262+/// the whole-frame path.
25263+static PIPELINE_TAKEN: AtomicU64 = AtomicU64::new(0);
25264+
25265+/// Current value of [`PIPELINE_TAKEN`], for a gate's own before/after delta.
25266+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
25267+pub(crate) fn pipeline_taken_frames() -> u64 {
25268+ PIPELINE_TAKEN.load(std::sync::atomic::Ordering::Relaxed)
25269+}
25270+
2525825271 /// Whether this frame's filters may run per superblock row. Everything that
2525925272 /// reads the picture out of band order, or the pipeline's own inputs out of
2526025273 /// row order, keeps the whole-frame path: superres (a between-CDEF-and-LR
@@ -39830,6 +39843,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
3983039843 let snap_on = pipe_on && (cdef_on || lr_active);
3983139844 let mut pipe_snap = snap_on.then(|| (snap_alloc(&y), snap_alloc(&u), snap_alloc(&v)));
3983239845 let mut pipe = pipe_on.then(|| {
39846+ // lane-av1lrflush: counted unconditionally (unlike `PIPE_FRAMES`
39847+ // below, which is `EC_AV1_WAVE_STATS`-gated) so a gate can prove a
39848+ // pipelined arm actually took the pipeline even when
39849+ // `filter_threads()`'s once-per-process env read was already cached
39850+ // by an earlier test in the same binary.
39851+ PIPELINE_TAKEN.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
3983339852 if wave_stats() {
3983439853 PIPE_FRAMES.fetch_add(1, Relaxed);
3983539854 }
crates/ec-av1/src/stream.rsmodified+149 -0
@@ -5891,6 +5891,155 @@ pub(crate) mod tests {
58915891 }
58925892 }
58935893
5894+ /// lane-av1lrflush: the pipelined loop-restoration band release flushes
5895+ /// RU row 0 on the inter frame whose top superblock row carries a
5896+ /// 128-root rect -- the exact shape lanes/av1444sb.report.md r2 named as
5897+ /// its stop-with-site DEFECT 3 ("`pipe_run_lr`'s `rrows` branch plus the
5898+ /// `ls.note`/`ls.close` band release never flushes RU row 0 on frame 2").
5899+ /// r3 REFUTED that defect by measurement: on this fixture the filter
5900+ /// pipeline (deblock/CDEF/LR band workers over `ls.note` releases)
5901+ /// produces output byte-identical to the whole-frame path on every frame
5902+ /// -- this gate pins that refutation so a future band-accounting
5903+ /// regression on a 128-root-rect inter frame cannot land silently.
5904+ ///
5905+ /// Non-vacuity, twice over: the `PIPELINE_TAKEN` delta proves the second
5906+ /// decode really constructed the pipeline on both inter frames (frame 0
5907+ /// is a key frame and the key-frame path runs whole-frame filters by
5908+ /// construction), and the `LR_STRIPE0_HITS` delta proves a real filter
5909+ /// ran on stripe 0 -- RU row 0's own first stripe, the span the named
5910+ /// defect left un-restored. Frames 0/1 are additionally asserted
5911+ /// byte-exact against BOTH the oracle aomdec and ffmpeg THROUGH the
5912+ /// pipeline. (Frame 2's own residual is the entropy lane's inter
5913+ /// rect-strip recon defect -- see lanes/av1lrflush.report.md r3 -- and
5914+ /// is identical on the serial and pipelined runs, so the pipeline
5915+ /// equality covers it without pinning its wrong samples.)
5916+ #[test]
5917+ fn a_444_sb128_witness_lr_pipeline_flushes_ru_row_0_pixel_exact() {
5918+ const NAME: &str = "a_444_sb128_witness_lr_pipeline_flushes_ru_row_0_pixel_exact";
5919+ const FIXTURE_LEN: usize = 794;
5920+ const FIXTURE_FNV: u64 = 0xf5a7_27f4_3fa7_abc3;
5921+ const W: usize = 192;
5922+ const H: usize = 160;
5923+ const FRAMES: usize = 3;
5924+ /// The inter (pipelinable) frames of the witness; frame 0 is the key
5925+ /// frame and never constructs the pipeline.
5926+ const INTER_FRAMES: u64 = 2;
5927+ let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
5928+ .join("fixtures/444_sb128rect_lr_witness.obu");
5929+ let stream = std::fs::read(&obu).unwrap_or_else(|e| {
5930+ panic!(
5931+ "{NAME}: pinned fixture {} is missing ({e}) -- the gate cannot \
5932+ run, which is a failure, not a skip",
5933+ obu.display()
5934+ )
5935+ });
5936+ assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved");
5937+ assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved");
5938+
5939+ let _guard = lock_gate_counters();
5940+ let serial = decode_stream(&stream)
5941+ .unwrap_or_else(|e| panic!("{NAME}: serial decode failed: {e}"));
5942+ assert_eq!(serial.len(), FRAMES, "{NAME}: frame count");
5943+
5944+ let pipe_before = crate::decode::pipeline_taken_frames();
5945+ let stripe0_before = crate::restoration::lr_stripe0_hits();
5946+ let piped = {
5947+ let _bands = crate::par::override_filter_threads(4);
5948+ decode_stream(&stream)
5949+ .unwrap_or_else(|e| panic!("{NAME}: pipelined decode failed: {e}"))
5950+ };
5951+ assert_eq!(piped.len(), FRAMES, "{NAME}: frame count");
5952+ assert_eq!(
5953+ crate::decode::pipeline_taken_frames() - pipe_before,
5954+ INTER_FRAMES,
5955+ "{NAME}: the filter pipeline did not take both inter frames -- the \
5956+ arm decoded serial and proves nothing (class \
5957+ gate-blind-to-feature)"
5958+ );
5959+ assert!(
5960+ crate::restoration::lr_stripe0_hits() - stripe0_before > 0,
5961+ "{NAME}: no stripe-0 (RU row 0's first stripe) filter ran -- RU row \
5962+ 0 was never restored in this arm (class gate-blind-to-feature)"
5963+ );
5964+
5965+ // The refutation itself: pipeline == serial, byte for byte, on every
5966+ // frame -- including frame 2, the 128-root-rect inter frame the
5967+ // r2 defect named.
5968+ for (i, (s, p)) in serial.iter().zip(piped.iter()).enumerate() {
5969+ for (pl, (a, b)) in
5970+ [(&s.y, &p.y), (&s.u, &p.u), (&s.v, &p.v)].into_iter().enumerate()
5971+ {
5972+ assert_eq!(
5973+ a, b,
5974+ "{NAME}: pipelined frame {i} plane {pl} differs from the \
5975+ whole-frame path (class lr-band-release)"
5976+ );
5977+ }
5978+ }
5979+
5980+ // Frames 0/1 through the PIPELINE, byte-exact vs both oracles.
5981+ if aomdec_path().is_file() {
5982+ let dir = std::env::temp_dir().join(format!("ec-av1-lrflush-{}", std::process::id()));
5983+ let _ = std::fs::remove_dir_all(&dir);
5984+ std::fs::create_dir_all(&dir).expect("scratch dir");
5985+ let raw = dir.join("aomdec.raw");
5986+ let out = Command::new(aomdec_path())
5987+ .args(["--codec=av1", "--rawvideo", "-o"])
5988+ .arg(&raw)
5989+ .arg(&obu)
5990+ .stdin(Stdio::null())
5991+ .stdout(Stdio::piped())
5992+ .stderr(Stdio::piped())
5993+ .output()
5994+ .expect("aomdec failed to run");
5995+ assert!(
5996+ out.status.success(),
5997+ "{NAME}: the oracle aomdec refused the stream: {}",
5998+ String::from_utf8_lossy(&out.stderr)
5999+ );
6000+ let ref_raw = std::fs::read(&raw).expect("aomdec rawvideo output");
6001+ let _ = std::fs::remove_dir_all(&dir);
6002+ assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size");
6003+ for (i, f) in piped.iter().enumerate().take(2) {
6004+ let base = i * W * H * 3;
6005+ for ((plane, off), p) in
6006+ [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)]
6007+ .into_iter()
6008+ .zip(["y", "u", "v"])
6009+ {
6010+ let want = &ref_raw[base + off..base + off + W * H];
6011+ let bad = plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count();
6012+ assert_eq!(
6013+ bad, 0,
6014+ "{NAME}: aomdec frame {i} plane {p} THROUGH THE PIPELINE: \
6015+ {bad} samples differ (class lr-band-release)"
6016+ );
6017+ }
6018+ }
6019+ } else {
6020+ eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display());
6021+ }
6022+ if have_ffmpeg() {
6023+ let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES);
6024+ for (i, (got, want)) in piped.iter().zip(refs.iter()).enumerate().take(2) {
6025+ for (p, (g, r)) in
6026+ [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)]
6027+ .iter()
6028+ .enumerate()
6029+ {
6030+ let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count();
6031+ assert_eq!(
6032+ bad, 0,
6033+ "{NAME}: ffmpeg frame {i} plane {p} THROUGH THE PIPELINE: \
6034+ {bad} samples differ"
6035+ );
6036+ }
6037+ }
6038+ } else {
6039+ eprintln!("SKIP {NAME} ffmpeg arm: no ffmpeg");
6040+ }
6041+ }
6042+
58946043 /// lane-lossless128: a LOSSLESS key frame that codes a 128-axis
58956044 /// (`BLOCK_64X128`) intra block -- the shape libaom's `read_tx_size` forces
58966045 /// to `TX_4X4` on its very first line (`decodeframe.c:1183`), so every plane
lanes/av1lrflush.report.mdadded+105 -0
@@ -0,0 +1,105 @@
1+# lane-av1lrflush — the r2 "RU-row-0 flush" defect REFUTED; f2 residual re-attributed to inter-rect entropy recon; one new threading defect named (r3)
2+
3+## Outcome
4+
5+1. THE NAMED DEFECT DOES NOT EXIST. r2's DEFECT 3 (stop-with-site: "`pipe_run_lr`'s
6+ `rrows: Some` branch refills only caller-passed RU rows, and the
7+ `ls.note(k-2)`/`ls.close(nb, false)` band release never flushes RU row 0 when the
8+ top SB row carries a 128-root rect") is refuted by direct measurement at this HEAD
9+ (48411287, fixture sha256 `27825e14…61e80` verified): with the filter pipeline
10+ engaged (`EC_AV1_FILTER_THREADS=4`, recon serial — `pipe_on=true` on both inter
11+ frames, witnessed by the new unconditional `PIPELINE_TAKEN` counter), the decoded
12+ output is **byte-identical to the whole-frame path on all three frames**, including
13+ frame 2 — the inter frame whose top SB row carries the 128-root rect. The band
14+ release provably flushes RU row 0 (f2 luma is a single RU row `(0,160)`,
15+ unit_size 128, 2 SGR units `ep=11 xqd=[0,73]/[0,72]`; f1's SGR-heavy restoration —
16+ 11754 changed samples — also reproduces exactly through the pipeline).
17+2. r2's stage ladder was misaligned by one stage. Measured at this HEAD with the
18+ pinned fixture and the current oracle (all dumps cross-checked frame-aligned; f0/f1
19+ byte-exact at every stage): frame 2 already diverges at **PREFILT** —
20+ Y 6952 / U 9568 / V 13496 samples — so POSTDEBLOCK/POSTCDEF are NOT byte-exact and
21+ the damage is introduced BEFORE loop restoration. r2's reported "FINAL" diff
22+ (Y 7308 / U 9685 / V 14012) matches today's POSTCDEF diff (Y 7307 / U 9685 /
23+ V 13722) almost sample-for-sample: the r2 comparisons paired our post-CDEF bytes
24+ against the oracle's FINAL and so on, one rung off. The "our final equals
25+ post-CDEF above row 63" reading is likewise stale — our LR actually changed rows
26+ from row 2 (Y) and covers all rows on V; U is `RestorationType::None` on f2 in
27+ BOTH decoders (oracle's U final == oracle's U post-CDEF, 0 rows differ), so the
28+ r2 parser reading (`lr_params` per-plane `f(2)`) is confirmed correct.
29+3. DEFECT A (real f2 residual — NOT this lane's): serial recon diverges at PREFILT
30+ with first diffs **Y (98,128), U (64,128), V (0,128)** — all three planes enter at
31+ column 128, i.e. inside the inter 64x128 block at (128,0), everything downstream
32+ carrying it. Site: the inter rect-strip entropy/recon path — the entropy lane's
33+ assigned territory (Agent044's `decode_rect4_16_strip` inter band stamping; their
34+ independent t6 finding — skipped inter 1:4 strips leaving stale band cells that
35+ flip coefficient contexts — is plausibly this class one size up). STOP per
36+ charter; nothing in the entropy path was touched here.
37+4. DEFECT B (NEW, needs its own lane): the wavefront reconstruction
38+ (`EC_AV1_RECON_THREADS>1`) diverges from the serial decoder at PREFILT on this
39+ fixture's inter frames — **chroma-only write-replay loss**: f1 U 17504 samples
40+ (first (1,0)), V 3 (29,67); f2 U 25472 (first (0,0)), V 1472 (first (128,2)); Y
41+ byte-exact on both frames, and f0 (keyframe) exact everywhere. Serial filters are
42+ unaffected (recon=2/filter=1 still diverges; recon=1/filter=4 is exact), so this
43+ is the wavefront write recording/replay machinery (lane-wave1 class), not the
44+ filter pipeline, not LR, not entropy. Never covered by any gate — every pixel gate
45+ decodes with default threads.
46+5. FIX: nothing to fix in the LR pipeline. What landed instead is the refutation
47+ pinned as a regression gate: `a_444_sb128_witness_lr_pipeline_flushes_ru_row_
48+ 0_pixel_exact` — serial decode vs `override_filter_threads(4)` decode of the same
49+ pinned fixture, asserting (a) `PIPELINE_TAKEN` delta == 2 (the arm really
50+ pipelined both inter frames; robust against the once-per-process
51+ `filter_threads()` env cache that would otherwise silently serialise the arm),
52+ (b) `LR_STRIPE0_HITS` delta > 0 (a real filter ran on RU row 0's own first stripe
53+ through the pipeline), (c) pipelined == serial byte-exact on every frame, and
54+ (d) frames 0/1 byte-exact vs oracle aomdec AND ffmpeg THROUGH the pipeline.
55+ Mutation-verified: hard-disabling the RU-row-0 release in `pipe_run_lr`'s band
56+ walk turns the gate red at assert (c) ("pipelined frame 1 plane 0 differs",
57+ class lr-band-release); reverted, green.
58+6. Gate-extension status for the original acceptance item: extending
59+ `a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact` to assert f2
60+ byte-exact vs aomdec/ffmpeg is **deferred** — f2 is not green and its fix belongs
61+ to the entropy lane (DEFECT A). Unblocks as soon as that fix lands in this
62+ branch's ancestry: change the two `take(2)` arms to `take(3)` in that gate. Its
63+ current scoping comment (naming the LR band release as the residual site) is now
64+ known-stale; left untouched here to keep the lane diff free of another lane's
65+ gate, to be corrected in the same deferred edit.
66+
67+## Verification
68+
69+- `cargo check -p ec-av1`: 0 warnings, 0 errors (target
70+ `$HOME/.cache/cargo-target-av1lrflush`; scoped `rustfmt --check` drift is
71+ repo-wide pre-existing, untouched files fail it identically).
72+- `stream::tests::a_444_sb128_witness_lr_pipeline_flushes_ru_row_0_pixel_exact`: PASS.
73+- `stream::tests::a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact`:
74+ PASS (f0/f1 pins intact).
75+- Restoration battery (`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib
76+ restoration`): 10 passed, 0 failed — includes the 4 real-aomenc gates r2 ran
77+ (`…reads_lr_symbols_correctly`, `…superres_key_frame_with_cdef_and_loop_
78+ restoration…`, `…non_420_subsampled…`, `…skipped_8x8_intra_leaf…`) plus the
79+ 10-bit-stripe and sibling LR gates.
80+- Mutation proof: `pipe_run_lr` band-walk mutated to never release RU row 0 → new
81+ gate FAILED at the pipeline==serial assert; reverted → PASS (red/green cycle in
82+ this lane, target dir reused, rebuild verified by the failure itself).
83+- Stage evidence produced with env-gated dumps on both decoders
84+ (`EC_AV1_PREFILT_DUMP`/`EC_AV1_POSTDEBLOCK_DUMP`/`EC_AV1_POSTCDEF_DUMP`/
85+ `EC_AV1_FINAL_DUMP`, per-frame strided slices, 192x160x3 per frame); all temp
86+ probes and the throwaway example removed before commit.
87+
88+## Decision
89+
90+- LR pipeline: EXONERATED, gate-pinned. No production code changed in
91+ restoration.rs; decode.rs gained only the unconditional `PIPELINE_TAKEN` counter +
92+ accessor (the non-vacuity witness; the wave-stats-gated `PIPE_FRAMES` is not
93+ readable by gates).
94+- DEFECT A: handed to the entropy lane with first-diff coordinates (see Outcome 3);
95+ cross-referenced with Agent044's t6 context-zeroing finding.
96+- DEFECT B: named for a wavefront lane — reproducible 100% (deterministic), chroma
97+ write replay under `EC_AV1_RECON_THREADS>1`; fix owner not this lane.
98+- NOT touched: entropy band stamping / `read_coeffs_rect` / `decode_rect4_16_strip`
99+ (sibling's), the 4:2:0 group-tail chroma SKIP arm (reserved), sub8 rect arm,
100+ leaf8 OOB, wavefront write-replay code.
101+
102+## State
103+
104+- Branch lane-av1-lrflush, commit on top of 48411287 (no push): the gate + the
105+ `PIPELINE_TAKEN` counter + this report.