Skip to content

Commit

Permalink
Rav1dFrameContext_lf::tx_lpf_right_edge: Split and make into Vecs
Browse files Browse the repository at this point in the history
  • Loading branch information
randomPoison committed Feb 29, 2024
1 parent 08f6b7c commit f90936b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 36 deletions.
32 changes: 8 additions & 24 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4237,23 +4237,15 @@ pub(crate) unsafe fn rav1d_decode_tile_sbrow(
// backup t->a/l.tx_lpf_y/uv at tile boundaries to use them to "fix"
// up the initial value in neighbour tiles when running the loopfilter
let mut align_h = f.bh + 31 & !31;
slice::from_raw_parts_mut(
f.lf.tx_lpf_right_edge[0],
(align_h * tile_col + t.by + sb_step).try_into().unwrap(),
)[(align_h * tile_col + t.by).try_into().unwrap()..][..sb_step.try_into().unwrap()]
.copy_from_slice(&t.l.tx_lpf_y.0[(t.by & 16) as usize..][..sb_step.try_into().unwrap()]);
let (tx_lpf_right_edge_y, tx_lpf_right_edge_uv) = f.lf.tx_lpf_right_edge_mut();
tx_lpf_right_edge_y[(align_h * tile_col + t.by) as usize..][..sb_step as usize]
.copy_from_slice(&t.l.tx_lpf_y.0[(t.by & 16) as usize..][..sb_step as usize]);
let ss_ver = (f.cur.p.layout == Rav1dPixelLayout::I420) as c_int;
align_h >>= ss_ver;
slice::from_raw_parts_mut(
f.lf.tx_lpf_right_edge[1],
(align_h * tile_col + (t.by >> ss_ver) + (sb_step >> ss_ver))
.try_into()
.unwrap(),
)[(align_h * tile_col + (t.by >> ss_ver)).try_into().unwrap()..]
[..(sb_step >> ss_ver).try_into().unwrap()]
tx_lpf_right_edge_uv[(align_h * tile_col + (t.by >> ss_ver)) as usize..]
[..(sb_step >> ss_ver) as usize]
.copy_from_slice(
&t.l.tx_lpf_uv.0[((t.by & 16) >> ss_ver) as usize..]
[..(sb_step >> ss_ver).try_into().unwrap()],
&t.l.tx_lpf_uv.0[((t.by & 16) >> ss_ver) as usize..][..(sb_step >> ss_ver) as usize],
);

Ok(())
Expand Down Expand Up @@ -4562,16 +4554,8 @@ pub(crate) unsafe fn rav1d_decode_frame_init(
}

let re_sz = f.sb128h * frame_hdr.tiling.cols;
if re_sz != f.lf.re_sz {
freep(&mut *f.lf.tx_lpf_right_edge.as_mut_ptr().offset(0) as *mut *mut u8 as *mut c_void);
f.lf.tx_lpf_right_edge[0] = malloc(re_sz as usize * 32 * 2) as *mut u8;
if f.lf.tx_lpf_right_edge[0].is_null() {
f.lf.re_sz = 0;
return Err(ENOMEM);
}
f.lf.tx_lpf_right_edge[1] = f.lf.tx_lpf_right_edge[0].offset((re_sz * 32) as isize);
f.lf.re_sz = re_sz;
}
// TODO: Fallible allocation
f.lf.tx_lpf_right_edge.resize(re_sz as usize * 32 * 2, 0);

// init ref mvs
if frame_hdr.frame_type.is_inter_or_switch() || frame_hdr.allow_intrabc != 0 {
Expand Down
15 changes: 13 additions & 2 deletions src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,10 @@ pub struct Rav1dFrameContext_lf {
pub cdef_buf_plane_sz: [c_int; 2], /* stride*sbh*4 */
pub cdef_buf_sbh: c_int,
pub lr_buf_plane_sz: [c_int; 2], /* (stride*sbh*4) << sb128 if n_tc > 1, else stride*4 */
pub re_sz: c_int, /* h */
pub lim_lut: Align16<Av1FilterLUT>,
pub last_sharpness: c_int,
pub lvl: [[[[u8; 2]; 8]; 4]; 8], /* [8 seg_id][4 dir][8 ref][2 is_gmv] */
pub tx_lpf_right_edge: [*mut u8; 2],
pub tx_lpf_right_edge: Vec<u8>, /* len = h*2 */
pub cdef_line_buf: *mut u8,
pub lr_line_buf: *mut u8,
pub cdef_line: [[*mut DynPixel; 3]; 2], /* [2 pre/post][3 plane] */
Expand All @@ -479,6 +478,18 @@ pub struct Rav1dFrameContext_lf {
pub restore_planes: c_int, // enum LrRestorePlanes
}

impl Rav1dFrameContext_lf {
pub fn tx_lpf_right_edge(&self) -> (&[u8], &[u8]) {
let mid = self.tx_lpf_right_edge.len() / 2;
self.tx_lpf_right_edge.split_at(mid)
}

pub fn tx_lpf_right_edge_mut(&mut self) -> (&mut [u8], &mut [u8]) {
let mid = self.tx_lpf_right_edge.len() / 2;
self.tx_lpf_right_edge.split_at_mut(mid)
}
}

#[repr(C)]
pub struct Rav1dFrameContext_task_thread_pending_tasks {
pub head: *mut Rav1dTask,
Expand Down
16 changes: 7 additions & 9 deletions src/lf_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,9 @@ pub(crate) unsafe fn rav1d_loopfilter_sbrow_cols<BD: BitDepth>(
let hmax = (1 as c_uint) << hmask;
let endy4 = (starty4 + cmp::min(f.h4 - sby * sbsz, sbsz)) as c_uint;
let uv_endy4: c_uint = endy4.wrapping_add(ss_ver as c_uint) >> ss_ver;
let mut lpf_y: *const u8 = &mut *(*(f.lf.tx_lpf_right_edge).as_ptr().offset(0))
.offset((sby << sbl2) as isize) as *mut u8;
let mut lpf_uv: *const u8 = &mut *(*(f.lf.tx_lpf_right_edge).as_ptr().offset(1))
.offset((sby << sbl2 - ss_ver) as isize) as *mut u8;
let (lpf_y, lpf_uv) = f.lf.tx_lpf_right_edge();
let mut lpf_y = &lpf_y[(sby << sbl2) as usize..];
let mut lpf_uv = &lpf_uv[(sby << sbl2 - ss_ver) as usize..];
let frame_hdr = &***f.frame_hdr.as_ref().unwrap();
let mut tile_col = 1;
loop {
Expand Down Expand Up @@ -592,7 +591,7 @@ pub(crate) unsafe fn rav1d_loopfilter_sbrow_cols<BD: BitDepth>(
*fresh2 = (*fresh2 as c_uint & !smask) as u16;
let ref mut fresh3 = (*y_hmask.offset(cmp::min(
idx,
*lpf_y.offset(y.wrapping_sub(starty4 as c_uint) as isize) as c_int,
lpf_y[y.wrapping_sub(starty4 as c_uint) as usize] as c_int,
) as isize))[sidx as usize];
*fresh3 = (*fresh3 as c_uint | smask) as u16;
y = y.wrapping_add(1);
Expand All @@ -614,16 +613,15 @@ pub(crate) unsafe fn rav1d_loopfilter_sbrow_cols<BD: BitDepth>(
*fresh5 = (*fresh5 as c_uint & !smask_0) as u16;
let ref mut fresh6 = (*uv_hmask.offset(cmp::min(
idx_0,
*lpf_uv.offset(y_0.wrapping_sub((starty4 >> ss_ver) as c_uint) as isize)
as c_int,
lpf_uv[y_0.wrapping_sub((starty4 >> ss_ver) as c_uint) as usize] as c_int,
) as isize))[sidx_0 as usize];
*fresh6 = (*fresh6 as c_uint | smask_0) as u16;
y_0 = y_0.wrapping_add(1);
uv_mask <<= 1;
}
}
lpf_y = lpf_y.offset(halign as isize);
lpf_uv = lpf_uv.offset((halign >> ss_ver) as isize);
lpf_y = &lpf_y[halign as usize..];
lpf_uv = &lpf_uv[(halign >> ss_ver) as usize..];
tile_col += 1;
}
if start_of_tile_row != 0 {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ impl Drop for Rav1dContext {
let _ = mem::take(&mut f.lf.mask); // TODO: remove when context is owned
free(f.lf.lr_mask as *mut c_void);
let _ = mem::take(&mut f.lf.level);
free(f.lf.tx_lpf_right_edge[0] as *mut c_void);
let _ = mem::take(&mut f.lf.tx_lpf_right_edge); // TODO: remove when context is owned
free(f.lf.start_of_tile_row as *mut c_void);
rav1d_refmvs_clear(&mut f.rf);
rav1d_free_aligned(f.lf.cdef_line_buf as *mut c_void);
Expand Down

0 comments on commit f90936b

Please sign in to comment.