lane/av1422ibctxsel: route the ss (1,0) non-split chroma gather through the pair rule
Browse files at this commit785e89a4b5c99f31cf060a723161267bfadacf3cParent: 12fd6d33 changed files +153 -18
- crates/ec-av1/fixtures/ibc422_nonsplit_ctx.obu +0 -0
- crates/ec-av1/src/decode.rs +59 -18
- crates/ec-av1/src/stream.rs +94 -0
crates/ec-av1/fixtures/ibc422_nonsplit_ctx.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+59 -18
| @@ -5167,6 +5167,15 @@ thread_local! { | |||
| 5167 | /// strip's chroma plane block. | 5167 | /// strip's chroma plane block. |
| 5168 | static IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS: std::cell::Cell<usize> = | 5168 | static IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS: std::cell::Cell<usize> = |
| 5169 | const { std::cell::Cell::new(0) }; | 5169 | const { std::cell::Cell::new(0) }; |
| 5170 | + /// lane-av1422ibctxsel: `decode_intrabc_owned_rect`'s NON-SPLIT chroma | ||
| 5171 | + /// gather taken through the 4:2:2 pair rule (`around_mi_422_chroma`) | ||
| 5172 | + /// under the ss (1, 0) guard -- both residual branches (the var-tx tree | ||
| 5173 | + /// and the no-leaves twin). `>= 1` can only come from a 4:2:2 stream | ||
| 5174 | + /// that reaches this function's non-split chroma arm; the 4:2:0/4:4:4 | ||
| 5175 | + /// arms keep the plain `around_mi_rect` gather (`ss_y != 0` / `ss_x == 0` | ||
| 5176 | + /// take the else), so the counter stays 0 for them. | ||
| 5177 | + static IBC_OWNED_RECT_422_PAIR_HITS: std::cell::Cell<usize> = | ||
| 5178 | + const { std::cell::Cell::new(0) }; | ||
| 5170 | } | 5179 | } |
| 5171 | 5180 | ||
| 5172 | /// lane-av1-intrabc r4: coded (`skip == 0`) rect intrabc blocks reconstructed, | 5181 | /// lane-av1-intrabc r4: coded (`skip == 0`) rect intrabc blocks reconstructed, |
| @@ -5222,6 +5231,18 @@ pub(crate) fn reset_ibc_owned_rect_chroma_footprint_444_hits() { | |||
| 5222 | IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.set(0)); | 5231 | IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.set(0)); |
| 5223 | } | 5232 | } |
| 5224 | 5233 | ||
| 5234 | +/// lane-av1422ibctxsel: [`IBC_OWNED_RECT_422_PAIR_HITS`]. | ||
| 5235 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 5236 | +pub fn ibc_owned_rect_422_pair_hits() -> usize { | ||
| 5237 | + IBC_OWNED_RECT_422_PAIR_HITS.with(|c| c.get()) | ||
| 5238 | +} | ||
| 5239 | + | ||
| 5240 | +/// lane-av1422ibctxsel: zeroes [`IBC_OWNED_RECT_422_PAIR_HITS`]. | ||
| 5241 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 5242 | +pub(crate) fn reset_ibc_owned_rect_422_pair_hits() { | ||
| 5243 | + IBC_OWNED_RECT_422_PAIR_HITS.with(|c| c.set(0)); | ||
| 5244 | +} | ||
| 5245 | + | ||
| 5225 | /// lane-whtshape: [`INTRABC_RECT_LOSSLESS_CHROMA4_HITS`]. | 5246 | /// lane-whtshape: [`INTRABC_RECT_LOSSLESS_CHROMA4_HITS`]. |
| 5226 | #[allow(dead_code)] // read only from the `#[cfg(test)]` gates | 5247 | #[allow(dead_code)] // read only from the `#[cfg(test)]` gates |
| 5227 | pub fn intrabc_rect_lossless_chroma4_hits() -> usize { | 5248 | pub fn intrabc_rect_lossless_chroma4_hits() -> usize { |
| @@ -18019,22 +18040,29 @@ fn decode_intrabc_owned_rect( | |||
| 18019 | u_grid = ug; | 18040 | u_grid = ug; |
| 18020 | v_grid = vg; | 18041 | v_grid = vg; |
| 18021 | } else { | 18042 | } else { |
| 18022 | - // lane-av1422gathercensus: the only `around_mi_rect` in the file | 18043 | + // lane-av1422ibctxsel: at ss (1, 0) a chroma 4-px cell spans TWO |
| 18023 | - // that feeds a CHROMA coefficient context and can run at ss | 18044 | + // luma mi columns, so a luma-span gather counts each chroma |
| 18024 | - // (1, 0): its above extent is the whole block's LUMA width, and | 18045 | + // column twice; libaom's `get_txb_ctx_general` reads one vote per |
| 18025 | - // libaom's `get_txb_ctx_general` reads one vote per CHROMA 4-px | 18046 | + // CHROMA cell, which is what `around_mi_422_chroma`'s |
| 18026 | - // cell, so at ss (1, 0) the per-mi sum counts each chroma column | 18047 | + // every-second sampling produces. Both non-split chroma arms of |
| 18027 | - // twice (the class `around_mi_422_chroma` fixes). | 18048 | + // this function route through it under the ss (1, 0) guard; every |
| 18028 | - // Kept verbatim because it is UNWITNESSED, not because it is | 18049 | + // other subsampling keeps the plain gather verbatim. WITNESS: the |
| 18029 | - // unreachable: it runs only for a NON-skipped, non-lossless | 18050 | + // no-leaves twin below (24 entries on |
| 18030 | - // intrabc-owned 64x32/32x64 (or smaller) rect strip, and no | 18051 | + // `fixtures/ibc422_nonsplit_ctx.obu`, five of them V-plane reads |
| 18031 | - // committed 4:2:2 fixture codes one -- an env-gated probe here | 18052 | + // whose two gathers disagree -- `dc_sign_ctx` 1 vs 0; gate |
| 18032 | - // fired 0 times across the whole committed 4:2:2 corpus (24 gate | 18053 | + // `a_422_intrabc_owned_rect_nonsplit_chroma_context_uses_the_pair_rule`). |
| 18033 | - // tests, 21 decoding cells; see | 18054 | + // THIS branch has no stream that splits a transform on the strip: |
| 18034 | - // `lanes/av1422gathercensus.report.md`). A future fixture that | 18055 | + // it needs `TX_MODE_SELECT` plus a `txfm_partition` split of the |
| 18035 | - // enters it must route through `around_mi_422_chroma` under the | 18056 | + // 64x32 strip, a conjunction no measured stream has produced |
| 18036 | - // ss (1, 0) guard. | 18057 | + // (`lane-av1422ibcrect` measured 0 entries under |
| 18037 | - let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); | 18058 | + // `TX_MODE_LARGEST`); the routing here is identical, so a future |
| 18059 | + // witness takes the same code. | ||
| 18060 | + let around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { | ||
| 18061 | + hit!(IBC_OWNED_RECT_422_PAIR_HITS); | ||
| 18062 | + neighbours.around_mi_422_chroma((mi_r, mi_c), bw, bh) | ||
| 18063 | + } else { | ||
| 18064 | + neighbours.around_mi_rect((mi_r, mi_c), bw, bh) | ||
| 18065 | + }; | ||
| 18038 | let (ug, _) = read_inter_plane_rect( | 18066 | let (ug, _) = read_inter_plane_rect( |
| 18039 | dec, | 18067 | dec, |
| 18040 | cdfs, | 18068 | cdfs, |
| @@ -18115,6 +18143,19 @@ fn decode_intrabc_owned_rect( | |||
| 18115 | u_grid = ug; | 18143 | u_grid = ug; |
| 18116 | v_grid = vg; | 18144 | v_grid = vg; |
| 18117 | } else { | 18145 | } else { |
| 18146 | + // lane-av1422ibctxsel: the twin of the tree branch above -- the | ||
| 18147 | + // CHROMA context at ss (1, 0) is the pair rule (one vote per | ||
| 18148 | + // chroma 4-px cell); `around` stays the plain luma-span gather | ||
| 18149 | + // for plane 0 (lane-av1422ibcrect measured this arm entered 24 | ||
| 18150 | + // times by a 4:2:2 64x32 strip whose two gathers happened to | ||
| 18151 | + // agree -- `fixtures/ibc422_nonsplit_ctx.obu` is the stream where | ||
| 18152 | + // they do not). | ||
| 18153 | + let around_chroma = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { | ||
| 18154 | + hit!(IBC_OWNED_RECT_422_PAIR_HITS); | ||
| 18155 | + neighbours.around_mi_422_chroma((mi_r, mi_c), bw, bh) | ||
| 18156 | + } else { | ||
| 18157 | + around | ||
| 18158 | + }; | ||
| 18118 | let (ug, _) = read_inter_plane_rect( | 18159 | let (ug, _) = read_inter_plane_rect( |
| 18119 | dec, | 18160 | dec, |
| 18120 | cdfs, | 18161 | cdfs, |
| @@ -18122,7 +18163,7 @@ fn decode_intrabc_owned_rect( | |||
| 18122 | (cw, ch), | 18163 | (cw, ch), |
| 18123 | cside, | 18164 | cside, |
| 18124 | 1, | 18165 | 1, |
| 18125 | - around[1], | 18166 | + around_chroma[1], |
| 18126 | 0, | 18167 | 0, |
| 18127 | u, | 18168 | u, |
| 18128 | cpx, | 18169 | cpx, |
| @@ -18139,7 +18180,7 @@ fn decode_intrabc_owned_rect( | |||
| 18139 | (cw, ch), | 18180 | (cw, ch), |
| 18140 | cside, | 18181 | cside, |
| 18141 | 2, | 18182 | 2, |
| 18142 | - around[2], | 18183 | + around_chroma[2], |
| 18143 | 0, | 18184 | 0, |
| 18144 | v, | 18185 | v, |
| 18145 | cpx, | 18186 | cpx, |
crates/ec-av1/src/stream.rsmodified+94 -0
| @@ -3539,6 +3539,100 @@ pub(crate) mod tests { | |||
| 3539 | } | 3539 | } |
| 3540 | } | 3540 | } |
| 3541 | 3541 | ||
| 3542 | + /// lane-av1422ibctxsel: the firing gate for `decode_intrabc_owned_rect`'s | ||
| 3543 | + /// NON-SPLIT chroma coefficient context at 4:2:2. | ||
| 3544 | + /// | ||
| 3545 | + /// `lanes/av1422gathercensus.report.md` closed its ss (1, 0) class sweep | ||
| 3546 | + /// with this one gather at STOP -- unwitnessed: `around_mi_rect` over the | ||
| 3547 | + /// block's LUMA span feeds the CHROMA `dc_sign_ctx`, and at ss (1, 0) a | ||
| 3548 | + /// chroma 4-px cell spans TWO luma mi columns, so the per-mi sum counts | ||
| 3549 | + /// every chroma column twice (`around_mi_422_chroma`'s every-second | ||
| 3550 | + /// sampling is libaom's one-vote-per-cell sum). `lane-av1422ibcrect` | ||
| 3551 | + /// found a stream that ENTERS the gather (24 entries) but whose two | ||
| 3552 | + /// gathers agree on every entry, so the class stayed harmless-ON-THAT- | ||
| 3553 | + /// STREAM, not proven. | ||
| 3554 | + /// | ||
| 3555 | + /// This fixture is the discriminating witness: aomenc profile 2, 384x288 | ||
| 3556 | + /// 4:2:2, 4 key frames, `--sb-size=64` with the last superblock row half | ||
| 3557 | + /// outside the frame (so the 64-root partition is a single gathered bit | ||
| 3558 | + /// and the strips are 64x32 HORZ intra-BC strips), `--enable-tx-size- | ||
| 3559 | + /// search=1` plus a high-frequency patch that keeps the frame's `tx_mode` | ||
| 3560 | + /// at `TX_MODE_SELECT` (`txb_split_count > 0`; without it encodeframe.c | ||
| 3561 | + /// :2690 downgrades every frame to `TX_MODE_LARGEST`), and a chroma band | ||
| 3562 | + /// above the strips so a full-weight above context meets a full-weight | ||
| 3563 | + /// left one of the opposite sign. | ||
| 3564 | + /// | ||
| 3565 | + /// Measured on the pinned bytes: 24 non-split chroma gathers entered (6 | ||
| 3566 | + /// strips x 4 frames; 48 plane reads), and FIVE of them -- plane 2, strips | ||
| 3567 | + /// mi (64,16)..(64,80) of frame 0 -- read `dc_sign_ctx` 1 through the | ||
| 3568 | + /// luma-span gather against libaom's 0 through the pair rule (`full = 2A + | ||
| 3569 | + /// L = -8`, `pair = A + L = 0`: the double-counted above vote crosses | ||
| 3570 | + /// zero, and the context is a sign). | ||
| 3571 | + /// | ||
| 3572 | + /// Red-before (the route reverted, same fixture bytes): the wrong sign | ||
| 3573 | + /// context changes the decoded dc-sign CDF and desyncs the tile -- the | ||
| 3574 | + /// decoder refuses the stream mid-frame with "a block size 4x8, 8x16 or | ||
| 3575 | + /// 16x4 ... has no chroma plane block at this frame's subsampling mode", | ||
| 3576 | + /// so NO frame decodes at all. That refusal is also the proof it is a | ||
| 3577 | + /// desync symptom and not a real sub-8x8 shape: both oracles decode the | ||
| 3578 | + /// pinned bytes fully. Green-after: 4/4 frames byte-exact against | ||
| 3579 | + /// ffmpeg's `yuv422p` rawvideo, with the per-plane coefficient-unit | ||
| 3580 | + /// census (the helper's) and the pair-rule route counter as the | ||
| 3581 | + /// non-vacuity arms. The 4:4:4 arm below pins the guard's other side: | ||
| 3582 | + /// the same function at ss (0, 0) keeps the verbatim luma-span gather and | ||
| 3583 | + /// must NOT fire the route. | ||
| 3584 | + #[test] | ||
| 3585 | + fn a_422_intrabc_owned_rect_nonsplit_chroma_context_uses_the_pair_rule() { | ||
| 3586 | + const NAME: &str = "a_422_intrabc_owned_rect_nonsplit_chroma_context_uses_the_pair_rule"; | ||
| 3587 | + const FILE: &str = "ibc422_nonsplit_ctx.obu"; | ||
| 3588 | + const LEN: usize = 2170; | ||
| 3589 | + /// sha256 `4f82d5da8b4c3d6553953fc373001a1c7a729c9b189214b65503af1e04eb6b68`, | ||
| 3590 | + /// fnv1a64 `0x92e2c4e45ca27e34`. | ||
| 3591 | + const FNV: u64 = 0x92e2c4e45ca27e34; | ||
| 3592 | + if !have_ffmpeg() { | ||
| 3593 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 3594 | + return; | ||
| 3595 | + } | ||
| 3596 | + let path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
| 3597 | + .join("fixtures") | ||
| 3598 | + .join(FILE); | ||
| 3599 | + let data = std::fs::read(&path).unwrap_or_else(|e| { | ||
| 3600 | + panic!( | ||
| 3601 | + "{NAME}: pinned witness {} is missing ({e}) -- the gate cannot run", | ||
| 3602 | + path.display() | ||
| 3603 | + ) | ||
| 3604 | + }); | ||
| 3605 | + assert_eq!(data.len(), LEN, "{NAME}: {FILE} size drifted"); | ||
| 3606 | + assert_eq!(fnv1a64(&data), FNV, "{NAME}: {FILE} bytes drifted"); | ||
| 3607 | + // No `lock_gate_counters()` here: the bumps are thread-local, and | ||
| 3608 | + // `assert_422_stream_pixel_exact` takes that same (non-reentrant) | ||
| 3609 | + // mutex itself -- holding it across this call self-deadlocks. | ||
| 3610 | + crate::decode::reset_ibc_owned_rect_422_pair_hits(); | ||
| 3611 | + assert_422_stream_pixel_exact(NAME, &data, 384, 288, 4, 8, true); | ||
| 3612 | + let hits = crate::decode::ibc_owned_rect_422_pair_hits(); | ||
| 3613 | + assert_eq!( | ||
| 3614 | + hits, 24, | ||
| 3615 | + "{NAME}: the pair-rule route fired {hits} times, not 24 (6 non-split chroma gathers \ | ||
| 3616 | + x 4 frames) -- the witness stopped exercising the arm, or the guard's extent moved" | ||
| 3617 | + ); | ||
| 3618 | + // The guard's other arm: the 4:4:4 owner-rect stream (`r512.obu`, | ||
| 3619 | + // pinned by the gate below) reaches this same function at ss (0, 0), | ||
| 3620 | + // where the verbatim luma-span gather is correct -- the route counter | ||
| 3621 | + // must stay put. | ||
| 3622 | + let r512 = std::fs::read( | ||
| 3623 | + std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("fixtures/r512.obu"), | ||
| 3624 | + ) | ||
| 3625 | + .expect("r512.obu must exist"); | ||
| 3626 | + crate::decode::reset_ibc_owned_rect_422_pair_hits(); | ||
| 3627 | + let _ = decode_stream(&r512).expect("the 4:4:4 owner-rect witness decodes"); | ||
| 3628 | + assert_eq!( | ||
| 3629 | + crate::decode::ibc_owned_rect_422_pair_hits(), | ||
| 3630 | + 0, | ||
| 3631 | + "{NAME}: the 4:2:2 pair-rule route fired on a 4:4:4 stream -- the ss (1, 0) guard \ | ||
| 3632 | + leaks (class gate-blind-to-feature)" | ||
| 3633 | + ); | ||
| 3634 | + } | ||
| 3635 | + | ||
| 3542 | /// lane-av1-ibc128chunk: the SOURCE-SCAN arm of the witness gate above. | 3636 | /// lane-av1-ibc128chunk: the SOURCE-SCAN arm of the witness gate above. |
| 3543 | /// | 3637 | /// |
| 3544 | /// The decode-level half of the red/green evidence cannot run in | 3638 | /// The decode-level half of the red/green evidence cannot run in |