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 935f5680..a184347f 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -3533,6 +3533,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 now runs in committed diff --git a/lanes/av1422ibctxsel.report.md b/lanes/av1422ibctxsel.report.md new file mode 100644 index 00000000..4b24253e --- /dev/null +++ b/lanes/av1422ibctxsel.report.md @@ -0,0 +1,218 @@ +# lane-av1422ibctxsel — the ss (1, 0) non-split chroma gather of +# `decode_intrabc_owned_rect` is DISCRIMINATED by a pinned witness, routed +# through the pair rule, and gated red-before/green-after + +Base `main` = `6d646f65` (branch `lane/av1422ibctxsel`, worktree +`~/.cache/wt/av1422ibctxsel`). Local only: no push, no merge. The fix commit +is `b5e034d4` (source + fixture + gate); this report is a second commit. + +## Verdict + +**Witnessed and fixed.** A real aomenc 4:2:2 stream enters the non-split +chroma gather of `decode_intrabc_owned_rect` **24 times** and, on **five** of +those entries (plane 2, strips mi (64,16)..(64,80) of frame 0), the two +gathers disagree: `dc_sign_ctx` **1** through the luma-span `around_mi_rect` +vs **0** through libaom's pair rule. Pre-fix that wrong context desyncs the +tile and **no frame decodes at all** (the decoder refuses mid-frame); post-fix +the pinned bytes are **byte-exact against ffmpeg on 4/4 frames**, with the +route counter reading 24. Both non-split chroma arms of the function are +routed under the `ss_x == 1 && ss_y == 0` guard; every other subsampling keeps +the plain gather verbatim. The witness is committed and pinned (size + +fnv1a64 + sha256) and the gate is mutation-proven (route reverted → red). + +## 1. The class, and the exact arithmetic a witness has to flip + +Both residual branches of `decode_intrabc_owned_rect` (`leaves.is_some()` — +the var-tx tree — and its `leaves == None` twin) read their **chroma** +coefficient context from `neighbours.around_mi_rect((mi_r, mi_c), bw, bh)` — +the block's **luma** span — and hand `around[1]`/`around[2]` to +`read_inter_plane_rect` planes 1 and 2 (`decode.rs:18037→18045/18062` in the +tree branch, `18076→18125/18142` in the twin, base line numbers). At ss +(1, 0) one chroma 4-px cell spans TWO luma mi columns, so the per-mi sum +counts each 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 (`decode.rs:10555`). + +`dc_sign_ctx(vote)` is `vote.signum()` → {0 zero, 1 negative, 2 positive} +(`decode.rs:8254`), so a witness needs the **sign** to differ: + +* full gather = `2A + L`; pair rule = `A + L`, where `A` = the pair-rule + above sum and `L` = the left sum (identical in both). +* Chroma units at 4:2:2 are ≥2 luma mi wide and even-mi aligned, so the + above part obeys **`full_above = 2 × pair_above` ALWAYS** — the above + votes alone can never disagree in sign. The asymmetry lives in `L`: a flip + needs `A` and `L` of **opposite sign with |L| ∈ [|A|, 2|A|)**. +* With one 32x32 chroma TU per strip (the non-split arm's unit), `L = 8 × + (previous strip's unit sign)` ∈ {+8, −8, 0} and `A = Σ (W_u/2) s_u` over + the units covering the row above. The sharpest case is `A = ±8, L = ∓8`: + `full = ±8` (a sign) vs `pair = 0` (ZERO) — a `dc_sign_ctx` 2-vs-0 or + 1-vs-0 split. + +This is also why `lane-av1422ibcrect`'s A1 measured 0/24: on that stream all +above votes shared one sign (and `A = 0` for strips 1..5), so no arithmetic +could flip. + +## 2. Encoder facts the hunt established (libaom source in `~/.cache/aom-oracle/src`) + +* **`tx_mode` is downgraded to `TX_MODE_LARGEST` when the frame splits no + transform**: `encodeframe.c:2690` — `if (features->tx_mode == TX_MODE_SELECT + && cpi->td.mb.txfm_search_info.txb_split_count == 0) features->tx_mode = + TX_MODE_LARGEST;`. A1's smooth sine content never splits → `txsel=false` + (the ibcrect report's observation) even with `--enable-tx-size-search=1`. + **A high-frequency patch makes `txb_split_count > 0` and the header bit + stays SELECT** (E5+ below) — so the ticket's "vary tx-mode" lever is this. +* **The intraBC hash is LUMA-ONLY**: `hash_motion.c:398` `av1_get_block_hash_ + value(..., const uint8_t *y_src, ...)` hashes 2x2 Y sub-blocks of + `cpi->source`; chroma is not in the key. Chroma offsets therefore cannot + break a luma match — but they do enter the DV's RD cost (E4's −20 strip + band made the encoder drop intraBC on 4 of 6 strips). +* **The geq source runs in the 4:2:0 domain** (`nullsrc … format=yuv420p`), + so a band written in "luma rows" silently never fires for chroma: E2 + changed NOTHING (bit-identical output to A1, same sha256). The band must be + expressed in 4:2:0 chroma rows (luma row `y` = chroma row `y/2`). + +## 3. The attempt table (8 aomenc encodes, all ≤180 s; budget was ≤12) + +Common flags (all rows): `--codec=av1 --i422 --profile=2 --passes=1 +--end-usage=q --cpu-used=0 --threads=1 --row-mt=0 --lag-in-frames=0 +--kf-max-dist=1 --tile-columns=0 --sb-size=64 --min-partition-size=32 +--max-partition-size=64 --enable-rect-partitions=1 --enable-ab-partitions=1 +--enable-1to4-partitions=0 --enable-palette=0 --tune-content=screen +--enable-intrabc=1 --deltaq-mode=0 --enable-tx-size-search=1 --obu`, +384x288, 4 frames, from a `geq` source; A1's base content is +`lum=128+90*sin((X+2N)/37)+30*sin(Y/29) cb=128+30*sin(X/23) +cr=128+30*sin((Y+N)/19)`. + +| id | delta over A1 | bytes | sha256 | arm | txsel | entries | ctx diffs | +|---|---|---|---|---|---|---|---| +| **A1** control | none (cq 32) | 1244 | `fd36bae4…b397db` | lar twin | false | 24 | **0** | +| E2 | `cr += 30*if(between(Y,192,255))` (luma rows — never fires) | 1244 | `fd36bae4…` (same) | lar | false | 24 | 0 | +| E2b | same band written in 4:2:0 chroma rows (96..127) | 1203 | `3bf9709a…3b1e54` | lar | false | 24 | 0 (above `A=+8`, strips `+8`) | +| E3 | band `−30` (chroma rows 96..127) | 1312 | `77d58313…077306` | lar | false | 11 | 0 (above mostly `None`) | +| E4 | E2b plus strip band `−20` (chroma rows 128..143) | 1339 | `fc68088a…8c3415b` | lar | false | 5 (intraBC survived on 2 of 6 strips) | 0 | +| E5 | luma `+40*sin(X*π/2)` patch, rows 0..31 x<64 | 2173 | `f4495f32…043c26f5e` | lar | **true** | 18 | 0 | +| E6 | E5 + `cr += 25*if(Y in 0..31) + 30*if(Y in 96..127)` + same luma patch inside strip 0's band | 3226 | `8d1bc1ec…e64459166` | lar | true | 17 | **4** (1 visible before the pre-fix refusal aborted the decode) | +| **E7** witness | E6 minus the strip luma patch | 2170 | `4f82d5da8b4c3d6553953fc373001a1c7a729c9b189214b65503af1e04eb6b68` | lar | true | 24 | **5** | + +E7's five discriminating entries (probe print, pre-fix): + + EC_IBCNS422P lar mi=(64,16) … ss=(1,0) txsel=true plane=2 fv=-8 pv=0 fctx=1 pctx=0 diff=1 + EC_IBCNS422P lar mi=(64,32) … plane=2 fv=-8 pv=0 fctx=1 pctx=0 diff=1 + EC_IBCNS422P lar mi=(64,48) … plane=2 fv=-8 pv=0 fctx=1 pctx=0 diff=1 + EC_IBCNS422P lar mi=(64,64) … plane=2 fv=-8 pv=0 fctx=1 pctx=0 diff=1 + EC_IBCNS422P lar mi=(64,80) … plane=2 fv=-8 pv=0 fctx=1 pctx=0 diff=1 + +i.e. `A = −8` (above uniform, the `+30` band) and `L = +8` (each strip's own +32x32 V unit is positive) → `full = 2A + L = −8` (negative, ctx 1) vs +`pair = A + L = 0` (zero, ctx 0). Five strips, frame 0 (frame 0 is the one +whose `cr` phase puts the strip residual positive). + +The entry/diff columns above were re-measured in one pass with the temporary +probe (the probe prints the raw gather vs the pair rule explicitly, so its +`diff` is independent of the route the decoder currently takes). E7's 24 is +corroborated by a second, committed instrument: the route counter +`IBC_OWNED_RECT_422_PAIR_HITS` reads exactly 24 in the gate. + +The probe (`EC_IBCNS422P`, env-gated, both arms, printing the luma-span +gather vs the pair rule) was **removed before the commit** — no probe and no +`EC_AV1_ALLOW_422_PROBE` remains in the tree. + +## 4. The fix + +`decode.rs`, `decode_intrabc_owned_rect` only: + +* tree branch: `let around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + hit!(IBC_OWNED_RECT_422_PAIR_HITS); neighbours.around_mi_422_chroma(…) } + else { neighbours.around_mi_rect(…) };` (plane 0 unused in this branch); +* twin branch: the same gate on a NEW `around_chroma` used by planes 1/2; + `around` stays the plain luma-span read that plane 0's own context uses + (`ss_x == 0` / `ss_y != 0` keep it for chroma too, verbatim); +* new counter `IBC_OWNED_RECT_422_PAIR_HITS` + accessor/reset + (`ibc_owned_rect_422_pair_hits`), in the crate's `hit!` pattern. + +The census's stale comment at the tree branch ("UNWITNESSED", "the only +`around_mi_rect` …") was replaced by the dated routing comment; it also +records the honest residue: the tree branch itself still has **no** stream +that splits a transform on the strip (`TX_MODE_SELECT` + `txfm_partition` on +the 64x32 strip) — the witness enters the twin, and both branches share the +same routed code. + +## 5. Evidence + +* **Gate**: `a_422_intrabc_owned_rect_nonsplit_chroma_context_uses_the_pair_rule` + (`stream.rs`) — pins size 2170 + fnv1a64 `0x92e2c4e45ca27e34` + sha256, + asserts `assert_422_stream_pixel_exact(…, 384, 288, 4, 8, true)` (ffmpeg + `yuv422p`, per-plane coefficient-unit census deltas + `units=[149, 219, 225] coded=[126, 27, 98]`, all non-zero), asserts the + route fired exactly **24** times, and asserts the 4:4:4 `r512.obu` arm + fires it **0** times (guard-does-not-leak arm). +* **Red-before (mutation proof)**: with both routed conditions forced + `if false` (temporary, reverted), the gate FAILS on the same pinned bytes: + `decode_stream refused a real 4:2:2 stream: … a block size 4x8, 8x16 or + 16x4 … has no chroma plane block at this frame's subsampling mode`. +* **Green-after**: 4/4 frames byte-exact vs ffmpeg; counter 24; gate + the + 422 `sb128_strip` gate + `a_16x4_intrabc_pair_strip_decodes_pixel_exact` + (4:2:0) + `a_444_intrabc_owned_rect_strip_sizes_its_chroma_plane_block_and_decodes` + (4:4:4) all pass in one scoped run (`4 passed; 846 filtered out`, + 1.8 s). Scoped tests only; no full suite. +* `cargo check -p ec-av1` clean (the one pre-existing `pin_reporting` + dead-code warning, unrelated). + +## 6. Findings for other lanes (measured here, not fixed here) + +1. **The pre-fix refusal on E6/E7 was a DESYNC SYMPTOM, not a real + sub-8x8 shape.** Pre-fix, our decoder refuses those bytes mid-frame while + **both oracles decode them fully** (`aomdec --rawvideo` → exit 0, + 884736 B = 4×221184; ffmpeg → 884736 B). Post-fix (same bytes, route + fixed) the refusal is gone and the decode is byte-exact. So the wrong + `dc_sign_ctx` → wrong dc-sign symbol → desync → the subsize guard fires on + garbage. The refusal string itself is libaom's + `decodeframe.c:1456` rule, but its trigger here was ours. `lane-av1422ibcrect`'s + A2/A4 refusals were NOT re-examined by this lane; their streams were not + measured against aomdec here. +2. **`scripts/fixture-library.tsv` needs a canonical-environment + regeneration** (deferred, unblock: run + `scripts/gen-fixture-library.sh` where `$ROOT/fixtures` is the real + library). Measured: regenerating on a **pristine `git archive` of + `6d646f65` with no edits** already differs from the committed manifest by + 651 diff lines here (e.g. "212" vs "48" unresolved media literals, + double-slash `fixtures//…` rows), and even with + `EC_FIXTURES=/fixtures` the output is not idempotent with HEAD's + file (dropped `encode.rs` rows, unreferenced-pin count 4→6). So this lane + does NOT commit manifest churn; the new fixture's row (measured: + `crates/ec-av1/fixtures/ibc422_nonsplit_ctx.obu crates/ec-av1/src/stream.rs:3587 … 4f82d5da…`) + and the stream.rs line shifts will land with that regeneration. +3. Process note (recorded for truthfulness): during the mutation proof a + bulk in-place replace of the routed-condition line matched a THIRD, + pre-existing site in another function (`around_mi_422_chroma(pair_mi, pw, ph)` + at base `19863-19872`). It was restored exactly and verified: the final + `git diff` hunks touch only statics/accessors and + `decode_intrabc_owned_rect` in `decode.rs`, and that function's text is + byte-identical to HEAD outside the intended hunks. + +## 7. Repro + +```text +git worktree add -b lane/av1422ibctxsel ~/.cache/wt/av1422ibctxsel 6d646f65 +cd ~/.cache/wt/av1422ibctxsel + +# witness (E7): aomenc = ~/.cache/aom-oracle/build/aomenc +ffmpeg -v error -f lavfi -i "nullsrc=size=384x288:rate=25,format=yuv420p,\ + geq=lum='128+90*sin((X+2*N)/37)+30*sin(Y/29)+40*sin(X*1.5707963)*(lt(X,64)*lt(Y,32))':\ + cb='128+30*sin(X/23)':\ + cr='128+30*sin((Y+N)/19)+25*if(between(Y,0,31),1,0)+30*if(between(Y,96,127),1,0)'" \ + -frames:v 4 -pix_fmt yuv422p -strict -1 -f yuv4mpegpipe -y E7.y4m +aomenc --codec=av1 --i422 --profile=2 --passes=1 --end-usage=q --cpu-used=0 \ + --threads=1 --row-mt=0 --lag-in-frames=0 --kf-max-dist=1 --tile-columns=0 \ + --sb-size=64 --min-partition-size=32 --max-partition-size=64 \ + --enable-rect-partitions=1 --enable-ab-partitions=1 --enable-1to4-partitions=0 \ + --enable-palette=0 --tune-content=screen --enable-intrabc=1 --deltaq-mode=0 \ + --enable-tx-size-search=1 --obu --cq-level=32 --limit=4 -o E7.obu E7.y4m +sha256sum E7.obu # 4f82d5da8b4c3d6553953fc373001a1c7a729c9b189214b65503af1e04eb6b68 + +# gate (green) +CARGO_TARGET_DIR=~/.cache/tgt-av1422ibctxsel \ + cargo test -p ec-av1 --lib a_422_intrabc_owned_rect_nonsplit_chroma_context_uses_the_pair_rule +``` + +`E7` = `crates/ec-av1/fixtures/ibc422_nonsplit_ctx.obu` (byte-identical).