forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-perf10' (6316b059): reference planes borrowed instead of copied nine times per inter frame (PlaneBuf data as Cow), DC-only column broadcast in the inverse transform, DCT network on fixed arrays; conflict with the banded deblock resolved by forcing the output plane owned once before banding; byte-exact at 1 and 4 filter threads on four inputs

Browse files at this commit

1a457937adee8576d163de96bc44cb68735b3034Ahmet Kaan GümüşParent: 1325edfe428d82
crates/ec-av1/src/decode.rsmodified+172 -169
@@ -7422,7 +7422,7 @@ fn tx_size_context_rect(
7422 }7422 }
7423 7423
7424 /// [`cfl_ac_q3`] for a true `bw`x`bh` rect strip (lane-intradisp r1).7424 /// [`cfl_ac_q3`] for a true `bw`x`bh` rect strip (lane-intradisp r1).
7425-fn cfl_ac_q3_rect(y: &PlaneBuf, px: usize, py: usize, bw: usize, bh: usize) -> Vec<i32> {7425+fn cfl_ac_q3_rect(y: &PlaneBuf<'_>, px: usize, py: usize, bw: usize, bh: usize) -> Vec<i32> {
7426 let (cw, ch) = (bw / 2, bh / 2);7426 let (cw, ch) = (bw / 2, bh / 2);
7427 let mut ac = vec![0i32; cw * ch];7427 let mut ac = vec![0i32; cw * ch];
7428 let mut sum = 0i32;7428 let mut sum = 0i32;
@@ -7526,9 +7526,9 @@ fn decode_rect_split(
7526 tx_w: usize,7526 tx_w: usize,
7527 tx_h: usize,7527 tx_h: usize,
7528 m: &RectStripModes,7528 m: &RectStripModes,
7529- y: &mut PlaneBuf,7529+ y: &mut PlaneBuf<'static>,
7530- u: &mut PlaneBuf,7530+ u: &mut PlaneBuf<'static>,
7531- v: &mut PlaneBuf,7531+ v: &mut PlaneBuf<'static>,
7532 base_q_idx: u8,7532 base_q_idx: u8,
7533 reduced_tx_set: bool, fctx: &crate::decode::FrameCtx,7533 reduced_tx_set: bool, fctx: &crate::decode::FrameCtx,
7534 ) -> Result<()> {7534 ) -> Result<()> {
@@ -8155,9 +8155,9 @@ fn decode_intra_rect_in_inter(
8155 // `(PARTITION_HORZ_4, is_chroma_reference)` when this strip is one of the8155 // `(PARTITION_HORZ_4, is_chroma_reference)` when this strip is one of the
8156 // four 16x4 / 4x16 strips of a 16x16-level 1:4 partition (lane-intra16x4).8156 // four 16x4 / 4x16 strips of a 16x16-level 1:4 partition (lane-intra16x4).
8157 strip16: Option<(bool, bool)>,8157 strip16: Option<(bool, bool)>,
8158- y: &mut PlaneBuf,8158+ y: &mut PlaneBuf<'static>,
8159- u: &mut PlaneBuf,8159+ u: &mut PlaneBuf<'static>,
8160- v: &mut PlaneBuf,8160+ v: &mut PlaneBuf<'static>,
8161 base_q_idx: u8, fctx: &crate::decode::FrameCtx,8161 base_q_idx: u8, fctx: &crate::decode::FrameCtx,
8162 ) -> Result<()> {8162 ) -> Result<()> {
8163 // `at` is in MI units (the inter path's own unit since lane-inter4);8163 // `at` is in MI units (the inter path's own unit since lane-inter4);
@@ -8708,9 +8708,9 @@ fn decode_block_rect(
8708 at: (usize, usize),8708 at: (usize, usize),
8709 bw: usize,8709 bw: usize,
8710 bh: usize,8710 bh: usize,
8711- y: &mut PlaneBuf,8711+ y: &mut PlaneBuf<'static>,
8712- u: &mut PlaneBuf,8712+ u: &mut PlaneBuf<'static>,
8713- v: &mut PlaneBuf,8713+ v: &mut PlaneBuf<'static>,
8714 enable_filter_intra: bool,8714 enable_filter_intra: bool,
8715 allow_screen_content_tools: bool,8715 allow_screen_content_tools: bool,
8716 base_q_idx: u8,8716 base_q_idx: u8,
@@ -9164,9 +9164,9 @@ fn decode_leaf_rect(
9164 bw: usize,9164 bw: usize,
9165 bh: usize,9165 bh: usize,
9166 prev_leaf: Option<((usize, usize), usize)>,9166 prev_leaf: Option<((usize, usize), usize)>,
9167- y: &mut PlaneBuf,9167+ y: &mut PlaneBuf<'static>,
9168- u: &mut PlaneBuf,9168+ u: &mut PlaneBuf<'static>,
9169- v: &mut PlaneBuf,9169+ v: &mut PlaneBuf<'static>,
9170 enable_filter_intra: bool,9170 enable_filter_intra: bool,
9171 allow_screen_content_tools: bool,9171 allow_screen_content_tools: bool,
9172 base_q_idx: u8,9172 base_q_idx: u8,
@@ -9504,9 +9504,9 @@ fn decode_block_rect4(
9504 bw: usize,9504 bw: usize,
9505 bh: usize,9505 bh: usize,
9506 prev_strip: Option<((usize, usize), usize)>,9506 prev_strip: Option<((usize, usize), usize)>,
9507- y: &mut PlaneBuf,9507+ y: &mut PlaneBuf<'static>,
9508- u: &mut PlaneBuf,9508+ u: &mut PlaneBuf<'static>,
9509- v: &mut PlaneBuf,9509+ v: &mut PlaneBuf<'static>,
9510 enable_filter_intra: bool,9510 enable_filter_intra: bool,
9511 allow_screen_content_tools: bool,9511 allow_screen_content_tools: bool,
9512 base_q_idx: u8,9512 base_q_idx: u8,
@@ -9973,9 +9973,9 @@ fn decode_rect4_16(
9973 neighbours: &mut Neighbours,9973 neighbours: &mut Neighbours,
9974 at16: (usize, usize),9974 at16: (usize, usize),
9975 horz: bool,9975 horz: bool,
9976- y: &mut PlaneBuf,9976+ y: &mut PlaneBuf<'static>,
9977- u: &mut PlaneBuf,9977+ u: &mut PlaneBuf<'static>,
9978- v: &mut PlaneBuf,9978+ v: &mut PlaneBuf<'static>,
9979 enable_filter_intra: bool,9979 enable_filter_intra: bool,
9980 allow_screen_content_tools: bool,9980 allow_screen_content_tools: bool,
9981 base_q_idx: u8,9981 base_q_idx: u8,
@@ -10049,9 +10049,9 @@ fn decode_rect4_16_strip(
10049 horz: bool,10049 horz: bool,
10050 has_chroma: bool,10050 has_chroma: bool,
10051 prev: Option<((usize, usize), usize)>,10051 prev: Option<((usize, usize), usize)>,
10052- y: &mut PlaneBuf,10052+ y: &mut PlaneBuf<'static>,
10053- u: &mut PlaneBuf,10053+ u: &mut PlaneBuf<'static>,
10054- v: &mut PlaneBuf,10054+ v: &mut PlaneBuf<'static>,
10055 enable_filter_intra: bool,10055 enable_filter_intra: bool,
10056 allow_screen_content_tools: bool,10056 allow_screen_content_tools: bool,
10057 base_q_idx: u8,10057 base_q_idx: u8,
@@ -10551,9 +10551,9 @@ fn decode_block_rect64(
10551 at: (usize, usize),10551 at: (usize, usize),
10552 bw: usize,10552 bw: usize,
10553 bh: usize,10553 bh: usize,
10554- y: &mut PlaneBuf,10554+ y: &mut PlaneBuf<'static>,
10555- u: &mut PlaneBuf,10555+ u: &mut PlaneBuf<'static>,
10556- v: &mut PlaneBuf,10556+ v: &mut PlaneBuf<'static>,
10557 enable_filter_intra: bool,10557 enable_filter_intra: bool,
10558 allow_screen_content_tools: bool,10558 allow_screen_content_tools: bool,
10559 base_q_idx: u8,10559 base_q_idx: u8,
@@ -11471,7 +11471,7 @@ fn read_cfl_alphas(dec: &mut SymbolDecoder, cdfs: &mut Cdfs) -> (i32, i32) {
11471 /// 4:2:0 to Q3 (`(a+b+c+d) << 1`, each 2x2 group), then block-average11471 /// 4:2:0 to Q3 (`(a+b+c+d) << 1`, each 2x2 group), then block-average
11472 /// subtracted (`round_offset = num_pel/2`, right-shifted by `log2(num_pel)`)11472 /// subtracted (`round_offset = num_pel/2`, right-shifted by `log2(num_pel)`)
11473 /// to give the AC values [`cfl_scaled`] scales by alpha.11473 /// to give the AC values [`cfl_scaled`] scales by alpha.
11474-fn cfl_ac_q3(y: &PlaneBuf, px: usize, py: usize, side: usize) -> Vec<i32> {11474+fn cfl_ac_q3(y: &PlaneBuf<'_>, px: usize, py: usize, side: usize) -> Vec<i32> {
11475 let cside = side / 2;11475 let cside = side / 2;
11476 let mut ac = vec![0i32; cside * cside];11476 let mut ac = vec![0i32; cside * cside];
11477 let mut sum = 0i32;11477 let mut sum = 0i32;
@@ -11525,7 +11525,7 @@ fn stage_dump_idx() -> usize {
11525 PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst).saturating_sub(1)11525 PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst).saturating_sub(1)
11526 }11526 }
11527 11527
11528-fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize, fh: usize) {11528+fn dump_stage16(var: &str, y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>, fw: usize, fh: usize) {
11529 use std::io::Write;11529 use std::io::Write;
11530 // lane-sbrect10 r2 / lane-cdef r1 (one shared helper): index the dump by11530 // lane-sbrect10 r2 / lane-cdef r1 (one shared helper): index the dump by
11531 // decode-order picture like EC_AV1_PREFILT_DUMP already does -- a fixed11531 // decode-order picture like EC_AV1_PREFILT_DUMP already does -- a fixed
@@ -11561,7 +11561,7 @@ fn dump_stage_idx(var: &str) -> usize {
11561 i11561 i
11562 }11562 }
11563 11563
11564-fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) {11564+fn dump_stage(var: &str, y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>) {
11565 use std::io::Write;11565 use std::io::Write;
11566 if let Ok(path) = crate::envflags::var(var)11566 if let Ok(path) = crate::envflags::var(var)
11567 && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var)))11567 && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var)))
@@ -11574,8 +11574,8 @@ fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) {
11574 }11574 }
11575 11575
11576 #[derive(Clone)]11576 #[derive(Clone)]
11577-struct PlaneBuf {11577+struct PlaneBuf<'a> {
11578- data: Vec<u16>,11578+ data: std::borrow::Cow<'a, [u16]>,
11579 width: usize,11579 width: usize,
11580 height: usize,11580 height: usize,
11581 /// The frame's true, decodable extent in this plane's own units — past11581 /// The frame's true, decodable extent in this plane's own units — past
@@ -11608,9 +11608,9 @@ struct PlaneBuf {
11608 /// (lane-av1refs: the same "empty slot" case `GOLDEN_FRAME` already11608 /// (lane-av1refs: the same "empty slot" case `GOLDEN_FRAME` already
11609 /// refused by name, now generic across `LAST2`/`LAST3`/`GOLDEN`/`BWDREF`/11609 /// refused by name, now generic across `LAST2`/`LAST3`/`GOLDEN`/`BWDREF`/
11610 /// `ALTREF2`/`ALTREF`).11610 /// `ALTREF2`/`ALTREF`).
11611-type RefSlots<'a> = [Option<(&'a PlaneBuf, &'a PlaneBuf, &'a PlaneBuf)>; 8];11611+type RefSlots<'a> = [Option<(&'a PlaneBuf<'a>, &'a PlaneBuf<'a>, &'a PlaneBuf<'a>)>; 8];
11612 11612
11613-impl PlaneBuf {11613+impl PlaneBuf<'_> {
11614 /// Sets this plane's own tile pixel origin ([`Self::tile_x0`]/11614 /// Sets this plane's own tile pixel origin ([`Self::tile_x0`]/
11615 /// [`Self::tile_y0`]) before that tile's own superblock walk. `x0`/`y0`11615 /// [`Self::tile_y0`]) before that tile's own superblock walk. `x0`/`y0`
11616 /// are already in this plane's own units (luma pixels for `y`, chroma11616 /// are already in this plane's own units (luma pixels for `y`, chroma
@@ -11792,7 +11792,7 @@ impl PlaneBuf {
11792 base = (base + cfl_scaled(alpha_q3, ac_q3[idx])).clamp(0, sample_max(fctx));11792 base = (base + cfl_scaled(alpha_q3, ac_q3[idx])).clamp(0, sample_max(fctx));
11793 }11793 }
11794 let sample = (base + residual[idx]).clamp(0, sample_max(fctx)) as u16;11794 let sample = (base + residual[idx]).clamp(0, sample_max(fctx)) as u16;
11795- self.data[(y + row) * self.width + x + col] = sample;11795+ self.data.to_mut()[(y + row) * self.width + x + col] = sample;
11796 }11796 }
11797 }11797 }
11798 }11798 }
@@ -11899,7 +11899,7 @@ impl PlaneBuf {
11899 base = (base + cfl_scaled(alpha_q3, ac_q3[idx])).clamp(0, sample_max(fctx));11899 base = (base + cfl_scaled(alpha_q3, ac_q3[idx])).clamp(0, sample_max(fctx));
11900 }11900 }
11901 let sample = (base + residual[idx]).clamp(0, sample_max(fctx)) as u16;11901 let sample = (base + residual[idx]).clamp(0, sample_max(fctx)) as u16;
11902- self.data[(y + row) * self.width + x + col] = sample;11902+ self.data.to_mut()[(y + row) * self.width + x + col] = sample;
11903 }11903 }
11904 }11904 }
11905 }11905 }
@@ -11922,7 +11922,7 @@ fn read_plane(
11922 predict_mode: usize,11922 predict_mode: usize,
11923 angle_delta: i32,11923 angle_delta: i32,
11924 reach: Reach,11924 reach: Reach,
11925- plane: &mut PlaneBuf,11925+ plane: &mut PlaneBuf<'static>,
11926 x: usize,11926 x: usize,
11927 y: usize,11927 y: usize,
11928 side: usize,11928 side: usize,
@@ -12062,9 +12062,9 @@ fn decode_block(
12062 chroma_tx: usize,12062 chroma_tx: usize,
12063 scans: (&[u16], &[u16]),12063 scans: (&[u16], &[u16]),
12064 cfl: bool,12064 cfl: bool,
12065- y: &mut PlaneBuf,12065+ y: &mut PlaneBuf<'static>,
12066- u: &mut PlaneBuf,12066+ u: &mut PlaneBuf<'static>,
12067- v: &mut PlaneBuf,12067+ v: &mut PlaneBuf<'static>,
12068 base_q_idx: u8,12068 base_q_idx: u8,
12069 enable_filter_intra: bool,12069 enable_filter_intra: bool,
12070 allow_screen_content_tools: bool,12070 allow_screen_content_tools: bool,
@@ -12807,9 +12807,9 @@ fn decode_block_128rect(
12807 at: (usize, usize),12807 at: (usize, usize),
12808 bw: usize,12808 bw: usize,
12809 bh: usize,12809 bh: usize,
12810- y: &mut PlaneBuf,12810+ y: &mut PlaneBuf<'static>,
12811- u: &mut PlaneBuf,12811+ u: &mut PlaneBuf<'static>,
12812- v: &mut PlaneBuf,12812+ v: &mut PlaneBuf<'static>,
12813 base_q_idx: u8,12813 base_q_idx: u8,
12814 enable_filter_intra: bool,12814 enable_filter_intra: bool,
12815 allow_screen_content_tools: bool,12815 allow_screen_content_tools: bool,
@@ -13128,9 +13128,9 @@ fn decode_leaf8(
13128 leaf_mi: (usize, usize),13128 leaf_mi: (usize, usize),
13129 scans: (&[u16], &[u16]),13129 scans: (&[u16], &[u16]),
13130 prev_leaf: Option<((usize, usize), usize)>,13130 prev_leaf: Option<((usize, usize), usize)>,
13131- y: &mut PlaneBuf,13131+ y: &mut PlaneBuf<'static>,
13132- u: &mut PlaneBuf,13132+ u: &mut PlaneBuf<'static>,
13133- v: &mut PlaneBuf,13133+ v: &mut PlaneBuf<'static>,
13134 base_q_idx: u8,13134 base_q_idx: u8,
13135 enable_filter_intra: bool,13135 enable_filter_intra: bool,
13136 allow_screen_content_tools: bool,13136 allow_screen_content_tools: bool,
@@ -13844,9 +13844,9 @@ fn decode_leaf_split4(
13844 leaf_mi: (usize, usize),13844 leaf_mi: (usize, usize),
13845 scan4: &[u16],13845 scan4: &[u16],
13846 prev_leaf: Option<((usize, usize), usize)>,13846 prev_leaf: Option<((usize, usize), usize)>,
13847- y: &mut PlaneBuf,13847+ y: &mut PlaneBuf<'static>,
13848- u: &mut PlaneBuf,13848+ u: &mut PlaneBuf<'static>,
13849- v: &mut PlaneBuf,13849+ v: &mut PlaneBuf<'static>,
13850 base_q_idx: u8,13850 base_q_idx: u8,
13851 enable_filter_intra: bool,13851 enable_filter_intra: bool,
13852 allow_intrabc: bool,13852 allow_intrabc: bool,
@@ -14064,9 +14064,9 @@ fn decode_leaf_rect8(
14064 leaf_mi: (usize, usize),14064 leaf_mi: (usize, usize),
14065 vert: bool,14065 vert: bool,
14066 scan4: &[u16],14066 scan4: &[u16],
14067- y: &mut PlaneBuf,14067+ y: &mut PlaneBuf<'static>,
14068- u: &mut PlaneBuf,14068+ u: &mut PlaneBuf<'static>,
14069- v: &mut PlaneBuf,14069+ v: &mut PlaneBuf<'static>,
14070 base_q_idx: u8,14070 base_q_idx: u8,
14071 enable_filter_intra: bool,14071 enable_filter_intra: bool,
14072 allow_intrabc: bool,14072 allow_intrabc: bool,
@@ -14574,7 +14574,7 @@ fn cdef_adjust_strength(strength: i32, var: i32) -> i32 {
14574 #[allow(unsafe_code)]14574 #[allow(unsafe_code)]
14575 fn cdef_filter_block(14575 fn cdef_filter_block(
14576 src: &[i32],14576 src: &[i32],
14577- dst: &mut PlaneBuf,14577+ dst: &mut PlaneBuf<'static>,
14578 ox: usize,14578 ox: usize,
14579 oy: usize,14579 oy: usize,
14580 bw: usize,14580 bw: usize,
@@ -14598,7 +14598,7 @@ fn cdef_filter_block(
14598 unsafe {14598 unsafe {
14599 cdef_simd::filter_block_avx2(14599 cdef_simd::filter_block_avx2(
14600 src,14600 src,
14601- &mut dst.data,14601+ dst.data.to_mut(),
14602 stride,14602 stride,
14603 ox,14603 ox,
14604 oy,14604 oy,
@@ -14619,7 +14619,7 @@ fn cdef_filter_block(
14619 }14619 }
14620 cdef_filter_block_scalar(14620 cdef_filter_block_scalar(
14621 src,14621 src,
14622- &mut dst.data,14622+ dst.data.to_mut(),
14623 stride,14623 stride,
14624 ox,14624 ox,
14625 oy,14625 oy,
@@ -14949,9 +14949,9 @@ mod cdef_simd {
14949 /// Ported from libaom's `av1/common/av1_loopfilter.c` (edge/level decision)14949 /// Ported from libaom's `av1/common/av1_loopfilter.c` (edge/level decision)
14950 /// and `aom_dsp/loopfilter.c` (the `aom_lpf_*` pixel kernels).14950 /// and `aom_dsp/loopfilter.c` (the `aom_lpf_*` pixel kernels).
14951 fn apply_deblock(14951 fn apply_deblock(
14952- y: &mut PlaneBuf,14952+ y: &mut PlaneBuf<'static>,
14953- u: &mut PlaneBuf,14953+ u: &mut PlaneBuf<'static>,
14954- v: &mut PlaneBuf,14954+ v: &mut PlaneBuf<'static>,
14955 lf: &LoopFilterParams,14955 lf: &LoopFilterParams,
14956 n: &Neighbours,14956 n: &Neighbours,
14957 frame_width: usize,14957 frame_width: usize,
@@ -16138,7 +16138,7 @@ fn read_inter_plane_rect(
16138 plane_idx: usize,16138 plane_idx: usize,
16139 around: (bool, bool, i32),16139 around: (bool, bool, i32),
16140 tx_mode: usize,16140 tx_mode: usize,
16141- plane: &mut PlaneBuf,16141+ plane: &mut PlaneBuf<'static>,
16142 x: usize,16142 x: usize,
16143 y: usize,16143 y: usize,
16144 prediction: &[u16],16144 prediction: &[u16],
@@ -16258,7 +16258,7 @@ fn read_inter_luma8(
16258 cdfs: &mut Cdfs,16258 cdfs: &mut Cdfs,
16259 neighbours: &mut Neighbours,16259 neighbours: &mut Neighbours,
16260 leaf_mi: (usize, usize),16260 leaf_mi: (usize, usize),
16261- y: &mut PlaneBuf,16261+ y: &mut PlaneBuf<'static>,
16262 px: usize,16262 px: usize,
16263 py: usize,16263 py: usize,
16264 pred_y: &[u16],16264 pred_y: &[u16],
@@ -17304,7 +17304,7 @@ fn filter_edge16(
17304 /// One plane's worth of spec 7.14: every vertical edge across the plane,17304 /// One plane's worth of spec 7.14: every vertical edge across the plane,
17305 /// then every horizontal edge (the order the spec and libaom both use).17305 /// then every horizontal edge (the order the spec and libaom both use).
17306 fn deblock_plane(17306 fn deblock_plane(
17307- plane: &mut PlaneBuf,17307+ plane: &mut PlaneBuf<'static>,
17308 plane_idx: usize,17308 plane_idx: usize,
17309 lf: &LoopFilterParams,17309 lf: &LoopFilterParams,
17310 n: &Neighbours,17310 n: &Neighbours,
@@ -17364,6 +17364,10 @@ fn deblock_plane(
17364 // group, whether it goes through `filter_edge16` with three neighbours or17364 // group, whether it goes through `filter_edge16` with three neighbours or
17365 // through `filter_edge` alone. Band boundaries are multiples of 16 so no17365 // through `filter_edge` alone. Band boundaries are multiples of 16 so no
17366 // group ever straddles one.17366 // group ever straddles one.
17367+ // lane-perf10 merge: the output plane is owned (perf10 made mutable
17368+ // plane params PlaneBuf<'static>); force the Cow to Owned ONCE here so
17369+ // the bands below never clone it concurrently.
17370+ plane.data.to_mut();
17367 let threads = crate::par::filter_threads();17371 let threads = crate::par::filter_threads();
17368 let sp = crate::par::Shared::new(plane);17372 let sp = crate::par::Shared::new(plane);
17369 let vbands: Vec<(usize, usize)> = crate::par::bands(th.div_ceil(16), threads)17373 let vbands: Vec<(usize, usize)> = crate::par::bands(th.div_ceil(16), threads)
@@ -17385,7 +17389,7 @@ fn deblock_plane(
17385 if let Some((len, level)) = ps[0] {17389 if let Some((len, level)) = ps[0] {
17386 if ps.iter().all(|p| *p == ps[0])17390 if ps.iter().all(|p| *p == ps[0])
17387 && filter_edge16(17391 && filter_edge16(
17388- &mut plane.data,17392+ plane.data.to_mut(),
17389 y0 * stride + x0,17393 y0 * stride + x0,
17390 stride,17394 stride,
17391 true,17395 true,
@@ -17401,7 +17405,7 @@ fn deblock_plane(
17401 for (k, p) in ps.iter().enumerate() {17405 for (k, p) in ps.iter().enumerate() {
17402 if let Some((len, level)) = *p {17406 if let Some((len, level)) = *p {
17403 filter_edge(17407 filter_edge(
17404- &mut plane.data,17408+ plane.data.to_mut(),
17405 (y0 + 4 * k) * stride + x0,17409 (y0 + 4 * k) * stride + x0,
17406 stride as isize,17410 stride as isize,
17407 1,17411 1,
@@ -17419,7 +17423,7 @@ fn deblock_plane(
17419 eprintln!("VEDGE x0={x0} y0={y0} len={len} level={level}");17423 eprintln!("VEDGE x0={x0} y0={y0} len={len} level={level}");
17420 }17424 }
17421 filter_edge(17425 filter_edge(
17422- &mut plane.data,17426+ plane.data.to_mut(),
17423 y0 * stride + x0,17427 y0 * stride + x0,
17424 stride as isize,17428 stride as isize,
17425 1,17429 1,
@@ -17453,7 +17457,7 @@ fn deblock_plane(
17453 if let Some((len, level)) = ps[0] {17457 if let Some((len, level)) = ps[0] {
17454 if ps.iter().all(|p| *p == ps[0])17458 if ps.iter().all(|p| *p == ps[0])
17455 && filter_edge16(17459 && filter_edge16(
17456- &mut plane.data,17460+ plane.data.to_mut(),
17457 y0 * stride + x0,17461 y0 * stride + x0,
17458 stride,17462 stride,
17459 false,17463 false,
@@ -17469,7 +17473,7 @@ fn deblock_plane(
17469 for (k, p) in ps.iter().enumerate() {17473 for (k, p) in ps.iter().enumerate() {
17470 if let Some((len, level)) = *p {17474 if let Some((len, level)) = *p {
17471 filter_edge(17475 filter_edge(
17472- &mut plane.data,17476+ plane.data.to_mut(),
17473 y0 * stride + x0 + 4 * k,17477 y0 * stride + x0 + 4 * k,
17474 1,17478 1,
17475 stride as isize,17479 stride as isize,
@@ -17493,7 +17497,7 @@ fn deblock_plane(
17493 );17497 );
17494 }17498 }
17495 filter_edge(17499 filter_edge(
17496- &mut plane.data,17500+ plane.data.to_mut(),
17497 y0 * stride + x0,17501 y0 * stride + x0,
17498 1,17502 1,
17499 stride as isize,17503 stride as isize,
@@ -17536,8 +17540,8 @@ fn scratch_empty() -> Vec<u16> {
17536 17540
17537 /// A plane's post-deblock snapshot, its samples taken from the pool (every17541 /// A plane's post-deblock snapshot, its samples taken from the pool (every
17538 /// other field is `usize`).17542 /// other field is `usize`).
17539-fn plane_snapshot(p: &PlaneBuf) -> PlaneBuf {17543+fn plane_snapshot(p: &PlaneBuf<'_>) -> PlaneBuf<'static> {
17540- PlaneBuf { data: scratch_from(&p.data), ..*p }17544+ PlaneBuf { data: std::borrow::Cow::Owned(scratch_from(&p.data)), ..*p }
17541 }17545 }
17542 17546
17543 /// Hands a buffer back to the pool; the capacity is what is worth keeping.17547 /// Hands a buffer back to the pool; the capacity is what is worth keeping.
@@ -17546,9 +17550,9 @@ fn scratch_return(v: Vec<u16>) {
17546 }17550 }
17547 17551
17548 fn apply_cdef(17552 fn apply_cdef(
17549- y: &mut PlaneBuf,17553+ y: &mut PlaneBuf<'static>,
17550- u: &mut PlaneBuf,17554+ u: &mut PlaneBuf<'static>,
17551- v: &mut PlaneBuf,17555+ v: &mut PlaneBuf<'static>,
17552 cdef: &CdefParams,17556 cdef: &CdefParams,
17553 skip_grid: &Neighbours,17557 skip_grid: &Neighbours,
17554 // This frame header's own CROPPED luma size, for the straddling-unit17558 // This frame header's own CROPPED luma size, for the straddling-unit
@@ -17789,12 +17793,12 @@ fn apply_cdef(
17789 /// CDEF-filtered plane, per `restoration.rs`'s own `lr_sample` doc comment.17793 /// CDEF-filtered plane, per `restoration.rs`'s own `lr_sample` doc comment.
17790 #[allow(clippy::too_many_arguments)]17794 #[allow(clippy::too_many_arguments)]
17791 fn apply_loop_restoration(17795 fn apply_loop_restoration(
17792- y: &mut PlaneBuf,17796+ y: &mut PlaneBuf<'static>,
17793- u: &mut PlaneBuf,17797+ u: &mut PlaneBuf<'static>,
17794- v: &mut PlaneBuf,17798+ v: &mut PlaneBuf<'static>,
17795- deblocked_y: &PlaneBuf,17799+ deblocked_y: &PlaneBuf<'_>,
17796- deblocked_u: &PlaneBuf,17800+ deblocked_u: &PlaneBuf<'_>,
17797- deblocked_v: &PlaneBuf,17801+ deblocked_v: &PlaneBuf<'_>,
17798 lr: &LoopRestorationParams,17802 lr: &LoopRestorationParams,
17799 grid: &crate::restoration::RestorationGrid,17803 grid: &crate::restoration::RestorationGrid,
17800 // lane-golomb r8: this frame header's own (cropped) luma size. Loop17804 // lane-golomb r8: this frame header's own (cropped) luma size. Loop
@@ -17829,8 +17833,7 @@ fn apply_loop_restoration(
17829 0,17833 0,
17830 &mut out, fctx,17834 &mut out, fctx,
17831 );17835 );
17832- std::mem::swap(&mut y.data, &mut out);17836+ scratch_return(std::mem::replace(&mut y.data, std::borrow::Cow::Owned(out)).into_owned());
17833- scratch_return(out);
17834 let mut out = scratch_empty();17837 let mut out = scratch_empty();
17835 crate::restoration::apply_loop_restoration_plane(17838 crate::restoration::apply_loop_restoration_plane(
17836 &u.data,17839 &u.data,
@@ -17845,8 +17848,7 @@ fn apply_loop_restoration(
17845 1,17848 1,
17846 &mut out, fctx,17849 &mut out, fctx,
17847 );17850 );
17848- std::mem::swap(&mut u.data, &mut out);17851+ scratch_return(std::mem::replace(&mut u.data, std::borrow::Cow::Owned(out)).into_owned());
17849- scratch_return(out);
17850 let mut out = scratch_empty();17852 let mut out = scratch_empty();
17851 crate::restoration::apply_loop_restoration_plane(17853 crate::restoration::apply_loop_restoration_plane(
17852 &v.data,17854 &v.data,
@@ -17861,8 +17863,7 @@ fn apply_loop_restoration(
17861 2,17863 2,
17862 &mut out, fctx,17864 &mut out, fctx,
17863 );17865 );
17864- std::mem::swap(&mut v.data, &mut out);17866+ scratch_return(std::mem::replace(&mut v.data, std::borrow::Cow::Owned(out)).into_owned());
17865- scratch_return(out);
17866 }17867 }
17867 17868
17868 /// Decodes the payload [`crate::tile::sb_coeff_key_frame_tile`] writes,17869 /// Decodes the payload [`crate::tile::sb_coeff_key_frame_tile`] writes,
@@ -18232,7 +18233,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
18232 let (width, height) = (cols32 as usize * BLOCK, rows32 as usize * BLOCK);18233 let (width, height) = (cols32 as usize * BLOCK, rows32 as usize * BLOCK);
18233 18234
18234 let mut y = PlaneBuf {18235 let mut y = PlaneBuf {
18235- data: vec![0u16; width * height],18236+ data: std::borrow::Cow::Owned(vec![0u16; width * height]),
18236 width,18237 width,
18237 height,18238 height,
18238 true_width,18239 true_width,
@@ -18243,7 +18244,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
18243 tile_y1: height,18244 tile_y1: height,
18244 };18245 };
18245 let mut u = PlaneBuf {18246 let mut u = PlaneBuf {
18246- data: vec![0u16; width * height / 4],18247+ data: std::borrow::Cow::Owned(vec![0u16; width * height / 4]),
18247 width: width / 2,18248 width: width / 2,
18248 height: height / 2,18249 height: height / 2,
18249 true_width: true_width / 2,18250 true_width: true_width / 2,
@@ -18254,7 +18255,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
18254 tile_y1: height / 2,18255 tile_y1: height / 2,
18255 };18256 };
18256 let mut v = PlaneBuf {18257 let mut v = PlaneBuf {
18257- data: vec![0u16; width * height / 4],18258+ data: std::borrow::Cow::Owned(vec![0u16; width * height / 4]),
18258 width: width / 2,18259 width: width / 2,
18259 height: height / 2,18260 height: height / 2,
18260 true_width: true_width / 2,18261 true_width: true_width / 2,
@@ -20130,7 +20131,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
20130 use std::io::Write;20131 use std::io::Write;
20131 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);20132 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
20132 if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {20133 if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {
20133- let narrow = |p: &PlaneBuf| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() };20134+ let narrow = |p: &PlaneBuf<'_>| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() };
20134 let _ = f.write_all(&narrow(&y));20135 let _ = f.write_all(&narrow(&y));
20135 let _ = f.write_all(&narrow(&u));20136 let _ = f.write_all(&narrow(&u));
20136 let _ = f.write_all(&narrow(&v));20137 let _ = f.write_all(&narrow(&v));
@@ -20142,7 +20143,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
20142 use std::io::Write;20143 use std::io::Write;
20143 static IDX2: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);20144 static IDX2: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
20144 let idx = IDX2.fetch_add(1, std::sync::atomic::Ordering::SeqCst);20145 let idx = IDX2.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
20145- let crop_wide = |plane: &PlaneBuf| -> Vec<u8> {20146+ let crop_wide = |plane: &PlaneBuf<'_>| -> Vec<u8> {
20146 let mut out = Vec::with_capacity(plane.true_width * plane.true_height);20147 let mut out = Vec::with_capacity(plane.true_width * plane.true_height);
20147 for row in 0..plane.true_height {20148 for row in 0..plane.true_height {
20148 out.extend(plane.data[row * plane.width..][..plane.true_width].iter().map(|&s| s as u8));20149 out.extend(plane.data[row * plane.width..][..plane.true_width].iter().map(|&s| s as u8));
@@ -20204,10 +20205,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
20204 if let Some((upscaled_w, _)) = superres(fctx) {20205 if let Some((upscaled_w, _)) = superres(fctx) {
20205 let bd = u32::from(bit_depth(fctx));20206 let bd = u32::from(bit_depth(fctx));
20206 let (uw, fw, fh) = (upscaled_w as usize, frame_width as usize, frame_height as usize);20207 let (uw, fw, fh) = (upscaled_w as usize, frame_width as usize, frame_height as usize);
20207- let up = |p: &PlaneBuf, in_w: usize, in_h: usize, out_w: usize| PlaneBuf {20208+ let up = |p: &PlaneBuf<'_>, in_w: usize, in_h: usize, out_w: usize| PlaneBuf {
20208- data: crate::superres::upscale_plane_strided(20209+ data: std::borrow::Cow::Owned(crate::superres::upscale_plane_strided(
20209 &p.data, p.width, in_w, in_h, p.true_width, out_w, bd,20210 &p.data, p.width, in_w, in_h, p.true_width, out_w, bd,
20210- ),20211+ )),
20211 width: out_w,20212 width: out_w,
20212 height: in_h,20213 height: in_h,
20213 true_width: out_w,20214 true_width: out_w,
@@ -20234,9 +20235,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
20234 );20235 );
20235 }20236 }
20236 if let Some((db_y, db_u, db_v)) = deblocked {20237 if let Some((db_y, db_u, db_v)) = deblocked {
20237- scratch_return(db_y.data);20238+ scratch_return(db_y.data.into_owned());
20238- scratch_return(db_u.data);20239+ scratch_return(db_u.data.into_owned());
20239- scratch_return(db_v.data);20240+ scratch_return(db_v.data.into_owned());
20240 }20241 }
20241 20242
20242 let (fw, fh) = (lr_w, frame_height as usize);20243 let (fw, fh) = (lr_w, frame_height as usize);
@@ -20254,14 +20255,14 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
20254 Picture {20255 Picture {
20255 width,20256 width,
20256 height,20257 height,
20257- y: y.data,20258+ y: y.data.into_owned(),
20258- u: u.data,20259+ u: u.data.into_owned(),
20259- v: v.data,20260+ v: v.data.into_owned(),
20260 },20261 },
20261 result_cdfs,20262 result_cdfs,
20262 ));20263 ));
20263 }20264 }
20264- let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u16> {20265+ let crop = |plane: &PlaneBuf<'_>, w: usize, h: usize| -> Vec<u16> {
20265 let mut out = Vec::with_capacity(w * h);20266 let mut out = Vec::with_capacity(w * h);
20266 for row in 0..h {20267 for row in 0..h {
20267 out.extend(plane.data[row * plane.width..][..w].iter().copied());20268 out.extend(plane.data[row * plane.width..][..w].iter().copied());
@@ -20583,7 +20584,7 @@ fn mv_to_q4(pos: usize, mv_component: i32, luma: bool) -> i32 {
20583 (pos as i32) * 16 + mv_component * if luma { 2 } else { 1 }20584 (pos as i32) * 16 + mv_component * if luma { 2 } else { 1 }
20584 }20585 }
20585 20586
20586-impl PlaneBuf {20587+impl PlaneBuf<'_> {
20587 /// Adds `residual` onto an already-computed `prediction` (motion20588 /// Adds `residual` onto an already-computed `prediction` (motion
20588 /// compensation's output, rather than [`predict`]'s intra one), writing20589 /// compensation's output, rather than [`predict`]'s intra one), writing
20589 /// the clamped reconstruction into the plane at `(x, y)` -- the inter20590 /// the clamped reconstruction into the plane at `(x, y)` -- the inter
@@ -20633,7 +20634,7 @@ impl PlaneBuf {
20633 let dst = (y + row) * self.width + x;20634 let dst = (y + row) * self.width + x;
20634 let pred = &prediction[src..src + w];20635 let pred = &prediction[src..src + w];
20635 let res = &residual[src..src + w];20636 let res = &residual[src..src + w];
20636- let out = &mut self.data[dst..dst + w];20637+ let out = &mut self.data.to_mut()[dst..dst + w];
20637 for ((o, &p), &r) in out.iter_mut().zip(pred).zip(res) {20638 for ((o, &p), &r) in out.iter_mut().zip(pred).zip(res) {
20638 *o = (i32::from(p) + r).clamp(0, max) as u16;20639 *o = (i32::from(p) + r).clamp(0, max) as u16;
20639 }20640 }
@@ -20655,7 +20656,7 @@ fn read_inter_plane(
20655 plane_idx: usize,20656 plane_idx: usize,
20656 around: (bool, bool, i32),20657 around: (bool, bool, i32),
20657 tx_mode: usize,20658 tx_mode: usize,
20658- plane: &mut PlaneBuf,20659+ plane: &mut PlaneBuf<'static>,
20659 x: usize,20660 x: usize,
20660 y: usize,20661 y: usize,
20661 side: usize,20662 side: usize,
@@ -20794,11 +20795,11 @@ fn read_single_ref(
20794 /// the compound path can call it twice (lane-av1comp).20795 /// the compound path can call it twice (lane-av1comp).
20795 fn ref_planes<'a>(20796 fn ref_planes<'a>(
20796 ref_frame: i8,20797 ref_frame: i8,
20797- ref_y: &'a PlaneBuf,20798+ ref_y: &'a PlaneBuf<'a>,
20798- ref_u: &'a PlaneBuf,20799+ ref_u: &'a PlaneBuf<'a>,
20799- ref_v: &'a PlaneBuf,20800+ ref_v: &'a PlaneBuf<'a>,
20800 other_refs: &'a RefSlots,20801 other_refs: &'a RefSlots,
20801-) -> Result<(&'a PlaneBuf, &'a PlaneBuf, &'a PlaneBuf)> {20802+) -> Result<(&'a PlaneBuf<'a>, &'a PlaneBuf<'a>, &'a PlaneBuf<'a>)> {
20802 if ref_frame == LAST_FRAME {20803 if ref_frame == LAST_FRAME {
20803 Ok((ref_y, ref_u, ref_v))20804 Ok((ref_y, ref_u, ref_v))
20804 } else {20805 } else {
@@ -21236,7 +21237,7 @@ nb_newmv={} cell_size={:?} cell_inter={:?} cell_ref={:?} sb_row_off={} sb_col_of
21236 /// under `av1_setup_build_prediction_by_{above,left}_pred`).21237 /// under `av1_setup_build_prediction_by_{above,left}_pred`).
21237 #[allow(clippy::too_many_arguments)]21238 #[allow(clippy::too_many_arguments)]
21238 fn obmc_neighbour_pred(21239 fn obmc_neighbour_pred(
21239- refplane: &PlaneBuf,21240+ refplane: &PlaneBuf<'_>,
21240 x: usize,21241 x: usize,
21241 y: usize,21242 y: usize,
21242 mv: (i32, i32),21243 mv: (i32, i32),
@@ -21309,7 +21310,7 @@ const II_WEIGHTS_1D: [u8; 128] = [
21309 /// lane-wii r2: `wedge == Some(..)` replaces the mode mask with the wedge21310 /// lane-wii r2: `wedge == Some(..)` replaces the mode mask with the wedge
21310 /// codebook mask (fixed sign 0; luma stride, 2x2 box-averaged for chroma).21311 /// codebook mask (fixed sign 0; luma stride, 2x2 box-averaged for chroma).
21311 fn interintra_blend(21312 fn interintra_blend(
21312- plane: &PlaneBuf,21313+ plane: &PlaneBuf<'_>,
21313 x: usize,21314 x: usize,
21314 y: usize,21315 y: usize,
21315 bw: usize,21316 bw: usize,
@@ -21512,9 +21513,9 @@ fn obmc_blend(
21512 py: usize,21513 py: usize,
21513 cpx: usize,21514 cpx: usize,
21514 cpy: usize,21515 cpy: usize,
21515- ref_y: &PlaneBuf,21516+ ref_y: &PlaneBuf<'_>,
21516- ref_u: &PlaneBuf,21517+ ref_u: &PlaneBuf<'_>,
21517- ref_v: &PlaneBuf,21518+ ref_v: &PlaneBuf<'_>,
21518 other_refs: &RefSlots,21519 other_refs: &RefSlots,
21519 interp_fixed: Option<mc::InterpFilterKind>,21520 interp_fixed: Option<mc::InterpFilterKind>,
21520 // lane-scaledref r1: this frame's own coded luma width -- each OBMC21521 // lane-scaledref r1: this frame's own coded luma width -- each OBMC
@@ -22086,12 +22087,12 @@ fn decode_inter_block(
22086 side: usize,22087 side: usize,
22087 mi_cols: u32,22088 mi_cols: u32,
22088 mi_rows: u32,22089 mi_rows: u32,
22089- y: &mut PlaneBuf,22090+ y: &mut PlaneBuf<'static>,
22090- u: &mut PlaneBuf,22091+ u: &mut PlaneBuf<'static>,
22091- v: &mut PlaneBuf,22092+ v: &mut PlaneBuf<'static>,
22092- ref_y: &PlaneBuf,22093+ ref_y: &PlaneBuf<'_>,
22093- ref_u: &PlaneBuf,22094+ ref_u: &PlaneBuf<'_>,
22094- ref_v: &PlaneBuf,22095+ ref_v: &PlaneBuf<'_>,
22095 // lane-av1refs: every non-`LAST_FRAME` reference this frame header's own22096 // lane-av1refs: every non-`LAST_FRAME` reference this frame header's own
22096 // `ref_frame_idx` names a live DPB slot for, indexed `[ref_frame]`22097 // `ref_frame_idx` names a live DPB slot for, indexed `[ref_frame]`
22097 // (`LAST2_FRAME`=2 .. `ALTREF_FRAME`=7; index 0/1 unused, `LAST_FRAME`22098 // (`LAST2_FRAME`=2 .. `ALTREF_FRAME`=7; index 0/1 unused, `LAST_FRAME`
@@ -25283,7 +25284,7 @@ fn decode_inter_block(
25283 );25284 );
25284 let cu_scan = default_scan(cu_tx);25285 let cu_scan = default_scan(cu_tx);
25285 for plane_idx in 1..3 {25286 for plane_idx in 1..3 {
25286- let buf: &mut PlaneBuf = if plane_idx == 1 { &mut *u } else { &mut *v };25287+ let buf: &mut PlaneBuf<'static> = if plane_idx == 1 { &mut *u } else { &mut *v };
25287 let cu_grid = if skip {25288 let cu_grid = if skip {
25288 buf.reconstruct(25289 buf.reconstruct(
25289 cu_x,25290 cu_x,
@@ -25781,12 +25782,12 @@ fn decode_inter_sub8_split4(
25781 group_mi: (usize, usize),25782 group_mi: (usize, usize),
25782 mi_cols: u32,25783 mi_cols: u32,
25783 mi_rows: u32,25784 mi_rows: u32,
25784- y: &mut PlaneBuf,25785+ y: &mut PlaneBuf<'static>,
25785- u: &mut PlaneBuf,25786+ u: &mut PlaneBuf<'static>,
25786- v: &mut PlaneBuf,25787+ v: &mut PlaneBuf<'static>,
25787- ref_y: &PlaneBuf,25788+ ref_y: &PlaneBuf<'_>,
25788- ref_u: &PlaneBuf,25789+ ref_u: &PlaneBuf<'_>,
25789- ref_v: &PlaneBuf,25790+ ref_v: &PlaneBuf<'_>,
25790 other_refs: &RefSlots,25791 other_refs: &RefSlots,
25791 sign_bias_table: &SignBiasTable,25792 sign_bias_table: &SignBiasTable,
25792 global_motion: &[ec_av1_syntax::WarpParams; 7],25793 global_motion: &[ec_av1_syntax::WarpParams; 7],
@@ -26292,9 +26293,9 @@ fn decode_intra_sub8_leaf(
26292 has_chroma: bool,26293 has_chroma: bool,
26293 skip: bool,26294 skip: bool,
26294 scan4: &[u16],26295 scan4: &[u16],
26295- y: &mut PlaneBuf,26296+ y: &mut PlaneBuf<'static>,
26296- u: &mut PlaneBuf,26297+ u: &mut PlaneBuf<'static>,
26297- v: &mut PlaneBuf,26298+ v: &mut PlaneBuf<'static>,
26298 base_q_idx: u8,26299 base_q_idx: u8,
26299 enable_filter_intra: bool,26300 enable_filter_intra: bool,
26300 tx_select: bool,26301 tx_select: bool,
@@ -26738,12 +26739,12 @@ fn decode_inter_sub8_rect2(
26738 vert: bool,26739 vert: bool,
26739 mi_cols: u32,26740 mi_cols: u32,
26740 mi_rows: u32,26741 mi_rows: u32,
26741- y: &mut PlaneBuf,26742+ y: &mut PlaneBuf<'static>,
26742- u: &mut PlaneBuf,26743+ u: &mut PlaneBuf<'static>,
26743- v: &mut PlaneBuf,26744+ v: &mut PlaneBuf<'static>,
26744- ref_y: &PlaneBuf,26745+ ref_y: &PlaneBuf<'_>,
26745- ref_u: &PlaneBuf,26746+ ref_u: &PlaneBuf<'_>,
26746- ref_v: &PlaneBuf,26747+ ref_v: &PlaneBuf<'_>,
26747 other_refs: &RefSlots,26748 other_refs: &RefSlots,
26748 sign_bias_table: &SignBiasTable,26749 sign_bias_table: &SignBiasTable,
26749 global_motion: &[ec_av1_syntax::WarpParams; 7],26750 global_motion: &[ec_av1_syntax::WarpParams; 7],
@@ -27345,12 +27346,12 @@ fn decode_inter_block8(
27345 mi_rows: u32,27346 mi_rows: u32,
27346 outer_at: (usize, usize),27347 outer_at: (usize, usize),
27347 leaf_mi: (usize, usize),27348 leaf_mi: (usize, usize),
27348- y: &mut PlaneBuf,27349+ y: &mut PlaneBuf<'static>,
27349- u: &mut PlaneBuf,27350+ u: &mut PlaneBuf<'static>,
27350- v: &mut PlaneBuf,27351+ v: &mut PlaneBuf<'static>,
27351- ref_y: &PlaneBuf,27352+ ref_y: &PlaneBuf<'_>,
27352- ref_u: &PlaneBuf,27353+ ref_u: &PlaneBuf<'_>,
27353- ref_v: &PlaneBuf,27354+ ref_v: &PlaneBuf<'_>,
27354 other_refs: &RefSlots,27355 other_refs: &RefSlots,
27355 base_q_idx: u8,27356 base_q_idx: u8,
27356 scan8: &[u16],27357 scan8: &[u16],
@@ -29577,7 +29578,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
29577 let (width, height) = (cols as usize * BLOCK, rows as usize * BLOCK);29578 let (width, height) = (cols as usize * BLOCK, rows as usize * BLOCK);
29578 29579
29579 let ref_y = PlaneBuf {29580 let ref_y = PlaneBuf {
29580- data: reference.y.iter().map(|&s| s as u16).collect(),29581+ data: std::borrow::Cow::Borrowed(&reference.y),
29581 width: reference.width,29582 width: reference.width,
29582 height: reference.height,29583 height: reference.height,
29583 true_width: reference.width,29584 true_width: reference.width,
@@ -29588,7 +29589,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
29588 tile_y1: reference.height,29589 tile_y1: reference.height,
29589 };29590 };
29590 let ref_u = PlaneBuf {29591 let ref_u = PlaneBuf {
29591- data: reference.u.iter().map(|&s| s as u16).collect(),29592+ data: std::borrow::Cow::Borrowed(&reference.u),
29592 width: reference.width / 2,29593 width: reference.width / 2,
29593 height: reference.height / 2,29594 height: reference.height / 2,
29594 true_width: reference.width / 2,29595 true_width: reference.width / 2,
@@ -29599,7 +29600,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
29599 tile_y1: reference.height / 2,29600 tile_y1: reference.height / 2,
29600 };29601 };
29601 let ref_v = PlaneBuf {29602 let ref_v = PlaneBuf {
29602- data: reference.v.iter().map(|&s| s as u16).collect(),29603+ data: std::borrow::Cow::Borrowed(&reference.v),
29603 width: reference.width / 2,29604 width: reference.width / 2,
29604 height: reference.height / 2,29605 height: reference.height / 2,
29605 true_width: reference.width / 2,29606 true_width: reference.width / 2,
@@ -29616,13 +29617,13 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
29616 // block it is decoding selects an index that is still `None` here29617 // block it is decoding selects an index that is still `None` here
29617 // (spec 7.9 requires every *active* reference be a compatible size;29618 // (spec 7.9 requires every *active* reference be a compatible size;
29618 // an inactive one this frame never selects is simply left `None`).29619 // an inactive one this frame never selects is simply left `None`).
29619- let owned_refs: [Option<(PlaneBuf, PlaneBuf, PlaneBuf)>; 8] = std::array::from_fn(|i| {29620+ let owned_refs: [Option<(PlaneBuf<'_>, PlaneBuf<'_>, PlaneBuf<'_>)>; 8] = std::array::from_fn(|i| {
29620 other_refs[i]29621 other_refs[i]
29621 .filter(|g| g.width == reference.width && g.height == reference.height)29622 .filter(|g| g.width == reference.width && g.height == reference.height)
29622 .map(|g| {29623 .map(|g| {
29623 (29624 (
29624 PlaneBuf {29625 PlaneBuf {
29625- data: g.y.iter().map(|&s| s as u16).collect(),29626+ data: std::borrow::Cow::Borrowed(&g.y),
29626 width: g.width,29627 width: g.width,
29627 height: g.height,29628 height: g.height,
29628 true_width: g.width,29629 true_width: g.width,
@@ -29633,7 +29634,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
29633 tile_y1: g.height,29634 tile_y1: g.height,
29634 },29635 },
29635 PlaneBuf {29636 PlaneBuf {
29636- data: g.u.iter().map(|&s| s as u16).collect(),29637+ data: std::borrow::Cow::Borrowed(&g.u),
29637 width: g.width / 2,29638 width: g.width / 2,
29638 height: g.height / 2,29639 height: g.height / 2,
29639 true_width: g.width / 2,29640 true_width: g.width / 2,
@@ -29644,7 +29645,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
29644 tile_y1: g.height / 2,29645 tile_y1: g.height / 2,
29645 },29646 },
29646 PlaneBuf {29647 PlaneBuf {
29647- data: g.v.iter().map(|&s| s as u16).collect(),29648+ data: std::borrow::Cow::Borrowed(&g.v),
29648 width: g.width / 2,29649 width: g.width / 2,
29649 height: g.height / 2,29650 height: g.height / 2,
29650 true_width: g.width / 2,29651 true_width: g.width / 2,
@@ -29661,7 +29662,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
29661 std::array::from_fn(|i| owned_refs[i].as_ref().map(|(a, b, c)| (a, b, c)));29662 std::array::from_fn(|i| owned_refs[i].as_ref().map(|(a, b, c)| (a, b, c)));
29662 29663
29663 let mut y = PlaneBuf {29664 let mut y = PlaneBuf {
29664- data: vec![0u16; width * height],29665+ data: std::borrow::Cow::Owned(vec![0u16; width * height]),
29665 width,29666 width,
29666 height,29667 height,
29667 true_width,29668 true_width,
@@ -29672,7 +29673,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
29672 tile_y1: height,29673 tile_y1: height,
29673 };29674 };
29674 let mut u = PlaneBuf {29675 let mut u = PlaneBuf {
29675- data: vec![0u16; width * height / 4],29676+ data: std::borrow::Cow::Owned(vec![0u16; width * height / 4]),
29676 width: width / 2,29677 width: width / 2,
29677 height: height / 2,29678 height: height / 2,
29678 true_width: true_width / 2,29679 true_width: true_width / 2,
@@ -29683,7 +29684,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
29683 tile_y1: height / 2,29684 tile_y1: height / 2,
29684 };29685 };
29685 let mut v = PlaneBuf {29686 let mut v = PlaneBuf {
29686- data: vec![0u16; width * height / 4],29687+ data: std::borrow::Cow::Owned(vec![0u16; width * height / 4]),
29687 width: width / 2,29688 width: width / 2,
29688 height: height / 2,29689 height: height / 2,
29689 true_width: true_width / 2,29690 true_width: true_width / 2,
@@ -32187,7 +32188,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
32187 use std::io::Write;32188 use std::io::Write;
32188 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);32189 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
32189 if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {32190 if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {
32190- let narrow = |p: &PlaneBuf| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() };32191+ let narrow = |p: &PlaneBuf<'_>| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() };
32191 let _ = f.write_all(&narrow(&y));32192 let _ = f.write_all(&narrow(&y));
32192 let _ = f.write_all(&narrow(&u));32193 let _ = f.write_all(&narrow(&u));
32193 let _ = f.write_all(&narrow(&v));32194 let _ = f.write_all(&narrow(&v));
@@ -32244,10 +32245,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
32244 if let Some((upscaled_w, _)) = superres(fctx) {32245 if let Some((upscaled_w, _)) = superres(fctx) {
32245 let bd = u32::from(bit_depth(fctx));32246 let bd = u32::from(bit_depth(fctx));
32246 let (uw, fw, fh) = (upscaled_w as usize, frame_width as usize, frame_height as usize);32247 let (uw, fw, fh) = (upscaled_w as usize, frame_width as usize, frame_height as usize);
32247- let up = |p: &PlaneBuf, in_w: usize, in_h: usize, out_w: usize| PlaneBuf {32248+ let up = |p: &PlaneBuf<'_>, in_w: usize, in_h: usize, out_w: usize| PlaneBuf {
32248- data: crate::superres::upscale_plane_strided(32249+ data: std::borrow::Cow::Owned(crate::superres::upscale_plane_strided(
32249 &p.data, p.width, in_w, in_h, p.true_width, out_w, bd,32250 &p.data, p.width, in_w, in_h, p.true_width, out_w, bd,
32250- ),32251+ )),
32251 width: out_w,32252 width: out_w,
32252 height: in_h,32253 height: in_h,
32253 true_width: out_w,32254 true_width: out_w,
@@ -32274,9 +32275,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
32274 );32275 );
32275 }32276 }
32276 if let Some((db_y, db_u, db_v)) = deblocked {32277 if let Some((db_y, db_u, db_v)) = deblocked {
32277- scratch_return(db_y.data);32278+ scratch_return(db_y.data.into_owned());
32278- scratch_return(db_u.data);32279+ scratch_return(db_u.data.into_owned());
32279- scratch_return(db_v.data);32280+ scratch_return(db_v.data.into_owned());
32280 }32281 }
32281 32282
32282 let motion_field = build_motion_field(32283 let motion_field = build_motion_field(
@@ -32303,15 +32304,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
32303 Picture {32304 Picture {
32304 width,32305 width,
32305 height,32306 height,
32306- y: y.data,32307+ y: y.data.into_owned(),
32307- u: u.data,32308+ u: u.data.into_owned(),
32308- v: v.data,32309+ v: v.data.into_owned(),
32309 },32310 },
32310 result_cdfs,32311 result_cdfs,
32311 motion_field,32312 motion_field,
32312 ));32313 ));
32313 }32314 }
32314- let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u16> {32315+ let crop = |plane: &PlaneBuf<'_>, w: usize, h: usize| -> Vec<u16> {
32315 let mut out = Vec::with_capacity(w * h);32316 let mut out = Vec::with_capacity(w * h);
32316 for row in 0..h {32317 for row in 0..h {
32317 out.extend(plane.data[row * plane.width..][..w].iter().copied());32318 out.extend(plane.data[row * plane.width..][..w].iter().copied());
@@ -32986,7 +32987,7 @@ mod tests {
32986 const REFUSAL: &str =32987 const REFUSAL: &str =
32987 "a reference frame selected with no picture at this frame's own ref_frame_idx slot";32988 "a reference frame selected with no picture at this frame's own ref_frame_idx slot";
32988 let plane = PlaneBuf {32989 let plane = PlaneBuf {
32989- data: vec![0u16; 16],32990+ data: std::borrow::Cow::Owned(vec![0u16; 16]),
32990 width: 4,32991 width: 4,
32991 height: 4,32992 height: 4,
32992 true_width: 4,32993 true_width: 4,
@@ -33708,12 +33709,14 @@ mod tests {
33708 let (width, height) = (64usize, 64usize);33709 let (width, height) = (64usize, 64usize);
33709 let ref_pattern: Vec<u16> = (0..width * height).map(|i| (i % 251) as u16).collect();33710 let ref_pattern: Vec<u16> = (0..width * height).map(|i| (i % 251) as u16).collect();
33710 let ref_plane = |scale: usize| PlaneBuf {33711 let ref_plane = |scale: usize| PlaneBuf {
33711- data: ref_pattern33712+ data: std::borrow::Cow::Owned(
33712- .iter()33713+ ref_pattern
33713- .step_by(scale.max(1))33714+ .iter()
33714- .take((width / scale) * (height / scale))33715+ .step_by(scale.max(1))
33715- .copied()33716+ .take((width / scale) * (height / scale))
33716- .collect(),33717+ .copied()
33718+ .collect(),
33719+ ),
33717 width: width / scale,33720 width: width / scale,
33718 height: height / scale,33721 height: height / scale,
33719 true_width: width / scale,33722 true_width: width / scale,
@@ -33724,7 +33727,7 @@ mod tests {
33724 tile_y1: height / scale,33727 tile_y1: height / scale,
33725 };33728 };
33726 let ref_y = PlaneBuf {33729 let ref_y = PlaneBuf {
33727- data: ref_pattern.clone(),33730+ data: std::borrow::Cow::Owned(ref_pattern.clone()),
33728 width,33731 width,
33729 height,33732 height,
33730 true_width: width,33733 true_width: width,
@@ -33738,7 +33741,7 @@ mod tests {
33738 let ref_v = ref_plane(2);33741 let ref_v = ref_plane(2);
33739 33742
33740 let mut y = PlaneBuf {33743 let mut y = PlaneBuf {
33741- data: vec![0u16; width * height],33744+ data: std::borrow::Cow::Owned(vec![0u16; width * height]),
33742 width,33745 width,
33743 height,33746 height,
33744 true_width: width,33747 true_width: width,
@@ -33749,7 +33752,7 @@ mod tests {
33749 tile_y1: height,33752 tile_y1: height,
33750 };33753 };
33751 let mut u = PlaneBuf {33754 let mut u = PlaneBuf {
33752- data: vec![0u16; (width / 2) * (height / 2)],33755+ data: std::borrow::Cow::Owned(vec![0u16; (width / 2) * (height / 2)]),
33753 width: width / 2,33756 width: width / 2,
33754 height: height / 2,33757 height: height / 2,
33755 true_width: width / 2,33758 true_width: width / 2,
@@ -33760,7 +33763,7 @@ mod tests {
33760 tile_y1: height / 2,33763 tile_y1: height / 2,
33761 };33764 };
33762 let mut v = PlaneBuf {33765 let mut v = PlaneBuf {
33763- data: vec![0u16; (width / 2) * (height / 2)],33766+ data: std::borrow::Cow::Owned(vec![0u16; (width / 2) * (height / 2)]),
33764 width: width / 2,33767 width: width / 2,
33765 height: height / 2,33768 height: height / 2,
33766 true_width: width / 2,33769 true_width: width / 2,
crates/ec-av1/src/transform.rsmodified+44 -5
@@ -107,7 +107,7 @@ fn clamp_range(x: i32, r: usize) -> i32 {
107 107
108 /// `B(a, b, angle, flip, r)` (spec 7.13.2.1): a butterfly rotation, and an108 /// `B(a, b, angle, flip, r)` (spec 7.13.2.1): a butterfly rotation, and an
109 /// exchange of the two entries when `flip` is set.109 /// exchange of the two entries when `flip` is set.
110-fn butterfly(t: &mut [i32], a: usize, b: usize, angle: i32, flip: bool, _r: usize) {110+fn butterfly(t: &mut [i32; 64], a: usize, b: usize, angle: i32, flip: bool, _r: usize) {
111 let (ta, tb) = (i64::from(t[a]), i64::from(t[b]));111 let (ta, tb) = (i64::from(t[a]), i64::from(t[b]));
112 let (c, s) = (i64::from(cos128(angle)), i64::from(sin128(angle)));112 let (c, s) = (i64::from(cos128(angle)), i64::from(sin128(angle)));
113 let x = ta * c - tb * s;113 let x = ta * c - tb * s;
@@ -121,7 +121,7 @@ fn butterfly(t: &mut [i32], a: usize, b: usize, angle: i32, flip: bool, _r: usiz
121 121
122 /// `H(a, b, flip, r)` (spec 7.13.2.1): a Hadamard rotation, with the indices122 /// `H(a, b, flip, r)` (spec 7.13.2.1): a Hadamard rotation, with the indices
123 /// exchanged when `flip` is set.123 /// exchanged when `flip` is set.
124-fn hadamard(t: &mut [i32], a: usize, b: usize, flip: bool, r: usize) {124+fn hadamard(t: &mut [i32; 64], a: usize, b: usize, flip: bool, r: usize) {
125 let (a, b) = if flip { (b, a) } else { (a, b) };125 let (a, b) = if flip { (b, a) } else { (a, b) };
126 let (x, y) = (t[a], t[b]);126 let (x, y) = (t[a], t[b]);
127 t[a] = clamp_range(x.wrapping_add(y), r);127 t[a] = clamp_range(x.wrapping_add(y), r);
@@ -130,7 +130,7 @@ fn hadamard(t: &mut [i32], a: usize, b: usize, flip: bool, r: usize) {
130 130
131 /// The inverse DCT array permutation (spec 7.13.2.2): an in-place bit-reversal131 /// The inverse DCT array permutation (spec 7.13.2.2): an in-place bit-reversal
132 /// of the first `1 << n` entries.132 /// of the first `1 << n` entries.
133-fn permute(t: &mut [i32], n: u32) {133+fn permute(t: &mut [i32; 64], n: u32) {
134 let n0 = 1usize << n;134 let n0 = 1usize << n;
135 // A stack copy: this ran once per 1D transform and its `Vec` was the135 // A stack copy: this ran once per 1D transform and its `Vec` was the
136 // `malloc` at the top of every `inverse_dct` frame in the annotation.136 // `malloc` at the top of every `inverse_dct` frame in the annotation.
@@ -148,6 +148,20 @@ fn permute(t: &mut [i32], n: u32) {
148 /// The stage list is the spec's, in the spec's order; the guards on `n` are148 /// The stage list is the spec's, in the spec's order; the guards on `n` are
149 /// what make one network serve every transform size from 4 to 64.149 /// what make one network serve every transform size from 4 to 64.
150 pub fn inverse_dct(t: &mut [i32], n: u32, r: usize) {150 pub fn inverse_dct(t: &mut [i32], n: u32, r: usize) {
151+ // lane-perf10: the network below indexes a 64-entry scratch with computed
152+ // indices, and on a `&mut [i32]` every one of them carried a bounds check.
153+ // A `&mut [i32; 64]` lets the optimiser discharge them all against the
154+ // constant length; this wrapper keeps the slice-taking signature for
155+ // callers outside the 2D driver.
156+ let m = 1usize << n;
157+ let mut fixed = [0i32; 64];
158+ fixed[..m].copy_from_slice(&t[..m]);
159+ inverse_dct_fixed(&mut fixed, n, r);
160+ t[..m].copy_from_slice(&fixed[..m]);
161+}
162+
163+/// [`inverse_dct`] on the driver's own 64-entry scratch.
164+fn inverse_dct_fixed(t: &mut [i32; 64], n: u32, r: usize) {
151 assert!((2..=6).contains(&n), "the inverse DCT is defined for 4..64");165 assert!((2..=6).contains(&n), "the inverse DCT is defined for 4..64");
152 permute(t, n);166 permute(t, n);
153 167
@@ -827,9 +841,9 @@ fn inverse_identity(t: &mut [i32], side: usize) {
827 841
828 /// Dispatches one row or column's 1D inverse transform by [`TxType1d`],842 /// Dispatches one row or column's 1D inverse transform by [`TxType1d`],
829 /// `log2` the spec's transform-size log (as [`inverse_dct`] takes).843 /// `log2` the spec's transform-size log (as [`inverse_dct`] takes).
830-fn inverse_1d(t: &mut [i32], log2: u32, r: usize, kind: TxType1d) {844+fn inverse_1d(t: &mut [i32; 64], log2: u32, r: usize, kind: TxType1d) {
831 match kind {845 match kind {
832- TxType1d::Dct => inverse_dct(t, log2, r),846+ TxType1d::Dct => inverse_dct_fixed(t, log2, r),
833 TxType1d::Adst => match log2 {847 TxType1d::Adst => match log2 {
834 2 => inverse_adst4(t),848 2 => inverse_adst4(t),
835 3 => inverse_adst8(t, r),849 3 => inverse_adst8(t, r),
@@ -904,6 +918,11 @@ pub fn inverse_transform_2d_typed_wh(
904 }918 }
905 let residual = &mut scratch[..w * h];919 let residual = &mut scratch[..w * h];
906 let mut t = [0i32; 64];920 let mut t = [0i32; 64];
921+ // lane-perf10: rows the row pass left non-zero, and whether the first
922+ // of them came out constant along the row -- see the fast path below.
923+ let mut nz_rows = 0usize;
924+ let mut nz_row = 0usize;
925+ let mut const_row = false;
907 for i in 0..h {926 for i in 0..h {
908 let dst = &mut residual[i * w..(i + 1) * w];927 let dst = &mut residual[i * w..(i + 1) * w];
909 // Rows at or past 32 carry no coefficients (the spec zeroes them928 // Rows at or past 32 carry no coefficients (the spec zeroes them
@@ -930,6 +949,26 @@ pub fn inverse_transform_2d_typed_wh(
930 for (d, &v) in dst.iter_mut().zip(t[..w].iter()) {949 for (d, &v) in dst.iter_mut().zip(t[..w].iter()) {
931 *d = clamp_range(round2(v, shift), col_clamp);950 *d = clamp_range(round2(v, shift), col_clamp);
932 }951 }
952+ nz_rows += 1;
953+ nz_row = i;
954+ const_row = nz_rows == 1 && dst.iter().all(|&v| v == dst[0]);
955+ }
956+
957+ // A block whose row pass left exactly one non-zero row, constant along
958+ // that row, feeds every column of the column pass the same vector --
959+ // the DC-only case, which dominates inter residuals. `inverse_1d` is a
960+ // pure function of its input, so one column transform broadcast across
961+ // the block is byte-identical to `w` of them, and the per-column gather
962+ // disappears with it.
963+ if nz_rows <= 1 && const_row {
964+ t[..h].fill(0);
965+ t[nz_row] = residual[nz_row * w];
966+ inverse_1d(&mut t, log2h, col_clamp, col_kind);
967+ for i in 0..h {
968+ let dst_row = if ud_flip { h - 1 - i } else { i };
969+ out[dst_row * w..dst_row * w + w].fill(round2(t[i], 4));
970+ }
971+ return;
933 }972 }
934 973
935 for j in 0..w {974 for j in 0..w {