From b86686a78ba61f20dd9a9020a5d02fee3d18835e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 28 Sep 2026 12:34:25 +0300 Subject: [PATCH] lane-av1422warp: gate the 32x16 strip reader's 4:2:2 chroma dc-sign vote decode_block_rect built its chroma vote with `around_rect` and no 4:2:2 rerouting -- the sibling decode_leaf_rect, which lane's round-6 fix gated, was not. At ss (1,0) that strip's chroma is a square (side/2, side) block whose above cells spread over `side` LUMA mi columns, so the per-mi rect gather double-counts every chroma column's whole-unit dc sign. Found with the EC_SYMR sequence diff (see the report): of 46260 symbol reads on a1_f0.obu, reads 0..45259 pair EXACTLY on value, range, CDF row (32768 - ours == oracle), alphabet, symbol and post-read range, and read 45260 is the first divergence -- the chroma-U 4x4 transform of the 32x16 strip at mi(68,16), whose DC sign this decoder reads from dc_sign_ctx 1 where libaom reads row 0. Same position, same symbol, same bits, different row: the signature the ladder cannot see. After the fix all 46260 reads match at state level (the only residual difference is the `bit` field over the last 17 reads, which is the reference's own buffer-end tell convention). Frame 0 is PIXEL-EXACT against aomdec for the first time on this stream; the 16-frame measure goes 0/16 -> 3/16 frames exact and 1619115 -> 1332125 differing samples. Identity, all four unchanged: the 4:2:0 control a420.obu byte-identical to aomdec --rawvideo; 444_sb128rect_lr_witness.obu byte-identical to the pre-lane build; pinned 422_allskip_2f.obu and 422_sb128_3f.obu still pixel-exact against aomdec. The gate is ss (1,0), so 4:2:0 and 4:4:4 never reach the sampler. Also restores EC_SYMR in SymbolDecoder::symbol (msac.rs), which an earlier `git checkout` in this lane had wiped along with the oracle's copy; the format follows skill ec-av1-consumption-gap-symr Step 3. --- crates/ec-av1/src/decode.rs | 23 ++++++++++++++++++++++- crates/ec-av1/src/msac.rs | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 2d63ed33..d2dee2b7 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -13256,7 +13256,28 @@ fn decode_block_rect( // --enable-tx-size-search=0 the encoder writes no such symbol, so the // decoder consumed one that was never there. { - let around = neighbours.around_rect(at, bw, bh); + // lane-av1422warp r20: this 32x16/16x32 strip reader is the SIBLING of + // `decode_leaf_rect`, and it was the one left ungated: at ss (1,0) the + // strip's chroma is a square (side/2, side) block whose above cells + // spread over `side` LUMA mi columns, so the per-mi rect gather + // double-counts every chroma column's whole-unit dc sign. Measured on + // the pinned 4:2:2 rotzoom stream (a1.obu frame 0): the chroma-U 4x4 + // transform of the 32x16 strip at mi(68,16) reads its DC sign from + // `dc_sign_ctx` 1 where libaom reads row 0 -- the first read of + // 45260 whose pre-state, bit position and symbol all match and only + // the CDF row differs, and the first divergence in the EC_SYMR + // sequence (all 45259 reads before it pair exactly). Luma keeps the + // per-mi gather; 4:2:0 and 4:4:4 keep the plain rect walk verbatim. + let mut around = neighbours.around_rect(at, bw, bh); + if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + let c2 = neighbours.around_mi_422_chroma( + (at.0 * (SUB / MI), at.1 * (SUB / MI)), + bw, + bh, + ); + around[1] = c2[1]; + around[2] = c2[2]; + } let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x16, fi_tx_row(mode, filter_intra)); let (luma_levels, luma_tx_type) = read_coeffs_rect( dec, diff --git a/crates/ec-av1/src/msac.rs b/crates/ec-av1/src/msac.rs index 9e7548f8..c0e66234 100644 --- a/crates/ec-av1/src/msac.rs +++ b/crates/ec-av1/src/msac.rs @@ -396,8 +396,18 @@ impl<'a> SymbolDecoder<'a> { } /// `decode_symbol` (spec 8.2.6), with the adaptation of 8.3.2. + /// + /// `EC_SYMR=1` dumps every symbol read's PRE state (before the read and + /// before the adaptation) together with the symbol and the post-read + /// range, so a divergence against a reference decoder can be bisected + /// read by read. `cdf0` is the PRE-adapt row[0] -- the reference's own + /// print of the same row is POST-adapt, so compare `32768 - ours_cdf0` + /// against its `cdf0`, never the raw numbers. #[inline] pub fn symbol(&mut self, cdf: &mut [u16]) -> usize { + let symr = std::env::var_os("EC_SYMR").is_some(); + let (pre_value, pre_range, pre_bit) = (self.value, self.range, self.bit); + let pre_cdf0 = cdf.first().copied().unwrap_or(0); // lane-census: the syntax census charges this symbol's bits to the // TABLE it read, so every coding tool is accounted without a // per-call-site label. Off (`EC_AV1_BITCENSUS` unset) this is one @@ -419,6 +429,18 @@ impl<'a> SymbolDecoder<'a> { if crate::census::armed() { crate::census::charge(cdf.as_ptr() as usize, self.tell_bits() - t0); } + if symr { + eprintln!( + "EC_SYMR pre=({},{},{}) cdf0={} n={} s={} post_rng={}", + pre_value, + pre_range, + pre_bit, + pre_cdf0, + cdf.len() - 1, + s, + self.range + ); + } s }