The writer records a rectangular block's two neighbour bands, and codes a 128-root HORZ/VERT half
Browse files at this commitb52bd176bb79806982546274e6e627649966b95fParent: 53e1991- feat
- the writer records a rectangular block's two neighbour bands, and codes a 128-root HORZ/VERT half
2 changed files +463 -72
- crates/ec-av1/src/encode.rs +68 -42
- crates/ec-av1/src/tile.rs +395 -30
crates/ec-av1/src/encode.rsmodified+68 -42
| @@ -3079,6 +3079,17 @@ impl Plane<'_> { | ||
| 3079 | 3079 | rows_of(self.source, self.width, x, y, side) |
| 3080 | 3080 | } |
| 3081 | 3081 | |
| 3082 | + /// lane-b128hv: [`Self::source_block`] over a rectangle, for the 128 | |
| 3083 | + /// root's own HORZ/VERT motion search. | |
| 3084 | + fn source_block_rect(&self, x: usize, y: usize, w: usize, h: usize) -> Vec<u8> { | |
| 3085 | + let mut out = vec![0u8; w * h]; | |
| 3086 | + for row in 0..h { | |
| 3087 | + out[row * w..][..w] | |
| 3088 | + .copy_from_slice(&self.source[(y + row) * self.width + x..][..w]); | |
| 3089 | + } | |
| 3090 | + out | |
| 3091 | + } | |
| 3092 | + | |
| 3082 | 3093 | /// The reconstructed samples of one square, so that a partition trial can |
| 3083 | 3094 | /// be undone. |
| 3084 | 3095 | /// The reconstructed samples of one square AND the coefficient contexts |
| @@ -9549,7 +9560,7 @@ fn search_root_128( | ||
| 9549 | 9560 | luma, |
| 9550 | 9561 | chroma, |
| 9551 | 9562 | (x128, y128), |
| 9552 | - SIDE, | |
| 9563 | + (SIDE, SIDE), | |
| 9553 | 9564 | &root_search, |
| 9554 | 9565 | false, |
| 9555 | 9566 | reference, |
| @@ -9662,12 +9673,14 @@ fn search_skip_64( | ||
| 9662 | 9673 | luma: &mut Plane, |
| 9663 | 9674 | chroma: &mut [Plane; 2], |
| 9664 | 9675 | (x, y): (usize, usize), |
| 9665 | - // The root's side in samples: [`SUPERBLOCK`] at a 64 root, twice that at | |
| 9666 | - // the 128 one [`search_root_128`] drives (lane-b128). Every trial below | |
| 9667 | - // is a square of this side and its half in chroma, and the residual arm | |
| 9668 | - // is only ever asked for at 64 -- a 128 block's residual is four | |
| 9676 | + // The root's footprint in samples: [`SUPERBLOCK`] square at a 64 root, | |
| 9677 | + // twice that at the 128 one [`search_root_128`] drives (lane-b128), and | |
| 9678 | + // 128x64 / 64x128 at the rect halves of [`search_root_128_rect`] | |
| 9679 | + // (lane-b128hv). Every trial below tiles it into squares of its SHORTER | |
| 9680 | + // side (one square when it is square, two otherwise), and the residual | |
| 9681 | + // arm is only ever asked for at 64 -- a 128 block's residual is four | |
| 9669 | 9682 | // TX_64X64 units the writer has no path for. |
| 9670 | - side: usize, | |
| 9683 | + (bw, bh): (usize, usize), | |
| 9671 | 9684 | search: &Search, |
| 9672 | 9685 | // Whether the non-skip arm is priced at all ([`b64_residual`], and off on |
| 9673 | 9686 | // screen content -- see that function's doc). |
| @@ -9680,7 +9693,23 @@ fn search_skip_64( | ||
| 9680 | 9693 | compound: &[(i8, &Picture, crate::mvstack::CompoundMvStack)], |
| 9681 | 9694 | fctx: &crate::decode::FrameCtx, |
| 9682 | 9695 | ) -> Option<(f64, BlockCoeffs)> { |
| 9683 | - debug_assert!(side == SUPERBLOCK || !residual, "a 128 root has no residual arm"); | |
| 9696 | + debug_assert!( | |
| 9697 | + (bw, bh) == (SUPERBLOCK, SUPERBLOCK) || !residual, | |
| 9698 | + "only a 64 root has a residual arm" | |
| 9699 | + ); | |
| 9700 | + // The square units every trial below is taken on: the block itself when | |
| 9701 | + // it is square, its two halves otherwise. Luma first (in raster order), | |
| 9702 | + // then each chroma plane over the same tiling at half the side -- which is | |
| 9703 | + // exactly `[(0, x, y, side), (1, ..), (2, ..)]` at bw == bh. | |
| 9704 | + let sq = bw.min(bh); | |
| 9705 | + let units: Vec<(usize, usize, usize, usize, bool)> = (0..3usize) | |
| 9706 | + .flat_map(|plane| { | |
| 9707 | + let (ox, oy, s) = if plane == 0 { (x, y, sq) } else { (x / 2, y / 2, sq / 2) }; | |
| 9708 | + (0..bh / sq).flat_map(move |j| { | |
| 9709 | + (0..bw / sq).map(move |i| (plane, ox + i * s, oy + j * s, s, plane == 0)) | |
| 9710 | + }) | |
| 9711 | + }) | |
| 9712 | + .collect(); | |
| 9684 | 9713 | let not_new = symbol_bits(&cdf::NEW_MV[stack.new_mv_ctx], 1); |
| 9685 | 9714 | let not_zero = symbol_bits(&cdf::ZERO_MV[stack.zero_mv_ctx], 1); |
| 9686 | 9715 | let ref_bits = single_ref_bits(crate::mvstack::LAST_FRAME, stack); |
| @@ -9718,7 +9747,7 @@ fn search_skip_64( | ||
| 9718 | 9747 | // candidate below to pair with the second reference's NEAREST half. |
| 9719 | 9748 | let mut last_new_mv: Option<(i32, i32)> = None; |
| 9720 | 9749 | if leaf_new_mv() { |
| 9721 | - let source_block = luma.source_block(x, y, side); | |
| 9750 | + let source_block = luma.source_block_rect(x, y, bw, bh); | |
| 9722 | 9751 | let (seeds, seed_n) = mv_seeds(stack); |
| 9723 | 9752 | let found = motion::search( |
| 9724 | 9753 | &reference.y, |
| @@ -9728,8 +9757,8 @@ fn search_skip_64( | ||
| 9728 | 9757 | &source_block, |
| 9729 | 9758 | x, |
| 9730 | 9759 | y, |
| 9731 | - side, | |
| 9732 | - side, | |
| 9760 | + bw, | |
| 9761 | + bh, | |
| 9733 | 9762 | stack.pred_mv, |
| 9734 | 9763 | &seeds[..seed_n], |
| 9735 | 9764 | search.lambda, |
| @@ -9746,14 +9775,11 @@ fn search_skip_64( | ||
| 9746 | 9775 | } |
| 9747 | 9776 | } |
| 9748 | 9777 | |
| 9749 | - let mut best: Option<(f64, f64, InterInfo, [Trial; 3])> = None; | |
| 9778 | + let mut best: Option<(f64, f64, InterInfo, Vec<Trial>)> = None; | |
| 9750 | 9779 | for (bits, info) in cands { |
| 9751 | - let trials = [ | |
| 9752 | - (0usize, x, y, side, true), | |
| 9753 | - (1, x / 2, y / 2, side / 2, false), | |
| 9754 | - (2, x / 2, y / 2, side / 2, false), | |
| 9755 | - ] | |
| 9756 | - .map(|(plane, px, py, s, is_luma)| { | |
| 9780 | + let trials: Vec<Trial> = units | |
| 9781 | + .iter() | |
| 9782 | + .map(|&(plane, px, py, s, is_luma)| { | |
| 9757 | 9783 | let (samples, stride, w, h) = match plane { |
| 9758 | 9784 | 0 => (&reference.y, reference.width, luma.true_width, luma.true_height), |
| 9759 | 9785 | 1 => ( |
| @@ -9784,11 +9810,10 @@ fn search_skip_64( | ||
| 9784 | 9810 | search.deadzone, |
| 9785 | 9811 | TxbSet::Luma32Inter, |
| 9786 | 9812 | ) |
| 9787 | - }); | |
| 9788 | - let cost = trials[0].sse | |
| 9789 | - + trials[1].sse | |
| 9790 | - + trials[2].sse | |
| 9791 | - + search.lambda * (fixed + bits); | |
| 9813 | + }) | |
| 9814 | + .collect(); | |
| 9815 | + let cost = | |
| 9816 | + trials.iter().map(|t| t.sse).sum::<f64>() + search.lambda * (fixed + bits); | |
| 9792 | 9817 | if best.as_ref().is_none_or(|b| cost < b.0) { |
| 9793 | 9818 | best = Some((cost, fixed + bits, info, trials)); |
| 9794 | 9819 | } |
| @@ -9847,12 +9872,9 @@ fn search_skip_64( | ||
| 9847 | 9872 | ccands.sort_by(|a, b| a.0.cmp(&b.0).then(a.1.total_cmp(&b.1))); |
| 9848 | 9873 | ccands.dedup_by_key(|c| c.0); |
| 9849 | 9874 | for (mvs, bits, info) in ccands { |
| 9850 | - let trials = [ | |
| 9851 | - (0usize, x, y, side, true), | |
| 9852 | - (1, x / 2, y / 2, side / 2, false), | |
| 9853 | - (2, x / 2, y / 2, side / 2, false), | |
| 9854 | - ] | |
| 9855 | - .map(|(plane, px, py, s, is_luma)| { | |
| 9875 | + let trials: Vec<Trial> = units | |
| 9876 | + .iter() | |
| 9877 | + .map(|&(plane, px, py, s, is_luma)| { | |
| 9856 | 9878 | let (r0, r1) = match plane { |
| 9857 | 9879 | 0 => ( |
| 9858 | 9880 | (reference.y.as_slice(), reference.width, luma.true_width, luma.true_height), |
| @@ -9890,10 +9912,10 @@ fn search_skip_64( | ||
| 9890 | 9912 | search.deadzone, |
| 9891 | 9913 | TxbSet::Luma32Inter, |
| 9892 | 9914 | ) |
| 9893 | - }); | |
| 9915 | + }) | |
| 9916 | + .collect(); | |
| 9894 | 9917 | let syntax = fixed - ref_bits + bits; |
| 9895 | - let cost = | |
| 9896 | - trials[0].sse + trials[1].sse + trials[2].sse + search.lambda * syntax; | |
| 9918 | + let cost = trials.iter().map(|t| t.sse).sum::<f64>() + search.lambda * syntax; | |
| 9897 | 9919 | if best.as_ref().is_none_or(|b| cost < b.0) { |
| 9898 | 9920 | best = Some((cost, syntax, info, trials)); |
| 9899 | 9921 | } |
| @@ -9923,11 +9945,13 @@ fn search_skip_64( | ||
| 9923 | 9945 | let mut luma_levels: Option<(Vec<i32>, u8, Vec<TxType>)> = None; |
| 9924 | 9946 | if residual { |
| 9925 | 9947 | let sets = [TxbSet::Luma64, TxbSet::Chroma32, TxbSet::Chroma32]; |
| 9948 | + // Square by construction (the `debug_assert` above), so `units` is | |
| 9949 | + // one entry per plane and `chosen.2[plane]` is that plane's trial. | |
| 9926 | 9950 | let residual_trials = [0usize, 1, 2].map(|plane| { |
| 9927 | 9951 | let (target, px, py, s) = if plane == 0 { |
| 9928 | - (&*luma, x, y, side) | |
| 9952 | + (&*luma, x, y, bw) | |
| 9929 | 9953 | } else { |
| 9930 | - (&chroma[plane - 1], x / 2, y / 2, side / 2) | |
| 9954 | + (&chroma[plane - 1], x / 2, y / 2, bw / 2) | |
| 9931 | 9955 | }; |
| 9932 | 9956 | target.code_from_prediction( |
| 9933 | 9957 | px, |
| @@ -9959,7 +9983,7 @@ fn search_skip_64( | ||
| 9959 | 9983 | commit_inter_luma( |
| 9960 | 9984 | luma, |
| 9961 | 9985 | (x, y), |
| 9962 | - side, | |
| 9986 | + bw, | |
| 9963 | 9987 | info.mv, |
| 9964 | 9988 | (&reference.y, reference.width, luma.true_width, luma.true_height), |
| 9965 | 9989 | search, |
| @@ -9980,18 +10004,20 @@ fn search_skip_64( | ||
| 9980 | 10004 | B64_VAR_TX_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 9981 | 10005 | } |
| 9982 | 10006 | luma_levels = Some((levels, depth, tx_types)); |
| 9983 | - chosen = (cost, false, residual_trials); | |
| 10007 | + chosen = (cost, false, residual_trials.to_vec()); | |
| 9984 | 10008 | } |
| 9985 | 10009 | } |
| 9986 | 10010 | |
| 9987 | 10011 | let (cost, skip, trials) = chosen; |
| 9988 | 10012 | // `commit_inter_luma` already wrote the residual arm's luma (its four |
| 9989 | 10013 | // split units are not one 64-sided trial); a skip winner overwrites it. |
| 9990 | - if skip || !luma_committed { | |
| 9991 | - luma.commit(x, y, side, &trials[0]); | |
| 10014 | + for (&(plane, px, py, s, _), trial) in units.iter().zip(&trials) { | |
| 10015 | + match plane { | |
| 10016 | + 0 if skip || !luma_committed => luma.commit(px, py, s, trial), | |
| 10017 | + 0 => {} | |
| 10018 | + _ => chroma[plane - 1].commit(px, py, s, trial), | |
| 10019 | + } | |
| 9992 | 10020 | } |
| 9993 | - chroma[0].commit(x / 2, y / 2, side / 2, &trials[1]); | |
| 9994 | - chroma[1].commit(x / 2, y / 2, side / 2, &trials[2]); | |
| 9995 | 10021 | Some(( |
| 9996 | 10022 | cost, |
| 9997 | 10023 | BlockCoeffs { |
| @@ -10011,8 +10037,8 @@ fn search_skip_64( | ||
| 10011 | 10037 | (false, Some((levels, _, _))) => coeffs(levels, BLOCK), |
| 10012 | 10038 | (false, None) => coeffs(&trials[0].levels, BLOCK), |
| 10013 | 10039 | }, |
| 10014 | - u: if skip { Vec::new() } else { coeffs(&trials[1].levels, side / 2) }, | |
| 10015 | - v: if skip { Vec::new() } else { coeffs(&trials[2].levels, side / 2) }, | |
| 10040 | + u: if skip { Vec::new() } else { coeffs(&trials[1].levels, bw / 2) }, | |
| 10041 | + v: if skip { Vec::new() } else { coeffs(&trials[2].levels, bw / 2) }, | |
| 10016 | 10042 | ..BlockCoeffs::default() |
| 10017 | 10043 | }, |
| 10018 | 10044 | )) |
| @@ -12462,7 +12488,7 @@ pub(crate) fn encode_inter_frame( | ||
| 12462 | 12488 | &mut luma, |
| 12463 | 12489 | &mut chroma, |
| 12464 | 12490 | (x64, y64), |
| 12465 | - SUPERBLOCK, | |
| 12491 | + (SUPERBLOCK, SUPERBLOCK), | |
| 12466 | 12492 | &sb_search, |
| 12467 | 12493 | b64_residual() && !screen, |
| 12468 | 12494 | reference, |
crates/ec-av1/src/tile.rsmodified+395 -30
| @@ -464,6 +464,184 @@ fn write_inter_block_128( | ||
| 464 | 464 | Ok(()) |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | +/// lane-b128hv: one 128x64 (HORZ) or 64x128 (VERT) inter block, the two | |
| 468 | +/// halves a `PARTITION_HORZ`/`PARTITION_VERT` 128 superblock root carries -- | |
| 469 | +/// the syntax `decode_inter_block` reads for `sb128_rect` (decode.rs ~35343): | |
| 470 | +/// the same chain [`write_inter_block_128`] writes, at the block's own | |
| 471 | +/// rectangular window. Every CDF/context decision is taken at the enclosing | |
| 472 | +/// square `side` of 128 (what the decoder's `inter_piece!` passes), and the | |
| 473 | +/// block's true footprint governs only its mv-stack window, its mi/grid stamp | |
| 474 | +/// and its neighbour bands (decode.rs' own `write_w`/`write_h` split). | |
| 475 | +/// | |
| 476 | +/// SKIP only: the decoder reads a rect half's residual through the mu-chunk | |
| 477 | +/// loop, but the 128 NONE residual arm it would share is itself parked | |
| 478 | +/// (`EC_AV1_B128RES`), so offering one here would buy the same open filter | |
| 479 | +/// mismatch for a candidate the RD takes 0-2 times a frame. | |
| 480 | +/// | |
| 481 | +/// # Errors | |
| 482 | +/// A block that is intra or that is not skipped. | |
| 483 | +#[allow(clippy::too_many_arguments)] | |
| 484 | +fn write_inter_block_128_rect( | |
| 485 | + enc: &mut SymbolEncoder, | |
| 486 | + cdfs: &mut Cdfs, | |
| 487 | + neighbours: &mut Neighbours, | |
| 488 | + grid: &mut MiGrid, | |
| 489 | + // The half's own top-left position in mode-info (4x4) units. | |
| 490 | + at_mi: (usize, usize), | |
| 491 | + // Its true footprint in samples: (128, 64) at HORZ, (64, 128) at VERT. | |
| 492 | + (w, h): (usize, usize), | |
| 493 | + block: &BlockCoeffs, | |
| 494 | + mi_cols: u32, | |
| 495 | + mi_rows: u32, | |
| 496 | + tx_select: bool, | |
| 497 | +) -> Result<()> { | |
| 498 | + let info = block.inter.ok_or_else(|| { | |
| 499 | + Error::unsupported("AV1 tile", "a 128-root rectangular half is coded inter") | |
| 500 | + })?; | |
| 501 | + if !block.skip { | |
| 502 | + return Err(Error::unsupported( | |
| 503 | + "AV1 tile", | |
| 504 | + "a 128-root rectangular half carries a residual", | |
| 505 | + )); | |
| 506 | + } | |
| 507 | + let (mi_r, mi_c) = at_mi; | |
| 508 | + let (w_mi, h_mi) = (w / MI, h / MI); | |
| 509 | + let has_above = neighbours.has_above(mi_r); | |
| 510 | + let has_left = neighbours.has_left(mi_c); | |
| 511 | + let skip_ctx = | |
| 512 | + usize::from(neighbours.above_skip[mi_c]) + usize::from(neighbours.left_skip[mi_r]); | |
| 513 | + enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]); | |
| 514 | + write_cdef_idx(enc, (mi_r, mi_c), block.skip); | |
| 515 | + // NOT a whole superblock: decode.rs' `whole_sb` is `write_w == write_h == | |
| 516 | + // sb_px`, so a rect half reads its `delta_q` group even when skipped. | |
| 517 | + write_delta_q(enc, cdfs, (mi_r, mi_c), false, block.skip); | |
| 518 | + let ii_ctx = intra_inter_ctx( | |
| 519 | + has_above, | |
| 520 | + has_left, | |
| 521 | + neighbours.above_inter[mi_c], | |
| 522 | + neighbours.left_inter[mi_r], | |
| 523 | + ); | |
| 524 | + enc.symbol(1, &mut cdfs.intra_inter[ii_ctx]); | |
| 525 | + write_comp_mode( | |
| 526 | + enc, | |
| 527 | + cdfs, | |
| 528 | + neighbours, | |
| 529 | + (mi_r, mi_c), | |
| 530 | + (has_above, has_left), | |
| 531 | + info.ref1.is_some(), | |
| 532 | + ); | |
| 533 | + let (mv, mv1, is_new_mv) = if info.ref1.is_some() { | |
| 534 | + write_compound_block( | |
| 535 | + enc, | |
| 536 | + cdfs, | |
| 537 | + neighbours, | |
| 538 | + grid, | |
| 539 | + (mi_r, mi_c), | |
| 540 | + (w_mi, h_mi), | |
| 541 | + (has_above, has_left), | |
| 542 | + info, | |
| 543 | + (mi_cols as usize, mi_rows as usize), | |
| 544 | + )? | |
| 545 | + } else { | |
| 546 | + write_single_ref( | |
| 547 | + enc, | |
| 548 | + cdfs, | |
| 549 | + info.ref_frame, | |
| 550 | + neighbours.above_ref[mi_c], | |
| 551 | + neighbours.above_ref1[mi_c], | |
| 552 | + neighbours.left_ref[mi_r], | |
| 553 | + neighbours.left_ref1[mi_r], | |
| 554 | + ); | |
| 555 | + let stack = find_mv_stack( | |
| 556 | + grid, | |
| 557 | + mi_r, | |
| 558 | + mi_c, | |
| 559 | + w_mi, | |
| 560 | + h_mi, | |
| 561 | + info.ref_frame, | |
| 562 | + mi_cols as usize, | |
| 563 | + mi_rows as usize, | |
| 564 | + ); | |
| 565 | + let (mv, is_new_mv) = write_inter_mode(enc, cdfs, info, &stack)?; | |
| 566 | + (mv, (0, 0), is_new_mv) | |
| 567 | + }; | |
| 568 | + for dr in 0..h_mi { | |
| 569 | + for dc in 0..w_mi { | |
| 570 | + grid.set( | |
| 571 | + mi_r + dr, | |
| 572 | + mi_c + dc, | |
| 573 | + MiInfo { | |
| 574 | + is_inter: true, | |
| 575 | + ref_frame: info.ref_frame, | |
| 576 | + ref_frame1: info.ref1.unwrap_or(NO_REF1), | |
| 577 | + mv1: mv16(mv1), | |
| 578 | + mv: mv16(mv), | |
| 579 | + is_new_mv, | |
| 580 | + size: w_mi as u8, | |
| 581 | + size_h: h_mi as u8, | |
| 582 | + is_global_mv0: false, | |
| 583 | + is_global_mv1: false, | |
| 584 | + }, | |
| 585 | + ); | |
| 586 | + } | |
| 587 | + } | |
| 588 | + if info.ref1.is_none() { | |
| 589 | + write_motion_mode( | |
| 590 | + enc, | |
| 591 | + cdfs, | |
| 592 | + grid, | |
| 593 | + (mi_r, mi_c), | |
| 594 | + (w_mi, h_mi), | |
| 595 | + (w, h), | |
| 596 | + (mi_cols as usize, mi_rows as usize), | |
| 597 | + info.ref_frame, | |
| 598 | + block.motion_mode, | |
| 599 | + )?; | |
| 600 | + } | |
| 601 | + if tx_select { | |
| 602 | + // `read_block_tx_size_rect`'s skip arm: `txfm_partition_update_rect` | |
| 603 | + // with the BLOCK's own size in both bands, no symbol. | |
| 604 | + neighbours.record_txfm_rect((mi_r, mi_c), (w, h), (w, h)); | |
| 605 | + } | |
| 606 | + let zero_grids = [ | |
| 607 | + vec![0i32; TX32 * TX32], | |
| 608 | + vec![0i32; TX32 * TX32], | |
| 609 | + vec![0i32; TX32 * TX32], | |
| 610 | + ]; | |
| 611 | + // A 128 root's half is always SUB (16 px) aligned, so the coarse mode / | |
| 612 | + // side bands are named by the same SUB-grid origin every square block | |
| 613 | + // uses. | |
| 614 | + let at_sub = (mi_r / (SUB / MI), mi_c / (SUB / MI)); | |
| 615 | + neighbours.record_planes_rect(at_sub, (w, h), 0, &zero_grids, true); | |
| 616 | + neighbours.record_inter_rect_mi((mi_r, mi_c), (w, h), block.skip, true, block_ref(block)); | |
| 617 | + if let Some(r1) = info.ref1 { | |
| 618 | + neighbours.record_compound_rect_mi((mi_r, mi_c), (w, h), r1, 0, 1); | |
| 619 | + } | |
| 620 | + if w > h { | |
| 621 | + SB128_HORZ_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 622 | + } else { | |
| 623 | + SB128_VERT_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 624 | + } | |
| 625 | + Ok(()) | |
| 626 | +} | |
| 627 | + | |
| 628 | +/// lane-b128hv: how many 128x64 / 64x128 halves the inter writer has coded | |
| 629 | +/// since the last [`take_sb128_horz_hits`] / [`take_sb128_vert_hits`] (class | |
| 630 | +/// `gate-blind-to-feature`). | |
| 631 | +static SB128_HORZ_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | |
| 632 | +/// The VERT twin of [`SB128_HORZ_HITS`]. | |
| 633 | +static SB128_VERT_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | |
| 634 | + | |
| 635 | +/// The 128x64-half count since the last call, and zero it. | |
| 636 | +pub fn take_sb128_horz_hits() -> usize { | |
| 637 | + SB128_HORZ_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) | |
| 638 | +} | |
| 639 | + | |
| 640 | +/// The 64x128-half count since the last call, and zero it. | |
| 641 | +pub fn take_sb128_vert_hits() -> usize { | |
| 642 | + SB128_VERT_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) | |
| 643 | +} | |
| 644 | + | |
| 467 | 645 | /// lane-b128r: how many of those blocks carried a REAL residual (four |
| 468 | 646 | /// TX_64X64 luma units plus their per-chunk chroma pair) rather than being |
| 469 | 647 | /// skipped, since the last [`take_sb128_residual_hits`]. |
| @@ -1634,6 +1812,10 @@ fn ec_rng_trace(msg: impl FnOnce() -> String) { | ||
| 1634 | 1812 | |
| 1635 | 1813 | /// `PARTITION_NONE` (spec 6.10.4): the whole block, undivided. |
| 1636 | 1814 | const PARTITION_NONE: usize = 0; |
| 1815 | +/// `PARTITION_HORZ` (spec 6.10.4): the block cut into a top and a bottom half. | |
| 1816 | +const PARTITION_HORZ: usize = 1; | |
| 1817 | +/// `PARTITION_VERT` (spec 6.10.4): the block cut into a left and a right half. | |
| 1818 | +const PARTITION_VERT: usize = 2; | |
| 1637 | 1819 | /// `PARTITION_SPLIT` (spec 6.10.4): the block cut into four quadrants. |
| 1638 | 1820 | const PARTITION_SPLIT: usize = 3; |
| 1639 | 1821 | |
| @@ -2365,6 +2547,15 @@ pub enum Quadrant { | ||
| 2365 | 2547 | /// interleaved with its chroma per 64x64 mu chunk, which this writer has |
| 2366 | 2548 | /// no path for; [`crate::tile::write_inter_block_128`] refuses one. |
| 2367 | 2549 | Whole128(BlockCoeffs), |
| 2550 | + /// lane-b128hv: the two 128x64 (`true`) or 64x128 (`false`) inter blocks a | |
| 2551 | + /// `PARTITION_HORZ` / `PARTITION_VERT` 128 superblock root carries, in the | |
| 2552 | + /// order the decoder reads them (top then bottom, left then right). | |
| 2553 | + /// Carried by the top-left 32x32 entry of the root's sixteen, exactly as | |
| 2554 | + /// [`Whole128`](Quadrant::Whole128) is. | |
| 2555 | + /// | |
| 2556 | + /// SKIP only ([`crate::tile::write_inter_block_128_rect`] refuses a | |
| 2557 | + /// residual), single reference or compound. | |
| 2558 | + Rect128(bool, Vec<BlockCoeffs>), | |
| 2368 | 2559 | /// A quadrant a [`Whole64`](Quadrant::Whole64) at its superblock's |
| 2369 | 2560 | /// top-left already coded; it carries no block of its own. |
| 2370 | 2561 | Covered, |
| @@ -2377,7 +2568,7 @@ impl Quadrant { | ||
| 2377 | 2568 | Quadrant::Whole(block) | Quadrant::Whole64(block) | Quadrant::Whole128(block) => { |
| 2378 | 2569 | std::slice::from_ref(block) |
| 2379 | 2570 | } |
| 2380 | - Quadrant::Split(blocks) => blocks.as_slice(), | |
| 2571 | + Quadrant::Split(blocks) | Quadrant::Rect128(_, blocks) => blocks.as_slice(), | |
| 2381 | 2572 | Quadrant::Covered => &[], |
| 2382 | 2573 | } |
| 2383 | 2574 | } |
| @@ -2722,14 +2913,18 @@ impl Neighbours { | ||
| 2722 | 2913 | /// [`Self::record_palette_y`] for the chroma bands (decode.rs |
| 2723 | 2914 | /// `record_palette_uv_rect`) -- `size == 0` clears stale state the same |
| 2724 | 2915 | /// way, and the span is in LUMA pixels for both planes' bands alike. |
| 2725 | - fn record_palette_uv(&mut self, (r, c): (usize, usize), side: usize, size: u8, colors: [u16; 8]) { | |
| 2726 | - for cell in 0..(side / MI).max(1) { | |
| 2916 | + fn record_palette_uv(&mut self, (r, c): (usize, usize), (w, h): (usize, usize), size: u8, colors: [u16; 8]) { | |
| 2917 | + // lane-b128hv: the above band spans the block's WIDTH and the left | |
| 2918 | + // band its HEIGHT; identical to the one loop this replaces at w == h. | |
| 2919 | + for cell in 0..(w / MI).max(1) { | |
| 2727 | 2920 | if let Some(e) = self.above_palette_uv_size.get_mut(c + cell) { |
| 2728 | 2921 | *e = size; |
| 2729 | 2922 | if size > 0 { |
| 2730 | 2923 | self.above_palette_uv_colors[c + cell] = colors; |
| 2731 | 2924 | } |
| 2732 | 2925 | } |
| 2926 | + } | |
| 2927 | + for cell in 0..(h / MI).max(1) { | |
| 2733 | 2928 | if let Some(e) = self.left_palette_uv_size.get_mut(r + cell) { |
| 2734 | 2929 | *e = size; |
| 2735 | 2930 | if size > 0 { |
| @@ -2742,14 +2937,18 @@ impl Neighbours { | ||
| 2742 | 2937 | /// What a just-written block leaves in the palette bands (decode.rs |
| 2743 | 2938 | /// `record_palette_y_rect`): its size and colours over every 4x4 unit it |
| 2744 | 2939 | /// spans, `0` for a block that took no palette. |
| 2745 | - fn record_palette_y(&mut self, (r, c): (usize, usize), side: usize, size: u8, colors: [u16; 8]) { | |
| 2746 | - for cell in 0..(side / MI).max(1) { | |
| 2940 | + fn record_palette_y(&mut self, (r, c): (usize, usize), (w, h): (usize, usize), size: u8, colors: [u16; 8]) { | |
| 2941 | + // lane-b128hv: the above band spans the block's WIDTH and the left | |
| 2942 | + // band its HEIGHT; identical to the one loop this replaces at w == h. | |
| 2943 | + for cell in 0..(w / MI).max(1) { | |
| 2747 | 2944 | if let Some(e) = self.above_palette_size.get_mut(c + cell) { |
| 2748 | 2945 | *e = size; |
| 2749 | 2946 | if size > 0 { |
| 2750 | 2947 | self.above_palette_colors[c + cell] = colors; |
| 2751 | 2948 | } |
| 2752 | 2949 | } |
| 2950 | + } | |
| 2951 | + for cell in 0..(h / MI).max(1) { | |
| 2753 | 2952 | if let Some(e) = self.left_palette_size.get_mut(r + cell) { |
| 2754 | 2953 | *e = size; |
| 2755 | 2954 | if size > 0 { |
| @@ -2776,6 +2975,27 @@ impl Neighbours { | ||
| 2776 | 2975 | } |
| 2777 | 2976 | } |
| 2778 | 2977 | |
| 2978 | + /// lane-b128hv: decode.rs `txfm_partition_update_rect` -- the two bands | |
| 2979 | + /// take the transform's own HEIGHT (left) and WIDTH (above), over the | |
| 2980 | + /// txb's own rect span. [`Self::record_txfm`] is this at `tx_w == tx_h`. | |
| 2981 | + fn record_txfm_rect( | |
| 2982 | + &mut self, | |
| 2983 | + (mi_r, mi_c): (usize, usize), | |
| 2984 | + (tx_w, tx_h): (usize, usize), | |
| 2985 | + (txb_w, txb_h): (usize, usize), | |
| 2986 | + ) { | |
| 2987 | + for i in 0..txb_h / MI { | |
| 2988 | + if let Some(cell) = self.left_txfm.get_mut(mi_r + i) { | |
| 2989 | + *cell = tx_h as u8; | |
| 2990 | + } | |
| 2991 | + } | |
| 2992 | + for i in 0..txb_w / MI { | |
| 2993 | + if let Some(cell) = self.above_txfm.get_mut(mi_c + i) { | |
| 2994 | + *cell = tx_w as u8; | |
| 2995 | + } | |
| 2996 | + } | |
| 2997 | + } | |
| 2998 | + | |
| 2779 | 2999 | /// `get_tx_size_context` as libaom writes it for a block inside an INTER |
| 2780 | 3000 | /// frame (decode.rs `tx_size_context_txfm_rect`): the `TXFM_CONTEXT` |
| 2781 | 3001 | /// bands, except that an *inter* neighbour contributes its own BLOCK size. |
| @@ -2897,15 +3117,31 @@ impl Neighbours { | ||
| 2897 | 3117 | mode: usize, |
| 2898 | 3118 | grids: &[Vec<i32>; 3], |
| 2899 | 3119 | luma: bool, |
| 3120 | + ) { | |
| 3121 | + self.record_planes_rect(at, (side, side), mode, grids, luma); | |
| 3122 | + } | |
| 3123 | + | |
| 3124 | + /// lane-b128hv: [`Self::record_planes`] with independent above (width) / | |
| 3125 | + /// left (height) extents, decode.rs `record_rect_mi`'s own split -- the | |
| 3126 | + /// 128 root's HORZ/VERT halves are the writer's first rect blocks. | |
| 3127 | + fn record_planes_rect( | |
| 3128 | + &mut self, | |
| 3129 | + at: (usize, usize), | |
| 3130 | + (w, h): (usize, usize), | |
| 3131 | + mode: usize, | |
| 3132 | + grids: &[Vec<i32>; 3], | |
| 3133 | + luma: bool, | |
| 2900 | 3134 | ) { |
| 2901 | 3135 | let (r, c) = at; |
| 2902 | - for cell in 0..side / SUB { | |
| 3136 | + for cell in 0..w / SUB { | |
| 2903 | 3137 | self.above_mode[c + cell] = mode; |
| 3138 | + self.above_side[c + cell] = w; | |
| 3139 | + } | |
| 3140 | + for cell in 0..h / SUB { | |
| 2904 | 3141 | self.left_mode[r + cell] = mode; |
| 2905 | - self.above_side[c + cell] = side; | |
| 2906 | - self.left_side[r + cell] = side; | |
| 3142 | + self.left_side[r + cell] = h; | |
| 2907 | 3143 | } |
| 2908 | - self.record_mi_planes((r * (SUB / MI), c * (SUB / MI)), side, grids, luma); | |
| 3144 | + self.record_mi_planes_rect((r * (SUB / MI), c * (SUB / MI)), (w, h), grids, luma); | |
| 2909 | 3145 | } |
| 2910 | 3146 | |
| 2911 | 3147 | /// The coefficient-context half of [`Self::record`], taking the block's |
| @@ -2926,19 +3162,33 @@ impl Neighbours { | ||
| 2926 | 3162 | side: usize, |
| 2927 | 3163 | grids: &[Vec<i32>; 3], |
| 2928 | 3164 | luma: bool, |
| 3165 | + ) { | |
| 3166 | + self.record_mi_planes_rect(at_mi, (side, side), grids, luma); | |
| 3167 | + } | |
| 3168 | + | |
| 3169 | + /// [`Self::record_mi_planes`] with independent above (width) / left | |
| 3170 | + /// (height) extents (lane-b128hv, decode.rs `record_mi_rect`). | |
| 3171 | + fn record_mi_planes_rect( | |
| 3172 | + &mut self, | |
| 3173 | + at_mi: (usize, usize), | |
| 3174 | + (w, h): (usize, usize), | |
| 3175 | + grids: &[Vec<i32>; 3], | |
| 3176 | + luma: bool, | |
| 2929 | 3177 | ) { |
| 2930 | 3178 | let (mi_r, mi_c) = at_mi; |
| 2931 | 3179 | if screen_armed() { |
| 2932 | 3180 | let (size, colors) = self.pending_palette.take().unwrap_or((0, [0u16; 8])); |
| 2933 | - self.record_palette_y(at_mi, side, size, colors); | |
| 3181 | + self.record_palette_y(at_mi, (w, h), size, colors); | |
| 2934 | 3182 | let (uv_size, uv_colors) = self.pending_palette_uv.take().unwrap_or((0, [0u16; 8])); |
| 2935 | - self.record_palette_uv(at_mi, side, uv_size, uv_colors); | |
| 3183 | + self.record_palette_uv(at_mi, (w, h), uv_size, uv_colors); | |
| 2936 | 3184 | } |
| 2937 | 3185 | let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(&grids[plane])); |
| 2938 | - let side_mi = side / MI; | |
| 2939 | - for cell in 0..side_mi { | |
| 2940 | - self.left_side_mi[mi_r + cell] = side; | |
| 2941 | - self.above_side_mi[mi_c + cell] = side; | |
| 3186 | + let (w_mi, h_mi) = (w / MI, h / MI); | |
| 3187 | + for cell in 0..h_mi { | |
| 3188 | + self.left_side_mi[mi_r + cell] = h; | |
| 3189 | + } | |
| 3190 | + for cell in 0..w_mi { | |
| 3191 | + self.above_side_mi[mi_c + cell] = w; | |
| 2942 | 3192 | } |
| 2943 | 3193 | // libaom rounds the luma edge up to the plane's own 4x4 unit before |
| 2944 | 3194 | // clamping a subsampled plane (`ROUND_POWER_OF_TWO(max_blocks_high, |
| @@ -2957,25 +3207,29 @@ impl Neighbours { | ||
| 2957 | 3207 | round_up_even(self.mi_cols), |
| 2958 | 3208 | round_up_even(self.mi_cols), |
| 2959 | 3209 | ]; |
| 2960 | - for cell in 0..side_mi { | |
| 3210 | + for cell in 0..h_mi { | |
| 2961 | 3211 | let keep_left = self.left[mi_r + cell][0]; |
| 2962 | - let keep_above = self.above[mi_c + cell][0]; | |
| 2963 | 3212 | self.left[mi_r + cell] = std::array::from_fn(|plane| { |
| 2964 | - if cell < side_mi.min(bound_h[plane].saturating_sub(mi_r)) { | |
| 3213 | + if cell < h_mi.min(bound_h[plane].saturating_sub(mi_r)) { | |
| 2965 | 3214 | states[plane] |
| 2966 | 3215 | } else { |
| 2967 | 3216 | Default::default() |
| 2968 | 3217 | } |
| 2969 | 3218 | }); |
| 3219 | + if !luma { | |
| 3220 | + self.left[mi_r + cell][0] = keep_left; | |
| 3221 | + } | |
| 3222 | + } | |
| 3223 | + for cell in 0..w_mi { | |
| 3224 | + let keep_above = self.above[mi_c + cell][0]; | |
| 2970 | 3225 | self.above[mi_c + cell] = std::array::from_fn(|plane| { |
| 2971 | - if cell < side_mi.min(bound_w[plane].saturating_sub(mi_c)) { | |
| 3226 | + if cell < w_mi.min(bound_w[plane].saturating_sub(mi_c)) { | |
| 2972 | 3227 | states[plane] |
| 2973 | 3228 | } else { |
| 2974 | 3229 | Default::default() |
| 2975 | 3230 | } |
| 2976 | 3231 | }); |
| 2977 | 3232 | if !luma { |
| 2978 | - self.left[mi_r + cell][0] = keep_left; | |
| 2979 | 3233 | self.above[mi_c + cell][0] = keep_above; |
| 2980 | 3234 | } |
| 2981 | 3235 | } |
| @@ -2989,6 +3243,56 @@ impl Neighbours { | ||
| 2989 | 3243 | self.record_inter_mi((r * (SUB / MI), c * (SUB / MI)), side, skip, is_inter, ref_frame); |
| 2990 | 3244 | } |
| 2991 | 3245 | |
| 3246 | + /// lane-b128hv: [`Self::record_inter_mi`] with independent above (width) | |
| 3247 | + /// / left (height) spans, decode.rs `record_inter_rect_mi`'s own split. | |
| 3248 | + fn record_inter_rect_mi( | |
| 3249 | + &mut self, | |
| 3250 | + (mi_r, mi_c): (usize, usize), | |
| 3251 | + (w, h): (usize, usize), | |
| 3252 | + skip: bool, | |
| 3253 | + is_inter: bool, | |
| 3254 | + ref_frame: i8, | |
| 3255 | + ) { | |
| 3256 | + let altref = is_inter && ref_frame == crate::mvstack::ALTREF_FRAME; | |
| 3257 | + for cell in 0..h / MI { | |
| 3258 | + self.left_skip[mi_r + cell] = skip; | |
| 3259 | + self.left_inter[mi_r + cell] = is_inter; | |
| 3260 | + self.left_ref[mi_r + cell] = ref_frame; | |
| 3261 | + self.left_ref1[mi_r + cell] = None; | |
| 3262 | + self.left_comp_group_idx[mi_r + cell] = if altref { 3 } else { 0 }; | |
| 3263 | + self.left_compound_idx[mi_r + cell] = u8::from(altref); | |
| 3264 | + } | |
| 3265 | + for cell in 0..w / MI { | |
| 3266 | + self.above_skip[mi_c + cell] = skip; | |
| 3267 | + self.above_inter[mi_c + cell] = is_inter; | |
| 3268 | + self.above_ref[mi_c + cell] = ref_frame; | |
| 3269 | + self.above_ref1[mi_c + cell] = None; | |
| 3270 | + self.above_comp_group_idx[mi_c + cell] = if altref { 3 } else { 0 }; | |
| 3271 | + self.above_compound_idx[mi_c + cell] = u8::from(altref); | |
| 3272 | + } | |
| 3273 | + } | |
| 3274 | + | |
| 3275 | + /// [`Self::record_compound_mi`] over a rect block's own two spans. | |
| 3276 | + fn record_compound_rect_mi( | |
| 3277 | + &mut self, | |
| 3278 | + (mi_r, mi_c): (usize, usize), | |
| 3279 | + (w, h): (usize, usize), | |
| 3280 | + ref1: i8, | |
| 3281 | + comp_group_idx: u8, | |
| 3282 | + compound_idx: u8, | |
| 3283 | + ) { | |
| 3284 | + for cell in 0..h / MI { | |
| 3285 | + self.left_ref1[mi_r + cell] = Some(ref1); | |
| 3286 | + self.left_comp_group_idx[mi_r + cell] = comp_group_idx; | |
| 3287 | + self.left_compound_idx[mi_r + cell] = compound_idx; | |
| 3288 | + } | |
| 3289 | + for cell in 0..w / MI { | |
| 3290 | + self.above_ref1[mi_c + cell] = Some(ref1); | |
| 3291 | + self.above_comp_group_idx[mi_c + cell] = comp_group_idx; | |
| 3292 | + self.above_compound_idx[mi_c + cell] = compound_idx; | |
| 3293 | + } | |
| 3294 | + } | |
| 3295 | + | |
| 2992 | 3296 | /// [`Self::record_inter_mi`]'s compound half (decode.rs |
| 2993 | 3297 | /// `Neighbours::record_compound_ctx_rect_mi`): overwrites the ALTREF |
| 2994 | 3298 | /// single-reference default with a real compound block's own second |
| @@ -3397,7 +3701,10 @@ pub(crate) fn sb_coeff_key_frame_tile_cdfs( | ||
| 3397 | 3701 | match quadrant { |
| 3398 | 3702 | // A 64x64 root is an INTER-frame partition; a |
| 3399 | 3703 | // key frame codes one as `Superblock::Whole`. |
| 3400 | - Quadrant::Whole64(_) | Quadrant::Whole128(_) | Quadrant::Covered => { | |
| 3704 | + Quadrant::Whole64(_) | |
| 3705 | + | Quadrant::Whole128(_) | |
| 3706 | + | Quadrant::Rect128(..) | |
| 3707 | + | Quadrant::Covered => { | |
| 3401 | 3708 | return Err(Error::unsupported( |
| 3402 | 3709 | "AV1 tile", |
| 3403 | 3710 | "a key frame codes a 64x64 block as `Superblock::Whole`", |
| @@ -5065,7 +5372,7 @@ pub(crate) fn predicted_coeff_bits(blocks: &[Quadrant], base_q_idx: u8) -> f64 { | ||
| 5065 | 5372 | // lane-b128: a 128x128 root is SKIP by construction (the |
| 5066 | 5373 | // writer refuses a residual at that size), so it names no |
| 5067 | 5374 | // coefficients on any plane. |
| 5068 | - Quadrant::Whole128(_) => return 0.0, | |
| 5375 | + Quadrant::Whole128(_) | Quadrant::Rect128(..) => return 0.0, | |
| 5069 | 5376 | Quadrant::Whole(_) => 32, |
| 5070 | 5377 | Quadrant::Split(_) => 16, |
| 5071 | 5378 | // lane-tx64: a 64x64 root that codes a residual pays for one |
| @@ -5687,6 +5994,22 @@ pub(crate) fn partition_bits(side: usize, split: bool) -> f64 { | ||
| 5687 | 5994 | crate::encode::symbol_bits(cdf, symbol) |
| 5688 | 5995 | } |
| 5689 | 5996 | |
| 5997 | +/// lane-b128hv: [`partition_bits`] for any partition symbol, at the same | |
| 5998 | +/// fixed (round-2) tables -- what the 128 root's HORZ/VERT candidate is priced | |
| 5999 | +/// with (`PARTITION_HORZ` = 1, `PARTITION_VERT` = 2). | |
| 6000 | +pub(crate) fn partition_bits_sym(side: usize, symbol: usize) -> f64 { | |
| 6001 | + static CDFS: LazyLock<Cdfs> = LazyLock::new(|| Cdfs::new(2)); | |
| 6002 | + let cdfs = &*CDFS; | |
| 6003 | + let cdf: &[u16] = match side { | |
| 6004 | + 128 => &cdfs.partition_w128[0], | |
| 6005 | + SB => &cdfs.partition_w64[0], | |
| 6006 | + BLOCK => &cdfs.partition_w32[0], | |
| 6007 | + TX8 => &cdfs.partition_w8[0], | |
| 6008 | + _ => &cdfs.partition_w16[0], | |
| 6009 | + }; | |
| 6010 | + crate::encode::symbol_bits(cdf, symbol) | |
| 6011 | +} | |
| 6012 | + | |
| 5690 | 6013 | /// coeffs() for one plane's transform block of any coefficients the base and |
| 5691 | 6014 | /// base-range syntax reach (spec 5.11.39). |
| 5692 | 6015 | /// |
| @@ -6769,12 +7092,17 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | ||
| 6769 | 7092 | if sb128 && sb_start { |
| 6770 | 7093 | // The 128x128 block a `PARTITION_NONE` root carries, held by the |
| 6771 | 7094 | // top-left 32x32 entry of the root's sixteen. |
| 6772 | - let root_block = ((sb_r & !1) * 2 < rows && (sb_c & !1) * 2 < cols) | |
| 6773 | - .then(|| &blocks[(((sb_r & !1) * 2) * cols + (sb_c & !1) * 2) as usize]) | |
| 6774 | - .and_then(|q| match q { | |
| 6775 | - Quadrant::Whole128(block) => Some(block), | |
| 6776 | - _ => None, | |
| 6777 | - }); | |
| 7095 | + let root_entry = ((sb_r & !1) * 2 < rows && (sb_c & !1) * 2 < cols) | |
| 7096 | + .then(|| &blocks[(((sb_r & !1) * 2) * cols + (sb_c & !1) * 2) as usize]); | |
| 7097 | + let root_block = root_entry.and_then(|q| match q { | |
| 7098 | + Quadrant::Whole128(block) => Some(block), | |
| 7099 | + _ => None, | |
| 7100 | + }); | |
| 7101 | + // lane-b128hv: the two rectangular halves a HORZ/VERT root carries. | |
| 7102 | + let root_rect = root_entry.and_then(|q| match q { | |
| 7103 | + Quadrant::Rect128(horz, halves) => Some((*horz, halves)), | |
| 7104 | + _ => None, | |
| 7105 | + }); | |
| 6778 | 7106 | write_sb128_root( |
| 6779 | 7107 | &mut enc, |
| 6780 | 7108 | &mut cdfs, |
| @@ -6783,7 +7111,12 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | ||
| 6783 | 7111 | sb_c, |
| 6784 | 7112 | mi_cols, |
| 6785 | 7113 | mi_rows, |
| 6786 | - if root_block.is_some() { PARTITION_NONE } else { PARTITION_SPLIT }, | |
| 7114 | + match (root_block.is_some(), root_rect) { | |
| 7115 | + (true, _) => PARTITION_NONE, | |
| 7116 | + (_, Some((true, _))) => PARTITION_HORZ, | |
| 7117 | + (_, Some((false, _))) => PARTITION_VERT, | |
| 7118 | + _ => PARTITION_SPLIT, | |
| 7119 | + }, | |
| 6787 | 7120 | ); |
| 6788 | 7121 | if let Some(block) = root_block { |
| 6789 | 7122 | let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); |
| @@ -6801,6 +7134,35 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | ||
| 6801 | 7134 | sb128_none = true; |
| 6802 | 7135 | continue; |
| 6803 | 7136 | } |
| 7137 | + if let Some((horz, halves)) = root_rect { | |
| 7138 | + // libaom `decode_partition` at BLOCK_128X128: `subsize` at | |
| 7139 | + // (mi_row, mi_col) and a second one at + hbs (16 mi) along the | |
| 7140 | + // cut axis, the second only when it is inside the frame -- the | |
| 7141 | + // search only offers a root wholly inside, so both are. | |
| 7142 | + let base_mi = ((sb_r & !1) as usize * SB_MI as usize, (sb_c & !1) as usize * SB_MI as usize); | |
| 7143 | + let (w, h) = if horz { (128usize, 64usize) } else { (64, 128) }; | |
| 7144 | + for (i, half) in halves.iter().enumerate() { | |
| 7145 | + let at_mi = if horz { | |
| 7146 | + (base_mi.0 + i * 16, base_mi.1) | |
| 7147 | + } else { | |
| 7148 | + (base_mi.0, base_mi.1 + i * 16) | |
| 7149 | + }; | |
| 7150 | + write_inter_block_128_rect( | |
| 7151 | + &mut enc, | |
| 7152 | + &mut cdfs, | |
| 7153 | + &mut neighbours, | |
| 7154 | + &mut grid, | |
| 7155 | + at_mi, | |
| 7156 | + (w, h), | |
| 7157 | + half, | |
| 7158 | + mi_cols, | |
| 7159 | + mi_rows, | |
| 7160 | + tx_select, | |
| 7161 | + )?; | |
| 7162 | + } | |
| 7163 | + sb128_none = true; | |
| 7164 | + continue; | |
| 7165 | + } | |
| 6804 | 7166 | } |
| 6805 | 7167 | { |
| 6806 | 7168 | if !sb128 { |
| @@ -7046,7 +7408,10 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | ||
| 7046 | 7408 | let block = match site { |
| 7047 | 7409 | // Already coded by the `Whole64` above -- but only inside |
| 7048 | 7410 | // a superblock that really carried one. |
| 7049 | - Quadrant::Whole64(_) | Quadrant::Whole128(_) | Quadrant::Covered => { | |
| 7411 | + Quadrant::Whole64(_) | |
| 7412 | + | Quadrant::Whole128(_) | |
| 7413 | + | Quadrant::Rect128(..) | |
| 7414 | + | Quadrant::Covered => { | |
| 7050 | 7415 | return Err(Error::unsupported( |
| 7051 | 7416 | "AV1 tile", |
| 7052 | 7417 | "a `Whole64`/`Covered` quadrant needs its superblock's \ |