forge
Explore
Log in

Don't you dare go Hollow

wip(rect16): plain PARTITION_HORZ/VERT below 16x16 (decode_leaf_rect, real-mi addressed); fix vacuous vert_b gate (missing --passes=1)

Browse files at this commit

5925aeeb09508b9ffed3c62442f8dca6ccd70935Ahmet Kaan GümüşParent: 870526d
crates/ec-av1/src/decode.rsmodified+259 -1
@@ -412,6 +412,22 @@ pub(crate) fn vert_b_intra_hits() -> usize {
412 VERT_B_INTRA_HITS.with(|c| c.get())412 VERT_B_INTRA_HITS.with(|c| c.get())
413 }413 }
414 414
415+// How many `partition_w16` reads resolved to a plain `PARTITION_HORZ`/
416+// `PARTITION_VERT` (lane-rect16 r2): re-measuring after the VERT_B fix above
417+// showed mandelbrot's real first-hit blocker is this plain arm at mi=(0,7),
418+// not VERT_B (`refusal-names-a-correlate`; the VERT_B write-up's "frame 0's
419+// very first non-NONE/SPLIT symbol" claim was about decode ORDER within one
420+// superblock's z-order recursion, not raster mi position).
421+thread_local! {
422+ static HORZ_VERT_INTRA_HITS: std::cell::Cell<usize> =
423+ const { std::cell::Cell::new(0) };
424+}
425+
426+/// Current value of [`HORZ_VERT_INTRA_HITS`].
427+pub(crate) fn horz_vert_intra_hits() -> usize {
428+ HORZ_VERT_INTRA_HITS.with(|c| c.get())
429+}
430+
415 // How many [`read_coeffs`] reads resolved a `tx_type` outside `TX_CLASS_2D`431 // How many [`read_coeffs`] reads resolved a `tx_type` outside `TX_CLASS_2D`
416 // (`V_DCT`/`H_DCT`, spec 5.11.39's `TxClass::Horiz`/`Vert`), across every432 // (`V_DCT`/`H_DCT`, spec 5.11.39's `TxClass::Horiz`/`Vert`), across every
417 // call on the current thread -- the same before/after counter pattern as433 // call on the current thread -- the same before/after counter pattern as
@@ -3403,6 +3419,156 @@ fn decode_block_rect(
3403 Ok(())3419 Ok(())
3404 }3420 }
3405 3421
3422+/// Decodes one `bw`x`bh` rect strip of a plain 16x16-level `PARTITION_HORZ`/
3423+/// `PARTITION_VERT` (lane-rect16 r2), sibling to [`decode_block_rect`] but
3424+/// addressed by REAL mi coordinates rather than derived from an [`SUB`]-grid
3425+/// `outer_at`, the same relationship [`decode_leaf8`] has to `decode_block`:
3426+/// the second strip of a HORZ/VERT split sits offset by half the 16x16
3427+/// parent, which `decode_block_rect`'s `at`-derived `px = c * SUB` can't
3428+/// name. `prev_leaf` mirrors `decode_leaf8`'s own convention -- when the
3429+/// previous strip is directly above (same column, `mi_h` rows up) or
3430+/// directly left (same row, `mi_w` cols over), its mode overrides the coarse
3431+/// per-16x16-cell `above_mode`/`left_mode` slot for THIS strip's own mode
3432+/// context read, and bookkeeping goes through the `_mi`/`_rect` neighbour
3433+/// writers (`record_mi_rect`, `fill_skip_grid_rect`, `fill_lf_grid_rect`) at
3434+/// this strip's real position, never the coarse `record_rect` (which the
3435+/// caller uses once, after both strips, exactly like the `VERT_B` arm next
3436+/// to it). Only the skip case is ported -- see [`decode_block_rect`]'s own
3437+/// doc for why a coded rect strip below 16x16 has no coefficient tables here
3438+/// yet.
3439+#[allow(clippy::too_many_arguments)]
3440+fn decode_leaf_rect(
3441+ dec: &mut SymbolDecoder,
3442+ cdfs: &mut Cdfs,
3443+ neighbours: &mut Neighbours,
3444+ outer_at: (usize, usize),
3445+ leaf_mi: (usize, usize),
3446+ bw: usize,
3447+ bh: usize,
3448+ prev_leaf: Option<((usize, usize), usize)>,
3449+ y: &mut PlaneBuf,
3450+ u: &mut PlaneBuf,
3451+ v: &mut PlaneBuf,
3452+ enable_filter_intra: bool,
3453+ allow_screen_content_tools: bool,
3454+ base_q_idx: u8,
3455+ tx_select: bool,
3456+) -> Result<usize> {
3457+ let _ = base_q_idx;
3458+ let (r, c) = outer_at;
3459+ let mut above_mode = neighbours.above_mode[c];
3460+ let mut left_mode = neighbours.left_mode[r];
3461+ let (mi_w, mi_h) = (bw / MI, bh / MI);
3462+ if let Some(((pr, pc), pmode)) = prev_leaf {
3463+ if pc == leaf_mi.1 && leaf_mi.0 == pr + mi_h {
3464+ above_mode = pmode;
3465+ } else if pr == leaf_mi.0 && leaf_mi.1 == pc + mi_w {
3466+ left_mode = pmode;
3467+ }
3468+ }
3469+ let smooth_neighbor =
3470+ is_smooth_mode(above_mode) || is_smooth_mode(left_mode);
3471+ if smooth_neighbor {
3472+ SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
3473+ }
3474+ let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra) =
3475+ read_intra_mode_rect(
3476+ dec,
3477+ cdfs,
3478+ above_mode,
3479+ left_mode,
3480+ true,
3481+ bw,
3482+ bh,
3483+ enable_filter_intra,
3484+ neighbours.skip_txfm_ctx(leaf_mi.0, leaf_mi.1),
3485+ allow_screen_content_tools,
3486+ leaf_mi.0,
3487+ leaf_mi.1,
3488+ )?;
3489+ if filter_intra.is_some() {
3490+ return Err(unsupported(
3491+ "filter intra on a HORZ/VERT strip (this decoder predicts square-only)",
3492+ ));
3493+ }
3494+ let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
3495+ let depth = if tx_select {
3496+ let ctx = tx_size_context_rect(neighbours, leaf_mi, bw, bh);
3497+ dec.symbol(&mut cdfs.tx_size_cat2[ctx])
3498+ } else {
3499+ 0
3500+ };
3501+ if depth != 0 {
3502+ return Err(unsupported(
3503+ "a HORZ/VERT intra strip with a split transform (per-unit rect \
3504+ prediction is not ported)",
3505+ ));
3506+ }
3507+ if !skip {
3508+ return Err(unsupported(
3509+ "a coded (non-skip) HORZ/VERT rect strip below 16x16 (this decoder ports only \
3510+ the skip case at this size)",
3511+ ));
3512+ }
3513+ let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
3514+ let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height);
3515+ let (cpx, cpy) = (px / 2, py / 2);
3516+ let (chroma_w, chroma_h) = (bw / 2, bh / 2);
3517+ y.reconstruct_rect(
3518+ px,
3519+ py,
3520+ bw,
3521+ bh,
3522+ mode,
3523+ angle_delta_y,
3524+ reach,
3525+ &vec![0i32; bw * bh],
3526+ None,
3527+ filter_intra,
3528+ smooth_neighbor,
3529+ );
3530+ let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
3531+ u.reconstruct_rect(
3532+ cpx,
3533+ cpy,
3534+ chroma_w,
3535+ chroma_h,
3536+ uv_predict_mode,
3537+ angle_delta_uv,
3538+ reach,
3539+ &vec![0i32; chroma_w * chroma_h],
3540+ alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
3541+ None,
3542+ false,
3543+ );
3544+ v.reconstruct_rect(
3545+ cpx,
3546+ cpy,
3547+ chroma_w,
3548+ chroma_h,
3549+ uv_predict_mode,
3550+ angle_delta_uv,
3551+ reach,
3552+ &vec![0i32; chroma_w * chroma_h],
3553+ alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
3554+ None,
3555+ false,
3556+ );
3557+ neighbours.record_mi_rect(
3558+ leaf_mi,
3559+ bw,
3560+ bh,
3561+ &[
3562+ vec![0i32; bw * bh],
3563+ vec![0i32; chroma_w * chroma_h],
3564+ vec![0i32; chroma_w * chroma_h],
3565+ ],
3566+ );
3567+ neighbours.fill_skip_grid_rect(leaf_mi, mi_w, mi_h, skip);
3568+ neighbours.fill_lf_grid_rect(leaf_mi, mi_w, mi_h, bw as u8, bh as u8, 0);
3569+ Ok(mode)
3570+}
3571+
3406 /// Decodes one true `bw`x`bh` superblock-level `PARTITION_HORZ`/3572 /// Decodes one true `bw`x`bh` superblock-level `PARTITION_HORZ`/
3407 /// `PARTITION_VERT` strip (lane-sbpart r2, `bw, bh` one of `(64, 32)` /3573 /// `PARTITION_VERT` strip (lane-sbpart r2, `bw, bh` one of `(64, 32)` /
3408 /// `(32, 64)` -- [`decode_block_rect`]'s own sibling one level up). Unlike3574 /// `(32, 64)` -- [`decode_block_rect`]'s own sibling one level up). Unlike
@@ -6737,9 +6903,101 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
6737 neighbours.left_mode[sr] = mode_br;6903 neighbours.left_mode[sr] = mode_br;
6738 continue;6904 continue;
6739 }6905 }
6906+ if part16 == PARTITION_HORZ {
6907+ HORZ_VERT_INTRA_HITS.with(|c| c.set(c.get() + 1));
6908+ let (mi_row0, mi_col0) = (
6909+ sr as u32 * SUB_MI,
6910+ sc as u32 * SUB_MI,
6911+ );
6912+ let top = (mi_row0 as usize, mi_col0 as usize);
6913+ let bot = (mi_row0 as usize + 2, mi_col0 as usize);
6914+ let mode_top = decode_leaf_rect(
6915+ &mut dec,
6916+ &mut cdfs,
6917+ &mut neighbours,
6918+ at16,
6919+ top,
6920+ 16,
6921+ 8,
6922+ None,
6923+ &mut y,
6924+ &mut u,
6925+ &mut v,
6926+ enable_filter_intra,
6927+ allow_screen_content_tools,
6928+ base_q_idx,
6929+ tx_select,
6930+ )?;
6931+ let mode_bot = decode_leaf_rect(
6932+ &mut dec,
6933+ &mut cdfs,
6934+ &mut neighbours,
6935+ at16,
6936+ bot,
6937+ 16,
6938+ 8,
6939+ Some((top, mode_top)),
6940+ &mut y,
6941+ &mut u,
6942+ &mut v,
6943+ enable_filter_intra,
6944+ allow_screen_content_tools,
6945+ base_q_idx,
6946+ tx_select,
6947+ )?;
6948+ neighbours.above_mode[sc] = mode_bot;
6949+ neighbours.left_mode[sr] = mode_bot;
6950+ continue;
6951+ }
6952+ if part16 == PARTITION_VERT {
6953+ HORZ_VERT_INTRA_HITS.with(|c| c.set(c.get() + 1));
6954+ let (mi_row0, mi_col0) = (
6955+ sr as u32 * SUB_MI,
6956+ sc as u32 * SUB_MI,
6957+ );
6958+ let left = (mi_row0 as usize, mi_col0 as usize);
6959+ let right = (mi_row0 as usize, mi_col0 as usize + 2);
6960+ let mode_left = decode_leaf_rect(
6961+ &mut dec,
6962+ &mut cdfs,
6963+ &mut neighbours,
6964+ at16,
6965+ left,
6966+ 8,
6967+ 16,
6968+ None,
6969+ &mut y,
6970+ &mut u,
6971+ &mut v,
6972+ enable_filter_intra,
6973+ allow_screen_content_tools,
6974+ base_q_idx,
6975+ tx_select,
6976+ )?;
6977+ let mode_right = decode_leaf_rect(
6978+ &mut dec,
6979+ &mut cdfs,
6980+ &mut neighbours,
6981+ at16,
6982+ right,
6983+ 8,
6984+ 16,
6985+ Some((left, mode_left)),
6986+ &mut y,
6987+ &mut u,
6988+ &mut v,
6989+ enable_filter_intra,
6990+ allow_screen_content_tools,
6991+ base_q_idx,
6992+ tx_select,
6993+ )?;
6994+ neighbours.above_mode[sc] = mode_right;
6995+ neighbours.left_mode[sr] = mode_right;
6996+ continue;
6997+ }
6740 if part16 != PARTITION_SPLIT {6998 if part16 != PARTITION_SPLIT {
6741 return Err(unsupported(6999 return Err(unsupported(
6742- "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)",7000+ "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)",
6743 ));7001 ));
6744 }7002 }
6745 // A real (non-straddle) SPLIT of a7003 // A real (non-straddle) SPLIT of a
crates/ec-av1/src/refusal_inventory.rsmodified+2 -1
@@ -36,7 +36,8 @@ const CAPABILITY_CLAIMS: &[&str] = &[
36 const REFUSALS: &[&str] = &[36 const REFUSALS: &[&str] = &[
37 "GLOBALMV (round 3)",37 "GLOBALMV (round 3)",
38 "a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 (this decoder ports only the skip case at this size)",38 "a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 (this decoder ports only the skip case at this size)",
39- "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)",39+ "a coded (non-skip) HORZ/VERT rect strip below 16x16 (this decoder ports only the skip case at this size)",
40+ "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)",
40 "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",41 "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
41 "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",42 "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
42 "a 32x32 partition type this decoder does not code (value={part32})",43 "a 32x32 partition type this decoder does not code (value={part32})",
crates/ec-av1/src/stream.rsmodified+31 -16
@@ -5208,20 +5208,25 @@ mod tests {
5208 );5208 );
5209 }5209 }
5210 5210
5211- /// lane-rect16 r1: a plain default-settings aomenc run over lavfi5211+ /// lane-rect16 r1/r2: a plain default-settings aomenc run over lavfi
5212 /// `mandelbrot` (`--cpu-used=4 --end-usage=q --cq-level=32`, no5212 /// `mandelbrot` (`--cpu-used=4 --end-usage=q --cq-level=32`, no
5213 /// `--enable-*` flags) used to refuse frame 0 outright with "a partition5213 /// `--enable-*` flags) used to refuse frame 0 outright with "a partition
5214- /// below 16x16 other than a clean split" -- reproduced live with5214+ /// below 16x16 other than a clean split". r1 root-caused the FIRST hit to
5215- /// `decode_probe`, root-caused to a `PARTITION_VERT_B` `partition_w16`5215+ /// a `PARTITION_VERT_B` `partition_w16` symbol at mi=(3,2) and wired it
5216- /// symbol at mi=(3,2), not the plain HORZ/VERT this lane's charter5216+ /// (left 8x16 real `decode_block_rect` strip + two stacked 8x8
5217- /// assumed (`refusal-names-a-correlate`). The `PARTITION_VERT_B` arm is5217+ /// `decode_leaf8` leaves on the right). r2 re-measured after that fix
5218- /// now wired (left 8x16 real `decode_block_rect` strip + two stacked5218+ /// (`decision-before-quantiser`-shaped: don't trust a stale premise) and
5219- /// 8x8 `decode_leaf8` leaves on the right); `vert_b_intra_hits` proves5219+ /// found this stream's REAL first-hit blocker in z-order is earlier, at
5220- /// that arm fires. This exact stream's own VERT_B block is *coded*5220+ /// mi=(0,7): a plain `PARTITION_HORZ`. That arm is now wired too
5221- /// (real coefficients), which is NOT ported (see the refusal on5221+ /// (`decode_leaf_rect`, sibling to `decode_leaf8` but real-mi-addressed
5222- /// `decode_block_rect`'s non-skip else-branch) -- so this gate proves5222+ /// for a non-square strip) -- `horz_vert_intra_hits` proves it fires.
5223- /// the new arm fires and no longer trips the OLD (now-false) refusal,5223+ /// This exact stream's own HORZ block at mi=(0,7) is *coded* (real
5224- /// not a pixel-exact decode of this stream.5224+ /// coefficients), which is NOT ported (same ceiling as VERT_B's own
5225+ /// non-skip refusal -- no rectangular-transform coefficient tables at
5226+ /// this size), so decode still stops there and `vert_b_intra_hits`
5227+ /// never gets a chance to increment on this particular stream. This gate
5228+ /// proves the HORZ arm fires and the OLD (now-false) two-clause refusal
5229+ /// never reappears, not a pixel-exact decode of this stream.
5225 #[test]5230 #[test]
5226 fn a_real_aomenc_stream_with_mandelbrot_fires_the_vert_b_partition_arm() {5231 fn a_real_aomenc_stream_with_mandelbrot_fires_the_vert_b_partition_arm() {
5227 const NAME: &str = "a_real_aomenc_stream_with_mandelbrot_fires_the_vert_b_partition_arm";5232 const NAME: &str = "a_real_aomenc_stream_with_mandelbrot_fires_the_vert_b_partition_arm";
@@ -5269,6 +5274,7 @@ mod tests {
5269 "--cpu-used=4",5274 "--cpu-used=4",
5270 "--end-usage=q",5275 "--end-usage=q",
5271 "--cq-level=32",5276 "--cq-level=32",
5277+ "--passes=1",
5272 "--obu",5278 "--obu",
5273 "-o",5279 "-o",
5274 "-",5280 "-",
@@ -5292,6 +5298,14 @@ mod tests {
5292 String::from_utf8_lossy(&out.stderr)5298 String::from_utf8_lossy(&out.stderr)
5293 );5299 );
5294 let stream = out.stdout;5300 let stream = out.stdout;
5301+ // lane-rect16 r2: the recipe above was missing `--passes=1` --
5302+ // without it aomenc silently ran 2-pass and wrote nothing to stdout
5303+ // on pass 1 (still exit 0), so this gate always decoded an EMPTY
5304+ // stream and never actually exercised the arm it claims to gate.
5305+ assert!(
5306+ !stream.is_empty(),
5307+ "{NAME}: aomenc wrote an empty stream (missing --passes=1?)"
5308+ );
5295 let result = decode_stream(&stream);5309 let result = decode_stream(&stream);
5296 // The now-lifted false claim ("codes only the square arms below5310 // The now-lifted false claim ("codes only the square arms below
5297 // 16x16") must never appear again.5311 // 16x16") must never appear again.
@@ -5303,12 +5317,13 @@ mod tests {
5303 );5317 );
5304 }5318 }
5305 assert!(5319 assert!(
5306- crate::decode::vert_b_intra_hits() > 0,5320+ crate::decode::horz_vert_intra_hits() > 0,
5307- "{NAME}: the PARTITION_VERT_B arm never fired on this stream (regression -- it fired \5321+ "{NAME}: the plain PARTITION_HORZ/VERT arm never fired on this stream (regression -- \
5308- deterministically at mi=(3,2) when this gate was written)"5322+ it fired deterministically at mi=(0,7) when this gate was written)"
5309 );5323 );
5310 eprintln!(5324 eprintln!(
5311- "{NAME}: vert_b_intra_hits={}, decode result: {:?}",5325+ "{NAME}: horz_vert_intra_hits={}, vert_b_intra_hits={}, decode result: {:?}",
5326+ crate::decode::horz_vert_intra_hits(),
5312 crate::decode::vert_b_intra_hits(),5327 crate::decode::vert_b_intra_hits(),
5313 result.as_ref().map(|f| f.len()).map_err(|e| e.to_string())5328 result.as_ref().map(|f| f.len()).map_err(|e| e.to_string())
5314 );5329 );