forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-coefgrid' (2e37f9aa): coefficient readers return the Grid enum so all-zero units alias the static zero residual (no per-unit Vec, no zero fill), pointer test replaces the full all-zero scan in the dequantiser and the neighbour-state sum; byte-exact, -1.2% instructions, -44% single-thread page faults

Browse files at this commit

14f4482798ce82c4e41c6a9c6a047c36d3ad3df0Ahmet Kaan GümüşParent: 1d9f0d37002e78
crates/ec-av1/src/decode.rsmodified+114 -104
@@ -2140,7 +2140,7 @@ impl Residual {
2140 /// the empty marker, so neither the grid nor the residual is cloned and2140 /// the empty marker, so neither the grid nor the residual is cloned and
2141 /// the worker never runs the transform (60% of the 4K segment's units).2141 /// the worker never runs the transform (60% of the 4K segment's units).
2142 fn coeffs(tx: TxParams, grid: &[i32], fctx: &crate::decode::FrameCtx) -> Self {2142 fn coeffs(tx: TxParams, grid: &[i32], fctx: &crate::decode::FrameCtx) -> Self {
2143- if grid.iter().all(|&c| c == 0) {2143+ if is_zero_grid(grid) {
2144 return Self::Done(0, 0);2144 return Self::Done(0, 0);
2145 }2145 }
2146 Self::Coeffs(tx, push_coeffs(grid, fctx), grid.len() as u32)2146 Self::Coeffs(tx, push_coeffs(grid, fctx), grid.len() as u32)
@@ -2197,13 +2197,14 @@ fn push_pred_samples(v: &[u16], fctx: &crate::decode::FrameCtx) -> u32 {
2197 /// and the reconstruction loops below read this instead of a per-unit2197 /// and the reconstruction loops below read this instead of a per-unit
2198 /// `vec![0; w * h]`. Sized for the largest stride a recorded unit can carry2198 /// `vec![0; w * h]`. Sized for the largest stride a recorded unit can carry
2199 /// (a 128-wide inter block's prediction stride).2199 /// (a 128-wide inter block's prediction stride).
2200-static ZERO_RESIDUAL: [i32; 128 * 128] = [0; 128 * 128];2200+pub(crate) static ZERO_RESIDUAL: [i32; 128 * 128] = [0; 128 * 128];
2201 2201
2202 /// lane-blockscratch: one plane's coefficient levels as the block-tail2202 /// lane-blockscratch: one plane's coefficient levels as the block-tail
2203 /// neighbour writes want them. A plane that coded nothing (a skipped block, a2203 /// neighbour writes want them. A plane that coded nothing (a skipped block, a
2204 /// strip with no chroma, luma under a var-tx split whose units already wrote2204 /// strip with no chroma, luma under a var-tx split whose units already wrote
2205 /// themselves) names the shared [`ZERO_RESIDUAL`] instead of allocating and2205 /// themselves) names the shared [`ZERO_RESIDUAL`] instead of allocating and
2206 /// zeroing up to 64 KB of its own per block.2206 /// zeroing up to 64 KB of its own per block.
2207+#[derive(Clone)]
2207 enum Grid {2208 enum Grid {
2208 Zero(usize),2209 Zero(usize),
2209 Own(Vec<i32>),2210 Own(Vec<i32>),
@@ -2230,6 +2231,13 @@ impl std::ops::Deref for Grid {
2230 }2231 }
2231 }2232 }
2232 2233
2234+/// Whether a coefficient grid codes nothing: a [`Grid::Zero`] unit IS the
2235+/// shared [`ZERO_RESIDUAL`], so one pointer compare answers the 60% of
2236+/// transform units that code no coefficient without the scan (lane-coefgrid).
2237+pub(crate) fn is_zero_grid(grid: &[i32]) -> bool {
2238+ std::ptr::eq(grid.as_ptr(), ZERO_RESIDUAL.as_ptr()) || grid.iter().all(|&c| c == 0)
2239+}
2240+
2233 /// `residual`, or `n` zeros when it is the empty all-zero marker.2241 /// `residual`, or `n` zeros when it is the empty all-zero marker.
2234 fn dense_residual(residual: &[i32], n: usize) -> &[i32] {2242 fn dense_residual(residual: &[i32], n: usize) -> &[i32] {
2235 if residual.is_empty() { &ZERO_RESIDUAL[..n] } else { residual }2243 if residual.is_empty() { &ZERO_RESIDUAL[..n] } else { residual }
@@ -5897,10 +5905,9 @@ fn read_coeffs(
5897 // root cause, see [`base_ctx`]). `None` everywhere else -- every other5905 // root cause, see [`base_ctx`]). `None` everywhere else -- every other
5898 // caller's block genuinely is `side` x `side`.5906 // caller's block genuinely is `side` x `side`.
5899 rect_shape: Option<(usize, usize)>,5907 rect_shape: Option<(usize, usize)>,
5900-) -> Result<(Vec<i32>, TxType)> {5908+) -> Result<(Grid, TxType)> {
5901 let trace = crate::envflags::env_flag!("EC_AV1_TRACE");5909 let trace = crate::envflags::env_flag!("EC_AV1_TRACE");
5902 let side = coding.side;5910 let side = coding.side;
5903- let mut grid = vec![0i32; side * side];
5904 if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") {5911 if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") {
5905 let (range, value) = dec.debug_state();5912 let (range, value) = dec.debug_state();
5906 eprintln!("EC_AV1_STATE_BEFORE_TXBSKIP range={range} value={value}");5913 eprintln!("EC_AV1_STATE_BEFORE_TXBSKIP range={range} value={value}");
@@ -5933,8 +5940,11 @@ fn read_coeffs(
5933 eprintln!("EC_AV1_STATE_AFTER_TXBSKIP range={range} value={value}");5940 eprintln!("EC_AV1_STATE_AFTER_TXBSKIP range={range} value={value}");
5934 }5941 }
5935 if all_zero {5942 if all_zero {
5936- return Ok((grid, TxType::DctDct));5943+ // lane-coefgrid: the all-zero unit (60% of the 4K segment's) names the
5944+ // shared zero grid instead of allocating and zeroing its own.
5945+ return Ok((Grid::Zero(side * side), TxType::DctDct));
5937 }5946 }
5947+ let mut grid = vec![0i32; side * side];
5938 let mut tx_type = default_tx_type;5948 let mut tx_type = default_tx_type;
5939 if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() {5949 if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() {
5940 // The CDF row's own width names its set (lane-cdffwd2: extended5950 // The CDF row's own width names its set (lane-cdffwd2: extended
@@ -6116,7 +6126,7 @@ fn read_coeffs(
6116 }6126 }
6117 grid[pos] = if negative { -level } else { level };6127 grid[pos] = if negative { -level } else { level };
6118 }6128 }
6119- Ok((grid, tx_type))6129+ Ok((Grid::Own(grid), tx_type))
6120 }6130 }
6121 6131
6122 /// [`read_coeffs`] widened to `(w, h)` (lane-rectwire; lane-rectx added the6132 /// [`read_coeffs`] widened to `(w, h)` (lane-rectwire; lane-rectx added the
@@ -6136,9 +6146,8 @@ fn read_coeffs_rect(
6136 skip_ctx: usize,6146 skip_ctx: usize,
6137 sign_ctx: usize,6147 sign_ctx: usize,
6138 default_tx_type: TxType,6148 default_tx_type: TxType,
6139-) -> Result<(Vec<i32>, TxType)> {6149+) -> Result<(Grid, TxType)> {
6140 let rect_trace = coeff_trace_on();6150 let rect_trace = coeff_trace_on();
6141- let mut grid = vec![0i32; w * h];
6142 let entry_rng = dec.debug_state().0;6151 let entry_rng = dec.debug_state().0;
6143 let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1;6152 let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1;
6144 if rect_trace {6153 if rect_trace {
@@ -6149,8 +6158,9 @@ fn read_coeffs_rect(
6149 );6158 );
6150 }6159 }
6151 if all_zero {6160 if all_zero {
6152- return Ok((grid, TxType::DctDct));6161+ return Ok((Grid::Zero(w * h), TxType::DctDct));
6153 }6162 }
6163+ let mut grid = vec![0i32; w * h];
6154 RECT_COEFF_TU_HITS.with(|c| c.set(c.get() + 1));6164 RECT_COEFF_TU_HITS.with(|c| c.set(c.get() + 1));
6155 // lane-tx4x8: a 4x8/8x4 luma TU DOES carry a `tx_type` symbol (its set is6165 // lane-tx4x8: a 4x8/8x4 luma TU DOES carry a `tx_type` symbol (its set is
6156 // `EXT_TX_SET_DTT4_IDTX(_1DDCT)`, `tx_size_sqr_up == TX_8X8`), including6166 // `EXT_TX_SET_DTT4_IDTX(_1DDCT)`, `tx_size_sqr_up == TX_8X8`), including
@@ -6288,7 +6298,7 @@ fn read_coeffs_rect(
6288 };6298 };
6289 grid[pos] = if negative { -level } else { level };6299 grid[pos] = if negative { -level } else { level };
6290 }6300 }
6291- Ok((grid, tx_type))6301+ Ok((Grid::Own(grid), tx_type))
6292 }6302 }
6293 6303
6294 /// What one coded block leaves behind for the blocks that read it as a6304 /// What one coded block leaves behind for the blocks that read it as a
@@ -6324,6 +6334,12 @@ fn fill_span<T: Copy>(dst: &mut [T], start: usize, n: usize, v: T) {
6324 }6334 }
6325 6335
6326 fn neighbour_state(grid: &[i32]) -> Neighbour {6336 fn neighbour_state(grid: &[i32]) -> Neighbour {
6337+ // lane-coefgrid: the shared zero grid sums to zero by construction; this
6338+ // sum has no early exit, so the 60% of units that code nothing used to
6339+ // walk their whole grid here.
6340+ if is_zero_grid(grid) {
6341+ return Neighbour::default();
6342+ }
6327 let cul: u32 = grid.iter().map(|&l| l.unsigned_abs()).sum();6343 let cul: u32 = grid.iter().map(|&l| l.unsigned_abs()).sum();
6328 Neighbour {6344 Neighbour {
6329 level: cul.min(7) as u8,6345 level: cul.min(7) as u8,
@@ -9223,7 +9239,7 @@ fn decode_rect_split(
9223 let ac = m.alpha.map(|_| cfl_src_rect(px, py, bw, bh));9239 let ac = m.alpha.map(|_| cfl_src_rect(px, py, bw, bh));
9224 let reach = block_reach;9240 let reach = block_reach;
9225 let (u_grid, v_grid) = if m.skip {9241 let (u_grid, v_grid) = if m.skip {
9226- let zero = vec![0i32; chroma_w * chroma_h];9242+ let zero = Grid::Zero(chroma_w * chroma_h);
9227 if let Some((ub, _)) = &m.palette_uv {9243 if let Some((ub, _)) = &m.palette_uv {
9228 set_palette_pred(ub.clone(), fctx);9244 set_palette_pred(ub.clone(), fctx);
9229 }9245 }
@@ -9250,7 +9266,7 @@ fn decode_rect_split(
9250 default_intra_tx_type(m.uv_predict_mode as u8)9266 default_intra_tx_type(m.uv_predict_mode as u8)
9251 };9267 };
9252 let around = neighbours.around_mi_rect(at_mi, bw, bh);9268 let around = neighbours.around_mi_rect(at_mi, bw, bh);
9253- let mut grids: Vec<Vec<i32>> = Vec::with_capacity(2);9269+ let mut grids: Vec<Grid> = Vec::with_capacity(2);
9254 for plane_idx in 1..=2 {9270 for plane_idx in 1..=2 {
9255 let skip_ctx =9271 let skip_ctx =
9256 usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1);9272 usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1);
@@ -10719,9 +10735,9 @@ fn decode_leaf_rect(
10719 let (chroma_w, chroma_h) = (bw / 2, bh / 2);10735 let (chroma_w, chroma_h) = (bw / 2, bh / 2);
10720 let (luma_levels, u_levels, v_levels);10736 let (luma_levels, u_levels, v_levels);
10721 if skip {10737 if skip {
10722- luma_levels = vec![0i32; bw * bh];10738+ luma_levels = Grid::Zero(bw * bh);
10723- u_levels = vec![0i32; chroma_w * chroma_h];10739+ u_levels = Grid::Zero(chroma_w * chroma_h);
10724- v_levels = vec![0i32; chroma_w * chroma_h];10740+ v_levels = Grid::Zero(chroma_w * chroma_h);
10725 if let Some(b) = &palette_y_buf {10741 if let Some(b) = &palette_y_buf {
10726 set_palette_pred(b.clone(), fctx);10742 set_palette_pred(b.clone(), fctx);
10727 }10743 }
@@ -11647,7 +11663,7 @@ fn decode_rect4_16_strip(
11647 }11663 }
11648 } else {11664 } else {
11649 let levels = if skip {11665 let levels = if skip {
11650- let zeros = vec![0i32; bw * bh];11666+ let zeros = Grid::Zero(bw * bh);
11651 if let Some(b) = &palette_y_buf {11667 if let Some(b) = &palette_y_buf {
11652 set_palette_pred(b.clone(), fctx);11668 set_palette_pred(b.clone(), fctx);
11653 }11669 }
@@ -11748,7 +11764,7 @@ fn decode_rect4_16_strip(
11748 RECT4_16_UV_PAIR_FILT_HITS.with(|h| h.set(h.get() + 1));11764 RECT4_16_UV_PAIR_FILT_HITS.with(|h| h.set(h.get() + 1));
11749 }11765 }
11750 let (u_levels, v_levels) = if skip {11766 let (u_levels, v_levels) = if skip {
11751- let zeros = vec![0i32; cw * ch];11767+ let zeros = Grid::Zero(cw * ch);
11752 // libaom `predict_and_reconstruct_intra_block` (decodeframe.c11768 // libaom `predict_and_reconstruct_intra_block` (decodeframe.c
11753 // ~1000) predicts EVERY plane and only guards the residual on11769 // ~1000) predicts EVERY plane and only guards the residual on
11754 // `mbmi->skip_txfm`, so a skipped `UV_CFL_PRED` block is still11770 // `mbmi->skip_txfm`, so a skipped `UV_CFL_PRED` block is still
@@ -13350,7 +13366,7 @@ fn read_plane(
13350 luma_skip_ctx: Option<usize>,13366 luma_skip_ctx: Option<usize>,
13351 // See [`PlaneBuf::reconstruct`]'s own doc: caller's neighbour-smooth check.13367 // See [`PlaneBuf::reconstruct`]'s own doc: caller's neighbour-smooth check.
13352 smooth_neighbor: bool, fctx: &crate::decode::FrameCtx,13368 smooth_neighbor: bool, fctx: &crate::decode::FrameCtx,
13353-) -> Result<Vec<i32>> {13369+) -> Result<Grid> {
13354 let skip_ctx = if plane_idx == 0 {13370 let skip_ctx = if plane_idx == 0 {
13355 luma_skip_ctx.unwrap_or(0)13371 luma_skip_ctx.unwrap_or(0)
13356 } else {13372 } else {
@@ -13410,19 +13426,11 @@ fn read_plane(
13410 // top-left 32x32 of frequencies are coded (spec 5.11.40); the rest of the13426 // top-left 32x32 of frequencies are coded (spec 5.11.40); the rest of the
13411 // dequantized grid stays zero, which `inverse_transform_2d`'s own `< 32`13427 // dequantized grid stays zero, which `inverse_transform_2d`'s own `< 32`
13412 // guard also assumes.13428 // guard also assumes.
13413- let levels = if tx_side == side {13429+ // `grid` is `tx_side x tx_side` (the coded corner); `dequant_and_inverse`
13414- grid13430+ // wants the true `side x side` transform, with dqDenom (spec 7.12.3)
13415- } else {13431+ // keyed by that true size, not the coded corner's -- so the corner
13416- // `grid` is `tx_side x tx_side` (the coded corner); `dequant_and_inverse`13432+ // goes into the top-left of a `side`-sized grid, not the reverse.
13417- // wants the true `side x side` transform, with dqDenom (spec 7.12.3)13433+ let levels = extend_corner(grid, tx_side, tx_side, side, side);
13418- // keyed by that true size, not the coded corner's -- so the corner
13419- // goes into the top-left of a `side`-sized grid, not the reverse.
13420- let mut full = vec![0i32; side * side];
13421- for row in 0..tx_side {
13422- full[row * side..][..tx_side].copy_from_slice(&grid[row * tx_side..][..tx_side]);
13423- }
13424- full
13425- };
13426 let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx);13434 let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx);
13427 let tx = TxParams {13435 let tx = TxParams {
13428 w: side, h: side, bit_depth: bit_depth(fctx), q_idx: block_q_idx(fctx), dc_delta,13436 w: side, h: side, bit_depth: bit_depth(fctx), q_idx: block_q_idx(fctx), dc_delta,
@@ -13431,7 +13439,7 @@ fn read_plane(
13431 if crate::envflags::env_flag!("EC_AV1_TRACE") {13439 if crate::envflags::env_flag!("EC_AV1_TRACE") {
13432 let residual = tx.run(&levels);13440 let residual = tx.run(&levels);
13433 eprintln!(13441 eprintln!(
13434- "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={levels:?} residual={residual:?}",13442+ "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={:?} residual={residual:?}", &*levels,
13435 );13443 );
13436 }13444 }
13437 push_intra_tx(13445 push_intra_tx(
@@ -13945,8 +13953,8 @@ fn decode_block(
13945 let chroma_ctx_offset = if cn > 1 { Some(3) } else { None };13953 let chroma_ctx_offset = if cn > 1 { Some(3) } else { None };
13946 let tpc = (n_axis / nchunk).max(1);13954 let tpc = (n_axis / nchunk).max(1);
13947 let cpc = (cn / nchunk).max(1);13955 let cpc = (cn / nchunk).max(1);
13948- let mut last_grids = [Vec::new(), Vec::new()];13956+ let mut last_grids = [Grid::Zero(0), Grid::Zero(0)];
13949- let mut units: Vec<((usize, usize), usize, Vec<i32>, Vec<i32>)> = Vec::new();13957+ let mut units: Vec<((usize, usize), usize, Grid, Grid)> = Vec::new();
13950 for ch_row in 0..nchunk {13958 for ch_row in 0..nchunk {
13951 for ch_col in 0..nchunk {13959 for ch_col in 0..nchunk {
13952 for tu_row in ch_row * tpc..(ch_row + 1) * tpc {13960 for tu_row in ch_row * tpc..(ch_row + 1) * tpc {
@@ -14308,8 +14316,8 @@ fn decode_block_128rect(
14308 let tpc = 64 / logical_tx;14316 let tpc = 64 / logical_tx;
14309 let zero_tu = vec![0i32; logical_tx * logical_tx];14317 let zero_tu = vec![0i32; logical_tx * logical_tx];
14310 let zero_cu = vec![0i32; chroma_tx * chroma_tx];14318 let zero_cu = vec![0i32; chroma_tx * chroma_tx];
14311- let mut last_grids = [Vec::new(), Vec::new()];14319+ let mut last_grids = [Grid::Zero(0), Grid::Zero(0)];
14312- let mut units: Vec<((usize, usize), Vec<i32>, Vec<i32>)> = Vec::new();14320+ let mut units: Vec<((usize, usize), Grid, Grid)> = Vec::new();
14313 for ch_row in 0..nch_y {14321 for ch_row in 0..nch_y {
14314 for ch_col in 0..nch_x {14322 for ch_col in 0..nch_x {
14315 for tu_row in ch_row * tpc..(ch_row + 1) * tpc {14323 for tu_row in ch_row * tpc..(ch_row + 1) * tpc {
@@ -14829,9 +14837,9 @@ fn decode_leaf8(
14829 None,14837 None,
14830 smooth_neighbor_uv, fctx,14838 smooth_neighbor_uv, fctx,
14831 );14839 );
14832- luma_grid = vec![0i32; 64];14840+ luma_grid = Grid::Zero(64);
14833- u_grid = vec![0i32; 16];14841+ u_grid = Grid::Zero(16);
14834- v_grid = vec![0i32; 16];14842+ v_grid = Grid::Zero(16);
14835 } else if resolved != 4 {14843 } else if resolved != 4 {
14836 let around = neighbours.around_mi(leaf_mi, 8);14844 let around = neighbours.around_mi(leaf_mi, 8);
14837 if let Some(buf) = &palette_y_buf {14845 if let Some(buf) = &palette_y_buf {
@@ -15369,7 +15377,7 @@ fn decode_leaf_split4(
15369 neighbours.above_uv_mode[c] = uv_predict_mode;15377 neighbours.above_uv_mode[c] = uv_predict_mode;
15370 neighbours.left_uv_mode[r] = uv_predict_mode;15378 neighbours.left_uv_mode[r] = uv_predict_mode;
15371 neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode);15379 neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode);
15372- let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if leaf_skips[3] {15380+ let (u_grid, v_grid): (Grid, Grid) = if leaf_skips[3] {
15373 // A skipped chroma block still gets its CfL contribution: libaom's15381 // A skipped chroma block still gets its CfL contribution: libaom's
15374 // `predict_and_reconstruct_intra_block` calls `cfl_predict_block`15382 // `predict_and_reconstruct_intra_block` calls `cfl_predict_block`
15375 // from `av1_predict_intra_block_facade` (av1/common/reconintra.c:1719)15383 // from `av1_predict_intra_block_facade` (av1/common/reconintra.c:1719)
@@ -15385,7 +15393,7 @@ fn decode_leaf_split4(
15385 }15393 }
15386 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);15394 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);
15387 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);15395 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);
15388- (vec![0i32; 16], vec![0i32; 16])15396+ (Grid::Zero(16), Grid::Zero(16))
15389 } else {15397 } else {
15390 let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));15398 let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));
15391 let chroma_around = neighbours.around_mi(leaf_mi, 8);15399 let chroma_around = neighbours.around_mi(leaf_mi, 8);
@@ -15661,7 +15669,7 @@ fn decode_leaf_rect8(
15661 continue;15669 continue;
15662 }15670 }
15663 let grid = if skip {15671 let grid = if skip {
15664- let zeros = vec![0i32; bw * bh];15672+ let zeros = Grid::Zero(bw * bh);
15665 push_intra_rect(0, 15673 push_intra_rect(0,
15666 px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra,15674 px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra,
15667 smooth_neighbor, fctx,15675 smooth_neighbor, fctx,
@@ -15741,7 +15749,7 @@ fn decode_leaf_rect8(
15741 neighbours.above_uv_mode[c] = uv_predict_mode;15749 neighbours.above_uv_mode[c] = uv_predict_mode;
15742 neighbours.left_uv_mode[r] = uv_predict_mode;15750 neighbours.left_uv_mode[r] = uv_predict_mode;
15743 neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode);15751 neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode);
15744- let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if leaf_skips[1] {15752+ let (u_grid, v_grid): (Grid, Grid) = if leaf_skips[1] {
15745 // A skipped chroma block still gets its CfL contribution: libaom's15753 // A skipped chroma block still gets its CfL contribution: libaom's
15746 // `predict_and_reconstruct_intra_block` calls `cfl_predict_block`15754 // `predict_and_reconstruct_intra_block` calls `cfl_predict_block`
15747 // from `av1_predict_intra_block_facade` (av1/common/reconintra.c:1719)15755 // from `av1_predict_intra_block_facade` (av1/common/reconintra.c:1719)
@@ -15757,7 +15765,7 @@ fn decode_leaf_rect8(
15757 }15765 }
15758 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);15766 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);
15759 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);15767 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);
15760- (vec![0i32; 16], vec![0i32; 16])15768+ (Grid::Zero(16), Grid::Zero(16))
15761 } else {15769 } else {
15762 let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));15770 let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));
15763 let chroma_around = neighbours.around_mi(leaf_mi, 8);15771 let chroma_around = neighbours.around_mi(leaf_mi, 8);
@@ -17675,7 +17683,7 @@ fn read_inter_plane_rect(
17675 prediction: Pred<'_>,17683 prediction: Pred<'_>,
17676 inherited_luma_tx_type: Option<TxType>,17684 inherited_luma_tx_type: Option<TxType>,
17677 luma_skip_ctx: Option<usize>, fctx: &crate::decode::FrameCtx,17685 luma_skip_ctx: Option<usize>, fctx: &crate::decode::FrameCtx,
17678-) -> Result<(Vec<i32>, TxType)> {17686+) -> Result<(Grid, TxType)> {
17679 let skip_ctx = if plane_idx == 0 {17687 let skip_ctx = if plane_idx == 0 {
17680 // `get_txb_ctx_general`: 0 only when this unit IS the whole plane17688 // `get_txb_ctx_general`: 0 only when this unit IS the whole plane
17681 // block; a var-tx leaf passes its own neighbour-table context.17689 // block; a var-tx leaf passes its own neighbour-table context.
@@ -17732,15 +17740,7 @@ fn read_inter_plane_rect(
17732 default_tx_type,17740 default_tx_type,
17733 )?17741 )?
17734 };17742 };
17735- let grid = if (cw, ch) == (w, h) {17743+ let grid = extend_corner(corner, cw, ch, w, h);
17736- corner
17737- } else {
17738- let mut full = vec![0i32; w * h];
17739- for row in 0..ch {
17740- full[row * w..][..cw].copy_from_slice(&corner[row * cw..][..cw]);
17741- }
17742- full
17743- };
17744 let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx);17744 let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx);
17745 if crate::envflags::env_flag!("EC_TRACE_TXTYPE") {17745 if crate::envflags::env_flag!("EC_TRACE_TXTYPE") {
17746 eprintln!("OUR_TXTYPE plane={plane_idx} x={x} y={y} w={w} h={h} tx_type={tx_type:?} inh={inherited_luma_tx_type:?}");17746 eprintln!("OUR_TXTYPE plane={plane_idx} x={x} y={y} w={w} h={h} tx_type={tx_type:?} inh={inherited_luma_tx_type:?}");
@@ -17756,6 +17756,24 @@ fn read_inter_plane_rect(
17756 Ok((grid, tx_type))17756 Ok((grid, tx_type))
17757 }17757 }
17758 17758
17759+/// The coded `cw x ch` corner of a transform zero-extended into its true
17760+/// `w x h` grid (a 64-length axis codes only its low 32 coefficients). A
17761+/// corner that coded nothing stays the shared zero grid -- no allocation
17762+/// (lane-coefgrid).
17763+fn extend_corner(corner: Grid, cw: usize, ch: usize, w: usize, h: usize) -> Grid {
17764+ if (cw, ch) == (w, h) {
17765+ return corner;
17766+ }
17767+ if let Grid::Zero(_) = corner {
17768+ return Grid::Zero(w * h);
17769+ }
17770+ let mut full = vec![0i32; w * h];
17771+ for row in 0..ch {
17772+ full[row * w..][..cw].copy_from_slice(&corner[row * cw..][..cw]);
17773+ }
17774+ Grid::Own(full)
17775+}
17776+
17759 /// A rect coefficient grid re-laid into the square `stride x stride` grid the17777 /// A rect coefficient grid re-laid into the square `stride x stride` grid the
17760 /// neighbour/deblock stamps downstream of the residual expect.17778 /// neighbour/deblock stamps downstream of the residual expect.
17761 fn embed_rect_grid(grid: &[i32], w: usize, h: usize, stride: usize) -> Vec<i32> {17779 fn embed_rect_grid(grid: &[i32], w: usize, h: usize, stride: usize) -> Vec<i32> {
@@ -17790,7 +17808,7 @@ fn read_inter_luma8(
17790 scan4: &[u16],17808 scan4: &[u16],
17791 reduced_tx_set: bool,17809 reduced_tx_set: bool,
17792 split: bool, fctx: &crate::decode::FrameCtx,17810 split: bool, fctx: &crate::decode::FrameCtx,
17793-) -> Result<(Vec<i32>, TxType)> {17811+) -> Result<(Grid, TxType)> {
17794 if !split {17812 if !split {
17795 return read_inter_plane(17813 return read_inter_plane(
17796 dec,17814 dec,
@@ -17847,7 +17865,7 @@ fn read_inter_luma8(
17847 neighbours.record_mi_luma(tu_mi, 4, &tu_grid);17865 neighbours.record_mi_luma(tu_mi, 4, &tu_grid);
17848 }17866 }
17849 }17867 }
17850- Ok((vec![0i32; 64], first))17868+ Ok((Grid::Zero(64), first))
17851 }17869 }
17852 17870
17853 /// The [`TxbSet`] one leaf of an inter block's var-tx tree reads its17871 /// The [`TxbSet`] one leaf of an inter block's var-tx tree reads its
@@ -23084,7 +23102,7 @@ fn read_inter_plane(
23084 // transform every non-var-tx caller reads, whose plane-0 context is the23102 // transform every non-var-tx caller reads, whose plane-0 context is the
23085 // lone-transform-unit 0.23103 // lone-transform-unit 0.
23086 luma_skip_ctx: Option<usize>, fctx: &crate::decode::FrameCtx,23104 luma_skip_ctx: Option<usize>, fctx: &crate::decode::FrameCtx,
23087-) -> Result<(Vec<i32>, TxType)> {23105+) -> Result<(Grid, TxType)> {
23088 let skip_ctx = if plane_idx == 0 {23106 let skip_ctx = if plane_idx == 0 {
23089 luma_skip_ctx.unwrap_or(0)23107 luma_skip_ctx.unwrap_or(0)
23090 } else {23108 } else {
@@ -23122,15 +23140,7 @@ fn read_inter_plane(
23122 // [`read_plane`]'s own `tx_side != side` branch. Every other transform23140 // [`read_plane`]'s own `tx_side != side` branch. Every other transform
23123 // this decoder codes has `tx_side == side`, so this is inert below 64.23141 // this decoder codes has `tx_side == side`, so this is inert below 64.
23124 let tx_side = side.min(32);23142 let tx_side = side.min(32);
23125- let grid = if tx_side == side {23143+ let grid = extend_corner(grid, tx_side, tx_side, side, side);
23126- grid
23127- } else {
23128- let mut full = vec![0i32; side * side];
23129- for row in 0..tx_side {
23130- full[row * side..][..tx_side].copy_from_slice(&grid[row * tx_side..][..tx_side]);
23131- }
23132- full
23133- };
23134 let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx);23144 let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx);
23135 let tx = TxParams {23145 let tx = TxParams {
23136 w: side, h: side, bit_depth: bit_depth(fctx), q_idx: block_q_idx(fctx), dc_delta,23146 w: side, h: side, bit_depth: bit_depth(fctx), q_idx: block_q_idx(fctx), dc_delta,
@@ -26018,7 +26028,7 @@ fn decode_inter_block(
26018 None,26028 None,
26019 None, fctx,26029 None, fctx,
26020 )?;26030 )?;
26021- luma_grid = Grid::Own(coded.0);26031+ luma_grid = coded.0;
26022 luma_tx_type = coded.1;26032 luma_tx_type = coded.1;
26023 }26033 }
26024 }26034 }
@@ -26087,7 +26097,7 @@ fn decode_inter_block(
26087 chroma_side,26097 chroma_side,
26088 ));26098 ));
26089 } else {26099 } else {
26090- u_grid = Grid::Own(read_inter_plane(26100+ u_grid = read_inter_plane(
26091 dec,26101 dec,
26092 cdfs,26102 cdfs,
26093 chroma_set,26103 chroma_set,
@@ -26104,8 +26114,8 @@ fn decode_inter_block(
26104 Some(luma_tx_type),26114 Some(luma_tx_type),
26105 None, fctx,26115 None, fctx,
26106 )?26116 )?
26107- .0);26117+ .0;
26108- v_grid = Grid::Own(read_inter_plane(26118+ v_grid = read_inter_plane(
26109 dec,26119 dec,
26110 cdfs,26120 cdfs,
26111 chroma_set,26121 chroma_set,
@@ -26122,7 +26132,7 @@ fn decode_inter_block(
26122 Some(luma_tx_type),26132 Some(luma_tx_type),
26123 None, fctx,26133 None, fctx,
26124 )?26134 )?
26125- .0);26135+ .0;
26126 }26136 }
26127 }26137 }
26128 } else {26138 } else {
@@ -27277,7 +27287,7 @@ fn decode_inter_block(
27277 None,27287 None,
27278 None, fctx,27288 None, fctx,
27279 )?;27289 )?;
27280- luma_grid = Grid::Own(coded.0);27290+ luma_grid = coded.0;
27281 luma_tx_type = coded.1;27291 luma_tx_type = coded.1;
27282 }27292 }
27283 }27293 }
@@ -27355,7 +27365,7 @@ fn decode_inter_block(
27355 chroma_side,27365 chroma_side,
27356 ));27366 ));
27357 } else {27367 } else {
27358- u_grid = Grid::Own(read_inter_plane(27368+ u_grid = read_inter_plane(
27359 dec,27369 dec,
27360 cdfs,27370 cdfs,
27361 chroma_set,27371 chroma_set,
@@ -27372,8 +27382,8 @@ fn decode_inter_block(
27372 Some(luma_tx_type),27382 Some(luma_tx_type),
27373 None, fctx,27383 None, fctx,
27374 )?27384 )?
27375- .0);27385+ .0;
27376- v_grid = Grid::Own(read_inter_plane(27386+ v_grid = read_inter_plane(
27377 dec,27387 dec,
27378 cdfs,27388 cdfs,
27379 chroma_set,27389 chroma_set,
@@ -27390,7 +27400,7 @@ fn decode_inter_block(
27390 Some(luma_tx_type),27400 Some(luma_tx_type),
27391 None, fctx,27401 None, fctx,
27392 )?27402 )?
27393- .0);27403+ .0;
27394 }27404 }
27395 }27405 }
27396 }27406 }
@@ -27816,7 +27826,7 @@ fn decode_inter_block(
27816 // so `txb_skip_ctx` is the neighbour-magnitude table, not27826 // so `txb_skip_ctx` is the neighbour-magnitude table, not
27817 // the lone-TU 0 (`get_txb_ctx_general`).27827 // the lone-TU 0 (`get_txb_ctx_general`).
27818 let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI);27828 let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI);
27819- Grid::Own(read_plane(27829+ read_plane(
27820 dec,27830 dec,
27821 cdfs,27831 cdfs,
27822 txbset_for(tx_px, reduced),27832 txbset_for(tx_px, reduced),
@@ -27841,7 +27851,7 @@ fn decode_inter_block(
27841 filter_intra,27851 filter_intra,
27842 Some(tu_skip_ctx),27852 Some(tu_skip_ctx),
27843 smooth_neighbor, fctx,27853 smooth_neighbor, fctx,
27844- )?)27854+ )?
27845 };27855 };
27846 neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid);27856 neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid);
27847 if side > 64 {27857 if side > 64 {
@@ -27882,7 +27892,7 @@ fn decode_inter_block(
27882 );27892 );
27883 Grid::Zero(cu_tx * cu_tx)27893 Grid::Zero(cu_tx * cu_tx)
27884 } else {27894 } else {
27885- Grid::Own(read_plane(27895+ read_plane(
27886 dec,27896 dec,
27887 cdfs,27897 cdfs,
27888 chroma_set,27898 chroma_set,
@@ -27909,7 +27919,7 @@ fn decode_inter_block(
27909 // (lane-sb128b r3).27919 // (lane-sb128b r3).
27910 Some(3),27920 Some(3),
27911 smooth_neighbor_uv, fctx,27921 smooth_neighbor_uv, fctx,
27912- )?)27922+ )?
27913 };27923 };
27914 // Immediately, so the NEXT chunk's unit reads this27924 // Immediately, so the NEXT chunk's unit reads this
27915 // one's coefficient context.27925 // one's coefficient context.
@@ -28007,7 +28017,7 @@ fn decode_inter_block(
28007 if let Some(buf) = &palette_y_buf {28017 if let Some(buf) = &palette_y_buf {
28008 set_palette_pred(buf.clone(), fctx);28018 set_palette_pred(buf.clone(), fctx);
28009 }28019 }
28010- luma_grid = Grid::Own(read_plane(28020+ luma_grid = read_plane(
28011 dec,28021 dec,
28012 cdfs,28022 cdfs,
28013 luma_set_intra,28023 luma_set_intra,
@@ -28028,13 +28038,13 @@ fn decode_inter_block(
28028 filter_intra,28038 filter_intra,
28029 None,28039 None,
28030 smooth_neighbor, fctx,28040 smooth_neighbor, fctx,
28031- )?);28041+ )?;
28032 }28042 }
28033 let ac = alpha.map(|_| cfl_src(px, py, side));28043 let ac = alpha.map(|_| cfl_src(px, py, side));
28034 if let Some((ub, _)) = &palette_uv_bufs {28044 if let Some((ub, _)) = &palette_uv_bufs {
28035 set_palette_pred(ub.clone(), fctx);28045 set_palette_pred(ub.clone(), fctx);
28036 }28046 }
28037- u_grid = Grid::Own(read_plane(28047+ u_grid = read_plane(
28038 dec,28048 dec,
28039 cdfs,28049 cdfs,
28040 chroma_set,28050 chroma_set,
@@ -28055,11 +28065,11 @@ fn decode_inter_block(
28055 None,28065 None,
28056 None,28066 None,
28057 smooth_neighbor_uv, fctx,28067 smooth_neighbor_uv, fctx,
28058- )?);28068+ )?;
28059 if let Some((_, vb)) = &palette_uv_bufs {28069 if let Some((_, vb)) = &palette_uv_bufs {
28060 set_palette_pred(vb.clone(), fctx);28070 set_palette_pred(vb.clone(), fctx);
28061 }28071 }
28062- v_grid = Grid::Own(read_plane(28072+ v_grid = read_plane(
28063 dec,28073 dec,
28064 cdfs,28074 cdfs,
28065 chroma_set,28075 chroma_set,
@@ -28080,7 +28090,7 @@ fn decode_inter_block(
28080 None,28090 None,
28081 None,28091 None,
28082 smooth_neighbor_uv, fctx,28092 smooth_neighbor_uv, fctx,
28083- )?);28093+ )?;
28084 }28094 }
28085 }28095 }
28086 // lane-comppin r9: end-of-block checkpoint -- everything between28096 // lane-comppin r9: end-of-block checkpoint -- everything between
@@ -28112,7 +28122,7 @@ fn decode_inter_block(
28112 // the partial right superblock read row 1 where libaom reads row 2). The28122 // the partial right superblock read row 1 where libaom reads row 2). The
28113 // units are collected here and re-stamped after that record, in mu-chunk28123 // units are collected here and re-stamped after that record, in mu-chunk
28114 // order so a later unit still wins over an earlier one.28124 // order so a later unit still wins over an earlier one.
28115- let mu_chroma_units: Vec<((usize, usize), usize, Vec<i32>)> = if mu_chroma {28125+ let mu_chroma_units: Vec<((usize, usize), usize, Grid)> = if mu_chroma {
28116 let cu = 32usize;28126 let cu = 32usize;
28117 let mut units = Vec::new();28127 let mut units = Vec::new();
28118 for cr in 0..(write_h / 64).max(1) {28128 for cr in 0..(write_h / 64).max(1) {
@@ -28124,7 +28134,7 @@ fn decode_inter_block(
28124 let start = (cr * cu + rr) * chroma_side + cc * cu;28134 let start = (cr * cu + rr) * chroma_side + cc * cu;
28125 unit.extend_from_slice(&grid[start..start + cu]);28135 unit.extend_from_slice(&grid[start..start + cu]);
28126 }28136 }
28127- units.push((cu_mi, plane, unit));28137+ units.push((cu_mi, plane, Grid::Own(unit)));
28128 }28138 }
28129 }28139 }
28130 }28140 }
@@ -28801,7 +28811,7 @@ fn decode_inter_sub8_split4(
28801 let (u_grid, v_grid) = if last_skip {28811 let (u_grid, v_grid) = if last_skip {
28802 push_mc(1, cpx, cpy, B4, Pred::dense(&pred_u), &ZERO_RESIDUAL[..B4 * B4], fctx);28812 push_mc(1, cpx, cpy, B4, Pred::dense(&pred_u), &ZERO_RESIDUAL[..B4 * B4], fctx);
28803 push_mc(2, cpx, cpy, B4, Pred::dense(&pred_v), &ZERO_RESIDUAL[..B4 * B4], fctx);28813 push_mc(2, cpx, cpy, B4, Pred::dense(&pred_v), &ZERO_RESIDUAL[..B4 * B4], fctx);
28804- (vec![0i32; B4 * B4], vec![0i32; B4 * B4])28814+ (Grid::Zero(B4 * B4), Grid::Zero(B4 * B4))
28805 } else {28815 } else {
28806 let around = neighbours.around_mi(group_mi, 8);28816 let around = neighbours.around_mi(group_mi, 8);
28807 let ug = read_inter_plane(28817 let ug = read_inter_plane(
@@ -29108,7 +29118,7 @@ fn decode_intra_sub8_leaf(
29108 }29118 }
29109 } else {29119 } else {
29110 let grid_levels = if skip {29120 let grid_levels = if skip {
29111- let zeros = vec![0i32; bw * bh];29121+ let zeros = Grid::Zero(bw * bh);
29112 push_intra_rect(0, 29122 push_intra_rect(0,
29113 px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra,29123 px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra,
29114 smooth_neighbor, fctx,29124 smooth_neighbor, fctx,
@@ -29238,14 +29248,14 @@ fn decode_intra_sub8_leaf(
29238 record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]);29248 record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]);
29239 29249
29240 let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));29250 let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));
29241- let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if skip {29251+ let (u_grid, v_grid): (Grid, Grid) = if skip {
29242 if alpha.is_some() {29252 if alpha.is_some() {
29243 CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));29253 CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));
29244 SKIP_CFL_HITS.with(|c| c.set(c.get() + 1));29254 SKIP_CFL_HITS.with(|c| c.set(c.get() + 1));
29245 }29255 }
29246 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);29256 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);
29247 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);29257 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);
29248- (vec![0i32; 16], vec![0i32; 16])29258+ (Grid::Zero(16), Grid::Zero(16))
29249 } else {29259 } else {
29250 let chroma_around = neighbours.around_mi(group_mi, 8);29260 let chroma_around = neighbours.around_mi(group_mi, 8);
29251 let ug = read_plane(29261 let ug = read_plane(
@@ -29820,7 +29830,7 @@ fn decode_inter_sub8_rect2(
29820 let (u_grid, v_grid) = if last_skip {29830 let (u_grid, v_grid) = if last_skip {
29821 push_mc(1, cpx, cpy, B4, Pred::dense(&pred_u), &ZERO_RESIDUAL[..B4 * B4], fctx);29831 push_mc(1, cpx, cpy, B4, Pred::dense(&pred_u), &ZERO_RESIDUAL[..B4 * B4], fctx);
29822 push_mc(2, cpx, cpy, B4, Pred::dense(&pred_v), &ZERO_RESIDUAL[..B4 * B4], fctx);29832 push_mc(2, cpx, cpy, B4, Pred::dense(&pred_v), &ZERO_RESIDUAL[..B4 * B4], fctx);
29823- (vec![0i32; B4 * B4], vec![0i32; B4 * B4])29833+ (Grid::Zero(B4 * B4), Grid::Zero(B4 * B4))
29824 } else {29834 } else {
29825 let around = neighbours.around_mi(group_mi, 8);29835 let around = neighbours.around_mi(group_mi, 8);
29826 let ug = read_inter_plane(29836 let ug = read_inter_plane(
@@ -30663,9 +30673,9 @@ fn decode_inter_block8(
30663 Pred::dense(&pred_v),30673 Pred::dense(&pred_v),
30664 &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,30674 &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,
30665 );30675 );
30666- luma_grid = vec![0i32; SIDE * SIDE];30676+ luma_grid = Grid::Zero(SIDE * SIDE);
30667- u_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];30677+ u_grid = Grid::Zero(CHROMA_SIDE * CHROMA_SIDE);
30668- v_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];30678+ v_grid = Grid::Zero(CHROMA_SIDE * CHROMA_SIDE);
30669 } else {30679 } else {
30670 let around = neighbours.around_mi(leaf_mi, 8);30680 let around = neighbours.around_mi(leaf_mi, 8);
30671 let (grid8, luma_tx_type) = read_inter_luma8(30681 let (grid8, luma_tx_type) = read_inter_luma8(
@@ -31308,9 +31318,9 @@ fn decode_inter_block8(
31308 Pred::dense(&pred_v),31318 Pred::dense(&pred_v),
31309 &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,31319 &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,
31310 );31320 );
31311- luma_grid = vec![0i32; SIDE * SIDE];31321+ luma_grid = Grid::Zero(SIDE * SIDE);
31312- u_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];31322+ u_grid = Grid::Zero(CHROMA_SIDE * CHROMA_SIDE);
31313- v_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];31323+ v_grid = Grid::Zero(CHROMA_SIDE * CHROMA_SIDE);
31314 } else {31324 } else {
31315 let around = neighbours.around_mi(leaf_mi, 8);31325 let around = neighbours.around_mi(leaf_mi, 8);
31316 let (grid8, luma_tx_type) = read_inter_luma8(31326 let (grid8, luma_tx_type) = read_inter_luma8(
@@ -31674,7 +31684,7 @@ fn decode_inter_block8(
31674 filter_intra,31684 filter_intra,
31675 smooth_neighbor, fctx,31685 smooth_neighbor, fctx,
31676 );31686 );
31677- vec![0i32; tx_px * tx_px]31687+ Grid::Zero(tx_px * tx_px)
31678 } else {31688 } else {
31679 // The unit is smaller than the block it sits in, so31689 // The unit is smaller than the block it sits in, so
31680 // `txb_skip_ctx` is the neighbour-magnitude table, not31690 // `txb_skip_ctx` is the neighbour-magnitude table, not
@@ -31761,16 +31771,16 @@ fn decode_inter_block8(
31761 None,31771 None,
31762 smooth_neighbor_uv, fctx,31772 smooth_neighbor_uv, fctx,
31763 );31773 );
31764- luma_grid = vec![0i32; SIDE * SIDE];31774+ luma_grid = Grid::Zero(SIDE * SIDE);
31765- u_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];31775+ u_grid = Grid::Zero(CHROMA_SIDE * CHROMA_SIDE);
31766- v_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];31776+ v_grid = Grid::Zero(CHROMA_SIDE * CHROMA_SIDE);
31767 } else {31777 } else {
31768 let around = neighbours.around_mi(leaf_mi, 8);31778 let around = neighbours.around_mi(leaf_mi, 8);
31769 luma_grid = if split8 {31779 luma_grid = if split8 {
31770 // Already coded and reconstructed unit by unit above; the31780 // Already coded and reconstructed unit by unit above; the
31771 // block-level grid only feeds the neighbour write-back,31781 // block-level grid only feeds the neighbour write-back,
31772 // which the `saved_luma_ctx` restore below keeps per-TU.31782 // which the `saved_luma_ctx` restore below keeps per-TU.
31773- vec![0i32; SIDE * SIDE]31783+ Grid::Zero(SIDE * SIDE)
31774 } else {31784 } else {
31775 if let Some(buf) = &palette_y_buf {31785 if let Some(buf) = &palette_y_buf {
31776 set_palette_pred(buf.clone(), fctx);31786 set_palette_pred(buf.clone(), fctx);
crates/ec-av1/src/transform.rsmodified+1 -1
@@ -1340,7 +1340,7 @@ pub fn dequant_and_inverse_typed_wh(
1340 // `decode.rs`), which also drops the `vec![0; w * h]` memset here and the1340 // `decode.rs`), which also drops the `vec![0; w * h]` memset here and the
1341 // `to_vec` clone the recorded [`crate::decode::Residual`] made of it --1341 // `to_vec` clone the recorded [`crate::decode::Residual`] made of it --
1342 // together 6.5% of the 4K segment's profile (memset + memmove).1342 // together 6.5% of the 4K segment's profile (memset + memmove).
1343- if levels.iter().all(|&l| l == 0) {1343+ if crate::decode::is_zero_grid(levels) {
1344 return Vec::new();1344 return Vec::new();
1345 }1345 }
1346 DQ_SCRATCH.with(|cell| {1346 DQ_SCRATCH.with(|cell| {