diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 104ae632..a4838a3b 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -24511,30 +24511,40 @@ thread_local! { /// of them, so this reads 0 on any stream that never codes one -- the /// non-vacuity anchor for the replay's own gate. pub(crate) static SB128RECT_CHROMA_REPLAY_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; - /// ... and the number of non-skip 128-root rect BLOCKS whose replay - /// height differs from the unit's own LUMA-MI height -- the signature of the - /// width passed to both axes (`luma_span` where the in-loop stamp used - /// `luma_span_h`). lane-av1422lift: the doc here used to read "Zero on - /// every stream this decoder admits ... 4:2:2 ... is refused by name at - /// the sequence header", and that was TRUE. Admitting 4:2:2 genuinely made - /// this counter able to fire, and it does fire: measured on this branch's - /// tip over all 21 committed 4:2:2 cells, `422_intrabc_sb128_strip.obu` - /// and `422_intrabc_sb128_strip_notxsearch.obu` each read - /// `replay = 72, mismatch = 9`; the other 19 read 0. + /// ... and the number of non-skip 128-root rect BLOCKS whose two LUMA-MI + /// spans differ (`luma_span = chroma_tx << ss_x` vs + /// `luma_span_h = chroma_tx << ss_y`). lane-av1422lift: the doc here used + /// to read "Zero on every stream this decoder admits ... 4:2:2 ... is + /// refused by name at the sequence header", and that was TRUE. Admitting + /// 4:2:2 genuinely made this counter able to fire, and it does fire: + /// measured, `422_intrabc_sb128_strip.obu` and + /// `422_intrabc_sb128_strip_notxsearch.obu` each read + /// `replay = 72, mismatch = 9`; the other 19 committed 4:2:2 cells read 0. /// - /// **Those two pins are byte-exact against ffmpeg** - /// (`the_pinned_422_intrabc_sb128_strip_witnesses_decode_pixel_exact`, all - /// five frames, every plane), so a non-zero mismatch is NOT a defect - /// signature at 4:2:2 -- it is the arm counting its own designed case. - /// Nothing here asserts zero, and nothing should: adding a zero assert - /// would red a gate on a cell that is provably correct. + /// lane-av1422mismatch9: the predicate is the span DIFFERENCE, which at + /// ss (1, 0) is true BY CONSTRUCTION for every 128-root rect block -- so + /// this is a shape test ("a 4:2:2-shaped block replayed"), NOT a + /// divergence test, and it does not witness the lane-av1-128rectspan + /// defect it was named for (that defect passed `luma_span` to both axes; + /// the source-scan arm in + /// `the_422_block_128rect_chroma_chunk_gather_stays_per_axis` is what + /// pins the per-axis spelling). It is not a pixel-miss signature either: + /// the replay re-stamps with the same per-axis pair the in-loop walk + /// stamped with, and `record_mi_chroma` writes only the `left`/`above` + /// context arrays -- zero pixel samples. Both pins are byte-exact against + /// ffmpeg (`the_pinned_422_intrabc_sb128_strip_witnesses_decode_pixel_ + /// exact`, all five frames, every plane). /// - /// The only readers of the pair are - /// [`sb128rect_chroma_replay_hits`]'s two gates, both on 4:4:4 and 4:2:0 - /// streams, where the unit's luma width and height are equal so the - /// mismatch half is structurally zero. That is the zero this counter is - /// currently a tripwire FOR, and it is a statement about those two - /// streams, not about the format. + /// **Nothing asserts zero here, and nothing should**: a zero assert would + /// red on a provably correct cell. The measured NINE is asserted instead, + /// in `the_422_block_128rect_chroma_chunk_gather_stays_per_axis` (with + /// this reasoning in its message), so a change in the count is a red gate + /// rather than a silent drift. + /// + /// The pair's other reader is `sb128rect_chroma_replay_hits` on a 4:4:4 + /// stream, where the unit's luma width and height are equal so the + /// mismatch half is structurally zero -- a zero that is a statement about + /// that stream, not about the format. pub(crate) static SB128RECT_REPLAY_SPAN_MISMATCH_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; } diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index a2b78d82..31765e82 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -326,8 +326,15 @@ pub fn intra128_lossless_counters() -> usize { /// `422_intrabc_sb128_strip*` pins each read `(72, 9)` while the other 19 /// committed 4:2:2 cells read `(0, 0)`. Those two pins are byte-exact /// against ffmpeg, so the non-zero half counts the arm's own designed case -/// and is not a defect. No 4:2:2 gate reads this pair; the two gates that do -/// are on 4:2:0 and 4:4:4 streams, where the half is structurally zero. +/// and is not a defect. lane-av1422mismatch9: the predicate is +/// `luma_span != luma_span_h` (`chroma_tx << ss_x` vs `<< ss_y`), true by +/// CONSTRUCTION at ss (1,0), and the replay re-stamps with the same per-axis +/// pair the in-loop walk used, so the counter is a 4:2:2 shape test, not a +/// divergence test (`record_mi_chroma` writes only the left/above context +/// arrays, never a pixel). One 4:2:2 gate now reads the pair and asserts the +/// measured `(72, 9)`: +/// `the_422_block_128rect_chroma_chunk_gather_stays_per_axis`; the other +/// reader is on a 4:4:4 stream, where the mismatch half is structurally zero. pub fn sb128rect_chroma_replay_counters() -> (usize, usize) { crate::decode::sb128rect_chroma_replay_hits() } @@ -3695,6 +3702,13 @@ pub(crate) mod tests { /// against ffmpeg, exactly as the pre-change tree was (the gathered /// votes cancel at every reached unit), so THIS gate -- not a pixel /// compare -- is what stops the routing being reverted. + /// + /// lane-av1422mismatch9: the same decode loop now also asserts the + /// `SB128RECT_REPLAY_SPAN_MISMATCH_HITS` count (NINE per pin) and states + /// why it is not a pixel miss -- the counter's predicate is a span + /// DIFFERENCE, true by construction at ss (1,0); the replay re-stamps the + /// identical context cells with the same per-axis pair the read walk used; + /// and `record_mi_chroma` writes no pixel sample. See the assert's message. #[test] fn the_422_block_128rect_chroma_chunk_gather_stays_per_axis() { const NAME: &str = "the_422_block_128rect_chroma_chunk_gather_stays_per_axis"; @@ -3766,18 +3780,58 @@ pub(crate) mod tests { assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted"); assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted"); let _guard = lock_gate_counters(); - let before = crate::decode::sb128rect_chroma_replay_hits().0; + let before = crate::decode::sb128rect_chroma_replay_hits(); let frames = decode_stream(&data) .unwrap_or_else(|e| panic!("{NAME}: {file} no longer decodes cleanly: {e}")); - let after = crate::decode::sb128rect_chroma_replay_hits().0; + let after = crate::decode::sb128rect_chroma_replay_hits(); assert_eq!( - after - before, + after.0 - before.0, 72, "{NAME}: {file} gathered {} chroma unit context(s) in \ decode_block_128rect's per-chunk walk; 72 were measured at ss (1, 0) -- \ a lower number means the gather is no longer REACHED here \ (class gate-blind-to-feature)", - after - before + after.0 - before.0 + ); + // lane-av1422mismatch9: `SB128RECT_REPLAY_SPAN_MISMATCH_HITS` reads + // NINE on each of these two pins, and this is the only place that + // number is asserted. It is NOT a pixel miss, and the three facts + // below are why -- the assert encodes the measurement, not a wish: + // + // 1. The predicate (`decode.rs`, end of `decode_block_128rect`) is + // `luma_span != luma_span_h` -- `chroma_tx << ss_x` vs + // `chroma_tx << ss_y`. At ss (1, 0) the two DIFFER BY + // CONSTRUCTION for every 128-root rect block, so the counter is + // a shape test ("this is the 4:2:2 span shape"), not a + // divergence test. Nine is the number of such blocks the five + // frames code. + // 2. The replay re-stamps with the SAME per-axis pair the in-loop + // walk stamped with (`record_mi_chroma(cu_mi, luma_span, + // luma_span_h, ...)` at both the read walk and the replay), so + // it rewrites the identical context cells -- this is exactly + // the `record_mi_chroma(cu_mi, luma_span, luma_span_h)` pairing + // the source-scan arm above pins. The pre-lane-av1-128rectspan + // defect (width passed on both axes) is caught by that + // spelling arm, not by this counter. + // 3. `record_mi_chroma` writes only `Neighbours::left`/`above` + // (entropy-context arrays); it touches ZERO pixel samples. So + // the 9 events cannot write a sample the oracle lacks. The + // pixel proof is the same file's + // `the_pinned_422_intrabc_sb128_strip_witnesses_decode_pixel_ + // exact`, which pins all five frames byte-exact against + // ffmpeg's `yuv422p` rawvideo. + // + // Change this expected count ONLY with a new measurement; a 4:2:2 + // stream coding more 128-root rect blocks legitimately changes it. + assert_eq!( + after.1 - before.1, + 9, + "{NAME}: {file} fired the 4:2:2 span-shape arm {} time(s); NINE were \ + measured and are NOT a pixel miss (the predicate is `luma_span != \ + luma_span_h`, true by construction at ss (1,0); the replay re-stamps the \ + identical context cells with the same per-axis pair; `record_mi_chroma` \ + writes no pixel) -- see the report above", + after.1 - before.1 ); assert_eq!(frames.len(), 5, "{NAME}: {file} frame count"); } diff --git a/lanes/av1422mismatch9.report.md b/lanes/av1422mismatch9.report.md new file mode 100644 index 00000000..6201d71f --- /dev/null +++ b/lanes/av1422mismatch9.report.md @@ -0,0 +1,129 @@ +# lane-av1422mismatch9 — the 9 on `SB128RECT_REPLAY_SPAN_MISMATCH_HITS` + +Base `main` @ `42b230c4`. Branch `lane/av1422mismatch9`. + +**Verdict: not a pixel miss, asserted.** + +`lanes/av1422gather3.report.md` recorded that +`SB128RECT_REPLAY_SPAN_MISMATCH_HITS` reads **9** on each of the two pinned +`422_intrabc_sb128_strip*.obu` cells while those cells are byte-exact against +ffmpeg, and that nothing asserted the 9 and nothing explained it. Both are now +settled. + +## 1. What the increment compares + +`decode_block_128rect`'s end-of-block chroma replay +(`crates/ec-av1/src/decode.rs`, the `for (plane, cu_mi, grid) in &units` loop at +the tail of the `else` branch): + +```rust +let luma_span = chroma_tx << ss_x(fctx); // 64 at ss (1,0), chroma_tx 32 +let luma_span_h = chroma_tx << ss_y(fctx); // 32 at ss (1,0) +... +if luma_span != luma_span_h { hit!(SB128RECT_REPLAY_SPAN_MISMATCH_HITS); } +for (plane, cu_mi, grid) in &units { + neighbours.record_mi_chroma(*cu_mi, luma_span, luma_span_h, *plane, grid); + hit!(SB128RECT_CHROMA_REPLAY_HITS); +} +``` + +The two spans are the unit's LUMA extent on each axis: **width** +`chroma_tx << ss_x` and **height** `chroma_tx << ss_y`, both in luma pixels. +The counter fires when they differ. + +## 2. The measured count + +Ran `the_422_block_128rect_chroma_chunk_gather_stays_per_axis` on both pins +(build `42b230c4` + this change, `CARGO_TARGET_DIR` own dir): + +| pin | size | fnv1a64 | replay (`.0`) | mismatch (`.1`) | +|---|---|---|---|---| +| `422_intrabc_sb128_strip.obu` | 1672 | `0x50f5cfc576e4cd00` | **72** | **9** | +| `422_intrabc_sb128_strip_notxsearch.obu` | 1675 | `0xd4936f252ff8cff0` | **72** | **9** | + +Confirmed: **9 per pin**, and `72 = 9 x 8` — each of the nine blocks replayed +eight chroma units. The counting reader now asserts `72` and `9` per pin. + +## 3. Not a pixel miss — one dumped unit + +A temporary env-gated trace at the replay site (removed before commit) dumped +every replayed unit's `(plane, cu_mi, span_w, span_h)` on both pins: +**144 lines, all `wh=(64,32)`**, distinct coords `plane ∈ {1,2}` x +`cu_mi.1 ∈ {0,16,32,48,64,80}` (step `luma_span/4 = 16` mi) x +`cu_mi.0 ∈ {64,72}` (step `luma_span_h/4 = 8` mi). The nine are the same +shape; one unit is representative: + +``` +EC_IBC128_SPAN_TMP replay plane=1 cu_mi=(64,32) wh=(64,32) +``` + +Three facts make that write **clipped to the same cells the walk already +stamped**, not a sample the oracle lacks: + +1. **The predicate is a shape test, not a divergence test.** `luma_span != + luma_span_h` is `chroma_tx< 10`, reran: + +``` +assertion `left == right` failed: ...: 422_intrabc_sb128_strip.obu fired the 4:2:2 +span-shape arm 9 time(s); NINE were measured and are NOT a pixel miss ... + left: 9 + right: 10 +test result: FAILED. 0 passed; 1 failed +``` + +Reverted to 9; the gate is green. The assert bites. + +## 6. Green after + +``` +test stream::tests::the_422_block_128rect_chroma_chunk_gather_stays_per_axis ... ok +test stream::tests::the_pinned_422_intrabc_sb128_strip_witnesses_decode_pixel_exact ... ok +test stream::tests::the_intrabc_128rect_chroma_chunk_walk_stays_per_axis ... ok +test result: ok. 3 passed; 0 failed +``` + +No decoder behaviour changed: comments/doc plus one `assert_eq!` in a test. + +## 7. Left open (disposition) + +- **The other 19 committed 4:2:2 cells' `mismatch = 0`** rests on the existing + doc measurement, not on an assert added here — `accepted`: the pinned pair + is the only cell class this counter is non-zero on, and the gate that would + cover the rest is the corpus gate, out of this ticket's scope. +- **The counter is not a divergence detector.** Renaming/repurposing it to + actually witness the lane-av1-128rectspan class is a separate change — + `deferred()`. The + source-scan arm already covers the defect.