merge(sub8x4)+fix(av1): one faithful copy of libaom's sub-8px mv-stack scans, and a sub-8x8 leaf that never saw its sibling's block size
Browse files at this commit5 changed files +825 -22
- crates/ec-av1/examples/decode_probe.rs +5 -0
- crates/ec-av1/src/decode.rs +633 -22
- crates/ec-av1/src/stream.rs +6 -0
- lanes/sub8intra-r1.handoff.md +108 -0
- lanes/sub8intra-r2.handoff.md +73 -0
crates/ec-av1/examples/decode_probe.rsmodified+5 -0
| @@ -45,6 +45,11 @@ fn main() { | |||
| 45 | println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits()); | 45 | println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits()); |
| 46 | let (h84, h48) = ec_av1::decode::sub8_inter_rect_hits(); | 46 | let (h84, h48) = ec_av1::decode::sub8_inter_rect_hits(); |
| 47 | println!("sub8_inter_rect: horz8x4={h84} vert4x8={h48}"); | 47 | println!("sub8_inter_rect: horz8x4={h84} vert4x8={h48}"); |
| 48 | + let si = ec_av1::stream::sub8_intra_rect_hits(); | ||
| 49 | + println!( | ||
| 50 | + "sub8_intra_rect: horz8x4={} vert4x8={} chroma_ref={} mixed={}", | ||
| 51 | + si.0, si.1, si.2, si.3 | ||
| 52 | + ); | ||
| 48 | let leaf = ec_av1::stream::vartx_rect_leaf_hits(); | 53 | let leaf = ec_av1::stream::vartx_rect_leaf_hits(); |
| 49 | println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]); | 54 | println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]); |
| 50 | // lane-inter16ab r1: the 16x16-level inter AB arms, so a recipe sweep | 55 | // lane-inter16ab r1: the 16x16-level inter AB arms, so a recipe sweep |
crates/ec-av1/src/decode.rsmodified+633 -22
| @@ -3117,6 +3117,21 @@ thread_local! { | |||
| 3117 | /// inter leaves (lane-intersub8 r3), indexed `[0] = HORZ` (two BLOCK_8X4), | 3117 | /// inter leaves (lane-intersub8 r3), indexed `[0] = HORZ` (two BLOCK_8X4), |
| 3118 | /// `[1] = VERT` (two BLOCK_4X8). | 3118 | /// `[1] = VERT` (two BLOCK_4X8). |
| 3119 | static SUB8_INTER_RECT_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) }; | 3119 | static SUB8_INTER_RECT_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) }; |
| 3120 | + /// lane-sub8intra: INTRA leaves decoded inside an inter frame's sub-8x8 | ||
| 3121 | + /// HORZ/VERT partition -- `[0]` 8x4, `[1]` 4x8, `[2]` of those that were | ||
| 3122 | + /// the chroma reference (so coded the group's 4x4 chroma intra), `[3]` | ||
| 3123 | + /// MIXED groups whose chroma reference is INTER while its sibling is | ||
| 3124 | + /// intra (the `is_sub8x8_inter` false path). | ||
| 3125 | + static SUB8_INTRA_RECT_HITS: std::cell::Cell<[usize; 4]> = const { std::cell::Cell::new([0; 4]) }; | ||
| 3126 | +} | ||
| 3127 | + | ||
| 3128 | +/// Current value of [`SUB8_INTRA_RECT_HITS`]: `(8x4, 4x8, chroma-reference, | ||
| 3129 | +/// mixed groups)`. | ||
| 3130 | +pub fn sub8_intra_rect_hits() -> (usize, usize, usize, usize) { | ||
| 3131 | + SUB8_INTRA_RECT_HITS.with(|c| { | ||
| 3132 | + let h = c.get(); | ||
| 3133 | + (h[0], h[1], h[2], h[3]) | ||
| 3134 | + }) | ||
| 3120 | } | 3135 | } |
| 3121 | 3136 | ||
| 3122 | /// Current value of [`SUB8_INTER_RECT_HITS`]: `(8x4 groups, 4x8 groups)`. | 3137 | /// Current value of [`SUB8_INTER_RECT_HITS`]: `(8x4 groups, 4x8 groups)`. |
| @@ -13313,6 +13328,19 @@ fn tx_size_context_txfm_rect( | |||
| 13313 | if has_left && n.left_inter[mi_r] { | 13328 | if has_left && n.left_inter[mi_r] { |
| 13314 | left = n.left_side_mi[mi_r] >= own_h; | 13329 | left = n.left_side_mi[mi_r] >= own_h; |
| 13315 | } | 13330 | } |
| 13331 | + if std::env::var_os("EC_TXCTX").is_some() { | ||
| 13332 | + eprintln!( | ||
| 13333 | + "EC_TXCTX mi={mi_r},{mi_c} own={own_w}x{own_h} ha={has_above} hl={has_left} \ | ||
| 13334 | + above_txfm={} left_txfm={} above_inter={} left_inter={} above_side={} left_side={} \ | ||
| 13335 | + above={above} left={left}", | ||
| 13336 | + n.above_txfm[mi_c], | ||
| 13337 | + n.left_txfm[mi_r], | ||
| 13338 | + n.above_inter[mi_c], | ||
| 13339 | + n.left_inter[mi_r], | ||
| 13340 | + n.above_side_mi[mi_c], | ||
| 13341 | + n.left_side_mi[mi_r], | ||
| 13342 | + ); | ||
| 13343 | + } | ||
| 13316 | match (has_above, has_left) { | 13344 | match (has_above, has_left) { |
| 13317 | (true, true) => usize::from(above) + usize::from(left), | 13345 | (true, true) => usize::from(above) + usize::from(left), |
| 13318 | (true, false) => usize::from(above), | 13346 | (true, false) => usize::from(above), |
| @@ -22646,6 +22674,9 @@ fn decode_inter_sub8_split4( | |||
| 22646 | [None; 4]; | 22674 | [None; 4]; |
| 22647 | let mut first_tx_type = TxType::DctDct; | 22675 | let mut first_tx_type = TxType::DctDct; |
| 22648 | let mut last_skip = true; | 22676 | let mut last_skip = true; |
| 22677 | + // Set when the chroma-reference (last) sub-block is INTRA: it coded the | ||
| 22678 | + // group's one chroma unit itself. | ||
| 22679 | + let mut intra_chroma = false; | ||
| 22649 | for i in 0..4usize { | 22680 | for i in 0..4usize { |
| 22650 | let (dr, dc) = (i / 2, i % 2); | 22681 | let (dr, dc) = (i / 2, i % 2); |
| 22651 | let lmi = (gr + dr, gc + dc); | 22682 | let lmi = (gr + dr, gc + dc); |
| @@ -22674,11 +22705,49 @@ fn decode_inter_sub8_split4( | |||
| 22674 | ); | 22705 | ); |
| 22675 | let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; | 22706 | let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; |
| 22676 | if !is_inter { | 22707 | if !is_inter { |
| 22708 | + if std::env::var_os("EC_SUB8INTRA").is_some() { | ||
| 22709 | + eprintln!( | ||
| 22710 | + "EC_SUB8INTRA shape=4x4 sub={i} has_chroma={} skip={skip} mi={rmi},{cmi} tx_select={}", | ||
| 22711 | + i == 3, | ||
| 22712 | + TX_SELECT_INTER.with(std::cell::Cell::get), | ||
| 22713 | + ); | ||
| 22714 | + } | ||
| 22715 | + // lane-sub8intra: same `EC_SUB8INTRA_DECODE` switch as the | ||
| 22716 | + // HORZ/VERT arm; the refusal is the default until the gate is | ||
| 22717 | + // green. | ||
| 22718 | + if std::env::var_os("EC_SUB8INTRA_DECODE").is_none() { | ||
| 22677 | return Err(unsupported( | 22719 | return Err(unsupported( |
| 22678 | "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes \ | 22720 | "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes \ |
| 22679 | only inter 4x4 sub-blocks there)", | 22721 | only inter 4x4 sub-blocks there)", |
| 22680 | )); | 22722 | )); |
| 22681 | } | 22723 | } |
| 22724 | + // lane-sub8intra: the `BLOCK_4X4` twin of the HORZ/VERT arm -- | ||
| 22725 | + // same [`decode_intra_sub8_leaf`], no tx-depth symbol, chroma on | ||
| 22726 | + // the LAST sub-block (`is_chroma_reference` under 4:2:0). | ||
| 22727 | + decode_intra_sub8_leaf( | ||
| 22728 | + dec, | ||
| 22729 | + cdfs, | ||
| 22730 | + neighbours, | ||
| 22731 | + grid, | ||
| 22732 | + group_mi, | ||
| 22733 | + lmi, | ||
| 22734 | + (B4, B4), | ||
| 22735 | + i == 3, | ||
| 22736 | + skip, | ||
| 22737 | + scan4, | ||
| 22738 | + y, | ||
| 22739 | + u, | ||
| 22740 | + v, | ||
| 22741 | + base_q_idx, | ||
| 22742 | + ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get), | ||
| 22743 | + TX_SELECT_INTER.with(std::cell::Cell::get), | ||
| 22744 | + reduced_tx_set, | ||
| 22745 | + )?; | ||
| 22746 | + if i == 3 { | ||
| 22747 | + intra_chroma = true; | ||
| 22748 | + } | ||
| 22749 | + continue; | ||
| 22750 | + } | ||
| 22682 | // Same print point as the oracle's `EC_MODE` (entry of | 22751 | // Same print point as the oracle's `EC_MODE` (entry of |
| 22683 | // `read_inter_block_mode_info`, i.e. after skip / is_inter), so the | 22752 | // `read_inter_block_mode_info`, i.e. after skip / is_inter), so the |
| 22684 | // two range ladders line up element for element. | 22753 | // two range ladders line up element for element. |
| @@ -22898,11 +22967,14 @@ fn decode_inter_sub8_split4( | |||
| 22898 | None, | 22967 | None, |
| 22899 | None, | 22968 | None, |
| 22900 | )?; | 22969 | )?; |
| 22901 | - if i == 0 { | 22970 | + if i == 0 || piece[0].is_none() { |
| 22902 | // `av1_get_tx_type`: an inter block's chroma inherits the | 22971 | // `av1_get_tx_type`: an inter block's chroma inherits the |
| 22903 | // tx_type of the CO-LOCATED luma position, which for the | 22972 | // tx_type of the CO-LOCATED luma position, which for the |
| 22904 | // group's one chroma unit is luma (0, 0) -- the FIRST | 22973 | // group's one chroma unit is luma (0, 0) -- the FIRST |
| 22905 | - // sub-block, not the last. | 22974 | + // sub-block, not the last. lane-sub8intra: an INTRA first |
| 22975 | + // sub-block writes no inter tx_type there at all, so the | ||
| 22976 | + // later inter sub-blocks' own is what `xd->tx_type_map` | ||
| 22977 | + // holds. | ||
| 22906 | first_tx_type = tx_type; | 22978 | first_tx_type = tx_type; |
| 22907 | } | 22979 | } |
| 22908 | neighbours.record_mi_luma_rect(lmi, B4, B4, &luma_grid); | 22980 | neighbours.record_mi_luma_rect(lmi, B4, B4, &luma_grid); |
| @@ -22919,20 +22991,43 @@ fn decode_inter_sub8_split4( | |||
| 22919 | neighbours.fill_lf_grid_rect(lmi, 1, 1, B4 as u8, B4 as u8, ref_frame.max(LAST_FRAME)); | 22991 | neighbours.fill_lf_grid_rect(lmi, 1, 1, B4 as u8, B4 as u8, ref_frame.max(LAST_FRAME)); |
| 22920 | last_skip = skip; | 22992 | last_skip = skip; |
| 22921 | } | 22993 | } |
| 22994 | + // lane-sub8intra: when the chroma-reference sub-block was INTRA it coded | ||
| 22995 | + // and reconstructed the group's one chroma unit itself. | ||
| 22996 | + if !intra_chroma { | ||
| 22922 | // Chroma, once for the whole group, on the last sub-block's own `skip` | 22997 | // Chroma, once for the whole group, on the last sub-block's own `skip` |
| 22923 | // flag -- prediction from all four sub-blocks (2x2 pieces), residual as | 22998 | // flag -- prediction from all four sub-blocks (2x2 pieces), residual as |
| 22924 | // one TX_4X4 unit per plane. | 22999 | // one TX_4X4 unit per plane. |
| 22925 | let mut pred_u = vec![0u16; B4 * B4]; | 23000 | let mut pred_u = vec![0u16; B4 * B4]; |
| 22926 | let mut pred_v = vec![0u16; B4 * B4]; | 23001 | let mut pred_v = vec![0u16; B4 * B4]; |
| 23002 | + // `is_sub8x8_inter` (reconinter_template.inc:54) is false as soon as ANY | ||
| 23003 | + // mi of the group is intra: the group's 4x4 chroma is then predicted WHOLE | ||
| 23004 | + // from the chroma-reference (last) sub-block's own mv, not in 2x2 pieces. | ||
| 23005 | + let mixed = piece.iter().any(Option::is_none); | ||
| 23006 | + if mixed { | ||
| 23007 | + SUB8_INTRA_RECT_HITS.with(|h| { | ||
| 23008 | + let mut st = h.get(); | ||
| 23009 | + st[3] += 1; | ||
| 23010 | + h.set(st); | ||
| 23011 | + }); | ||
| 23012 | + } | ||
| 22927 | for i in 0..4usize { | 23013 | for i in 0..4usize { |
| 22928 | let (dr, dc) = (i / 2, i % 2); | 23014 | let (dr, dc) = (i / 2, i % 2); |
| 23015 | + if mixed && i != 3 { | ||
| 23016 | + continue; | ||
| 23017 | + } | ||
| 22929 | let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else { | 23018 | let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else { |
| 22930 | continue; | 23019 | continue; |
| 22931 | }; | 23020 | }; |
| 22932 | let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?; | 23021 | let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?; |
| 22933 | - let (ox, oy) = (cpx + dc * 2, cpy + dr * 2); | 23022 | + let (ox, oy) = if mixed { |
| 23023 | + (cpx, cpy) | ||
| 23024 | + } else { | ||
| 23025 | + (cpx + dc * 2, cpy + dr * 2) | ||
| 23026 | + }; | ||
| 23027 | + let (pw, ph) = if mixed { (B4, B4) } else { (2, 2) }; | ||
| 23028 | + let (row0, col0) = if mixed { (0, 0) } else { (dr * 2, dc * 2) }; | ||
| 22934 | for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { | 23029 | for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { |
| 22935 | - let mut buf = vec![0u16; 4]; | 23030 | + let mut buf = vec![0u16; pw * ph]; |
| 22936 | mc::predict_with_filters( | 23031 | mc::predict_with_filters( |
| 22937 | &plane.data, | 23032 | &plane.data, |
| 22938 | plane.width, | 23033 | plane.width, |
| @@ -22940,15 +23035,15 @@ fn decode_inter_sub8_split4( | |||
| 22940 | plane.true_height, | 23035 | plane.true_height, |
| 22941 | mv_to_q4(ox, mv.1, false), | 23036 | mv_to_q4(ox, mv.1, false), |
| 22942 | mv_to_q4(oy, mv.0, false), | 23037 | mv_to_q4(oy, mv.0, false), |
| 22943 | - 2, | 23038 | + pw, |
| 22944 | - 2, | 23039 | + ph, |
| 22945 | h_filter, | 23040 | h_filter, |
| 22946 | v_filter, | 23041 | v_filter, |
| 22947 | &mut buf, | 23042 | &mut buf, |
| 22948 | ); | 23043 | ); |
| 22949 | - for row in 0..2 { | 23044 | + for row in 0..ph { |
| 22950 | - for col in 0..2 { | 23045 | + for col in 0..pw { |
| 22951 | - dst[(dr * 2 + row) * B4 + dc * 2 + col] = buf[row * 2 + col]; | 23046 | + dst[(row0 + row) * B4 + col0 + col] = buf[row * pw + col]; |
| 22952 | } | 23047 | } |
| 22953 | } | 23048 | } |
| 22954 | } | 23049 | } |
| @@ -22972,6 +23067,22 @@ fn decode_inter_sub8_split4( | |||
| 22972 | (ug, vg) | 23067 | (ug, vg) |
| 22973 | }; | 23068 | }; |
| 22974 | neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED); | 23069 | neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED); |
| 23070 | + let round_up_even = |n: usize| n.div_ceil(2) * 2; | ||
| 23071 | + let bound_h = round_up_even(neighbours.mi_rows); | ||
| 23072 | + let bound_w = round_up_even(neighbours.mi_cols); | ||
| 23073 | + let u_state = neighbour_state(&u_grid); | ||
| 23074 | + let v_state = neighbour_state(&v_grid); | ||
| 23075 | + for cell in 0..2usize { | ||
| 23076 | + if cell < 2usize.min(bound_h.saturating_sub(gr)) { | ||
| 23077 | + neighbours.left[gr + cell][1] = u_state; | ||
| 23078 | + neighbours.left[gr + cell][2] = v_state; | ||
| 23079 | + } | ||
| 23080 | + if cell < 2usize.min(bound_w.saturating_sub(gc)) { | ||
| 23081 | + neighbours.above[gc + cell][1] = u_state; | ||
| 23082 | + neighbours.above[gc + cell][2] = v_state; | ||
| 23083 | + } | ||
| 23084 | + } | ||
| 23085 | + } | ||
| 22975 | // Same two neighbour tails [`decode_leaf_split4`] runs: the partition | 23086 | // Same two neighbour tails [`decode_leaf_split4`] runs: the partition |
| 22976 | // context of a `BLOCK_4X4` subsize (`partition_context_lookup` bit 0 = 1, | 23087 | // context of a `BLOCK_4X4` subsize (`partition_context_lookup` bit 0 = 1, |
| 22977 | // reached by `side_mi = 4` here) and the group's chroma coefficient state. | 23088 | // reached by `side_mi = 4` here) and the group's chroma coefficient state. |
| @@ -22979,6 +23090,407 @@ fn decode_inter_sub8_split4( | |||
| 22979 | neighbours.left_side_mi[gr + cell] = 4; | 23090 | neighbours.left_side_mi[gr + cell] = 4; |
| 22980 | neighbours.above_side_mi[gc + cell] = 4; | 23091 | neighbours.above_side_mi[gc + cell] = 4; |
| 22981 | } | 23092 | } |
| 23093 | + Ok(()) | ||
| 23094 | +} | ||
| 23095 | + | ||
| 23096 | +/// One INTRA 8x4/4x8 leaf inside an INTER frame's sub-8x8 HORZ/VERT partition | ||
| 23097 | +/// (lane-sub8intra) -- the shape [`decode_inter_sub8_rect2`] refused by name. | ||
| 23098 | +/// Mode syntax is `read_intra_block_mode_info`'s (decodemv.c:1065), not the key | ||
| 23099 | +/// frame's above/left pair: `y_mode[size_group_lookup[BLOCK_8X4] == 0]`, NO | ||
| 23100 | +/// angle delta (`av1_use_angle_delta` needs `bsize >= BLOCK_8X8`), `uv_mode` + | ||
| 23101 | +/// CfL alphas only on the chroma-reference sub-block (`is_chroma_reference`: | ||
| 23102 | +/// the SECOND one under 4:2:0), then `filter_intra` off BLOCK_8X4/BLOCK_4X8's | ||
| 23103 | +/// own class row (`av1_filter_intra_allowed_bsize` is `wide <= 32 && high <= | ||
| 23104 | +/// 32`, so this shape is allowed). Everything below the mode read -- the tx | ||
| 23105 | +/// depth symbol, the whole-leaf `TX_8X4`/`TX_4X8` or split `TX_4X4` walk, the | ||
| 23106 | +/// 4x4 chroma unit at the group's origin -- is [`decode_leaf_rect8`]'s body for | ||
| 23107 | +/// the same shape; the INTER-frame differences are the tx-depth context | ||
| 23108 | +/// (`above_txfm`/`left_txfm`, not the key frame's deblock-grid approximation), | ||
| 23109 | +/// `set_txfm_ctxs` publication, and the inter-side bands + mi map the caller's | ||
| 23110 | +/// inter leaves also write (`is_inter = 0`, ref `INTRA_FRAME`, no interp | ||
| 23111 | +/// filter). | ||
| 23112 | +#[allow(clippy::too_many_arguments)] | ||
| 23113 | +fn decode_intra_sub8_leaf( | ||
| 23114 | + dec: &mut SymbolDecoder, | ||
| 23115 | + cdfs: &mut Cdfs, | ||
| 23116 | + neighbours: &mut Neighbours, | ||
| 23117 | + grid: &mut MiGrid, | ||
| 23118 | + group_mi: (usize, usize), | ||
| 23119 | + lmi: (usize, usize), | ||
| 23120 | + // `(bw, bh)`: 8x4 / 4x8 under HORZ/VERT, 4x4 under SPLIT. | ||
| 23121 | + (bw, bh): (usize, usize), | ||
| 23122 | + has_chroma: bool, | ||
| 23123 | + skip: bool, | ||
| 23124 | + scan4: &[u16], | ||
| 23125 | + y: &mut PlaneBuf, | ||
| 23126 | + u: &mut PlaneBuf, | ||
| 23127 | + v: &mut PlaneBuf, | ||
| 23128 | + base_q_idx: u8, | ||
| 23129 | + enable_filter_intra: bool, | ||
| 23130 | + tx_select: bool, | ||
| 23131 | + reduced_tx_set: bool, | ||
| 23132 | +) -> Result<usize> { | ||
| 23133 | + let vert = bw < bh; | ||
| 23134 | + let (w_mi, h_mi) = (bw / MI, bh / MI); | ||
| 23135 | + let (gr, gc) = group_mi; | ||
| 23136 | + let (r, c) = (gr / (SUB / MI), gc / (SUB / MI)); | ||
| 23137 | + let (above_mode, left_mode) = neighbours.modes_above_left(r, c); | ||
| 23138 | + let leaf_above = neighbours | ||
| 23139 | + .mode_above_mi(lmi.0, lmi.1) | ||
| 23140 | + .unwrap_or(above_mode); | ||
| 23141 | + let leaf_left = neighbours.mode_left_mi(lmi.0, lmi.1).unwrap_or(left_mode); | ||
| 23142 | + let step = std::env::var_os("EC_TRACE_MODE_STEP").is_some(); | ||
| 23143 | + // `size_group_lookup[BLOCK_8X4] == size_group_lookup[BLOCK_4X8] == 0` | ||
| 23144 | + // (libaom common_data.h:61). | ||
| 23145 | + let mode = dec.symbol(&mut cdfs.y_mode[0]); | ||
| 23146 | + if step { | ||
| 23147 | + eprintln!( | ||
| 23148 | + "EC_ISTEP mi_row={} mi_col={} name=mode val={mode} rng={}", | ||
| 23149 | + lmi.0, | ||
| 23150 | + lmi.1, | ||
| 23151 | + dec.debug_state().0 | ||
| 23152 | + ); | ||
| 23153 | + } | ||
| 23154 | + // No angle delta below 8x8 (`av1_use_angle_delta`), for luma or chroma. | ||
| 23155 | + let angle_delta_y = 0; | ||
| 23156 | + let (uv_mode, alpha) = if has_chroma { | ||
| 23157 | + // `is_cfl_allowed` is `wide <= 32 && high <= 32` -- true for this | ||
| 23158 | + // shape, so the 14-symbol CFL alphabet is the right one. | ||
| 23159 | + let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]); | ||
| 23160 | + if (9..=12).contains(&uv_mode) { | ||
| 23161 | + SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23162 | + } | ||
| 23163 | + let alpha = if uv_mode == UV_CFL_PRED { | ||
| 23164 | + Some(read_cfl_alphas(dec, cdfs)) | ||
| 23165 | + } else { | ||
| 23166 | + None | ||
| 23167 | + }; | ||
| 23168 | + if (V_PRED..=D67_PRED).contains(&uv_mode) { | ||
| 23169 | + DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23170 | + } | ||
| 23171 | + (uv_mode, alpha) | ||
| 23172 | + } else { | ||
| 23173 | + (DC_PRED, None) | ||
| 23174 | + }; | ||
| 23175 | + let mut filter_intra = None; | ||
| 23176 | + if mode == DC_PRED && enable_filter_intra { | ||
| 23177 | + let fi_class = if bw == bh { | ||
| 23178 | + filter_intra_size_class(bw).expect("BLOCK_4X4 has its own filter_intra row") | ||
| 23179 | + } else { | ||
| 23180 | + filter_intra_size_class_rect(bw, bh) | ||
| 23181 | + .expect("BLOCK_4X8/BLOCK_8X4 are inside av1_filter_intra_allowed_bsize") | ||
| 23182 | + }; | ||
| 23183 | + let use_fi = dec.symbol(&mut cdfs.filter_intra[fi_class]); | ||
| 23184 | + if step { | ||
| 23185 | + eprintln!( | ||
| 23186 | + "EC_ISTEP mi_row={} mi_col={} name=use_filter_intra val={use_fi} rng={}", | ||
| 23187 | + lmi.0, | ||
| 23188 | + lmi.1, | ||
| 23189 | + dec.debug_state().0 | ||
| 23190 | + ); | ||
| 23191 | + } | ||
| 23192 | + if use_fi != 0 { | ||
| 23193 | + FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23194 | + FILTER_INTRA_RECT_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23195 | + FILTER_INTRA_RECT_SUB8_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23196 | + let fi = dec.symbol(&mut cdfs.filter_intra_mode); | ||
| 23197 | + if step { | ||
| 23198 | + eprintln!( | ||
| 23199 | + "EC_ISTEP mi_row={} mi_col={} name=filter_intra_mode val={fi} rng={}", | ||
| 23200 | + lmi.0, | ||
| 23201 | + lmi.1, | ||
| 23202 | + dec.debug_state().0 | ||
| 23203 | + ); | ||
| 23204 | + } | ||
| 23205 | + filter_intra = Some(fi); | ||
| 23206 | + } | ||
| 23207 | + } | ||
| 23208 | + // `read_block_tx_size`' non-var-tx arm: an INTRA block of an inter frame | ||
| 23209 | + // reads `read_tx_size(allow_select = 1)` -- `bsize_to_tx_size_cat | ||
| 23210 | + // (BLOCK_4X8) == 0` (blockd.h:1344, depth table entry 1), the same | ||
| 23211 | + // 2-symbol category [`decode_leaf_rect8`] reads -- with the var-tx | ||
| 23212 | + // context bands, which on an inter frame are live. | ||
| 23213 | + // `block_signals_txsize(BLOCK_4X4)` is false (blockd.h:1027): the 4x4 leaf | ||
| 23214 | + // codes no depth symbol at all, its transform is its own size. | ||
| 23215 | + let depth = if tx_select && bw != bh { | ||
| 23216 | + let ctx = tx_size_context_txfm_rect(neighbours, lmi, bw, bh); | ||
| 23217 | + let d = dec.symbol(&mut cdfs.tx_size_cat0[ctx]); | ||
| 23218 | + if step { | ||
| 23219 | + eprintln!( | ||
| 23220 | + "EC_ISTEP mi_row={} mi_col={} name=tx_depth val={d} ctx={ctx} cat=0 rng={}", | ||
| 23221 | + lmi.0, | ||
| 23222 | + lmi.1, | ||
| 23223 | + dec.debug_state().0 | ||
| 23224 | + ); | ||
| 23225 | + } | ||
| 23226 | + d | ||
| 23227 | + } else { | ||
| 23228 | + 0 | ||
| 23229 | + }; | ||
| 23230 | + if depth != 0 { | ||
| 23231 | + TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23232 | + RECT8_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23233 | + } | ||
| 23234 | + let split = depth != 0; | ||
| 23235 | + let (px, py) = (lmi.1 * MI, lmi.0 * MI); | ||
| 23236 | + let reach = if bw == bh { | ||
| 23237 | + Reach::of(bw, px, py, y.width, y.height) | ||
| 23238 | + } else { | ||
| 23239 | + Reach::of_rect(bw, bh, px, py, y.width, y.height) | ||
| 23240 | + }; | ||
| 23241 | + let smooth_neighbor = is_smooth_mode(leaf_above) || is_smooth_mode(leaf_left); | ||
| 23242 | + if smooth_neighbor { | ||
| 23243 | + SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23244 | + } | ||
| 23245 | + neighbours.record_mode_mi(lmi.0, lmi.1, w_mi, h_mi, mode); | ||
| 23246 | + let scan: &[u16] = if vert { &SCAN_4X8 } else { &SCAN_8X4 }; | ||
| 23247 | + if split { | ||
| 23248 | + // `sub_tx_size_map[TX_4X8] == TX_4X4`: two 4x4 units along the long | ||
| 23249 | + // axis, each predicted off the previous one's reconstruction. | ||
| 23250 | + for tu in 0..2usize { | ||
| 23251 | + let tu_mi = if vert { | ||
| 23252 | + (lmi.0 + tu, lmi.1) | ||
| 23253 | + } else { | ||
| 23254 | + (lmi.0, lmi.1 + tu) | ||
| 23255 | + }; | ||
| 23256 | + let (tu_px, tu_py) = (tu_mi.1 * MI, tu_mi.0 * MI); | ||
| 23257 | + let tu_reach = tu_reach( | ||
| 23258 | + bw, | ||
| 23259 | + bh, | ||
| 23260 | + tu_px - px, | ||
| 23261 | + tu_py - py, | ||
| 23262 | + 4, | ||
| 23263 | + reach, | ||
| 23264 | + px, | ||
| 23265 | + py, | ||
| 23266 | + y.width, | ||
| 23267 | + y.height, | ||
| 23268 | + ); | ||
| 23269 | + if skip { | ||
| 23270 | + let zeros = vec![0i32; 16]; | ||
| 23271 | + y.reconstruct( | ||
| 23272 | + tu_px, tu_py, 4, mode, angle_delta_y, tu_reach, &zeros, None, filter_intra, | ||
| 23273 | + smooth_neighbor, | ||
| 23274 | + ); | ||
| 23275 | + neighbours.record_mi_luma(tu_mi, 4, &zeros); | ||
| 23276 | + continue; | ||
| 23277 | + } | ||
| 23278 | + let tu_around = neighbours.around_mi(tu_mi, 4)[0]; | ||
| 23279 | + let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, 1); | ||
| 23280 | + let tu_grid = read_plane( | ||
| 23281 | + dec, | ||
| 23282 | + cdfs, | ||
| 23283 | + if reduced_tx_set { | ||
| 23284 | + TxbSet::Luma4 | ||
| 23285 | + } else { | ||
| 23286 | + TxbSet::Luma4Set1 | ||
| 23287 | + }, | ||
| 23288 | + scan4, | ||
| 23289 | + 0, | ||
| 23290 | + tu_around, | ||
| 23291 | + mode, | ||
| 23292 | + mode, | ||
| 23293 | + angle_delta_y, | ||
| 23294 | + tu_reach, | ||
| 23295 | + y, | ||
| 23296 | + tu_px, | ||
| 23297 | + tu_py, | ||
| 23298 | + 4, | ||
| 23299 | + TX4, | ||
| 23300 | + base_q_idx, | ||
| 23301 | + None, | ||
| 23302 | + filter_intra, | ||
| 23303 | + Some(tu_skip_ctx), | ||
| 23304 | + smooth_neighbor, | ||
| 23305 | + )?; | ||
| 23306 | + neighbours.record_mi_luma(tu_mi, 4, &tu_grid); | ||
| 23307 | + } | ||
| 23308 | + } else if bw == bh { | ||
| 23309 | + // A `BLOCK_4X4` leaf's luma TU *is* the whole block, so `get_txb_ctx` | ||
| 23310 | + // fixes `txb_skip_ctx` at 0 (`luma_skip_ctx: None`) -- the same square | ||
| 23311 | + // reader [`decode_leaf_split4`] uses. | ||
| 23312 | + if skip { | ||
| 23313 | + y.reconstruct( | ||
| 23314 | + px, py, 4, mode, angle_delta_y, reach, &vec![0i32; 16], None, filter_intra, | ||
| 23315 | + smooth_neighbor, | ||
| 23316 | + ); | ||
| 23317 | + neighbours.record_mi_luma(lmi, 4, &vec![0i32; 16]); | ||
| 23318 | + } else { | ||
| 23319 | + let tu_around = neighbours.around_mi(lmi, 4)[0]; | ||
| 23320 | + let tu_grid = read_plane( | ||
| 23321 | + dec, | ||
| 23322 | + cdfs, | ||
| 23323 | + if reduced_tx_set { | ||
| 23324 | + TxbSet::Luma4 | ||
| 23325 | + } else { | ||
| 23326 | + TxbSet::Luma4Set1 | ||
| 23327 | + }, | ||
| 23328 | + scan4, | ||
| 23329 | + 0, | ||
| 23330 | + tu_around, | ||
| 23331 | + mode, | ||
| 23332 | + mode, | ||
| 23333 | + angle_delta_y, | ||
| 23334 | + reach, | ||
| 23335 | + y, | ||
| 23336 | + px, | ||
| 23337 | + py, | ||
| 23338 | + 4, | ||
| 23339 | + TX4, | ||
| 23340 | + base_q_idx, | ||
| 23341 | + None, | ||
| 23342 | + filter_intra, | ||
| 23343 | + None, | ||
| 23344 | + smooth_neighbor, | ||
| 23345 | + )?; | ||
| 23346 | + neighbours.record_mi_luma(lmi, 4, &tu_grid); | ||
| 23347 | + } | ||
| 23348 | + } else { | ||
| 23349 | + let grid_levels = if skip { | ||
| 23350 | + let zeros = vec![0i32; bw * bh]; | ||
| 23351 | + y.reconstruct_rect( | ||
| 23352 | + px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra, | ||
| 23353 | + smooth_neighbor, | ||
| 23354 | + ); | ||
| 23355 | + zeros | ||
| 23356 | + } else { | ||
| 23357 | + // The leaf's luma TU *is* the leaf, so `get_txb_ctx` fixes | ||
| 23358 | + // `txb_skip_ctx` at 0. | ||
| 23359 | + let around = neighbours.around_mi_rect(lmi, bw, bh)[0]; | ||
| 23360 | + let set = if reduced_tx_set { | ||
| 23361 | + TxbSet::LumaRect4x8 | ||
| 23362 | + } else { | ||
| 23363 | + TxbSet::LumaRect4x8Set1 | ||
| 23364 | + }; | ||
| 23365 | + let mut coding = cdfs.txb(set, fi_tx_row(mode, filter_intra)); | ||
| 23366 | + let (levels, tx_type) = read_coeffs_rect( | ||
| 23367 | + dec, | ||
| 23368 | + &mut coding, | ||
| 23369 | + scan, | ||
| 23370 | + bw, | ||
| 23371 | + bh, | ||
| 23372 | + 0, | ||
| 23373 | + dc_sign_ctx(around.2), | ||
| 23374 | + TxType::DctDct, | ||
| 23375 | + )?; | ||
| 23376 | + let residual = dequant_and_inverse_typed_wh( | ||
| 23377 | + &levels, | ||
| 23378 | + bw, | ||
| 23379 | + bh, | ||
| 23380 | + crate::decode::bit_depth(), | ||
| 23381 | + CURRENT_Q_IDX.with(|q| q.get()), | ||
| 23382 | + plane_q_delta(0).0, | ||
| 23383 | + plane_q_delta(0).1, | ||
| 23384 | + tx_type, | ||
| 23385 | + ); | ||
| 23386 | + y.reconstruct_rect( | ||
| 23387 | + px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra, | ||
| 23388 | + smooth_neighbor, | ||
| 23389 | + ); | ||
| 23390 | + levels | ||
| 23391 | + }; | ||
| 23392 | + let state = neighbour_state(&grid_levels); | ||
| 23393 | + for cell in 0..h_mi { | ||
| 23394 | + if lmi.0 + cell < neighbours.mi_rows { | ||
| 23395 | + neighbours.left[lmi.0 + cell][0] = state; | ||
| 23396 | + } | ||
| 23397 | + } | ||
| 23398 | + for cell in 0..w_mi { | ||
| 23399 | + if lmi.1 + cell < neighbours.mi_cols { | ||
| 23400 | + neighbours.above[lmi.1 + cell][0] = state; | ||
| 23401 | + } | ||
| 23402 | + } | ||
| 23403 | + } | ||
| 23404 | + let (tx_w, tx_h) = if split { (4, 4) } else { (bw, bh) }; | ||
| 23405 | + neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip); | ||
| 23406 | + neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, tx_w as u8, tx_h as u8, 0); | ||
| 23407 | + // `set_txfm_ctxs(tx_size, n4_w, n4_h, skip && is_inter == 0, xd)`: an | ||
| 23408 | + // intra block of an inter frame publishes its TRANSFORM dims, never its | ||
| 23409 | + // block dims (blockd.h). Missing this left the next block reading the | ||
| 23410 | + // previous block's band (the lane-intra16x4 finding for the 16x4 strip). | ||
| 23411 | + for i in 0..w_mi { | ||
| 23412 | + if let Some(cell) = neighbours.above_txfm.get_mut(lmi.1 + i) { | ||
| 23413 | + *cell = tx_w as u8; | ||
| 23414 | + } | ||
| 23415 | + } | ||
| 23416 | + for i in 0..h_mi { | ||
| 23417 | + if let Some(cell) = neighbours.left_txfm.get_mut(lmi.0 + i) { | ||
| 23418 | + *cell = tx_h as u8; | ||
| 23419 | + } | ||
| 23420 | + } | ||
| 23421 | + neighbours.above_mode[c] = mode; | ||
| 23422 | + neighbours.left_mode[r] = mode; | ||
| 23423 | + // The inter-side bands and the mi map, exactly as the square | ||
| 23424 | + // intra-in-inter block writes them: `is_inter = 0`, `INTRA_FRAME` ref, no | ||
| 23425 | + // interpolation filter, no skip mode. | ||
| 23426 | + neighbours.record_inter_rect_mi(lmi, w_mi, h_mi, skip, false, 0, [3, 3], false); | ||
| 23427 | + for dr in 0..h_mi { | ||
| 23428 | + for dc in 0..w_mi { | ||
| 23429 | + grid.set( | ||
| 23430 | + lmi.0 + dr, | ||
| 23431 | + lmi.1 + dc, | ||
| 23432 | + MiInfo { | ||
| 23433 | + is_inter: false, | ||
| 23434 | + ref_frame: -1, | ||
| 23435 | + ref_frame1: None, | ||
| 23436 | + mv1: None, | ||
| 23437 | + mv: (0, 0), | ||
| 23438 | + is_new_mv: false, | ||
| 23439 | + size: w_mi, | ||
| 23440 | + size_h: h_mi, | ||
| 23441 | + is_global_mv0: false, | ||
| 23442 | + is_global_mv1: false, | ||
| 23443 | + }, | ||
| 23444 | + ); | ||
| 23445 | + } | ||
| 23446 | + } | ||
| 23447 | + SUB8_INTRA_RECT_HITS.with(|h| { | ||
| 23448 | + let mut s = h.get(); | ||
| 23449 | + s[usize::from(vert)] += 1; | ||
| 23450 | + s[2] += usize::from(has_chroma); | ||
| 23451 | + h.set(s); | ||
| 23452 | + }); | ||
| 23453 | + if !has_chroma { | ||
| 23454 | + return Ok(mode); | ||
| 23455 | + } | ||
| 23456 | + // The group's single 4x4 chroma unit, intra-predicted from THIS | ||
| 23457 | + // (chroma-reference) sub-block's own `uv_mode` -- `is_sub8x8_inter` | ||
| 23458 | + // (reconinter_template.inc:54) returns false as soon as any mi of the | ||
| 23459 | + // group is intra, and the decoder reconstructs chroma with the | ||
| 23460 | + // chroma-reference block's own type. Same body as [`decode_leaf_rect8`]'s | ||
| 23461 | + // post-loop chroma. | ||
| 23462 | + let (gpx, gpy) = (gc * MI, gr * MI); | ||
| 23463 | + let (cpx, cpy) = (gpx / 2, gpy / 2); | ||
| 23464 | + let group_reach = Reach::of(8, gpx, gpy, y.width, y.height); | ||
| 23465 | + let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(gr, gc, r, c); | ||
| 23466 | + let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; | ||
| 23467 | + let angle_delta_uv = 0; | ||
| 23468 | + neighbours.above_uv_mode[c] = uv_predict_mode; | ||
| 23469 | + neighbours.left_uv_mode[r] = uv_predict_mode; | ||
| 23470 | + neighbours.record_uv_mode_mi(gr, gc, 2, 2, uv_predict_mode); | ||
| 23471 | + let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8)); | ||
| 23472 | + let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if skip { | ||
| 23473 | + if alpha.is_some() { | ||
| 23474 | + CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1)); | ||
| 23475 | + SKIP_CFL_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23476 | + } | ||
| 23477 | + u.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv); | ||
| 23478 | + v.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv); | ||
| 23479 | + (vec![0i32; 16], vec![0i32; 16]) | ||
| 23480 | + } else { | ||
| 23481 | + let chroma_around = neighbours.around_mi(group_mi, 8); | ||
| 23482 | + let ug = read_plane( | ||
| 23483 | + dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode, | ||
| 23484 | + angle_delta_uv, group_reach, u, cpx, cpy, 4, TX4, base_q_idx, | ||
| 23485 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, | ||
| 23486 | + )?; | ||
| 23487 | + let vg = read_plane( | ||
| 23488 | + dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode, | ||
| 23489 | + angle_delta_uv, group_reach, v, cpx, cpy, 4, TX4, base_q_idx, | ||
| 23490 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, | ||
| 23491 | + )?; | ||
| 23492 | + (ug, vg) | ||
| 23493 | + }; | ||
| 22982 | let round_up_even = |n: usize| n.div_ceil(2) * 2; | 23494 | let round_up_even = |n: usize| n.div_ceil(2) * 2; |
| 22983 | let bound_h = round_up_even(neighbours.mi_rows); | 23495 | let bound_h = round_up_even(neighbours.mi_rows); |
| 22984 | let bound_w = round_up_even(neighbours.mi_cols); | 23496 | let bound_w = round_up_even(neighbours.mi_cols); |
| @@ -22994,7 +23506,7 @@ fn decode_inter_sub8_split4( | |||
| 22994 | neighbours.above[gc + cell][2] = v_state; | 23506 | neighbours.above[gc + cell][2] = v_state; |
| 22995 | } | 23507 | } |
| 22996 | } | 23508 | } |
| 22997 | - Ok(()) | 23509 | + Ok(mode) |
| 22998 | } | 23510 | } |
| 22999 | 23511 | ||
| 23000 | /// Decodes a `PARTITION_HORZ`/`PARTITION_VERT` of one 8x8 INTER block into two | 23512 | /// Decodes a `PARTITION_HORZ`/`PARTITION_VERT` of one 8x8 INTER block into two |
| @@ -23084,11 +23596,34 @@ fn decode_inter_sub8_rect2( | |||
| 23084 | [None; 2]; | 23596 | [None; 2]; |
| 23085 | let mut first_tx_type = TxType::DctDct; | 23597 | let mut first_tx_type = TxType::DctDct; |
| 23086 | let mut last_skip = true; | 23598 | let mut last_skip = true; |
| 23599 | + // Set when the chroma-reference sub-block is INTRA: it coded the group's | ||
| 23600 | + // one chroma unit itself. | ||
| 23601 | + let mut intra_chroma = false; | ||
| 23087 | for i in 0..2usize { | 23602 | for i in 0..2usize { |
| 23088 | let lmi = if vert { (gr, gc + i) } else { (gr + i, gc) }; | 23603 | let lmi = if vert { (gr, gc + i) } else { (gr + i, gc) }; |
| 23089 | if lmi.0 >= mi_rows as usize || lmi.1 >= mi_cols as usize { | 23604 | if lmi.0 >= mi_rows as usize || lmi.1 >= mi_cols as usize { |
| 23090 | continue; | 23605 | continue; |
| 23091 | } | 23606 | } |
| 23607 | + // libaom's `xd->above_mbmi`/`xd->left_mbmi` are the neighbour block as | ||
| 23608 | + // DECODED, so leaf 1 sees leaf 0's own `bsize` -- the group tail below | ||
| 23609 | + // publishes the side bands only once both leaves are done, which left | ||
| 23610 | + // leaf 1 reading whatever block preceded the GROUP. `get_tx_size_context` | ||
| 23611 | + // (pred_common.h:342) takes `block_size_wide[above_mbmi->bsize]` from it, | ||
| 23612 | + // so an intra 8x4 leaf 1 read `tx_size_cat0` row 1 where aomdec reads | ||
| 23613 | + // row 2 (class tx-grid-published-block-side). | ||
| 23614 | + if i == 1 { | ||
| 23615 | + if vert { | ||
| 23616 | + for cell in 0..h_mi { | ||
| 23617 | + neighbours.left_side_mi[gr + cell] = bh; | ||
| 23618 | + } | ||
| 23619 | + neighbours.above_side_mi[gc] = bw; | ||
| 23620 | + } else { | ||
| 23621 | + for cell in 0..w_mi { | ||
| 23622 | + neighbours.above_side_mi[gc + cell] = bw; | ||
| 23623 | + } | ||
| 23624 | + neighbours.left_side_mi[gr] = bh; | ||
| 23625 | + } | ||
| 23626 | + } | ||
| 23092 | let (rmi, cmi) = lmi; | 23627 | let (rmi, cmi) = lmi; |
| 23093 | let (px, py) = (cmi * MI, rmi * MI); | 23628 | let (px, py) = (cmi * MI, rmi * MI); |
| 23094 | inter_segment_id(dec, cdfs, rmi, cmi, w_mi, h_mi, false, true); | 23629 | inter_segment_id(dec, cdfs, rmi, cmi, w_mi, h_mi, false, true); |
| @@ -23111,11 +23646,54 @@ fn decode_inter_sub8_rect2( | |||
| 23111 | ); | 23646 | ); |
| 23112 | let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; | 23647 | let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; |
| 23113 | if !is_inter { | 23648 | if !is_inter { |
| 23649 | + if std::env::var_os("EC_SUB8INTRA").is_some() { | ||
| 23650 | + eprintln!( | ||
| 23651 | + "EC_SUB8INTRA shape={}x{} sub={i} has_chroma={} skip={skip} mi={rmi},{cmi} tx_select={}", | ||
| 23652 | + bw, | ||
| 23653 | + bh, | ||
| 23654 | + i == 1, | ||
| 23655 | + TX_SELECT_INTER.with(std::cell::Cell::get), | ||
| 23656 | + ); | ||
| 23657 | + } | ||
| 23658 | + // lane-sub8intra: the leaf decodes ([`decode_intra_sub8_leaf`]) | ||
| 23659 | + // only under `EC_SUB8INTRA_DECODE` -- the r1 gate is RED (a | ||
| 23660 | + // 128x128 8-bit witness desyncs a few blocks later), so the | ||
| 23661 | + // refusal stays the default behaviour (class | ||
| 23662 | + // `refusal-lifted-without-a-gate`). | ||
| 23663 | + if std::env::var_os("EC_SUB8INTRA_DECODE").is_none() { | ||
| 23114 | return Err(unsupported( | 23664 | return Err(unsupported( |
| 23115 | "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition \ | 23665 | "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition \ |
| 23116 | (this decoder codes only inter sub-blocks there)", | 23666 | (this decoder codes only inter sub-blocks there)", |
| 23117 | )); | 23667 | )); |
| 23118 | } | 23668 | } |
| 23669 | + // Its chroma rule is `is_sub8x8_inter`'s: when the | ||
| 23670 | + // chroma-reference (second) sub-block is the intra one, the | ||
| 23671 | + // group's 4x4 chroma is coded and predicted INTRA there and the | ||
| 23672 | + // inter chroma tail below is skipped entirely. | ||
| 23673 | + decode_intra_sub8_leaf( | ||
| 23674 | + dec, | ||
| 23675 | + cdfs, | ||
| 23676 | + neighbours, | ||
| 23677 | + grid, | ||
| 23678 | + group_mi, | ||
| 23679 | + lmi, | ||
| 23680 | + (bw, bh), | ||
| 23681 | + i == 1, | ||
| 23682 | + skip, | ||
| 23683 | + scan4, | ||
| 23684 | + y, | ||
| 23685 | + u, | ||
| 23686 | + v, | ||
| 23687 | + base_q_idx, | ||
| 23688 | + ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get), | ||
| 23689 | + TX_SELECT_INTER.with(std::cell::Cell::get), | ||
| 23690 | + reduced_tx_set, | ||
| 23691 | + )?; | ||
| 23692 | + if i == 1 { | ||
| 23693 | + intra_chroma = true; | ||
| 23694 | + } | ||
| 23695 | + continue; | ||
| 23696 | + } | ||
| 23119 | if std::env::var_os("EC_TRACE_MODE").is_some() { | 23697 | if std::env::var_os("EC_TRACE_MODE").is_some() { |
| 23120 | eprintln!( | 23698 | eprintln!( |
| 23121 | "EC_MODE mi_row={rmi} mi_col={cmi} rng={}", | 23699 | "EC_MODE mi_row={rmi} mi_col={cmi} rng={}", |
| @@ -23374,10 +23952,13 @@ fn decode_inter_sub8_rect2( | |||
| 23374 | None, | 23952 | None, |
| 23375 | )? | 23953 | )? |
| 23376 | }; | 23954 | }; |
| 23377 | - if idx == 0 { | 23955 | + if idx == 0 && (i == 0 || piece[0].is_none()) { |
| 23378 | // `av1_get_tx_type`: the group's one chroma unit scales | 23956 | // `av1_get_tx_type`: the group's one chroma unit scales |
| 23379 | // back to luma (0, 0), i.e. the FIRST sub-block's first | 23957 | // back to luma (0, 0), i.e. the FIRST sub-block's first |
| 23380 | - // transform unit. | 23958 | + // transform unit -- unless that sub-block is INTRA |
| 23959 | + // (lane-sub8intra), in which case it wrote no inter | ||
| 23960 | + // tx_type at all and `xd->tx_type_map[0]` of the | ||
| 23961 | + // chroma-reference block is this one's. | ||
| 23381 | first_tx_type = tu_tx_type; | 23962 | first_tx_type = tu_tx_type; |
| 23382 | } | 23963 | } |
| 23383 | neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid); | 23964 | neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid); |
| @@ -23397,23 +23978,52 @@ fn decode_inter_sub8_rect2( | |||
| 23397 | neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip); | 23978 | neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip); |
| 23398 | last_skip = skip; | 23979 | last_skip = skip; |
| 23399 | } | 23980 | } |
| 23981 | + // lane-sub8intra: when the chroma-reference sub-block was INTRA it coded | ||
| 23982 | + // and reconstructed the group's one chroma unit itself. | ||
| 23983 | + if !intra_chroma { | ||
| 23400 | // The group's single 4x4 chroma unit per plane, on the chroma-reference | 23984 | // The group's single 4x4 chroma unit per plane, on the chroma-reference |
| 23401 | // (second) sub-block's own skip flag. | 23985 | // (second) sub-block's own skip flag. |
| 23402 | const B4: usize = 4; | 23986 | const B4: usize = 4; |
| 23403 | let mut pred_u = vec![0u16; B4 * B4]; | 23987 | let mut pred_u = vec![0u16; B4 * B4]; |
| 23404 | let mut pred_v = vec![0u16; B4 * B4]; | 23988 | let mut pred_v = vec![0u16; B4 * B4]; |
| 23405 | - let (piece_w, piece_h) = if vert { (2usize, 4usize) } else { (4usize, 2usize) }; | 23989 | + // `is_sub8x8_inter` (reconinter_template.inc:54) is false as soon as ANY |
| 23990 | + // mi of the group is intra, so a group whose chroma reference is inter but | ||
| 23991 | + // whose sibling is INTRA does NOT get the two-piece sub8x8 prediction: the | ||
| 23992 | + // ordinary 8x8-and-bigger path predicts the WHOLE 4x4 chroma unit from the | ||
| 23993 | + // chroma-reference block's own mv, at the group's chroma origin | ||
| 23994 | + // (`row_start`/`col_start` shift `pre_x`/`pre_y` there either way). | ||
| 23995 | + let mixed = piece[0].is_none(); | ||
| 23996 | + if mixed { | ||
| 23997 | + SUB8_INTRA_RECT_HITS.with(|h| { | ||
| 23998 | + let mut s = h.get(); | ||
| 23999 | + s[3] += 1; | ||
| 24000 | + h.set(s); | ||
| 24001 | + }); | ||
| 24002 | + } | ||
| 24003 | + let (piece_w, piece_h) = match (mixed, vert) { | ||
| 24004 | + (true, _) => (B4, B4), | ||
| 24005 | + (false, true) => (2usize, 4usize), | ||
| 24006 | + (false, false) => (4usize, 2usize), | ||
| 24007 | + }; | ||
| 23406 | for i in 0..2usize { | 24008 | for i in 0..2usize { |
| 23407 | let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else { | 24009 | let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else { |
| 23408 | continue; | 24010 | continue; |
| 23409 | }; | 24011 | }; |
| 23410 | let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?; | 24012 | let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?; |
| 23411 | - let (ox, oy) = if vert { | 24013 | + let (ox, oy) = if mixed { |
| 24014 | + (cpx, cpy) | ||
| 24015 | + } else if vert { | ||
| 23412 | (cpx + i * piece_w, cpy) | 24016 | (cpx + i * piece_w, cpy) |
| 23413 | } else { | 24017 | } else { |
| 23414 | (cpx, cpy + i * piece_h) | 24018 | (cpx, cpy + i * piece_h) |
| 23415 | }; | 24019 | }; |
| 23416 | - let (dc, dr) = if vert { (i * piece_w, 0) } else { (0, i * piece_h) }; | 24020 | + let (dc, dr) = if mixed { |
| 24021 | + (0, 0) | ||
| 24022 | + } else if vert { | ||
| 24023 | + (i * piece_w, 0) | ||
| 24024 | + } else { | ||
| 24025 | + (0, i * piece_h) | ||
| 24026 | + }; | ||
| 23417 | for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { | 24027 | for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { |
| 23418 | let mut buf = vec![0u16; piece_w * piece_h]; | 24028 | let mut buf = vec![0u16; piece_w * piece_h]; |
| 23419 | mc::predict_with_filters( | 24029 | mc::predict_with_filters( |
| @@ -23455,13 +24065,6 @@ fn decode_inter_sub8_rect2( | |||
| 23455 | (ug, vg) | 24065 | (ug, vg) |
| 23456 | }; | 24066 | }; |
| 23457 | neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED); | 24067 | neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED); |
| 23458 | - // `update_partition_context` writes `partition_context_lookup[subsize]` | ||
| 23459 | - // over the whole 8x8 span -- BLOCK_4X8's width above and height left, the | ||
| 23460 | - // same values [`decode_leaf_rect8`] writes for the intra shape. | ||
| 23461 | - for cell in 0..2usize { | ||
| 23462 | - neighbours.above_side_mi[gc + cell] = bw; | ||
| 23463 | - neighbours.left_side_mi[gr + cell] = bh; | ||
| 23464 | - } | ||
| 23465 | let round_up_even = |n: usize| n.div_ceil(2) * 2; | 24068 | let round_up_even = |n: usize| n.div_ceil(2) * 2; |
| 23466 | let bound_h = round_up_even(neighbours.mi_rows); | 24069 | let bound_h = round_up_even(neighbours.mi_rows); |
| 23467 | let bound_w = round_up_even(neighbours.mi_cols); | 24070 | let bound_w = round_up_even(neighbours.mi_cols); |
| @@ -23477,6 +24080,14 @@ fn decode_inter_sub8_rect2( | |||
| 23477 | neighbours.above[gc + cell][2] = v_state; | 24080 | neighbours.above[gc + cell][2] = v_state; |
| 23478 | } | 24081 | } |
| 23479 | } | 24082 | } |
| 24083 | + } | ||
| 24084 | + // `update_partition_context` writes `partition_context_lookup[subsize]` | ||
| 24085 | + // over the whole 8x8 span -- BLOCK_4X8's width above and height left, the | ||
| 24086 | + // same values [`decode_leaf_rect8`] writes for the intra shape. | ||
| 24087 | + for cell in 0..2usize { | ||
| 24088 | + neighbours.above_side_mi[gc + cell] = bw; | ||
| 24089 | + neighbours.left_side_mi[gr + cell] = bh; | ||
| 24090 | + } | ||
| 23480 | Ok(()) | 24091 | Ok(()) |
| 23481 | } | 24092 | } |
| 23482 | 24093 | ||
crates/ec-av1/src/stream.rsmodified+6 -0
| @@ -86,6 +86,12 @@ pub fn intra16x4_in_inter_hits() -> (usize, usize, usize) { | |||
| 86 | crate::decode::intra16x4_in_inter_hits() | 86 | crate::decode::intra16x4_in_inter_hits() |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | +/// lane-sub8intra: INTRA 8x4/4x8 leaves inside an inter frame's sub-8x8 | ||
| 90 | +/// HORZ/VERT partition, `(8x4, 4x8, chroma-reference, mixed groups)`. | ||
| 91 | +pub fn sub8_intra_rect_hits() -> (usize, usize, usize, usize) { | ||
| 92 | + crate::decode::sub8_intra_rect_hits() | ||
| 93 | +} | ||
| 94 | + | ||
| 89 | /// lane-r14 r3: RECTANGULAR var-tx leaf transform units, `[32x16, 16x32]` -- | 95 | /// lane-r14 r3: RECTANGULAR var-tx leaf transform units, `[32x16, 16x32]` -- |
| 90 | /// the leaves `sub_tx_size_map` produces when a 1:4 strip with a 64-px axis | 96 | /// the leaves `sub_tx_size_map` produces when a 1:4 strip with a 64-px axis |
| 91 | /// splits its transform (`[TX_64X16] == TX_32X16`, `[TX_16X64] == TX_16X32`). | 97 | /// splits its transform (`[TX_64X16] == TX_32X16`, `[TX_16X64] == TX_16X32`). |
lanes/sub8intra-r1.handoff.mdadded+108 -0
| @@ -0,0 +1,108 @@ | |||
| 1 | +# lane-sub8intra r1 HANDOFF (tip = this commit) | ||
| 2 | + | ||
| 3 | +Env switch: **`EC_SUB8INTRA_DECODE=1`** enables the decode path; `EC_SUB8INTRA=1` prints the | ||
| 4 | +measurement line at the refusal sites. WITHOUT the switch both refusals are unchanged | ||
| 5 | +(verified: hg-0 and the 1920x792 @900 cut both still stop at | ||
| 6 | +"an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition"). | ||
| 7 | +No refusal lifted, `refusal_inventory.rs` / `gate_coverage.rs` untouched, no gate added. | ||
| 8 | + | ||
| 9 | +## Step 1 measurement (`EC_SUB8INTRA=1 EC_RECT64_SPLIT=1 EC_INTRA16X4_DECODE=1`, decode_probe) | ||
| 10 | + | ||
| 11 | +| probe | shape | sub-block | is chroma ref | skip | tx_select | | ||
| 12 | +|---|---|---|---|---|---| | ||
| 13 | +| 10-bit 3840x1608 cut 0 | 4x8 | 0 | false | 0 | 1 | | ||
| 14 | +| 10-bit 3840x1608 cut 300 | 8x4 | 0 | false | 0 | 1 | | ||
| 15 | +| 10-bit 1920x792 @900 | 4x8 | 0 | false | 0 | 1 | | ||
| 16 | +| 10-bit 1920x792 @5400 | 4x8 | 0 | false | 0 | 1 | | ||
| 17 | +| 10-bit 1920x792 @6300 | 4x8 | 0 | false | 0 | 1 | | ||
| 18 | +| 10-bit 1920x792 @8100 | -- (stops earlier on the clipped-16x4 arm) | | ||
| 19 | + | ||
| 20 | +5/6 fire first on sub-block 0 (NOT the chroma reference), non-skip, `--enable-tx-size-search` on. | ||
| 21 | +The 4x4 SPLIT refusal is never the first wall, but becomes the wall on 3/6 probes once the | ||
| 22 | +HORZ/VERT arm decodes, so both arms are implemented. | ||
| 23 | + | ||
| 24 | +## What is implemented (crates/ec-av1/src/decode.rs) | ||
| 25 | + | ||
| 26 | +* `decode_intra_sub8_leaf(.., (bw,bh), has_chroma, skip, ..)` -- one INTRA 8x4/4x8 **or 4x4** | ||
| 27 | + leaf on the inter path. Reads `y_mode[0]` (`size_group_lookup[BLOCK_8X4]==0`), NO angle delta | ||
| 28 | + (`av1_use_angle_delta` needs >= 8x8), `uv_mode` off `uv_mode_cfl[mode]` + CfL alphas only on | ||
| 29 | + the chroma reference, `filter_intra` off the shape's own class row | ||
| 30 | + (`filter_intra_size_class_rect` / `_class(4)`), then the tx-depth symbol | ||
| 31 | + (`tx_size_cat0`, ctx from `tx_size_context_txfm_rect` -- the INTER frame's live | ||
| 32 | + `above_txfm`/`left_txfm`, not the key frame's deblock approximation; `BLOCK_4X4` reads none, | ||
| 33 | + `block_signals_txsize` is false). Luma = `decode_leaf_rect8`'s body (whole `TX_8X4`/`TX_4X8` | ||
| 34 | + via `read_coeffs_rect` + `LumaRect4x8[Set1]` + `SCAN_8X4`/`SCAN_4X8`, or two `TX_4X4` units at | ||
| 35 | + depth 1; square `read_plane` for 4x4). Chroma, when this leaf IS the chroma reference: the | ||
| 36 | + group's one 4x4 unit intra-predicted at the 8x8 group origin with `group_reach = Reach::of(8,..)`, | ||
| 37 | + CfL AC from the group's 8x8 luma -- `decode_leaf_rect8`'s post-loop chroma verbatim. | ||
| 38 | + Publishes: mode into `record_mode_mi` + the coarse `above_mode`/`left_mode`, skip grid, | ||
| 39 | + lf grid at tx dims, `set_txfm_ctxs` equivalent (`above_txfm = tx_w`, `left_txfm = tx_h`), | ||
| 40 | + `record_inter_rect_mi(.., is_inter=false, ref 0, filter [3,3])`, and `MiInfo { is_inter:false, | ||
| 41 | + ref_frame:-1 }` over every mi cell. | ||
| 42 | +* `decode_inter_sub8_rect2` / `decode_inter_sub8_split4`: the `!is_inter` arm calls it (behind | ||
| 43 | + the env switch), sets `intra_chroma` when the leaf was the chroma reference, and the whole | ||
| 44 | + chroma tail (prediction, residual, `record_uv_mode_mi`, the u/v neighbour-state loop) is | ||
| 45 | + guarded by `if !intra_chroma`. | ||
| 46 | +* MIXED groups (chroma reference INTER, a sibling INTRA): `is_sub8x8_inter` | ||
| 47 | + (reconinter_template.inc:54) returns false as soon as any mi of the group is intra, so the | ||
| 48 | + chroma is predicted WHOLE 4x4 from the chroma-reference block's own mv at the group's chroma | ||
| 49 | + origin instead of in 2x2/4x2 pieces -- implemented in both functions (`mixed` flag). | ||
| 50 | +* tx_type rule for that chroma: `first_tx_type` now comes from the chroma-reference block's own | ||
| 51 | + first TU when sub-block 0 is intra (`xd->tx_type_map[0]` of the current mi). NOTE the | ||
| 52 | + pre-existing all-inter rule ("FIRST sub-block") is untouched but looks wrong against | ||
| 53 | + blockd.h:1288 -- `xd->tx_type_map` is rebased to the CURRENT (chroma-reference) mi, so the | ||
| 54 | + co-located luma (0,0) is the LAST sub-block's, not the first's. Flagged, not changed. | ||
| 55 | +* Counter `sub8_intra_rect_hits() -> (8x4, 4x8, chroma_ref, mixed)`, printed by decode_probe | ||
| 56 | + (`sub8_intra_rect: ...`), exported through `stream.rs`. | ||
| 57 | +* `EC_TRACE_MODE_STEP` prints `name=mode` and `name=tx_depth val/ctx` for the leaf, in the | ||
| 58 | + oracle's EC_ISTEP format. | ||
| 59 | + | ||
| 60 | +## Pixel state under the bypass -- the gate is RED | ||
| 61 | + | ||
| 62 | +* Film: all six probes move past this wall (hg-0 7 leaves, hg-300 10, @900 21 (+2 mixed), | ||
| 63 | + @5400 28 (+2 mixed), @6300 2) and stop at the NEXT wall (4x4 split intra on 3 of them, | ||
| 64 | + the 16x4 strip arms on the others). No film pixel comparison is possible: every firing frame | ||
| 65 | + also carries the unproven intra-16x4 strip. | ||
| 66 | +* aomenc witness sweep `~/.cache/sub8intra-tmp/sweep.sh` and `sweep2.sh` (recipe: 128x128 / | ||
| 67 | + 192x128 gray lavfi sources, cq 48..63, `--min-partition-size=4 --enable-1to4-partitions=0 | ||
| 68 | + --max-partition-size=8|16 --enable-filter-intra=0 --sb-size=64 --enable-tx-size-search=1`), | ||
| 69 | + logs `sweep1.log` / `sweep2.log`: the counters fire on every arm (up to 293 8x4 leaves) but | ||
| 70 | + **only 1 of 24 arms decodes all 6 frames, and that one MISMATCHES at byte 24735**. Eleven | ||
| 71 | + arms encoded with `--max-partition-size=8` -- where a 16x4 block CANNOT exist -- still report | ||
| 72 | + "an intra 16x4/4x16 strip inside an inter 16x16-level 1:4 partition", i.e. the refusal is | ||
| 73 | + hallucinated by our own desync (class `refusal-from-own-desync`). | ||
| 74 | + | ||
| 75 | +## Where the desync is (bisected, do not redo this) | ||
| 76 | + | ||
| 77 | +Witness `~/.cache/sub8intra-tmp/x_1t_48_8_128x128.obu` (8-bit 128x128, cq48, max-partition 8; | ||
| 78 | +1 intra 8x4 leaf then the bogus refusal). | ||
| 79 | + | ||
| 80 | +* EC_MODE ladder (ours vs instrumented aomdec, `r.l`/`o.l` in that dir): identical for 168 | ||
| 81 | + entries; first divergence at `mi_row=24 mi_col=0` (ref rng=39238, ours rng=44268 and ours | ||
| 82 | + reads a 16-wide block where the reference reads four 4x4s). | ||
| 83 | +* The intra leaf itself is EXACT: it is at mi(23,12) (HORZ pair with the inter leaf at | ||
| 84 | + mi(22,12), so the INTRA one is the chroma reference). Ours prints | ||
| 85 | + `EC_ISTEP mi_row=23 mi_col=12 name=mode val=0 rng=38508` and | ||
| 86 | + `name=tx_depth val=0 ctx=2 cat=0 rng=49194`; the oracle prints the identical tx_depth line | ||
| 87 | + (ref_step.log:2463). So `y_mode[0]`, the missing angle delta, the uv/CfL reads and the | ||
| 88 | + tx-depth ctx are all right. | ||
| 89 | +* `tag=all_zero` ladder (`rz.l`/`oz.l`): the first 1405 luma/chroma transform units match | ||
| 90 | + exactly; unit 1406 diverges (ref `all_zero=0 rng=40294`, ours `all_zero=0 rng=52548`). Both | ||
| 91 | + decoders are still reading plane 0 there, so the divergence is in symbols read BETWEEN two | ||
| 92 | + luma TUs -- i.e. inside the block following the intra leaf (the group at mi(22..23,14), the | ||
| 93 | + 8x8 immediately to its right) or in that group's chroma. | ||
| 94 | + | ||
| 95 | +## Exact next step | ||
| 96 | + | ||
| 97 | +1. On that witness, ladder the group at mi(22,14)/(23,14) element by element (aomdec | ||
| 98 | + `EC_ISTEP2 name=interp` / `EC_MODE`, ours `EC_MODE_MV`/`EC_MODE_VALR`) -- the intra leaf at | ||
| 99 | + mi(23,12) is its LEFT neighbour, so the prime suspects are the left-side bands the intra | ||
| 100 | + leaf publishes: `left_txfm` (tx dims vs block dims), `left_ref`/`left_inter` from | ||
| 101 | + `record_inter_rect_mi(ref 0)` (INTRA_FRAME is 0 vs the `-1` the mi grid gets), the | ||
| 102 | + coefficient state `left[..][0..2]`, and `left_side_mi` (the caller writes the group's | ||
| 103 | + partition ctx AFTER the leaf, check the order). | ||
| 104 | +2. Then re-check the chroma of the MIXED group at mi(22,12): its chroma is coded by the intra | ||
| 105 | + leaf, so the inter sibling's own `piece` is dropped -- confirm against | ||
| 106 | + `build_inter_predictors_sub8x8`'s `is_sub8x8_inter == false` path. | ||
| 107 | +3. Only then re-run the sweep; a green arm needs `--max-partition-size=8` (no 16x4 shape can | ||
| 108 | + exist there, so any 1:4 refusal is proof of a remaining desync). | ||
lanes/sub8intra-r2.handoff.mdadded+73 -0
| @@ -0,0 +1,73 @@ | |||
| 1 | +# lane-sub8intra r2 HANDOFF (tip = this commit) | ||
| 2 | + | ||
| 3 | +## The band: NOT a band -- the mv-stack's second-outer COLUMN scan (`mvstack.rs`) | ||
| 4 | + | ||
| 5 | +r1's suspects (above/left txfm, inter, ref, skip, y_mode, coeff, side-mi bands published by | ||
| 6 | +the intra leaf) were ALL innocent. The first diverging symbol on the r1 witness | ||
| 7 | +`~/.cache/sub8intra-tmp/x_1t_48_8_128x128.obu` is the `refmv` symbol of the INTER 8x4 leaf at | ||
| 8 | +mi(23,14) -- the block whose LEFT neighbour is the intra leaf at mi(23,12..13). Same decoded | ||
| 9 | +value (NEARESTMV), different CDF ROW (class `wrong-alphabet-same-value` / `cdf-row-held-constant`): | ||
| 10 | + | ||
| 11 | +* instrumented aomdec (private build, see below): `mode_ctx=75` -> newmv 3, globalmv 1, **refmv 4** | ||
| 12 | +* ours before the fix: newmv 3, globalmv 1, **refmv 3** -> rng 62378 where the reference has 47820 | ||
| 13 | + | ||
| 14 | +`refmv 4` vs `3` is `ref_match_count == 2` vs `1` in `setup_ref_mv_list`'s `case 1:` switch | ||
| 15 | +(mvref_common.c:638): libaom's second-outer column scan (`col_offset = -3`) found an inter | ||
| 16 | +match at mi(23,11), ours found none. | ||
| 17 | + | ||
| 18 | +## Two defects fixed (crates/ec-av1/src/mvstack.rs, all FOUR scan functions) | ||
| 19 | + | ||
| 20 | +Both are pure sub-8x8 (a side < 2 mi) defects; every block main decodes today has both sides | ||
| 21 | +>= 8px in at least one of the two axes checked, which is why they survived until this lane. | ||
| 22 | + | ||
| 23 | +1. **`scan_col_mbmi`'s odd-row snap was missing** (`scan_col` L~600, `scan_col_compound` L~1406): | ||
| 24 | + libaom does `row_offset = 1; if ((mi_row & 0x01) && xd->height < n8_h_8) --row_offset;`. | ||
| 25 | + For an 8x4 leaf on an ODD mi row our walk probed the row BELOW (undecoded), losing the | ||
| 26 | + match. Fixed as `col_offset.unsigned_abs() > 1 && !(mi_row % 2 == 1 && bh4 < 2)`. | ||
| 27 | + Transposed twin fixed in `scan_row`/`scan_row_compound` | ||
| 28 | + (`(mi_col & 1) && xd->width < n8_w_8`). | ||
| 29 | +2. **the weight / `processed_rows|cols` guard dropped libaom's `>= n8_*_8` half**: | ||
| 30 | + libaom `if (xd->height >= n8_h_8 && xd->height <= n4_h)`; ours was `if (bh4 <= n4)`, so a | ||
| 31 | + 1-mi-tall query block set `processed_cols` and a boosted weight libaom never sets (which can | ||
| 32 | + also suppress the second-outer scan entirely). Now `bh4 >= 2 && bh4 <= n4` (and `bw4` twin). | ||
| 33 | + | ||
| 34 | +`cargo check -p ec-av1`: clean. | ||
| 35 | + | ||
| 36 | +## Ladder result on x_1t_48_8_128x128.obu (EC_SUB8INTRA_DECODE=1) | ||
| 37 | + | ||
| 38 | +* mi(24,0) EC_MODE: ref 39238, ours **39238** (was 44268) -- matches. | ||
| 39 | +* `tag=all_zero` ladder: **2106/2106 units identical in value AND range, all 6 frames** | ||
| 40 | + (`diff rz2.l oz2.l` empty). r1's ladder stopped matching at 1405. | ||
| 41 | +* `OK: 6 frames decoded, 128x128`, `sub8_intra_rect: horz8x4=19 vert4x8=2 chroma_ref=10 mixed=3`. | ||
| 42 | +* Pixels: 3 residual clusters (frame 3 two 4x4 luma, frames 4/5 one +-1 pixel triple) -- | ||
| 43 | + root-caused to the OBMC `mi_step == 1` chroma-pair merge, which is **already fixed on | ||
| 44 | + lane-intra16x4 as f403337** (`overlappable_above`/`overlappable_left`). NOT duplicated here | ||
| 45 | + (charter: those functions belong to that lane). With f403337's decode.rs hunk applied on top of | ||
| 46 | + this commit the witness is **cmp-EXACT vs `ffmpeg -pix_fmt yuv420p` on all 6 frames** | ||
| 47 | + (verified, then reverted out of this tree). | ||
| 48 | + | ||
| 49 | +## Oracle instrumentation added (additive, env-gated `EC_SUB8CTX`) | ||
| 50 | + | ||
| 51 | +`av1/decoder/decodemv.c` in `~/.cache/aom-oracle/src`: one print after `read_ref_frames` | ||
| 52 | +(single-ref p1 ctx + rng) and one after `read_inter_mode` (mode_ctx split into | ||
| 53 | +newmv/globalmv/refmv + ref_mv_count). Built into the PRIVATE dir | ||
| 54 | +`~/.cache/sub8intra-tmp/aom-build` (`ninja aomdec`); `~/.cache/aom-oracle/build` untouched. | ||
| 55 | +This print is what named the band in one step -- keep it. | ||
| 56 | + | ||
| 57 | +## Next step (r3) | ||
| 58 | + | ||
| 59 | +1. Sweep `~/.cache/sub8intra-tmp/sweep3.sh` (max-partition-size=8, 1:4 off, 8- and 10-bit, | ||
| 60 | + cq 48/55/63, 128x128 + 192x128) -- 5 of 12 arms already decode all 6 frames pixel-EXACT | ||
| 61 | + (`10 cq48 128x128`, `10 cq48 192x128`, `10 cq55 128x128`, `10 cq63 128x128`, | ||
| 62 | + `8 cq55 192x128`). Those are the gate arms. | ||
| 63 | +2. The other arms still stop at a refusal naming a shape the encoder cannot have coded | ||
| 64 | + (`--max-partition-size=8` + `--enable-1to4-partitions=0`) -- class `refusal-from-own-desync`, | ||
| 65 | + one desync left. Bisected on `g_8_48_128x128.obu`: first divergence at all_zero unit 1581, | ||
| 66 | + block mi(25,2) -- the reference reads `use_filter_intra=1`, `filter_intra_mode=3`, | ||
| 67 | + `tx_depth=1` for an INTRA sub-8x8 leaf there (ra2.l:4370-4372) which OUR path never reads; | ||
| 68 | + ours continues the previous block's 4x4 units instead. So: filter_intra IS read on a | ||
| 69 | + sub-8x8 intra leaf in that stream, and the `tx_depth=1` split (two TX_4X4) path is the | ||
| 70 | + one to check first. | ||
| 71 | +3. Then: gate + refusal lift (both sub-8x8 intra refusals), refusal_inventory.rs + | ||
| 72 | + gate_coverage.rs, suite, films. Also still open: the flagged all-inter `first_tx_type` | ||
| 73 | + rule (blockd.h:1288, LAST sub-block vs first) -- unmeasured this round. | ||