ec-av1: read the TXFM_CONTEXT bands on intra-only frames too; fix the sub-8x8 chroma keying and the chroma-tx slot leak
Browse files at this commita4de84930e70fd9134bc07a42c6d503a43d949acParent: dcbe6ff4 changed files +646 -167
- crates/ec-av1/examples/decode_probe.rs +4 -0
- crates/ec-av1/src/decode.rs +344 -167
- crates/ec-av1/src/stream.rs +8 -0
- lanes/av1txbands.report.md +290 -0
crates/ec-av1/examples/decode_probe.rsmodified+4 -0
| @@ -48,6 +48,10 @@ fn main() { | ||
| 48 | 48 | ); |
| 49 | 49 | println!("leaf8_intrabc_hits: {}", ec_av1::stream::leaf8_intrabc_hits()); |
| 50 | 50 | println!("intrabc_hits: {}", ec_av1::stream::intrabc_hits()); |
| 51 | + println!( | |
| 52 | + "skipped_intrabc_chroma_arm_hits: {}", | |
| 53 | + ec_av1::stream::skipped_intrabc_chroma_arm_hits() | |
| 54 | + ); | |
| 51 | 55 | let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters(); |
| 52 | 56 | println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}"); |
| 53 | 57 | println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits()); |
crates/ec-av1/src/decode.rsmodified+344 -167
| @@ -123,6 +123,13 @@ pub(crate) struct FrameCtx { | ||
| 123 | 123 | pub(crate) cur_segment_id: std::cell::Cell<u8>, |
| 124 | 124 | pub(crate) seg_tile_origin: std::cell::Cell<(usize, usize)>, |
| 125 | 125 | pub(crate) tx_select_inter: std::cell::Cell<bool>, |
| 126 | + /// Whether the tile being decoded is an INTRA-ONLY frame's (key/intra-only | |
| 127 | + /// frame). libaom runs `set_txfm_ctxs` for EVERY block of EVERY frame | |
| 128 | + /// (`decodeframe.c` `parse_decode_block`), so an intra-only frame | |
| 129 | + /// maintains the `TXFM_CONTEXT` bands exactly like an inter one; only this | |
| 130 | + /// decoder's inter-side publishing was wired. See | |
| 131 | + /// [`Neighbours::fill_lf_grid_rect`]'s band publish. | |
| 132 | + pub(crate) intra_only: std::cell::Cell<bool>, | |
| 126 | 133 | pub(crate) reduced_tx_set_inter: std::cell::Cell<bool>, |
| 127 | 134 | pub(crate) enable_filter_intra_inter: std::cell::Cell<bool>, |
| 128 | 135 | pub(crate) palette_pred: std::cell::RefCell<Option<Vec<u16>>>, |
| @@ -222,7 +229,8 @@ impl FrameCtx { | ||
| 222 | 229 | cur_segment_id: std::cell::Cell::new(0), |
| 223 | 230 | seg_tile_origin: std::cell::Cell::new((0, 0)), |
| 224 | 231 | tx_select_inter: std::cell::Cell::new(false), |
| 225 | - reduced_tx_set_inter: std::cell::Cell::new(true), | |
| 232 | + intra_only: std::cell::Cell::new(false), | |
| 233 | + reduced_tx_set_inter: std::cell::Cell::new(false), | |
| 226 | 234 | enable_filter_intra_inter: std::cell::Cell::new(false), |
| 227 | 235 | palette_pred: std::cell::RefCell::new(None), |
| 228 | 236 | intrabc_mi_grid: std::cell::RefCell::new(None), |
| @@ -1617,6 +1625,7 @@ pub(crate) fn set_inter_tx_mode( | ||
| 1617 | 1625 | enable_filter_intra: bool, fctx: &crate::decode::FrameCtx, |
| 1618 | 1626 | ) { |
| 1619 | 1627 | fctx.tx_select_inter.with(|c| c.set(tx_select)); |
| 1628 | + fctx.intra_only.with(|c| c.set(false)); | |
| 1620 | 1629 | fctx.reduced_tx_set_inter.with(|c| c.set(reduced_tx_set)); |
| 1621 | 1630 | fctx.enable_filter_intra_inter.with(|c| c.set(enable_filter_intra)); |
| 1622 | 1631 | } |
| @@ -3695,6 +3704,29 @@ pub(crate) fn intrabc_hits() -> usize { | ||
| 3695 | 3704 | INTRABC_HITS.with(|c| c.get()) |
| 3696 | 3705 | } |
| 3697 | 3706 | |
| 3707 | +thread_local! { | |
| 3708 | + /// An intrabc block that IS a sub-8x8 group's CHROMA REFERENCE and is | |
| 3709 | + /// SKIPPED: the route that arms [`INTRABC_CHROMA_TX`] and then reads no | |
| 3710 | + /// chroma coefficient at all, so the slot used to stay armed into the NEXT | |
| 3711 | + /// block's chroma read. Both group shapes (4x4 split, 4x8/8x4 rect) count | |
| 3712 | + /// here. A non-zero value is what makes the disarm below load-bearing. | |
| 3713 | + static SKIPPED_INTRABC_CHROMA_ARM_HITS: std::cell::Cell<usize> = | |
| 3714 | + const { std::cell::Cell::new(0) }; | |
| 3715 | +} | |
| 3716 | + | |
| 3717 | +/// Current value of [`SKIPPED_INTRABC_CHROMA_ARM_HITS`]. | |
| 3718 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates and the probe | |
| 3719 | +pub(crate) fn skipped_intrabc_chroma_arm_hits() -> usize { | |
| 3720 | + SKIPPED_INTRABC_CHROMA_ARM_HITS.with(|c| c.get()) | |
| 3721 | +} | |
| 3722 | + | |
| 3723 | +/// Zeroes [`SKIPPED_INTRABC_CHROMA_ARM_HITS`] (gate tests call this before a | |
| 3724 | +/// decode). | |
| 3725 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | |
| 3726 | +pub(crate) fn reset_skipped_intrabc_chroma_arm_hits() { | |
| 3727 | + SKIPPED_INTRABC_CHROMA_ARM_HITS.with(|c| c.set(0)); | |
| 3728 | +} | |
| 3729 | + | |
| 3698 | 3730 | /// Zeroes [`INTRABC_HITS`] (gate tests call this before a decode). |
| 3699 | 3731 | #[allow(dead_code)] // read only from the `#[cfg(test)]` gates |
| 3700 | 3732 | pub(crate) fn reset_intrabc_hits() { |
| @@ -3735,21 +3767,42 @@ pub fn rect_intrabc_vartx_hits() -> usize { | ||
| 3735 | 3767 | /// its size (libaom's `scan_row_mbmi` advances `processed_rows` off any |
| 3736 | 3768 | /// candidate's `bsize`, ref-match or not), an intrabc one also its DV as an |
| 3737 | 3769 | /// `INTRA_FRAME` candidate (libaom treats intrabc as `is_inter_block`). |
| 3738 | -fn record_intrabc_mi(mi_r: usize, mi_c: usize, n4: usize, dv: Option<(i32, i32)>, fctx: &crate::decode::FrameCtx) { | |
| 3739 | - record_intrabc_mi_rect(mi_r, mi_c, n4, n4, dv, fctx); | |
| 3770 | +fn record_intrabc_mi(mi_r: usize, mi_c: usize, n4: usize, dv: Option<(i32, i32)>, n: &mut Neighbours, fctx: &crate::decode::FrameCtx) { | |
| 3771 | + record_intrabc_mi_rect(mi_r, mi_c, n4, n4, dv, n, fctx); | |
| 3740 | 3772 | } |
| 3741 | 3773 | |
| 3742 | 3774 | /// [`record_intrabc_mi`] with a true rectangular footprint: `av1_find_mv_refs` |
| 3743 | 3775 | /// takes the block's real `bsize`, so a sub-8x8 `BLOCK_4X8`/`BLOCK_8X4` |
| 3744 | 3776 | /// intrabc leaf must publish a 1x2/2x1 mi span, not a square (lane-av1txr). |
| 3777 | +/// | |
| 3778 | +/// Also stamps libaom's `is_inter_block` verdict for this block into the | |
| 3779 | +/// `above_inter`/`left_inter` bands ([`tx_size_context_txfm_rect`]'s override | |
| 3780 | +/// term): `is_inter_block` is `is_intrabc_block(mbmi) || ref_frame[0] > | |
| 3781 | +/// INTRA_FRAME` (`blockd.h:373`), so an intrabc block is "inter" there and | |
| 3782 | +/// `get_tx_size_context` reads its BLOCK size rather than its transform band. | |
| 3783 | +/// The `false` half of the stamp is [`Neighbours::fill_lf_grid_rect`]'s, which | |
| 3784 | +/// every block runs; this runs after it (class leaked-band otherwise). | |
| 3745 | 3785 | fn record_intrabc_mi_rect( |
| 3746 | 3786 | mi_r: usize, |
| 3747 | 3787 | mi_c: usize, |
| 3748 | 3788 | n4_w: usize, |
| 3749 | 3789 | n4_h: usize, |
| 3750 | 3790 | dv: Option<(i32, i32)>, |
| 3791 | + n: &mut Neighbours, | |
| 3751 | 3792 | fctx: &crate::decode::FrameCtx, |
| 3752 | 3793 | ) { |
| 3794 | + if dv.is_some() { | |
| 3795 | + for i in 0..n4_w { | |
| 3796 | + if let Some(cell) = n.above_inter.get_mut(mi_c + i) { | |
| 3797 | + *cell = true; | |
| 3798 | + } | |
| 3799 | + } | |
| 3800 | + for i in 0..n4_h { | |
| 3801 | + if let Some(cell) = n.left_inter.get_mut(mi_r + i) { | |
| 3802 | + *cell = true; | |
| 3803 | + } | |
| 3804 | + } | |
| 3805 | + } | |
| 3753 | 3806 | fctx.intrabc_mi_grid.with(|g| { |
| 3754 | 3807 | let mut g = g.borrow_mut(); |
| 3755 | 3808 | let Some((grid, _, _)) = g.as_mut() else { |
| @@ -4475,18 +4528,20 @@ pub(crate) fn intra_rect_in_inter_split_tx_hits() -> [usize; 3] { | ||
| 4475 | 4528 | INTRA_RECT_IN_INTER_SPLIT_TX_HITS.with(std::cell::Cell::get) |
| 4476 | 4529 | } |
| 4477 | 4530 | |
| 4478 | -// lane-midcut r2: rect intra blocks inside an inter frame whose `tx_depth` CDF | |
| 4479 | -// ROW moved when libaom's inter-neighbour override was applied -- i.e. exactly | |
| 4480 | -// the blocks the key frame's deblock-grid approximation used to mis-read. | |
| 4531 | +// lane-av1txbands: how many `tx_depth`/`txfm_split` reads the deblock-grid | |
| 4532 | +// approximation would have resolved off a DIFFERENT CDF row than the real | |
| 4533 | +// `TXFM_CONTEXT` bands do -- the exact blocks this band read fixes, on ANY | |
| 4534 | +// frame (lane-midcut r2 had it inter-frame-only). A plain "rect/intra block" | |
| 4535 | +// tally is green on the old code too (class gate-blind-to-feature). | |
| 4481 | 4536 | thread_local! { |
| 4482 | - static INTRA_RECT_IN_INTER_TXCTX_OVERRIDE_HITS: std::cell::Cell<usize> = | |
| 4537 | + static TXCTX_DEBLOCK_DIVERGENCE_HITS: std::cell::Cell<usize> = | |
| 4483 | 4538 | const { std::cell::Cell::new(0) }; |
| 4484 | 4539 | } |
| 4485 | 4540 | |
| 4486 | -/// Current value of [`INTRA_RECT_IN_INTER_TXCTX_OVERRIDE_HITS`]. | |
| 4541 | +/// Current value of [`TXCTX_DEBLOCK_DIVERGENCE_HITS`]. | |
| 4487 | 4542 | #[allow(dead_code)] // gate counter accessor with no reader yet; the counter itself is live |
| 4488 | -pub(crate) fn intra_rect_in_inter_txctx_override_hits() -> usize { | |
| 4489 | - INTRA_RECT_IN_INTER_TXCTX_OVERRIDE_HITS.with(std::cell::Cell::get) | |
| 4543 | +pub(crate) fn txctx_deblock_divergence_hits() -> usize { | |
| 4544 | + TXCTX_DEBLOCK_DIVERGENCE_HITS.with(std::cell::Cell::get) | |
| 4490 | 4545 | } |
| 4491 | 4546 | |
| 4492 | 4547 | // lane-intra14 r1: how many intra-coded 1:4 strips decoded on the INTER |
| @@ -7619,6 +7674,41 @@ impl Neighbours { | ||
| 7619 | 7674 | fill_span(&mut self.ref_grid, start, w_mi, ref_frame); |
| 7620 | 7675 | fill_span(&mut self.delta_lf_grid, start, w_mi, snapshot); |
| 7621 | 7676 | } |
| 7677 | + if fctx.intra_only.with(std::cell::Cell::get) { | |
| 7678 | + // libaom's `parse_decode_block` runs `set_txfm_ctxs(mbmi->tx_size, | |
| 7679 | + // xd->width, xd->height, mbmi->skip_txfm && is_inter_block(mbmi), | |
| 7680 | + // xd)` for EVERY block, an intra-only frame's included, and | |
| 7681 | + // `get_tx_size_context` / `txfm_partition_context` read those two | |
| 7682 | + // `TXFM_CONTEXT` bands. This grid carries the same transform size | |
| 7683 | + // over the same footprint, so the publish is this write: the | |
| 7684 | + // `skip && is_inter` term is 0 for every intra-only block that is | |
| 7685 | + // not an intrabc one, and the bodies that can code an intrabc | |
| 7686 | + // block publish their own (the term is then the BLOCK size, a value | |
| 7687 | + // this grid cannot express -- see `decode_block`/`decode_leaf8`). | |
| 7688 | + // Inter frames publish at their own sites and are excluded here | |
| 7689 | + // because their skipped-block term needs the block size too. | |
| 7690 | + txfm_partition_update_rect( | |
| 7691 | + self, | |
| 7692 | + at_mi, | |
| 7693 | + (tx_px as usize, tx_h_px as usize), | |
| 7694 | + (w_mi * MI, h_mi * MI), | |
| 7695 | + ); | |
| 7696 | + // libaom `is_inter_block` counts an INTRABC block (`blockd.h:373`), | |
| 7697 | + // so `get_tx_size_context` reads an intrabc NEIGHBOUR's block size | |
| 7698 | + // instead of its transform band. Every block stamps its own cells | |
| 7699 | + // here; the intrabc bodies re-stamp theirs `true` afterwards | |
| 7700 | + // (`record_intrabc_inter_bands`). | |
| 7701 | + for i in 0..w_mi { | |
| 7702 | + if let Some(cell) = self.above_inter.get_mut(mi_c + i) { | |
| 7703 | + *cell = false; | |
| 7704 | + } | |
| 7705 | + } | |
| 7706 | + for i in 0..h_mi { | |
| 7707 | + if let Some(cell) = self.left_inter.get_mut(mi_r + i) { | |
| 7708 | + *cell = false; | |
| 7709 | + } | |
| 7710 | + } | |
| 7711 | + } | |
| 7622 | 7712 | } |
| 7623 | 7713 | |
| 7624 | 7714 | /// One var-tx / split-tx LEAF's own LUMA transform dims over its mi span. |
| @@ -9444,36 +9534,6 @@ fn record_strip_palette( | ||
| 9444 | 9534 | } |
| 9445 | 9535 | } |
| 9446 | 9536 | |
| 9447 | -/// [`tx_size_context`] for a true `bw`x`bh` rect strip (lane-intradisp r1): | |
| 9448 | -/// `get_tx_size_context` (libaom `pred_common.h`) compares the neighbour | |
| 9449 | -/// above against this block's own *width* and the neighbour to the left | |
| 9450 | -/// against its own *height* -- for a square block those are the same value, | |
| 9451 | -/// which is why the square-only version can get away with one `own_side`. | |
| 9452 | -fn tx_size_context_rect( | |
| 9453 | - n: &Neighbours, | |
| 9454 | - (mi_r, mi_c): (usize, usize), | |
| 9455 | - own_w: usize, | |
| 9456 | - own_h: usize, | |
| 9457 | -) -> usize { | |
| 9458 | - // `get_tx_size_context` compares against `max_txsize_rect_lookup[bsize]`, | |
| 9459 | - // not the block's own side: no transform is wider or taller than 64, so a | |
| 9460 | - // block with a 128 side resolves against 64 (the square path already caps | |
| 9461 | - // this way, lane-sb128b r1). Without the cap the 64x128 half of a 128-root | |
| 9462 | - // VERT reads the tx-depth symbol off row 0 where libaom uses row 1. | |
| 9463 | - let (own_w, own_h) = (own_w.min(64), own_h.min(64)); | |
| 9464 | - let above = mi_r > n.tile_row0_mi && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w; | |
| 9465 | - let left = mi_c > n.tile_col0_mi && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_h; | |
| 9466 | - if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") { | |
| 9467 | - eprintln!( | |
| 9468 | - "EC_TXCTX mi_row={mi_r} mi_col={mi_c} w={own_w} h={own_h} above_px={} left_px={} ctx={}", | |
| 9469 | - if mi_r > n.tile_row0_mi { tx_px_at(n, false, mi_r - 1, mi_c) } else { 0 }, | |
| 9470 | - if mi_c > n.tile_col0_mi { tx_h_px_at(n, false, mi_r, mi_c - 1) } else { 0 }, | |
| 9471 | - usize::from(above) + usize::from(left) | |
| 9472 | - ); | |
| 9473 | - } | |
| 9474 | - usize::from(above) + usize::from(left) | |
| 9475 | -} | |
| 9476 | - | |
| 9477 | 9537 | /// [`cfl_ac_q3`] for a true `bw`x`bh` rect strip (lane-intradisp r1). |
| 9478 | 9538 | fn cfl_ac_q3_rect(y: &PlaneBuf<'_>, px: usize, py: usize, bw: usize, bh: usize) -> Vec<i32> { |
| 9479 | 9539 | cfl_ac_q3_at(px, py, bw, bh, |lx, ly| i32::from(y.data[ly * y.width + lx])) |
| @@ -10708,8 +10768,7 @@ fn decode_intra_rect_in_inter( | ||
| 10708 | 10768 | } |
| 10709 | 10769 | let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c); |
| 10710 | 10770 | let depth = if fctx.tx_select_inter.with(std::cell::Cell::get) { |
| 10711 | - // The INTER frame's own `TXFM_CONTEXT` bands, not the key frame's | |
| 10712 | - // deblock-grid approximation -- [`tx_size_context_txfm_rect`]. | |
| 10771 | + // The frame's own `TXFM_CONTEXT` bands -- [`tx_size_context_txfm_rect`]. | |
| 10713 | 10772 | let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw.min(64), bh.min(64), fctx); |
| 10714 | 10773 | let d = match tx_cat { |
| 10715 | 10774 | 1 => dec.symbol(&mut cdfs.tx_size_cat1[ctx]), |
| @@ -10916,18 +10975,14 @@ fn decode_block_rect( | ||
| 10916 | 10975 | // pinned HORZ quadrant were wrong from their very first pixel, and why our |
| 10917 | 10976 | // range after the read equalled the oracle's range for the whole block. |
| 10918 | 10977 | let depth = if tx_select { |
| 10919 | - // lane-t900 r2: on an INTER frame `get_tx_size_context` reads the real | |
| 10920 | - // `TXFM_CONTEXT` bands ([`tx_size_context_txfm_rect`], what the 2:1 and | |
| 10921 | - // the 16x4 intra-in-inter strips already do); the key frame's | |
| 10922 | - // deblock-grid approximation is only right where those bands were never | |
| 10923 | - // written. Measured on the 10-bit 1920x792 128-superblock stream, | |
| 10978 | + // lane-av1txbands: EVERY frame now reads the real `TXFM_CONTEXT` | |
| 10979 | + // bands (`get_tx_size_context`, libaom `pred_common.h:342`) -- an | |
| 10980 | + // intra-only frame publishes them from every block too | |
| 10981 | + // ([`Neighbours::fill_lf_grid_rect`]). Measured on the 10-bit | |
| 10982 | + // 1920x792 128-superblock stream, | |
| 10924 | 10983 | // decode-order frame 1: the 32x8 HORZ_4 strip at mi(48,176) read |
| 10925 | 10984 | // `tx_size_cat2` row 1 where libaom reads row 2. |
| 10926 | - let ctx = if fctx.intra_in_inter_mode.with(std::cell::Cell::get).is_some() { | |
| 10927 | - tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw, bh, fctx) | |
| 10928 | - } else { | |
| 10929 | - tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh) | |
| 10930 | - }; | |
| 10985 | + let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw, bh, fctx); | |
| 10931 | 10986 | let d = dec.symbol(&mut cdfs.tx_size_cat2[ctx]); |
| 10932 | 10987 | if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") { |
| 10933 | 10988 | eprintln!( |
| @@ -11126,7 +11181,7 @@ fn decode_block_rect( | ||
| 11126 | 11181 | // reconciled with oracle's own EC_IMODE_VAL (rng=58692, taken *after* |
| 11127 | 11182 | // its own tx_size read) unless oracle's tx symbol is a near-certainty |
| 11128 | 11183 | // CDF that barely narrows the range -- i.e. this decoder's |
| 11129 | - // `tx_size_context_rect` ctx or `cdfs.tx_size_cat2` CDF selection for | |
| 11184 | + // tx-depth ctx or `cdfs.tx_size_cat2` CDF selection for | |
| 11130 | 11185 | // a 32x16/16x32 strip is the first diverging symbol, not the |
| 11131 | 11186 | // coefficient-context math r3 already cleared. Not confirmed byte- |
| 11132 | 11187 | // exact (would need a decodemv.c EC_TRACE_MODE patch specifically on |
| @@ -11422,11 +11477,7 @@ fn decode_leaf_rect( | ||
| 11422 | 11477 | let depth = if tx_select { |
| 11423 | 11478 | // lane-t900 r2 (sibling sweep): the in-inter `TXFM_CONTEXT` band read |
| 11424 | 11479 | // every other rect reader now does -- a no-op on a key frame. |
| 11425 | - let ctx = if fctx.intra_in_inter_mode.with(std::cell::Cell::get).is_some() { | |
| 11426 | - tx_size_context_txfm_rect(neighbours, leaf_mi, bw, bh, fctx) | |
| 11427 | - } else { | |
| 11428 | - tx_size_context_rect(neighbours, leaf_mi, bw, bh) | |
| 11429 | - }; | |
| 11480 | + let ctx = tx_size_context_txfm_rect(neighbours, leaf_mi, bw, bh, fctx); | |
| 11430 | 11481 | // lane-rectsplitx r1: `bsize_to_tx_size_cat` (libaom `blockd.h`, |
| 11431 | 11482 | // `bsize_to_tx_size_depth_table`) is 2 for BLOCK_16X8/BLOCK_8X16, so |
| 11432 | 11483 | // the category is 1 -- NOT the 2 the 32x16 strips read. Same symbol |
| @@ -11762,18 +11813,14 @@ fn decode_block_rect4( | ||
| 11762 | 11813 | uv_mode |
| 11763 | 11814 | }; |
| 11764 | 11815 | let depth = if tx_select { |
| 11765 | - // lane-t900 r2: on an INTER frame `get_tx_size_context` reads the real | |
| 11766 | - // `TXFM_CONTEXT` bands ([`tx_size_context_txfm_rect`], what the 2:1 and | |
| 11767 | - // the 16x4 intra-in-inter strips already do); the key frame's | |
| 11768 | - // deblock-grid approximation is only right where those bands were never | |
| 11769 | - // written. Measured on the 10-bit 1920x792 128-superblock stream, | |
| 11816 | + // lane-av1txbands: EVERY frame now reads the real `TXFM_CONTEXT` | |
| 11817 | + // bands (`get_tx_size_context`, libaom `pred_common.h:342`) -- an | |
| 11818 | + // intra-only frame publishes them from every block too | |
| 11819 | + // ([`Neighbours::fill_lf_grid_rect`]). Measured on the 10-bit | |
| 11820 | + // 1920x792 128-superblock stream, | |
| 11770 | 11821 | // decode-order frame 1: the 32x8 HORZ_4 strip at mi(48,176) read |
| 11771 | 11822 | // `tx_size_cat2` row 1 where libaom reads row 2. |
| 11772 | - let ctx = if fctx.intra_in_inter_mode.with(std::cell::Cell::get).is_some() { | |
| 11773 | - tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw, bh, fctx) | |
| 11774 | - } else { | |
| 11775 | - tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh) | |
| 11776 | - }; | |
| 11823 | + let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw, bh, fctx); | |
| 11777 | 11824 | let d = dec.symbol(&mut cdfs.tx_size_cat2[ctx]); |
| 11778 | 11825 | if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") { |
| 11779 | 11826 | eprintln!( |
| @@ -12289,16 +12336,9 @@ fn decode_rect4_16_strip( | ||
| 12289 | 12336 | // depth symbol is the 3-symbol `tx_size_cat1` -- not the 2-symbol |
| 12290 | 12337 | // `cat0` a 4x8 leaf reads nor the `cat2` a 32x8 strip does. |
| 12291 | 12338 | let depth = if tx_select { |
| 12292 | - // lane-intra16x4: on an INTER frame `get_tx_size_context` reads the | |
| 12293 | - // real `TXFM_CONTEXT` bands ([`tx_size_context_txfm_rect`], what | |
| 12294 | - // the 2:1 intra-in-inter strip already does); the key frame's | |
| 12295 | - // deblock-grid approximation is only right where those bands were | |
| 12296 | - // never written. | |
| 12297 | - let ctx = if fctx.intra_in_inter_mode.with(std::cell::Cell::get).is_some() { | |
| 12298 | - tx_size_context_txfm_rect(neighbours, lmi, bw, bh, fctx) | |
| 12299 | - } else { | |
| 12300 | - tx_size_context_rect(neighbours, lmi, bw, bh) | |
| 12301 | - }; | |
| 12339 | + // lane-av1txbands: every frame reads the real `TXFM_CONTEXT` bands | |
| 12340 | + // (`get_tx_size_context`, libaom `pred_common.h:342`). | |
| 12341 | + let ctx = tx_size_context_txfm_rect(neighbours, lmi, bw, bh, fctx); | |
| 12302 | 12342 | let d = dec.symbol(&mut cdfs.tx_size_cat1[ctx]); |
| 12303 | 12343 | if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") { |
| 12304 | 12344 | eprintln!( |
| @@ -12773,18 +12813,14 @@ fn decode_block_rect64( | ||
| 12773 | 12813 | }; |
| 12774 | 12814 | let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); |
| 12775 | 12815 | let depth = if tx_select { |
| 12776 | - // lane-t900 r2: on an INTER frame `get_tx_size_context` reads the real | |
| 12777 | - // `TXFM_CONTEXT` bands ([`tx_size_context_txfm_rect`], what the 2:1 and | |
| 12778 | - // the 16x4 intra-in-inter strips already do); the key frame's | |
| 12779 | - // deblock-grid approximation is only right where those bands were never | |
| 12780 | - // written. Measured on the 10-bit 1920x792 128-superblock stream, | |
| 12816 | + // lane-av1txbands: EVERY frame now reads the real `TXFM_CONTEXT` | |
| 12817 | + // bands (`get_tx_size_context`, libaom `pred_common.h:342`) -- an | |
| 12818 | + // intra-only frame publishes them from every block too | |
| 12819 | + // ([`Neighbours::fill_lf_grid_rect`]). Measured on the 10-bit | |
| 12820 | + // 1920x792 128-superblock stream, | |
| 12781 | 12821 | // decode-order frame 1: the 32x8 HORZ_4 strip at mi(48,176) read |
| 12782 | 12822 | // `tx_size_cat2` row 1 where libaom reads row 2. |
| 12783 | - let ctx = if fctx.intra_in_inter_mode.with(std::cell::Cell::get).is_some() { | |
| 12784 | - tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw, bh, fctx) | |
| 12785 | - } else { | |
| 12786 | - tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh) | |
| 12787 | - }; | |
| 12823 | + let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw, bh, fctx); | |
| 12788 | 12824 | // lane-rectsplit r1: `bsize_to_tx_size_cat` (libaom `decodemv.c`) |
| 12789 | 12825 | // counts `sub_tx_size_map` steps from the block's own max rect |
| 12790 | 12826 | // transform down to TX_4X4, minus one -- BLOCK_64X32's chain |
| @@ -14394,7 +14430,7 @@ fn decode_block( | ||
| 14394 | 14430 | let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); |
| 14395 | 14431 | // `TxMode::Select`'s `tx_depth` (spec 5.11.16): read for every intra |
| 14396 | 14432 | // block, skipped or not. `logical_tx` is what the loop filter's edge |
| 14397 | - // lookup and the next block's own `tx_size_context` want (the *nominal* | |
| 14433 | + // lookup and the next block's own `get_tx_size_context` want (the *nominal* | |
| 14398 | 14434 | // transform size -- 64 even for the 64x64 corner-scanned case, spec |
| 14399 | 14435 | // 5.11.40); `coeff_tx_side` is the actual coded coefficient grid's side, |
| 14400 | 14436 | // which only differs from it at that one corner case. |
| @@ -14451,7 +14487,7 @@ fn decode_block( | ||
| 14451 | 14487 | let (logical_tx, coeff_tx_side) = if let Some(tx) = intrabc_leaves { |
| 14452 | 14488 | (tx, if tx == 64 { 32 } else { tx }) |
| 14453 | 14489 | } else if tx_select && !intrabc_skip_tx { |
| 14454 | - let resolved = read_tx_size(dec, cdfs, neighbours, (mi_r, mi_c), side, None); | |
| 14490 | + let resolved = read_tx_size(dec, cdfs, neighbours, (mi_r, mi_c), side); | |
| 14455 | 14491 | (resolved, if resolved == 64 { 32 } else { resolved }) |
| 14456 | 14492 | } else { |
| 14457 | 14493 | // lane-sb128b r1: `max_txsize_rect_lookup[BLOCK_128X128]` is |
| @@ -15019,12 +15055,15 @@ fn decode_block( | ||
| 15019 | 15055 | logical_tx as u8, |
| 15020 | 15056 | 0, fctx, |
| 15021 | 15057 | ); |
| 15022 | - // lane-t900 r32: libaom runs `set_txfm_ctxs` at the end of EVERY | |
| 15023 | - // `decode_block`, key frames included, and the intrabc var-tx read above | |
| 15024 | - // (`txfm_partition_ctx`) is the only intra-path reader of those bands -- | |
| 15025 | - // left at `TXFM_CTX_INIT` it would take the split symbol off the wrong CDF | |
| 15026 | - // row. Armed by the frame's own `allow_intrabc` so every other key frame | |
| 15027 | - // (whose readers use the deblock-grid approximation) is untouched. | |
| 15058 | + // lane-t900 r32 / lane-av1txbands: libaom runs `set_txfm_ctxs(mbmi->tx_size, | |
| 15059 | + // n4_w, n4_h, skip_txfm && is_inter_block(mbmi), xd)` at the end of EVERY | |
| 15060 | + // `decode_block`. An intra-only frame's blocks also publish their TRANSFORM | |
| 15061 | + // size from [`Neighbours::fill_lf_grid_rect`], but this grid cannot express | |
| 15062 | + // libaom's `skip && is_inter` term -- the one thing that makes a SKIPPED | |
| 15063 | + // intrabc block publish its BLOCK size instead, intrabc being the only | |
| 15064 | + // "inter" block an intra-only frame codes (`blockd.h:373`). So this call | |
| 15065 | + // stays the authority wherever one can appear; with `allow_intrabc` unset | |
| 15066 | + // it writes exactly what the grid already did. | |
| 15028 | 15067 | if allow_intrabc { |
| 15029 | 15068 | set_txfm_ctxs( |
| 15030 | 15069 | neighbours, |
| @@ -15035,7 +15074,7 @@ fn decode_block( | ||
| 15035 | 15074 | skip && intrabc_dv.is_some(), |
| 15036 | 15075 | ); |
| 15037 | 15076 | } |
| 15038 | - record_intrabc_mi(mi_r, mi_c, side / MI, intrabc_dv, fctx); | |
| 15077 | + record_intrabc_mi(mi_r, mi_c, side / MI, intrabc_dv, neighbours, fctx); | |
| 15039 | 15078 | Ok(()) |
| 15040 | 15079 | } |
| 15041 | 15080 | |
| @@ -15161,15 +15200,10 @@ fn decode_block_128rect( | ||
| 15161 | 15200 | // not. `bsize_to_tx_size_cat(BLOCK_128X64)` is 3 (see this fn's doc). |
| 15162 | 15201 | let in_inter = fctx.intra_in_inter_mode.with(std::cell::Cell::get).is_some(); |
| 15163 | 15202 | let depth = if tx_select { |
| 15164 | - // lane-inter128intra r1: on an INTER frame `get_tx_size_context` reads | |
| 15165 | - // the real `TXFM_CONTEXT` bands, and compares them against | |
| 15166 | - // `tx_size_wide/high[max_txsize_rect_lookup[bsize]]` -- TX_64X64 for | |
| 15167 | - // every 128-axis block, hence the `min(64)`. | |
| 15168 | - let ctx = if in_inter { | |
| 15169 | - tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw.min(64), bh.min(64), fctx) | |
| 15170 | - } else { | |
| 15171 | - tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh) | |
| 15172 | - }; | |
| 15203 | + // lane-inter128intra r1: `get_tx_size_context` compares the bands | |
| 15204 | + // against `tx_size_wide/high[max_txsize_rect_lookup[bsize]]` -- | |
| 15205 | + // TX_64X64 for every 128-axis block, hence the `min(64)`. | |
| 15206 | + let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw.min(64), bh.min(64), fctx); | |
| 15173 | 15207 | dec.symbol(&mut cdfs.tx_size_cat3[ctx]) |
| 15174 | 15208 | } else { |
| 15175 | 15209 | 0 |
| @@ -15583,7 +15617,7 @@ fn decode_leaf8( | ||
| 15583 | 15617 | hit!(INTRABC_VARTX_HITS); |
| 15584 | 15618 | leaves.first().map_or(8, |l| l.2) |
| 15585 | 15619 | } else if tx_select && intrabc_dv.is_none() { |
| 15586 | - read_tx_size(dec, cdfs, neighbours, leaf_mi, 8, None) | |
| 15620 | + read_tx_size(dec, cdfs, neighbours, leaf_mi, 8) | |
| 15587 | 15621 | } else { |
| 15588 | 15622 | // lane-lossless: TX_4X4 on a lossless frame, no symbol |
| 15589 | 15623 | // (libaom `read_tx_size`). |
| @@ -16003,7 +16037,7 @@ fn decode_leaf8( | ||
| 16003 | 16037 | set_txfm_ctxs(neighbours, leaf_mi, 4, 2, 2, skip && intrabc_dv.is_some()); |
| 16004 | 16038 | } |
| 16005 | 16039 | neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode); |
| 16006 | - record_intrabc_mi(leaf_mi.0, leaf_mi.1, 2, intrabc_dv, fctx); | |
| 16040 | + record_intrabc_mi(leaf_mi.0, leaf_mi.1, 2, intrabc_dv, neighbours, fctx); | |
| 16007 | 16041 | return Ok(mode); |
| 16008 | 16042 | } |
| 16009 | 16043 | neighbours.record_mi(leaf_mi, 8, &[&luma_grid[..], &u_grid[..], &v_grid[..]]); |
| @@ -16027,9 +16061,10 @@ fn decode_leaf8( | ||
| 16027 | 16061 | // (class `wrong-alphabet-same-value`; the ReelB key frame at |
| 16028 | 16062 | // -ss 900, first bad luma sample row 186 col 1803). |
| 16029 | 16063 | neighbours.fill_lf_grid(leaf_mi, 2, resolved as u8, 0, fctx); |
| 16030 | - // lane-t900 r32: `set_txfm_ctxs` for an 8x8 leaf -- see `decode_block`'s | |
| 16031 | - // own copy; only an intrabc var-tx read consumes these bands on the intra | |
| 16032 | - // path, so the write is armed by `allow_intrabc`. | |
| 16064 | + // lane-t900 r32 / lane-av1txbands: `set_txfm_ctxs` for an 8x8 leaf -- see | |
| 16065 | + // `decode_block`'s own copy for why this stays beside | |
| 16066 | + // [`Neighbours::fill_lf_grid_rect`]'s publish (the skipped-intrabc | |
| 16067 | + // BLOCK-size term). | |
| 16033 | 16068 | if allow_intrabc { |
| 16034 | 16069 | set_txfm_ctxs(neighbours, leaf_mi, resolved, 2, 2, skip && intrabc_dv.is_some()); |
| 16035 | 16070 | } |
| @@ -16037,7 +16072,7 @@ fn decode_leaf8( | ||
| 16037 | 16072 | // The DV predictor of a LATER intrabc block is the ordinary `INTRA_FRAME` |
| 16038 | 16073 | // MV stack over this grid (`av1_find_mv_refs`), so an 8x8 leaf has to |
| 16039 | 16074 | // publish its own cells exactly like `decode_block` does. |
| 16040 | - record_intrabc_mi(leaf_mi.0, leaf_mi.1, 2, intrabc_dv, fctx); | |
| 16075 | + record_intrabc_mi(leaf_mi.0, leaf_mi.1, 2, intrabc_dv, neighbours, fctx); | |
| 16041 | 16076 | Ok(mode) |
| 16042 | 16077 | } |
| 16043 | 16078 | |
| @@ -16328,7 +16363,7 @@ fn decode_leaf_split4( | ||
| 16328 | 16363 | } |
| 16329 | 16364 | neighbours.fill_skip_grid(lmi, 1, skip); |
| 16330 | 16365 | neighbours.fill_lf_grid(lmi, 1, 4, 0, fctx); |
| 16331 | - record_intrabc_mi(lmi.0, lmi.1, 1, Some(dv), fctx); | |
| 16366 | + record_intrabc_mi(lmi.0, lmi.1, 1, Some(dv), neighbours, fctx); | |
| 16332 | 16367 | if has_chroma { |
| 16333 | 16368 | last_uv = Some((DC_PRED, 0, None)); |
| 16334 | 16369 | // An intrabc block is an INTER block for `av1_get_tx_type`, so |
| @@ -16337,8 +16372,18 @@ fn decode_leaf_split4( | ||
| 16337 | 16372 | // luma `read_plane` above just set [`LUMA_TX_TYPE`]. Armed for |
| 16338 | 16373 | // exactly this group's two chroma reads. |
| 16339 | 16374 | fctx.intrabc_chroma_tx.with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get)))); |
| 16375 | + // lane-av1txbands: the group's chroma is the CHROMA-REFERENCE | |
| 16376 | + // leaf's own block -- libaom codes one chroma unit under the | |
| 16377 | + // last sub-block only (`is_chroma_reference`), so its prediction | |
| 16378 | + // is that leaf's `uv_mode` (CfL alpha and all) unless THAT leaf | |
| 16379 | + // is the intrabc one. Arming this from a non-chroma-reference | |
| 16380 | + // leaf's DV made `warped.obu`'s 8x8 group at mi(40,62) copy | |
| 16381 | + // frame bytes at mi(41,62)'s vector where aomdec predicts | |
| 16382 | + // `uv_mode=UV_CFL_PRED`: luma stayed byte-exact and only chroma | |
| 16383 | + // moved (class chroma-keyed-at-a-non-chroma-leaf). Mirrors | |
| 16384 | + // [`decode_leaf_rect8`]'s own placement. | |
| 16385 | + last_intrabc = Some(dv); | |
| 16340 | 16386 | } |
| 16341 | - last_intrabc = Some(dv); | |
| 16342 | 16387 | continue; |
| 16343 | 16388 | } |
| 16344 | 16389 | if skip { |
| @@ -16411,6 +16456,18 @@ fn decode_leaf_split4( | ||
| 16411 | 16456 | } |
| 16412 | 16457 | push_intra(1, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx); |
| 16413 | 16458 | push_intra(2, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx); |
| 16459 | + // lane-av1txbands: a SKIPPED chroma-reference leaf reads no chroma | |
| 16460 | + // coefficient, so it never consults the inherited luma transform type | |
| 16461 | + // -- but an intrabc chroma-reference leaf did arm | |
| 16462 | + // [`INTRABC_CHROMA_TX`] above (`has_chroma`), and the two coefficient | |
| 16463 | + // branches below are the only ones that disarm it. Left armed, the slot | |
| 16464 | + // picks the NEXT block's chroma scan and inverse transform (class | |
| 16465 | + // arm-without-clear-on-a-skip-route). Counted so a gate can tell a | |
| 16466 | + // stream that reaches this route from one that never does. | |
| 16467 | + if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() { | |
| 16468 | + hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS); | |
| 16469 | + fctx.intrabc_chroma_tx.with(|c| c.set(None)); | |
| 16470 | + } | |
| 16414 | 16471 | (Grid::Zero(16), Grid::Zero(16)) |
| 16415 | 16472 | } else if let Some(dv) = last_intrabc { |
| 16416 | 16473 | // lane-av1txr: the chroma-reference leaf was an intrabc block, so the |
| @@ -16763,7 +16820,7 @@ fn decode_leaf_rect8( | ||
| 16763 | 16820 | ); |
| 16764 | 16821 | // `record_intrabc_mi` publishes a square `n4`x`n4` footprint; a |
| 16765 | 16822 | // 4x8/8x4 leaf needs its true `w_mi`x`h_mi` (lane-av1txr). |
| 16766 | - record_intrabc_mi_rect(lmi.0, lmi.1, w_mi, h_mi, Some(dv), fctx); | |
| 16823 | + record_intrabc_mi_rect(lmi.0, lmi.1, w_mi, h_mi, Some(dv), neighbours, fctx); | |
| 16767 | 16824 | if has_chroma { |
| 16768 | 16825 | last_uv = Some((DC_PRED, 0, None)); |
| 16769 | 16826 | last_intrabc = Some(dv); |
| @@ -16793,13 +16850,9 @@ fn decode_leaf_rect8( | ||
| 16793 | 16850 | // and desynced the tile at the very first rect leaf (class |
| 16794 | 16851 | // `symbol-consumption-gap`). |
| 16795 | 16852 | let depth = if tx_select { |
| 16796 | - // lane-t900 r2 (sibling sweep): the in-inter `TXFM_CONTEXT` band | |
| 16797 | - // read every other rect reader now does -- a no-op on a key frame. | |
| 16798 | - let ctx = if fctx.intra_in_inter_mode.with(std::cell::Cell::get).is_some() { | |
| 16799 | - tx_size_context_txfm_rect(neighbours, lmi, bw, bh, fctx) | |
| 16800 | - } else { | |
| 16801 | - tx_size_context_rect(neighbours, lmi, bw, bh) | |
| 16802 | - }; | |
| 16853 | + // lane-av1txbands: the `TXFM_CONTEXT` band read every other rect | |
| 16854 | + // reader already does. | |
| 16855 | + let ctx = tx_size_context_txfm_rect(neighbours, lmi, bw, bh, fctx); | |
| 16803 | 16856 | dec.symbol(&mut cdfs.tx_size_cat0[ctx]) |
| 16804 | 16857 | } else { |
| 16805 | 16858 | 0 |
| @@ -17019,6 +17072,18 @@ fn decode_leaf_rect8( | ||
| 17019 | 17072 | } |
| 17020 | 17073 | push_intra(1, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx); |
| 17021 | 17074 | push_intra(2, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx); |
| 17075 | + // lane-av1txbands: a SKIPPED chroma-reference leaf reads no chroma | |
| 17076 | + // coefficient, so it never consults the inherited luma transform type | |
| 17077 | + // -- but an intrabc chroma-reference leaf did arm | |
| 17078 | + // [`INTRABC_CHROMA_TX`] above (`has_chroma`), and the two coefficient | |
| 17079 | + // branches below are the only ones that disarm it. Left armed, the slot | |
| 17080 | + // picks the NEXT block's chroma scan and inverse transform (class | |
| 17081 | + // arm-without-clear-on-a-skip-route). Counted so a gate can tell a | |
| 17082 | + // stream that reaches this route from one that never does. | |
| 17083 | + if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() { | |
| 17084 | + hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS); | |
| 17085 | + fctx.intrabc_chroma_tx.with(|c| c.set(None)); | |
| 17086 | + } | |
| 17022 | 17087 | (Grid::Zero(16), Grid::Zero(16)) |
| 17023 | 17088 | } else if let Some(dv) = last_intrabc { |
| 17024 | 17089 | // lane-av1txr: the chroma-reference leaf was an intrabc block, so the |
| @@ -17851,29 +17916,24 @@ fn tx_h_px_at(n: &Neighbours, chroma: bool, mi_r: usize, mi_c: usize) -> u32 { | ||
| 17851 | 17916 | /// present only when its neighbour exists inside the true frame -- whether |
| 17852 | 17917 | /// the block immediately above (at this block's own leftmost mi column) or |
| 17853 | 17918 | /// to the left (at its own topmost mi row) coded a transform at least as wide |
| 17854 | -/// as `own_side`. | |
| 17855 | -fn tx_size_context(n: &Neighbours, (mi_r, mi_c): (usize, usize), own_side: usize) -> usize { | |
| 17856 | - let above = mi_r > n.tile_row0_mi && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_side; | |
| 17857 | - let left = mi_c > n.tile_col0_mi && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_side; | |
| 17858 | - usize::from(above) + usize::from(left) | |
| 17859 | -} | |
| 17860 | - | |
| 17861 | -/// `get_tx_size_context` as libaom actually writes it (`pred_common.h:342`), | |
| 17862 | -/// for a block inside an INTER frame: the two `TXFM_CONTEXT` arrays | |
| 17863 | -/// ([`Neighbours::above_txfm`]/[`Neighbours::left_txfm`], which only the | |
| 17864 | -/// inter path maintains), except that an *inter* neighbour contributes its | |
| 17865 | -/// own BLOCK size rather than its transform size -- the two differ the moment | |
| 17866 | -/// a neighbour's var-tx tree splits. [`tx_size_context`]'s deblock-grid | |
| 17867 | -/// approximation coincides with this only while every neighbour codes one | |
| 17868 | -/// whole-block transform, which is exactly what `TxMode::Select` ends. | |
| 17869 | -/// [`tx_size_context_txfm`] with the block's own width and height (lane-intrasplit | |
| 17870 | -/// r1): `get_tx_size_context` compares the neighbour ABOVE against | |
| 17871 | -/// `tx_size_wide[max_txsize_rect_lookup[bsize]]` and the neighbour to the LEFT | |
| 17872 | -/// against `tx_size_high[...]` (libaom `pred_common.h:342`), which for a 2:1 | |
| 17873 | -/// strip are two different numbers. The intra strip inside an inter frame read | |
| 17874 | -/// this through [`tx_size_context_rect`] -- the key frame's deblock-grid | |
| 17875 | -/// approximation -- so once `TxMode::Select` made the depth symbol exist, it was | |
| 17876 | -/// read off the wrong CDF row whenever a neighbour's var-tx tree had split. | |
| 17919 | +/// (tall) as this block's own `max_txsize_rect_lookup[bsize]`. | |
| 17920 | +/// | |
| 17921 | +/// lane-av1txbands: this reads the real `TXFM_CONTEXT` bands | |
| 17922 | +/// ([`Neighbours::above_txfm`]/[`Neighbours::left_txfm`]) for EVERY frame | |
| 17923 | +/// now -- libaom maintains them on intra-only frames too (`parse_decode_block` | |
| 17924 | +/// runs `set_txfm_ctxs` for every block, and | |
| 17925 | +/// [`Neighbours::fill_lf_grid_rect`] publishes them there), except that an | |
| 17926 | +/// *inter* neighbour contributes its own BLOCK size rather than its transform | |
| 17927 | +/// size -- and libaom's `is_inter_block` counts an INTRABC block | |
| 17928 | +/// (`blockd.h:373`), which is what the `above_inter`/`left_inter` bands carry. | |
| 17929 | +/// The previous deblock-grid approximation coincided with this only while | |
| 17930 | +/// every neighbour coded one whole-block transform, which is exactly what | |
| 17931 | +/// `TxMode::Select` ends. | |
| 17932 | +/// | |
| 17933 | +/// The rect form (lane-intrasplit r1): `get_tx_size_context` compares the | |
| 17934 | +/// neighbour ABOVE against `tx_size_wide[max_txsize_rect_lookup[bsize]]` and | |
| 17935 | +/// the neighbour to the LEFT against `tx_size_high[...]` (libaom | |
| 17936 | +/// `pred_common.h:342`), which for a 2:1 strip are two different numbers. | |
| 17877 | 17937 | fn tx_size_context_txfm_rect( |
| 17878 | 17938 | n: &Neighbours, |
| 17879 | 17939 | (mi_r, mi_c): (usize, usize), |
| @@ -17881,6 +17941,10 @@ fn tx_size_context_txfm_rect( | ||
| 17881 | 17941 | own_h: usize, fctx: &crate::decode::FrameCtx, |
| 17882 | 17942 | ) -> usize { |
| 17883 | 17943 | hit!(INTRA_IN_INTER_TXCTX_HITS); |
| 17944 | + // `max_txsize_rect_lookup[bsize]` tops out at TX_64X64: no transform is | |
| 17945 | + // wider or taller than 64, so a block with a 128 side resolves against 64 | |
| 17946 | + // (lane-sb128b r1). | |
| 17947 | + let (own_w, own_h) = (own_w.min(64), own_h.min(64)); | |
| 17884 | 17948 | let has_above = mi_r > n.tile_row0_mi; |
| 17885 | 17949 | let has_left = mi_c > n.tile_col0_mi; |
| 17886 | 17950 | let mut above = usize::from(n.above_txfm[mi_c]) >= own_w; |
| @@ -17894,8 +17958,9 @@ fn tx_size_context_txfm_rect( | ||
| 17894 | 17958 | if crate::envflags::env_flag!("EC_TXCTX") { |
| 17895 | 17959 | eprintln!( |
| 17896 | 17960 | "EC_TXCTX mi={mi_r},{mi_c} own={own_w}x{own_h} ha={has_above} hl={has_left} \ |
| 17897 | - above_txfm={} left_txfm={} above_inter={} left_inter={} above_side={} left_side={} \ | |
| 17898 | - above={above} left={left}", | |
| 17961 | + intra_only={} above_txfm={} left_txfm={} above_inter={} left_inter={} \ | |
| 17962 | + above_side={} left_side={} above={above} left={left}", | |
| 17963 | + fctx.intra_only.with(std::cell::Cell::get), | |
| 17899 | 17964 | n.above_txfm[mi_c], |
| 17900 | 17965 | n.left_txfm[mi_r], |
| 17901 | 17966 | n.above_inter[mi_c], |
| @@ -17910,17 +17975,11 @@ fn tx_size_context_txfm_rect( | ||
| 17910 | 17975 | (false, true) => usize::from(left), |
| 17911 | 17976 | (false, false) => 0, |
| 17912 | 17977 | }; |
| 17913 | - // lane-midcut r3: count only the blocks the KEY FRAME deblock-grid | |
| 17914 | - // approximation ([`tx_size_context_rect`]) would have read off a DIFFERENT | |
| 17915 | - // CDF row, i.e. exactly the blocks this band read fixes -- a plain "rect | |
| 17916 | - // intra in an inter frame" tally is green on the buggy code too (class | |
| 17917 | - // gate-blind-to-feature). | |
| 17918 | - if fctx.intra_in_inter_mode.with(std::cell::Cell::get).is_some() { | |
| 17919 | - let (cw, ch) = (own_w.min(64), own_h.min(64)); | |
| 17920 | - let stale = usize::from(has_above && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= cw) | |
| 17921 | - + usize::from(has_left && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= ch); | |
| 17978 | + { | |
| 17979 | + let stale = usize::from(has_above && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w) | |
| 17980 | + + usize::from(has_left && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_h); | |
| 17922 | 17981 | if ctx != stale { |
| 17923 | - hit!(INTRA_RECT_IN_INTER_TXCTX_OVERRIDE_HITS); | |
| 17982 | + hit!(TXCTX_DEBLOCK_DIVERGENCE_HITS); | |
| 17924 | 17983 | } |
| 17925 | 17984 | } |
| 17926 | 17985 | ctx |
| @@ -17983,10 +18042,6 @@ fn read_tx_size( | ||
| 17983 | 18042 | n: &Neighbours, |
| 17984 | 18043 | at_mi: (usize, usize), |
| 17985 | 18044 | side: usize, |
| 17986 | - // lane-txselect: `get_tx_size_context`'s real context, for the callers | |
| 17987 | - // that have one -- see [`tx_size_context_txfm`]. `None` keeps the | |
| 17988 | - // key-frame path's own deblock-grid approximation. | |
| 17989 | - ctx_override: Option<usize>, | |
| 17990 | 18045 | ) -> usize { |
| 17991 | 18046 | // `max_txsize_rect_lookup[bsize]` (libaom `read_selected_tx_size` / |
| 17992 | 18047 | // `get_tx_size_context`): a block wider than 64 still tops out at |
| @@ -17994,7 +18049,7 @@ fn read_tx_size( | ||
| 17994 | 18049 | // chain 64->32->16->8->4 is the same four steps) and resolves against 64, |
| 17995 | 18050 | // never against its own 128 side (lane-sb128b r1). |
| 17996 | 18051 | let max_tx = side.min(64); |
| 17997 | - let ctx = ctx_override.unwrap_or_else(|| tx_size_context(n, at_mi, max_tx)); | |
| 18052 | + let ctx = tx_size_context_txfm(n, at_mi, max_tx); | |
| 17998 | 18053 | let depth = match max_tx { |
| 17999 | 18054 | 8 => { |
| 18000 | 18055 | dec.symbol(&mut cdfs.tx_size_cat0[ctx]) |
| @@ -18477,10 +18532,6 @@ fn read_block_tx_size( | ||
| 18477 | 18532 | n, |
| 18478 | 18533 | at_mi, |
| 18479 | 18534 | side, |
| 18480 | - // lane-sb128c r3: `get_tx_size_context` compares the neighbour txfm | |
| 18481 | - // contexts against `tx_size_wide[max_txsize_rect_lookup[bsize]]`, | |
| 18482 | - // which is 64 for BLOCK_128X128 -- never the block's own 128 side. | |
| 18483 | - Some(tx_size_context_txfm(n, at_mi, side.min(64))), | |
| 18484 | 18535 | ) |
| 18485 | 18536 | }; |
| 18486 | 18537 | set_txfm_ctxs(n, at_mi, tx, side_mi, side_mi, skip && is_inter); |
| @@ -22693,6 +22744,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 22693 | 22744 | // otherwise inherit it and read its `tx_depth` context off the inter |
| 22694 | 22745 | // frame's stale `TXFM_CONTEXT` bands. |
| 22695 | 22746 | fctx.tx_select_inter.with(|c| c.set(false)); |
| 22747 | + // Every block of an intra-only frame publishes its resolved transform into | |
| 22748 | + // the `TXFM_CONTEXT` bands exactly like an inter frame's does -- see | |
| 22749 | + // [`Neighbours::fill_lf_grid_rect`]. | |
| 22750 | + fctx.intra_only.with(|c| c.set(true)); | |
| 22696 | 22751 | if mi_cols == 0 || mi_rows == 0 { |
| 22697 | 22752 | return Err(unsupported("a frame with no mode-info grid")); |
| 22698 | 22753 | } |
| @@ -31689,7 +31744,7 @@ fn decode_inter_sub8_split4( | ||
| 31689 | 31744 | /// depth symbol, the whole-leaf `TX_8X4`/`TX_4X8` or split `TX_4X4` walk, the |
| 31690 | 31745 | /// 4x4 chroma unit at the group's origin -- is [`decode_leaf_rect8`]'s body for |
| 31691 | 31746 | /// the same shape; the INTER-frame differences are the tx-depth context |
| 31692 | -/// (`above_txfm`/`left_txfm`, not the key frame's deblock-grid approximation), | |
| 31747 | +/// (`above_txfm`/`left_txfm`), | |
| 31693 | 31748 | /// `set_txfm_ctxs` publication, and the inter-side bands + mi map the caller's |
| 31694 | 31749 | /// inter leaves also write (`is_inter = 0`, ref `INTRA_FRAME`, no interp |
| 31695 | 31750 | /// filter). |
| @@ -39337,6 +39392,128 @@ mod tests { | ||
| 39337 | 39392 | ); |
| 39338 | 39393 | } |
| 39339 | 39394 | |
| 39395 | + /// lane-av1txbands item 3: the sub-8x8 group whose CHROMA-REFERENCE leaf | |
| 39396 | + /// codes `use_intrabc` AND `skip` -- the one route that arms | |
| 39397 | + /// [`INTRABC_CHROMA_TX`] and then reads no chroma coefficient at all, so | |
| 39398 | + /// before this round the slot stayed armed into the NEXT block's chroma | |
| 39399 | + /// read (whose scan and inverse transform it then picked). No encoder in | |
| 39400 | + /// hand codes this shape -- `crate::tile::write_intra_mode` hardcodes | |
| 39401 | + /// `skip = 0`, and `aomenc`'s RD search never picked it on any of this | |
| 39402 | + /// lane's screen-content recipes (the census in | |
| 39403 | + /// `lanes/av1txbands.report.md`) -- so the symbol sequence is | |
| 39404 | + /// hand-written, exactly as [`a_skipped_block_decodes_to_pure_prediction`] | |
| 39405 | + /// does for a skipped block. | |
| 39406 | + /// | |
| 39407 | + /// An 8x8 frame descends the superblock cascade to one 8x8 group without | |
| 39408 | + /// coding any partition symbol at the outer levels (the true frame edge | |
| 39409 | + /// forces every split), so that group's own `partition_w8` is the first | |
| 39410 | + /// symbol the tile reads. | |
| 39411 | + #[test] | |
| 39412 | + fn a_skipped_intrabc_chroma_reference_leaf_disarms_the_inherited_chroma_tx() { | |
| 39413 | + let fctx = &crate::decode::FrameCtx::new(); | |
| 39414 | + reset_skipped_intrabc_chroma_arm_hits(); | |
| 39415 | + use crate::msac::SymbolEncoder; | |
| 39416 | + let mut cdfs = Cdfs::new(q_ctx_of(40)); | |
| 39417 | + let mut enc = SymbolEncoder::new(); | |
| 39418 | + // The frame edge forces every split above this group, so its own | |
| 39419 | + // `partition_w8` is the FIRST symbol the tile reads. | |
| 39420 | + enc.symbol(PARTITION_SPLIT, &mut cdfs.partition_w8[0]); | |
| 39421 | + // Leaves 0..2: ordinary intra `DC_PRED`, skipped (a skipped block codes | |
| 39422 | + // no coefficient at all, which is what keeps this sequence short). | |
| 39423 | + // `get_skip_txfm_context` over the group: 0 with no skipped neighbour | |
| 39424 | + // yet, 1 once leaf 0 is to the left (leaf 1) or above (leaf 2), and 2 | |
| 39425 | + // for the bottom-right leaf, which has both. | |
| 39426 | + for skip_ctx in [0usize, 1, 1] { | |
| 39427 | + enc.symbol(1, &mut cdfs.skip[skip_ctx]); | |
| 39428 | + enc.symbol(0, &mut cdfs.intrabc); | |
| 39429 | + enc.symbol( | |
| 39430 | + DC_PRED, | |
| 39431 | + &mut cdfs.kf_y_mode[INTRA_MODE_CTX[DC_PRED]][INTRA_MODE_CTX[DC_PRED]], | |
| 39432 | + ); | |
| 39433 | + } | |
| 39434 | + // Leaf 3 IS the group's chroma reference: skipped AND intrabc. | |
| 39435 | + enc.symbol(1, &mut cdfs.skip[2]); | |
| 39436 | + enc.symbol(1, &mut cdfs.intrabc); | |
| 39437 | + enc.symbol(0, &mut cdfs.dv_joint); | |
| 39438 | + let data = enc.finish(); | |
| 39439 | + let _ = decode_key_frame_tile( | |
| 39440 | + &data, | |
| 39441 | + 2, | |
| 39442 | + 2, | |
| 39443 | + 40, | |
| 39444 | + 8, | |
| 39445 | + 8, | |
| 39446 | + false, | |
| 39447 | + &CdefParams::default(), | |
| 39448 | + &LoopFilterParams::default(), | |
| 39449 | + false, | |
| 39450 | + true, | |
| 39451 | + true, | |
| 39452 | + true, | |
| 39453 | + fctx, | |
| 39454 | + ); | |
| 39455 | + assert!( | |
| 39456 | + skipped_intrabc_chroma_arm_hits() >= 1, | |
| 39457 | + "the hand-written tile never reached the skipped-intrabc chroma-reference route" | |
| 39458 | + ); | |
| 39459 | + assert!( | |
| 39460 | + fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_none(), | |
| 39461 | + "the inherited chroma transform slot must be disarmed when its block's chroma \ | |
| 39462 | + route ends, or the NEXT block's chroma read picks its scan and inverse transform" | |
| 39463 | + ); | |
| 39464 | + } | |
| 39465 | + | |
| 39466 | + /// [`a_skipped_intrabc_chroma_reference_leaf_disarms_the_inherited_chroma_tx`]'s | |
| 39467 | + /// twin for the OTHER sub-8x8 group shape: a `partition_w8` of VERT sends | |
| 39468 | + /// the 8x8 to [`decode_leaf_rect8`], whose chroma reference is its second | |
| 39469 | + /// (right-hand) 8x4 leaf. Same route, same disarm. | |
| 39470 | + #[test] | |
| 39471 | + fn a_skipped_intrabc_rect_chroma_reference_leaf_disarms_the_inherited_chroma_tx() { | |
| 39472 | + let fctx = &crate::decode::FrameCtx::new(); | |
| 39473 | + reset_skipped_intrabc_chroma_arm_hits(); | |
| 39474 | + use crate::msac::SymbolEncoder; | |
| 39475 | + let mut cdfs = Cdfs::new(q_ctx_of(40)); | |
| 39476 | + let mut enc = SymbolEncoder::new(); | |
| 39477 | + enc.symbol(PARTITION_VERT, &mut cdfs.partition_w8[0]); | |
| 39478 | + // Left leaf: skipped intra `DC_PRED`. | |
| 39479 | + enc.symbol(1, &mut cdfs.skip[0]); | |
| 39480 | + enc.symbol(0, &mut cdfs.intrabc); | |
| 39481 | + enc.symbol( | |
| 39482 | + DC_PRED, | |
| 39483 | + &mut cdfs.kf_y_mode[INTRA_MODE_CTX[DC_PRED]][INTRA_MODE_CTX[DC_PRED]], | |
| 39484 | + ); | |
| 39485 | + // Right leaf IS the group's chroma reference: skipped AND intrabc. | |
| 39486 | + enc.symbol(1, &mut cdfs.skip[1]); | |
| 39487 | + enc.symbol(1, &mut cdfs.intrabc); | |
| 39488 | + enc.symbol(0, &mut cdfs.dv_joint); | |
| 39489 | + let data = enc.finish(); | |
| 39490 | + let _ = decode_key_frame_tile( | |
| 39491 | + &data, | |
| 39492 | + 2, | |
| 39493 | + 2, | |
| 39494 | + 40, | |
| 39495 | + 8, | |
| 39496 | + 8, | |
| 39497 | + false, | |
| 39498 | + &CdefParams::default(), | |
| 39499 | + &LoopFilterParams::default(), | |
| 39500 | + false, | |
| 39501 | + true, | |
| 39502 | + true, | |
| 39503 | + true, | |
| 39504 | + fctx, | |
| 39505 | + ); | |
| 39506 | + assert!( | |
| 39507 | + skipped_intrabc_chroma_arm_hits() >= 1, | |
| 39508 | + "the hand-written tile never reached the skipped-intrabc rect chroma-reference route" | |
| 39509 | + ); | |
| 39510 | + assert!( | |
| 39511 | + fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_none(), | |
| 39512 | + "the inherited chroma transform slot must be disarmed when its block's chroma \ | |
| 39513 | + route ends, or the NEXT block's chroma read picks its scan and inverse transform" | |
| 39514 | + ); | |
| 39515 | + } | |
| 39516 | + | |
| 39340 | 39517 | /// An inter tile's SB-level `part64` used to be read and thrown away |
| 39341 | 39518 | /// (`let _ = part64;`), recursing as SPLIT unconditionally -- a real |
| 39342 | 39519 | /// non-SPLIT value there silently desynced the whole tile instead of |
crates/ec-av1/src/stream.rsmodified+8 -0
| @@ -187,6 +187,14 @@ pub fn intrabc_hits() -> usize { | ||
| 187 | 187 | crate::decode::intrabc_hits() |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | +/// lane-av1txbands: sub-8x8 group chroma-reference leaves that USED intrabc and | |
| 191 | +/// were SKIPPED -- the route that armed [`crate::decode::intrabc_hits`]'s chroma | |
| 192 | +/// transform slot and then read no chroma coefficient. A non-zero value is what | |
| 193 | +/// makes the disarm at that route load-bearing on a real stream. | |
| 194 | +pub fn skipped_intrabc_chroma_arm_hits() -> usize { | |
| 195 | + crate::decode::skipped_intrabc_chroma_arm_hits() | |
| 196 | +} | |
| 197 | + | |
| 190 | 198 | /// lane-sb128c r8: the 128 root's INTRA (key-frame) rect arm -- (128x64 |
| 191 | 199 | /// blocks, 64x128 blocks, blocks per resolved intra `tx_depth` 0/1/2). |
| 192 | 200 | pub fn intra_sb128_counters() -> (usize, usize, [usize; 3]) { |
lanes/av1txbands.report.mdadded+290 -0
| @@ -0,0 +1,290 @@ | ||
| 1 | +# lane-av1-txbands — warped byte-exact; the key-frame TXFM bands are published by every block | |
| 2 | + | |
| 3 | +Base: `main` **3ecd4a10** (wave 1 merged). Worktree `../edith_codecs-av1txb`, branch | |
| 4 | +`lane-av1-txbands`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1txb`, | |
| 5 | +`TMPDIR=$HOME/.cache/tmp-av1txb`. Nothing pushed. | |
| 6 | + | |
| 7 | +Three items, all landed: (1) the key-frame tx-depth/var-tx context now reads the | |
| 8 | +real `TXFM_CONTEXT` bands, which an intra-only frame now maintains like libaom | |
| 9 | +does — **`warped.obu` is byte-exact end to end**; (2) the sub-8x8 group's chroma | |
| 10 | +keying (`decode_leaf_split4`'s `last_intrabc`) — found by that same stream, whose | |
| 11 | +luma was already exact while only chroma moved; (3) the `intrabc_chroma_tx` slot | |
| 12 | +leak — two reachable routes, both fixed, both witnessed by a hand-written tile. | |
| 13 | +One **pre-existing** defect found and deferred (a panic, §7), stated as such. | |
| 14 | + | |
| 15 | +--- | |
| 16 | + | |
| 17 | +## 1. Headline: `warped` is byte-exact, and it moved 4.5x on `allintra` | |
| 18 | + | |
| 19 | +`aomenc --enable-warped-motion=1 --cpu-used=0` over `testsrc2 320x240 rate 8 dur 3`: | |
| 20 | + | |
| 21 | +``` | |
| 22 | +$PROBE ~/.cache/av1txr/s/warped.obu /tmp/w.raw # OK: 24 frames decoded, 320x240 | |
| 23 | +ffmpeg -loglevel error -i ~/.cache/av1txr/s/warped.obu -pix_fmt yuv420p -f rawvideo /tmp/w.ref.raw -y | |
| 24 | +cmp /tmp/w.raw /tmp/w.ref.raw # identical | |
| 25 | +sha256 196fdd8be1c5c04a6e3f031892b55deb9606e7ba8c89dad196b11c27e8395162 (both files, 2764800 B) | |
| 26 | +``` | |
| 27 | + | |
| 28 | +On the merged base that same command **REFUSES** in frame 0 | |
| 29 | +(`intra block copy on a HORZ/VERT/1:4 rect intra strip`), which is a desync | |
| 30 | +symptom: with the context bands wrong the tile's symbol stream walks off into a | |
| 31 | +shape it cannot reconstruct. | |
| 32 | + | |
| 33 | +`allintra.obu` (aomenc `--allintra --cpu-used=6`) still stops, but far later. | |
| 34 | +Measured with the `intrabc` symbol ladder against the instrumented `aomdec` | |
| 35 | +(`EC_TRACE_MODE_STEP=1`, one `name=intrabc` token per block, both decoders): | |
| 36 | + | |
| 37 | +| build | intrabc tokens decoded | first divergence from aomdec | | |
| 38 | +|---|---|---| | |
| 39 | +| merged base | 650 | token **570**, `aom=mi(28,64)` vs `base=mi(26,68)` | | |
| 40 | +| **this lane** | 2658 | token **2593**, `aom=mi(32,24)` vs `lane=mi(36,22)` | | |
| 41 | +| aomdec (reference) | 10315 | — | | |
| 42 | + | |
| 43 | +So the first divergence moved from 570 to 2593 (4.55x further), and what stops | |
| 44 | +`allintra`/`allintra0` now is a **named refusal of its own** | |
| 45 | +(`intra block copy on a HORZ/VERT/1:4 rect intra strip …`, `decode.rs`'s rect | |
| 46 | +mode reader) at mi(32,68) in frame 0 — the rect-strip intrabc reconstruction | |
| 47 | +gap, which is **lane-av1-intrabc's** (Kubra owns that reader; coordinated, she | |
| 48 | +keeps the write side off her plate — see §9). | |
| 49 | + | |
| 50 | +## 2. What changed | |
| 51 | + | |
| 52 | +### 2.1 The bands are now maintained on intra-only frames too | |
| 53 | + | |
| 54 | +libaom runs `set_txfm_ctxs(mbmi->tx_size, xd->width, xd->height, | |
| 55 | +mbmi->skip_txfm && is_inter_block(mbmi), xd)` at the end of **every** | |
| 56 | +`parse_decode_block` (`decodeframe.c:1229`), an intra-only frame's blocks | |
| 57 | +included, and `get_tx_size_context` (`pred_common.h:342`) plus | |
| 58 | +`txfm_partition_context` read those two arrays. This decoder published them on | |
| 59 | +inter frames only, and read them on inter frames only: an intra-only frame's | |
| 60 | +`tx_depth`/`txfm_split` context came off the **deblock grid** | |
| 61 | +(`tx_px_at`/`tx_h_px_at`), an approximation that coincides with the bands only | |
| 62 | +while every neighbour codes one whole-block transform. | |
| 63 | + | |
| 64 | +Now: | |
| 65 | + | |
| 66 | +* `FrameCtx::intra_only` (new `Cell<bool>`) is set in | |
| 67 | + `decode_key_frame_tile_with_cdfs` and cleared in `set_inter_tx_mode` (the one | |
| 68 | + place the inter tile decoder arms its own frame state). | |
| 69 | +* `Neighbours::fill_lf_grid_rect` — the deblocker's own grid, called by **every** | |
| 70 | + block body with the resolved transform and the block's mi span — publishes the | |
| 71 | + same `(tx_w, tx_h)` over the same span into `above_txfm`/`left_txfm` when | |
| 72 | + `intra_only` is set, and stamps `above_inter`/`left_inter` false over that | |
| 73 | + span. That is what makes the coverage complete without threading a new call | |
| 74 | + through ten block bodies; the two bodies that can code an **intrabc** block | |
| 75 | + keep their explicit `set_txfm_ctxs` (still `allow_intrabc`-gated) because | |
| 76 | + libaom's `skip && is_inter` term makes a *skipped intrabc* block publish its | |
| 77 | + BLOCK size, which the deblock grid cannot express. | |
| 78 | +* `read_tx_size` always reads `tx_size_context_txfm`; the seven | |
| 79 | + `if intra_in_inter_mode.is_some() { …txfm… } else { …deblock… }` sites now | |
| 80 | + read `tx_size_context_txfm_rect` unconditionally; `tx_size_context` and | |
| 81 | + `tx_size_context_rect` are **deleted** (the deblock approximation survives only | |
| 82 | + in the divergence witness counter, §6). | |
| 83 | +* `record_intrabc_mi_rect` now also stamps `above_inter`/`left_inter` **true** | |
| 84 | + over an intrabc block's own span: libaom's `is_inter_block` is | |
| 85 | + `is_intrabc_block(mbmi) || ref_frame[0] > INTRA_FRAME` (`blockd.h:373`), so | |
| 86 | + `get_tx_size_context` reads an intrabc neighbour's **block size** instead of | |
| 87 | + its transform band. This is the whole of the `(46,66)` divergence: the block | |
| 88 | + above it is an intrabc `BLOCK_8X4` at mi(45,66) whose band was 4 while its | |
| 89 | + block width is 8. | |
| 90 | + | |
| 91 | +### 2.2 `decode_leaf_split4`: chroma is keyed on the CHROMA-REFERENCE leaf | |
| 92 | + | |
| 93 | +`last_intrabc` was set by **every** intrabc leaf of the 2x2 group and only | |
| 94 | +cleared by the coefficient branches, so a group whose intrabc leaf was a | |
| 95 | +non-chroma-reference one (i=2) reconstructed its single chroma unit as a frame | |
| 96 | +copy at **that** leaf's block vector — where libaom codes one chroma unit under | |
| 97 | +the last sub-block only (`is_chroma_reference`), so the prediction is leaf 3's | |
| 98 | +own `uv_mode` (its `cfl_alphas` included). Moved inside `if has_chroma`, | |
| 99 | +mirroring `decode_leaf_rect8`. `warped.obu`'s 8x8 group at mi(40,62) is exactly | |
| 100 | +that shape (leaf 2 intrabc, leaf 3 `uv_mode = UV_CFL_PRED`), and it was the | |
| 101 | +**only** remaining divergence once the bands were fixed: luma byte-exact, | |
| 102 | +chroma wrong from its first sample (luma byte 89724, chroma row 80). | |
| 103 | + | |
| 104 | +### 2.3 `intrabc_chroma_tx`: armed routes are now disarmed routes | |
| 105 | + | |
| 106 | +See §5. | |
| 107 | + | |
| 108 | +## 3. Regression evidence | |
| 109 | + | |
| 110 | +**Corpus sweep, base build vs this lane's build, byte-for-byte** (same probe, | |
| 111 | +private target dirs; `$PROBE <stream> <out.raw>` then `cmp`): all 23 committed | |
| 112 | +`crates/ec-av1/fixtures/*.obu` produce **identical** plane bytes, and so do 40 | |
| 113 | +generated streams (4:4:4 controls, `plain`, `cdf0`, 16-lossless/blur/box/flat | |
| 114 | +aomenc recipes, the s2/s3 screen-content attempts). Every 4:4:4 stream still | |
| 115 | +**refuses by name** (`a chroma format other than 4:2:0`), and the three | |
| 116 | +generated streams that the base refused with a *desync-induced* string | |
| 117 | +(`an intrabc block whose var-tx tree resolved to mixed leaf transform sizes`, | |
| 118 | +`blur-screen-cpu0`) now refuse with the genuine rect-strip-intrabc string — | |
| 119 | +both still zero bytes. | |
| 120 | + | |
| 121 | +The one row that differs in that table is the intended one: `warped.obu` base | |
| 122 | +`REFUSED` → this lane `OK: 24 frames`. | |
| 123 | + | |
| 124 | +**Refusal/witness probes** (per-lane context): the committed reelb_*/reelc_*/ | |
| 125 | +palette_*/superres_* 10-bit and screen fixtures all decode byte-exact against | |
| 126 | +ffmpeg inside the suite (identical to base in the sweep above); the non-4:2:0 and | |
| 127 | +qmatrix refusals are unchanged. The 10-bit film-window hash probe | |
| 128 | +(`hbd-r5/reelb.obu`, sha256 `d7214bb7…`) could **not** be re-run: that stream is | |
| 129 | +no longer on disk anywhere under `$HOME` (`find` for `reelb*.obu`: none). Its | |
| 130 | +regression role is covered by the committed `reelb_*` 10-bit witnesses, which are | |
| 131 | +byte-identical to the base build and ffmpeg-exact (the suite prints them). | |
| 132 | + | |
| 133 | +## 4. Item 2 witness | |
| 134 | + | |
| 135 | +The stream is its own witness: pre-fix it is luma-exact and chroma-wrong | |
| 136 | +(`cmp` first difference at byte 89724, i.e. chroma row 80 of frame 0), post-fix | |
| 137 | +the whole 24-frame file is identical to ffmpeg's decode (sha256 above). Nothing | |
| 138 | +else changed for that stream's symbols (the luma plane was already byte-exact | |
| 139 | +before the one-line move), which is the point: the slot only ever decided the | |
| 140 | +chroma prediction's *source*, never a symbol. | |
| 141 | + | |
| 142 | +## 5. Item 3: the `intrabc_chroma_tx` slot leak — two routes, both fixed | |
| 143 | + | |
| 144 | +`INTRABC_CHROMA_TX` is the `Cell<Option<TxType>>` that stands in for libaom's | |
| 145 | +`xd->tx_type_map` at the co-located luma position: it is armed immediately | |
| 146 | +before an intrabc block's two chroma `read_plane` calls and cleared immediately | |
| 147 | +after, and the chroma reader picks its scan and inverse transform off it. | |
| 148 | + | |
| 149 | +**The leak.** An intrabc sub-8x8 group leaves one arm at the *group's* | |
| 150 | +chroma-reference leaf, but the group's chroma section dispatches | |
| 151 | +`leaf_skips[chroma_ref]` **first**: a SKIPPED chroma-reference leaf reads no | |
| 152 | +chroma coefficient at all, so it never reaches the coefficient branch that | |
| 153 | +would have disarmed the slot — which then stayed armed into the **next** block's | |
| 154 | +chroma read, changing that block's scan and inverse transform. | |
| 155 | + | |
| 156 | +Three routes carry the arm-then-skip shape, and the census (every `intrabc_chroma_tx` write on the | |
| 157 | +production path: four arms, four clears, one reader) is: | |
| 158 | + | |
| 159 | +| route | arms? | clears? | | |
| 160 | +|---|---|---| | |
| 161 | +| `decode_leaf_split4` (4x4 group) | yes, on `has_chroma` | **no** → fixed (disarm + `SKIPPED_INTRABC_CHROMA_ARM_HITS`) | | |
| 162 | +| `decode_leaf_rect8` (4x8/8x4 group) | yes, on `has_chroma` | **no** → fixed (same) | | |
| 163 | +| `decode_block` (square) | no arm on the skip route (arm and clear are straight-line in the same branch, `14772`→`14830`) | n/a | | |
| 164 | +| `decode_leaf8` (8x8) | no arm on the skip route (same straight-line pairing) | n/a | | |
| 165 | + | |
| 166 | +(The `decode_intra_sub8_leaf` chroma-skip branch, `decode.rs`'s inter-frame | |
| 167 | +sub-8x8 twin, has no intrabc arm either — intrabc exists on intra-only frames | |
| 168 | +only.) So the reachable instances are exactly the two fixed above; the | |
| 169 | +"square-path instance" this lane was sent to sweep does not exist as an | |
| 170 | +arm-without-clear (it can only *suffer* a leak, which the source-side fix now | |
| 171 | +removes), and that is stated here rather than papered over with a dead clear. | |
| 172 | + | |
| 173 | +**Census: no stream in hand reaches the route.** `aomenc` never picked it on any | |
| 174 | +recipe tried (screen-content / lossless / cpu-used 0..6 / flat, blur, box, | |
| 175 | +repeated-rectangle and drawn-text sources), this crate's own encoder cannot | |
| 176 | +(`crate::tile::write_intra_mode` hardcodes `skip = 0`), and the counter reads 0 | |
| 177 | +on every committed fixture and generated stream | |
| 178 | +(`$PROBE <stream>` prints `skipped_intrabc_chroma_arm_hits:`). | |
| 179 | + | |
| 180 | +**Witness tests** (two, one per route), driving the kernel with hand-written | |
| 181 | +symbols exactly as `a_skipped_block_decodes_to_pure_prediction` does — an 8x8 | |
| 182 | +frame descends the superblock cascade to one 8x8 group with no partition symbol | |
| 183 | +of its own, so the tile is `partition_w8` + four/nTwo leaf symbol sets: | |
| 184 | + | |
| 185 | +* `a_skipped_intrabc_chroma_reference_leaf_disarms_the_inherited_chroma_tx` | |
| 186 | + (`partition_w8 = SPLIT` → `decode_leaf_split4`), | |
| 187 | +* `a_skipped_intrabc_rect_chroma_reference_leaf_disarms_the_inherited_chroma_tx` | |
| 188 | + (`partition_w8 = VERT` → `decode_leaf_rect8`). | |
| 189 | + | |
| 190 | +Each asserts (a) the route was reached (`skipped_intrabc_chroma_arm_hits() >= 1`) | |
| 191 | +and (b) the slot is disarmed at the end (`intrabc_chroma_tx` is `None`). | |
| 192 | + | |
| 193 | +**Fail-pre-fix, measured** (the disarm removed on that route, counter kept): | |
| 194 | + | |
| 195 | +``` | |
| 196 | +a_skipped_intrabc_chroma_reference_leaf_disarms_the_inherited_chroma_tx ... FAILED | |
| 197 | + panicked: the inherited chroma transform slot must be disarmed when its block's chroma | |
| 198 | + route ends, or the NEXT block's chroma read picks its scan and inverse transform | |
| 199 | +``` | |
| 200 | +and identically for the rect8 twin (its own disarm removed → only that test | |
| 201 | +fails). Restored, both pass. | |
| 202 | + | |
| 203 | +## 6. Gates | |
| 204 | + | |
| 205 | +* `cargo check -p ec-av1 --all-targets` — **0 warnings** | |
| 206 | + (`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1txb`, `cargo check` after a | |
| 207 | + touch-sweep). | |
| 208 | +* `cargo test -p ec-av1 --lib` (to completion, hub-supervised) — | |
| 209 | + **still running at yield time** (hub process `av1txb-suite`, started before the final edits-freeze; the tree it runs on is the tree in the commit). Its scope: the full `ec-av1` lib suite on this branch, expected `600 passed; 0 failed; 60 ignored` (base 598 + this lane's 2 new gates). The scoped runs that DID complete on this tree: `cargo check -p ec-av1 --all-targets` = 0 warnings (forced re-check), both new gates and both fail-pre-fix runs, and the base-vs-lane corpus byte sweep in §3. | |
| 210 | +* Two new gates (`a_skipped_intrabc_{,}rect_…`) plus their fail-pre-fix runs | |
| 211 | + above; the previous baseline was 598 passed / 0 failed / 60 ignored, so this | |
| 212 | + lane's target is **600 passed / 60 ignored**. | |
| 213 | +* Regression probes: §3 (corpus base-vs-lane byte sweep, refusal preservation). | |
| 214 | +* Divergence witness counter `TXCTX_DEBLOCK_DIVERGENCE_HITS` | |
| 215 | + (`decode::txctx_deblock_divergence_hits`) counts blocks where the band read | |
| 216 | + resolves to a **different** CDF row than the deleted deblock approximation — | |
| 217 | + i.e. exactly the blocks this change fixes. It replaced | |
| 218 | + `INTRA_RECT_IN_INTER_TXCTX_OVERRIDE_HITS`, which was inter-frame-only and had | |
| 219 | + no reader. | |
| 220 | + | |
| 221 | +## 7. Found and DEFERRED (not this lane's shape): a lossless 128-axis intra block panics | |
| 222 | + | |
| 223 | +`decode_block_128rect` has no `lossless` carve-out. libaom's `read_block_tx_size` | |
| 224 | +returns TX_4X4 for a lossless frame before reading anything, but this body still | |
| 225 | +reads a 64/32-point transform and then reconstructs with a residual slice sized | |
| 226 | +for a 4x4 unit: | |
| 227 | + | |
| 228 | +``` | |
| 229 | +$ ~/.cache/aomenc --codec=av1 --passes=1 --threads=1 --obu --lossless=1 --cpu-used=0 \ | |
| 230 | + -o /tmp/loss.obu <320x240 y4m> | |
| 231 | +$ $PROBE /tmp/loss.obu /dev/null | |
| 232 | +thread 'main' panicked at crates/ec-av1/src/decode.rs:3596:16: | |
| 233 | +index out of bounds: the len is 16 but the index is 16 | |
| 234 | + decode::exec_intra <- decode::read_plane <- decode::decode_block_128rect | |
| 235 | +``` | |
| 236 | + | |
| 237 | +**Pre-existing**: the merged base panics at the same place (its line 3587, the | |
| 238 | +same site before this lane's edits), and it is reachable via any `--lossless=1` | |
| 239 | +stream that codes a `BLOCK_128X64`/`BLOCK_64X128` intra block (the panicking | |
| 240 | +block is `fn=rect bw=64 bh=128` at mi(32,64)). Disposition: **deferred(lossless | |
| 241 | +128-axis intra tiling)** — the fix is a TX_4X4 per-unit arm (or a named refusal | |
| 242 | +at this body's head) and belongs with a lossless-shape lane; it is *not* a | |
| 243 | +regression and is stated here rather than folded silently into a success | |
| 244 | +summary. | |
| 245 | + | |
| 246 | +## 8. Repro recipes | |
| 247 | + | |
| 248 | +``` | |
| 249 | +# build (absolute fixture env; private target dir) | |
| 250 | +cd /home/user/Documents/Code/Rust/edith_codecs-av1txb | |
| 251 | +CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1txb TMPDIR=$HOME/.cache/tmp-av1txb \ | |
| 252 | + cargo build --release -p ec-av1 --example decode_probe | |
| 253 | + | |
| 254 | +# streams (re-derivable) | |
| 255 | +cd ~/.cache/av1txr | |
| 256 | +aomenc --codec=av1 --passes=1 --threads=1 --obu --enable-warped-motion=1 --cpu-used=0 -o s/warped.obu s/s420.y4m | |
| 257 | +aomenc --codec=av1 --passes=1 --threads=1 --obu --allintra --cpu-used=6 -o s/allintra.obu s/s420.y4m | |
| 258 | +# (s420.y4m = ffmpeg -f lavfi -i testsrc2=size=320x240:rate=8:duration=3 -pix_fmt yuv420p) | |
| 259 | + | |
| 260 | +# byte-exactness (8-bit: EC_PROBE_OUT16 is yuv420p10le and must NOT be compared | |
| 261 | +# to ffmpeg's yuv420p10le for an 8-bit source -- ffmpeg left-shifts, the probe does not) | |
| 262 | +$PROBE s/warped.obu out8.raw | |
| 263 | +ffmpeg -i s/warped.obu -pix_fmt yuv420p -f rawvideo ref8.raw -y && cmp out8.raw ref8.raw | |
| 264 | + | |
| 265 | +# base-vs-lane regression sweep | |
| 266 | +$PROBE <stream> a.raw && cargo-target-base/release/examples/decode_probe <stream> b.raw && cmp a.raw b.raw | |
| 267 | + | |
| 268 | +# the two witness gates + their fail-pre-fix runs | |
| 269 | +CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1txb cargo test -p ec-av1 --lib -- a_skipped_intrabc | |
| 270 | + | |
| 271 | +# the divergence ladder (per-name intrabc tokens; rng values COLLIDE, do not align on them) | |
| 272 | +EC_TRACE_MODE_STEP=1 ~/.cache/aom-oracle/build/aomdec --rawvideo -o /dev/null s/allintra.obu 2>a.step | |
| 273 | +EC_TRACE_MODE_STEP=1 $PROBE s/allintra.obu /dev/null 2>o.step | |
| 274 | +grep -oP 'mi_row=\d+ mi_col=\d+ name=intrabc val=-?\d+' a.step > a.ib # then diff a.ib o.ib | |
| 275 | +``` | |
| 276 | + | |
| 277 | +## 9. Notes for the next lane | |
| 278 | + | |
| 279 | +* **`lane-av1-intrabc` (Kubra)**: the band WRITE side is this lane's and is | |
| 280 | + landed — rebase on `lane-av1-txbands` rather than adding publishes in the | |
| 281 | + rect-strip bodies. `allintra`/`allintra0` now stop at the genuine | |
| 282 | + `intra block copy on a HORZ/VERT/1:4 rect intra strip` refusal at mi(32,68) | |
| 283 | + frame 0 (was a desync at mi(28,64)); the mixed-leaf var-tx refusal the base hit | |
| 284 | + on `blur-screen-cpu0` is no longer reached (that was a desync symptom too). | |
| 285 | +* `EC_TXCTX` still prints both bands, `above_inter`/`left_inter`, the neighbour | |
| 286 | + sides and the new `intra_only` flag; `EC_TXCTXDBG` was removed with the | |
| 287 | + temporary probe print it served. | |
| 288 | +* The deblock approximation is gone from the read path but still computed (as | |
| 289 | + `tx_px_at`/`tx_h_px_at`) for the divergence counter and for the deblocker | |
| 290 | + itself; deleting it wholesale means deleting that counter. |