diff --git a/crates/ec-av1/fixtures/ibc422_nonsplit_ctx.obu b/crates/ec-av1/fixtures/ibc422_nonsplit_ctx.obu new file mode 100644 index 0000000000000000000000000000000000000000..f0ce0ad134ea3718e79ae32b7d161467f6d15fcb GIT binary patch literal 2170 zcmZA2_dgU41Hkb+D_d4NE8|2tI^&yYn8&3uG7j0YXEt~CiEKq@#97&7pP3^gvLau; zw(OL1=ZrY#`@{46@I3tw@7L$U1z=`T0|4k?)CUn1e58C99S@)caCwV|%ZW&!*ZDwdLHP@+$zQ9bnfkwH6#sQqEieSPj$T z*qxLqE+}Ik8}J^@7yYhpjRHu@;3X}h4kY4~-T!xTy2P!y*fZFtc}95WWXOCv20OJv zKrrDb!RZaQAZ?grSY7U{($9HKm8@NF2bjfYwz6()CXg0bObR@$UMgC2)sGlGDb;GY z$4l?;$P+CW{`9vm?M9tNP8Dr>64F*5=xMlrZ{Z4%aB;CduIR^Ld=}!)f`&2XA{@w; z=eCAoVR%h${*Y^5Ln|xgs*O(Hsl%CUk~LPw!$J)#(TT!(>m}hKwfPs`IyjJarAa$B zTh{=)D3VFOv0^tN0~E)b9A0@|sJpX}r46mElbnHU$@L{cll-O`q#nN^$#VoJkL zgB7&9mJ>}ufqv9ap0167sy~!o{aV0KeWLuV2DL{f0yf7)KmTaOT#`|iOGNpJJmWX7 z#@Km6gn~2KD?}N+A`|YEvJYv3(dJ1E-oGi$vmx8J$NY6lK*=EC-V3XvtyS@Lz<)YjCM|D zyF~wwK=T(mmbjU_uJ&~=@2?d5F*)*ikGer=Z+GOToJZ{eI1W9jZzmE{0#{cfx&DxH zNc+E1x*yQXdh;E0E7&4eUqz2qv57nzyoyv}FD86X?rm9n3p}fnl{6H`$)4b|7{aPN zzFEUrsk?>ie)7Wspo0x7gpQ(eIzjMhfFze$>5O#xylD{3D@qewlfpN@J=%nEWHgu( z8AoS-EbO*qu_T+?gbx1InPdN(M1GtoQ`OwaEUBN=rFS#)M%#Xzz#1@4;rI3TZ|Fwo z+@c06Tl(6JGGoNea7>Y7(l?xZL5rr{Nboc34oC088GFxQ6}Rd<+P+95DLV$J8RWLB zh8W;xz2$*$FuQ|SV(6m6>lRxg3KD-bP(Tr?+Uq~*u28qB_Gb{z}von~Th z@SefD6gsi?u(&!=za>O8|)}+&|1SU?_Qxl+``6VVyX*v4{e#$Ae zXN()XrNC0(F!W&oUannk!jCnv#qA{(fQ3gH4DySLsPv1^W#=I9tKyT? zPc`247!!MkwDm5(Zw?yhM<&;_7=HmXxmuTxQRTjrVe+;&2W)LGUh7JIH6=3{$vQ)% zS3sk@YbT{_6k(EBxRs3I6B1d<5d;F672D=_+-gVEHb~{@&&0T@gEQ_bbET-K$a_SZ z^o*RfT7CU1Wx48asHLVmCDuJ+*q4YrGaP~)=kexOv7F152{@~4D>m=Ff3GdR$=9^Z z7YPMY6>AFB(ixh-PcU$pu{)+!ciSvlvBCp-9&!4(?HT}cgF$Gnp}nb0z3ieiZOtyz zHYQcTVvU-#te28~i7FDZGuyKfK1tE83GNZznv;p` zWxTbX`v4$Ebt?;)c%kx+ZkX_WO&euQd`{_vlBVRQNg4H z)p2uoLR{L~-2-XkmmoTc9c*JNb5}{f7HUt^iv#^8t2NmU(Ifqy*l4SvB3Yrr2;3g2 z?axscK1+%}SAh(#P0J~X)I8kM-`qGK&=K)DKsycA2R;0S|C2z|f1Xjq2S*l9VCze) z$}1nz(==+4gE*?12fJ0SCu}_@(!;lF?njQ+7EUAVPk-V^*q~J zkt#p9-XF^drxE)8b8`f7FRq=)>;iRSr9`tC>3vZ>yxmDFg$T{+EdYg!*31fe6nB6ZKpmHKSU7>#5 = const { std::cell::Cell::new(0) }; + /// lane-av1422ibctxsel: `decode_intrabc_owned_rect`'s NON-SPLIT chroma + /// gather taken through the 4:2:2 pair rule (`around_mi_422_chroma`) + /// under the ss (1, 0) guard -- both residual branches (the var-tx tree + /// and the no-leaves twin). `>= 1` can only come from a 4:2:2 stream + /// that reaches this function's non-split chroma arm; the 4:2:0/4:4:4 + /// arms keep the plain `around_mi_rect` gather (`ss_y != 0` / `ss_x == 0` + /// take the else), so the counter stays 0 for them. + static IBC_OWNED_RECT_422_PAIR_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; } /// 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() { IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.set(0)); } +/// lane-av1422ibctxsel: [`IBC_OWNED_RECT_422_PAIR_HITS`]. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub fn ibc_owned_rect_422_pair_hits() -> usize { + IBC_OWNED_RECT_422_PAIR_HITS.with(|c| c.get()) +} + +/// lane-av1422ibctxsel: zeroes [`IBC_OWNED_RECT_422_PAIR_HITS`]. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn reset_ibc_owned_rect_422_pair_hits() { + IBC_OWNED_RECT_422_PAIR_HITS.with(|c| c.set(0)); +} + /// lane-whtshape: [`INTRABC_RECT_LOSSLESS_CHROMA4_HITS`]. #[allow(dead_code)] // read only from the `#[cfg(test)]` gates pub fn intrabc_rect_lossless_chroma4_hits() -> usize { @@ -18019,22 +18040,29 @@ fn decode_intrabc_owned_rect( u_grid = ug; v_grid = vg; } else { - // lane-av1422gathercensus: the only `around_mi_rect` in the file - // that feeds a CHROMA coefficient context and can run at ss - // (1, 0): its above extent is the whole block's LUMA width, and - // libaom's `get_txb_ctx_general` reads one vote per CHROMA 4-px - // cell, so at ss (1, 0) the per-mi sum counts each chroma column - // twice (the class `around_mi_422_chroma` fixes). - // Kept verbatim because it is UNWITNESSED, not because it is - // unreachable: it runs only for a NON-skipped, non-lossless - // intrabc-owned 64x32/32x64 (or smaller) rect strip, and no - // committed 4:2:2 fixture codes one -- an env-gated probe here - // fired 0 times across the whole committed 4:2:2 corpus (24 gate - // tests, 21 decoding cells; see - // `lanes/av1422gathercensus.report.md`). A future fixture that - // enters it must route through `around_mi_422_chroma` under the - // ss (1, 0) guard. - let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); + // lane-av1422ibctxsel: at ss (1, 0) a chroma 4-px cell spans TWO + // luma mi columns, so a luma-span gather counts each chroma + // column twice; libaom's `get_txb_ctx_general` reads one vote per + // CHROMA cell, which is what `around_mi_422_chroma`'s + // every-second sampling produces. Both non-split chroma arms of + // this function route through it under the ss (1, 0) guard; every + // other subsampling keeps the plain gather verbatim. WITNESS: the + // no-leaves twin below (24 entries on + // `fixtures/ibc422_nonsplit_ctx.obu`, five of them V-plane reads + // whose two gathers disagree -- `dc_sign_ctx` 1 vs 0; gate + // `a_422_intrabc_owned_rect_nonsplit_chroma_context_uses_the_pair_rule`). + // THIS branch has no stream that splits a transform on the strip: + // it needs `TX_MODE_SELECT` plus a `txfm_partition` split of the + // 64x32 strip, a conjunction no measured stream has produced + // (`lane-av1422ibcrect` measured 0 entries under + // `TX_MODE_LARGEST`); the routing here is identical, so a future + // witness takes the same code. + let around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + hit!(IBC_OWNED_RECT_422_PAIR_HITS); + neighbours.around_mi_422_chroma((mi_r, mi_c), bw, bh) + } else { + neighbours.around_mi_rect((mi_r, mi_c), bw, bh) + }; let (ug, _) = read_inter_plane_rect( dec, cdfs, @@ -18115,6 +18143,19 @@ fn decode_intrabc_owned_rect( u_grid = ug; v_grid = vg; } else { + // lane-av1422ibctxsel: the twin of the tree branch above -- the + // CHROMA context at ss (1, 0) is the pair rule (one vote per + // chroma 4-px cell); `around` stays the plain luma-span gather + // for plane 0 (lane-av1422ibcrect measured this arm entered 24 + // times by a 4:2:2 64x32 strip whose two gathers happened to + // agree -- `fixtures/ibc422_nonsplit_ctx.obu` is the stream where + // they do not). + let around_chroma = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + hit!(IBC_OWNED_RECT_422_PAIR_HITS); + neighbours.around_mi_422_chroma((mi_r, mi_c), bw, bh) + } else { + around + }; let (ug, _) = read_inter_plane_rect( dec, cdfs, @@ -18122,7 +18163,7 @@ fn decode_intrabc_owned_rect( (cw, ch), cside, 1, - around[1], + around_chroma[1], 0, u, cpx, @@ -18139,7 +18180,7 @@ fn decode_intrabc_owned_rect( (cw, ch), cside, 2, - around[2], + around_chroma[2], 0, v, cpx, diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 1870abc2..bb1e8408 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -3539,6 +3539,100 @@ pub(crate) mod tests { } } + /// lane-av1422ibctxsel: the firing gate for `decode_intrabc_owned_rect`'s + /// NON-SPLIT chroma coefficient context at 4:2:2. + /// + /// `lanes/av1422gathercensus.report.md` closed its ss (1, 0) class sweep + /// with this one gather at STOP -- unwitnessed: `around_mi_rect` over the + /// block's LUMA span feeds the CHROMA `dc_sign_ctx`, and at ss (1, 0) a + /// chroma 4-px cell spans TWO luma mi columns, so the per-mi sum counts + /// every chroma column twice (`around_mi_422_chroma`'s every-second + /// sampling is libaom's one-vote-per-cell sum). `lane-av1422ibcrect` + /// found a stream that ENTERS the gather (24 entries) but whose two + /// gathers agree on every entry, so the class stayed harmless-ON-THAT- + /// STREAM, not proven. + /// + /// This fixture is the discriminating witness: aomenc profile 2, 384x288 + /// 4:2:2, 4 key frames, `--sb-size=64` with the last superblock row half + /// outside the frame (so the 64-root partition is a single gathered bit + /// and the strips are 64x32 HORZ intra-BC strips), `--enable-tx-size- + /// search=1` plus a high-frequency patch that keeps the frame's `tx_mode` + /// at `TX_MODE_SELECT` (`txb_split_count > 0`; without it encodeframe.c + /// :2690 downgrades every frame to `TX_MODE_LARGEST`), and a chroma band + /// above the strips so a full-weight above context meets a full-weight + /// left one of the opposite sign. + /// + /// Measured on the pinned bytes: 24 non-split chroma gathers entered (6 + /// strips x 4 frames; 48 plane reads), and FIVE of them -- plane 2, strips + /// mi (64,16)..(64,80) of frame 0 -- read `dc_sign_ctx` 1 through the + /// luma-span gather against libaom's 0 through the pair rule (`full = 2A + + /// L = -8`, `pair = A + L = 0`: the double-counted above vote crosses + /// zero, and the context is a sign). + /// + /// Red-before (the route reverted, same fixture bytes): the wrong sign + /// context changes the decoded dc-sign CDF and desyncs the tile -- the + /// decoder refuses the stream mid-frame with "a block size 4x8, 8x16 or + /// 16x4 ... has no chroma plane block at this frame's subsampling mode", + /// so NO frame decodes at all. That refusal is also the proof it is a + /// desync symptom and not a real sub-8x8 shape: both oracles decode the + /// pinned bytes fully. Green-after: 4/4 frames byte-exact against + /// ffmpeg's `yuv422p` rawvideo, with the per-plane coefficient-unit + /// census (the helper's) and the pair-rule route counter as the + /// non-vacuity arms. The 4:4:4 arm below pins the guard's other side: + /// the same function at ss (0, 0) keeps the verbatim luma-span gather and + /// must NOT fire the route. + #[test] + fn a_422_intrabc_owned_rect_nonsplit_chroma_context_uses_the_pair_rule() { + const NAME: &str = "a_422_intrabc_owned_rect_nonsplit_chroma_context_uses_the_pair_rule"; + const FILE: &str = "ibc422_nonsplit_ctx.obu"; + const LEN: usize = 2170; + /// sha256 `4f82d5da8b4c3d6553953fc373001a1c7a729c9b189214b65503af1e04eb6b68`, + /// fnv1a64 `0x92e2c4e45ca27e34`. + const FNV: u64 = 0x92e2c4e45ca27e34; + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + let path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("fixtures") + .join(FILE); + let data = std::fs::read(&path).unwrap_or_else(|e| { + panic!( + "{NAME}: pinned witness {} is missing ({e}) -- the gate cannot run", + path.display() + ) + }); + assert_eq!(data.len(), LEN, "{NAME}: {FILE} size drifted"); + assert_eq!(fnv1a64(&data), FNV, "{NAME}: {FILE} bytes drifted"); + // No `lock_gate_counters()` here: the bumps are thread-local, and + // `assert_422_stream_pixel_exact` takes that same (non-reentrant) + // mutex itself -- holding it across this call self-deadlocks. + crate::decode::reset_ibc_owned_rect_422_pair_hits(); + assert_422_stream_pixel_exact(NAME, &data, 384, 288, 4, 8, true); + let hits = crate::decode::ibc_owned_rect_422_pair_hits(); + assert_eq!( + hits, 24, + "{NAME}: the pair-rule route fired {hits} times, not 24 (6 non-split chroma gathers \ + x 4 frames) -- the witness stopped exercising the arm, or the guard's extent moved" + ); + // The guard's other arm: the 4:4:4 owner-rect stream (`r512.obu`, + // pinned by the gate below) reaches this same function at ss (0, 0), + // where the verbatim luma-span gather is correct -- the route counter + // must stay put. + let r512 = std::fs::read( + std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("fixtures/r512.obu"), + ) + .expect("r512.obu must exist"); + crate::decode::reset_ibc_owned_rect_422_pair_hits(); + let _ = decode_stream(&r512).expect("the 4:4:4 owner-rect witness decodes"); + assert_eq!( + crate::decode::ibc_owned_rect_422_pair_hits(), + 0, + "{NAME}: the 4:2:2 pair-rule route fired on a 4:4:4 stream -- the ss (1, 0) guard \ + leaks (class gate-blind-to-feature)" + ); + } + /// lane-av1-ibc128chunk: the SOURCE-SCAN arm of the witness gate above. /// /// The decode-level half of the red/green evidence cannot run in