Skip to content

Commit

Permalink
Rav1dFrameContext_lf::lr_line_buf: Make into AlignedVec64 (#792)
Browse files Browse the repository at this point in the history
  • Loading branch information
randomPoison authored Mar 11, 2024
2 parents 10a60f9 + 72d2e25 commit f7ddd24
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
12 changes: 4 additions & 8 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4448,18 +4448,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 {
Expand Down
2 changes: 1 addition & 1 deletion src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>, /* AlignedVec32<DynPixel> */
pub lr_line_buf: *mut u8,
pub lr_line_buf: AlignedVec64<u8>,
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 */
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f7ddd24

Please sign in to comment.