forge
Explore
Log in

Don't you dare go Hollow

Merge d3d3e45e (lrflush) — suite green: lrflush 629/0

Browse files at this commit

a708fe5b6d8b2428be6241529494d5e1626f01c7Ahmet Kaan GümüşParent: 133df114c11025
crates/ec-av1/src/decode.rsmodified+42 -0
@@ -25137,6 +25137,16 @@ fn pipe_run_lr(
2513725137 if lp.next == r_lo {
2513825138 continue;
2513925139 }
25140+ if r_lo == 0 {
25141+ // lane-av1lrflush: RU row 0 just entered this plane's
25142+ // processed range -- the band release flushed the frame's
25143+ // first restoration row through the pipeline. Process-global
25144+ // (not a `thread_local!` gate counter): the witnessing gate
25145+ // decodes on its own thread while this bump fires on a
25146+ // filter-pool worker, and frame 0's whole-frame LR runs on
25147+ // the gate's thread and must not satisfy the delta.
25148+ LR_PIPELINE_ROW0.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
25149+ }
2514025150 let (src, deb) = match lp.p {
2514125151 0 => (&y.data, &sy2.data),
2514225152 1 => (&u.data, &su2.data),
@@ -25262,6 +25272,32 @@ fn wave_rows_complete(fctx: &crate::decode::FrameCtx) -> usize {
2526225272 static PIPE_FRAMES: AtomicU64 = AtomicU64::new(0);
2526325273 static PIPE_WHOLE: AtomicU64 = AtomicU64::new(0);
2526425274
25275+/// lane-av1lrflush: frames that CONSTRUCTED the filter pipeline, counted
25276+/// unconditionally. Read by gates through [`pipeline_taken_frames`] as a
25277+/// before/after delta -- the non-vacuity witness that a "pipelined" gate arm
25278+/// really ran `pipe_run`/`pipe_run_lr` rather than silently falling back to
25279+/// the whole-frame path.
25280+static PIPELINE_TAKEN: AtomicU64 = AtomicU64::new(0);
25281+
25282+/// Current value of [`PIPELINE_TAKEN`], for a gate's own before/after delta.
25283+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
25284+pub(crate) fn pipeline_taken_frames() -> u64 {
25285+ PIPELINE_TAKEN.load(std::sync::atomic::Ordering::Relaxed)
25286+}
25287+
25288+/// lane-av1lrflush: RU-row-0 flushes the pipeline actually performed, one per
25289+/// LR-active plane whose first restoration unit row enters `pipe_run_lr`'s
25290+/// processed range. Process-global on purpose -- the filter-pool worker bumps
25291+/// it, the gate's thread reads it -- unlike the `thread_local!` gate counters,
25292+/// which a gate's own thread can satisfy from the whole-frame path alone.
25293+static LR_PIPELINE_ROW0: AtomicU64 = AtomicU64::new(0);
25294+
25295+/// Current value of [`LR_PIPELINE_ROW0`], for a gate's before/after delta.
25296+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
25297+pub(crate) fn lr_pipeline_row0_flushes() -> u64 {
25298+ LR_PIPELINE_ROW0.load(std::sync::atomic::Ordering::Relaxed)
25299+}
25300+
2526525301 /// Whether this frame's filters may run per superblock row. Everything that
2526625302 /// reads the picture out of band order, or the pipeline's own inputs out of
2526725303 /// row order, keeps the whole-frame path: superres (a between-CDEF-and-LR
@@ -39933,6 +39969,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
3993339969 let snap_on = pipe_on && (cdef_on || lr_active);
3993439970 let mut pipe_snap = snap_on.then(|| (snap_alloc(&y), snap_alloc(&u), snap_alloc(&v)));
3993539971 let mut pipe = pipe_on.then(|| {
39972+ // lane-av1lrflush: counted unconditionally (unlike `PIPE_FRAMES`
39973+ // below, which is `EC_AV1_WAVE_STATS`-gated) so a gate can prove a
39974+ // pipelined arm actually took the pipeline even when
39975+ // `filter_threads()`'s once-per-process env read was already cached
39976+ // by an earlier test in the same binary.
39977+ PIPELINE_TAKEN.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
3993639978 if wave_stats() {
3993739979 PIPE_FRAMES.fetch_add(1, Relaxed);
3993839980 }
crates/ec-av1/src/stream.rsmodified+159 -0
@@ -5890,6 +5890,165 @@ pub(crate) mod tests {
58905890 }
58915891 }
58925892
5893+ /// lane-av1lrflush: the pipelined loop-restoration band release flushes
5894+ /// RU row 0 on the inter frame whose top superblock row carries a
5895+ /// 128-root rect -- the exact shape lanes/av1444sb.report.md r2 named as
5896+ /// its stop-with-site DEFECT 3 ("`pipe_run_lr`'s `rrows` branch plus the
5897+ /// `ls.note`/`ls.close` band release never flushes RU row 0 on frame 2").
5898+ /// r3 REFUTED that defect by measurement: on this fixture the filter
5899+ /// pipeline (deblock/CDEF/LR band workers over `ls.note` releases)
5900+ /// produces output byte-identical to the whole-frame path on every frame
5901+ /// -- this gate pins that refutation so a future band-accounting
5902+ /// regression on a 128-root-rect inter frame cannot land silently.
5903+ ///
5904+ /// Non-vacuity, twice over: the `PIPELINE_TAKEN` delta proves the second
5905+ /// decode really constructed the pipeline on both inter frames (frame 0
5906+ /// is a key frame and the key-frame path runs whole-frame filters by
5907+ /// construction), and the `LR_PIPELINE_ROW0` delta proves the pipeline's
5908+ /// band release itself flushed RU row 0 -- a process-global counter
5909+ /// bumped by `pipe_run_lr`'s worker, so frame 0's whole-frame LR (which
5910+ /// runs on the gate's own thread and satisfies the thread-local
5911+ /// `LR_STRIPE0_HITS`) cannot fake it. Frames 0/1 are additionally asserted
5912+ /// byte-exact against BOTH the oracle aomdec and ffmpeg THROUGH the
5913+ /// pipeline. (Frame 2's own residual is the entropy lane's inter
5914+ /// rect-strip recon defect -- see lanes/av1lrflush.report.md r3 -- and
5915+ /// is identical on the serial and pipelined runs, so the pipeline
5916+ /// equality covers it without pinning its wrong samples.)
5917+ #[test]
5918+ fn a_444_sb128_witness_lr_pipeline_flushes_ru_row_0_pixel_exact() {
5919+ const NAME: &str = "a_444_sb128_witness_lr_pipeline_flushes_ru_row_0_pixel_exact";
5920+ const FIXTURE_LEN: usize = 794;
5921+ const FIXTURE_FNV: u64 = 0xf5a7_27f4_3fa7_abc3;
5922+ const W: usize = 192;
5923+ const H: usize = 160;
5924+ const FRAMES: usize = 3;
5925+ /// The inter (pipelinable) frames of the witness; frame 0 is the key
5926+ /// frame and never constructs the pipeline.
5927+ const INTER_FRAMES: u64 = 2;
5928+ let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
5929+ .join("fixtures/444_sb128rect_lr_witness.obu");
5930+ let stream = std::fs::read(&obu).unwrap_or_else(|e| {
5931+ panic!(
5932+ "{NAME}: pinned fixture {} is missing ({e}) -- the gate cannot \
5933+ run, which is a failure, not a skip",
5934+ obu.display()
5935+ )
5936+ });
5937+ assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved");
5938+ assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved");
5939+
5940+ let _guard = lock_gate_counters();
5941+ let serial = decode_stream(&stream)
5942+ .unwrap_or_else(|e| panic!("{NAME}: serial decode failed: {e}"));
5943+ assert_eq!(serial.len(), FRAMES, "{NAME}: frame count");
5944+
5945+ let pipe_before = crate::decode::pipeline_taken_frames();
5946+ let row0_before = crate::decode::lr_pipeline_row0_flushes();
5947+ let piped = {
5948+ let _bands = crate::par::override_filter_threads(4);
5949+ decode_stream(&stream)
5950+ .unwrap_or_else(|e| panic!("{NAME}: pipelined decode failed: {e}"))
5951+ };
5952+ assert_eq!(piped.len(), FRAMES, "{NAME}: frame count");
5953+ assert_eq!(
5954+ crate::decode::pipeline_taken_frames() - pipe_before,
5955+ INTER_FRAMES,
5956+ "{NAME}: the filter pipeline did not take both inter frames -- the \
5957+ arm decoded serial and proves nothing (class \
5958+ gate-blind-to-feature)"
5959+ );
5960+ // f1 restores all three planes, f2 all but U -> 3 + 2 row-0 flushes.
5961+ // `LR_PIPELINE_ROW0` is process-global and bumped by the pipeline's
5962+ // own worker, so this delta cannot be satisfied by frame 0's
5963+ // whole-frame LR (which runs on this test's thread and never touches
5964+ // the counter).
5965+ assert_eq!(
5966+ crate::decode::lr_pipeline_row0_flushes() - row0_before,
5967+ 5,
5968+ "{NAME}: the pipeline never flushed RU row 0 ({} planes' worth \
5969+ expected) -- the named defect class is present (class \
5970+ lr-band-release)",
5971+ 5
5972+ );
5973+
5974+ // The refutation itself: pipeline == serial, byte for byte, on every
5975+ // frame -- including frame 2, the 128-root-rect inter frame the
5976+ // r2 defect named.
5977+ for (i, (s, p)) in serial.iter().zip(piped.iter()).enumerate() {
5978+ for (pl, (a, b)) in
5979+ [(&s.y, &p.y), (&s.u, &p.u), (&s.v, &p.v)].into_iter().enumerate()
5980+ {
5981+ assert_eq!(
5982+ a, b,
5983+ "{NAME}: pipelined frame {i} plane {pl} differs from the \
5984+ whole-frame path (class lr-band-release)"
5985+ );
5986+ }
5987+ }
5988+
5989+ // Frames 0/1 through the PIPELINE, byte-exact vs both oracles.
5990+ if aomdec_path().is_file() {
5991+ let dir = std::env::temp_dir().join(format!("ec-av1-lrflush-{}", std::process::id()));
5992+ let _ = std::fs::remove_dir_all(&dir);
5993+ std::fs::create_dir_all(&dir).expect("scratch dir");
5994+ let raw = dir.join("aomdec.raw");
5995+ let out = Command::new(aomdec_path())
5996+ .args(["--codec=av1", "--rawvideo", "-o"])
5997+ .arg(&raw)
5998+ .arg(&obu)
5999+ .stdin(Stdio::null())
6000+ .stdout(Stdio::piped())
6001+ .stderr(Stdio::piped())
6002+ .output()
6003+ .expect("aomdec failed to run");
6004+ assert!(
6005+ out.status.success(),
6006+ "{NAME}: the oracle aomdec refused the stream: {}",
6007+ String::from_utf8_lossy(&out.stderr)
6008+ );
6009+ let ref_raw = std::fs::read(&raw).expect("aomdec rawvideo output");
6010+ let _ = std::fs::remove_dir_all(&dir);
6011+ assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size");
6012+ for (i, f) in piped.iter().enumerate().take(2) {
6013+ let base = i * W * H * 3;
6014+ for ((plane, off), p) in
6015+ [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)]
6016+ .into_iter()
6017+ .zip(["y", "u", "v"])
6018+ {
6019+ let want = &ref_raw[base + off..base + off + W * H];
6020+ let bad = plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count();
6021+ assert_eq!(
6022+ bad, 0,
6023+ "{NAME}: aomdec frame {i} plane {p} THROUGH THE PIPELINE: \
6024+ {bad} samples differ (class lr-band-release)"
6025+ );
6026+ }
6027+ }
6028+ } else {
6029+ eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display());
6030+ }
6031+ if have_ffmpeg() {
6032+ let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES);
6033+ for (i, (got, want)) in piped.iter().zip(refs.iter()).enumerate().take(2) {
6034+ for (p, (g, r)) in
6035+ [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)]
6036+ .iter()
6037+ .enumerate()
6038+ {
6039+ let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count();
6040+ assert_eq!(
6041+ bad, 0,
6042+ "{NAME}: ffmpeg frame {i} plane {p} THROUGH THE PIPELINE: \
6043+ {bad} samples differ"
6044+ );
6045+ }
6046+ }
6047+ } else {
6048+ eprintln!("SKIP {NAME} ffmpeg arm: no ffmpeg");
6049+ }
6050+ }
6051+
58936052 /// lane-lossless128: a LOSSLESS key frame that codes a 128-axis
58946053 /// (`BLOCK_64X128`) intra block -- the shape libaom's `read_tx_size` forces
58956054 /// to `TX_4X4` on its very first line (`decodeframe.c:1183`), so every plane
lanes/av1lrflush.report.mdadded+110 -0
@@ -0,0 +1,110 @@
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_PIPELINE_ROW0` delta == 5 (f1 restores all three planes, f2 all but U:
53+ the pipeline's band release flushed RU row 0 that many times), (c) pipelined ==
54+ serial byte-exact on every frame, and (d) frames 0/1 byte-exact vs oracle
55+ aomdec AND ffmpeg THROUGH the pipeline. r4 review hole, fixed: the original (b)
56+ used the thread-local `LR_STRIPE0_HITS`, which the gate's own thread can
57+ satisfy from frame 0's whole-frame LR alone — vacuous as a pipeline witness;
58+ the replacement is a process-global counter bumped by `pipe_run_lr`'s
59+ filter-pool worker itself, so only a real pipeline row-0 flush can move it.
60+ Mutation-verified: hard-disabling the RU-row-0 release in `pipe_run_lr`'s
61+ band walk turns the gate red (row-0 delta 0 and "pipelined frame 1 plane 0
62+ differs", class lr-band-release); reverted, green.
63+6. Gate-extension status for the original acceptance item: extending
64+ `a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact` to assert f2
65+ byte-exact vs aomdec/ffmpeg is **deferred** — f2 is not green and its fix belongs
66+ to the entropy lane (DEFECT A). Unblocks as soon as that fix lands in this
67+ branch's ancestry: change the two `take(2)` arms to `take(3)` in that gate. Its
68+ current scoping comment (naming the LR band release as the residual site) is now
69+ known-stale; left untouched here to keep the lane diff free of another lane's
70+ gate, to be corrected in the same deferred edit.
71+
72+## Verification
73+
74+- `cargo check -p ec-av1`: 0 warnings, 0 errors (target
75+ `$HOME/.cache/cargo-target-av1lrflush`; scoped `rustfmt --check` drift is
76+ repo-wide pre-existing, untouched files fail it identically).
77+- `stream::tests::a_444_sb128_witness_lr_pipeline_flushes_ru_row_0_pixel_exact`: PASS.
78+- `stream::tests::a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact`:
79+ PASS (f0/f1 pins intact).
80+- Restoration battery (`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib
81+ restoration`): 10 passed, 0 failed — includes the 4 real-aomenc gates r2 ran
82+ (`…reads_lr_symbols_correctly`, `…superres_key_frame_with_cdef_and_loop_
83+ restoration…`, `…non_420_subsampled…`, `…skipped_8x8_intra_leaf…`) plus the
84+ 10-bit-stripe and sibling LR gates.
85+- Mutation proof: `pipe_run_lr` band-walk mutated to never release RU row 0 → new
86+ gate FAILED at the pipeline==serial assert; reverted → PASS (red/green cycle in
87+ this lane, target dir reused, rebuild verified by the failure itself).
88+- Stage evidence produced with env-gated dumps on both decoders
89+ (`EC_AV1_PREFILT_DUMP`/`EC_AV1_POSTDEBLOCK_DUMP`/`EC_AV1_POSTCDEF_DUMP`/
90+ `EC_AV1_FINAL_DUMP`, per-frame strided slices, 192x160x3 per frame); all temp
91+ probes and the throwaway example removed before commit.
92+
93+## Decision
94+
95+- LR pipeline: EXONERATED, gate-pinned. No production code changed in
96+ restoration.rs; decode.rs gained only the unconditional `PIPELINE_TAKEN` counter +
97+ accessor (the non-vacuity witness; the wave-stats-gated `PIPE_FRAMES` is not
98+ readable by gates).
99+- DEFECT A: handed to the entropy lane with first-diff coordinates (see Outcome 3);
100+ cross-referenced with Agent044's t6 context-zeroing finding.
101+- DEFECT B: named for a wavefront lane — reproducible 100% (deterministic), chroma
102+ write replay under `EC_AV1_RECON_THREADS>1`; fix owner not this lane.
103+- NOT touched: entropy band stamping / `read_coeffs_rect` / `decode_rect4_16_strip`
104+ (sibling's), the 4:2:0 group-tail chroma SKIP arm (reserved), sub8 rect arm,
105+ leaf8 OOB, wavefront write-replay code.
106+
107+## State
108+
109+- Branch lane-av1-lrflush, commit on top of 48411287 (no push): the gate + the
110+ `PIPELINE_TAKEN` counter + this report.