From ca4790ff3ec50db2bcffb1751a3cbbc29771cd7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 18:21:50 +0300 Subject: [PATCH] wip(rect16): builder's in-flight edits, committed verbatim at the 75-turn cap (state unverified by me) --- crates/ec-av1/src/decode.rs | 123 ++++++++++++++++++++++++- crates/ec-av1/src/refusal_inventory.rs | 3 +- crates/ec-av1/src/stream.rs | 106 +++++++++++++++++++++ 3 files changed, 230 insertions(+), 2 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 9841d484..55140ea1 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -341,6 +341,24 @@ pub(crate) fn tx_depth_hits() -> usize { TX_DEPTH_HITS.with(|c| c.get()) } +// How many `partition_w16` reads (a 16x16 block's own partition symbol, key +// intra-frame path) resolved to `PARTITION_VERT_B` -- lane-rect16 r1: a +// plain default-settings aomenc run over lavfi mandelbrot hits this arm on +// frame 0's very first non-NONE/SPLIT `partition_w16` symbol (mi=(3,2)), not +// the plain HORZ/VERT this lane's charter assumed. Left rect (8x16, real +// `decode_block_rect`) + two 8x8 leaves stacked on the right (`decode_leaf8`, +// chained via `prev_leaf` exactly like the existing 16x16-SPLIT-into-4x8x8 +// path above). +thread_local! { + static VERT_B_INTRA_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`VERT_B_INTRA_HITS`]. +pub(crate) fn vert_b_intra_hits() -> usize { + VERT_B_INTRA_HITS.with(|c| c.get()) +} + // How many [`read_coeffs`] reads resolved a `tx_type` outside `TX_CLASS_2D` // (`V_DCT`/`H_DCT`, spec 5.11.39's `TxClass::Horiz`/`Vert`), across every // call on the current thread -- the same before/after counter pattern as @@ -2854,6 +2872,21 @@ fn decode_block_rect( vec![0i32; chroma_w * chroma_h], ], ); + } else if (bw, bh) != (32, 16) && (bw, bh) != (16, 32) { + // lane-rect16 r1: a real (non-skip) coefficient read at this size + // (8x16/16x32 VERT_B's own left strip) is not ported -- it needs its + // own `TxbSet`/`eob_pt` tables (a true 128-position luma group has no + // `EOB_PT_128_LUMA` in this decoder yet, only the *chroma* one + // `lane-rectwire` built for `ChromaRect16x8`) and, unlike the 32x32 + // sqr-up case `LumaRect32x16` safely skips, `get_ext_tx_set_type` + // does NOT return `EXT_TX_SET_DCTONLY` at a 16x16 sqr-up under this + // encoder's reduced_tx_set -- a real `tx_type` symbol may be coded + // that no table here reads. Refused by name rather than guess-decoded + // or silently desynced. + return Err(unsupported( + "a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 (this decoder ports only \ + the skip case at this size)", + )); } else { // lane-rectwire r2: real coefficients. `get_txsize_entropy_ctx` // reduces both size pairs to their square-up CDF sets @@ -5829,9 +5862,97 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( )?; continue; } + if part16 == PARTITION_VERT_B { + VERT_B_INTRA_HITS.with(|c| c.set(c.get() + 1)); + // Left rect: 8x16, real + // `decode_block_rect`, sat at the + // 16x16 parent's own origin (no + // fractional-SUB-grid pixel + // offset needed -- the plain + // HORZ/VERT arms this lane's + // charter named DO need one, + // since their second half is + // offset by half the parent; + // unported, see decode_block_rect's + // own doc comment). + decode_block_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + 8, + 16, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + )?; + // Two 8x8 squares stacked on the + // right, chained through + // `prev_leaf` exactly like the + // real (non-straddle) SPLIT path + // below: the bottom leaf's ABOVE + // context is the top leaf, not + // the coarse SUB-grid array (a + // real block never sat there). + let (mi_row0, mi_col0) = + (sr as u32 * SUB_MI, sc as u32 * SUB_MI); + let top_right = + (mi_row0 as usize, mi_col0 as usize + 2); + let bot_right = + (mi_row0 as usize + 2, mi_col0 as usize + 2); + let mode_tr = decode_leaf8( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + top_right, + (&scan8, &scan4), + None, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + tx_select, + reduced_tx_set, + )?; + let mode_br = decode_leaf8( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + bot_right, + (&scan8, &scan4), + Some((top_right, mode_tr)), + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + tx_select, + reduced_tx_set, + )?; + // `record()`'s above_mode/left_mode + // write is a no-op at an 8x8 + // leaf's own side (same gap the + // real-SPLIT path above patches): + // force it from the last-decoded + // (bottom-right) leaf. + neighbours.above_mode[sc] = mode_br; + neighbours.left_mode[sr] = mode_br; + continue; + } if part16 != PARTITION_SPLIT { return Err(unsupported( - "a partition below 16x16 other than a clean split (this decoder codes only the square arms below 16x16)", + "a partition below 16x16 other than a clean split or a VERT_B (this decoder codes only the square arms, VERT_B, and a clean split below 16x16)", )); } // A real (non-straddle) SPLIT of a diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index e785fd9f..b8c09a32 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -27,7 +27,6 @@ const CAPABILITY_CLAIMS: &[&str] = &[ "a non-2D tx class on a rectangular transform (never expected at this size)", "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)", "a nonzero angle delta (this encoder never writes one)", - "a partition below 16x16 other than a clean split (this decoder codes only the square arms below 16x16)", "a partition below 8x8 (this encoder never writes one)", "a tx_type symbol on a rectangular transform (never expected at this size)", ]; @@ -35,6 +34,8 @@ const CAPABILITY_CLAIMS: &[&str] = &[ #[cfg(test)] const REFUSALS: &[&str] = &[ "GLOBALMV (round 3)", + "a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 (this decoder ports only the skip case at this size)", + "a partition below 16x16 other than a clean split or a VERT_B (this decoder codes only the square arms, VERT_B, and a clean split below 16x16)", "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", "a 32x32 partition type this decoder does not code (value={part32})", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index a2276602..b2162c2e 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -4799,6 +4799,112 @@ mod tests { crate::decode::wii_hits() ); } + + /// lane-rect16 r1: a plain default-settings aomenc run over lavfi + /// `mandelbrot` (`--cpu-used=4 --end-usage=q --cq-level=32`, no + /// `--enable-*` flags) used to refuse frame 0 outright with "a partition + /// below 16x16 other than a clean split" -- reproduced live with + /// `decode_probe`, root-caused to a `PARTITION_VERT_B` `partition_w16` + /// symbol at mi=(3,2), not the plain HORZ/VERT this lane's charter + /// assumed (`refusal-names-a-correlate`). The `PARTITION_VERT_B` arm is + /// now wired (left 8x16 real `decode_block_rect` strip + two stacked + /// 8x8 `decode_leaf8` leaves on the right); `vert_b_intra_hits` proves + /// that arm fires. This exact stream's own VERT_B block is *coded* + /// (real coefficients), which is NOT ported (see the refusal on + /// `decode_block_rect`'s non-skip else-branch) -- so this gate proves + /// the new arm fires and no longer trips the OLD (now-false) refusal, + /// not a pixel-exact decode of this stream. + #[test] + fn a_real_aomenc_stream_with_mandelbrot_fires_the_vert_b_partition_arm() { + const NAME: &str = "a_real_aomenc_stream_with_mandelbrot_fires_the_vert_b_partition_arm"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); + return; + } + let (width, height) = (192usize, 128usize); + let y4m = Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + &format!("mandelbrot=size={width}x{height}"), + "-pix_fmt", + "yuv420p", + "-t", + "1", + "-f", + "yuv4mpegpipe", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let mut child = Command::new(aomenc_path()) + .args([ + "--threads=1", + "--row-mt=0", + "--sb-size=64", + "--cpu-used=4", + "--end-usage=q", + "--cq-level=32", + "--obu", + "-o", + "-", + "-", + ]) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m.stdout) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let result = decode_stream(&stream); + // The now-lifted false claim ("codes only the square arms below + // 16x16") must never appear again. + if let Err(e) = &result { + let msg = e.to_string(); + assert!( + !msg.contains("this decoder codes only the square arms below 16x16"), + "{NAME}: the OLD (disproved) refusal reappeared: {msg}" + ); + } + assert!( + crate::decode::vert_b_intra_hits() > 0, + "{NAME}: the PARTITION_VERT_B arm never fired on this stream (regression -- it fired \ + deterministically at mi=(3,2) when this gate was written)" + ); + eprintln!( + "{NAME}: vert_b_intra_hits={}, decode result: {:?}", + crate::decode::vert_b_intra_hits(), + result.as_ref().map(|f| f.len()).map_err(|e| e.to_string()) + ); + } /// lane-rectgate r1: every prior gate pins `--enable-rect-partitions=0 /// --enable-ab-partitions=0 --min/max-partition-size=32` so aomenc never /// gets to choose a real rect/ab split. This charter's premise ("rect