av1: assert the measured 9 on SB128RECT_REPLAY_SPAN_MISMATCH_HITS
Browse files at this commit08f717d5b11bad85b942d791df060c7387d1beffParent: cb271bc3 changed files +221 -28
- crates/ec-av1/src/decode.rs +32 -22
- crates/ec-av1/src/stream.rs +60 -6
- lanes/av1422mismatch9.report.md +129 -0
crates/ec-av1/src/decode.rsmodified+32 -22
| @@ -24511,30 +24511,40 @@ thread_local! { | ||
| 24511 | 24511 | /// of them, so this reads 0 on any stream that never codes one -- the |
| 24512 | 24512 | /// non-vacuity anchor for the replay's own gate. |
| 24513 | 24513 | pub(crate) static SB128RECT_CHROMA_REPLAY_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 24514 | - /// ... and the number of non-skip 128-root rect BLOCKS whose replay | |
| 24515 | - /// height differs from the unit's own LUMA-MI height -- the signature of the | |
| 24516 | - /// width passed to both axes (`luma_span` where the in-loop stamp used | |
| 24517 | - /// `luma_span_h`). lane-av1422lift: the doc here used to read "Zero on | |
| 24518 | - /// every stream this decoder admits ... 4:2:2 ... is refused by name at | |
| 24519 | - /// the sequence header", and that was TRUE. Admitting 4:2:2 genuinely made | |
| 24520 | - /// this counter able to fire, and it does fire: measured on this branch's | |
| 24521 | - /// tip over all 21 committed 4:2:2 cells, `422_intrabc_sb128_strip.obu` | |
| 24522 | - /// and `422_intrabc_sb128_strip_notxsearch.obu` each read | |
| 24523 | - /// `replay = 72, mismatch = 9`; the other 19 read 0. | |
| 24514 | + /// ... and the number of non-skip 128-root rect BLOCKS whose two LUMA-MI | |
| 24515 | + /// spans differ (`luma_span = chroma_tx << ss_x` vs | |
| 24516 | + /// `luma_span_h = chroma_tx << ss_y`). lane-av1422lift: the doc here used | |
| 24517 | + /// to read "Zero on every stream this decoder admits ... 4:2:2 ... is | |
| 24518 | + /// refused by name at the sequence header", and that was TRUE. Admitting | |
| 24519 | + /// 4:2:2 genuinely made this counter able to fire, and it does fire: | |
| 24520 | + /// measured, `422_intrabc_sb128_strip.obu` and | |
| 24521 | + /// `422_intrabc_sb128_strip_notxsearch.obu` each read | |
| 24522 | + /// `replay = 72, mismatch = 9`; the other 19 committed 4:2:2 cells read 0. | |
| 24524 | 24523 | /// |
| 24525 | - /// **Those two pins are byte-exact against ffmpeg** | |
| 24526 | - /// (`the_pinned_422_intrabc_sb128_strip_witnesses_decode_pixel_exact`, all | |
| 24527 | - /// five frames, every plane), so a non-zero mismatch is NOT a defect | |
| 24528 | - /// signature at 4:2:2 -- it is the arm counting its own designed case. | |
| 24529 | - /// Nothing here asserts zero, and nothing should: adding a zero assert | |
| 24530 | - /// would red a gate on a cell that is provably correct. | |
| 24524 | + /// lane-av1422mismatch9: the predicate is the span DIFFERENCE, which at | |
| 24525 | + /// ss (1, 0) is true BY CONSTRUCTION for every 128-root rect block -- so | |
| 24526 | + /// this is a shape test ("a 4:2:2-shaped block replayed"), NOT a | |
| 24527 | + /// divergence test, and it does not witness the lane-av1-128rectspan | |
| 24528 | + /// defect it was named for (that defect passed `luma_span` to both axes; | |
| 24529 | + /// the source-scan arm in | |
| 24530 | + /// `the_422_block_128rect_chroma_chunk_gather_stays_per_axis` is what | |
| 24531 | + /// pins the per-axis spelling). It is not a pixel-miss signature either: | |
| 24532 | + /// the replay re-stamps with the same per-axis pair the in-loop walk | |
| 24533 | + /// stamped with, and `record_mi_chroma` writes only the `left`/`above` | |
| 24534 | + /// context arrays -- zero pixel samples. Both pins are byte-exact against | |
| 24535 | + /// ffmpeg (`the_pinned_422_intrabc_sb128_strip_witnesses_decode_pixel_ | |
| 24536 | + /// exact`, all five frames, every plane). | |
| 24531 | 24537 | /// |
| 24532 | - /// The only readers of the pair are | |
| 24533 | - /// [`sb128rect_chroma_replay_hits`]'s two gates, both on 4:4:4 and 4:2:0 | |
| 24534 | - /// streams, where the unit's luma width and height are equal so the | |
| 24535 | - /// mismatch half is structurally zero. That is the zero this counter is | |
| 24536 | - /// currently a tripwire FOR, and it is a statement about those two | |
| 24537 | - /// streams, not about the format. | |
| 24538 | + /// **Nothing asserts zero here, and nothing should**: a zero assert would | |
| 24539 | + /// red on a provably correct cell. The measured NINE is asserted instead, | |
| 24540 | + /// in `the_422_block_128rect_chroma_chunk_gather_stays_per_axis` (with | |
| 24541 | + /// this reasoning in its message), so a change in the count is a red gate | |
| 24542 | + /// rather than a silent drift. | |
| 24543 | + /// | |
| 24544 | + /// The pair's other reader is `sb128rect_chroma_replay_hits` on a 4:4:4 | |
| 24545 | + /// stream, where the unit's luma width and height are equal so the | |
| 24546 | + /// mismatch half is structurally zero -- a zero that is a statement about | |
| 24547 | + /// that stream, not about the format. | |
| 24538 | 24548 | pub(crate) static SB128RECT_REPLAY_SPAN_MISMATCH_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 24539 | 24549 | } |
| 24540 | 24550 |
crates/ec-av1/src/stream.rsmodified+60 -6
| @@ -326,8 +326,15 @@ pub fn intra128_lossless_counters() -> usize { | ||
| 326 | 326 | /// `422_intrabc_sb128_strip*` pins each read `(72, 9)` while the other 19 |
| 327 | 327 | /// committed 4:2:2 cells read `(0, 0)`. Those two pins are byte-exact |
| 328 | 328 | /// against ffmpeg, so the non-zero half counts the arm's own designed case |
| 329 | -/// and is not a defect. No 4:2:2 gate reads this pair; the two gates that do | |
| 330 | -/// are on 4:2:0 and 4:4:4 streams, where the half is structurally zero. | |
| 329 | +/// and is not a defect. lane-av1422mismatch9: the predicate is | |
| 330 | +/// `luma_span != luma_span_h` (`chroma_tx << ss_x` vs `<< ss_y`), true by | |
| 331 | +/// CONSTRUCTION at ss (1,0), and the replay re-stamps with the same per-axis | |
| 332 | +/// pair the in-loop walk used, so the counter is a 4:2:2 shape test, not a | |
| 333 | +/// divergence test (`record_mi_chroma` writes only the left/above context | |
| 334 | +/// arrays, never a pixel). One 4:2:2 gate now reads the pair and asserts the | |
| 335 | +/// measured `(72, 9)`: | |
| 336 | +/// `the_422_block_128rect_chroma_chunk_gather_stays_per_axis`; the other | |
| 337 | +/// reader is on a 4:4:4 stream, where the mismatch half is structurally zero. | |
| 331 | 338 | pub fn sb128rect_chroma_replay_counters() -> (usize, usize) { |
| 332 | 339 | crate::decode::sb128rect_chroma_replay_hits() |
| 333 | 340 | } |
| @@ -3695,6 +3702,13 @@ pub(crate) mod tests { | ||
| 3695 | 3702 | /// against ffmpeg, exactly as the pre-change tree was (the gathered |
| 3696 | 3703 | /// votes cancel at every reached unit), so THIS gate -- not a pixel |
| 3697 | 3704 | /// compare -- is what stops the routing being reverted. |
| 3705 | + /// | |
| 3706 | + /// lane-av1422mismatch9: the same decode loop now also asserts the | |
| 3707 | + /// `SB128RECT_REPLAY_SPAN_MISMATCH_HITS` count (NINE per pin) and states | |
| 3708 | + /// why it is not a pixel miss -- the counter's predicate is a span | |
| 3709 | + /// DIFFERENCE, true by construction at ss (1,0); the replay re-stamps the | |
| 3710 | + /// identical context cells with the same per-axis pair the read walk used; | |
| 3711 | + /// and `record_mi_chroma` writes no pixel sample. See the assert's message. | |
| 3698 | 3712 | #[test] |
| 3699 | 3713 | fn the_422_block_128rect_chroma_chunk_gather_stays_per_axis() { |
| 3700 | 3714 | const NAME: &str = "the_422_block_128rect_chroma_chunk_gather_stays_per_axis"; |
| @@ -3766,18 +3780,58 @@ pub(crate) mod tests { | ||
| 3766 | 3780 | assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted"); |
| 3767 | 3781 | assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted"); |
| 3768 | 3782 | let _guard = lock_gate_counters(); |
| 3769 | - let before = crate::decode::sb128rect_chroma_replay_hits().0; | |
| 3783 | + let before = crate::decode::sb128rect_chroma_replay_hits(); | |
| 3770 | 3784 | let frames = decode_stream(&data) |
| 3771 | 3785 | .unwrap_or_else(|e| panic!("{NAME}: {file} no longer decodes cleanly: {e}")); |
| 3772 | - let after = crate::decode::sb128rect_chroma_replay_hits().0; | |
| 3786 | + let after = crate::decode::sb128rect_chroma_replay_hits(); | |
| 3773 | 3787 | assert_eq!( |
| 3774 | - after - before, | |
| 3788 | + after.0 - before.0, | |
| 3775 | 3789 | 72, |
| 3776 | 3790 | "{NAME}: {file} gathered {} chroma unit context(s) in \ |
| 3777 | 3791 | decode_block_128rect's per-chunk walk; 72 were measured at ss (1, 0) -- \ |
| 3778 | 3792 | a lower number means the gather is no longer REACHED here \ |
| 3779 | 3793 | (class gate-blind-to-feature)", |
| 3780 | - after - before | |
| 3794 | + after.0 - before.0 | |
| 3795 | + ); | |
| 3796 | + // lane-av1422mismatch9: `SB128RECT_REPLAY_SPAN_MISMATCH_HITS` reads | |
| 3797 | + // NINE on each of these two pins, and this is the only place that | |
| 3798 | + // number is asserted. It is NOT a pixel miss, and the three facts | |
| 3799 | + // below are why -- the assert encodes the measurement, not a wish: | |
| 3800 | + // | |
| 3801 | + // 1. The predicate (`decode.rs`, end of `decode_block_128rect`) is | |
| 3802 | + // `luma_span != luma_span_h` -- `chroma_tx << ss_x` vs | |
| 3803 | + // `chroma_tx << ss_y`. At ss (1, 0) the two DIFFER BY | |
| 3804 | + // CONSTRUCTION for every 128-root rect block, so the counter is | |
| 3805 | + // a shape test ("this is the 4:2:2 span shape"), not a | |
| 3806 | + // divergence test. Nine is the number of such blocks the five | |
| 3807 | + // frames code. | |
| 3808 | + // 2. The replay re-stamps with the SAME per-axis pair the in-loop | |
| 3809 | + // walk stamped with (`record_mi_chroma(cu_mi, luma_span, | |
| 3810 | + // luma_span_h, ...)` at both the read walk and the replay), so | |
| 3811 | + // it rewrites the identical context cells -- this is exactly | |
| 3812 | + // the `record_mi_chroma(cu_mi, luma_span, luma_span_h)` pairing | |
| 3813 | + // the source-scan arm above pins. The pre-lane-av1-128rectspan | |
| 3814 | + // defect (width passed on both axes) is caught by that | |
| 3815 | + // spelling arm, not by this counter. | |
| 3816 | + // 3. `record_mi_chroma` writes only `Neighbours::left`/`above` | |
| 3817 | + // (entropy-context arrays); it touches ZERO pixel samples. So | |
| 3818 | + // the 9 events cannot write a sample the oracle lacks. The | |
| 3819 | + // pixel proof is the same file's | |
| 3820 | + // `the_pinned_422_intrabc_sb128_strip_witnesses_decode_pixel_ | |
| 3821 | + // exact`, which pins all five frames byte-exact against | |
| 3822 | + // ffmpeg's `yuv422p` rawvideo. | |
| 3823 | + // | |
| 3824 | + // Change this expected count ONLY with a new measurement; a 4:2:2 | |
| 3825 | + // stream coding more 128-root rect blocks legitimately changes it. | |
| 3826 | + assert_eq!( | |
| 3827 | + after.1 - before.1, | |
| 3828 | + 9, | |
| 3829 | + "{NAME}: {file} fired the 4:2:2 span-shape arm {} time(s); NINE were \ | |
| 3830 | + measured and are NOT a pixel miss (the predicate is `luma_span != \ | |
| 3831 | + luma_span_h`, true by construction at ss (1,0); the replay re-stamps the \ | |
| 3832 | + identical context cells with the same per-axis pair; `record_mi_chroma` \ | |
| 3833 | + writes no pixel) -- see the report above", | |
| 3834 | + after.1 - before.1 | |
| 3781 | 3835 | ); |
| 3782 | 3836 | assert_eq!(frames.len(), 5, "{NAME}: {file} frame count"); |
| 3783 | 3837 | } |
lanes/av1422mismatch9.report.mdadded+129 -0
| @@ -0,0 +1,129 @@ | ||
| 1 | +# lane-av1422mismatch9 — the 9 on `SB128RECT_REPLAY_SPAN_MISMATCH_HITS` | |
| 2 | + | |
| 3 | +Base `main` @ `42b230c4`. Branch `lane/av1422mismatch9`. | |
| 4 | + | |
| 5 | +**Verdict: not a pixel miss, asserted.** | |
| 6 | + | |
| 7 | +`lanes/av1422gather3.report.md` recorded that | |
| 8 | +`SB128RECT_REPLAY_SPAN_MISMATCH_HITS` reads **9** on each of the two pinned | |
| 9 | +`422_intrabc_sb128_strip*.obu` cells while those cells are byte-exact against | |
| 10 | +ffmpeg, and that nothing asserted the 9 and nothing explained it. Both are now | |
| 11 | +settled. | |
| 12 | + | |
| 13 | +## 1. What the increment compares | |
| 14 | + | |
| 15 | +`decode_block_128rect`'s end-of-block chroma replay | |
| 16 | +(`crates/ec-av1/src/decode.rs`, the `for (plane, cu_mi, grid) in &units` loop at | |
| 17 | +the tail of the `else` branch): | |
| 18 | + | |
| 19 | +```rust | |
| 20 | +let luma_span = chroma_tx << ss_x(fctx); // 64 at ss (1,0), chroma_tx 32 | |
| 21 | +let luma_span_h = chroma_tx << ss_y(fctx); // 32 at ss (1,0) | |
| 22 | +... | |
| 23 | +if luma_span != luma_span_h { hit!(SB128RECT_REPLAY_SPAN_MISMATCH_HITS); } | |
| 24 | +for (plane, cu_mi, grid) in &units { | |
| 25 | + neighbours.record_mi_chroma(*cu_mi, luma_span, luma_span_h, *plane, grid); | |
| 26 | + hit!(SB128RECT_CHROMA_REPLAY_HITS); | |
| 27 | +} | |
| 28 | +``` | |
| 29 | + | |
| 30 | +The two spans are the unit's LUMA extent on each axis: **width** | |
| 31 | +`chroma_tx << ss_x` and **height** `chroma_tx << ss_y`, both in luma pixels. | |
| 32 | +The counter fires when they differ. | |
| 33 | + | |
| 34 | +## 2. The measured count | |
| 35 | + | |
| 36 | +Ran `the_422_block_128rect_chroma_chunk_gather_stays_per_axis` on both pins | |
| 37 | +(build `42b230c4` + this change, `CARGO_TARGET_DIR` own dir): | |
| 38 | + | |
| 39 | +| pin | size | fnv1a64 | replay (`.0`) | mismatch (`.1`) | | |
| 40 | +|---|---|---|---|---| | |
| 41 | +| `422_intrabc_sb128_strip.obu` | 1672 | `0x50f5cfc576e4cd00` | **72** | **9** | | |
| 42 | +| `422_intrabc_sb128_strip_notxsearch.obu` | 1675 | `0xd4936f252ff8cff0` | **72** | **9** | | |
| 43 | + | |
| 44 | +Confirmed: **9 per pin**, and `72 = 9 x 8` — each of the nine blocks replayed | |
| 45 | +eight chroma units. The counting reader now asserts `72` and `9` per pin. | |
| 46 | + | |
| 47 | +## 3. Not a pixel miss — one dumped unit | |
| 48 | + | |
| 49 | +A temporary env-gated trace at the replay site (removed before commit) dumped | |
| 50 | +every replayed unit's `(plane, cu_mi, span_w, span_h)` on both pins: | |
| 51 | +**144 lines, all `wh=(64,32)`**, distinct coords `plane ∈ {1,2}` x | |
| 52 | +`cu_mi.1 ∈ {0,16,32,48,64,80}` (step `luma_span/4 = 16` mi) x | |
| 53 | +`cu_mi.0 ∈ {64,72}` (step `luma_span_h/4 = 8` mi). The nine are the same | |
| 54 | +shape; one unit is representative: | |
| 55 | + | |
| 56 | +``` | |
| 57 | +EC_IBC128_SPAN_TMP replay plane=1 cu_mi=(64,32) wh=(64,32) | |
| 58 | +``` | |
| 59 | + | |
| 60 | +Three facts make that write **clipped to the same cells the walk already | |
| 61 | +stamped**, not a sample the oracle lacks: | |
| 62 | + | |
| 63 | +1. **The predicate is a shape test, not a divergence test.** `luma_span != | |
| 64 | + luma_span_h` is `chroma_tx<<ss_x != chroma_tx<<ss_y`, which at ss (1,0) is | |
| 65 | + true **by construction for every 128-root rect block**. So 9 is simply the | |
| 66 | + number of such blocks the five frames code; the counter cannot distinguish | |
| 67 | + a correct 4:2:2 replay from a wrong one. | |
| 68 | +2. **The replay re-stamps with the identical per-axis pair the read walk | |
| 69 | + used.** The in-loop stamp is | |
| 70 | + `record_mi_chroma(cu_mi, luma_span, luma_span_h, plane_pass, &grid)`; the | |
| 71 | + replay is `record_mi_chroma(*cu_mi, luma_span, luma_span_h, *plane, grid)` | |
| 72 | + — same receiver, same `cu_mi`, same `(luma_span, luma_span_h)`, same grid. | |
| 73 | + It rewrites the **same** `left[]`/`above[]` cells, so it cannot introduce a | |
| 74 | + state the walk did not already publish. (The lane-av1-128rectspan defect — | |
| 75 | + width passed on both axes — is pinned by the source-scan arm of the same | |
| 76 | + gate, which counts the per-axis spellings, not by this counter.) | |
| 77 | +3. **`record_mi_chroma` writes no pixel.** Its body | |
| 78 | + (`decode.rs:~11379-11384`) writes only `Neighbours::left[..][plane]` and | |
| 79 | + `Neighbours::above[..][plane]` — entropy-context arrays, both clipped by | |
| 80 | + `min(bound_h.saturating_sub(mi_r))` / `min(bound_w.saturating_sub(mi_c))` | |
| 81 | + against the frame's mi bounds. Zero plane samples are touched, so the 9 | |
| 82 | + events physically cannot write a sample the oracle lacks. The pixel proof | |
| 83 | + is the sibling pin `the_pinned_422_intrabc_sb128_strip_witnesses_decode_ | |
| 84 | + pixel_exact` (all five frames, every plane, byte-exact vs ffmpeg | |
| 85 | + `yuv422p`), which passes on the same bytes. | |
| 86 | + | |
| 87 | +## 4. What changed | |
| 88 | + | |
| 89 | +| file | change | | |
| 90 | +|---|---| | |
| 91 | +| `stream.rs` | `the_422_block_128rect_chroma_chunk_gather_stays_per_axis` now reads the full `(replay, mismatch)` pair and `assert_eq!`s the measured **9** per pin, with the three-fact reason in the message; the gate doc gains the same note. | | |
| 92 | +| `stream.rs` | `sb128rect_chroma_replay_counters` doc: corrected from "No 4:2:2 gate reads this pair" to name the gate that now asserts `(72, 9)`. | | |
| 93 | +| `decode.rs` | `SB128RECT_REPLAY_SPAN_MISMATCH_HITS` doc: the predicate restated as the per-axis span **difference** (a 4:2:2 shape test, not the divergence test it was named for and not a pixel-miss signature); the `record_mi_chroma`-writes-no-pixel and byte-exact-pin facts recorded; "nothing asserts zero" now says the measured NINE is asserted instead. | | |
| 94 | + | |
| 95 | +## 5. Red-before proof of the new assert | |
| 96 | + | |
| 97 | +Flipped the expected count `9 -> 10`, reran: | |
| 98 | + | |
| 99 | +``` | |
| 100 | +assertion `left == right` failed: ...: 422_intrabc_sb128_strip.obu fired the 4:2:2 | |
| 101 | +span-shape arm 9 time(s); NINE were measured and are NOT a pixel miss ... | |
| 102 | + left: 9 | |
| 103 | + right: 10 | |
| 104 | +test result: FAILED. 0 passed; 1 failed | |
| 105 | +``` | |
| 106 | + | |
| 107 | +Reverted to 9; the gate is green. The assert bites. | |
| 108 | + | |
| 109 | +## 6. Green after | |
| 110 | + | |
| 111 | +``` | |
| 112 | +test stream::tests::the_422_block_128rect_chroma_chunk_gather_stays_per_axis ... ok | |
| 113 | +test stream::tests::the_pinned_422_intrabc_sb128_strip_witnesses_decode_pixel_exact ... ok | |
| 114 | +test stream::tests::the_intrabc_128rect_chroma_chunk_walk_stays_per_axis ... ok | |
| 115 | +test result: ok. 3 passed; 0 failed | |
| 116 | +``` | |
| 117 | + | |
| 118 | +No decoder behaviour changed: comments/doc plus one `assert_eq!` in a test. | |
| 119 | + | |
| 120 | +## 7. Left open (disposition) | |
| 121 | + | |
| 122 | +- **The other 19 committed 4:2:2 cells' `mismatch = 0`** rests on the existing | |
| 123 | + doc measurement, not on an assert added here — `accepted`: the pinned pair | |
| 124 | + is the only cell class this counter is non-zero on, and the gate that would | |
| 125 | + cover the rest is the corpus gate, out of this ticket's scope. | |
| 126 | +- **The counter is not a divergence detector.** Renaming/repurposing it to | |
| 127 | + actually witness the lane-av1-128rectspan class is a separate change — | |
| 128 | + `deferred(<unblock: a lane that owns the counter's semantics>)`. The | |
| 129 | + source-scan arm already covers the defect. |