From 366e4bc77a66d42ed737a1d9b2edfbaf08cc5416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 30 Sep 2026 02:54:02 +0300 Subject: [PATCH] ec-av1: lane-av1txctxband -- get_tx_size_context must read the block covering the ABUTTING CELL, not the last block written in the column libaom's get_tx_size_context (pred_common.h:361-370) gates its inter-neighbour override on xd->above_mbmi / xd->left_mbmi, which set_mi_offsets takes as xd->mi[-mi_stride] / xd->mi[-1] (av1_common_int.h:1381-1389); setup_mbs (decodeframe.c:355-361) writes the covering block's own MB_MODE_INFO pointer into EVERY mi cell the block covers, so the granularity is the covering block PER CELL. This decoder read the per-COLUMN above_inter/left_inter bands and the per-column above_side_mi/left_side_mi bands -- the last block written in that column, which names the abutting block only for the block directly below it. On a 4:4:4 lossy --sb-size=128 cq-62 256x256 stream the 8x4 intra leaf at mi(57,52) read a stale above_inter=true with above_side=4 while the covering block of cell (56,52) is 8 px wide, so the override fired with 4, above came out 0 where libaom keeps 1, ctx came out 1 instead of 2, and tx_size_cat0[1] was read where libaom reads row 2 -- the EC_SYMR fork at read 32813 (identical pre-state (7550,45492), identical n=2 s=1, only cdf0 differing: ours 6424 -> 26384 vs oracle 19938, so not even the ICDF mirror convention). New Neighbours::inter_grid (per 4x4 mi cell) carries is_inter_block of the covering block, written by exactly the three places that already wrote the bands: record_inter_rect_mi, record_intrabc_mi_rect, and fill_lf_grid_rect's intra-only clear. The covering block's own size comes from blk_grid's existing per-mi BlkCell::dim, so no new size array. Both readers (tx_size_context_txfm_rect and tx_size_context_txfm) gate and size the override from inter_at(mi_r-1, mi_c) / inter_at(mi_r, mi_c-1) and blk_side_at(..); the TXFM_CONTEXT bands and the tile-border guards are untouched. red-before (unpatched a1f818a9): frame 0 Y 841 / U 1295 / V 1372 of 65536, frame 1 Y 56986 / U 55974 / V 56442; EC_SYMR 41245 vs 37229 reads, fork at 32813 green: 0/0/0 on both frames; EC_SYMR 37229/37229 with ZERO divergence over the whole stream class sweep: 99 cells of 4:4:4 lossy --sb-size=128 (10 sources x cq 30..62) all EXACT-ENTROPY; 12 of them forked before and 4 of those also exited non-zero new pin 444_lossy_sb128_txctx_witness.obu (6186 B, sha256 14acb74e...) and gate a_444_lossy_sb128_txctx_reads_the_covering_block_per_cell, whose non-vacuity arm is TXCTX_INTER_CELL_BAND_DIVERGENCE_HITS (reads whose RESOLVED term differs between the two models): green 1, and RED on the band-revert mutation. The counter counts resolved terms, not booleans -- on this stream the two is_inter booleans agree and the SIZE term is what is stale. neighbours re-quoted: 44 passed (444_lossy/444_rect/444_intrabc_rect4/ ll444/lossless/intrabc_rect), 43 passed 2 pre-existing ignored (420/sb128/tile_rows/tilerows/intrabc/av1real_aomenc) Named, not swept: av1_get_intra_inter_context and the ref_ctx family read the same per-column is_inter bands and share the granularity hazard; nothing observed them here. txfm_partition_context reads only the TXFM bands and is correct as it stands. scripts/fixture-library.tsv NOT regenerated: it records a file:line for every fixture reference in the crate, so regenerating it in a feature lane produces a 501-line diff that collides with every sibling touching decode.rs/stream.rs. It belongs to the post-wave merge (the row it yields is in the report). --- .../444_lossy_sb128_txctx_witness.obu | Bin 0 -> 6186 bytes crates/ec-av1/src/decode.rs | 226 ++++++++++++- crates/ec-av1/src/stream.rs | 94 ++++++ lanes/av1txctxband.report.md | 301 ++++++++++++++++++ 4 files changed, 609 insertions(+), 12 deletions(-) create mode 100644 crates/ec-av1/fixtures/444_lossy_sb128_txctx_witness.obu create mode 100644 lanes/av1txctxband.report.md diff --git a/crates/ec-av1/fixtures/444_lossy_sb128_txctx_witness.obu b/crates/ec-av1/fixtures/444_lossy_sb128_txctx_witness.obu new file mode 100644 index 0000000000000000000000000000000000000000..78625b64dcaf84814c6a09bf0e2c904142962d09 GIT binary patch literal 6186 zcmV+_7}e(z0165q000BO|NFJ`1TwoU6ab;{5cwU*eOxCg7iUL{tCna;Z-k)sFeUmT zS_y@iyH@}Oo|6mI!dDE zR$E#tz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%xw8nv z4su^ESaVm{Ol{mIO8JZ@h}u~-I!bq#6pp=;O7&M`oup5`ip6-qws15Pg>?gWWy!g)k8@%)TE(aD1c@uL6Y5{>Dt zt9aj1^>n!;DfK7>Lx7(svsY$pIlI}UY$@#H6Z=p-?Ea)rXny9arKHBRrbQ9bsG^FF zIm7fdRNFxWnd9G4B%$UccDT#2`Fdla?~z$Yv9D1$-LhhJ0Lo+!9g$-P=Cc8KHH;l- zt9;YmMPt}t(>j|y88b2}_JRhd^rV?d^78~)jL_o1u@k!UNC-0z#1fMV=|}Ni>b10z z*H~g%Y?|+-ZVsfEJbbg>S1)9V4AEb?PoyHLvN@qEJNP%YtMhLqfo+$6Ly_1L05aJF zG6BFq0009_fDSE01(cpvfB?X&S?cZGj*mghw_|>(gJ|!2OG{ie(`dtjdddqz%}djZA>-p~3Vh!3hf zU*-HT^OfoOQ|~qMtceig#rQ;w%8QqRdTDH3B|d*t&Fe{s%xcg zV%Qj4gBqs&^8Mxytb6vOHc4OF&I})1qG0$2Ky8tZ2>Rg3BB7oWCVN%2=f(|1PW5ap zfCki{USO;TfB>^zbb=k|ywTv`B`JENl%d<2weKkpFm2&!zX(9>m~;p-vc7Y)6f}E( z4P`g`-5>T}tyl%8I$_rt!`Fj8MLyJW1Xa8p)bud zTdhEJ4kdO!GlZpCCJ~+j0f;WS`CG*6%}I0s+axcQ7m^!Z*C6 I3XG3229+uh@c;k- literal 0 HcmV?d00001 diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index b3541c02..9b93baa4 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -5043,6 +5043,11 @@ fn record_intrabc_mi_rect( *cell = true; } } + // lane-av1txctxband: the per-CELL `is_inter_block` an INTRABC block + // publishes (`blockd.h:372-374` counts it), at the granularity + // `get_tx_size_context` reads it. The band above is one slot per + // column and so survives every later block in that column. + n.mark_inter_grid_rect((mi_r, mi_c), n4_w, n4_h, true); } fctx.intrabc_mi_grid.with(|g| { let mut g = g.borrow_mut(); @@ -5885,6 +5890,30 @@ thread_local! { pub(crate) fn txctx_deblock_divergence_hits() -> usize { TXCTX_DEBLOCK_DIVERGENCE_HITS.with(std::cell::Cell::get) } +// lane-av1txctxband: how many `get_tx_size_context` reads the per-CELL +// `is_inter_block` cover and the per-COLUMN `above_inter`/`left_inter` bands +// DISAGREE about -- i.e. exactly the reads whose CDF row the old code chose +// wrongly. Green on the old code too (a plain "some block was inter" tally +// would be), so this is the non-vacuity arm of the witness gate: it is 0 on +// every stream where the bands happened to be right and non-zero on the +// 4:4:4 lossy `--sb-size=128` cq-62 stream whose entropy forked at read 32813 +// on the 8x4 intra leaf at mi(57,52). +thread_local! { + static TXCTX_INTER_CELL_BAND_DIVERGENCE_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`TXCTX_INTER_CELL_BAND_DIVERGENCE_HITS`]. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gate +pub(crate) fn txctx_inter_cell_band_divergence_hits() -> usize { + TXCTX_INTER_CELL_BAND_DIVERGENCE_HITS.with(std::cell::Cell::get) +} + +/// Zeroes [`TXCTX_INTER_CELL_BAND_DIVERGENCE_HITS`]. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gate +pub(crate) fn reset_txctx_inter_cell_band_divergence_hits() { + TXCTX_INTER_CELL_BAND_DIVERGENCE_HITS.with(|c| c.set(0)); +} // lane-intra14 r1: how many intra-coded 1:4 strips decoded on the INTER // block path, per shape -- [0] 64x16, [1] 16x64, [2] 32x8, [3] 8x32. Every @@ -8931,6 +8960,26 @@ struct Neighbours { /// pixels, which for chroma is `max(luma_dim / 2, 4)` (lane-t900 r30b). blk_grid: Vec, skip_grid_cols_mi: usize, + /// Per-4x4-mi `is_inter_block` of the coded block COVERING that cell -- + /// lane-av1txctxband. libaom's `get_tx_size_context` + /// (`av1/common/pred_common.h:361-370`) gates its "an inter neighbour + /// contributes its own BLOCK size" override on `xd->above_mbmi` / + /// `xd->left_mbmi`, which `set_mi_offsets` takes as `xd->mi[-mi_stride]` + /// / `xd->mi[-1]`: the block whose bottom (left) edge abuts THIS block's + /// top (right) edge at THIS cell. `setup_mbs` (`decodeframe.c:355-361`) + /// writes that pointer into EVERY mi cell a block covers, so libaom's + /// granularity is the covering block PER CELL -- not one slot per column. + /// [`Self::above_inter`]/[`Self::left_inter`] are per-COLUMN bands holding + /// the LAST block written in that column, which is the covering block only + /// for the block immediately below it: on a 4:4:4 lossy `--sb-size=128` + /// cq-62 stream the 8x4 intra leaf at mi(57,52) read `above_inter` as + /// `true` (stale, from an intrabc block earlier in column 52) with + /// `above_side_mi` 4, took the override, and read `tx_size_cat0[1]` where + /// libaom reads row 2 -- the `EC_SYMR` fork at read 32813. + /// Written by exactly the three places that already write the bands: + /// [`Self::record_inter_rect_mi`], `record_intrabc_mi_rect` and + /// `fill_lf_grid_rect`'s intra-only clear. + inter_grid: Vec, /// Per-4x4-mi luma transform width in pixels (8/16/32/64) -- this decoder /// never splits a coded block's transform below its own size (round 2: /// `TxMode::Select`/`tx_depth` refused), so a block's own side *is* its @@ -9065,6 +9114,7 @@ impl Neighbours { cols * (SUB / MI) * rows * (SUB / MI) ], skip_grid_cols_mi: cols * (SUB / MI), + inter_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)], tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], uv_tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], @@ -9551,6 +9601,12 @@ impl Neighbours { *cell = false; } } + // lane-av1txctxband: the same clear at libaom's own per-CELL + // granularity. The band above clears one slot per column, so a + // block that covered column 52 and a later block in the SAME + // column but a different row leave the band describing whichever + // wrote last; the grid clears exactly the cells this block owns. + self.mark_inter_grid_rect(at_mi, w_mi, h_mi, false); } // lane-av1-intrabc r4: publish this coded block's own mi footprint // into the intrabc MV grid's block-COVERAGE map -- every coded block, @@ -9628,6 +9684,55 @@ impl Neighbours { ); } } + /// Publishes one coded block's `is_inter_block` over EVERY 4x4 mi cell it + /// covers -- lane-av1txctxband. libaom's `setup_mbs` + /// (`decodeframe.c:355-361`) writes the block's own `MB_MODE_INFO` + /// pointer into all of them, so `xd->mi[-xd->mi_stride]` / + /// `xd->mi[-1]` name the block COVERING the cell, not "the last block + /// written in this column" ([`Self::above_inter`] / + /// [`Self::left_inter`], which is a per-column band and therefore stale + /// for any block below the last writer in its column). + /// Separate from [`Self::fill_skip_grid_rect`] because the two publishers + /// run in BOTH orders at different call sites; both write disjoint fields, + /// so the order does not matter. The value read is libaom's + /// `is_inter_block` (`blockd.h:372-374`): an INTRABC block counts. + fn mark_inter_grid_rect( + &mut self, + at_mi: (usize, usize), + w_mi: usize, + h_mi: usize, + is_inter: bool, + ) { + for rr in 0..h_mi { + let start = (at_mi.0 + rr) * self.skip_grid_cols_mi + at_mi.1; + fill_span(&mut self.inter_grid, start, w_mi, is_inter); + } + } + + /// `is_inter_block` of the coded block covering the mi cell + /// `(mi_r, mi_c)`, or `false` for a cell no block has written yet (a tile + /// border or a not-yet-decoded cell) -- lane-av1txctxband. The caller's + /// `up_available` / `left_available` guard already excludes the borders. + fn inter_at(&self, mi_r: usize, mi_c: usize) -> bool { + self.inter_grid + .get(mi_r * self.skip_grid_cols_mi + mi_c) + .copied() + .unwrap_or(false) + } + + /// The covering block's own `(block_size_wide, block_size_high)` in + /// pixels at the mi cell `(mi_r, mi_c)`, from [`Self::blk_grid`]'s `dim` + /// (the published mi extent) scaled by [`MI`] -- lane-av1txctxband. This + /// is libaom's `block_size_wide[above_mbmi->bsize]` / + /// `block_size_high[left_mbmi->bsize]`, read at the abutting CELL rather + /// than from the per-column [`Self::above_side_mi`] / + /// [`Self::left_side_mi`] band. + fn blk_side_at(&self, mi_r: usize, mi_c: usize) -> (usize, usize) { + self.blk_grid + .get(mi_r * self.skip_grid_cols_mi + mi_c) + .filter(|c| c.written) + .map_or((0, 0), |c| (c.dim[0] as usize * MI, c.dim[1] as usize * MI)) + } /// Whether the 8x8 luma block at mi position `(mi_r, mi_c)` (2x2 mi /// cells) was `skip_txfm` -- [`apply_cdef`]'s dlist membership test. @@ -9795,6 +9900,9 @@ impl Neighbours { self.record_mode_mi(r, c, w_mi, h_mi, DC_PRED); self.record_uv_mode_mi(r, c, w_mi, h_mi, DC_PRED); } + // lane-av1txctxband: the per-CELL `is_inter_block` the per-column + // `above_inter` band stands in for, at libaom's own granularity. + self.mark_inter_grid_rect(at_mi, w_mi, h_mi, is_inter); let altref = is_inter && ref_frame == crate::mvstack::ALTREF_FRAME; self.above_skip[c..c + w_mi].fill(skip); self.above_skip_mode[c..c + w_mi].fill(skip_mode); @@ -28297,17 +28405,56 @@ fn tx_size_context_txfm_rect( let has_left = mi_c > n.tile_col0_mi; let mut above = usize::from(n.above_txfm[mi_c]) >= own_w; let mut left = usize::from(n.left_txfm[mi_r]) >= own_h; - if has_above && n.above_inter[mi_c] { - above = usize::from(n.above_side_mi[mi_c]) >= own_w; - } - if has_left && n.left_inter[mi_r] { - left = usize::from(n.left_side_mi[mi_r]) >= own_h; + // lane-av1txctxband: the override's gate and its size term are read at + // the ABUTTING CELL -- libaom's `xd->above_mbmi` is `xd->mi[-mi_stride]` + // and `xd->left_mbmi` is `xd->mi[-1]` (`set_mi_offsets`, + // av1_common_int.h:1381-1389), which `setup_mbs` fills with the pointer + // of the block COVERING that cell (decodeframe.c:355-361). The old code + // read the per-COLUMN `above_inter`/`left_inter` bands and the matching + // `above_side_mi`/`left_side_mi` bands, i.e. the LAST block written in + // that column, which names the abutting block only for the block directly + // below it. Measured: on the 4:4:4 lossy `--sb-size=128` cq-62 stream the + // 8x4 intra leaf at mi(57,52) saw a stale `above_inter=true` (from an + // intrabc block earlier in column 52) with `above_side=4`, took the + // override, and read `tx_size_cat0[1]` where libaom reads row 2. + if has_above && n.inter_at(mi_r - 1, mi_c) { + above = usize::from(n.blk_side_at(mi_r - 1, mi_c).0) >= own_w; + } + if has_left && n.inter_at(mi_r, mi_c - 1) { + left = usize::from(n.blk_side_at(mi_r, mi_c - 1).1) >= own_h; + } + // lane-av1txctxband: the non-vacuity arm. It counts the reads whose + // RESOLVED context term differs from what the old per-column bands would + // have produced -- not merely reads where the two `is_inter` booleans + // disagree, because on the measured witness they AGREE (`above_inter` and + // the per-cell cover are both true at mi(57,52)) and it is the SIZE term + // that is stale (band 4 vs the covering block's own 8), which is what put + // the read on `tx_size_cat0[1]` instead of row 2. + { + let band_above = has_above + && if n.above_inter[mi_c] { + usize::from(n.above_side_mi[mi_c]) >= own_w + } else { + usize::from(n.above_txfm[mi_c]) >= own_w + }; + let band_left = has_left + && if n.left_inter[mi_r] { + usize::from(n.left_side_mi[mi_r]) >= own_h + } else { + usize::from(n.left_txfm[mi_r]) >= own_h + }; + if band_above != (has_above && usize::from(above) != 0) + || band_left != (has_left && usize::from(left) != 0) + { + hit!(TXCTX_INTER_CELL_BAND_DIVERGENCE_HITS); + } } if crate::envflags::env_flag!("EC_TXCTX") { eprintln!( "EC_TXCTX mi={mi_r},{mi_c} own={own_w}x{own_h} ha={has_above} hl={has_left} \ intra_only={} above_txfm={} left_txfm={} above_inter={} left_inter={} \ - above_side={} left_side={} above={above} left={left}", + above_side={} left_side={} above={above} left={left} \ + | cell_inter ab={} lb={} ab_side={} lb_side={}", fctx.intra_only.with(std::cell::Cell::get), n.above_txfm[mi_c], n.left_txfm[mi_r], @@ -28315,6 +28462,21 @@ fn tx_size_context_txfm_rect( n.left_inter[mi_r], n.above_side_mi[mi_c], n.left_side_mi[mi_r], + // lane-av1txctxband: the per-CELL terms this read now uses, next to + // the per-column bands it used to use, so a divergence names which + // of the two disagreed. + has_above + .then(|| n.inter_at(mi_r - 1, mi_c)) + .unwrap_or(false), + has_left + .then(|| n.inter_at(mi_r, mi_c - 1)) + .unwrap_or(false), + has_above + .then(|| n.blk_side_at(mi_r - 1, mi_c).0) + .unwrap_or(0), + has_left + .then(|| n.blk_side_at(mi_r, mi_c - 1).1) + .unwrap_or(0), ); } let ctx = match (has_above, has_left) { @@ -28352,23 +28514,63 @@ fn tx_size_context_txfm(n: &Neighbours, (mi_r, mi_c): (usize, usize), side: usiz // 16x16 intra block whose left neighbour is an inter block at mi row 4 // then missed libaom's "an inter neighbour contributes its BLOCK size" // override and read `tx_size_cat1` row 1 where aomdec reads row 2. - if has_above && n.above_inter[mi_c] { - above = usize::from(n.above_side_mi[mi_c]) >= side; - } - if has_left && n.left_inter[mi_r] { - left = usize::from(n.left_side_mi[mi_r]) >= side; + // lane-angledelta r1 (class [[context-read-from-one-cell]]) fixed the + // `/ (SUB / MI)` on this pair; lane-av1txctxband fixes what it could not: + // the bands are per COLUMN, so they name the last block written in the + // column, not the block covering the abutting cell. libaom's + // `xd->above_mbmi` is `xd->mi[-xd->mi_stride]` and `xd->left_mbmi` is + // `xd->mi[-1]` (`set_mi_offsets`, av1_common_int.h:1381-1389), and + // `setup_mbs` (decodeframe.c:355-361) writes the covering block's own + // pointer into every mi cell the block covers. + if has_above && n.inter_at(mi_r - 1, mi_c) { + above = usize::from(n.blk_side_at(mi_r - 1, mi_c).0) >= side; + } + if has_left && n.inter_at(mi_r, mi_c - 1) { + left = usize::from(n.blk_side_at(mi_r, mi_c - 1).1) >= side; + } + // lane-av1txctxband: the non-vacuity arm (see the rect form above). + { + let band_above = has_above + && if n.above_inter[mi_c] { + usize::from(n.above_side_mi[mi_c]) >= side + } else { + usize::from(n.above_txfm[mi_c]) >= side + }; + let band_left = has_left + && if n.left_inter[mi_r] { + usize::from(n.left_side_mi[mi_r]) >= side + } else { + usize::from(n.left_txfm[mi_r]) >= side + }; + if band_above != (has_above && usize::from(above) != 0) + || band_left != (has_left && usize::from(left) != 0) + { + hit!(TXCTX_INTER_CELL_BAND_DIVERGENCE_HITS); + } } if crate::envflags::env_flag!("EC_TXCTX") { eprintln!( "EC_TXCTX mi={mi_r},{mi_c} own={side} ha={has_above} hl={has_left} \ above_txfm={} left_txfm={} above_inter={} left_inter={} above_side={} left_side={} \ - above={above} left={left}", + above={above} left={left} | cell_inter ab={} lb={} ab_side={} lb_side={}", n.above_txfm[mi_c], n.left_txfm[mi_r], n.above_inter[mi_c], n.left_inter[mi_r], n.above_side_mi[mi_c], n.left_side_mi[mi_r], + has_above + .then(|| n.inter_at(mi_r - 1, mi_c)) + .unwrap_or(false), + has_left + .then(|| n.inter_at(mi_r, mi_c - 1)) + .unwrap_or(false), + has_above + .then(|| n.blk_side_at(mi_r - 1, mi_c).0) + .unwrap_or(0), + has_left + .then(|| n.blk_side_at(mi_r, mi_c - 1).1) + .unwrap_or(0), ); } match (has_above, has_left) { diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index f3708dd8..c372e945 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -8278,6 +8278,100 @@ pub(crate) mod tests { fn a_444_lossy_256x128_stream_decodes_pixel_exact() { gate_444_lossy_live_exact("a_444_lossy_256x128_stream_decodes_pixel_exact", 256, 128); } + /// lane-av1txctxband — the 4:4:4 lossy `--sb-size=128` stream whose + /// `EC_SYMR` ladder forked at read 32813, and the gate that makes the fix + /// non-vacuous. + /// + /// **The defect.** `get_tx_size_context` (libaom + /// `av1/common/pred_common.h:361-370`) gates its "an inter neighbour + /// contributes its own BLOCK size" override on `xd->above_mbmi` / + /// `xd->left_mbmi`, which `set_mi_offsets` + /// (`av1_common_int.h:1381-1389`) takes as `xd->mi[-xd->mi_stride]` / + /// `xd->mi[-1]`. `setup_mbs` (`decodeframe.c:355-361`) writes the covering + /// block's own `MB_MODE_INFO` pointer into EVERY mi cell the block covers, + /// so libaom's granularity is the covering block PER CELL. This decoder + /// read the per-COLUMN `above_inter`/`left_inter` bands and the matching + /// `above_side_mi`/`left_side_mi` bands instead — the LAST block written in + /// that column, which names the abutting block only for the block directly + /// below it. On this witness the 8x4 intra leaf at mi(57,52) (SB row 1, + /// col 1) read a stale `above_inter=true` with `above_side=4`, took the + /// override, got `above = (4 >= 8) = 0` where libaom keeps + /// `above = (above_txfm_context[0] >= 8) = 1`, and read + /// `tx_size_cat0[1]` where libaom reads `tx_size_cdf[...][2]`. + /// + /// **The fork signature that identifies it** (a CDF-row error, not a + /// unit-enumeration one): the two sides held the IDENTICAL pre-state + /// `pre=(7550, 45492)` and the IDENTICAL width/value `n=2 s=1`; only + /// `cdf0` differed, ours 6424 (`32768-6424 = 26344`) vs the oracle's + /// 19938, so the ICDF mirror convention does not reconcile it either. + /// + /// **Non-vacuity.** The pixel assert alone would be green on the old code + /// for any stream where the bands happened to be right, so the gate also + /// asserts `txctx_inter_cell_band_divergence_hits() > 0` — the number of + /// `get_tx_size_context` reads where the per-CELL cover and the + /// per-COLUMN band DISAGREE, i.e. exactly the reads the old code resolved + /// off a different CDF row. Reverting either reader to the bands drives + /// this to 0 and the gate red, with the oracle compare as the second, + /// independent arm. + /// + /// **Fixture provenance** (`444_lossy_sb128_txctx_witness.obu`, 6186 B, + /// sha256 `14acb74e825a2bb3ef195a52cc2abc67794d9c4d92080b66c739d318177fc7c6`): + /// ```text + /// ffmpeg -f lavfi -i "testsrc2=size=256x256:rate=25" -frames:v 2 \ + /// -pix_fmt yuv444p -strict -1 -f yuv4mpegpipe -y src.y4m + /// aomenc --codec=av1 --passes=1 --end-usage=q --cq-level=62 --cpu-used=2 \ + /// --threads=1 --row-mt=0 --lag-in-frames=0 --kf-max-dist=100 \ + /// --sb-size=128 --profile=1 --obu -o t256.obu src.y4m + /// ``` + /// 256x256 is the smallest geometry that gives `--sb-size=128` a SECOND + /// superblock row and column, which is where the stale band bites: a cell + /// whose abutting block is not the last block written in its column. The + /// cq level is load-bearing — this cell is entropy-exact at cq 20..58 and + /// forks at 54/56/60/62 depending on the frame count (12 of the 99 cells + /// swept in `lanes/av1txctxband.report.md` §4 forked, all of them at + /// cq >= 54 on 256x256/320x240/256x384). `--sb-size=128` is load-bearing + /// too: at the default 64 the two superblock columns are 4 mi wide, so a + /// column band and a per-cell cover coincide for every 4-column run. + #[test] + fn a_444_lossy_sb128_txctx_reads_the_covering_block_per_cell() { + const NAME: &str = "a_444_lossy_sb128_txctx_reads_the_covering_block_per_cell"; + let path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("fixtures/444_lossy_sb128_txctx_witness.obu"); + let bytes = std::fs::read(&path).unwrap_or_else(|e| { + panic!( + "{NAME}: pinned fixture {} is missing ({e}) -- a failure, not a skip", + path.display() + ) + }); + assert_eq!(bytes.len(), 6186, "{NAME}: fixture length moved"); + assert_eq!( + fnv1a64(&bytes), + 0x2ec1_bb1b_5196_c4b3, + "{NAME}: fixture bytes moved" + ); + + let _guard = lock_gate_counters(); + crate::decode::reset_txctx_inter_cell_band_divergence_hits(); + let frames = decode_stream(&bytes) + .unwrap_or_else(|e| panic!("{NAME}: the pinned 4:4:4 stream was refused: {e}")); + assert_eq!(frames.len(), 2, "{NAME}: frame count"); + let diverged = crate::decode::txctx_inter_cell_band_divergence_hits(); + assert!( + diverged > 0, + "{NAME}: no `get_tx_size_context` read on this stream had the \ + per-CELL cover and the per-COLUMN band disagree, so the witness \ + does not exercise the corrected read at all (class \ + gate-blind-to-feature) -- re-encode per the recipe above" + ); + if aomdec_available(NAME) { + decode_all_frames_vs_oracle(&bytes, NAME); + } + eprintln!( + "{NAME}: {diverged} tx_depth read(s) where the per-cell cover and \ + the per-column band disagreed (the 8x4 intra leaf at mi(57,52) is \ + the one that forked the ladder at read 32813)" + ); + } /// lane-av1444rect r2 — the SAME class as the gate above, second /// instance: `decode_rect4_16_intrabc` applied the 4:2:0 pair geometry at /// ss (0,0), where `is_chroma_reference` makes an intra-BC 1:4 strip its diff --git a/lanes/av1txctxband.report.md b/lanes/av1txctxband.report.md new file mode 100644 index 00000000..1660d1cd --- /dev/null +++ b/lanes/av1txctxband.report.md @@ -0,0 +1,301 @@ +# lane-av1txctxband — `get_tx_size_context` must read the block covering the ABUTTING CELL, not the last block written in the column + +Base / branch: `a1f818a9` (main, "Merge lane-av1sb128fork: the sb128 inter fork +is a CDF-ROW error, not var-tx enumeration") → `lane-av1txctxband`, worktree +`~/.cache/wt/av1sb128fork`. The fix lane for +`lanes/av1sb128fork.report.md`'s narrowed statement. + +Build: `CARGO_TARGET_DIR=/home/user/.cache/tgt-av1txctx` (private). +Oracle: `~/.cache/aom-oracle/build/{aomenc,aomdec}` (instrumented), read-only, +`--threads=1` (rung order identical with and without). + +--- + +## 0. Verdict + +**The band was wrong and the fix is in.** `get_tx_size_context` read a +per-COLUMN `above_inter`/`left_inter` band (and the matching per-column +`above_side_mi`/`left_side_mi`) where libaom reads the block **covering the +abutting mi cell**. On the witness the 8x4 intra leaf at mi(57,52) took the +"an inter neighbour contributes its BLOCK size" override with a **stale side of +4** where the covering block's own width is **8**, so `above` resolved 0 instead +of 1, `ctx` came out 1 instead of 2, and `tx_size_cat0[1]` was read where +libaom reads row 2. + +| | red-before | green | +|---|---|---| +| witness per-plane wrong (frame 0) | Y 841 / U 1295 / V 1372 of 65536 | **0 / 0 / 0** | +| witness per-plane wrong (frame 1) | Y 56986 / U 55974 / V 56442 | **0 / 0 / 0** | +| `EC_SYMR` ladder | 41245 ours vs 37229 oracle, fork at read **32813** | **37229 / 37229, zero divergence over the whole stream** | +| the fork read's `cdf0` | ours 6424 (`32768-6424 = 26344`) vs oracle 19938 | reconciled — the read is no longer divergent | +| `EC_TXCTX mi=57,52` | `above=false left=true` (ctx 1) | `above=true left=true` (ctx 2) = the oracle's row | +| 99-cell class sweep (§4) | 12 forked, 4 of those also `OURS-EXIT1` | **99/99 exact-entropy, no exits** | + +--- + +## 1. Red-before, measured on the unpatched tree + +Branch `lane-av1txctxband` at `a1f818a9`, no source change. The witness +(`t256_n2_cq62.obu`, 6186 B, sha256 `14acb74e825a2bb3ef195a52cc2abc67794d9c4d92080b66c739d318177fc7c6`), +compared per plane against `aomdec --threads=1` with +`EC_AV1_FINAL_DUMP` (`~/.cache/sb128fork/cmp444.py`, 30 lines, outside the repo): + +``` +frame 0: Y 841/65536 | first Y(216,224) ours 171 oracle 170 + | U 1295/65536 | first U(216,224) ours 139 oracle 159 + | V 1372/65536 | first V(216,224) ours 17 oracle 9 +frame 1: Y 56986/65536 | U 55974/65536 | V 56442/65536 +VERDICT: DIVERGENT (exit 1) +``` + +The first wrong sample is `Y(216,224)` = mi(54,56) — inside SB row 1, col 1, the +superblock the forked leaf sits in. + +The entropy fork, same tree, `EC_SYMR` both sides, CDF-row convention reconciled +(`a == b or 32768 - a == b`): + +``` +*** FORK at read index 32813 *** +ours pre=(7550,45492,45418) cdf0=6424 n=2 s=1 post_rng=36377 +aom pre=(7550,45492,45403) cdf0=19938 n=2 s=1 post_rng=55054 site=decodeframe.c:1106 +``` + +Identical pre-state, identical width, identical symbol, only the row — and +`32768-6424 = 26344 != 19938`, so the ICDF mirror convention does not explain +it either. + +--- + +## 2. The rule, with the libaom lines I followed + +`get_tx_size_context` — `av1/common/pred_common.h:348-380`: + +```c +const MB_MODE_INFO *const above_mbmi = xd->above_mbmi; +const MB_MODE_INFO *const left_mbmi = xd->left_mbmi; +const TX_SIZE max_tx_size = max_txsize_rect_lookup[mbmi->bsize]; +const int max_tx_wide = tx_size_wide[max_tx_size]; +const int max_tx_high = tx_size_high[max_tx_size]; +const int has_above = xd->up_available; +const int has_left = xd->left_available; +int above = xd->above_txfm_context[0] >= max_tx_wide; +int left = xd->left_txfm_context[0] >= max_tx_high; +if (has_above) if (is_inter_block(above_mbmi)) above = block_size_wide[above_mbmi->bsize] >= max_tx_wide; +if (has_left) if (is_inter_block(left_mbmi)) left = block_size_high[left_mbmi->bsize] >= max_tx_high; +``` + +The two neighbours, and why they are PER CELL: + +- `av1/common/av1_common_int.h:1380-1389` (`set_mi_offsets`): + `xd->above_mbmi = xd->mi[-xd->mi_stride];` and `xd->left_mbmi = xd->mi[-1];` +- `av1/decoder/decodeframe.c:355-361` (`setup_mbs`): + ```c + for (int x = 1; x < x_mis; ++x) xd->mi[x] = xd->mi[0]; + int idx = mi_params->mi_stride; + for (int y = 1; y < y_mis; ++y) { + memcpy(&xd->mi[idx], &xd->mi[0], x_mis * sizeof(xd->mi[0])); + idx += mi_params->mi_stride; + } + ``` + `MB_MODE_INFO::bmi` is a POINTER, so this writes the covering block's own + pointer into **every** mi cell the block covers. `xd->mi[(r)*stride + c]` is + therefore "the block covering (r, c)", and `xd->mi[-stride]` / `xd->mi[-1]` + are the blocks whose bottom/left edge abuts this block's top/right edge **at + this cell**. +- `av1/common/blockd.h:372-374`: `is_inter_block(mbmi) = is_intrabc_block(mbmi) + || mbmi->ref_frame[0] > INTRA_FRAME` — an INTRABC block counts. + +**What the old code was reading.** `tx_size_context_txfm_rect` and +`tx_size_context_txfm` (both in `crates/ec-av1/src/decode.rs`) resolved the +override as: + +```rust +if has_above && n.above_inter[mi_c] { above = usize::from(n.above_side_mi[mi_c]) >= own_w; } +if has_left && n.left_inter[mi_r] { left = usize::from(n.left_side_mi[mi_r]) >= own_h; } +``` + +`above_inter`, `left_inter`, `above_side_mi` and `left_side_mi` are all indexed +by a BARE mi column/row (`mi_c` / `mi_r`), i.e. they are **per-column bands +holding the LAST block written in that column**. They are the covering block +only for the block immediately below/right of the last writer. On the witness +at mi(57,52) the band said `above_inter=true, above_side=4` while the covering +block of cell (56,52) is 8 px wide, so the override fired with 4 and resolved +`above = (4 >= 8) = 0`. + +**Measured, from the `EC_TXCTX` rung extended with the per-cell terms (the rung +now prints both models side by side so a future divergence names which one +disagreed):** + +``` +before: EC_TXCTX mi=57,52 own=8x4 ... above_inter=true left_inter=false \ + above_side=4 left_side=16 above=false left=true +after: EC_TXCTX mi=57,52 own=8x4 ... above_inter=true left_inter=false \ + above_side=4 left_side=16 above=true left=true \ + | cell_inter ab=true lb=false ab_side=8 lb_side=16 +oracle: EC_TXCTXB mi=57,52 bsize=2 maxw=8 maxh=4 hasup=1 hasleft=1 \ + abv=8 lft=8 above=1 left=1 ctx=2 +``` + +The boolean agreed all along; the SIZE term was the stale one. + +## 3. The change + +Four hunks, all in `crates/ec-av1/src/decode.rs`, plus one fixture and one gate. + +1. **`Neighbours::inter_grid: Vec`** (new field, per 4x4 mi cell, same + superblock-padded shape as `blk_grid`). libaom's `is_inter_block` of the + block covering each cell. +2. **Three writers, and only the three that already wrote the bands**, so the + per-cell grid inherits the bands' exact coverage and call-site ordering: + - `record_inter_rect_mi` → `mark_inter_grid_rect(at_mi, w_mi, h_mi, is_inter)` + (every block on an inter frame, with its own flag) + - `record_intrabc_mi_rect` → `.. = true` when `dv.is_some()` (an INTRABC block + counts as inter) + - `fill_lf_grid_rect`'s intra-only clear → `.. = false` (every block on a key + frame) + It is a **separate** writer from `fill_skip_grid_rect` on purpose: the two + publishers run in BOTH orders at different call sites (e.g. + `record_inter_rect_mi` at `decode.rs:44824` runs BEFORE + `fill_skip_grid_rect` at `:44844`), and they write disjoint fields, so the + order cannot matter. +3. **The covering block's own size** comes from `blk_grid`'s existing per-mi + `MI` — libaom's `block_size_wide[above_mbmi->bsize]` / + `block_size_high[left_mbmi->bsize]`. No new size array: `dim` was already + there, per mi, published by every coded block. +4. **Both readers** now gate and size the override from + `inter_at(mi_r - 1, mi_c)` / `inter_at(mi_r, mi_c - 1)` and + `blk_side_at(...)` instead of the four bands. `above_txfm` / `left_txfm` (the + real `TXFM_CONTEXT`) and the `has_above` / `has_left` tile-border guards are + **unchanged** — only the inter-neighbour override's two inputs move. + +Plus `crates/ec-av1/fixtures/444_lossy_sb128_txctx_witness.obu` (6186 B, +sha256 `14acb74e…`) and the gate +`a_444_lossy_sb128_txctx_reads_the_covering_block_per_cell`. + +**Why `--sb-size=128` and cq >= 54 are load-bearing for the witness** (stated on +the gate so nobody re-encodes it wrong): 256x256 is the smallest geometry that +gives `--sb-size=128` a SECOND superblock row and column, which is where a +column band and a per-cell cover stop coinciding — at the default 64 the columns +are 4 mi wide, so the two models agree for every 4-column run. The cell is +entropy-exact at cq 20..52 and forks from cq 54 up on 256x256. + +## 4. Proof + +**The witness, per plane** (`cmp444.py`, the same script as §1): + +``` +frame 0: Y 0/65536 | U 0/65536 | V 0/65536 +frame 1: Y 0/65536 | U 0/65536 | V 0/65536 +VERDICT: EXACT +``` + +**The whole entropy ladder, not just the fork read:** + +``` +ours 37229 reads | oracle 37229 reads +no divergence within the shorter stream +``` + +**The class sweep** — 10 sources x 11 cq levels = **99 cells** of 4:4:4 lossy +`--sb-size=128` (256x256 2/3/4 frames, 320x240, 256x384, 192x256, 256x192, +384x384, mandelbrot, testsrc; cq 30..62), aligned on +`(value, range, n, s, post_rng)` with the CDF-row convention reconciled +(`hunt5.py`): **99/99 `EXACT-ENTROPY`**. Before the fix the same 99 cells gave +**12 forks** (§ `lanes/av1sb128fork.report.md` §2) and **4 `OURS-EXIT1`** — the +refusals at `s256_3_cq56`, `s256_3_cq63`, `sz_320x240_cq54`, +`sz_256x384_cq54` were this same desync reaching a named refusal, and all four +now decode entropy-exact. I did not diagnose which refusal each was; the claim +is only that they no longer fire. + +**The gate's non-vacuity, by mutation.** Reverting the RECT reader's four lines +to the band form and re-running the gate: + +``` +panicked at crates/ec-av1/src/stream.rs:8359: + no `get_tx_size_context` read on this stream had the per-CELL cover and the + per-COLUMN band disagree ... +test result: FAILED. 0 passed; 1 failed +``` + +So the counter arm is not green on the old code. Green run: **1** diverging +read — the single one at mi(57,52), named in the gate's own message. The pixel +arm is independently red on the same mutation, by the §1 measurement. + +**The counter counts RESOLVED terms, not booleans** — my first version compared +`inter_at(cell) != above_inter[mi_c]` and read **0** on the witness, because on +this stream the two booleans AGREE and it is the SIZE term that is stale. The +gate's red-then-green on that first version is what caught it; the counter now +compares the resolved `above`/`left` under each model, which is the term that +feeds `ctx`. + +**Neighbouring families, re-quoted on the fixed tree** +(`cargo test -p ec-av1 --lib -- --test-threads=1`, scoped): + +| filter | result | +|---|---| +| `444_lossy 444_rect 444_intrabc_rect4 ll444 lossless intrabc_rect` | **44 passed, 0 failed** | +| `420 sb128 tile_rows tilerows intrabc av1real_aomenc` | **43 passed, 0 failed, 2 ignored** — the 2 ignored are `sb128_r2_control_sb64` and one sibling, both pre-existing `#[ignore]`s | + +## 5. Class sweep: the other `get_tx_size_context` consumers + +`grep` for every read of the four bands inside a tx-size context, and for every +other consumer of `above_inter` / `left_inter` / `above_side_mi` / +`left_side_mi`: + +| site | reads | verdict | +|---|---|---| +| `tx_size_context_txfm_rect` | the override | **FIXED** — per-cell cover | +| `tx_size_context_txfm` (square) | the override | **FIXED** — per-cell cover | +| `av1_get_intra_inter_context` (`is_inter` context, spec 8.4.2.1) | `above_inter[mi_c]` / `left_inter[mi_r]` | **NOT this defect.** libaom's `av1_get_intra_inter_context` (`pred_common.c:124-146`) also reads `above_mbmi`/`left_mbmi`, so it has the same granularity hazard — but its own gate (`lane-t900`'s, `INTRA_IN_INTER_*`) and the 99-cell sweep give no evidence either way, and I did not change it. **Named, not swept.** | +| `modes_above_left` / `record_mode_mi` consumers | `above_mode`/`left_mode` (mode bands) | Unrelated field; not touched. | +| `ref_ctx` family (`above_ref`, `above_ref1`) | `ref_frame` bands | **Same hazard, same granularity question.** `is_inter_block` and `av1_get_pred_context_single_ref_*` both consult the neighbour's reference. Not changed; the 99-cell sweep is exact, so no committed fixture observes it. **Named.** | +| `txfm_partition_ctx_rect` (the inter var-tx split) | `above_txfm` / `left_txfm` only | **Correct and untouched.** libaom's `txfm_partition_context` (`av1_common_int.h:1539-1552`) reads `above_txfm_context + mi_col` / `left_txfm_context + mi_row` — the TXFM bands at mi granularity, no block-size override at all. This is the "other `get_tx_size_context` consumer" the sweep asked about, and it is right as it stands. | + +So: **two** consumers of the inter-neighbour override, both fixed; **two** other +consumers of the same per-column `is_inter` bands (`is_inter` context, `ref` +context) that share the granularity hazard and are **named, not swept**; **one** +(the inter var-tx `txfm_partition_context`) that does not use them and is +correct. + +## 6. Follow-up that belongs to the merge, not to this lane + +`scripts/fixture-library.tsv` is GENERATED output +(`scripts/gen-fixture-library.sh`, "do not hand-edit") and it records a +`file:line` for **every** fixture reference in the crate. Regenerating it here +produced a **501-line** diff (205 insertions, 296 deletions) that has nothing to +do with this fix and would collide with every sibling lane that also touched +`decode.rs` / `stream.rs`. I reverted it and left the manifest alone: the new +pin is committed, reachable, and sha256-asserted by the gate, and the manifest +must be regenerated **once, after the wave lands** +(class `generated-manifest-regenerate-on-merge`). For the record, the row the +regeneration produces for the new pin is: + +``` +crates/ec-av1/fixtures/444_lossy_sb128_txctx_witness.obu crates/ec-av1/src/stream.rs:8339 captured - ok no 14acb74e825a2bb3ef195a52cc2abc67794d9c4d92080b66c739d318177fc7c6 +``` + +## 7. What I did NOT do + +- **No sweep of the `is_inter` / `ref` context consumers** (§5). They share the + granularity hazard; nothing in the 99-cell sweep or the re-quoted families + observes them, so changing them would be a blind refactor. +- **No diagnosis of the four `OURS-EXIT1` cells** the fix also cured. The claim + is that they no longer exit, not why they did. +- **No change to the `above_inter` / `left_inter` / `above_side_mi` / + `left_side_mi` bands themselves.** They still have their other readers (§5); + deleting them is a separate cleanup with its own re-quote. +- **The `EC_PART` rung's `mi` misprint** found in the previous lane (one of its + four arms prints the 16-px-unit index) is still there. Diagnostic-rung defect, + not a decode defect, not this lane's fix. + +## 8. Files + +- `crates/ec-av1/src/decode.rs` — `inter_grid` field + constructor entry, + `mark_inter_grid_rect` / `inter_at` / `blk_side_at`, the three writer calls, + both readers, `TXCTX_INTER_CELL_BAND_DIVERGENCE_HITS` + accessors, and the + `EC_TXCTX` rung extended with the per-cell terms. +- `crates/ec-av1/src/stream.rs` — the gate + `a_444_lossy_sb128_txctx_reads_the_covering_block_per_cell` (+94 lines). +- `crates/ec-av1/fixtures/444_lossy_sb128_txctx_witness.obu` — new pin. +- Throwaway, outside the repo: `~/.cache/sb128fork/` (`cmp444.py`, `align.py`, + `hunt5.py`, the `rb/` red-before and `gr2/` green dumps, and the 99 encodes).