From 72d2e25a9b55e64dd14f83e746e50a0ec03425af Mon Sep 17 00:00:00 2001 From: Nicole LeGare Date: Mon, 11 Mar 2024 09:08:46 -0700 Subject: [PATCH] `Rav1dFrameContext_lf::lr_line_buf`: Make into `AlignedVec64` --- src/decode.rs | 12 ++++-------- src/internal.rs | 2 +- src/lib.rs | 3 ++- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/decode.rs b/src/decode.rs index 5d07c0fb2..ef1773523 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -4449,18 +4449,14 @@ pub(crate) unsafe fn rav1d_decode_frame_init( if y_stride * num_lines as isize != f.lf.lr_buf_plane_sz[0] as isize || uv_stride * num_lines as isize * 2 != f.lf.lr_buf_plane_sz[1] as isize { - rav1d_free_aligned(f.lf.lr_line_buf as *mut c_void); // lr simd may overread the input, so slightly over-allocate the lpf buffer let mut alloc_sz: usize = 128; alloc_sz += y_stride.unsigned_abs() * num_lines as usize; alloc_sz += uv_stride.unsigned_abs() * num_lines as usize * 2; - f.lf.lr_line_buf = rav1d_alloc_aligned(alloc_sz, 64) as *mut u8; - let mut ptr = f.lf.lr_line_buf; - if ptr.is_null() { - f.lf.lr_buf_plane_sz[1] = 0; - f.lf.lr_buf_plane_sz[0] = f.lf.lr_buf_plane_sz[1]; - return Err(ENOMEM); - } + // TODO: Fallible allocation + // On allocation failure set `f.lf.lr_buf_plane_sz` to 0. + f.lf.lr_line_buf.resize(alloc_sz, 0); + let mut ptr = f.lf.lr_line_buf.as_mut_ptr(); ptr = ptr.offset(64); if y_stride < 0 { diff --git a/src/internal.rs b/src/internal.rs index 5fcdccb1b..02139885d 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -461,7 +461,7 @@ pub struct Rav1dFrameContext_lf { pub lvl: [[[[u8; 2]; 8]; 4]; 8], /* [8 seg_id][4 dir][8 ref][2 is_gmv] */ pub tx_lpf_right_edge: TxLpfRightEdge, pub cdef_line_buf: AlignedVec32, /* AlignedVec32 */ - pub lr_line_buf: *mut u8, + pub lr_line_buf: AlignedVec64, pub cdef_line: [[usize; 3]; 2], /* [2 pre/post][3 plane] */ pub cdef_lpf_line: [usize; 3], /* plane */ pub lr_lpf_line: [*mut DynPixel; 3], /* plane */ diff --git a/src/lib.rs b/src/lib.rs index 55e048ec8..76b5f5165 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -349,6 +349,7 @@ pub(crate) unsafe fn rav1d_open(c_out: &mut *mut Rav1dContext, s: &Rav1dSettings addr_of_mut!(f.lf.lr_mask).write(Default::default()); addr_of_mut!(f.lf.tx_lpf_right_edge).write(Default::default()); addr_of_mut!(f.lf.cdef_line_buf).write(Default::default()); + addr_of_mut!(f.lf.lr_line_buf).write(Default::default()); f.lf.last_sharpness = -(1 as c_int); rav1d_refmvs_init(&mut f.rf); n = n.wrapping_add(1); @@ -928,7 +929,7 @@ impl Drop for Rav1dContext { free(f.lf.start_of_tile_row as *mut c_void); rav1d_refmvs_clear(&mut f.rf); let _ = mem::take(&mut f.lf.cdef_line_buf); // TODO: remove when context is owned - rav1d_free_aligned(f.lf.lr_line_buf as *mut c_void); + let _ = mem::take(&mut f.lf.lr_line_buf); // TODO: remove when context is owned n_1 = n_1.wrapping_add(1); } rav1d_free_aligned(self.fc as *mut c_void);