Sub-8x8 inter PARTITION_VERT (two BLOCK_4X8 leaves)
Browse files at this commit60b3ba2487ba23117f55c73fa4c6338409a99c36Parent: 458aba6- feat
- sub-8x8 inter PARTITION_VERT (two BLOCK_4X8 leaves)
- HORZ twin implemented but refused
6 changed files +743 -12
- crates/ec-av1/examples/decode_probe.rs +2 -0
- crates/ec-av1/src/cdf_state.rs +40 -0
- crates/ec-av1/src/decode.rs +588 -2
- crates/ec-av1/src/refusal_inventory.rs +2 -1
- crates/ec-av1/src/stream.rs +32 -9
- lanes/intersub8-r3.handoff.md +79 -0
crates/ec-av1/examples/decode_probe.rsmodified+2 -0
| @@ -36,6 +36,8 @@ fn main() { | |||
| 36 | let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters(); | 36 | let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters(); |
| 37 | println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}"); | 37 | println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}"); |
| 38 | println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits()); | 38 | println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits()); |
| 39 | + let (h84, h48) = ec_av1::decode::sub8_inter_rect_hits(); | ||
| 40 | + println!("sub8_inter_rect: horz8x4={h84} vert4x8={h48}"); | ||
| 39 | let leaf = ec_av1::stream::vartx_rect_leaf_hits(); | 41 | let leaf = ec_av1::stream::vartx_rect_leaf_hits(); |
| 40 | println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]); | 42 | println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]); |
| 41 | let ir = ec_av1::stream::inter_rect_counters(); | 43 | let ir = ec_av1::stream::inter_rect_counters(); |
crates/ec-av1/src/cdf_state.rsmodified+40 -0
| @@ -230,6 +230,22 @@ pub(crate) enum TxbSet { | |||
| 230 | /// counterpart: `EXT_TX_SET_DTT4_IDTX_1DDCT`, the seven-symbol `TX_4X4` | 230 | /// counterpart: `EXT_TX_SET_DTT4_IDTX_1DDCT`, the seven-symbol `TX_4X4` |
| 231 | /// row [`LumaRect4x8Set1`](TxbSet::LumaRect4x8Set1) reads. | 231 | /// row [`LumaRect4x8Set1`](TxbSet::LumaRect4x8Set1) reads. |
| 232 | LumaRect16x4Set1, | 232 | LumaRect16x4Set1, |
| 233 | + /// The luma 8x4/4x8 transform of an INTER `PARTITION_HORZ`/`PARTITION_VERT` | ||
| 234 | + /// leaf under an 8x8 block (lane-intersub8 r3): every coefficient table is | ||
| 235 | + /// [`LumaRect4x8`](TxbSet::LumaRect4x8)'s (`get_txsize_entropy_ctx` squares | ||
| 236 | + /// `TX_8X4` up to the 8x8 class, 32-position `eob_pt`), with the INTER | ||
| 237 | + /// `tx_type` alphabet in its place. Under `reduced_tx_set` | ||
| 238 | + /// `av1_get_ext_tx_set_type` (`tx_size_sqr_up == TX_8X8`, `is_inter`) | ||
| 239 | + /// returns `EXT_TX_SET_DCT_IDTX`, whose row is | ||
| 240 | + /// `default_inter_ext_tx_cdf[?][txsize_sqr_map[TX_8X4] == TX_4X4]` -- the | ||
| 241 | + /// same `TX_4X4` inter row [`Luma4Inter`](TxbSet::Luma4Inter) reads. | ||
| 242 | + LumaRect8x4Inter, | ||
| 243 | + /// [`LumaRect8x4Inter`](TxbSet::LumaRect8x4Inter)'s `reduced_tx_set: false` | ||
| 244 | + /// counterpart: `tx_size_sqr == TX_4X4` with `tx_size_sqr_up == TX_8X8`, so | ||
| 245 | + /// `av1_ext_tx_set_lookup[is_inter=1][...]` is `EXT_TX_SET_ALL16` -- sixteen | ||
| 246 | + /// symbols at the `TX_4X4` inter row, the table | ||
| 247 | + /// [`Luma4InterSet1`](TxbSet::Luma4InterSet1) also reads. | ||
| 248 | + LumaRect8x4InterSet1, | ||
| 233 | } | 249 | } |
| 234 | 250 | ||
| 235 | /// The tables one transform block is coded with, borrowed from the state for | 251 | /// The tables one transform block is coded with, borrowed from the state for |
| @@ -1792,6 +1808,30 @@ impl Cdfs { | |||
| 1792 | tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()), | 1808 | tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()), |
| 1793 | eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1), | 1809 | eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1), |
| 1794 | }, | 1810 | }, |
| 1811 | + TxbSet::LumaRect8x4Inter => TxbTables { | ||
| 1812 | + side: 8, | ||
| 1813 | + txb_skip: &mut self.txb_skip_luma_8, | ||
| 1814 | + eob_pt: &mut self.eob_pt_32_luma, | ||
| 1815 | + eob_extra: &mut self.eob_extra_luma_8, | ||
| 1816 | + base: &mut self.base_luma_8, | ||
| 1817 | + base_eob: &mut self.base_eob_luma_8, | ||
| 1818 | + br: &mut self.br_luma_8, | ||
| 1819 | + dc_sign: &mut self.dc_sign_luma, | ||
| 1820 | + tx_type: Some(self.inter_tx_type_4.as_mut_slice()), | ||
| 1821 | + eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1), | ||
| 1822 | + }, | ||
| 1823 | + TxbSet::LumaRect8x4InterSet1 => TxbTables { | ||
| 1824 | + side: 8, | ||
| 1825 | + txb_skip: &mut self.txb_skip_luma_8, | ||
| 1826 | + eob_pt: &mut self.eob_pt_32_luma, | ||
| 1827 | + eob_extra: &mut self.eob_extra_luma_8, | ||
| 1828 | + base: &mut self.base_luma_8, | ||
| 1829 | + base_eob: &mut self.base_eob_luma_8, | ||
| 1830 | + br: &mut self.br_luma_8, | ||
| 1831 | + dc_sign: &mut self.dc_sign_luma, | ||
| 1832 | + tx_type: Some(self.inter_tx_type_4_set1.as_mut_slice()), | ||
| 1833 | + eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1), | ||
| 1834 | + }, | ||
| 1795 | TxbSet::LumaRect4x8Set1 => TxbTables { | 1835 | TxbSet::LumaRect4x8Set1 => TxbTables { |
| 1796 | side: 8, | 1836 | side: 8, |
| 1797 | txb_skip: &mut self.txb_skip_luma_8, | 1837 | txb_skip: &mut self.txb_skip_luma_8, |
crates/ec-av1/src/decode.rsmodified+588 -2
| @@ -2541,6 +2541,18 @@ thread_local! { | |||
| 2541 | /// How many 8x8 groups an INTER frame split into four BLOCK_4X4 inter | 2541 | /// How many 8x8 groups an INTER frame split into four BLOCK_4X4 inter |
| 2542 | /// sub-blocks (lane-intersub8). | 2542 | /// sub-blocks (lane-intersub8). |
| 2543 | static SUB8_INTER_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | 2543 | static SUB8_INTER_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 2544 | + /// How many 8x8 groups an INTER frame split into two rectangular sub-8x8 | ||
| 2545 | + /// inter leaves (lane-intersub8 r3), indexed `[0] = HORZ` (two BLOCK_8X4), | ||
| 2546 | + /// `[1] = VERT` (two BLOCK_4X8). | ||
| 2547 | + static SUB8_INTER_RECT_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) }; | ||
| 2548 | +} | ||
| 2549 | + | ||
| 2550 | +/// Current value of [`SUB8_INTER_RECT_HITS`]: `(8x4 groups, 4x8 groups)`. | ||
| 2551 | +pub fn sub8_inter_rect_hits() -> (usize, usize) { | ||
| 2552 | + SUB8_INTER_RECT_HITS.with(|c| { | ||
| 2553 | + let h = c.get(); | ||
| 2554 | + (h[0], h[1]) | ||
| 2555 | + }) | ||
| 2544 | } | 2556 | } |
| 2545 | 2557 | ||
| 2546 | /// Current value of [`SUB8_SPLIT_HITS`]. | 2558 | /// Current value of [`SUB8_SPLIT_HITS`]. |
| @@ -19478,6 +19490,523 @@ fn decode_inter_sub8_split4( | |||
| 19478 | Ok(()) | 19490 | Ok(()) |
| 19479 | } | 19491 | } |
| 19480 | 19492 | ||
| 19493 | +/// Decodes a `PARTITION_HORZ`/`PARTITION_VERT` of one 8x8 INTER block into two | ||
| 19494 | +/// `BLOCK_8X4`/`BLOCK_4X8` inter leaves (lane-intersub8 r3) -- the inter twin of | ||
| 19495 | +/// [`decode_leaf_rect8`] and the rectangular sibling of | ||
| 19496 | +/// [`decode_inter_sub8_split4`], whose element order it follows exactly. | ||
| 19497 | +/// Per sub-block, in libaom `decodemv.c` `read_inter_frame_mode_info` order: | ||
| 19498 | +/// | ||
| 19499 | +/// * `segment_id`, `skip`, `cdef`/`delta_q`/`delta_lf`, `intra_inter`; | ||
| 19500 | +/// * NO `skip_mode` symbol: `is_comp_ref_allowed(BLOCK_8X4)` is false | ||
| 19501 | +/// (`av1_is_comp_ref_allowed` needs both sides >= 8), so | ||
| 19502 | +/// `read_skip_mode` returns 0 without reading and `comp_mode` is never read | ||
| 19503 | +/// either (`read_ref_frames`' `is_comp_ref_allowed` guard) -- single | ||
| 19504 | +/// reference only; | ||
| 19505 | +/// * NO `interintra` and NO `motion_mode`/OBMC/warp symbol: every one of those | ||
| 19506 | +/// gates needs `block_size_wide >= 8 && block_size_high >= 8` | ||
| 19507 | +/// (`is_interintra_allowed_bsize`, `motion_mode_allowed`), and one side is 4; | ||
| 19508 | +/// * `read_mb_interp_filter` DOES run for both sub-blocks. | ||
| 19509 | +/// | ||
| 19510 | +/// The shape's own differences from the four-way split: | ||
| 19511 | +/// | ||
| 19512 | +/// * `block_signals_txsize(BLOCK_8X4)` is true (`bsize > BLOCK_4X4`, | ||
| 19513 | +/// blockd.h:1027), so a non-skipped sub-block reads ONE `txfm_partition` | ||
| 19514 | +/// symbol under `TX_MODE_SELECT` at `max_txsize_rect_lookup[BLOCK_8X4] == | ||
| 19515 | +/// TX_8X4` ([`read_var_tx_size`]); split resolves to two `TX_4X4` units | ||
| 19516 | +/// (`sub_tx_size_map[TX_8X4] == TX_4X4`, libaom's early return), no split to | ||
| 19517 | +/// the whole-leaf `TX_8X4`; | ||
| 19518 | +/// * the luma coefficient set is [`TxbSet::LumaRect8x4Inter`] (the 8x8 | ||
| 19519 | +/// coefficient class with a 32-position `eob_pt` and the INTER `TX_4X4` | ||
| 19520 | +/// `tx_type` row) for the whole-leaf unit, and the square | ||
| 19521 | +/// [`TxbSet::Luma4Inter`] for a split `TX_4X4` unit; | ||
| 19522 | +/// * chroma is coded ONCE, on the sub-block that is the chroma reference: | ||
| 19523 | +/// `is_chroma_reference` (`av1_common_int.h`) is | ||
| 19524 | +/// `((mi_row & 1) || !(bh4 & 1) || !ss_y) && ((mi_col & 1) || !(bw4 & 1) || | ||
| 19525 | +/// !ss_x)`, i.e. under 4:2:0 the BOTTOM 8x4 (`bh4 == 1`, odd) and the RIGHT | ||
| 19526 | +/// 4x8 (`bw4 == 1`) -- always the second sub-block here; | ||
| 19527 | +/// * that chroma unit's prediction is the sub8x8 one (`reconinter.c` | ||
| 19528 | +/// `build_inter_predictors_sub8x8`: `row_start = -(block_size_high == 4 && | ||
| 19529 | +/// ss_y)`, `col_start = -(block_size_wide == 4 && ss_x)`), two 4x2 (HORZ) or | ||
| 19530 | +/// 2x4 (VERT) chroma pieces, each from its OWN sub-block's reference, mv and | ||
| 19531 | +/// interpolation filters. | ||
| 19532 | +#[allow(clippy::too_many_arguments)] | ||
| 19533 | +fn decode_inter_sub8_rect2( | ||
| 19534 | + dec: &mut SymbolDecoder, | ||
| 19535 | + cdfs: &mut Cdfs, | ||
| 19536 | + neighbours: &mut Neighbours, | ||
| 19537 | + grid: &mut MiGrid, | ||
| 19538 | + group_mi: (usize, usize), | ||
| 19539 | + vert: bool, | ||
| 19540 | + mi_cols: u32, | ||
| 19541 | + mi_rows: u32, | ||
| 19542 | + y: &mut PlaneBuf, | ||
| 19543 | + u: &mut PlaneBuf, | ||
| 19544 | + v: &mut PlaneBuf, | ||
| 19545 | + ref_y: &PlaneBuf, | ||
| 19546 | + ref_u: &PlaneBuf, | ||
| 19547 | + ref_v: &PlaneBuf, | ||
| 19548 | + other_refs: &RefSlots, | ||
| 19549 | + sign_bias_table: &SignBiasTable, | ||
| 19550 | + global_motion: &[ec_av1_syntax::WarpParams; 7], | ||
| 19551 | + base_q_idx: u8, | ||
| 19552 | + scan4: &[u16], | ||
| 19553 | + allow_high_precision_mv: bool, | ||
| 19554 | + force_integer_mv: bool, | ||
| 19555 | + interp_fixed: Option<mc::InterpFilterKind>, | ||
| 19556 | + enable_dual_filter: bool, | ||
| 19557 | + tpl_frame: Option<&TplFrameArgs>, | ||
| 19558 | + reduced_tx_set: bool, | ||
| 19559 | + frame_width: usize, | ||
| 19560 | +) -> Result<()> { | ||
| 19561 | + const LAST_FRAME: i8 = 1; | ||
| 19562 | + // The 8x8 group's own square stride: both leaves' prediction buffers are | ||
| 19563 | + // laid out at it, as every other rect inter unit here is. | ||
| 19564 | + const SIDE: usize = 8; | ||
| 19565 | + let (bw, bh) = if vert { (4usize, 8usize) } else { (8usize, 4usize) }; | ||
| 19566 | + let (w_mi, h_mi) = (bw / MI, bh / MI); | ||
| 19567 | + SUB8_INTER_RECT_HITS.with(|c| { | ||
| 19568 | + let mut h = c.get(); | ||
| 19569 | + h[usize::from(vert)] += 1; | ||
| 19570 | + c.set(h); | ||
| 19571 | + }); | ||
| 19572 | + let (gr, gc) = group_mi; | ||
| 19573 | + let (gpx, gpy) = (gc * MI, gr * MI); | ||
| 19574 | + let (cpx, cpy) = (gpx / 2, gpy / 2); | ||
| 19575 | + // Per-sub-block state the group's one chroma unit predicts from. | ||
| 19576 | + let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 2] = | ||
| 19577 | + [None; 2]; | ||
| 19578 | + let mut first_tx_type = TxType::DctDct; | ||
| 19579 | + let mut last_skip = true; | ||
| 19580 | + for i in 0..2usize { | ||
| 19581 | + let lmi = if vert { (gr, gc + i) } else { (gr + i, gc) }; | ||
| 19582 | + if lmi.0 >= mi_rows as usize || lmi.1 >= mi_cols as usize { | ||
| 19583 | + continue; | ||
| 19584 | + } | ||
| 19585 | + let (rmi, cmi) = lmi; | ||
| 19586 | + let (px, py) = (cmi * MI, rmi * MI); | ||
| 19587 | + inter_segment_id(dec, cdfs, rmi, cmi, w_mi, h_mi, false, true); | ||
| 19588 | + let skip_ctx = | ||
| 19589 | + usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]); | ||
| 19590 | + let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; | ||
| 19591 | + inter_segment_id(dec, cdfs, rmi, cmi, w_mi, h_mi, skip, false); | ||
| 19592 | + maybe_read_cdef_idx(dec, rmi, cmi, skip); | ||
| 19593 | + maybe_read_delta_q(dec, cdfs, rmi, cmi, false, skip); | ||
| 19594 | + maybe_read_delta_lf(dec, cdfs, rmi, cmi, false, skip); | ||
| 19595 | + let (has_above, has_left) = ( | ||
| 19596 | + rmi > neighbours.tile_row0_mi, | ||
| 19597 | + cmi > neighbours.tile_col0_mi, | ||
| 19598 | + ); | ||
| 19599 | + let ii_ctx = intra_inter_ctx( | ||
| 19600 | + has_above, | ||
| 19601 | + has_left, | ||
| 19602 | + neighbours.above_inter[cmi], | ||
| 19603 | + neighbours.left_inter[rmi], | ||
| 19604 | + ); | ||
| 19605 | + let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; | ||
| 19606 | + if !is_inter { | ||
| 19607 | + return Err(unsupported( | ||
| 19608 | + "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition \ | ||
| 19609 | + (this decoder codes only inter sub-blocks there)", | ||
| 19610 | + )); | ||
| 19611 | + } | ||
| 19612 | + if std::env::var_os("EC_TRACE_MODE").is_some() { | ||
| 19613 | + eprintln!( | ||
| 19614 | + "EC_MODE mi_row={rmi} mi_col={cmi} rng={}", | ||
| 19615 | + dec.debug_state().0 | ||
| 19616 | + ); | ||
| 19617 | + } | ||
| 19618 | + let ref_frame = read_single_ref( | ||
| 19619 | + dec, | ||
| 19620 | + cdfs, | ||
| 19621 | + neighbours.above_ref[cmi], | ||
| 19622 | + neighbours.above_ref1[cmi], | ||
| 19623 | + neighbours.left_ref[rmi], | ||
| 19624 | + neighbours.left_ref1[rmi], | ||
| 19625 | + ); | ||
| 19626 | + let (sref_y, _, _) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?; | ||
| 19627 | + if mc::scale_factor(sref_y.width, frame_width) != mc::REF_NO_SCALE { | ||
| 19628 | + return Err(unsupported( | ||
| 19629 | + "a sub-8x8 inter block under a scaled reference (superres, unimplemented)", | ||
| 19630 | + )); | ||
| 19631 | + } | ||
| 19632 | + let gm_table = build_gm_mv_table( | ||
| 19633 | + global_motion, | ||
| 19634 | + rmi, | ||
| 19635 | + cmi, | ||
| 19636 | + w_mi, | ||
| 19637 | + h_mi, | ||
| 19638 | + allow_high_precision_mv, | ||
| 19639 | + force_integer_mv, | ||
| 19640 | + ); | ||
| 19641 | + let tpl = tpl_frame.map(|t| crate::mvstack::TplArgs { | ||
| 19642 | + field: t.field, | ||
| 19643 | + cur_offset_0: crate::motion_field::get_relative_dist( | ||
| 19644 | + t.order_hint_bits, | ||
| 19645 | + t.order_hint, | ||
| 19646 | + t.ref_order_hints[(ref_frame - LAST_FRAME) as usize], | ||
| 19647 | + ), | ||
| 19648 | + allow_high_precision_mv, | ||
| 19649 | + }); | ||
| 19650 | + let stack = crate::mvstack::find_mv_stack_with_sign_bias( | ||
| 19651 | + grid, | ||
| 19652 | + rmi, | ||
| 19653 | + cmi, | ||
| 19654 | + w_mi, | ||
| 19655 | + h_mi, | ||
| 19656 | + ref_frame, | ||
| 19657 | + mi_cols as usize, | ||
| 19658 | + mi_rows as usize, | ||
| 19659 | + sign_bias_table, | ||
| 19660 | + &gm_table, | ||
| 19661 | + tpl, | ||
| 19662 | + ); | ||
| 19663 | + let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1; | ||
| 19664 | + let mut is_globalmv = false; | ||
| 19665 | + let (mv, is_new_mv) = if !not_new { | ||
| 19666 | + let mut idx = 0usize; | ||
| 19667 | + while idx < 2 && stack.entries.len() > idx + 1 { | ||
| 19668 | + if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { | ||
| 19669 | + break; | ||
| 19670 | + } | ||
| 19671 | + idx += 1; | ||
| 19672 | + } | ||
| 19673 | + let base_mv = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv); | ||
| 19674 | + ( | ||
| 19675 | + read_mv( | ||
| 19676 | + dec, | ||
| 19677 | + &mut cdfs.mv_comp, | ||
| 19678 | + &mut cdfs.mv_joint, | ||
| 19679 | + base_mv, | ||
| 19680 | + allow_high_precision_mv, | ||
| 19681 | + force_integer_mv, | ||
| 19682 | + ), | ||
| 19683 | + true, | ||
| 19684 | + ) | ||
| 19685 | + } else { | ||
| 19686 | + let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1; | ||
| 19687 | + is_globalmv = !not_zero; | ||
| 19688 | + let mv = if !not_zero { | ||
| 19689 | + gm_table[(ref_frame - LAST_FRAME) as usize] | ||
| 19690 | + } else { | ||
| 19691 | + let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0; | ||
| 19692 | + if nearest { | ||
| 19693 | + stack.nearest_mv | ||
| 19694 | + } else { | ||
| 19695 | + let mut idx = 1usize; | ||
| 19696 | + while idx < 3 && stack.entries.len() > idx + 1 { | ||
| 19697 | + if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { | ||
| 19698 | + break; | ||
| 19699 | + } | ||
| 19700 | + idx += 1; | ||
| 19701 | + } | ||
| 19702 | + stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv) | ||
| 19703 | + } | ||
| 19704 | + }; | ||
| 19705 | + (mv, false) | ||
| 19706 | + }; | ||
| 19707 | + if std::env::var_os("EC_TRACE_MODE").is_some() { | ||
| 19708 | + eprintln!( | ||
| 19709 | + "EC_MODE_MV mi_row={rmi} mi_col={cmi} mv0=({},{}) rng={}", | ||
| 19710 | + mv.0, | ||
| 19711 | + mv.1, | ||
| 19712 | + dec.debug_state().0 | ||
| 19713 | + ); | ||
| 19714 | + } | ||
| 19715 | + let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize]; | ||
| 19716 | + let above_filter_ctx = if neighbours.above_ref[cmi] == ref_frame | ||
| 19717 | + || neighbours.above_ref1[cmi] == Some(ref_frame) | ||
| 19718 | + { | ||
| 19719 | + neighbours.above_filter[cmi] | ||
| 19720 | + } else { | ||
| 19721 | + [3, 3] | ||
| 19722 | + }; | ||
| 19723 | + let left_filter_ctx = if neighbours.left_ref[rmi] == ref_frame | ||
| 19724 | + || neighbours.left_ref1[rmi] == Some(ref_frame) | ||
| 19725 | + { | ||
| 19726 | + neighbours.left_filter[rmi] | ||
| 19727 | + } else { | ||
| 19728 | + [3, 3] | ||
| 19729 | + }; | ||
| 19730 | + let gm_nontrans = is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation; | ||
| 19731 | + let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( | ||
| 19732 | + dec, | ||
| 19733 | + cdfs, | ||
| 19734 | + interp_fixed, | ||
| 19735 | + enable_dual_filter, | ||
| 19736 | + gm_nontrans, | ||
| 19737 | + above_filter_ctx, | ||
| 19738 | + left_filter_ctx, | ||
| 19739 | + false, | ||
| 19740 | + ); | ||
| 19741 | + // `read_block_tx_size` (libaom `decodeframe.c`): unlike a `BLOCK_4X4`, | ||
| 19742 | + // this shape signals its transform size. A non-skipped inter block | ||
| 19743 | + // walks the var-tx tree from `max_txsize_rect_lookup[BLOCK_8X4]`; a | ||
| 19744 | + // skipped one codes nothing and records its BLOCK size in both txfm | ||
| 19745 | + // contexts (`set_txfm_ctxs`' `skip_inter` arm). | ||
| 19746 | + let mut leaves: Vec<(usize, usize, usize, usize)> = Vec::new(); | ||
| 19747 | + if TX_SELECT_INTER.with(std::cell::Cell::get) && !skip { | ||
| 19748 | + let max_w_mi = w_mi.min((mi_cols as usize).saturating_sub(cmi)); | ||
| 19749 | + let max_h_mi = h_mi.min((mi_rows as usize).saturating_sub(rmi)); | ||
| 19750 | + read_var_tx_size( | ||
| 19751 | + dec, | ||
| 19752 | + cdfs, | ||
| 19753 | + neighbours, | ||
| 19754 | + lmi, | ||
| 19755 | + SIDE, | ||
| 19756 | + (max_w_mi, max_h_mi), | ||
| 19757 | + (bw, bh), | ||
| 19758 | + 0, | ||
| 19759 | + 0, | ||
| 19760 | + 0, | ||
| 19761 | + &mut leaves, | ||
| 19762 | + ); | ||
| 19763 | + } else { | ||
| 19764 | + leaves.push((0, 0, bw, bh)); | ||
| 19765 | + set_txfm_ctxs(neighbours, lmi, bw.max(bh), w_mi, h_mi, skip); | ||
| 19766 | + } | ||
| 19767 | + if std::env::var_os("EC_TRACE_MODE").is_some() { | ||
| 19768 | + eprintln!( | ||
| 19769 | + "EC_MODE_VALR mi_row={rmi} mi_col={cmi} newmv={is_new_mv} globalmv={is_globalmv} \ | ||
| 19770 | + ref0={ref_frame} mv0=({},{}) stack={} leaves={} rng={}", | ||
| 19771 | + mv.0, | ||
| 19772 | + mv.1, | ||
| 19773 | + stack.entries.len(), | ||
| 19774 | + leaves.len(), | ||
| 19775 | + dec.debug_state().0 | ||
| 19776 | + ); | ||
| 19777 | + } | ||
| 19778 | + grid_stamp_rect(grid, rmi, cmi, w_mi, h_mi, ref_frame, mv, is_new_mv); | ||
| 19779 | + piece[i] = Some((ref_frame, mv, h_filter, v_filter)); | ||
| 19780 | + // Prediction over the leaf's true footprint, laid out at the group's | ||
| 19781 | + // square stride (what `reconstruct_mc_rect` and `read_inter_plane_rect` | ||
| 19782 | + // index with). | ||
| 19783 | + let mut pred_y = vec![0u16; SIDE * SIDE]; | ||
| 19784 | + { | ||
| 19785 | + let mut dense = vec![0u16; bw * bh]; | ||
| 19786 | + mc::predict_with_filters( | ||
| 19787 | + &sref_y.data, | ||
| 19788 | + sref_y.width, | ||
| 19789 | + sref_y.true_width, | ||
| 19790 | + sref_y.true_height, | ||
| 19791 | + mv_to_q4(px, mv.1, true), | ||
| 19792 | + mv_to_q4(py, mv.0, true), | ||
| 19793 | + bw, | ||
| 19794 | + bh, | ||
| 19795 | + h_filter, | ||
| 19796 | + v_filter, | ||
| 19797 | + &mut dense, | ||
| 19798 | + ); | ||
| 19799 | + for row in 0..bh { | ||
| 19800 | + pred_y[row * SIDE..][..bw].copy_from_slice(&dense[row * bw..][..bw]); | ||
| 19801 | + } | ||
| 19802 | + } | ||
| 19803 | + if skip { | ||
| 19804 | + y.reconstruct_mc_rect(px, py, SIDE, bw, bh, &pred_y, &vec![0i32; SIDE * SIDE]); | ||
| 19805 | + neighbours.record_mi_luma_rect(lmi, bw, bh, &vec![0i32; bw * bh]); | ||
| 19806 | + neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, bw as u8, bh as u8, ref_frame.max(LAST_FRAME)); | ||
| 19807 | + } else { | ||
| 19808 | + let (mut last_tw, mut last_th) = (bw, bh); | ||
| 19809 | + for (idx, &(row, col, tw, th)) in leaves.iter().enumerate() { | ||
| 19810 | + let tu_mi = (rmi + row, cmi + col); | ||
| 19811 | + let (tu_px, tu_py) = (px + col * MI, py + row * MI); | ||
| 19812 | + let (tu_grid, tu_tx_type) = if tw == th { | ||
| 19813 | + // A split `TX_4X4` unit: square reader, its own | ||
| 19814 | + // `get_txb_ctx_general` neighbour context (the unit is | ||
| 19815 | + // smaller than its plane block, so the lone-TU 0 does not | ||
| 19816 | + // apply). | ||
| 19817 | + let mut tu_pred = Vec::with_capacity(tw * th); | ||
| 19818 | + for rr in 0..th { | ||
| 19819 | + let start = (row * MI + rr) * SIDE + col * MI; | ||
| 19820 | + tu_pred.extend_from_slice(&pred_y[start..start + tw]); | ||
| 19821 | + } | ||
| 19822 | + let tu_skip_ctx = neighbours.luma_skip_ctx_rect(tu_mi, tw / MI, th / MI); | ||
| 19823 | + read_inter_plane( | ||
| 19824 | + dec, | ||
| 19825 | + cdfs, | ||
| 19826 | + if reduced_tx_set { | ||
| 19827 | + TxbSet::Luma4Inter | ||
| 19828 | + } else { | ||
| 19829 | + TxbSet::Luma4InterSet1 | ||
| 19830 | + }, | ||
| 19831 | + scan4, | ||
| 19832 | + 0, | ||
| 19833 | + neighbours.around_mi(tu_mi, tw)[0], | ||
| 19834 | + 0, | ||
| 19835 | + y, | ||
| 19836 | + tu_px, | ||
| 19837 | + tu_py, | ||
| 19838 | + tw, | ||
| 19839 | + base_q_idx, | ||
| 19840 | + &tu_pred, | ||
| 19841 | + None, | ||
| 19842 | + Some(tu_skip_ctx), | ||
| 19843 | + )? | ||
| 19844 | + } else { | ||
| 19845 | + // The whole leaf as one `TX_8X4`/`TX_4X8` unit: it IS the | ||
| 19846 | + // plane block, so `get_txb_ctx_general` fixes `txb_skip_ctx` | ||
| 19847 | + // at 0 (`luma_skip_ctx: None`). | ||
| 19848 | + let start = row * MI * SIDE + col * MI; | ||
| 19849 | + read_inter_plane_rect( | ||
| 19850 | + dec, | ||
| 19851 | + cdfs, | ||
| 19852 | + if reduced_tx_set { | ||
| 19853 | + TxbSet::LumaRect8x4Inter | ||
| 19854 | + } else { | ||
| 19855 | + TxbSet::LumaRect8x4InterSet1 | ||
| 19856 | + }, | ||
| 19857 | + (tw, th), | ||
| 19858 | + SIDE, | ||
| 19859 | + 0, | ||
| 19860 | + neighbours.around_mi_rect(tu_mi, tw, th)[0], | ||
| 19861 | + 0, | ||
| 19862 | + y, | ||
| 19863 | + tu_px, | ||
| 19864 | + tu_py, | ||
| 19865 | + &pred_y[start..], | ||
| 19866 | + None, | ||
| 19867 | + None, | ||
| 19868 | + )? | ||
| 19869 | + }; | ||
| 19870 | + if idx == 0 { | ||
| 19871 | + // `av1_get_tx_type`: the group's one chroma unit scales | ||
| 19872 | + // back to luma (0, 0), i.e. the FIRST sub-block's first | ||
| 19873 | + // transform unit. | ||
| 19874 | + first_tx_type = tu_tx_type; | ||
| 19875 | + } | ||
| 19876 | + neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid); | ||
| 19877 | + (last_tw, last_th) = (tw, th); | ||
| 19878 | + } | ||
| 19879 | + neighbours.fill_lf_grid_rect( | ||
| 19880 | + lmi, | ||
| 19881 | + w_mi, | ||
| 19882 | + h_mi, | ||
| 19883 | + last_tw as u8, | ||
| 19884 | + last_th as u8, | ||
| 19885 | + ref_frame.max(LAST_FRAME), | ||
| 19886 | + ); | ||
| 19887 | + } | ||
| 19888 | + neighbours.record_mode_mi(rmi, cmi, w_mi, h_mi, DC_PRED); | ||
| 19889 | + neighbours.record_inter_rect_mi(lmi, w_mi, h_mi, skip, true, ref_frame, resolved_filter, false); | ||
| 19890 | + neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip); | ||
| 19891 | + last_skip = skip; | ||
| 19892 | + } | ||
| 19893 | + // The group's single 4x4 chroma unit per plane, on the chroma-reference | ||
| 19894 | + // (second) sub-block's own skip flag. | ||
| 19895 | + const B4: usize = 4; | ||
| 19896 | + let mut pred_u = vec![0u16; B4 * B4]; | ||
| 19897 | + let mut pred_v = vec![0u16; B4 * B4]; | ||
| 19898 | + let (piece_w, piece_h) = if vert { (2usize, 4usize) } else { (4usize, 2usize) }; | ||
| 19899 | + for i in 0..2usize { | ||
| 19900 | + let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else { | ||
| 19901 | + continue; | ||
| 19902 | + }; | ||
| 19903 | + let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?; | ||
| 19904 | + let (ox, oy) = if vert { | ||
| 19905 | + (cpx + i * piece_w, cpy) | ||
| 19906 | + } else { | ||
| 19907 | + (cpx, cpy + i * piece_h) | ||
| 19908 | + }; | ||
| 19909 | + let (dc, dr) = if vert { (i * piece_w, 0) } else { (0, i * piece_h) }; | ||
| 19910 | + for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { | ||
| 19911 | + let mut buf = vec![0u16; piece_w * piece_h]; | ||
| 19912 | + mc::predict_with_filters( | ||
| 19913 | + &plane.data, | ||
| 19914 | + plane.width, | ||
| 19915 | + plane.true_width, | ||
| 19916 | + plane.true_height, | ||
| 19917 | + mv_to_q4(ox, mv.1, false), | ||
| 19918 | + mv_to_q4(oy, mv.0, false), | ||
| 19919 | + piece_w, | ||
| 19920 | + piece_h, | ||
| 19921 | + h_filter, | ||
| 19922 | + v_filter, | ||
| 19923 | + &mut buf, | ||
| 19924 | + ); | ||
| 19925 | + for row in 0..piece_h { | ||
| 19926 | + for col in 0..piece_w { | ||
| 19927 | + dst[(dr + row) * B4 + dc + col] = buf[row * piece_w + col]; | ||
| 19928 | + } | ||
| 19929 | + } | ||
| 19930 | + } | ||
| 19931 | + } | ||
| 19932 | + let (u_grid, v_grid) = if last_skip { | ||
| 19933 | + u.reconstruct_mc(cpx, cpy, B4, &pred_u, &vec![0i32; B4 * B4]); | ||
| 19934 | + v.reconstruct_mc(cpx, cpy, B4, &pred_v, &vec![0i32; B4 * B4]); | ||
| 19935 | + (vec![0i32; B4 * B4], vec![0i32; B4 * B4]) | ||
| 19936 | + } else { | ||
| 19937 | + let around = neighbours.around_mi(group_mi, 8); | ||
| 19938 | + let ug = read_inter_plane( | ||
| 19939 | + dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], 0, u, cpx, cpy, B4, base_q_idx, | ||
| 19940 | + &pred_u, Some(first_tx_type), None, | ||
| 19941 | + )? | ||
| 19942 | + .0; | ||
| 19943 | + let vg = read_inter_plane( | ||
| 19944 | + dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], 0, v, cpx, cpy, B4, base_q_idx, | ||
| 19945 | + &pred_v, Some(first_tx_type), None, | ||
| 19946 | + )? | ||
| 19947 | + .0; | ||
| 19948 | + (ug, vg) | ||
| 19949 | + }; | ||
| 19950 | + neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED); | ||
| 19951 | + // `update_partition_context` writes `partition_context_lookup[subsize]` | ||
| 19952 | + // over the whole 8x8 span -- BLOCK_4X8's width above and height left, the | ||
| 19953 | + // same values [`decode_leaf_rect8`] writes for the intra shape. | ||
| 19954 | + for cell in 0..2usize { | ||
| 19955 | + neighbours.above_side_mi[gc + cell] = bw; | ||
| 19956 | + neighbours.left_side_mi[gr + cell] = bh; | ||
| 19957 | + } | ||
| 19958 | + let round_up_even = |n: usize| n.div_ceil(2) * 2; | ||
| 19959 | + let bound_h = round_up_even(neighbours.mi_rows); | ||
| 19960 | + let bound_w = round_up_even(neighbours.mi_cols); | ||
| 19961 | + let u_state = neighbour_state(&u_grid); | ||
| 19962 | + let v_state = neighbour_state(&v_grid); | ||
| 19963 | + for cell in 0..2usize { | ||
| 19964 | + if cell < 2usize.min(bound_h.saturating_sub(gr)) { | ||
| 19965 | + neighbours.left[gr + cell][1] = u_state; | ||
| 19966 | + neighbours.left[gr + cell][2] = v_state; | ||
| 19967 | + } | ||
| 19968 | + if cell < 2usize.min(bound_w.saturating_sub(gc)) { | ||
| 19969 | + neighbours.above[gc + cell][1] = u_state; | ||
| 19970 | + neighbours.above[gc + cell][2] = v_state; | ||
| 19971 | + } | ||
| 19972 | + } | ||
| 19973 | + Ok(()) | ||
| 19974 | +} | ||
| 19975 | + | ||
| 19976 | +/// Stamps one sub-8x8 inter leaf into every mi cell of its true `w_mi`x`h_mi` | ||
| 19977 | +/// footprint (class: a rect block's grid span is its own, never a square guess). | ||
| 19978 | +fn grid_stamp_rect( | ||
| 19979 | + grid: &mut MiGrid, | ||
| 19980 | + mi_row: usize, | ||
| 19981 | + mi_col: usize, | ||
| 19982 | + w_mi: usize, | ||
| 19983 | + h_mi: usize, | ||
| 19984 | + ref_frame: i8, | ||
| 19985 | + mv: (i32, i32), | ||
| 19986 | + is_new_mv: bool, | ||
| 19987 | +) { | ||
| 19988 | + for dr in 0..h_mi { | ||
| 19989 | + for dc in 0..w_mi { | ||
| 19990 | + grid.set( | ||
| 19991 | + mi_row + dr, | ||
| 19992 | + mi_col + dc, | ||
| 19993 | + MiInfo { | ||
| 19994 | + is_inter: true, | ||
| 19995 | + ref_frame, | ||
| 19996 | + ref_frame1: None, | ||
| 19997 | + mv1: None, | ||
| 19998 | + mv, | ||
| 19999 | + is_new_mv, | ||
| 20000 | + size: w_mi, | ||
| 20001 | + size_h: h_mi, | ||
| 20002 | + is_global_mv0: false, | ||
| 20003 | + is_global_mv1: false, | ||
| 20004 | + }, | ||
| 20005 | + ); | ||
| 20006 | + } | ||
| 20007 | + } | ||
| 20008 | +} | ||
| 20009 | + | ||
| 19481 | /// Decodes one 8x8 leaf of a straddling 16x16 inter-frame block | 20010 | /// Decodes one 8x8 leaf of a straddling 16x16 inter-frame block |
| 19482 | /// (lane-av1inter8), mirroring [`crate::tile::write_inter_frame_leaf8`]'s | 20011 | /// (lane-av1inter8), mirroring [`crate::tile::write_inter_frame_leaf8`]'s |
| 19483 | /// exact symbol order: its own skip flag, intra/inter choice and (when | 20012 | /// exact symbol order: its own skip flag, intra/inter choice and (when |
| @@ -21566,6 +22095,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 21566 | // instead of silently decoding as SPLIT and desyncing. | 22095 | // instead of silently decoding as SPLIT and desyncing. |
| 21567 | let part64 = match (has_cols, has_rows) { | 22096 | let part64 = match (has_cols, has_rows) { |
| 21568 | (true, true) => { | 22097 | (true, true) => { |
| 22098 | + if std::env::var_os("EC_TRACE_PART").is_some() { eprintln!("EC_PART mi_row={} mi_col={} bsize=12 ctx={} rng={}", sb_r as usize * SB_MI as usize, sb_c as usize * SB_MI as usize, sb_ctx, dec.debug_state().0); } | ||
| 21569 | let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]); | 22099 | let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]); |
| 21570 | if std::env::var_os("EC_AV1_TRACE").is_some() { | 22100 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 21571 | eprintln!( | 22101 | eprintln!( |
| @@ -21750,6 +22280,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 21750 | dec.debug_state().0 | 22280 | dec.debug_state().0 |
| 21751 | ); | 22281 | ); |
| 21752 | } | 22282 | } |
| 22283 | + if std::env::var_os("EC_TRACE_PART").is_some() { eprintln!("EC_PART mi_row={} mi_col={} bsize=9 ctx={} rng={}", (r32 as usize), (c32 as usize), ctx32, dec.debug_state().0); } | ||
| 21753 | let p = dec.symbol(&mut cdfs.partition_w32[ctx32]); | 22284 | let p = dec.symbol(&mut cdfs.partition_w32[ctx32]); |
| 21754 | if std::env::var_os("EC_AV1_TRACE").is_some() { | 22285 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 21755 | eprintln!( | 22286 | eprintln!( |
| @@ -21862,6 +22393,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 21862 | // inter leaves through the very same loop the | 22393 | // inter leaves through the very same loop the |
| 21863 | // straddling case has always used. | 22394 | // straddling case has always used. |
| 21864 | let part16 = if has_cols16 && has_rows16 { | 22395 | let part16 = if has_cols16 && has_rows16 { |
| 22396 | + if std::env::var_os("EC_TRACE_PART").is_some() { eprintln!("EC_PART mi_row={} mi_col={} bsize=6 ctx={} rng={}", (sr as usize*SUB_MI as usize), (sc as usize*SUB_MI as usize), ctx16, dec.debug_state().0); } | ||
| 21865 | let p = dec.symbol(&mut cdfs.partition_w16[ctx16]); | 22397 | let p = dec.symbol(&mut cdfs.partition_w16[ctx16]); |
| 21866 | if std::env::var_os("EC_AV1_TRACE").is_some() { | 22398 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 21867 | let (rng, _) = dec.debug_state(); | 22399 | let (rng, _) = dec.debug_state(); |
| @@ -22077,6 +22609,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 22077 | for (mr, mc) in leaf_positions { | 22609 | for (mr, mc) in leaf_positions { |
| 22078 | let leaf_mi = (mr as usize, mc as usize); | 22610 | let leaf_mi = (mr as usize, mc as usize); |
| 22079 | let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); | 22611 | let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); |
| 22612 | + if std::env::var_os("EC_TRACE_PART").is_some() { eprintln!("EC_PART mi_row={} mi_col={} bsize=3 ctx={} rng={}", leaf_mi.0, leaf_mi.1, leaf_ctx, dec.debug_state().0); } | ||
| 22080 | let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); | 22613 | let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); |
| 22081 | if part8 == PARTITION_SPLIT { | 22614 | if part8 == PARTITION_SPLIT { |
| 22082 | // lane-intersub8: four BLOCK_4X4 inter | 22615 | // lane-intersub8: four BLOCK_4X4 inter |
| @@ -22110,11 +22643,64 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 22110 | )?; | 22643 | )?; |
| 22111 | continue; | 22644 | continue; |
| 22112 | } | 22645 | } |
| 22113 | - if part8 != PARTITION_NONE { | 22646 | + if part8 == PARTITION_HORZ { |
| 22647 | + // lane-intersub8 r3: the two-BLOCK_8X4 | ||
| 22648 | + // shape IS implemented below | ||
| 22649 | + // ([`decode_inter_sub8_rect2`], same | ||
| 22650 | + // function as the 4x8 one), and it | ||
| 22651 | + // decodes most streams exact -- but a | ||
| 22652 | + // measured 4-of-28-attempt sweep | ||
| 22653 | + // (transposed-structure source, cq | ||
| 22654 | + // 12..32, both depths) desyncs in the | ||
| 22655 | + // MODE INFO of the 16x8 inter block | ||
| 22656 | + // immediately to its right: entry | ||
| 22657 | + // ranges match at that block's | ||
| 22658 | + // `EC_MODE` print and differ by its | ||
| 22659 | + // first coefficient TU, so some | ||
| 22660 | + // per-row neighbour band this group | ||
| 22661 | + // leaves behind is wrong. Refused by | ||
| 22662 | + // name rather than shipped as silent | ||
| 22663 | + // pixel drift; the 4x8 twin is gated. | ||
| 22114 | return Err(unsupported( | 22664 | return Err(unsupported( |
| 22115 | - "an inter 8x8 HORZ/VERT partition (8x4/4x8 inter leaves; the 4x4 SPLIT arm decodes, but a rectangular sub-8x8 inter transform is unimplemented)", | 22665 | + "an inter 8x8 HORZ partition (two BLOCK_8X4 inter leaves; decoded, but a measured sweep desyncs the block to its right)", |
| 22116 | )); | 22666 | )); |
| 22117 | } | 22667 | } |
| 22668 | + if part8 == PARTITION_VERT { | ||
| 22669 | + // lane-intersub8 r3: two BLOCK_8X4 / | ||
| 22670 | + // BLOCK_4X8 inter leaves, chroma once | ||
| 22671 | + // per 8x8 on the second of them. | ||
| 22672 | + decode_inter_sub8_rect2( | ||
| 22673 | + &mut dec, | ||
| 22674 | + &mut cdfs, | ||
| 22675 | + &mut neighbours, | ||
| 22676 | + &mut grid, | ||
| 22677 | + leaf_mi, | ||
| 22678 | + true, | ||
| 22679 | + mi_cols, | ||
| 22680 | + mi_rows, | ||
| 22681 | + &mut y, | ||
| 22682 | + &mut u, | ||
| 22683 | + &mut v, | ||
| 22684 | + &ref_y, | ||
| 22685 | + &ref_u, | ||
| 22686 | + &ref_v, | ||
| 22687 | + &ref_slots, | ||
| 22688 | + &sign_bias_table, | ||
| 22689 | + &global_motion, | ||
| 22690 | + base_q_idx, | ||
| 22691 | + &scan4, | ||
| 22692 | + allow_high_precision_mv, | ||
| 22693 | + force_integer_mv, | ||
| 22694 | + interp_fixed, | ||
| 22695 | + enable_dual_filter, | ||
| 22696 | + tpl_frame.as_ref(), | ||
| 22697 | + reduced_tx_set, | ||
| 22698 | + frame_width as usize, | ||
| 22699 | + )?; | ||
| 22700 | + continue; | ||
| 22701 | + } | ||
| 22702 | + // `partition_w8` is a 4-symbol alphabet | ||
| 22703 | + // (NONE/HORZ/VERT/SPLIT), all four handled. | ||
| 22118 | let ( | 22704 | let ( |
| 22119 | skip, | 22705 | skip, |
| 22120 | is_inter, | 22706 | is_inter, |
crates/ec-av1/src/refusal_inventory.rsmodified+2 -1
| @@ -33,9 +33,10 @@ const REFUSALS: &[&str] = &[ | |||
| 33 | "a nonzero angle delta on an 8x8 intra leaf in an inter frame (no gate reaches this leaf with one; the >=16x16 arm decodes deltas)", | 33 | "a nonzero angle delta on an 8x8 intra leaf in an inter frame (no gate reaches this leaf with one; the >=16x16 arm decodes deltas)", |
| 34 | "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", | 34 | "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", |
| 35 | "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", | 35 | "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", |
| 36 | - "an inter 8x8 HORZ/VERT partition (8x4/4x8 inter leaves; the 4x4 SPLIT arm decodes, but a rectangular sub-8x8 inter transform is unimplemented)", | ||
| 37 | "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes only inter 4x4 sub-blocks there)", | 36 | "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes only inter 4x4 sub-blocks there)", |
| 37 | + "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition (this decoder codes only inter sub-blocks there)", | ||
| 38 | "a sub-8x8 inter block under a scaled reference (superres, unimplemented)", | 38 | "a sub-8x8 inter block under a scaled reference (superres, unimplemented)", |
| 39 | + "an inter 8x8 HORZ partition (two BLOCK_8X4 inter leaves; decoded, but a measured sweep desyncs the block to its right)", | ||
| 39 | "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)", | 40 | "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)", |
| 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", |
crates/ec-av1/src/stream.rsmodified+32 -9
| @@ -7519,10 +7519,12 @@ mod tests { | |||
| 7519 | /// oracle `aomdec`'s `EC_TRACE` prints `EC_PART_VAL ... bsize=3 value=3` | 7519 | /// oracle `aomdec`'s `EC_TRACE` prints `EC_PART_VAL ... bsize=3 value=3` |
| 7520 | /// on this recipe's inter frames. | 7520 | /// on this recipe's inter frames. |
| 7521 | /// | 7521 | /// |
| 7522 | - /// `--enable-rect-partitions=0` because the 8x4/4x8 sub-8x8 leaves are | 7522 | + /// Attempts 0..7 run `--enable-rect-partitions=0`, where aomenc can only |
| 7523 | - /// still refused (a rectangular sub-8x8 inter transform is unimplemented); | 7523 | + /// pick SPLIT below 8x8; attempts 8..15 repeat the schedule with rect on, |
| 7524 | - /// with rect on, aomenc picks HORZ/VERT below 8x8 far more often than | 7524 | + /// where it picks HORZ/VERT below 8x8 far more often than SPLIT -- the VERT |
| 7525 | - /// SPLIT and no attempt reaches a split group. | 7525 | + /// arm (two `BLOCK_4X8` inter leaves, `decode_inter_sub8_rect2`) is what the |
| 7526 | + /// `rect_fired` assert pins. The HORZ twin decodes but is refused by name | ||
| 7527 | + /// (lane-intersub8 r3: a measured sweep desyncs the block to its right). | ||
| 7526 | #[test] | 7528 | #[test] |
| 7527 | fn a_real_aomenc_inter_sequence_with_a_sub8x8_inter_split_decodes_pixel_exact() { | 7529 | fn a_real_aomenc_inter_sequence_with_a_sub8x8_inter_split_decodes_pixel_exact() { |
| 7528 | const NAME: &str = | 7530 | const NAME: &str = |
| @@ -7538,10 +7540,17 @@ mod tests { | |||
| 7538 | } | 7540 | } |
| 7539 | let (width, height, frame_count) = (192usize, 128usize, 6usize); | 7541 | let (width, height, frame_count) = (192usize, 128usize, 6usize); |
| 7540 | let mut fired = 0u32; | 7542 | let mut fired = 0u32; |
| 7543 | + // lane-intersub8 r3: attempts 8..15 repeat the same schedule with | ||
| 7544 | + // `--enable-rect-partitions=1`, where aomenc picks PARTITION_VERT below | ||
| 7545 | + // 8x8 (two BLOCK_4X8 inter leaves, one shared 4x4 chroma unit predicted | ||
| 7546 | + // from BOTH sub-blocks' mvs). The HORZ twin is still refused by name. | ||
| 7547 | + let mut rect_fired = 0u32; | ||
| 7541 | let mut refusals: Vec<String> = Vec::new(); | 7548 | let mut refusals: Vec<String> = Vec::new(); |
| 7542 | let mut out_of_scope_mismatch = 0u32; | 7549 | let mut out_of_scope_mismatch = 0u32; |
| 7543 | for bit_depth in [8u32, 10u32] { | 7550 | for bit_depth in [8u32, 10u32] { |
| 7544 | - for attempt in 0..8u32 { | 7551 | + for attempt in 0..16u32 { |
| 7552 | + let rect = attempt / 8; | ||
| 7553 | + let rect_arg = format!("--enable-rect-partitions={rect}"); | ||
| 7545 | // lane-intersub8 r2, measured schedule (sweep of cq | 7554 | // lane-intersub8 r2, measured schedule (sweep of cq |
| 7546 | // {8,10,12,14,16,18,20} x sp {3,6,9,12} x both depths, | 7555 | // {8,10,12,14,16,18,20} x sp {3,6,9,12} x both depths, |
| 7547 | // `decode_probe`'s `sub8_inter_split:` counter vs an ffmpeg | 7556 | // `decode_probe`'s `sub8_inter_split:` counter vs an ffmpeg |
| @@ -7557,7 +7566,7 @@ mod tests { | |||
| 7557 | // is not selecting quantizers that hide a defect of its own | 7566 | // is not selecting quantizers that hide a defect of its own |
| 7558 | // shape. | 7567 | // shape. |
| 7559 | let cq = [12, 14][(attempt % 2) as usize]; | 7568 | let cq = [12, 14][(attempt % 2) as usize]; |
| 7560 | - let sp = 3 + (attempt / 2) * 3; | 7569 | + let sp = 3 + ((attempt % 8) / 2) * 3; |
| 7561 | let duration = frame_count as f64 / 25.0; | 7570 | let duration = frame_count as f64 / 25.0; |
| 7562 | let source = format!( | 7571 | let source = format!( |
| 7563 | "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ | 7572 | "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ |
| @@ -7592,6 +7601,7 @@ mod tests { | |||
| 7592 | "--enable-rect-partitions=0", "--enable-ab-partitions=0", | 7601 | "--enable-rect-partitions=0", "--enable-ab-partitions=0", |
| 7593 | "--enable-1to4-partitions=0", "--min-partition-size=4", | 7602 | "--enable-1to4-partitions=0", "--min-partition-size=4", |
| 7594 | "--max-partition-size=16", | 7603 | "--max-partition-size=16", |
| 7604 | + &rect_arg, | ||
| 7595 | "--obu", "-o", "-", "-", | 7605 | "--obu", "-o", "-", "-", |
| 7596 | ]; | 7606 | ]; |
| 7597 | let mut child = Command::new(aomenc_path()) | 7607 | let mut child = Command::new(aomenc_path()) |
| @@ -7615,6 +7625,7 @@ mod tests { | |||
| 7615 | ); | 7625 | ); |
| 7616 | let stream = out.stdout; | 7626 | let stream = out.stdout; |
| 7617 | let before = decode::sub8_inter_split_hits(); | 7627 | let before = decode::sub8_inter_split_hits(); |
| 7628 | + let before_rect = decode::sub8_inter_rect_hits(); | ||
| 7618 | let frames = match decode_stream(&stream) { | 7629 | let frames = match decode_stream(&stream) { |
| 7619 | Err(e) => { | 7630 | Err(e) => { |
| 7620 | let msg = e.to_string(); | 7631 | let msg = e.to_string(); |
| @@ -7628,7 +7639,10 @@ mod tests { | |||
| 7628 | } | 7639 | } |
| 7629 | Ok(frames) => frames, | 7640 | Ok(frames) => frames, |
| 7630 | }; | 7641 | }; |
| 7631 | - let groups = decode::sub8_inter_split_hits() - before; | 7642 | + let split_groups = decode::sub8_inter_split_hits() - before; |
| 7643 | + let rect_now = decode::sub8_inter_rect_hits(); | ||
| 7644 | + let rect_groups = (rect_now.0 - before_rect.0) + (rect_now.1 - before_rect.1); | ||
| 7645 | + let groups = split_groups + rect_groups; | ||
| 7632 | let ffmpeg_frames = if bit_depth == 10 { | 7646 | let ffmpeg_frames = if bit_depth == 10 { |
| 7633 | ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | 7647 | ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) |
| 7634 | } else { | 7648 | } else { |
| @@ -7645,7 +7659,7 @@ mod tests { | |||
| 7645 | out_of_scope_mismatch += 1; | 7659 | out_of_scope_mismatch += 1; |
| 7646 | eprintln!( | 7660 | eprintln!( |
| 7647 | "{NAME}: {bit_depth}-bit attempt {attempt} MISMATCHES with zero \ | 7661 | "{NAME}: {bit_depth}-bit attempt {attempt} MISMATCHES with zero \ |
| 7648 | - sub-8x8 inter split group -- another shape's defect" | 7662 | + sub-8x8 inter group -- another shape's defect" |
| 7649 | ); | 7663 | ); |
| 7650 | } | 7664 | } |
| 7651 | refusals.push(format!( | 7665 | refusals.push(format!( |
| @@ -7663,17 +7677,26 @@ mod tests { | |||
| 7663 | assert_eq!(got.v, want.v, "V frame {i} ({bit_depth}-bit attempt {attempt})"); | 7677 | assert_eq!(got.v, want.v, "V frame {i} ({bit_depth}-bit attempt {attempt})"); |
| 7664 | } | 7678 | } |
| 7665 | fired += 1; | 7679 | fired += 1; |
| 7680 | + if rect_groups > 0 { | ||
| 7681 | + rect_fired += 1; | ||
| 7682 | + } | ||
| 7666 | } | 7683 | } |
| 7667 | } | 7684 | } |
| 7668 | assert_eq!( | 7685 | assert_eq!( |
| 7669 | out_of_scope_mismatch, 0, | 7686 | out_of_scope_mismatch, 0, |
| 7670 | - "{NAME}: attempts mismatched with no sub-8x8 inter split group" | 7687 | + "{NAME}: attempts mismatched with no sub-8x8 inter group" |
| 7671 | ); | 7688 | ); |
| 7672 | assert!( | 7689 | assert!( |
| 7673 | fired >= 2, | 7690 | fired >= 2, |
| 7674 | "{NAME}: fewer than 2 firing+pixel-exact attempts:\n{}", | 7691 | "{NAME}: fewer than 2 firing+pixel-exact attempts:\n{}", |
| 7675 | refusals.join("\n") | 7692 | refusals.join("\n") |
| 7676 | ); | 7693 | ); |
| 7694 | + assert!( | ||
| 7695 | + rect_fired >= 2, | ||
| 7696 | + "{NAME}: fewer than 2 firing+pixel-exact attempts with a RECTANGULAR sub-8x8 \ | ||
| 7697 | + inter leaf (4x8):\n{}", | ||
| 7698 | + refusals.join("\n") | ||
| 7699 | + ); | ||
| 7677 | } | 7700 | } |
| 7678 | 7701 | ||
| 7679 | #[test] | 7702 | #[test] |
lanes/intersub8-r3.handoff.mdadded+79 -0
| @@ -0,0 +1,79 @@ | |||
| 1 | +# lane-intersub8 r3 — HANDOFF (4x8 gated GREEN, 8x4 implemented but refused) | ||
| 2 | + | ||
| 3 | +## What is wired (decode.rs `decode_inter_sub8_rect2`, ~line 19100) | ||
| 4 | +One function serves both shapes (`vert: bool`); the call site | ||
| 5 | +(`part8 == PARTITION_VERT` arm of the sub-16 SPLIT leaf loop, ~decode.rs:22630) currently | ||
| 6 | +only reaches it with `vert = true`. | ||
| 7 | +* mode info per sub-block in `decodemv.c` `read_inter_frame_mode_info` order: segment_id, | ||
| 8 | + skip, cdef/dq/dlf, intra_inter, single ref only (`is_comp_ref_allowed(BLOCK_8X4)` false -> | ||
| 9 | + no skip_mode, no comp_mode), no interintra / motion_mode / OBMC / warp (all need min dim 8), | ||
| 10 | + `read_mb_interp_filter` DOES run. | ||
| 11 | +* tx: `block_signals_txsize(BLOCK_8X4)` true (blockd.h:1027) -> ONE `txfm_partition` symbol | ||
| 12 | + under TX_MODE_SELECT at `max_txsize_rect_lookup[BLOCK_8X4] = TX_8X4`, through r14's general | ||
| 13 | + `read_var_tx_size` with max `(bw,bh)` and `blk_max_px = 8`; `sub_tx_size_map[TX_8X4]=TX_4X4` | ||
| 14 | + so a split resolves to two TX_4X4 units (libaom's early return). Skip -> `set_txfm_ctxs` | ||
| 15 | + skip_inter arm. | ||
| 16 | +* luma sets NEW in cdf_state.rs: `TxbSet::LumaRect8x4Inter` / `LumaRect8x4InterSet1` = | ||
| 17 | + `LumaRect4x8`'s tables (8x8 coefficient class, 32-position eob_pt) with `inter_tx_type_4` / | ||
| 18 | + `inter_tx_type_4_set1` (EXT_TX_SET_ALL16 at the TX_4X4 inter row). Split TX_4X4 units read | ||
| 19 | + `Luma4Inter{,Set1}`. Whole-leaf unit passes `luma_skip_ctx: None` (it IS the plane block, | ||
| 20 | + `get_txb_ctx_general` fixes 0); split units pass `luma_skip_ctx_rect`. | ||
| 21 | +* chroma once, on the SECOND sub-block (`is_chroma_reference` under 4:2:0: bottom 8x4 / | ||
| 22 | + right 4x8), as one TX_4X4 per plane (`TxbSet::Chroma4`), inheriting the FIRST luma TU's | ||
| 23 | + tx_type; prediction is the sub8x8 one (`reconinter.c build_inter_predictors_sub8x8`, | ||
| 24 | + `row_start = -(block_size_high==4 && ss_y)`): two 4x2 (HORZ) / 2x4 (VERT) pieces, each from | ||
| 25 | + its own sub-block's ref/mv/filters. | ||
| 26 | +* neighbour writes per mi: `grid_stamp_rect` (size=w_mi, size_h=h_mi over the true span), | ||
| 27 | + `record_mode_mi`, `record_inter_rect_mi`, `fill_skip_grid_rect`, `fill_lf_grid_rect`, | ||
| 28 | + `record_mi_luma_rect` per TU; partition tail `above_side_mi = bw`, `left_side_mi = bh`. | ||
| 29 | + | ||
| 30 | +## The 8x4 defect (refused by name, NOT fixed) | ||
| 31 | +Stream: `~/.cache/intersub8-tmp/gen_t.sh 14 3 8 d1.obu --enable-rect-partitions=1` | ||
| 32 | +(transposed-structure geq source: `128+58*sin((Y+N*3)/6)+18*sin(X/23)`, 192x128, 6 frames). | ||
| 33 | +Decode-order frame 5 mismatches; frames 0..4 exact. 4 HORZ groups, all at mi rows 30/31, | ||
| 34 | +cols 4 and 6. | ||
| 35 | +Range ladder (`EC_TRACE_PART=1` ours, new gated print at each partition read, vs aomdec | ||
| 36 | +`EC_TRACE=1` `EC_PART`; and `EC_TRACE_MODE` `EC_MODE`; and `EC_TRACE_COEFF` `tag=all_zero`): | ||
| 37 | +* every element matches through the 16x16 partition read at mi(28,8) (ctx 2 == oracle's 6, | ||
| 38 | + entry rng 37489 both) and through `EC_MODE mi_row=30 mi_col=8 rng=46505` (both); | ||
| 39 | +* that slot is PARTITION_HORZ -> two BLOCK_16X8 at (28,8) and (30,8); | ||
| 40 | +* block (30,8)'s LEFT neighbour is our HORZ 8x4 group at (30,6); | ||
| 41 | +* first divergence is INSIDE (30,8)'s mode info, AFTER its `EC_MODE` print (so skip and | ||
| 42 | + intra_inter are still right) and BEFORE its first coefficient TU: our TU entry rng 54923 vs | ||
| 43 | + oracle 61760 (`EC_COEFF plane=0 tx_size=8` = TX_16X8, all_zero=0 both). all_zero #468 of | ||
| 44 | + 470/473. | ||
| 45 | +=> some per-ROW neighbour band our HORZ group leaves at rows 30/31 is wrong. Remaining | ||
| 46 | +suspects, in read order after the print: `left_ref[30]`, the mv stack (MiGrid cells (30,7)/ | ||
| 47 | +(31,7)), `left_filter[30]`, `left_txfm[30]`. All four were transcribed against libaom and | ||
| 48 | +looked right on inspection -- not bisected. NOTE ledger: this oracle's | ||
| 49 | +`EC_AV1_PREFILT_DUMP` is already post-deblock, so pixel-stage bisection is confounded; use | ||
| 50 | +the range ladder only. | ||
| 51 | + | ||
| 52 | +## Provable vs not | ||
| 53 | +* PROVABLE (gated): two-BLOCK_4X8 (PARTITION_VERT) inter leaves. Sweep | ||
| 54 | + `~/.cache/intersub8-tmp/sweep2.sh` (28 arms, cq {8,12,14,16,20,26,32} x sp {3,6,9,12} x | ||
| 55 | + 8/10-bit, original source, rect on): every arm with `vert4x8 > 0` outside the known-bad | ||
| 56 | + cq8 band decoded pixel-exact; the two cq8 mismatches are r2's CDEF |d|=1 defect. | ||
| 57 | +* NOT PROVABLE: 8x4 (HORZ). `sweep3.sh` (transposed source): 4 of 28 arms mismatch with | ||
| 58 | + `horz8x4 > 0` at cq 12/14/16/32, i.e. outside the CDEF band. Refused by name. | ||
| 59 | + | ||
| 60 | +## Gate | ||
| 61 | +`cargo test -p ec-av1 --lib sub8x8_inter_split` -> ok, 1 passed / 0 failed (414 filtered), | ||
| 62 | +28.94s. The test now runs 16 attempts per depth: 0..7 `--enable-rect-partitions=0` (SPLIT), | ||
| 63 | +8..15 `=1` (VERT). Asserts `fired >= 2`, NEW `rect_fired >= 2`, `out_of_scope_mismatch == 0`, | ||
| 64 | +every decode-order frame Y/U/V. `refusal_inventory` 3/3 ok, `gate_coverage` 9/9 ok. | ||
| 65 | + | ||
| 66 | +## Not done | ||
| 67 | +* Full `cargo test -p ec-av1 --lib` suite: NOT RUN this round (turn cap). r2's unit | ||
| 68 | + `intersub8-suite-1788328909` was still running on a stale binary at round start and is now | ||
| 69 | + gone from the unit list; `$HOME/.cache/intersub8-suite-r2.log` has 218 ok / 0 FAILED and no | ||
| 70 | + `test result:` line. Start r3's suite per COMMON's SUITE RUNS recipe, log | ||
| 71 | + `$HOME/.cache/intersub8-suite-r3.log`. | ||
| 72 | +* HG film probe: not run. | ||
| 73 | +* `--tile-columns=1` gate arm: still owed (no NEW per-mi band was added, all reused). | ||
| 74 | + | ||
| 75 | +## Exact next step | ||
| 76 | +1. Start the r3 suite. 2. Bisect the 8x4 defect on `d1.obu` frame 5 block (30,8) by dumping, | ||
| 77 | +one at a time, the four left-band values our HORZ group writes at rows 30/31 and comparing | ||
| 78 | +against an instrumented aomdec print of `xd->left_mbmi`/`left_txfm_context[0]` at that block. | ||
| 79 | +3. Lift the HORZ refusal with a `sweep3.sh`-based arm once green. | ||