forge
Explore
Log in

Don't you dare go Hollow

lane/av1422ibctxsel: route the ss (1,0) non-split chroma gather through the pair rule

Browse files at this commit

785e89a4b5c99f31cf060a723161267bfadacf3cAhmet Kaan GümüşParent: 12fd6d3
decode_intrabc_owned_rect's non-split chroma arms (both the var-tx tree and
the no-leaves twin) fed `read_inter_plane_rect`'s CHROMA coefficient context
with `around_mi_rect` over the block's LUMA span. At ss (1, 0) a chroma 4-px
cell spans two luma mi columns, so the per-mi sum counts every chroma column
twice; libaom's `get_txb_ctx_general` reads one vote per chroma cell, which
is `around_mi_422_chroma`'s every-second sampling. The luma-span form is
kept verbatim at ss (0, 0) and ss (1, 1) (`ss_x == 0` / `ss_y != 0`).

Witness: fixtures/ibc422_nonsplit_ctx.obu (2170 B, sha256
4f82d5da8b4c3d6553953fc373001a1c7a729c9b189214b65503af1e04eb6b68, fnv1a64
0x92e2c4e45ca27e34) -- aomenc profile 2 384x288 4:2:2, 4 key frames,
--sb-size=64 with the last superblock row half outside the frame (64x32 HORZ
intra-BC strips), --enable-tx-size-search=1 plus a high-frequency patch that
keeps the frame at TX_MODE_SELECT (txb_split_count > 0, encodeframe.c:2690),
and a chroma band above the strips so a full-weight above context meets a
full-weight left one of the opposite sign.

Measured: 24 non-split chroma gathers entered; five V-plane reads (strips mi
(64,16)..(64,80) of frame 0) disagree -- dc_sign_ctx 1 through the luma-span
gather vs 0 through the pair rule (full = 2A + L = -8, pair = A + L = 0).

Red-before (route reverted, same bytes): the wrong sign context desyncs the
tile and the decoder refuses the stream mid-frame with the sub-8x8
plane-block refusal -- no frame decodes; both oracles (aomdec, ffmpeg) decode
the pinned bytes fully, so that refusal is a desync symptom, not a real
shape. Green-after: 4/4 frames byte-exact against ffmpeg yuv422p; the route
counter reads 24; the 4:4:4 r512 arm fires it 0 times and stays byte-exact.

New counter: IBC_OWNED_RECT_422_PAIR_HITS (accessor
ibc_owned_rect_422_pair_hits). Gate:
a_422_intrabc_owned_rect_nonsplit_chroma_context_uses_the_pair_rule.
Scoped run: that gate + the 422 sb128 strip gate + a_16x4_intrabc_pair_strip
(4:2:0) + the 4:4:4 owner-rect gate, all green.
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! {
51675167 /// strip's chroma plane block.
51685168 static IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS: std::cell::Cell<usize> =
51695169 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) };
51705179 }
51715180
51725181 /// 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() {
52225231 IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.set(0));
52235232 }
52245233
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+
52255246 /// lane-whtshape: [`INTRABC_RECT_LOSSLESS_CHROMA4_HITS`].
52265247 #[allow(dead_code)] // read only from the `#[cfg(test)]` gates
52275248 pub fn intrabc_rect_lossless_chroma4_hits() -> usize {
@@ -18019,22 +18040,29 @@ fn decode_intrabc_owned_rect(
1801918040 u_grid = ug;
1802018041 v_grid = vg;
1802118042 } else {
18022- // lane-av1422gathercensus: the only `around_mi_rect` in the file
18023- // that feeds a CHROMA coefficient context and can run at ss
18024- // (1, 0): its above extent is the whole block's LUMA width, and
18025- // libaom's `get_txb_ctx_general` reads one vote per CHROMA 4-px
18026- // cell, so at ss (1, 0) the per-mi sum counts each chroma column
18027- // twice (the class `around_mi_422_chroma` fixes).
18028- // Kept verbatim because it is UNWITNESSED, not because it is
18029- // unreachable: it runs only for a NON-skipped, non-lossless
18030- // intrabc-owned 64x32/32x64 (or smaller) rect strip, and no
18031- // committed 4:2:2 fixture codes one -- an env-gated probe here
18032- // fired 0 times across the whole committed 4:2:2 corpus (24 gate
18033- // tests, 21 decoding cells; see
18034- // `lanes/av1422gathercensus.report.md`). A future fixture that
18035- // enters it must route through `around_mi_422_chroma` under the
18036- // ss (1, 0) guard.
18037- let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh);
18043+ // lane-av1422ibctxsel: at ss (1, 0) a chroma 4-px cell spans TWO
18044+ // luma mi columns, so a luma-span gather counts each chroma
18045+ // column twice; libaom's `get_txb_ctx_general` reads one vote per
18046+ // CHROMA cell, which is what `around_mi_422_chroma`'s
18047+ // every-second sampling produces. Both non-split chroma arms of
18048+ // this function route through it under the ss (1, 0) guard; every
18049+ // other subsampling keeps the plain gather verbatim. WITNESS: the
18050+ // no-leaves twin below (24 entries on
18051+ // `fixtures/ibc422_nonsplit_ctx.obu`, five of them V-plane reads
18052+ // whose two gathers disagree -- `dc_sign_ctx` 1 vs 0; gate
18053+ // `a_422_intrabc_owned_rect_nonsplit_chroma_context_uses_the_pair_rule`).
18054+ // THIS branch has no stream that splits a transform on the strip:
18055+ // it needs `TX_MODE_SELECT` plus a `txfm_partition` split of the
18056+ // 64x32 strip, a conjunction no measured stream has produced
18057+ // (`lane-av1422ibcrect` measured 0 entries under
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+ };
1803818066 let (ug, _) = read_inter_plane_rect(
1803918067 dec,
1804018068 cdfs,
@@ -18115,6 +18143,19 @@ fn decode_intrabc_owned_rect(
1811518143 u_grid = ug;
1811618144 v_grid = vg;
1811718145 } 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+ };
1811818159 let (ug, _) = read_inter_plane_rect(
1811918160 dec,
1812018161 cdfs,
@@ -18122,7 +18163,7 @@ fn decode_intrabc_owned_rect(
1812218163 (cw, ch),
1812318164 cside,
1812418165 1,
18125- around[1],
18166+ around_chroma[1],
1812618167 0,
1812718168 u,
1812818169 cpx,
@@ -18139,7 +18180,7 @@ fn decode_intrabc_owned_rect(
1813918180 (cw, ch),
1814018181 cside,
1814118182 2,
18142- around[2],
18183+ around_chroma[2],
1814318184 0,
1814418185 v,
1814518186 cpx,
crates/ec-av1/src/stream.rsmodified+94 -0
@@ -3539,6 +3539,100 @@ pub(crate) mod tests {
35393539 }
35403540 }
35413541
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+
35423636 /// lane-av1-ibc128chunk: the SOURCE-SCAN arm of the witness gate above.
35433637 ///
35443638 /// The decode-level half of the red/green evidence cannot run in