Coefficient readers return the shared zero grid instead of a fresh Vec
Browse files at this commitf969486e2bb4ec91bb31175dcd49cf64172145b6Parent: c870931- perf
- coefficient readers return the shared zero grid instead of a fresh Vec
1 changed file +104 -102
- crates/ec-av1/src/decode.rs +104 -102
crates/ec-av1/src/decode.rsmodified+104 -102
| @@ -2140,6 +2140,11 @@ impl Residual { | ||
| 2140 | 2140 | /// the empty marker, so neither the grid nor the residual is cloned and |
| 2141 | 2141 | /// the worker never runs the transform (60% of the 4K segment's units). |
| 2142 | 2142 | fn coeffs(tx: TxParams, grid: &[i32], fctx: &crate::decode::FrameCtx) -> Self { |
| 2143 | + // lane-coefgrid: a [`Grid::Zero`] unit IS the shared zero grid -- one | |
| 2144 | + // pointer compare instead of scanning up to 16 K coefficients. | |
| 2145 | + if std::ptr::eq(grid.as_ptr(), ZERO_RESIDUAL.as_ptr()) { | |
| 2146 | + return Self::Done(0, 0); | |
| 2147 | + } | |
| 2143 | 2148 | if grid.iter().all(|&c| c == 0) { |
| 2144 | 2149 | return Self::Done(0, 0); |
| 2145 | 2150 | } |
| @@ -2204,6 +2209,7 @@ static ZERO_RESIDUAL: [i32; 128 * 128] = [0; 128 * 128]; | ||
| 2204 | 2209 | /// strip with no chroma, luma under a var-tx split whose units already wrote |
| 2205 | 2210 | /// themselves) names the shared [`ZERO_RESIDUAL`] instead of allocating and |
| 2206 | 2211 | /// zeroing up to 64 KB of its own per block. |
| 2212 | +#[derive(Clone)] | |
| 2207 | 2213 | enum Grid { |
| 2208 | 2214 | Zero(usize), |
| 2209 | 2215 | Own(Vec<i32>), |
| @@ -5897,10 +5903,9 @@ fn read_coeffs( | ||
| 5897 | 5903 | // root cause, see [`base_ctx`]). `None` everywhere else -- every other |
| 5898 | 5904 | // caller's block genuinely is `side` x `side`. |
| 5899 | 5905 | rect_shape: Option<(usize, usize)>, |
| 5900 | -) -> Result<(Vec<i32>, TxType)> { | |
| 5906 | +) -> Result<(Grid, TxType)> { | |
| 5901 | 5907 | let trace = crate::envflags::env_flag!("EC_AV1_TRACE"); |
| 5902 | 5908 | let side = coding.side; |
| 5903 | - let mut grid = vec![0i32; side * side]; | |
| 5904 | 5909 | if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") { |
| 5905 | 5910 | let (range, value) = dec.debug_state(); |
| 5906 | 5911 | eprintln!("EC_AV1_STATE_BEFORE_TXBSKIP range={range} value={value}"); |
| @@ -5933,8 +5938,11 @@ fn read_coeffs( | ||
| 5933 | 5938 | eprintln!("EC_AV1_STATE_AFTER_TXBSKIP range={range} value={value}"); |
| 5934 | 5939 | } |
| 5935 | 5940 | if all_zero { |
| 5936 | - return Ok((grid, TxType::DctDct)); | |
| 5941 | + // lane-coefgrid: the all-zero unit (60% of the 4K segment's) names the | |
| 5942 | + // shared zero grid instead of allocating and zeroing its own. | |
| 5943 | + return Ok((Grid::Zero(side * side), TxType::DctDct)); | |
| 5937 | 5944 | } |
| 5945 | + let mut grid = vec![0i32; side * side]; | |
| 5938 | 5946 | let mut tx_type = default_tx_type; |
| 5939 | 5947 | if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() { |
| 5940 | 5948 | // The CDF row's own width names its set (lane-cdffwd2: extended |
| @@ -6116,7 +6124,7 @@ fn read_coeffs( | ||
| 6116 | 6124 | } |
| 6117 | 6125 | grid[pos] = if negative { -level } else { level }; |
| 6118 | 6126 | } |
| 6119 | - Ok((grid, tx_type)) | |
| 6127 | + Ok((Grid::Own(grid), tx_type)) | |
| 6120 | 6128 | } |
| 6121 | 6129 | |
| 6122 | 6130 | /// [`read_coeffs`] widened to `(w, h)` (lane-rectwire; lane-rectx added the |
| @@ -6136,9 +6144,8 @@ fn read_coeffs_rect( | ||
| 6136 | 6144 | skip_ctx: usize, |
| 6137 | 6145 | sign_ctx: usize, |
| 6138 | 6146 | default_tx_type: TxType, |
| 6139 | -) -> Result<(Vec<i32>, TxType)> { | |
| 6147 | +) -> Result<(Grid, TxType)> { | |
| 6140 | 6148 | let rect_trace = coeff_trace_on(); |
| 6141 | - let mut grid = vec![0i32; w * h]; | |
| 6142 | 6149 | let entry_rng = dec.debug_state().0; |
| 6143 | 6150 | let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1; |
| 6144 | 6151 | if rect_trace { |
| @@ -6149,8 +6156,9 @@ fn read_coeffs_rect( | ||
| 6149 | 6156 | ); |
| 6150 | 6157 | } |
| 6151 | 6158 | if all_zero { |
| 6152 | - return Ok((grid, TxType::DctDct)); | |
| 6159 | + return Ok((Grid::Zero(w * h), TxType::DctDct)); | |
| 6153 | 6160 | } |
| 6161 | + let mut grid = vec![0i32; w * h]; | |
| 6154 | 6162 | RECT_COEFF_TU_HITS.with(|c| c.set(c.get() + 1)); |
| 6155 | 6163 | // lane-tx4x8: a 4x8/8x4 luma TU DOES carry a `tx_type` symbol (its set is |
| 6156 | 6164 | // `EXT_TX_SET_DTT4_IDTX(_1DDCT)`, `tx_size_sqr_up == TX_8X8`), including |
| @@ -6288,7 +6296,7 @@ fn read_coeffs_rect( | ||
| 6288 | 6296 | }; |
| 6289 | 6297 | grid[pos] = if negative { -level } else { level }; |
| 6290 | 6298 | } |
| 6291 | - Ok((grid, tx_type)) | |
| 6299 | + Ok((Grid::Own(grid), tx_type)) | |
| 6292 | 6300 | } |
| 6293 | 6301 | |
| 6294 | 6302 | /// What one coded block leaves behind for the blocks that read it as a |
| @@ -9223,7 +9231,7 @@ fn decode_rect_split( | ||
| 9223 | 9231 | let ac = m.alpha.map(|_| cfl_src_rect(px, py, bw, bh)); |
| 9224 | 9232 | let reach = block_reach; |
| 9225 | 9233 | let (u_grid, v_grid) = if m.skip { |
| 9226 | - let zero = vec![0i32; chroma_w * chroma_h]; | |
| 9234 | + let zero = Grid::Zero(chroma_w * chroma_h); | |
| 9227 | 9235 | if let Some((ub, _)) = &m.palette_uv { |
| 9228 | 9236 | set_palette_pred(ub.clone(), fctx); |
| 9229 | 9237 | } |
| @@ -9250,7 +9258,7 @@ fn decode_rect_split( | ||
| 9250 | 9258 | default_intra_tx_type(m.uv_predict_mode as u8) |
| 9251 | 9259 | }; |
| 9252 | 9260 | let around = neighbours.around_mi_rect(at_mi, bw, bh); |
| 9253 | - let mut grids: Vec<Vec<i32>> = Vec::with_capacity(2); | |
| 9261 | + let mut grids: Vec<Grid> = Vec::with_capacity(2); | |
| 9254 | 9262 | for plane_idx in 1..=2 { |
| 9255 | 9263 | let skip_ctx = |
| 9256 | 9264 | usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1); |
| @@ -10719,9 +10727,9 @@ fn decode_leaf_rect( | ||
| 10719 | 10727 | let (chroma_w, chroma_h) = (bw / 2, bh / 2); |
| 10720 | 10728 | let (luma_levels, u_levels, v_levels); |
| 10721 | 10729 | if skip { |
| 10722 | - luma_levels = vec![0i32; bw * bh]; | |
| 10723 | - u_levels = vec![0i32; chroma_w * chroma_h]; | |
| 10724 | - v_levels = vec![0i32; chroma_w * chroma_h]; | |
| 10730 | + luma_levels = Grid::Zero(bw * bh); | |
| 10731 | + u_levels = Grid::Zero(chroma_w * chroma_h); | |
| 10732 | + v_levels = Grid::Zero(chroma_w * chroma_h); | |
| 10725 | 10733 | if let Some(b) = &palette_y_buf { |
| 10726 | 10734 | set_palette_pred(b.clone(), fctx); |
| 10727 | 10735 | } |
| @@ -11647,7 +11655,7 @@ fn decode_rect4_16_strip( | ||
| 11647 | 11655 | } |
| 11648 | 11656 | } else { |
| 11649 | 11657 | let levels = if skip { |
| 11650 | - let zeros = vec![0i32; bw * bh]; | |
| 11658 | + let zeros = Grid::Zero(bw * bh); | |
| 11651 | 11659 | if let Some(b) = &palette_y_buf { |
| 11652 | 11660 | set_palette_pred(b.clone(), fctx); |
| 11653 | 11661 | } |
| @@ -11748,7 +11756,7 @@ fn decode_rect4_16_strip( | ||
| 11748 | 11756 | RECT4_16_UV_PAIR_FILT_HITS.with(|h| h.set(h.get() + 1)); |
| 11749 | 11757 | } |
| 11750 | 11758 | let (u_levels, v_levels) = if skip { |
| 11751 | - let zeros = vec![0i32; cw * ch]; | |
| 11759 | + let zeros = Grid::Zero(cw * ch); | |
| 11752 | 11760 | // libaom `predict_and_reconstruct_intra_block` (decodeframe.c |
| 11753 | 11761 | // ~1000) predicts EVERY plane and only guards the residual on |
| 11754 | 11762 | // `mbmi->skip_txfm`, so a skipped `UV_CFL_PRED` block is still |
| @@ -13351,7 +13359,7 @@ fn read_plane( | ||
| 13351 | 13359 | luma_skip_ctx: Option<usize>, |
| 13352 | 13360 | // See [`PlaneBuf::reconstruct`]'s own doc: caller's neighbour-smooth check. |
| 13353 | 13361 | smooth_neighbor: bool, fctx: &crate::decode::FrameCtx, |
| 13354 | -) -> Result<Vec<i32>> { | |
| 13362 | +) -> Result<Grid> { | |
| 13355 | 13363 | let skip_ctx = if plane_idx == 0 { |
| 13356 | 13364 | luma_skip_ctx.unwrap_or(0) |
| 13357 | 13365 | } else { |
| @@ -13411,19 +13419,11 @@ fn read_plane( | ||
| 13411 | 13419 | // top-left 32x32 of frequencies are coded (spec 5.11.40); the rest of the |
| 13412 | 13420 | // dequantized grid stays zero, which `inverse_transform_2d`'s own `< 32` |
| 13413 | 13421 | // guard also assumes. |
| 13414 | - let levels = if tx_side == side { | |
| 13415 | - grid | |
| 13416 | - } else { | |
| 13417 | - // `grid` is `tx_side x tx_side` (the coded corner); `dequant_and_inverse` | |
| 13418 | - // wants the true `side x side` transform, with dqDenom (spec 7.12.3) | |
| 13419 | - // keyed by that true size, not the coded corner's -- so the corner | |
| 13420 | - // goes into the top-left of a `side`-sized grid, not the reverse. | |
| 13421 | - let mut full = vec![0i32; side * side]; | |
| 13422 | - for row in 0..tx_side { | |
| 13423 | - full[row * side..][..tx_side].copy_from_slice(&grid[row * tx_side..][..tx_side]); | |
| 13424 | - } | |
| 13425 | - full | |
| 13426 | - }; | |
| 13422 | + // `grid` is `tx_side x tx_side` (the coded corner); `dequant_and_inverse` | |
| 13423 | + // wants the true `side x side` transform, with dqDenom (spec 7.12.3) | |
| 13424 | + // keyed by that true size, not the coded corner's -- so the corner | |
| 13425 | + // goes into the top-left of a `side`-sized grid, not the reverse. | |
| 13426 | + let levels = extend_corner(grid, tx_side, tx_side, side, side); | |
| 13427 | 13427 | let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx); |
| 13428 | 13428 | let tx = TxParams { |
| 13429 | 13429 | w: side, h: side, bit_depth: bit_depth(fctx), q_idx: block_q_idx(fctx), dc_delta, |
| @@ -13432,7 +13432,7 @@ fn read_plane( | ||
| 13432 | 13432 | if crate::envflags::env_flag!("EC_AV1_TRACE") { |
| 13433 | 13433 | let residual = tx.run(&levels); |
| 13434 | 13434 | eprintln!( |
| 13435 | - "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={levels:?} residual={residual:?}", | |
| 13435 | + "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={:?} residual={residual:?}", &*levels, | |
| 13436 | 13436 | ); |
| 13437 | 13437 | } |
| 13438 | 13438 | push_intra_tx( |
| @@ -13946,8 +13946,8 @@ fn decode_block( | ||
| 13946 | 13946 | let chroma_ctx_offset = if cn > 1 { Some(3) } else { None }; |
| 13947 | 13947 | let tpc = (n_axis / nchunk).max(1); |
| 13948 | 13948 | let cpc = (cn / nchunk).max(1); |
| 13949 | - let mut last_grids = [Vec::new(), Vec::new()]; | |
| 13950 | - let mut units: Vec<((usize, usize), usize, Vec<i32>, Vec<i32>)> = Vec::new(); | |
| 13949 | + let mut last_grids = [Grid::Zero(0), Grid::Zero(0)]; | |
| 13950 | + let mut units: Vec<((usize, usize), usize, Grid, Grid)> = Vec::new(); | |
| 13951 | 13951 | for ch_row in 0..nchunk { |
| 13952 | 13952 | for ch_col in 0..nchunk { |
| 13953 | 13953 | for tu_row in ch_row * tpc..(ch_row + 1) * tpc { |
| @@ -14309,8 +14309,8 @@ fn decode_block_128rect( | ||
| 14309 | 14309 | let tpc = 64 / logical_tx; |
| 14310 | 14310 | let zero_tu = vec![0i32; logical_tx * logical_tx]; |
| 14311 | 14311 | let zero_cu = vec![0i32; chroma_tx * chroma_tx]; |
| 14312 | - let mut last_grids = [Vec::new(), Vec::new()]; | |
| 14313 | - let mut units: Vec<((usize, usize), Vec<i32>, Vec<i32>)> = Vec::new(); | |
| 14312 | + let mut last_grids = [Grid::Zero(0), Grid::Zero(0)]; | |
| 14313 | + let mut units: Vec<((usize, usize), Grid, Grid)> = Vec::new(); | |
| 14314 | 14314 | for ch_row in 0..nch_y { |
| 14315 | 14315 | for ch_col in 0..nch_x { |
| 14316 | 14316 | for tu_row in ch_row * tpc..(ch_row + 1) * tpc { |
| @@ -14830,9 +14830,9 @@ fn decode_leaf8( | ||
| 14830 | 14830 | None, |
| 14831 | 14831 | smooth_neighbor_uv, fctx, |
| 14832 | 14832 | ); |
| 14833 | - luma_grid = vec![0i32; 64]; | |
| 14834 | - u_grid = vec![0i32; 16]; | |
| 14835 | - v_grid = vec![0i32; 16]; | |
| 14833 | + luma_grid = Grid::Zero(64); | |
| 14834 | + u_grid = Grid::Zero(16); | |
| 14835 | + v_grid = Grid::Zero(16); | |
| 14836 | 14836 | } else if resolved != 4 { |
| 14837 | 14837 | let around = neighbours.around_mi(leaf_mi, 8); |
| 14838 | 14838 | if let Some(buf) = &palette_y_buf { |
| @@ -15370,7 +15370,7 @@ fn decode_leaf_split4( | ||
| 15370 | 15370 | neighbours.above_uv_mode[c] = uv_predict_mode; |
| 15371 | 15371 | neighbours.left_uv_mode[r] = uv_predict_mode; |
| 15372 | 15372 | neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode); |
| 15373 | - let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if leaf_skips[3] { | |
| 15373 | + let (u_grid, v_grid): (Grid, Grid) = if leaf_skips[3] { | |
| 15374 | 15374 | // A skipped chroma block still gets its CfL contribution: libaom's |
| 15375 | 15375 | // `predict_and_reconstruct_intra_block` calls `cfl_predict_block` |
| 15376 | 15376 | // from `av1_predict_intra_block_facade` (av1/common/reconintra.c:1719) |
| @@ -15386,7 +15386,7 @@ fn decode_leaf_split4( | ||
| 15386 | 15386 | } |
| 15387 | 15387 | push_intra(1, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx); |
| 15388 | 15388 | push_intra(2, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx); |
| 15389 | - (vec![0i32; 16], vec![0i32; 16]) | |
| 15389 | + (Grid::Zero(16), Grid::Zero(16)) | |
| 15390 | 15390 | } else { |
| 15391 | 15391 | let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); |
| 15392 | 15392 | let chroma_around = neighbours.around_mi(leaf_mi, 8); |
| @@ -15662,7 +15662,7 @@ fn decode_leaf_rect8( | ||
| 15662 | 15662 | continue; |
| 15663 | 15663 | } |
| 15664 | 15664 | let grid = if skip { |
| 15665 | - let zeros = vec![0i32; bw * bh]; | |
| 15665 | + let zeros = Grid::Zero(bw * bh); | |
| 15666 | 15666 | push_intra_rect(0, |
| 15667 | 15667 | px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra, |
| 15668 | 15668 | smooth_neighbor, fctx, |
| @@ -15742,7 +15742,7 @@ fn decode_leaf_rect8( | ||
| 15742 | 15742 | neighbours.above_uv_mode[c] = uv_predict_mode; |
| 15743 | 15743 | neighbours.left_uv_mode[r] = uv_predict_mode; |
| 15744 | 15744 | neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode); |
| 15745 | - let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if leaf_skips[1] { | |
| 15745 | + let (u_grid, v_grid): (Grid, Grid) = if leaf_skips[1] { | |
| 15746 | 15746 | // A skipped chroma block still gets its CfL contribution: libaom's |
| 15747 | 15747 | // `predict_and_reconstruct_intra_block` calls `cfl_predict_block` |
| 15748 | 15748 | // from `av1_predict_intra_block_facade` (av1/common/reconintra.c:1719) |
| @@ -15758,7 +15758,7 @@ fn decode_leaf_rect8( | ||
| 15758 | 15758 | } |
| 15759 | 15759 | push_intra(1, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx); |
| 15760 | 15760 | push_intra(2, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx); |
| 15761 | - (vec![0i32; 16], vec![0i32; 16]) | |
| 15761 | + (Grid::Zero(16), Grid::Zero(16)) | |
| 15762 | 15762 | } else { |
| 15763 | 15763 | let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); |
| 15764 | 15764 | let chroma_around = neighbours.around_mi(leaf_mi, 8); |
| @@ -17676,7 +17676,7 @@ fn read_inter_plane_rect( | ||
| 17676 | 17676 | prediction: Pred<'_>, |
| 17677 | 17677 | inherited_luma_tx_type: Option<TxType>, |
| 17678 | 17678 | luma_skip_ctx: Option<usize>, fctx: &crate::decode::FrameCtx, |
| 17679 | -) -> Result<(Vec<i32>, TxType)> { | |
| 17679 | +) -> Result<(Grid, TxType)> { | |
| 17680 | 17680 | let skip_ctx = if plane_idx == 0 { |
| 17681 | 17681 | // `get_txb_ctx_general`: 0 only when this unit IS the whole plane |
| 17682 | 17682 | // block; a var-tx leaf passes its own neighbour-table context. |
| @@ -17733,15 +17733,7 @@ fn read_inter_plane_rect( | ||
| 17733 | 17733 | default_tx_type, |
| 17734 | 17734 | )? |
| 17735 | 17735 | }; |
| 17736 | - let grid = if (cw, ch) == (w, h) { | |
| 17737 | - corner | |
| 17738 | - } else { | |
| 17739 | - let mut full = vec![0i32; w * h]; | |
| 17740 | - for row in 0..ch { | |
| 17741 | - full[row * w..][..cw].copy_from_slice(&corner[row * cw..][..cw]); | |
| 17742 | - } | |
| 17743 | - full | |
| 17744 | - }; | |
| 17736 | + let grid = extend_corner(corner, cw, ch, w, h); | |
| 17745 | 17737 | let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx); |
| 17746 | 17738 | if crate::envflags::env_flag!("EC_TRACE_TXTYPE") { |
| 17747 | 17739 | eprintln!("OUR_TXTYPE plane={plane_idx} x={x} y={y} w={w} h={h} tx_type={tx_type:?} inh={inherited_luma_tx_type:?}"); |
| @@ -17757,6 +17749,24 @@ fn read_inter_plane_rect( | ||
| 17757 | 17749 | Ok((grid, tx_type)) |
| 17758 | 17750 | } |
| 17759 | 17751 | |
| 17752 | +/// The coded `cw x ch` corner of a transform zero-extended into its true | |
| 17753 | +/// `w x h` grid (a 64-length axis codes only its low 32 coefficients). A | |
| 17754 | +/// corner that coded nothing stays the shared zero grid -- no allocation | |
| 17755 | +/// (lane-coefgrid). | |
| 17756 | +fn extend_corner(corner: Grid, cw: usize, ch: usize, w: usize, h: usize) -> Grid { | |
| 17757 | + if (cw, ch) == (w, h) { | |
| 17758 | + return corner; | |
| 17759 | + } | |
| 17760 | + if let Grid::Zero(_) = corner { | |
| 17761 | + return Grid::Zero(w * h); | |
| 17762 | + } | |
| 17763 | + let mut full = vec![0i32; w * h]; | |
| 17764 | + for row in 0..ch { | |
| 17765 | + full[row * w..][..cw].copy_from_slice(&corner[row * cw..][..cw]); | |
| 17766 | + } | |
| 17767 | + Grid::Own(full) | |
| 17768 | +} | |
| 17769 | + | |
| 17760 | 17770 | /// A rect coefficient grid re-laid into the square `stride x stride` grid the |
| 17761 | 17771 | /// neighbour/deblock stamps downstream of the residual expect. |
| 17762 | 17772 | fn embed_rect_grid(grid: &[i32], w: usize, h: usize, stride: usize) -> Vec<i32> { |
| @@ -17791,7 +17801,7 @@ fn read_inter_luma8( | ||
| 17791 | 17801 | scan4: &[u16], |
| 17792 | 17802 | reduced_tx_set: bool, |
| 17793 | 17803 | split: bool, fctx: &crate::decode::FrameCtx, |
| 17794 | -) -> Result<(Vec<i32>, TxType)> { | |
| 17804 | +) -> Result<(Grid, TxType)> { | |
| 17795 | 17805 | if !split { |
| 17796 | 17806 | return read_inter_plane( |
| 17797 | 17807 | dec, |
| @@ -17848,7 +17858,7 @@ fn read_inter_luma8( | ||
| 17848 | 17858 | neighbours.record_mi_luma(tu_mi, 4, &tu_grid); |
| 17849 | 17859 | } |
| 17850 | 17860 | } |
| 17851 | - Ok((vec![0i32; 64], first)) | |
| 17861 | + Ok((Grid::Zero(64), first)) | |
| 17852 | 17862 | } |
| 17853 | 17863 | |
| 17854 | 17864 | /// The [`TxbSet`] one leaf of an inter block's var-tx tree reads its |
| @@ -23085,7 +23095,7 @@ fn read_inter_plane( | ||
| 23085 | 23095 | // transform every non-var-tx caller reads, whose plane-0 context is the |
| 23086 | 23096 | // lone-transform-unit 0. |
| 23087 | 23097 | luma_skip_ctx: Option<usize>, fctx: &crate::decode::FrameCtx, |
| 23088 | -) -> Result<(Vec<i32>, TxType)> { | |
| 23098 | +) -> Result<(Grid, TxType)> { | |
| 23089 | 23099 | let skip_ctx = if plane_idx == 0 { |
| 23090 | 23100 | luma_skip_ctx.unwrap_or(0) |
| 23091 | 23101 | } else { |
| @@ -23123,15 +23133,7 @@ fn read_inter_plane( | ||
| 23123 | 23133 | // [`read_plane`]'s own `tx_side != side` branch. Every other transform |
| 23124 | 23134 | // this decoder codes has `tx_side == side`, so this is inert below 64. |
| 23125 | 23135 | let tx_side = side.min(32); |
| 23126 | - let grid = if tx_side == side { | |
| 23127 | - grid | |
| 23128 | - } else { | |
| 23129 | - let mut full = vec![0i32; side * side]; | |
| 23130 | - for row in 0..tx_side { | |
| 23131 | - full[row * side..][..tx_side].copy_from_slice(&grid[row * tx_side..][..tx_side]); | |
| 23132 | - } | |
| 23133 | - full | |
| 23134 | - }; | |
| 23136 | + let grid = extend_corner(grid, tx_side, tx_side, side, side); | |
| 23135 | 23137 | let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx); |
| 23136 | 23138 | let tx = TxParams { |
| 23137 | 23139 | w: side, h: side, bit_depth: bit_depth(fctx), q_idx: block_q_idx(fctx), dc_delta, |
| @@ -25928,7 +25930,7 @@ fn decode_inter_block( | ||
| 25928 | 25930 | None, |
| 25929 | 25931 | None, fctx, |
| 25930 | 25932 | )?; |
| 25931 | - luma_grid = Grid::Own(coded.0); | |
| 25933 | + luma_grid = coded.0; | |
| 25932 | 25934 | luma_tx_type = coded.1; |
| 25933 | 25935 | } |
| 25934 | 25936 | } |
| @@ -25997,7 +25999,7 @@ fn decode_inter_block( | ||
| 25997 | 25999 | chroma_side, |
| 25998 | 26000 | )); |
| 25999 | 26001 | } else { |
| 26000 | - u_grid = Grid::Own(read_inter_plane( | |
| 26002 | + u_grid = read_inter_plane( | |
| 26001 | 26003 | dec, |
| 26002 | 26004 | cdfs, |
| 26003 | 26005 | chroma_set, |
| @@ -26014,8 +26016,8 @@ fn decode_inter_block( | ||
| 26014 | 26016 | Some(luma_tx_type), |
| 26015 | 26017 | None, fctx, |
| 26016 | 26018 | )? |
| 26017 | - .0); | |
| 26018 | - v_grid = Grid::Own(read_inter_plane( | |
| 26019 | + .0; | |
| 26020 | + v_grid = read_inter_plane( | |
| 26019 | 26021 | dec, |
| 26020 | 26022 | cdfs, |
| 26021 | 26023 | chroma_set, |
| @@ -26032,7 +26034,7 @@ fn decode_inter_block( | ||
| 26032 | 26034 | Some(luma_tx_type), |
| 26033 | 26035 | None, fctx, |
| 26034 | 26036 | )? |
| 26035 | - .0); | |
| 26037 | + .0; | |
| 26036 | 26038 | } |
| 26037 | 26039 | } |
| 26038 | 26040 | } else { |
| @@ -27202,7 +27204,7 @@ fn decode_inter_block( | ||
| 27202 | 27204 | None, |
| 27203 | 27205 | None, fctx, |
| 27204 | 27206 | )?; |
| 27205 | - luma_grid = Grid::Own(coded.0); | |
| 27207 | + luma_grid = coded.0; | |
| 27206 | 27208 | luma_tx_type = coded.1; |
| 27207 | 27209 | } |
| 27208 | 27210 | } |
| @@ -27280,7 +27282,7 @@ fn decode_inter_block( | ||
| 27280 | 27282 | chroma_side, |
| 27281 | 27283 | )); |
| 27282 | 27284 | } else { |
| 27283 | - u_grid = Grid::Own(read_inter_plane( | |
| 27285 | + u_grid = read_inter_plane( | |
| 27284 | 27286 | dec, |
| 27285 | 27287 | cdfs, |
| 27286 | 27288 | chroma_set, |
| @@ -27297,8 +27299,8 @@ fn decode_inter_block( | ||
| 27297 | 27299 | Some(luma_tx_type), |
| 27298 | 27300 | None, fctx, |
| 27299 | 27301 | )? |
| 27300 | - .0); | |
| 27301 | - v_grid = Grid::Own(read_inter_plane( | |
| 27302 | + .0; | |
| 27303 | + v_grid = read_inter_plane( | |
| 27302 | 27304 | dec, |
| 27303 | 27305 | cdfs, |
| 27304 | 27306 | chroma_set, |
| @@ -27315,7 +27317,7 @@ fn decode_inter_block( | ||
| 27315 | 27317 | Some(luma_tx_type), |
| 27316 | 27318 | None, fctx, |
| 27317 | 27319 | )? |
| 27318 | - .0); | |
| 27320 | + .0; | |
| 27319 | 27321 | } |
| 27320 | 27322 | } |
| 27321 | 27323 | } |
| @@ -27741,7 +27743,7 @@ fn decode_inter_block( | ||
| 27741 | 27743 | // so `txb_skip_ctx` is the neighbour-magnitude table, not |
| 27742 | 27744 | // the lone-TU 0 (`get_txb_ctx_general`). |
| 27743 | 27745 | let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI); |
| 27744 | - Grid::Own(read_plane( | |
| 27746 | + read_plane( | |
| 27745 | 27747 | dec, |
| 27746 | 27748 | cdfs, |
| 27747 | 27749 | txbset_for(tx_px, reduced), |
| @@ -27766,7 +27768,7 @@ fn decode_inter_block( | ||
| 27766 | 27768 | filter_intra, |
| 27767 | 27769 | Some(tu_skip_ctx), |
| 27768 | 27770 | smooth_neighbor, fctx, |
| 27769 | - )?) | |
| 27771 | + )? | |
| 27770 | 27772 | }; |
| 27771 | 27773 | neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid); |
| 27772 | 27774 | if side > 64 { |
| @@ -27807,7 +27809,7 @@ fn decode_inter_block( | ||
| 27807 | 27809 | ); |
| 27808 | 27810 | Grid::Zero(cu_tx * cu_tx) |
| 27809 | 27811 | } else { |
| 27810 | - Grid::Own(read_plane( | |
| 27812 | + read_plane( | |
| 27811 | 27813 | dec, |
| 27812 | 27814 | cdfs, |
| 27813 | 27815 | chroma_set, |
| @@ -27834,7 +27836,7 @@ fn decode_inter_block( | ||
| 27834 | 27836 | // (lane-sb128b r3). |
| 27835 | 27837 | Some(3), |
| 27836 | 27838 | smooth_neighbor_uv, fctx, |
| 27837 | - )?) | |
| 27839 | + )? | |
| 27838 | 27840 | }; |
| 27839 | 27841 | // Immediately, so the NEXT chunk's unit reads this |
| 27840 | 27842 | // one's coefficient context. |
| @@ -27932,7 +27934,7 @@ fn decode_inter_block( | ||
| 27932 | 27934 | if let Some(buf) = &palette_y_buf { |
| 27933 | 27935 | set_palette_pred(buf.clone(), fctx); |
| 27934 | 27936 | } |
| 27935 | - luma_grid = Grid::Own(read_plane( | |
| 27937 | + luma_grid = read_plane( | |
| 27936 | 27938 | dec, |
| 27937 | 27939 | cdfs, |
| 27938 | 27940 | luma_set_intra, |
| @@ -27953,13 +27955,13 @@ fn decode_inter_block( | ||
| 27953 | 27955 | filter_intra, |
| 27954 | 27956 | None, |
| 27955 | 27957 | smooth_neighbor, fctx, |
| 27956 | - )?); | |
| 27958 | + )?; | |
| 27957 | 27959 | } |
| 27958 | 27960 | let ac = alpha.map(|_| cfl_src(px, py, side)); |
| 27959 | 27961 | if let Some((ub, _)) = &palette_uv_bufs { |
| 27960 | 27962 | set_palette_pred(ub.clone(), fctx); |
| 27961 | 27963 | } |
| 27962 | - u_grid = Grid::Own(read_plane( | |
| 27964 | + u_grid = read_plane( | |
| 27963 | 27965 | dec, |
| 27964 | 27966 | cdfs, |
| 27965 | 27967 | chroma_set, |
| @@ -27980,11 +27982,11 @@ fn decode_inter_block( | ||
| 27980 | 27982 | None, |
| 27981 | 27983 | None, |
| 27982 | 27984 | smooth_neighbor_uv, fctx, |
| 27983 | - )?); | |
| 27985 | + )?; | |
| 27984 | 27986 | if let Some((_, vb)) = &palette_uv_bufs { |
| 27985 | 27987 | set_palette_pred(vb.clone(), fctx); |
| 27986 | 27988 | } |
| 27987 | - v_grid = Grid::Own(read_plane( | |
| 27989 | + v_grid = read_plane( | |
| 27988 | 27990 | dec, |
| 27989 | 27991 | cdfs, |
| 27990 | 27992 | chroma_set, |
| @@ -28005,7 +28007,7 @@ fn decode_inter_block( | ||
| 28005 | 28007 | None, |
| 28006 | 28008 | None, |
| 28007 | 28009 | smooth_neighbor_uv, fctx, |
| 28008 | - )?); | |
| 28010 | + )?; | |
| 28009 | 28011 | } |
| 28010 | 28012 | } |
| 28011 | 28013 | // lane-comppin r9: end-of-block checkpoint -- everything between |
| @@ -28037,7 +28039,7 @@ fn decode_inter_block( | ||
| 28037 | 28039 | // the partial right superblock read row 1 where libaom reads row 2). The |
| 28038 | 28040 | // units are collected here and re-stamped after that record, in mu-chunk |
| 28039 | 28041 | // order so a later unit still wins over an earlier one. |
| 28040 | - let mu_chroma_units: Vec<((usize, usize), usize, Vec<i32>)> = if mu_chroma { | |
| 28042 | + let mu_chroma_units: Vec<((usize, usize), usize, Grid)> = if mu_chroma { | |
| 28041 | 28043 | let cu = 32usize; |
| 28042 | 28044 | let mut units = Vec::new(); |
| 28043 | 28045 | for cr in 0..(write_h / 64).max(1) { |
| @@ -28049,7 +28051,7 @@ fn decode_inter_block( | ||
| 28049 | 28051 | let start = (cr * cu + rr) * chroma_side + cc * cu; |
| 28050 | 28052 | unit.extend_from_slice(&grid[start..start + cu]); |
| 28051 | 28053 | } |
| 28052 | - units.push((cu_mi, plane, unit)); | |
| 28054 | + units.push((cu_mi, plane, Grid::Own(unit))); | |
| 28053 | 28055 | } |
| 28054 | 28056 | } |
| 28055 | 28057 | } |
| @@ -28729,7 +28731,7 @@ fn decode_inter_sub8_split4( | ||
| 28729 | 28731 | let (u_grid, v_grid) = if last_skip { |
| 28730 | 28732 | push_mc(1, cpx, cpy, B4, Pred::dense(&pred_u), &ZERO_RESIDUAL[..B4 * B4], fctx); |
| 28731 | 28733 | push_mc(2, cpx, cpy, B4, Pred::dense(&pred_v), &ZERO_RESIDUAL[..B4 * B4], fctx); |
| 28732 | - (vec![0i32; B4 * B4], vec![0i32; B4 * B4]) | |
| 28734 | + (Grid::Zero(B4 * B4), Grid::Zero(B4 * B4)) | |
| 28733 | 28735 | } else { |
| 28734 | 28736 | let around = neighbours.around_mi(group_mi, 8); |
| 28735 | 28737 | let ug = read_inter_plane( |
| @@ -29036,7 +29038,7 @@ fn decode_intra_sub8_leaf( | ||
| 29036 | 29038 | } |
| 29037 | 29039 | } else { |
| 29038 | 29040 | let grid_levels = if skip { |
| 29039 | - let zeros = vec![0i32; bw * bh]; | |
| 29041 | + let zeros = Grid::Zero(bw * bh); | |
| 29040 | 29042 | push_intra_rect(0, |
| 29041 | 29043 | px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra, |
| 29042 | 29044 | smooth_neighbor, fctx, |
| @@ -29166,14 +29168,14 @@ fn decode_intra_sub8_leaf( | ||
| 29166 | 29168 | record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]); |
| 29167 | 29169 | |
| 29168 | 29170 | let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); |
| 29169 | - let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if skip { | |
| 29171 | + let (u_grid, v_grid): (Grid, Grid) = if skip { | |
| 29170 | 29172 | if alpha.is_some() { |
| 29171 | 29173 | CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1)); |
| 29172 | 29174 | SKIP_CFL_HITS.with(|c| c.set(c.get() + 1)); |
| 29173 | 29175 | } |
| 29174 | 29176 | push_intra(1, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx); |
| 29175 | 29177 | push_intra(2, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx); |
| 29176 | - (vec![0i32; 16], vec![0i32; 16]) | |
| 29178 | + (Grid::Zero(16), Grid::Zero(16)) | |
| 29177 | 29179 | } else { |
| 29178 | 29180 | let chroma_around = neighbours.around_mi(group_mi, 8); |
| 29179 | 29181 | let ug = read_plane( |
| @@ -29751,7 +29753,7 @@ fn decode_inter_sub8_rect2( | ||
| 29751 | 29753 | let (u_grid, v_grid) = if last_skip { |
| 29752 | 29754 | push_mc(1, cpx, cpy, B4, Pred::dense(&pred_u), &ZERO_RESIDUAL[..B4 * B4], fctx); |
| 29753 | 29755 | push_mc(2, cpx, cpy, B4, Pred::dense(&pred_v), &ZERO_RESIDUAL[..B4 * B4], fctx); |
| 29754 | - (vec![0i32; B4 * B4], vec![0i32; B4 * B4]) | |
| 29756 | + (Grid::Zero(B4 * B4), Grid::Zero(B4 * B4)) | |
| 29755 | 29757 | } else { |
| 29756 | 29758 | let around = neighbours.around_mi(group_mi, 8); |
| 29757 | 29759 | let ug = read_inter_plane( |
| @@ -30597,9 +30599,9 @@ fn decode_inter_block8( | ||
| 30597 | 30599 | Pred::dense(&pred_v), |
| 30598 | 30600 | &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx, |
| 30599 | 30601 | ); |
| 30600 | - luma_grid = vec![0i32; SIDE * SIDE]; | |
| 30601 | - u_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; | |
| 30602 | - v_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; | |
| 30602 | + luma_grid = Grid::Zero(SIDE * SIDE); | |
| 30603 | + u_grid = Grid::Zero(CHROMA_SIDE * CHROMA_SIDE); | |
| 30604 | + v_grid = Grid::Zero(CHROMA_SIDE * CHROMA_SIDE); | |
| 30603 | 30605 | } else { |
| 30604 | 30606 | let around = neighbours.around_mi(leaf_mi, 8); |
| 30605 | 30607 | let (grid8, luma_tx_type) = read_inter_luma8( |
| @@ -31245,9 +31247,9 @@ fn decode_inter_block8( | ||
| 31245 | 31247 | Pred::dense(&pred_v), |
| 31246 | 31248 | &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx, |
| 31247 | 31249 | ); |
| 31248 | - luma_grid = vec![0i32; SIDE * SIDE]; | |
| 31249 | - u_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; | |
| 31250 | - v_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; | |
| 31250 | + luma_grid = Grid::Zero(SIDE * SIDE); | |
| 31251 | + u_grid = Grid::Zero(CHROMA_SIDE * CHROMA_SIDE); | |
| 31252 | + v_grid = Grid::Zero(CHROMA_SIDE * CHROMA_SIDE); | |
| 31251 | 31253 | } else { |
| 31252 | 31254 | let around = neighbours.around_mi(leaf_mi, 8); |
| 31253 | 31255 | let (grid8, luma_tx_type) = read_inter_luma8( |
| @@ -31611,7 +31613,7 @@ fn decode_inter_block8( | ||
| 31611 | 31613 | filter_intra, |
| 31612 | 31614 | smooth_neighbor, fctx, |
| 31613 | 31615 | ); |
| 31614 | - vec![0i32; tx_px * tx_px] | |
| 31616 | + Grid::Zero(tx_px * tx_px) | |
| 31615 | 31617 | } else { |
| 31616 | 31618 | // The unit is smaller than the block it sits in, so |
| 31617 | 31619 | // `txb_skip_ctx` is the neighbour-magnitude table, not |
| @@ -31698,16 +31700,16 @@ fn decode_inter_block8( | ||
| 31698 | 31700 | None, |
| 31699 | 31701 | smooth_neighbor_uv, fctx, |
| 31700 | 31702 | ); |
| 31701 | - luma_grid = vec![0i32; SIDE * SIDE]; | |
| 31702 | - u_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; | |
| 31703 | - v_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; | |
| 31703 | + luma_grid = Grid::Zero(SIDE * SIDE); | |
| 31704 | + u_grid = Grid::Zero(CHROMA_SIDE * CHROMA_SIDE); | |
| 31705 | + v_grid = Grid::Zero(CHROMA_SIDE * CHROMA_SIDE); | |
| 31704 | 31706 | } else { |
| 31705 | 31707 | let around = neighbours.around_mi(leaf_mi, 8); |
| 31706 | 31708 | luma_grid = if split8 { |
| 31707 | 31709 | // Already coded and reconstructed unit by unit above; the |
| 31708 | 31710 | // block-level grid only feeds the neighbour write-back, |
| 31709 | 31711 | // which the `saved_luma_ctx` restore below keeps per-TU. |
| 31710 | - vec![0i32; SIDE * SIDE] | |
| 31712 | + Grid::Zero(SIDE * SIDE) | |
| 31711 | 31713 | } else { |
| 31712 | 31714 | if let Some(buf) = &palette_y_buf { |
| 31713 | 31715 | set_palette_pred(buf.clone(), fctx); |