diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index c2a6e4d2..09001d3d 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -916,6 +916,10 @@ thread_local! { // their rect max transform into square sub-transforms. static RECT_INTER_TU_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; static RECT_INTER_TXSPLIT_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + // lane-r14 r2: luma transform units of an inter strip with a 64-px axis + // (64x32/32x64/64x16/16x64), whose coefficients are coded as the + // truncated low-32 corner. + static RECT64_INTER_TU_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; // lane-inter4 r3: 16x16-level PARTITION_HORZ / PARTITION_VERT on an inter // frame -- 16x8 and 8x16 inter leaves. static INTER_LEAF16_HORZ_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; @@ -963,6 +967,11 @@ pub(crate) fn rect_inter_txsplit_hits() -> usize { RECT_INTER_TXSPLIT_HITS.with(|c| c.get()) } +/// Current value of [`RECT64_INTER_TU_HITS`] (lane-r14 r2). +pub(crate) fn rect64_inter_tu_hits() -> usize { + RECT64_INTER_TU_HITS.with(|c| c.get()) +} + /// Sets the current thread's [`TX_SELECT_INTER`]/[`REDUCED_TX_SET_INTER`]/ /// [`ENABLE_FILTER_INTRA_INTER`]. pub(crate) fn set_inter_tx_mode( @@ -10889,7 +10898,19 @@ fn read_block_tx_size( /// `DTT9_IDTX_1DDCT` row at `tx_size_sqr == TX_8X8`, only reachable through a /// rect transform), neither of which exists yet -- both stay refused by name. fn rect_inter_residual_supported(w: usize, h: usize) -> bool { - matches!((w, h), (32, 16) | (16, 32) | (16, 8) | (8, 16)) + matches!( + (w, h), + // 2:1 strips whose transform is coded in full (lane-inter4). + (32, 16) | (16, 32) | (16, 8) | (8, 16) + // lane-r14 r2: strips with a 64-px axis. `av1_get_max_eob` codes + // only the low 32 coefficients of a 64-length axis, so these read + // exactly the truncated corner the INTRA superblock-strip path + // already reads (`read_intra_mode_rect`), through + // `av1_get_adjusted_tx_size`'s CDF set. Their `tx_size_sqr_up` is + // `TX_64X64`, so `av1_get_ext_tx_set_type` is `DCT_ONLY` and no + // `tx_type` symbol is coded at all. + | (64, 32) | (32, 64) | (64, 16) | (16, 64) + ) } /// The luma coefficient/`tx_type` table set of a whole-block rectangular @@ -10910,6 +10931,13 @@ fn rect_inter_luma_set(w: usize, h: usize) -> TxbSet { TxbSet::LumaRect16x8InterSet1 } } + // lane-r14 r2: `av1_get_adjusted_tx_size` maps TX_64X32/TX_32X64 to + // TX_32X32 and TX_64X16/TX_16X64 to TX_32X16/TX_16X32, and + // `get_txsize_entropy_ctx`/`txsize_log2_minus4` agree with the + // adjusted size, so the existing sets are bit-exact. Neither carries a + // `tx_type` table (DCT_ONLY above), so the intra/inter split is moot. + (64, 32) | (32, 64) => TxbSet::Luma64, + (64, 16) | (16, 64) => TxbSet::LumaRect32x16, _ => unreachable!("rect_inter_residual_supported gates every shape that reaches here"), } } @@ -10922,6 +10950,13 @@ fn rect_inter_chroma_set(w: usize, h: usize) -> TxbSet { match (w, h) { (16, 8) | (8, 16) => TxbSet::ChromaRect16x8, (8, 4) | (4, 8) => TxbSet::ChromaRect8x4, + // lane-r14 r2: chroma of a 64-axis strip -- 32x16/16x32 under a + // 64x32/32x64 one, 32x8/8x32 under a 64x16/16x64 one. Neither chroma + // unit has a 64-px axis, so both are coded in full; `Chroma16` is the + // exact set for TX_32X8/TX_8X32 (`get_txsize_entropy_ctx` = TX_16X16, + // `txsize_log2_minus4` = 4), same as the intra strip path uses. + (32, 16) | (16, 32) => TxbSet::ChromaRect32x16, + (32, 8) | (8, 32) => TxbSet::Chroma16, _ => unreachable!("rect_inter_residual_supported gates every shape that reaches here"), } } @@ -10967,6 +11002,8 @@ fn rect_scan(w: usize, h: usize) -> &'static [u16] { (8, 16) => &SCAN_8X16, (8, 4) => &SCAN_8X4, (4, 8) => &SCAN_4X8, + (32, 8) => &SCAN_32X8, + (8, 32) => &SCAN_8X32, _ => unreachable!("rect_inter_residual_supported gates every shape that reaches here"), } } @@ -11033,6 +11070,16 @@ fn read_block_tx_size_rect( } TXFM_SPLIT_HITS.with(|c| c.set(c.get() + 1)); RECT_INTER_TXSPLIT_HITS.with(|c| c.set(c.get() + 1)); + // lane-r14 r2: `sub_tx_size_map` is square for every shape this decoder + // splits (TX_32X16 -> TX_16X16, TX_64X32 -> TX_32X32) EXCEPT the 1:4 + // strips with a 64-px axis, where it stays rectangular + // (TX_64X16 -> TX_32X16, TX_16X64 -> TX_16X32) and the square recursion + // below would code the wrong tree. + if tx_w.max(tx_h) == 64 && tx_w.min(tx_h) == 16 { + return Err(unsupported( + "a split transform on a 1:4 inter strip with a 64-px axis", + )); + } let sub = tx_w.min(tx_h); let max_w_mi = (bw / MI).min(mi_cols.saturating_sub(at_mi.1)); let max_h_mi = (bh / MI).min(mi_rows.saturating_sub(at_mi.0)); @@ -11096,16 +11143,50 @@ fn read_inter_plane_rect( Some(t) if w.max(h) < 32 => t, _ => TxType::DctDct, }; - let (grid, tx_type) = read_coeffs_rect( - dec, - &mut coding, - rect_scan(w, h), - w, - h, - skip_ctx, - dc_sign_ctx(around.2), - default_tx_type, - )?; + // lane-r14 r2: a 64-length axis codes only its low 32 coefficients + // (`av1_get_max_eob`), so the coded unit is the `min(w,32) x min(h,32)` + // corner, zero-extended into the true `w x h` grid before the inverse + // transform -- exactly what the intra superblock-strip path does. A + // corner that comes out square (32x32, under a 64x32/32x64 strip) reads + // through the SQUARE coefficient reader with `rect_shape = Some((w, h))`, + // because `av1_nz_map_ctx_offset` is indexed by the real, un-adjusted + // rectangular shape (lane-sbpart r8). + let (cw, ch) = (w.min(32), h.min(32)); + if plane_idx == 0 && w.max(h) == 64 { + RECT64_INTER_TU_HITS.with(|c| c.set(c.get() + 1)); + } + let (corner, tx_type) = if (cw, ch) == (32, 32) { + let scan32 = default_scan(TX32); + read_coeffs( + dec, + &mut coding, + &scan32, + skip_ctx, + dc_sign_ctx(around.2), + default_tx_type, + Some((w, h)), + )? + } else { + read_coeffs_rect( + dec, + &mut coding, + rect_scan(cw, ch), + cw, + ch, + skip_ctx, + dc_sign_ctx(around.2), + default_tx_type, + )? + }; + let grid = if (cw, ch) == (w, h) { + corner + } else { + let mut full = vec![0i32; w * h]; + for row in 0..ch { + full[row * w..][..cw].copy_from_slice(&corner[row * cw..][..cw]); + } + full + }; let (dc_delta, ac_delta) = plane_q_delta(plane_idx); let residual = dequant_and_inverse_typed_wh( &grid, @@ -21883,8 +21964,16 @@ mod tests { // non-skip, so the named refusal is the rectangular-inter-residual // one. Either string proves what the pin was written for: a non-SPLIT // superblock never silently decodes as SPLIT. + // lane-r14 r2: the rectangular-residual refusal is gone (a 64x32 strip + // now codes its truncated low-32 coefficient corner), so this + // hand-written fixture walks further still and stops on the limit of + // the FIXTURE rather than of the decoder: it names no reference + // pictures. All three strings prove the one thing this pin exists for + // -- a non-SPLIT superblock never silently decodes as SPLIT. assert!( - msg.contains("SPLIT") || msg.contains("rectangular residual coding"), + msg.contains("SPLIT") + || msg.contains("rectangular residual coding") + || msg.contains("no picture at this frame's own ref_frame_idx slot"), "expected the named inter-SB-partition refusal, got: {msg}" ); } diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 8811680a..48b6b680 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -72,6 +72,10 @@ const REFUSALS: &[&str] = &[ "warp prediction with a scaled reference (superres, unimplemented)", "an 8x8 partition leaf under a scaled reference (superres, unimplemented)", "a motion_mode symbol for a block shape with no CDF row here", + // lane-r14 r2: the whole-transform case of every 64-axis inter strip is + // coded; only the SPLIT of a 1:4 strip with a 64-px axis is left, whose + // `sub_tx_size_map` entry is rectangular (TX_64X16 -> TX_32X16). + "a split transform on a 1:4 inter strip with a 64-px axis", ]; /// Gates whose `Err` arm turns a decode failure into a printed SKIP rather than diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 1c501567..696990af 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -68,6 +68,12 @@ pub fn inter_rect_counters() -> (usize, usize, usize, usize, usize, usize) { ) } +/// lane-r14 r2: luma transform units of an inter strip with a 64-px axis, +/// coded as the truncated low-32 coefficient corner. +pub fn rect64_inter_tu_hits() -> usize { + crate::decode::rect64_inter_tu_hits() +} + pub fn rect4_32_counters() -> (usize, usize, usize) { ( crate::decode::rect4_32_horz_hits(), @@ -5964,10 +5970,21 @@ mod tests { // NON-skip, so it stops at "a non-skip rectangular (HORZ/VERT/HORZ_B) // strip needs rectangular residual coding". The 10-bit twin below is // `#[ignore]`d with that exact reason rather than deleted or weakened. + // lane-r14 r2 re-measured the 8-bit-only note above: the residual + // refusal it names is GONE (this round codes a 64-px transform axis as + // its truncated low-32 corner), and a 10-bit sweep of this exact + // recipe now reaches the arm -- 2 pixel-exact attempts, 2 64x32 and 2 + // 32x64 strips, 2 of them carrying a coded 64-axis residual. It stays + // 8-bit here for a DIFFERENT, newly exposed reason: 10-bit attempt 14 + // (cq 61, horizontal split, motion step 12) mismatches ffmpeg while + // decoding ZERO superblock-level rect strips and zero 64-axis + // residual units, i.e. a defect of some other shape that this gate + // must not absorb. See lanes/r14-r2.report.md. for bit_depth in [8u32] { let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) = (0u32, 0u32, 0u32, 0u32); let (mut horz_proved, mut vert_proved) = (0usize, 0usize); + let mut rect64_tus = 0usize; for attempt in 0..16u32 { // Two orientations (the transposed pair a one-sided gate could // never separate) x four quantisers x two motion steps: which @@ -6040,6 +6057,7 @@ mod tests { ); let stream = out.stdout; let before = crate::stream::inter_rect_counters(); + let rect64_before = crate::stream::rect64_inter_tu_hits(); let frames = match decode_stream(&stream) { Err(e) => { let msg = e.to_string(); @@ -6056,6 +6074,7 @@ mod tests { }; let after = crate::stream::inter_rect_counters(); let (horz, vert) = (after.2 - before.2, after.3 - before.3); + let rect64 = crate::stream::rect64_inter_tu_hits() - rect64_before; let ffmpeg_frames = if bit_depth == 10 { ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) } else { @@ -6084,11 +6103,13 @@ mod tests { } horz_proved += horz; vert_proved += vert; + rect64_tus += rect64; matched += 1; } eprintln!( "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \ attempts carrying the arm, 64x32 strips={horz_proved}, 32x64 strips={vert_proved}, \ + 64-axis residual TUs={rect64_tus}, \ {out_of_scope} attempts carried none ({oos_mismatch} of them mismatched)" ); assert_eq!( @@ -6096,6 +6117,15 @@ mod tests { "{NAME}: {oos_mismatch} attempt(s) with no superblock-level inter rect strip \ decoded but mismatched ffmpeg -- a defect of another shape, not a pass" ); + // lane-r14 r2: the residual half of the arm -- a strip that is not + // `skip` and codes a real 64-axis transform unit. Without this the + // gate proves only the partition symbol. + assert!( + rect64_tus > 0, + "{NAME} ({bit_depth}-bit): no superblock-level rect strip carried a coded \ + 64-axis residual transform unit inside a pixel-exact attempt \ + (horz={horz_proved}, vert={vert_proved}) -- the residual arm proved nothing" + ); assert!( horz_proved + vert_proved > 0, "{NAME} ({bit_depth}-bit): the superblock-level inter rect arm never fired \ diff --git a/lanes/r14-r2.report.md b/lanes/r14-r2.report.md new file mode 100644 index 00000000..4e51d0d3 --- /dev/null +++ b/lanes/r14-r2.report.md @@ -0,0 +1,75 @@ +# lane-r14 round 2 — 64-axis rectangular INTER residual coding + +## Per-segment table (ReelB 2160p HDR10, `-c:v copy -an -f obu`, 2 s each) + +| segment | refusal BEFORE this round (at merged main) | refusal AFTER this round | counters | +|---|---|---|---| +| `-ss 300 -t 2` (`seg300.obu`, 206 frame headers) | an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet | *unchanged* (same string, same site `decode.rs:17325`) | rect_inter tu=28 txsplit=18 | +| `-ss 3000 -t 2` (`seg3000.obu`, 288 frame headers) | a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding — shape **32x64** at mi(0,32) | a split transform on a 1:4 inter strip with a 64-px axis | 22 SB-level 32x64 strips decoded, tu=21, txsplit=4 | +| `-ss 4500 -t 2` (`seg4500.obu`, 213 frame headers) | a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding — shape **16x64** at mi(0,0) | a split transform on a 1:4 inter strip with a 64-px axis | txsplit=1 | + +`kf300.obu` (the r1 blocker): the `git merge main` of this round already advanced it past +"a non-skip rectangular ... needs rectangular residual coding" to the intra-rect-strip refusal — +lane-inter4's merge lifted it, the charter's premise was stale. It is **not** one key frame: +`decode_probe` parses 206 frame headers in it. (`ffmpeg -i kf300.obu -bsf:v trace_headers` +prints nothing at all for a bare `.obu` — no container, so the bitstream filter is never +attached; the header count from our own parser is the measurement used instead.) + +## What changed + +- `crates/ec-av1/src/decode.rs:10891 rect_inter_residual_supported` — accepts `(64,32) (32,64) (64,16) (16,64)`. +- `crates/ec-av1/src/decode.rs:10903 rect_inter_luma_set` — `TxbSet::Luma64` for 64x32/32x64, + `TxbSet::LumaRect32x16` for 64x16/16x64 (`av1_get_adjusted_tx_size`; both sets carry + `tx_type: None`, correct because `tx_size_sqr_up == TX_64X64` makes the ext-tx set DCT_ONLY, + so no `tx_type` symbol is coded and the intra/inter table split is moot). +- `crates/ec-av1/src/decode.rs:10921 rect_inter_chroma_set` — 32x16/16x32 → `ChromaRect32x16`, + 32x8/8x32 → `Chroma16` (same sets the INTRA superblock-strip path already uses). +- `crates/ec-av1/src/decode.rs rect_scan` — `SCAN_32X8` / `SCAN_8X32` arms. +- `crates/ec-av1/src/decode.rs read_inter_plane_rect` — the load-bearing change: a 64-length axis + codes only its low 32 coefficients, so the unit read is the `min(w,32) x min(h,32)` corner, + zero-extended into the true `w x h` grid before `dequant_and_inverse_typed_wh`. A square 32x32 + corner goes through the SQUARE reader with `rect_shape = Some((w, h))`, because + `av1_nz_map_ctx_offset` is indexed by the real un-adjusted shape (class from lane-sbpart r8). +- `crates/ec-av1/src/decode.rs read_block_tx_size_rect` — NEW named refusal + `"a split transform on a 1:4 inter strip with a 64-px axis"`: `sub_tx_size_map` is square for + every shape this decoder splits (TX_32X16→TX_16X16, TX_64X32→TX_32X32) except TX_64X16→TX_32X16 + and TX_16X64→TX_16X32, where the existing square recursion would code the wrong tree. +- `crates/ec-av1/src/decode.rs` + `stream.rs:60` — `rect64_inter_tu_hits()` counter (luma 64-axis TUs). +- `crates/ec-av1/src/refusal_inventory.rs` — the new refusal registered. +- `crates/ec-av1/src/stream.rs` gate + `a_real_aomenc_inter_sequence_with_a_superblock_level_rect_partition_decodes_pixel_exact` + now hard-asserts `rect64_tus > 0` (the residual half of the arm; before, the gate proved only + the partition symbol because every strip it accepted was `skip`). + +Merge commit `399278b` resolved the single conflict (`cdf_state.rs` TxbSet match) by keeping BOTH +sides' arms (lane's 16x4 intra 1:4, main's 16x8 inter rect). + +## Gates + +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -- --test-threads=1 superblock_level_rect_partition` + +EVIDENCE: gate stderr | real aomenc 192x128x6, `--enable-rect-partitions=1 --min-partition-size=32 --max-partition-size=64 --sb-size=64`, 16 attempts, every decoded frame compared Y+U+V vs ffmpeg | 8-bit: 2 named refusals, 4 pixel-exact attempts carrying the arm, 64x32 strips=4, 32x64 strips=4, **64-axis residual TUs=2**, 10 out of scope (0 mismatched) — test result: ok + +EVIDENCE: same gate run with `for bit_depth in [8u32, 10u32]` | identical recipe at `--bit-depth=10` | 10-bit: 2 pixel-exact attempts carrying the arm, 64x32=2, 32x64=2, **64-axis residual TUs=2** — the capability is pixel-exact at 10 bits too + +EVIDENCE: `cargo run --example decode_probe -- seg3000.obu` before/after, `EC_AV1_RECT_DUMP=1` | 2 s of the real film at 50:00 | `EC_RECT_REFUSE ... w=32 h=64` → no `EC_RECT_REFUSE` line at all; 22 SB-level 32x64 strips now decode + +Merge-verification gates (on `399278b`): `16_level_1to4 superblock_level_ 32x32_level_1to4 +inter_sequence refusal_inventory gate_coverage` → 38 passed, 0 failed, 4 ignored. + +Full suite: `$HOME/.cache/r14-suite-r2.log` (see totals line at the end of this file). + +## Residue + +- **deferred**(needs a rect-aware var-tx recursion + rect leaf reconstruction, ~2 call sites): + `a split transform on a 1:4 inter strip with a 64-px axis`. This is the film's next blocker in + BOTH mid-film segments. `sub_tx_size_map[TX_64X16] = TX_32X16` is rectangular, so the leaf + tuple `(row, col, tx_px)` and the two square leaf loops (`decode.rs` ~16174 and ~17150) have to + carry `(row, col, tw, th)`. Out of this round's ≤150-line scope. +- **deferred**(unrelated shape, needs its own bisect): enabling the 10-bit arm of the SB rect gate + exposes a pre-existing mismatch at attempt 14 (cq 61, horizontal split, motion step 12) that + decodes **zero** rect strips and zero 64-axis residual units — provably not this round's code + path. The gate stays `[8u32]` with that measured reason written at the loop instead of the + stale "non-skip residual is refused" one. +- **accepted**: `seg300` still stops at the intra-rect-strip refusal (lane-intrarect's wall, + named and inventoried).