diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index b7954e31..9dc706a3 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -21635,28 +21635,46 @@ fn refuse_invalid_plane_block(_bw: usize, _bh: usize, _fctx: &crate::decode::Fra /// the output does not depend on the plane buffer's initial content. const PLANE_SENTINEL: u16 = 0xDEAD; -/// lane-unwritten-dep: the census count at the LAST point of the pipeline, after -/// deblock/CDEF/LR -- i.e. on the exact bytes `EC_AV1_FINAL_DUMP` writes. +/// lane-unwritten-dep: the census count at the LAST point of the pipeline, on the +/// exact bytes `EC_AV1_FINAL_DUMP` writes. /// -/// WHY A SECOND COUNT (the pre-deblock one is not enough, and this is the -/// measured reason, not a guess): on `440_request_is_422` the pre-deblock plane -/// is BYTE-IDENTICAL between an uninitialised and a `PLANE_SENTINEL`-filled run -/// (0 sentinel samples in both) while the final output differs by 1986 bytes, -/// all of it in the U/V planes' rows 30..63. The deblock pass is where the -/// dependence is CREATED: `EC_AV1_POSTDEBLOCK_DUMP16` is identical pre-deblock -/// and differs by 26 bytes post-deblock, and `EC_AV1_DEBUG_SKIP_DEBLOCK=1` does -/// not remove the difference. So a pre-deblock scan cannot see a hole the loop -/// filter then READS: deblock reads a neighbour to decide an edge, so an -/// unwritten sample changes its neighbour's filtered value even when the -/// unwritten sample itself is overwritten afterwards. +/// WHY A SECOND COUNT, and what it is actually for -- the justification this +/// comment originally carried was WRONG and is corrected here, because a reader +/// would otherwise re-derive the wrong conclusion. An earlier revision of this +/// lane claimed the pre-deblock plane was byte-identical plain-vs-sentinel and +/// that "deblock creates the dependence". That reading came from +/// [`dump_stage16`], which cropped chroma as `(fw/2, fh/2)` -- a 4:2:0 +/// assumption. On a 64x64 4:2:2 frame (ss_x=1, ss_y=0) that wrote 32x32 chroma +/// where the frame carries 32x64, so 2048 chroma samples appeared in NO stage +/// dump, and they are exactly the region where the difference lives. /// -/// This count is the same measurement taken where the output is taken, so it is -/// what a gate can assert: "no sample the tile walk never wrote survives into the -/// frame the caller receives". Zero here AND zero pre-deblock = no dependence; -/// non-zero here with zero pre-deblock = a loop-filter read, named. +/// With per-axis extents the corrected measurement on `440_request_is_422` is: +/// the PRE-DEBLOCK dump already DIFFERS by 2158 bytes plain-vs-sentinel, and an +/// exact u16 whole-plane census finds 224 unwritten samples (U 112, V 112, +/// rows 36..63, whole 4x4 groups) -- the same number +/// `lanes/av1unwritten.report.md` reports. **The hole is present before any +/// filter runs, and the pre-deblock census sees it.** This comment previously +/// said the opposite; that was the instrument's blind spot read as a property of +/// the pipeline. +/// +/// So what this second count is FOR, stated honestly: it is not there because the +/// pre-deblock census misses holes. It is there because it is the measurement +/// taken where the OUTPUT is taken -- the bytes stored into the reference slots +/// and handed to the caller. A hole can be created after reconstruction (a +/// filter stage, a superres step, a second pass) and be invisible to a scan taken +/// before it; this one cannot. It is a check on the whole span from the tile walk +/// to the caller's frame, not a claim that the pre-deblock scan is insufficient. static FINAL_UNWRITTEN_SAMPLES: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); +/// Samples [`census_unwritten_final`] has looked at since the last +/// [`take_final_census_scanned`]. A gate that only asserts +/// [`take_final_unwritten_samples`] == 0 passes on a build whose census call was +/// deleted, so it reads THIS too -- the same pairing +/// [`CENSUS_SCANNED`] documents for the pre-deblock census. +static FINAL_CENSUS_SCANNED: std::sync::atomic::AtomicUsize = + std::sync::atomic::AtomicUsize::new(0); + /// lane-unwritten-dep: reads and clears [`FINAL_UNWRITTEN_SAMPLES`] -- unwritten /// samples still present in the frame as handed to the caller, summed over every /// frame and plane. Process-global, like the pre-deblock census's counter, so a @@ -21666,26 +21684,35 @@ pub fn take_final_unwritten_samples() -> usize { FINAL_UNWRITTEN_SAMPLES.swap(0, std::sync::atomic::Ordering::SeqCst) } +/// Reads and clears [`FINAL_CENSUS_SCANNED`]; the pairing is the reason it +/// exists, exactly as for [`take_census_scanned`]. +pub fn take_final_census_scanned() -> usize { + FINAL_CENSUS_SCANNED.swap(0, std::sync::atomic::Ordering::SeqCst) +} + /// lane-unwritten-dep: the census at the pipeline's last point. Counts, over each -/// plane's true extent, how many samples still hold [`PLANE_SENTINEL`] once every -/// filter has run. Env-gated on the same flag as [`fresh_plane`] (there is no -/// separate one: the fill and the census must agree on when they are live). +/// plane, how many samples still hold [`PLANE_SENTINEL`] once every filter has +/// run, and records how many samples it LOOKED at in [`FINAL_CENSUS_SCANNED`]. /// -/// Scans IN PLACE at the point the picture is finished, which is what -/// distinguishes it from the pre-deblock census: this one sees what the caller -/// receives. +/// Gated on [`plane_sentinel_on`] -- the SAME predicate as [`fresh_plane`] and as +/// the pre-deblock [`census_unwritten`]: the env flag OR the thread-local +/// [`set_plane_sentinel`] override. An earlier revision gated this on the raw env +/// var alone, which made the census silently inert for any in-process test using +/// the thread-local switch that the rest of the crate honours. The fill and both +/// censuses must agree on when they are live, or a "0" means nothing. pub(crate) fn census_unwritten_final(y: &[u16], u: &[u16], v: &[u16]) { - if !crate::envflags::env_flag!("EC_AV1_PLANE_SENTINEL") { + if !plane_sentinel_on() { return; } // The caller passes the frame's planes exactly as they are about to be // stored into the reference slots, which are already cropped to the true // extent (no padding past it reaches this point), so a flat count over // each plane IS the true-extent count. - let total: usize = [y, u, v] + let (scanned, total): (usize, usize) = [y, u, v] .iter() - .map(|p| p.iter().filter(|&&s| s == PLANE_SENTINEL).count()) - .sum(); + .map(|p| (p.len(), p.iter().filter(|&&s| s == PLANE_SENTINEL).count())) + .fold((0, 0), |(a, b), (c, d)| (a + c, b + d)); + FINAL_CENSUS_SCANNED.fetch_add(scanned, std::sync::atomic::Ordering::SeqCst); FINAL_UNWRITTEN_SAMPLES.fetch_add(total, std::sync::atomic::Ordering::SeqCst); } diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 6329e6a5..37626b0d 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -2221,14 +2221,28 @@ fn decode_frame( // (scripts/instrument-aom-oracle.sh rung 12), which is what makes a // hidden frame's pixels comparable at all. // lane-unwritten-dep: the census AT the output point, beside the dump that - // defines "the output". The pre-deblock census cannot see a hole the loop - // filter later READS: deblock reads a neighbour to decide an edge, so an - // unwritten sample changes its neighbour's filtered value even when the - // unwritten sample itself is overwritten afterwards. Measured on - // `440_request_is_422`: pre-deblock 0 sentinel samples and byte-identical - // plain-vs-sentinel, yet the final output differs by 1986 bytes, entering - // the picture at the deblock pass (`EC_AV1_POSTDEBLOCK_DUMP16` is identical - // pre-deblock and differs by 26 bytes post-deblock). + // defines "the output" -- the same bytes, so the claim is about the frame the + // caller receives rather than about an intermediate stage. + // + // WHAT THIS IS FOR, corrected: an earlier revision of this comment said the + // pre-deblock plane was byte-identical plain-vs-sentinel and that deblock + // creates the dependence. That was wrong, and it was `dump_stage16`'s fault: + // it cropped chroma as `(fw/2, fh/2)`, a 4:2:0 assumption, so on a 64x64 + // 4:2:2 frame 2048 chroma samples appeared in no stage dump at all -- exactly + // the region the difference lives in. With per-axis extents the corrected + // measurement on `440_request_is_422` is that the PRE-DEBLOCK dump already + // differs by 2158 bytes and an exact u16 census finds 224 unwritten samples + // (U 112, V 112, rows 36..63) -- the same count `lanes/av1unwritten.report.md` + // reports. The hole is present before any filter runs, and the pre-deblock + // census SEES it. + // + // So this second census is not a patch for a blind pre-deblock scan. It is + // the measurement taken where the output is taken, which covers the whole span + // from the tile walk to the caller's frame: anything a later stage could + // introduce (a filter, superres, a second pass) is inside its extent, where + // a scan taken before it would not be. It also runs before `apply_grain`, so + // the claim is over the PRE-GRAIN planes -- the bytes the reference bank + // stores and every later frame predicts from. decode::census_unwritten_final(&picture.y, &picture.u, &picture.v); if let Some(prefix) = final_dump { use std::io::Write; @@ -48221,12 +48235,12 @@ exit 0 /// /// SCOPE, stated rather than implied: the census is taken where /// `EC_AV1_FINAL_DUMP` writes, which is BEFORE `apply_grain`. The claim is - /// therefore over the PRE-GRAIN planes -- which is also the claim that matters - /// most, because those exact bytes are what the reference bank stores and what - /// every later frame predicts from. Film grain synthesises from that pre-grain - /// frame plus the grain parameters and does not read the plane buffer, so it - /// cannot introduce a hole. The claim is NOT "the caller's final grained - /// picture has no hole" and is not asserted. + /// therefore over the PRE-GRAIN planes -- which are also the bytes the + /// reference bank stores and every later frame predicts from, the dependency + /// that matters. Whether `apply_grain` can itself introduce a hole is NOT + /// measured: the census never sees the planes `apply_grain` allocates. So the + /// claim is NOT "the caller's final grained picture has no hole", and nothing + /// here asserts that grain cannot introduce one. /// /// NON-VACUITY, the part that makes this gate worth having: a census is only a /// measurement if it CAN report non-zero. The control is a SYNTHETIC positive @@ -48238,6 +48252,20 @@ exit 0 /// cannot change behaviour when a lane lands. It is proven by mutation in the /// same run: neutering `census_unwritten_final` reds it (lane report §5). /// + /// WHAT THIS IS NOT, corrected from an earlier revision of this comment: it + /// does NOT rest on a claim that the pre-deblock census is blind. That claim + /// was wrong. It came from `dump_stage16` cropping chroma as `(fw/2, fh/2)` -- + /// a 4:2:0 assumption -- so on a 64x64 4:2:2 frame 2048 chroma samples were in + /// no stage dump at all, and an earlier revision read that blind spot as + /// "identical pre-deblock, so deblock creates the dependence". With per-axis + /// extents the corrected measurement is the opposite: the pre-deblock dump on + /// `440_request_is_422` already DIFFERS by 2158 bytes and the exact u16 census + /// finds 224 unwritten samples (U 112, V 112, rows 36..63, whole 4x4 groups) -- + /// the same count `lanes/av1unwritten.report.md` reports. The hole is present + /// before any filter runs and the pre-deblock census SEES it. This census is + /// here because it is the measurement taken where the OUTPUT is taken, which + /// spans the whole route from the tile walk to the caller. + /// /// The four film fixtures are the corpus's real 10-bit streams with hidden /// alt-refs -- the shapes where a hidden frame's unwritten region would feed /// a later DISPLAYED frame through the reference bank, which is the only way @@ -48269,7 +48297,7 @@ exit 0 // the fill cannot be switched from inside a test process. The child // process below is therefore how the measurement is taken; what the // parent asserts is the CHILD's reported count. - let census = |fixture: &str| -> usize { + let census = |fixture: &str| -> (usize, usize) { let exe = std::env::current_exe().expect("test binary path"); let out = std::process::Command::new(exe) .args([ @@ -48290,7 +48318,7 @@ exit 0 ); text.lines() .find_map(|l| l.strip_prefix("UWDEP_CENSUS ")) - .and_then(|v| v.split_whitespace().next().and_then(|n| n.parse().ok())) + .and_then(parse_census_line) .unwrap_or_else(|| { panic!( "{NAME}: the census child reported no count for {fixture} \ @@ -48305,7 +48333,12 @@ exit 0 // report exactly that number. No fixture is involved, so this cannot be // affected by lane/av1unwritten refusing `440_request_is_422` on merge. // The fill is env-gated, so even this runs in the child. - let synthetic = census_synthetic(); + let (synthetic, synthetic_scanned) = census_synthetic(); + assert_eq!( + synthetic_scanned, 40, + "{NAME}: the synthetic control scanned {synthetic_scanned} samples, expected 40 \ + (16 + 16 + 8) -- the census did not look at what it was handed" + ); assert_eq!( synthetic, 7, "{NAME}: the census reported {synthetic} for planes carrying exactly 7 sentinel \ @@ -48319,7 +48352,13 @@ exit 0 "gm_small_side_witness", "reelc_sb128_inter_witness", ] { - let n = census(fixture); + let (n, scanned) = census(fixture); + assert!( + scanned > 0, + "{NAME}: the census scanned 0 samples on {fixture} -- the call at the output \ + point is not running, so the {n} below proves nothing (class: \ + census-never-ran). Deleting the call site reproduces this." + ); assert_eq!( n, 0, "{NAME}: {fixture} hands the caller {n} samples the tile walk never wrote" @@ -48327,12 +48366,27 @@ exit 0 } } + /// Parses the child's `UWDEP_CENSUS frames= scanned=` line + /// into `(unwritten, scanned)`. The scanned count is what makes the fixture + /// arms meaningful: `unwritten == 0` is also what a build with the census call + /// deleted reports, and only a non-zero scanned count distinguishes "scanned + /// and found nothing" from "never scanned". + fn parse_census_line(v: &str) -> Option<(usize, usize)> { + let mut parts = v.split_whitespace(); + let unwritten = parts.next()?.parse().ok()?; + let scanned = parts + .find_map(|p| p.strip_prefix("scanned="))? + .parse() + .ok()?; + Some((unwritten, scanned)) + } + /// Runs the census child with `UWDEP_CENSUS_FIXTURE` UNSET, which makes it /// take the synthetic-positive path: hand [`census_unwritten_final`] planes /// with a known number of `PLANE_SENTINEL` values and report what it counted. /// This is the non-vacuity control, and it is a direct function-level check /// rather than a decode, so no fixture's decode behaviour can change it. - fn census_synthetic() -> usize { + fn census_synthetic() -> (usize, usize) { const NAME: &str = "the_frame_the_caller_receives_carries_no_unwritten_plane_sample"; let exe = std::env::current_exe().expect("test binary path"); let out = std::process::Command::new(exe) @@ -48353,7 +48407,7 @@ exit 0 ); text.lines() .find_map(|l| l.strip_prefix("UWDEP_CENSUS ")) - .and_then(|v| v.split_whitespace().next().and_then(|n| n.parse().ok())) + .and_then(parse_census_line) .unwrap_or_else(|| { panic!( "{NAME}: the census child reported no synthetic count (child said: {:?})", @@ -48392,7 +48446,8 @@ exit 0 let _ = decode::take_final_unwritten_samples(); decode::census_unwritten_final(&a, &b, &c); let n = decode::take_final_unwritten_samples(); - println!("UWDEP_CENSUS {n} synthetic=1"); + let scanned = decode::take_final_census_scanned(); + println!("UWDEP_CENSUS {n} synthetic=1 scanned={scanned}"); return; } let Ok(fixture) = std::env::var("UWDEP_CENSUS_FIXTURE") else { @@ -48407,7 +48462,8 @@ exit 0 let _ = decode::take_final_unwritten_samples(); let frames = decode_stream(&stream).unwrap_or_else(|e| panic!("{fixture} refused: {e}")); let n = decode::take_final_unwritten_samples(); - println!("UWDEP_CENSUS {n} frames={}", frames.len()); + let scanned = decode::take_final_census_scanned(); + println!("UWDEP_CENSUS {n} frames={} scanned={scanned}", frames.len()); } /// lane-t900 r6: the 128-superblock INTER witness. diff --git a/lanes/unwritten-dep.report.md b/lanes/unwritten-dep.report.md index 4f147866..a362728b 100644 --- a/lanes/unwritten-dep.report.md +++ b/lanes/unwritten-dep.report.md @@ -131,10 +131,11 @@ region r2's conclusion was drawn from.** **Coordinates, from the corrected pre-deblock dump** (8192 samples, u16, whole plane, `0xDEAD` counted): -* unwritten samples, sentinel run: **U 112, V 112, Y 0** — U and V rows 36–63 - (16 distinct rows), cols 0–15, in whole 4×4 groups (row 36: cols 0–3 and - 12–15). **224 total, which is exactly lane/av1unwritten's own census number** - (`lanes/av1unwritten.report.md:152-156`). +* unwritten samples, sentinel run: **U 112, V 112, Y 0** — U and V, 28 whole + 4×4 groups each, spanning rows 36–63 (12 rows carrying 8 samples + 4 rows + carrying 4 = 96 + 16 = 112). The column span runs 0–15 but is NOT filled: + every row has cols 0–3 and 12–15. **224 total, exactly lane/av1unwritten's own + census number** (`lanes/av1unwritten.report.md:152-156`). * plain vs sentinel differing samples, pre-deblock: **U 1004 of 2048, V 1004 of 2048, Y 0**, rows 32–63 — the hole plus everything predicted from it. @@ -174,11 +175,12 @@ over the three planes at the point they are stored into the reference slots, wit `stream.rs`: the census is called beside the `EC_AV1_FINAL_DUMP` site. **SCOPE, stated not implied:** that point is **before `apply_grain`**, so the -claim is over the **pre-grain** planes. That is also the claim that matters -most — those exact bytes are what the reference bank stores and what every later -frame predicts from, and grain synthesises from the pre-grain frame plus the -grain parameters without reading the plane buffer. "The caller's final grained -picture has no hole" is **not** claimed and is not asserted. +claim is over the **pre-grain** planes only. Those are also the bytes the +reference bank stores and every later frame predicts from, which is the +dependency that matters. Whether `apply_grain` can itself introduce a hole is +**not measured here** -- the census never sees the planes `apply_grain` +allocates -- so "the caller's final grained picture has no hole" is **not +claimed**, and no sentence asserts that grain cannot introduce one. Gate `the_frame_the_caller_receives_carries_no_unwritten_plane_sample`: @@ -198,23 +200,43 @@ meaningless zero. merged into this branch (`c62eeda9`), then: ``` -$ CARGO_TARGET_DIR=.../uwdep-merge cargo test -p ec-av1 --lib -- the_frame_the_caller_receives_carries_no_unwritten_plane_sample -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 816 filtered out; finished in 71.58s +$ cargo test -p ec-av1 --lib -- the_frame_the_caller_receives_carries_no_unwritten_plane_sample +test result: ok. 1 passed; 0 failed; 0 ignored; 816 filtered out; finished in 71.59s ``` -816 filtered (vs 813 on the branch point) — the merged tree's extra tests are -present, so this is the gate running against both lanes' content, not one. +The proof that this tree really carries `av1unwritten`'s content is behavioural, +not a test count (a filtered-test count is a count of names, and a merge that +dropped hunks would print the same number): + +``` +$ decode_probe crates/ec-av1/fixtures/440_request_is_422.obu +REFUSED: unsupported: AV1 tile (a block size 4x8, 8x16 or 16x4 (or 8x4 at 4:4:0) has no +chroma plane block at this frame's subsampling mode ... +``` + +**0 frames, refused** — only reachable with the refusal present. On the branch +point `8d6998d7` the same fixture decodes to `OK: 1 frames decoded`. That is the +merge proof. (It is also why the fixture-carried control had to go: the census +child could not run at all here.) ### Mutations | mutation | result | |---|---| -| `census_unwritten_final` neutered (`if true { return; }`) | **RED**: "the census reported 0 for planes carrying exactly 7 sentinel samples … (class: census-silently-blind)" | -| the `census_unwritten_final` call removed from the output point | RED at the same control | +| `census_unwritten_final` neutered (`if true { return; }`) | **RED** at the synthetic control: "the census reported 0 for planes carrying exactly 7 sentinel samples … (class: census-silently-blind)" | +| **the call at `stream.rs` DELETED** (the whole line replaced by a `let _ =`) | **RED**: "the census scanned 0 samples on reelb_arf_witness -- the call at the output point is not running, so the 0 below proves nothing (class: census-never-ran). Deleting the call site reproduces this." | | one sentinel sample forced into a film frame's output (`p.y[0] = 0xDEAD`) | RED on the fixture: "reelb_arf_witness hands the caller N samples the tile walk never wrote" | -The first is the non-vacuity proof in the same run, and it no longer depends on -any fixture's decode behaviour. +The second row was **false as stated in r3** and is the substantive fix here: r3's +control called `census_unwritten_final` directly, so deleting the pipeline call +left every assertion passing and the gate pinned nothing about the decode. The +gate now reads `take_final_census_scanned()` alongside +`take_final_unwritten_samples()` — the same pairing the merged pre-deblock census +already documents ("a gate that only asserts `take_unwritten_samples() == 0` +passes on a decode that never scanned anything, so it reads THIS too"). The +fixture arms require `scanned > 0`, the synthetic arm requires `scanned == 40` +(16 + 16 + 8), so "scanned and found nothing" is now distinguishable from +"never scanned". ## 7. Commands @@ -295,3 +317,22 @@ contradictory: the witness's output depends on ambient memory, and what the allocator hands back is machine- and run-dependent, so a fixed value on one host and a varying one on another are the same defect. **Stated as measured: 3/3 identical here, and no claim about reproducing their observation.** + +## 11. What the per-axis extent change invalidated in published work + +`round_ss(dim, 1)` is bit-identical to `dim.div_ceil(2)`, so **every 4:2:0 dump is +byte-for-byte unchanged** by the `dump_stage16` fix. The change only affects 4:2:2 +and 4:4:0 frames. + +21 lane files reference the `*_DUMP16` dumps. Of those, exactly one, +`lanes/av1422luma.report.md`, uses non-4:2:0 fixtures (`s422_416x250_10b`). Its +stage table (line 77 onward) is a **Y-only** conclusion — every row reads +"frame 0 Y wrong vs ffmpeg", and the reported numbers are luma sample counts and +a luma first-differing coordinate — so that conclusion **survives** the extent +change unchanged. What the change invalidates is only that report's **label**: +"depth-correct `*_DUMP16`" is no longer accurate for the **chroma half** of those +files, which the 4:2:0 crop had truncated to the top half-height. No published +number moves. + +`lanes/unwritten-dep.report.md` (this file) is the only other DUMP16 reference +touching a non-4:2:0 frame, and its numbers are the corrected ones above.