Merge branch 'lane-ab128': the four AB partition shapes at the 128 root are written and witnessed sample-exact through both decoders, and ship off by measurement (EC_AV1_B128AB=1); pins unmoved at 8291 / 33227
Browse files at this commit3 changed files +643 -18
- crates/ec-av1/src/encode.rs +410 -11
- crates/ec-av1/src/tile.rs +77 -7
- lanes/ab128.report.md +156 -0
crates/ec-av1/src/encode.rsmodified+410 -11
| @@ -826,6 +826,80 @@ pub(crate) fn force_b128_rect(which: u8) { | |||
| 826 | FORCE_B128_RECT.store(which, std::sync::atomic::Ordering::Relaxed); | 826 | FORCE_B128_RECT.store(which, std::sync::atomic::Ordering::Relaxed); |
| 827 | } | 827 | } |
| 828 | 828 | ||
| 829 | +/// lane-ab128: whether the 128 superblock root offers its four AB shapes -- | ||
| 830 | +/// `PARTITION_HORZ_A` (two 64x64 on top, one 128x64 below), `_HORZ_B` (one | ||
| 831 | +/// 128x64 on top, two 64x64 below), `_VERT_A` (two 64x64 left, one 64x128 | ||
| 832 | +/// right) and `_VERT_B` (one 64x128 left, two 64x64 right). Every piece is | ||
| 833 | +/// the same skip-only single-reference/compound block the NONE and HORZ/VERT | ||
| 834 | +/// arms ship, at its own footprint ([`search_root_128_ab`], | ||
| 835 | +/// `crate::tile::write_inter_block_128_rect`). `EC_AV1_B128AB=0` is this | ||
| 836 | +/// arm's attribution control. | ||
| 837 | +/// | ||
| 838 | +/// **Off by default** (`EC_AV1_B128AB=1` turns it on): measured on both gates | ||
| 839 | +/// and it does not pay. The shapes fire 0-2 roots a frame against ~1000 coded | ||
| 840 | +/// blocks (`EC_AV1_B128_CENSUS`), and every row is flat or 0.1 worse -- | ||
| 841 | +/// long-GOP film A +22.0/-8.5 against a +21.9/-8.6 control, film B +75.8/+0.8 | ||
| 842 | +/// against the same, 12-frame film A +18.1/-6.2 against +18.0/-6.3, film B | ||
| 843 | +/// +23.1/-3.3 against +23.0/-3.5, screen byte-identical (lane-ab128). The | ||
| 844 | +/// machinery is written, witnessed sample-exact through both decoders on all | ||
| 845 | +/// four shapes, and kept for the arm that makes it pay: a non-skip piece (the | ||
| 846 | +/// 64x64 pieces could carry the 64 root's residual, which is where libaom's | ||
| 847 | +/// AB shapes earn their keep) or a cheaper partition price. | ||
| 848 | +fn b128_ab() -> bool { | ||
| 849 | + static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | ||
| 850 | + crate::envflags::var("EC_AV1_B128AB").ok().map(|v| v != "0") | ||
| 851 | + }); | ||
| 852 | + ENV.unwrap_or(false) && b128_root() | ||
| 853 | +} | ||
| 854 | + | ||
| 855 | +/// How many 128 roots the search left as each AB shape since the last take, | ||
| 856 | +/// in `PARTITION_HORZ_A`, `_HORZ_B`, `_VERT_A`, `_VERT_B` order (class | ||
| 857 | +/// `gate-blind-to-feature`). | ||
| 858 | +static B128_AB_HITS: [std::sync::atomic::AtomicUsize; 4] = | ||
| 859 | + [const { std::sync::atomic::AtomicUsize::new(0) }; 4]; | ||
| 860 | + | ||
| 861 | +/// The four per-shape AB-root counts since the last call, and zero them. | ||
| 862 | +pub fn take_b128_ab_hits() -> [usize; 4] { | ||
| 863 | + std::array::from_fn(|i| B128_AB_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed)) | ||
| 864 | +} | ||
| 865 | + | ||
| 866 | +/// Test-only: force the 128 root's AB shape whatever it costs -- 0 off, then | ||
| 867 | +/// 4..=7, the partition symbol itself ([`force_b128_rect`]'s twin; synthetic | ||
| 868 | +/// content is where the shapes are cheapest to decode-check and the RD there | ||
| 869 | +/// prefers one whole block). | ||
| 870 | +static FORCE_B128_AB: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(0); | ||
| 871 | + | ||
| 872 | +/// Arms [`FORCE_B128_AB`] for the rest of the process (0 off, else 4..=7). | ||
| 873 | +#[cfg(test)] | ||
| 874 | +pub(crate) fn force_b128_ab(which: u8) { | ||
| 875 | + FORCE_B128_AB.store(which, std::sync::atomic::Ordering::Relaxed); | ||
| 876 | +} | ||
| 877 | + | ||
| 878 | +/// lane-ab128: the three pieces of an AB shape at a 128 root, in the order | ||
| 879 | +/// libaom's `decode_partition` codes them and decode.rs' `sb128_ab` arm | ||
| 880 | +/// reads them (decode.rs ~35269) -- HORZ_A = TL, TR, bottom half; HORZ_B = | ||
| 881 | +/// top half, BL, BR; VERT_A = TL, BL, right half; VERT_B = left half, TR, BR. | ||
| 882 | +/// Each entry is the piece's own top-left in mode-info units and its | ||
| 883 | +/// footprint in samples. | ||
| 884 | +pub(crate) fn ab128_pieces( | ||
| 885 | + symbol: usize, | ||
| 886 | + (mi_row, mi_col): (usize, usize), | ||
| 887 | +) -> [((usize, usize), (usize, usize)); 3] { | ||
| 888 | + const S: usize = SUPERBLOCK; | ||
| 889 | + let (r, c) = (mi_row, mi_col); | ||
| 890 | + let (r1, c1) = (mi_row + 16, mi_col + 16); | ||
| 891 | + match symbol { | ||
| 892 | + // PARTITION_HORZ_A | ||
| 893 | + 4 => [((r, c), (S, S)), ((r, c1), (S, S)), ((r1, c), (S * 2, S))], | ||
| 894 | + // PARTITION_HORZ_B | ||
| 895 | + 5 => [((r, c), (S * 2, S)), ((r1, c), (S, S)), ((r1, c1), (S, S))], | ||
| 896 | + // PARTITION_VERT_A | ||
| 897 | + 6 => [((r, c), (S, S)), ((r1, c), (S, S)), ((r, c1), (S, S * 2))], | ||
| 898 | + // PARTITION_VERT_B | ||
| 899 | + _ => [((r, c), (S, S * 2)), ((r, c1), (S, S)), ((r1, c1), (S, S))], | ||
| 900 | + } | ||
| 901 | +} | ||
| 902 | + | ||
| 829 | /// Test-only: take the 128 root's residual arm whatever it costs, so a | 903 | /// Test-only: take the 128 root's residual arm whatever it costs, so a |
| 830 | /// witness clip codes the shape rather than waiting for content on which the | 904 | /// witness clip codes the shape rather than waiting for content on which the |
| 831 | /// RD picks it (the same role [`force_sb128`] plays for the superblock size). | 905 | /// RD picks it (the same role [`force_sb128`] plays for the superblock size). |
| @@ -9891,6 +9965,156 @@ fn search_root_128_rect( | |||
| 9891 | )) | 9965 | )) |
| 9892 | } | 9966 | } |
| 9893 | 9967 | ||
| 9968 | +/// lane-ab128: one AB shape at a 128 superblock root -- two 64x64 blocks and | ||
| 9969 | +/// one 128x64 / 64x128 half, in the order [`ab128_pieces`] gives (the | ||
| 9970 | +/// decoder's own). Each piece is priced through the same `search_skip_64` | ||
| 9971 | +/// the NONE and HORZ/VERT arms use, at its own footprint, and is published | ||
| 9972 | +/// into `grid` before the next is searched -- the writer publishes it too, so | ||
| 9973 | +/// a later piece searched against a stale grid would be priced (and its mv | ||
| 9974 | +/// predicted) off a stack the decoder never derives (class | ||
| 9975 | +/// `encoder-grid-drift-invisible-to-pixel-gate`). The grid and both planes | ||
| 9976 | +/// are put back before returning; the caller re-applies the winner. | ||
| 9977 | +/// | ||
| 9978 | +/// SKIP only, for the reason [`search_root_128_rect`] gives: the 128 residual | ||
| 9979 | +/// arm the pieces would share is itself parked behind `EC_AV1_B128RES`. | ||
| 9980 | +/// | ||
| 9981 | +/// Returns `(cost, lambda, the three pieces, reconstruction)`, the cost | ||
| 9982 | +/// already carrying the root's own partition symbol so it ranks against the | ||
| 9983 | +/// other root candidates and against the four superblocks below. | ||
| 9984 | +#[allow(clippy::too_many_arguments)] | ||
| 9985 | +fn search_root_128_ab( | ||
| 9986 | + luma: &mut Plane, | ||
| 9987 | + chroma: &mut [Plane; 2], | ||
| 9988 | + grid: &mut crate::mvstack::MiGrid, | ||
| 9989 | + (root_r, root_c): (usize, usize), | ||
| 9990 | + (rows, cols): (usize, usize), | ||
| 9991 | + (mi_cols, mi_rows): (u32, u32), | ||
| 9992 | + search: Search<'_>, | ||
| 9993 | + tpl_factors: &Option<Vec<f64>>, | ||
| 9994 | + sb_q: Option<&Vec<u8>>, | ||
| 9995 | + sb_cols: usize, | ||
| 9996 | + tpl_cells_x: usize, | ||
| 9997 | + base_q_idx: u8, | ||
| 9998 | + reference: &Picture, | ||
| 9999 | + compound: &[(i8, &Picture, crate::mvstack::CompoundMvStack)], | ||
| 10000 | + // The partition symbol, 4..=7. | ||
| 10001 | + symbol: usize, | ||
| 10002 | + fctx: &crate::decode::FrameCtx, | ||
| 10003 | +) -> Option<(f64, f64, [BlockCoeffs; 3], [(Vec<u8>, Vec<CoefCtx>); 3])> { | ||
| 10004 | + const SIDE: usize = SUPERBLOCK * 2; | ||
| 10005 | + const SIDE_MI: usize = SIDE / 4; | ||
| 10006 | + let (x128, y128) = (root_c * SUPERBLOCK, root_r * SUPERBLOCK); | ||
| 10007 | + let (mi_row, mi_col) = (root_r * 16, root_c * 16); | ||
| 10008 | + if root_r * 2 + 3 >= rows | ||
| 10009 | + || root_c * 2 + 3 >= cols | ||
| 10010 | + || (mi_row + SIDE_MI) as u32 > mi_rows | ||
| 10011 | + || (mi_col + SIDE_MI) as u32 > mi_cols | ||
| 10012 | + || x128 + SIDE > luma.true_width | ||
| 10013 | + || y128 + SIDE > luma.true_height | ||
| 10014 | + { | ||
| 10015 | + return None; | ||
| 10016 | + } | ||
| 10017 | + // The root's own lambda, the mean of its four superblocks' -- the same one | ||
| 10018 | + // [`search_root_128`] prices with, so every root candidate and the | ||
| 10019 | + // four-superblock arm are comparable. | ||
| 10020 | + let cell_lambda = |sb_r: usize, sb_c: usize| match (sb_q, tpl_factors) { | ||
| 10021 | + (Some(q), _) => sb_q_search(q, sb_cols, base_q_idx, (sb_r, sb_c), search).lambda, | ||
| 10022 | + (None, Some(f)) => { | ||
| 10023 | + let mean = (0..16) | ||
| 10024 | + .map(|i| f[(sb_r * 4 + i / 4) * tpl_cells_x + sb_c * 4 + i % 4]) | ||
| 10025 | + .sum::<f64>() | ||
| 10026 | + / 16.0; | ||
| 10027 | + search.lambda * mean | ||
| 10028 | + } | ||
| 10029 | + (None, None) => search.lambda, | ||
| 10030 | + }; | ||
| 10031 | + let lambda = [(0, 0), (0, 1), (1, 0), (1, 1)] | ||
| 10032 | + .iter() | ||
| 10033 | + .map(|&(dr, dc)| cell_lambda(root_r + dr, root_c + dc)) | ||
| 10034 | + .sum::<f64>() | ||
| 10035 | + / 4.0; | ||
| 10036 | + let root_search = Search { | ||
| 10037 | + lambda, | ||
| 10038 | + ..match sb_q { | ||
| 10039 | + Some(q) => sb_q_search(q, sb_cols, base_q_idx, (root_r, root_c), search), | ||
| 10040 | + None => search, | ||
| 10041 | + } | ||
| 10042 | + }; | ||
| 10043 | + let base = snapshot(luma, chroma, (x128, y128), SIDE); | ||
| 10044 | + let grid_base = grid.snapshot_rect(mi_row, mi_col, SIDE_MI, SIDE_MI); | ||
| 10045 | + let mut cost = 0.0f64; | ||
| 10046 | + let mut pieces: Vec<BlockCoeffs> = Vec::with_capacity(3); | ||
| 10047 | + for ((mr, mc), (w, h)) in ab128_pieces(symbol, (mi_row, mi_col)) { | ||
| 10048 | + let (w_mi, h_mi) = (w / 4, h / 4); | ||
| 10049 | + let stack = find_mv_stack( | ||
| 10050 | + grid, | ||
| 10051 | + mr, | ||
| 10052 | + mc, | ||
| 10053 | + w_mi, | ||
| 10054 | + h_mi, | ||
| 10055 | + LAST_FRAME, | ||
| 10056 | + mi_cols as usize, | ||
| 10057 | + mi_rows as usize, | ||
| 10058 | + ); | ||
| 10059 | + let piece_compound: Vec<(i8, &Picture, crate::mvstack::CompoundMvStack)> = compound | ||
| 10060 | + .iter() | ||
| 10061 | + .map(|&(r, pic, _)| { | ||
| 10062 | + ( | ||
| 10063 | + r, | ||
| 10064 | + pic, | ||
| 10065 | + crate::mvstack::find_mv_stack_compound( | ||
| 10066 | + grid, | ||
| 10067 | + mr, | ||
| 10068 | + mc, | ||
| 10069 | + w_mi, | ||
| 10070 | + h_mi, | ||
| 10071 | + (LAST_FRAME, r), | ||
| 10072 | + mi_cols as usize, | ||
| 10073 | + mi_rows as usize, | ||
| 10074 | + grid.sign_bias_table(), | ||
| 10075 | + &[(0, 0); 7], | ||
| 10076 | + None, | ||
| 10077 | + ), | ||
| 10078 | + ) | ||
| 10079 | + }) | ||
| 10080 | + .collect(); | ||
| 10081 | + let found = search_skip_64( | ||
| 10082 | + luma, | ||
| 10083 | + chroma, | ||
| 10084 | + (mc * 4, mr * 4), | ||
| 10085 | + (w, h), | ||
| 10086 | + &root_search, | ||
| 10087 | + false, | ||
| 10088 | + reference, | ||
| 10089 | + &stack, | ||
| 10090 | + &piece_compound, | ||
| 10091 | + fctx, | ||
| 10092 | + ); | ||
| 10093 | + match found { | ||
| 10094 | + Some((c, block)) => { | ||
| 10095 | + cost += c; | ||
| 10096 | + record_mi_rect(grid, mr, mc, (w_mi, h_mi), block.inter, block.skip); | ||
| 10097 | + pieces.push(block); | ||
| 10098 | + } | ||
| 10099 | + None => { | ||
| 10100 | + restore(luma, chroma, (x128, y128), SIDE, &base); | ||
| 10101 | + grid.restore_rect(mi_row, mi_col, SIDE_MI, SIDE_MI, &grid_base); | ||
| 10102 | + return None; | ||
| 10103 | + } | ||
| 10104 | + } | ||
| 10105 | + } | ||
| 10106 | + let after = snapshot(luma, chroma, (x128, y128), SIDE); | ||
| 10107 | + restore(luma, chroma, (x128, y128), SIDE, &base); | ||
| 10108 | + grid.restore_rect(mi_row, mi_col, SIDE_MI, SIDE_MI, &grid_base); | ||
| 10109 | + let [b0, b1, b2] = <[BlockCoeffs; 3]>::try_from(pieces).ok()?; | ||
| 10110 | + Some(( | ||
| 10111 | + cost + lambda * crate::tile::partition_bits_sym(SIDE, symbol), | ||
| 10112 | + lambda, | ||
| 10113 | + [b0, b1, b2], | ||
| 10114 | + after, | ||
| 10115 | + )) | ||
| 10116 | +} | ||
| 10117 | + | ||
| 9894 | /// The 64x64 `PARTITION_NONE` candidate for a whole superblock ([`B64_ROOT`]): | 10118 | /// The 64x64 `PARTITION_NONE` candidate for a whole superblock ([`B64_ROOT`]): |
| 9895 | /// single-reference LAST at `NEARESTMV`/`GLOBALMV`/`NEARMV`/`NEWMV`, coded | 10119 | /// single-reference LAST at `NEARESTMV`/`GLOBALMV`/`NEARMV`/`NEWMV`, coded |
| 9896 | /// SKIP, priced through the same `symbol_bits` path every other candidate | 10120 | /// SKIP, priced through the same `symbol_bits` path every other candidate |
| @@ -12660,6 +12884,47 @@ pub(crate) fn encode_inter_frame( | |||
| 12660 | best | 12884 | best |
| 12661 | }) | 12885 | }) |
| 12662 | .flatten(); | 12886 | .flatten(); |
| 12887 | + // lane-ab128: and the same root as one of the four AB shapes -- two | ||
| 12888 | + // 64x64 pieces plus one 128x64 / 64x128 half. All four are priced; | ||
| 12889 | + // the cheapest joins the candidate list below. | ||
| 12890 | + let forced_ab = FORCE_B128_AB.load(std::sync::atomic::Ordering::Relaxed); | ||
| 12891 | + let root_ab = (sb128_search | ||
| 12892 | + && (b128_ab() || forced_ab != 0) | ||
| 12893 | + && cells.len() == 4 | ||
| 12894 | + && forced_rect == 0) | ||
| 12895 | + .then(|| { | ||
| 12896 | + let mut best: Option<(usize, _)> = None; | ||
| 12897 | + for symbol in 4..=7usize { | ||
| 12898 | + if forced_ab != 0 && usize::from(forced_ab) != symbol { | ||
| 12899 | + continue; | ||
| 12900 | + } | ||
| 12901 | + let Some(found) = search_root_128_ab( | ||
| 12902 | + &mut luma, | ||
| 12903 | + &mut chroma, | ||
| 12904 | + &mut grid, | ||
| 12905 | + (root_r, root_c), | ||
| 12906 | + (rows, cols), | ||
| 12907 | + (header.mi_cols, header.mi_rows), | ||
| 12908 | + search, | ||
| 12909 | + &tpl_factors, | ||
| 12910 | + sb_q.as_ref(), | ||
| 12911 | + sb_cols, | ||
| 12912 | + tpl_cells_x, | ||
| 12913 | + base_q_idx, | ||
| 12914 | + reference, | ||
| 12915 | + &root_compound, | ||
| 12916 | + symbol, | ||
| 12917 | + fctx, | ||
| 12918 | + ) else { | ||
| 12919 | + continue; | ||
| 12920 | + }; | ||
| 12921 | + if best.as_ref().is_none_or(|b: &(usize, (f64, f64, _, _))| found.0 < b.1.0) { | ||
| 12922 | + best = Some((symbol, found)); | ||
| 12923 | + } | ||
| 12924 | + } | ||
| 12925 | + best | ||
| 12926 | + }) | ||
| 12927 | + .flatten(); | ||
| 12663 | for (sb_r, sb_c) in cells { | 12928 | for (sb_r, sb_c) in cells { |
| 12664 | // lane-b64: the whole superblock as ONE 64x64 block, tried before | 12929 | // lane-b64: the whole superblock as ONE 64x64 block, tried before |
| 12665 | // its quadrants are (`search_skip_64`) and compared against the | 12930 | // its quadrants are (`search_skip_64`) and compared against the |
| @@ -13238,18 +13503,26 @@ pub(crate) fn encode_inter_frame( | |||
| 13238 | // `partition_w128` symbol) against what its four superblocks really | 13503 | // `partition_w128` symbol) against what its four superblocks really |
| 13239 | // cost, the same weighing the 64 root does one size down. Both sides | 13504 | // cost, the same weighing the 64 root does one size down. Both sides |
| 13240 | // carry their own partition symbol, so the comparison is complete. | 13505 | // carry their own partition symbol, so the comparison is complete. |
| 13241 | - // lane-b128hv: `None` is the NONE arm, `Some(horz)` a rect cut. | 13506 | + // The root candidates, each tagged with the PARTITION symbol its |
| 13242 | - let mut cands: Vec<(f64, f64, Option<bool>, Vec<BlockCoeffs>, _)> = Vec::new(); | 13507 | + // writer codes: 0 NONE, 1 HORZ, 2 VERT (lane-b128hv), 4..=7 the AB |
| 13508 | + // shapes (lane-ab128). | ||
| 13509 | + let mut cands: Vec<(f64, f64, usize, Vec<BlockCoeffs>, _)> = Vec::new(); | ||
| 13243 | if let Some((c, l, b, a)) = root128 { | 13510 | if let Some((c, l, b, a)) = root128 { |
| 13244 | - cands.push((c, l, None, vec![b], a)); | 13511 | + cands.push((c, l, 0, vec![b], a)); |
| 13245 | } | 13512 | } |
| 13246 | if let Some((horz, (c, l, halves, a))) = root_rect { | 13513 | if let Some((horz, (c, l, halves, a))) = root_rect { |
| 13247 | - cands.push((c, l, Some(horz), halves.to_vec(), a)); | 13514 | + cands.push((c, l, usize::from(!horz) + 1, halves.to_vec(), a)); |
| 13515 | + } | ||
| 13516 | + if let Some((symbol, (c, l, pieces, a))) = root_ab { | ||
| 13517 | + cands.push((c, l, symbol, pieces.to_vec(), a)); | ||
| 13248 | } | 13518 | } |
| 13249 | - // The rect witness knob drops the NONE arm outright: on synthetic | 13519 | + // The witness knobs drop every other arm outright: on synthetic |
| 13250 | // content the whole block always wins its own comparison. | 13520 | // content the whole block always wins its own comparison. |
| 13251 | if forced_rect != 0 { | 13521 | if forced_rect != 0 { |
| 13252 | - cands.retain(|c| c.2.is_some()); | 13522 | + cands.retain(|c| c.2 == 1 || c.2 == 2); |
| 13523 | + } | ||
| 13524 | + if forced_ab != 0 { | ||
| 13525 | + cands.retain(|c| c.2 == usize::from(forced_ab)); | ||
| 13253 | } | 13526 | } |
| 13254 | cands.sort_by(|a, b| a.0.total_cmp(&b.0)); | 13527 | cands.sort_by(|a, b| a.0.total_cmp(&b.0)); |
| 13255 | if let Some((cost128, lambda128, shape, halves, after)) = cands.into_iter().next() | 13528 | if let Some((cost128, lambda128, shape, halves, after)) = cands.into_iter().next() |
| @@ -13257,20 +13530,40 @@ pub(crate) fn encode_inter_frame( | |||
| 13257 | // The witness knobs take the root whatever it costs, so the | 13530 | // The witness knobs take the root whatever it costs, so the |
| 13258 | // forced block really reaches the writer. | 13531 | // forced block really reaches the writer. |
| 13259 | || FORCE_B128_ROOT.load(std::sync::atomic::Ordering::Relaxed) | 13532 | || FORCE_B128_ROOT.load(std::sync::atomic::Ordering::Relaxed) |
| 13260 | - || forced_rect != 0) | 13533 | + || forced_rect != 0 |
| 13534 | + || forced_ab != 0) | ||
| 13261 | { | 13535 | { |
| 13262 | let (x128, y128) = (root_c * SUPERBLOCK, root_r * SUPERBLOCK); | 13536 | let (x128, y128) = (root_c * SUPERBLOCK, root_r * SUPERBLOCK); |
| 13263 | blocks.truncate(mark128); | 13537 | blocks.truncate(mark128); |
| 13264 | restore(&mut luma, &mut chroma, (x128, y128), SUPERBLOCK * 2, &after); | 13538 | restore(&mut luma, &mut chroma, (x128, y128), SUPERBLOCK * 2, &after); |
| 13265 | let at = (root_r * 2) * cols + root_c * 2; | 13539 | let at = (root_r * 2) * cols + root_c * 2; |
| 13266 | match shape { | 13540 | match shape { |
| 13267 | - None => { | 13541 | + 0 => { |
| 13268 | B128_NONE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 13542 | B128_NONE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 13269 | let block = halves.into_iter().next().expect("the NONE arm's block"); | 13543 | let block = halves.into_iter().next().expect("the NONE arm's block"); |
| 13270 | record_mi(&mut grid, root_r * 16, root_c * 16, 32, block.inter, block.skip); | 13544 | record_mi(&mut grid, root_r * 16, root_c * 16, 32, block.inter, block.skip); |
| 13271 | blocks.push((at, Quadrant::Whole128(block))); | 13545 | blocks.push((at, Quadrant::Whole128(block))); |
| 13272 | } | 13546 | } |
| 13273 | - Some(horz) => { | 13547 | + // lane-ab128: three pieces, published at their own footprints |
| 13548 | + // in the writer's own order ([`ab128_pieces`]). | ||
| 13549 | + symbol @ 4..=7 => { | ||
| 13550 | + B128_AB_HITS[symbol - 4].fetch_add(1, std::sync::atomic::Ordering::Relaxed); | ||
| 13551 | + for (((mr, mc), (w, h)), piece) in | ||
| 13552 | + ab128_pieces(symbol, (root_r * 16, root_c * 16)).iter().zip(&halves) | ||
| 13553 | + { | ||
| 13554 | + record_mi_rect( | ||
| 13555 | + &mut grid, | ||
| 13556 | + *mr, | ||
| 13557 | + *mc, | ||
| 13558 | + (w / 4, h / 4), | ||
| 13559 | + piece.inter, | ||
| 13560 | + piece.skip, | ||
| 13561 | + ); | ||
| 13562 | + } | ||
| 13563 | + blocks.push((at, Quadrant::Ab128(symbol as u8, halves))); | ||
| 13564 | + } | ||
| 13565 | + symbol => { | ||
| 13566 | + let horz = symbol == 1; | ||
| 13274 | if horz { | 13567 | if horz { |
| 13275 | B128_HORZ_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 13568 | B128_HORZ_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 13276 | } else { | 13569 | } else { |
| @@ -13362,11 +13655,26 @@ pub(crate) fn encode_inter_frame( | |||
| 13362 | if hs.iter().any(|b| b.inter.is_some_and(|i| i.ref1.is_some()))) | 13655 | if hs.iter().any(|b| b.inter.is_some_and(|i| i.ref1.is_some()))) |
| 13363 | }) | 13656 | }) |
| 13364 | .count(); | 13657 | .count(); |
| 13658 | + // lane-ab128: and how many took each AB shape, in PARTITION_HORZ_A | ||
| 13659 | + // .. _VERT_B order -- the per-shape fire count its gate rows are read | ||
| 13660 | + // against. | ||
| 13661 | + let ab: [usize; 4] = std::array::from_fn(|i| { | ||
| 13662 | + blocks | ||
| 13663 | + .iter() | ||
| 13664 | + .filter(|q| matches!(q, Quadrant::Ab128(s, _) if *s as usize == i + 4)) | ||
| 13665 | + .count() | ||
| 13666 | + }); | ||
| 13365 | eprintln!( | 13667 | eprintln!( |
| 13366 | "B128 census: inter frame, {whole} whole 128x128 roots ({residual} with a residual, \ | 13668 | "B128 census: inter frame, {whole} whole 128x128 roots ({residual} with a residual, \ |
| 13367 | {compound} compound), {horz} HORZ + {vert} VERT roots ({rect_compound} with a \ | 13669 | {compound} compound), {horz} HORZ + {vert} VERT roots ({rect_compound} with a \ |
| 13368 | - compound half), {roots} coded blocks ({:.1}% of the frame's area at 128)", | 13670 | + compound half), AB roots {}/{}/{}/{} (HORZ_A/HORZ_B/VERT_A/VERT_B), \ |
| 13369 | - 100.0 * ((whole + horz + vert) * 16) as f64 / blocks.len().max(1) as f64, | 13671 | + {roots} coded blocks ({:.1}% of the frame's area at 128)", |
| 13672 | + ab[0], | ||
| 13673 | + ab[1], | ||
| 13674 | + ab[2], | ||
| 13675 | + ab[3], | ||
| 13676 | + 100.0 * ((whole + horz + vert + ab.iter().sum::<usize>()) * 16) as f64 | ||
| 13677 | + / blocks.len().max(1) as f64, | ||
| 13370 | ); | 13678 | ); |
| 13371 | } | 13679 | } |
| 13372 | let modes = blocks | 13680 | let modes = blocks |
| @@ -16977,6 +17285,97 @@ mod tests { | |||
| 16977 | ); | 17285 | ); |
| 16978 | } | 17286 | } |
| 16979 | 17287 | ||
| 17288 | + /// lane-ab128: the 128 root's four AB shapes -- `PARTITION_HORZ_A` (two | ||
| 17289 | + /// 64x64 on top, one 128x64 below), `_HORZ_B`, `_VERT_A`, `_VERT_B`. | ||
| 17290 | + /// Five passes over the same `testsrc2` clip | ||
| 17291 | + /// `a_128_root_horz_and_vert_halves_decode_exact_through_both_decoders` | ||
| 17292 | + /// uses: each shape forced at every root ([`force_b128_ab`]), so every | ||
| 17293 | + /// context and every visit order the shape reads is exercised rather than | ||
| 17294 | + /// the handful the RD would pick, and then an UNFORCED pass whose | ||
| 17295 | + /// per-shape count is REPORTED (it is the number the gate rows are read | ||
| 17296 | + /// against). | ||
| 17297 | + /// | ||
| 17298 | + /// Each pass is sample-exact against the encoder's own reconstruction | ||
| 17299 | + /// through `decode_stream` AND through ffmpeg; a writer/reader mismatch | ||
| 17300 | + /// surfaces here as a refusal or a pixel miss, never in the BD gate. RED | ||
| 17301 | + /// before this lane by construction: `write_sb128_root` could only name | ||
| 17302 | + /// NONE / HORZ / VERT / SPLIT, so all four counts were 0. | ||
| 17303 | + /// | ||
| 17304 | + /// cargo test -p ec-av1 --release --lib -- --ignored \ | ||
| 17305 | + /// a_128_root_ab_shapes --nocapture | ||
| 17306 | + #[test] | ||
| 17307 | + #[ignore = "sets the process-global superblock size: run it alone"] | ||
| 17308 | + fn a_128_root_ab_shapes_decode_exact_through_both_decoders() { | ||
| 17309 | + let _knobs = crate::speed::knob_write(); | ||
| 17310 | + if !have_ffmpeg() { | ||
| 17311 | + eprintln!("SKIP: no ffmpeg"); | ||
| 17312 | + return; | ||
| 17313 | + } | ||
| 17314 | + force_sb128(true); | ||
| 17315 | + let dir = std::env::temp_dir().join(format!("ec-av1-ab128-{}", std::process::id())); | ||
| 17316 | + std::fs::create_dir_all(&dir).unwrap(); | ||
| 17317 | + let clip = dir.join("testsrc2-1280x768.y4m"); | ||
| 17318 | + let ok = Command::new("ffmpeg") | ||
| 17319 | + .args(["-v", "error", "-y", "-f", "lavfi"]) | ||
| 17320 | + .args(["-i", "testsrc2=size=1280x768:rate=24"]) | ||
| 17321 | + .args(["-frames:v", "12", "-pix_fmt", "yuv420p"]) | ||
| 17322 | + .arg(&clip) | ||
| 17323 | + .status() | ||
| 17324 | + .expect("ffmpeg failed to run") | ||
| 17325 | + .success(); | ||
| 17326 | + assert!(ok, "ffmpeg could not write the synthetic clip"); | ||
| 17327 | + let (width, height) = (1280usize, 768usize); | ||
| 17328 | + let pictures = | ||
| 17329 | + crate::probe::source(clip.to_str().unwrap(), "0", "null", width, height, 12); | ||
| 17330 | + let names = ["HORZ_A", "HORZ_B", "VERT_A", "VERT_B"]; | ||
| 17331 | + let mut unforced = [0usize; 4]; | ||
| 17332 | + for force in [4u8, 5, 6, 7, 0] { | ||
| 17333 | + force_b128_ab(force); | ||
| 17334 | + let label = if force == 0 { "unforced" } else { names[usize::from(force) - 4] }; | ||
| 17335 | + let _ = take_b128_ab_hits(); | ||
| 17336 | + let _ = crate::tile::take_sb128_ab_hits(); | ||
| 17337 | + let encoded = encode_sequence(&pictures, 150, 0.5).unwrap(); | ||
| 17338 | + let won = take_b128_ab_hits(); | ||
| 17339 | + let coded = crate::tile::take_sb128_ab_hits(); | ||
| 17340 | + eprintln!( | ||
| 17341 | + "{label}: search won {won:?} AB roots, writer coded {coded:?} \ | ||
| 17342 | + (HORZ_A/HORZ_B/VERT_A/VERT_B)" | ||
| 17343 | + ); | ||
| 17344 | + if force == 0 { | ||
| 17345 | + // The unforced counts are REPORTED, not asserted: a zero here | ||
| 17346 | + // would be an RD result, not a defect (the four forced passes | ||
| 17347 | + // already prove the writer and the reader agree on the shape). | ||
| 17348 | + unforced = won; | ||
| 17349 | + } else { | ||
| 17350 | + let i = usize::from(force) - 4; | ||
| 17351 | + assert!(coded[i] > 0, "no {label} root was coded with {label} forced"); | ||
| 17352 | + } | ||
| 17353 | + let decoded = crate::stream::decode_stream(&encoded.stream).expect("our decoder"); | ||
| 17354 | + assert_eq!(decoded.len(), encoded.frames.len(), "{label}: frame count"); | ||
| 17355 | + for (i, (frame, dec)) in encoded.frames.iter().zip(&decoded).enumerate() { | ||
| 17356 | + for (plane, got, want) in [ | ||
| 17357 | + ("luma", &dec.y, &frame.reconstruction.y), | ||
| 17358 | + ("U", &dec.u, &frame.reconstruction.u), | ||
| 17359 | + ("V", &dec.v, &frame.reconstruction.v), | ||
| 17360 | + ] { | ||
| 17361 | + let differ = got.iter().zip(want.iter()).filter(|(a, b)| a != b).count(); | ||
| 17362 | + assert_eq!(differ, 0, "{label} frame {i}: {plane} -- {differ} samples differ"); | ||
| 17363 | + } | ||
| 17364 | + } | ||
| 17365 | + let ff = ffmpeg_decode_sequence(&encoded.stream, width, height, pictures.len()); | ||
| 17366 | + for (i, (frame, dec)) in encoded.frames.iter().zip(&ff).enumerate() { | ||
| 17367 | + assert_eq!(dec.y, frame.reconstruction.y, "{label} frame {i}: ffmpeg luma"); | ||
| 17368 | + assert_eq!(dec.u, frame.reconstruction.u, "{label} frame {i}: ffmpeg U"); | ||
| 17369 | + assert_eq!(dec.v, frame.reconstruction.v, "{label} frame {i}: ffmpeg V"); | ||
| 17370 | + } | ||
| 17371 | + } | ||
| 17372 | + force_b128_ab(0); | ||
| 17373 | + eprintln!( | ||
| 17374 | + "unforced on testsrc2 over 12 frames: {} HORZ_A + {} HORZ_B + {} VERT_A + {} VERT_B", | ||
| 17375 | + unforced[0], unforced[1], unforced[2], unforced[3], | ||
| 17376 | + ); | ||
| 17377 | + } | ||
| 17378 | + | ||
| 16980 | #[test] | 17379 | #[test] |
| 16981 | #[ignore = "sets the process-global superblock size: run it alone"] | 17380 | #[ignore = "sets the process-global superblock size: run it alone"] |
| 16982 | fn a_128_superblock_clip_whose_drl_index_the_write_time_stack_cannot_carry_decodes_exact() { | 17381 | fn a_128_superblock_clip_whose_drl_index_the_write_time_stack_cannot_carry_decodes_exact() { |
crates/ec-av1/src/tile.rsmodified+77 -7
| @@ -617,9 +617,12 @@ fn write_inter_block_128_rect( | |||
| 617 | if let Some(r1) = info.ref1 { | 617 | if let Some(r1) = info.ref1 { |
| 618 | neighbours.record_compound_rect_mi((mi_r, mi_c), (w, h), r1, 0, 1); | 618 | neighbours.record_compound_rect_mi((mi_r, mi_c), (w, h), r1, 0, 1); |
| 619 | } | 619 | } |
| 620 | + // lane-ab128: an AB shape codes its two 64x64 pieces through this same | ||
| 621 | + // function, and they are neither a 128x64 nor a 64x128 half -- the | ||
| 622 | + // witness reads these two counters for the HORZ/VERT shape alone. | ||
| 620 | if w > h { | 623 | if w > h { |
| 621 | SB128_HORZ_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 624 | SB128_HORZ_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 622 | - } else { | 625 | + } else if h > w { |
| 623 | SB128_VERT_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 626 | SB128_VERT_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 624 | } | 627 | } |
| 625 | Ok(()) | 628 | Ok(()) |
| @@ -642,6 +645,17 @@ pub fn take_sb128_vert_hits() -> usize { | |||
| 642 | SB128_VERT_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) | 645 | SB128_VERT_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) |
| 643 | } | 646 | } |
| 644 | 647 | ||
| 648 | +/// lane-ab128: how many AB-shape roots the inter writer has coded since the | ||
| 649 | +/// last [`take_sb128_ab_hits`], in `PARTITION_HORZ_A` .. `_VERT_B` order | ||
| 650 | +/// (class `gate-blind-to-feature`). | ||
| 651 | +static SB128_AB_HITS: [std::sync::atomic::AtomicUsize; 4] = | ||
| 652 | + [const { std::sync::atomic::AtomicUsize::new(0) }; 4]; | ||
| 653 | + | ||
| 654 | +/// The four per-shape AB-root counts since the last call, and zero them. | ||
| 655 | +pub fn take_sb128_ab_hits() -> [usize; 4] { | ||
| 656 | + std::array::from_fn(|i| SB128_AB_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed)) | ||
| 657 | +} | ||
| 658 | + | ||
| 645 | /// lane-b128r: how many of those blocks carried a REAL residual (four | 659 | /// lane-b128r: how many of those blocks carried a REAL residual (four |
| 646 | /// TX_64X64 luma units plus their per-chunk chroma pair) rather than being | 660 | /// TX_64X64 luma units plus their per-chunk chroma pair) rather than being |
| 647 | /// skipped, since the last [`take_sb128_residual_hits`]. | 661 | /// skipped, since the last [`take_sb128_residual_hits`]. |
| @@ -2594,6 +2608,17 @@ pub enum Quadrant { | |||
| 2594 | /// SKIP only ([`crate::tile::write_inter_block_128_rect`] refuses a | 2608 | /// SKIP only ([`crate::tile::write_inter_block_128_rect`] refuses a |
| 2595 | /// residual), single reference or compound. | 2609 | /// residual), single reference or compound. |
| 2596 | Rect128(bool, Vec<BlockCoeffs>), | 2610 | Rect128(bool, Vec<BlockCoeffs>), |
| 2611 | + /// lane-ab128: the THREE inter blocks an AB shape at a 128 superblock | ||
| 2612 | + /// root carries -- two 64x64 pieces and one 128x64 / 64x128 half -- in | ||
| 2613 | + /// the order the decoder reads them | ||
| 2614 | + /// ([`crate::encode::ab128_pieces`]). The `u8` is the partition symbol | ||
| 2615 | + /// itself (4 `PARTITION_HORZ_A` .. 7 `PARTITION_VERT_B`). Carried by the | ||
| 2616 | + /// top-left 32x32 entry of the root's sixteen, exactly as | ||
| 2617 | + /// [`Rect128`](Quadrant::Rect128) is. | ||
| 2618 | + /// | ||
| 2619 | + /// SKIP only, same writer ([`crate::tile::write_inter_block_128_rect`]) | ||
| 2620 | + /// and same reason. | ||
| 2621 | + Ab128(u8, Vec<BlockCoeffs>), | ||
| 2597 | /// A quadrant a [`Whole64`](Quadrant::Whole64) at its superblock's | 2622 | /// A quadrant a [`Whole64`](Quadrant::Whole64) at its superblock's |
| 2598 | /// top-left already coded; it carries no block of its own. | 2623 | /// top-left already coded; it carries no block of its own. |
| 2599 | Covered, | 2624 | Covered, |
| @@ -2606,7 +2631,9 @@ impl Quadrant { | |||
| 2606 | Quadrant::Whole(block) | Quadrant::Whole64(block) | Quadrant::Whole128(block) => { | 2631 | Quadrant::Whole(block) | Quadrant::Whole64(block) | Quadrant::Whole128(block) => { |
| 2607 | std::slice::from_ref(block) | 2632 | std::slice::from_ref(block) |
| 2608 | } | 2633 | } |
| 2609 | - Quadrant::Split(blocks) | Quadrant::Rect128(_, blocks) => blocks.as_slice(), | 2634 | + Quadrant::Split(blocks) |
| 2635 | + | Quadrant::Rect128(_, blocks) | ||
| 2636 | + | Quadrant::Ab128(_, blocks) => blocks.as_slice(), | ||
| 2610 | Quadrant::Covered => &[], | 2637 | Quadrant::Covered => &[], |
| 2611 | } | 2638 | } |
| 2612 | } | 2639 | } |
| @@ -3742,6 +3769,7 @@ pub(crate) fn sb_coeff_key_frame_tile_cdfs( | |||
| 3742 | Quadrant::Whole64(_) | 3769 | Quadrant::Whole64(_) |
| 3743 | | Quadrant::Whole128(_) | 3770 | | Quadrant::Whole128(_) |
| 3744 | | Quadrant::Rect128(..) | 3771 | | Quadrant::Rect128(..) |
| 3772 | + | Quadrant::Ab128(..) | ||
| 3745 | | Quadrant::Covered => { | 3773 | | Quadrant::Covered => { |
| 3746 | return Err(Error::unsupported( | 3774 | return Err(Error::unsupported( |
| 3747 | "AV1 tile", | 3775 | "AV1 tile", |
| @@ -5410,7 +5438,9 @@ pub(crate) fn predicted_coeff_bits(blocks: &[Quadrant], base_q_idx: u8) -> f64 { | |||
| 5410 | // lane-b128: a 128x128 root is SKIP by construction (the | 5438 | // lane-b128: a 128x128 root is SKIP by construction (the |
| 5411 | // writer refuses a residual at that size), so it names no | 5439 | // writer refuses a residual at that size), so it names no |
| 5412 | // coefficients on any plane. | 5440 | // coefficients on any plane. |
| 5413 | - Quadrant::Whole128(_) | Quadrant::Rect128(..) => return 0.0, | 5441 | + Quadrant::Whole128(_) | Quadrant::Rect128(..) | Quadrant::Ab128(..) => { |
| 5442 | + return 0.0; | ||
| 5443 | + } | ||
| 5414 | Quadrant::Whole(_) => 32, | 5444 | Quadrant::Whole(_) => 32, |
| 5415 | Quadrant::Split(_) => 16, | 5445 | Quadrant::Split(_) => 16, |
| 5416 | // lane-tx64: a 64x64 root that codes a residual pays for one | 5446 | // lane-tx64: a 64x64 root that codes a residual pays for one |
| @@ -7141,6 +7171,12 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 7141 | Quadrant::Rect128(horz, halves) => Some((*horz, halves)), | 7171 | Quadrant::Rect128(horz, halves) => Some((*horz, halves)), |
| 7142 | _ => None, | 7172 | _ => None, |
| 7143 | }); | 7173 | }); |
| 7174 | + // lane-ab128: the three pieces an AB-shape root carries, and the | ||
| 7175 | + // partition symbol it is coded under. | ||
| 7176 | + let root_ab = root_entry.and_then(|q| match q { | ||
| 7177 | + Quadrant::Ab128(symbol, pieces) => Some((*symbol as usize, pieces)), | ||
| 7178 | + _ => None, | ||
| 7179 | + }); | ||
| 7144 | write_sb128_root( | 7180 | write_sb128_root( |
| 7145 | &mut enc, | 7181 | &mut enc, |
| 7146 | &mut cdfs, | 7182 | &mut cdfs, |
| @@ -7149,10 +7185,11 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 7149 | sb_c, | 7185 | sb_c, |
| 7150 | mi_cols, | 7186 | mi_cols, |
| 7151 | mi_rows, | 7187 | mi_rows, |
| 7152 | - match (root_block.is_some(), root_rect) { | 7188 | + match (root_block.is_some(), root_rect, root_ab) { |
| 7153 | - (true, _) => PARTITION_NONE, | 7189 | + (true, ..) => PARTITION_NONE, |
| 7154 | - (_, Some((true, _))) => PARTITION_HORZ, | 7190 | + (_, Some((true, _)), _) => PARTITION_HORZ, |
| 7155 | - (_, Some((false, _))) => PARTITION_VERT, | 7191 | + (_, Some((false, _)), _) => PARTITION_VERT, |
| 7192 | + (_, _, Some((symbol, _))) => symbol, | ||
| 7156 | _ => PARTITION_SPLIT, | 7193 | _ => PARTITION_SPLIT, |
| 7157 | }, | 7194 | }, |
| 7158 | ); | 7195 | ); |
| @@ -7201,6 +7238,38 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 7201 | sb128_none = true; | 7238 | sb128_none = true; |
| 7202 | continue; | 7239 | continue; |
| 7203 | } | 7240 | } |
| 7241 | + if let Some((symbol, pieces)) = root_ab { | ||
| 7242 | + // libaom `decode_partition` at BLOCK_128X128, AB arm: two | ||
| 7243 | + // 64x64 blocks and one 128x64 / 64x128 half, in the order | ||
| 7244 | + // decode.rs' `sb128_ab` reads them | ||
| 7245 | + // ([`crate::encode::ab128_pieces`]). An AB shape only comes | ||
| 7246 | + // from the full alphabet symbol (both halves in frame), so | ||
| 7247 | + // there is no edge break to mirror -- the search offers one | ||
| 7248 | + // only at a root wholly inside. | ||
| 7249 | + let base_mi = ( | ||
| 7250 | + (sb_r & !1) as usize * SB_MI as usize, | ||
| 7251 | + (sb_c & !1) as usize * SB_MI as usize, | ||
| 7252 | + ); | ||
| 7253 | + for (((mi_r, mi_c), (w, h)), piece) in | ||
| 7254 | + crate::encode::ab128_pieces(symbol, base_mi).iter().zip(pieces) | ||
| 7255 | + { | ||
| 7256 | + write_inter_block_128_rect( | ||
| 7257 | + &mut enc, | ||
| 7258 | + &mut cdfs, | ||
| 7259 | + &mut neighbours, | ||
| 7260 | + &mut grid, | ||
| 7261 | + (*mi_r, *mi_c), | ||
| 7262 | + (*w, *h), | ||
| 7263 | + piece, | ||
| 7264 | + mi_cols, | ||
| 7265 | + mi_rows, | ||
| 7266 | + tx_select, | ||
| 7267 | + )?; | ||
| 7268 | + } | ||
| 7269 | + SB128_AB_HITS[symbol - 4].fetch_add(1, std::sync::atomic::Ordering::Relaxed); | ||
| 7270 | + sb128_none = true; | ||
| 7271 | + continue; | ||
| 7272 | + } | ||
| 7204 | } | 7273 | } |
| 7205 | { | 7274 | { |
| 7206 | if !sb128 { | 7275 | if !sb128 { |
| @@ -7449,6 +7518,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 7449 | Quadrant::Whole64(_) | 7518 | Quadrant::Whole64(_) |
| 7450 | | Quadrant::Whole128(_) | 7519 | | Quadrant::Whole128(_) |
| 7451 | | Quadrant::Rect128(..) | 7520 | | Quadrant::Rect128(..) |
| 7521 | + | Quadrant::Ab128(..) | ||
| 7452 | | Quadrant::Covered => { | 7522 | | Quadrant::Covered => { |
| 7453 | return Err(Error::unsupported( | 7523 | return Err(Error::unsupported( |
| 7454 | "AV1 tile", | 7524 | "AV1 tile", |
lanes/ab128.report.mdadded+156 -0
| @@ -0,0 +1,156 @@ | |||
| 1 | +# lane-ab128 — the four AB shapes at the 128 superblock root | ||
| 2 | + | ||
| 3 | +`PARTITION_HORZ_A` (two 64x64 on top, one 128x64 below), `_HORZ_B` (one | ||
| 4 | +128x64 on top, two 64x64 below), `_VERT_A` (two 64x64 left, one 64x128 | ||
| 5 | +right), `_VERT_B` (one 64x128 left, two 64x64 right) are written, witnessed | ||
| 6 | +sample-exact through `decode_stream` AND ffmpeg on all four shapes, and | ||
| 7 | +measured on both gates. **They ship OFF** (`EC_AV1_B128AB=1` turns them on): | ||
| 8 | +every gate row is flat or 0.1 worse. The lane's value is the measurement and | ||
| 9 | +the machinery, not a shipped default. | ||
| 10 | + | ||
| 11 | +## 1. What was built | ||
| 12 | + | ||
| 13 | +* `crate::encode::ab128_pieces(symbol, (mi_row, mi_col))` — the three pieces | ||
| 14 | + of a shape, position and footprint, in libaom's `decode_partition` order | ||
| 15 | + and decode.rs' `sb128_ab` order (decode.rs ~35269): HORZ_A = TL, TR, bottom | ||
| 16 | + half; HORZ_B = top half, BL, BR; VERT_A = TL, BL, right half; VERT_B = left | ||
| 17 | + half, TR, BR. One table, read by the search, by the writer and by the | ||
| 18 | + winner's grid publication, so the three cannot drift (class | ||
| 19 | + *table and reader move together*). | ||
| 20 | +* `search_root_128_ab` — the three pieces priced through the same | ||
| 21 | + `search_skip_64` the NONE and HORZ/VERT arms use, each at its own | ||
| 22 | + footprint, each published into the mi grid (`record_mi_rect`) before the | ||
| 23 | + next is searched and the whole 32x32-mi window restored with | ||
| 24 | + `MiGrid::snapshot_rect`/`restore_rect` before returning (class | ||
| 25 | + *encoder-grid-drift-invisible-to-pixel-gate*). The cost carries the root's | ||
| 26 | + own `partition_bits_sym(128, symbol)`. | ||
| 27 | +* `Quadrant::Ab128(symbol, pieces)` on the root's top-left 32x32 entry, the | ||
| 28 | + fifteen others `Covered` — exactly as `Rect128` does. | ||
| 29 | +* The writer needed **no new block function**: a 64x64 AB piece is one inter | ||
| 30 | + block coded at side 64 with `write_w == write_h == 64`, and a half is the | ||
| 31 | + 128x64/64x128 `write_inter_block_128_rect` already codes. All three go | ||
| 32 | + through `write_inter_block_128_rect` at their own `(w, h)`. | ||
| 33 | +* `EC_AV1_B128AB` (default off), `force_b128_ab` (test knob, 0 or the | ||
| 34 | + partition symbol 4..=7), per-shape search and writer counters, and the | ||
| 35 | + `EC_AV1_B128_CENSUS` line extended with `AB roots a/b/c/d`. | ||
| 36 | + | ||
| 37 | +## 2. Charter premises checked against the code | ||
| 38 | + | ||
| 39 | +* **"decide whether the 64 pieces of an AB shape run the full 64-root search | ||
| 40 | + or the skip-64 search, and justify by measurement; the full search is what | ||
| 41 | + libaom does" — refuted by the syntax, so nothing to measure.** decode.rs' | ||
| 42 | + `sb128_ab` codes each 64x64 piece as ONE `decode_inter_block` at | ||
| 43 | + `side = SB` with no partition symbol of its own (`square64_inter!`), which | ||
| 44 | + is libaom's own AB shape: an AB piece is a whole block, never a | ||
| 45 | + further-partitionable root. A "full 64-root search" candidate could not be | ||
| 46 | + written at all. The pieces are `search_skip_64` at (64, 64), skip-only, for | ||
| 47 | + the same reason `search_root_128_rect`'s halves are: the 128 residual arm | ||
| 48 | + they would share is parked behind `EC_AV1_B128RES`. | ||
| 49 | +* **"Extend `cdef_unit_owner` for the two-unit shape and the four-way | ||
| 50 | + `pick_filters` grouping" — not needed, and NOT done (rung 1: it would be | ||
| 51 | + dead code).** `write_cdef_idx` writes a literal only for a NON-SKIP block; | ||
| 52 | + every AB piece and every HORZ/VERT half is skip, so such a root puts no | ||
| 53 | + `cdef_idx` in the stream at all and CDEF filters none of its (all-skip) | ||
| 54 | + units. `cdef_unit_owner` collapses units only for `Whole128`, which is the | ||
| 55 | + one 128-wide shape that can carry a residual (`EC_AV1_B128RES`). The same | ||
| 56 | + reasoning covers `Rect128`, which lane-b128hv also left out of the map — | ||
| 57 | + swept and confirmed inert, not a sibling defect. The day a piece carries a | ||
| 58 | + residual, `cdef_unit_owner` must learn `Rect128` and `Ab128` in the SAME | ||
| 59 | + diff; that is named as the constraint below. | ||
| 60 | +* `write_delta_q` needed no change: it already gates on the block's own | ||
| 61 | + position within the (128-wide) superblock, and no AB piece is the whole | ||
| 62 | + superblock, so `is_whole_sb = false` — what `write_inter_block_128_rect` | ||
| 63 | + passes — is right for all three. `intrabc_dv_pred` is intra-frame only and | ||
| 64 | + this is the inter writer. | ||
| 65 | +* The charter's witness fixtures ("4K bars + film B 12-frame fixtures used by | ||
| 66 | + `a_128_root_horz_and_vert_halves_decode_exact_through_both_decoders`") are | ||
| 67 | + stale: that test encodes ONE synthetic `testsrc2` 1280x768 12-frame clip. | ||
| 68 | + The AB witness mirrors it exactly. | ||
| 69 | + | ||
| 70 | +## 3. Witness | ||
| 71 | + | ||
| 72 | +`encode::tests::a_128_root_ab_shapes_decode_exact_through_both_decoders` | ||
| 73 | +(`--ignored`), five passes over the same clip — each shape forced at every | ||
| 74 | +root, then unforced: | ||
| 75 | + | ||
| 76 | + HORZ_A: search won [660, 0, 0, 0] writer coded [1320, 0, 0, 0] | ||
| 77 | + HORZ_B: search won [0, 660, 0, 0] writer coded [0, 1320, 0, 0] | ||
| 78 | + VERT_A: search won [0, 0, 660, 0] writer coded [0, 0, 1320, 0] | ||
| 79 | + VERT_B: search won [0, 0, 0, 660] writer coded [0, 0, 0, 660*2] | ||
| 80 | + unforced: search won [0, 0, 1, 1] writer coded [0, 0, 2, 2] | ||
| 81 | + | ||
| 82 | +Every pass sample-exact against the encoder's own reconstruction through | ||
| 83 | +`decode_stream` and through ffmpeg, first run, no bisect needed. RED before | ||
| 84 | +this lane by construction: `write_sb128_root` could name only NONE / HORZ / | ||
| 85 | +VERT / SPLIT. | ||
| 86 | + | ||
| 87 | +## 4. Census on real content (`EC_AV1_B128_CENSUS=1`, long-GOP films) | ||
| 88 | + | ||
| 89 | +171 inter frames: a typical frame is `7 whole 128 roots, 0-1 HORZ + 0-1 VERT, | ||
| 90 | +AB roots 0/0/0/1`, out of ~1050-1900 coded blocks. 44 of 171 frames took no | ||
| 91 | +AB root at all; the modal non-zero frame takes exactly one. The shapes are | ||
| 92 | +real but rare — which is the whole BD result below. | ||
| 93 | + | ||
| 94 | +## 5. Gates (arm = default-on build, control = `EC_AV1_B128AB=0`; lower is better) | ||
| 95 | + | ||
| 96 | +12-frame `bd_rate_screen_native` (`~/.cache/ab128/12arm.log`, `12ctl.log`): | ||
| 97 | + | ||
| 98 | +| row | arm vs libaom | ctl vs libaom | arm vs rav1e | ctl vs rav1e | | ||
| 99 | +| --- | --- | --- | --- | --- | | ||
| 100 | +| bars 1080p | -3.4% | -3.4% | -19.0% | -19.0% | | ||
| 101 | +| bars 2160p | +8.4% | +8.4% | -14.0% | -14.0% | | ||
| 102 | +| film A | +18.1% | +18.0% | -6.2% | -6.3% | | ||
| 103 | +| film B | +23.1% | +23.0% | -3.3% | -3.5% | | ||
| 104 | +| screen | +14.4% | +14.4% | -33.2% | -33.2% | | ||
| 105 | + | ||
| 106 | +Long-GOP `bd_rate_film_long_gop` — the deciding gate (`lgarm.log`, | ||
| 107 | +`lgctl.log`): | ||
| 108 | + | ||
| 109 | +| row | arm vs libaom | ctl vs libaom | arm vs rav1e | ctl vs rav1e | | ||
| 110 | +| --- | --- | --- | --- | --- | | ||
| 111 | +| film A | +22.0% | +21.9% | -8.5% | -8.6% | | ||
| 112 | +| film B | +75.8% | +75.8% | +0.8% | +0.8% | | ||
| 113 | + | ||
| 114 | +Wall (both arms run concurrently, so the contention is shared): long-GOP | ||
| 115 | +706.6 + 520.0 = 1226.6 s arm against 665.0 + 463.5 = 1128.5 s control, | ||
| 116 | +**+8.7%** — inside the +15% ceiling, but bought for nothing. | ||
| 117 | + | ||
| 118 | +**Keep rule: FAILED.** It asks for both film rows down on both columns, or | ||
| 119 | +one >= 0.5 down with the other flat. Film A is 0.1 WORSE on both columns, | ||
| 120 | +film B is unchanged to the decimal. The candidate costs a partition symbol on | ||
| 121 | +every root it wins and buys back less than it spends. Shipped off. | ||
| 122 | + | ||
| 123 | +Known under-pricing shared with lane-b128hv (unchanged by this lane): a | ||
| 124 | +non-origin AB piece codes no `delta_q` group, but the piece AT the superblock | ||
| 125 | +origin does, and nothing here prices it — lane-rectdq is adding the | ||
| 126 | +`delta_q_bits` pricer. The mispricing is under a bit per root and is the same | ||
| 127 | +for the rect arm, so it cannot explain a 0.1 BD miss on its own. | ||
| 128 | + | ||
| 129 | +## 6. Suite, pins, checks | ||
| 130 | + | ||
| 131 | +* Pins: `encode::tests::the_encoders_own_streams_are_byte_identical_to_their_pins` | ||
| 132 | + green at default and at `EC_AV1_SPEED=6`, **unmoved** (`pins2.log`) — the | ||
| 133 | + arm is off by default, so the default encoder is byte-identical to main's. | ||
| 134 | +* `--ignored --exact encoder::tests::every_speed_preset_decodes_sample_exact_through_both_decoders`: ok. | ||
| 135 | +* `--ignored` HORZ/VERT witness (lane-b128hv's): ok, unaffected by the | ||
| 136 | + counter split (a 64x64 piece no longer counts as a "64x128 half"). | ||
| 137 | +* Suite in three lanes, all green: `-- --skip stream::` 345 passed / 0 | ||
| 138 | + failed / 40 ignored; `-- stream:: --skip 10bit` 202 / 0 / 15; `-- 10bit` | ||
| 139 | + 42 / 0 / 1. | ||
| 140 | +* `timeout 900 cargo check --workspace --all-targets -j4`: 0 errors, 0 | ||
| 141 | + ec-av1 warnings (the 22 warnings in the log are pre-existing ec-opus / | ||
| 142 | + ec-vorbis ones). | ||
| 143 | + | ||
| 144 | +## 7. Disposition | ||
| 145 | + | ||
| 146 | +* `deferred: a non-skip AB piece` — the 64x64 pieces could carry the 64 | ||
| 147 | + root's own residual (`b64_residual`), which is where libaom's AB shapes | ||
| 148 | + earn their keep; the skip-only pieces here can only ever move the partition | ||
| 149 | + price. Unblocked by nothing but a lane: the residual writer at 64 exists | ||
| 150 | + (`Whole64`), it is the piece's `search_skip_64(.., residual = true)` call | ||
| 151 | + and the `write_inter_block_128_rect` refusal that would have to move — | ||
| 152 | + together with `cdef_unit_owner` learning `Rect128` and `Ab128` in the SAME | ||
| 153 | + diff, since a non-skip piece writes a `cdef_idx` literal that covers two | ||
| 154 | + units for a half. | ||
| 155 | +* `accepted: the delta_q under-pricing` — shared with lane-b128hv, under a | ||
| 156 | + bit per root, lane-rectdq owns the pricer. | ||