From 37c9fd74686fa567a68f022844daf33cad7b9190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Sep 2026 19:54:58 +0300 Subject: [PATCH] feat(av1): decode the 128-root HORZ/VERT half coded INTRA in an inter frame (opt-in, ungated) The shape routes through the key frame's own proven body (decode_block_128rect: square TX_64X64 luma units, one TX_32X32 chroma unit per 64x64 mu chunk on the offset-10 txb_skip rows, per-TU prediction, Reach::of_tu mu-chunk rule, frame-edge write clip) with the three inter-frame differences: the mode-info read (INTRA_IN_INTER_MODE -> y_mode[3] -- size_group_lookup puts BLOCK_128X64/64X128/128X128 in group 3 -- plus the skip the inter caller already read), the tx_depth context (the real TXFM_CONTEXT bands via tx_size_context_txfm_rect against max_txsize_rect_lookup's TX_64X64, hence min(64)), and the set_txfm_ctxs publication an intra block of an inter frame makes. CfL (>32), filter intra (>32) and palette (>64) do not exist at this size and stay refused by name inside that body. OPT-IN ONLY (EC_INTRA128_IN_INTER=1): the named refusal is NOT lifted, because nothing proves the arm yet. The three 2 s cuts of the 10-bit 1920x792 128-superblock stream that reach this shape reach it AFTER a pre-existing entropy desync -- their frame 2 diverges from instrumented aomdec inside the superblock at mi(0,320), hundreds of blocks before mi(128,416) -- and three aomenc recipes (256x256 noise / static-band-plus-noise-strips, cq 20/32/45/55, --sb-size=128 --min-partition-size=64 --enable-rect-partitions=1 --kf-max-dist=100) produced zero 128-root HORZ/VERT halves in an inter frame at all. Default decode behaviour is byte-for-byte unchanged. --- crates/ec-av1/examples/decode_probe.rs | 4 ++ crates/ec-av1/src/decode.rs | 90 +++++++++++++++++++++++++- crates/ec-av1/src/stream.rs | 6 ++ 3 files changed, 98 insertions(+), 2 deletions(-) diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index b10e749b..eb002b74 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -78,6 +78,10 @@ fn main() { println!( "rect_wedge(8x16,16x8,16x32,32x16,8x32,32x8): compound={rw:?} interintra={rwi:?}" ); + // lane-inter128intra r1: the 128 root's HORZ/VERT half coded INTRA in + // an INTER frame -- the arm this round implemented. + let i128 = ec_av1::stream::intra128_in_inter_counters(); + println!("intra128_in_inter: 128x64={} 64x128={}", i128[0], i128[1]); let sb = ec_av1::stream::sb128_rect_counters(); println!( "sb128_rect: edge_horz={} edge_vert={} inter_128x64={} inter_64x128={}", diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 0554728b..2f810b6a 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -7386,6 +7386,56 @@ fn decode_intra_rect_in_inter( }); return Ok(()); } + // lane-inter128intra r1: the 128 superblock's PARTITION_HORZ/VERT half + // coded INTRA inside an inter frame. `size_group_lookup` (common_data.h:61) + // puts BLOCK_128X64/64X128/128X128 in group 3 and + // `max_txsize_rect_lookup` caps them at TX_64X64, i.e. the same + // `tx_size_cat3` row [`decode_block_128rect`] already reads -- so the whole + // block decodes through the very body the KEY FRAME path proves for this + // shape (square 64x64 luma units, one TX_32X32 chroma unit per 64x64 mu + // chunk on the offset-10 txb_skip rows, per-TU prediction, the mu-chunk + // `Reach` rule and the frame-edge write clip). The only inter-frame + // differences live inside that body: the mode-info read + // ([`INTRA_IN_INTER_MODE`] -> `y_mode[3]` plus the `skip` this caller + // already read), the `tx_depth` context (the real TXFM_CONTEXT bands) and + // the `set_txfm_ctxs` publication. CfL (>32), filter intra (>32) and + // palette (>64) do not exist at this size and are refused by name there. + // lane-inter128intra r1: OPT-IN ONLY (`EC_INTRA128_IN_INTER=1`) until a + // gate exists. The body below is believed right (it is the key frame's own + // proven body plus the three inter-frame differences), but the three 1080p + // cuts that reach this shape reach it AFTER a pre-existing desync (see the + // lane report: their frame 2 diverges from aomdec inside the superblock at + // mi(0,320), long before mi(128,416)), and no aomenc recipe found so far + // emits a 128-root HORZ/VERT half coded intra in an inter frame -- so + // nothing can currently prove this arm. A refusal is lifted only with a + // gate (COMMON), so the default path still refuses by name below. + if bw.max(bh) == 128 && std::env::var_os("EC_INTRA128_IN_INTER").is_some() { + if allow_screen_content_tools { + return Err(unsupported( + "a HORZ/VERT intra strip in a screen-content frame (palette syntax \ + is consumed for square blocks only)", + )); + } + INTRA_IN_INTER_MODE.with(|c| c.set(Some((3, skip)))); + let res = decode_block_128rect( + dec, + cdfs, + neighbours, + (r, c), + bw, + bh, + y, + u, + v, + base_q_idx, + ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get), + allow_screen_content_tools, + TX_SELECT_INTER.with(std::cell::Cell::get), + REDUCED_TX_SET_INTER.with(std::cell::Cell::get), + ); + INTRA_IN_INTER_MODE.with(|c| c.set(None)); + return res; + } let (size_group, tx_cat) = match (bw.min(bh), bw.max(bh)) { (8, 16) => (1usize, 1usize), (16, 32) => (2, 2), @@ -11517,6 +11567,15 @@ thread_local! { /// Those blocks by resolved intra `tx_depth` (0 = TX_64X64 units, /// 1 = TX_32X32, 2 = TX_16X16) -- proof the depth symbol is really read. pub(crate) static INTRA_SB128_DEPTH_HITS: std::cell::Cell<[usize; 3]> = const { std::cell::Cell::new([0; 3]) }; + /// lane-inter128intra r1: the same shapes decoded on the INTER block path + /// (an intra-coded PARTITION_HORZ/VERT half of a 128 superblock inside an + /// inter frame) -- (128x64, 64x128). + pub(crate) static INTRA128_IN_INTER_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) }; +} + +/// [`INTRA128_IN_INTER_HITS`], for a gate's own before/after delta. +pub(crate) fn intra128_in_inter_hits() -> [usize; 2] { + INTRA128_IN_INTER_HITS.with(std::cell::Cell::get) } /// [`INTRA_SB128_HORZ_HITS`] / [`INTRA_SB128_VERT_HITS`] / @@ -11608,8 +11667,17 @@ fn decode_block_128rect( let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c); // spec 5.11.16 `read_tx_size`: read for every intra block, skipped or // not. `bsize_to_tx_size_cat(BLOCK_128X64)` is 3 (see this fn's doc). + let in_inter = INTRA_IN_INTER_MODE.with(std::cell::Cell::get).is_some(); let depth = if tx_select { - let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh); + // lane-inter128intra r1: on an INTER frame `get_tx_size_context` reads + // the real `TXFM_CONTEXT` bands, and compares them against + // `tx_size_wide/high[max_txsize_rect_lookup[bsize]]` -- TX_64X64 for + // every 128-axis block, hence the `min(64)`. + let ctx = if in_inter { + tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw.min(64), bh.min(64)) + } else { + tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh) + }; dec.symbol(&mut cdfs.tx_size_cat3[ctx]) } else { 0 @@ -11801,7 +11869,25 @@ fn decode_block_128rect( logical_tx as u8, 0, ); - if bw > bh { + if in_inter { + // `set_txfm_ctxs(tx_size, n4_w, n4_h, skip && is_inter, xd)` + // (libaom `decodeframe.c` `decode_block`) runs for EVERY block of an + // inter frame, intra ones included: an intra block stamps its + // TRANSFORM size over its own footprint in both TXFM_CONTEXT bands. + // A key frame has no var-tx tree and its readers use the deblock grid, + // so this is the inter path's alone. + txfm_partition_update_rect( + neighbours, + (mi_r, mi_c), + (logical_tx, logical_tx), + (bw, bh), + ); + INTRA128_IN_INTER_HITS.with(|c| { + let mut h = c.get(); + h[usize::from(bw < bh)] += 1; + c.set(h); + }); + } else if bw > bh { INTRA_SB128_HORZ_HITS.with(|c| c.set(c.get() + 1)); } else { INTRA_SB128_VERT_HITS.with(|c| c.set(c.get() + 1)); diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index f6464425..bd0102fd 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -153,6 +153,12 @@ pub fn intra_sb128_counters() -> (usize, usize, [usize; 3]) { crate::decode::intra_sb128_hits() } +/// lane-inter128intra r1: the 128 root's HORZ/VERT half coded INTRA inside an +/// INTER frame -- (128x64 blocks, 64x128 blocks). +pub fn intra128_in_inter_counters() -> [usize; 2] { + crate::decode::intra128_in_inter_hits() +} + /// lane-sb128c r9: the four AB shapes at the 128 root, in `PARTITION_HORZ_A`, /// `_HORZ_B`, `_VERT_A`, `_VERT_B` order (key and inter tile paths share the /// counter -- it is bumped where the root symbol resolves).