Skip to content

Commit

Permalink
Rav1dFrameContext_lf::cdef_lpf_line: Make ptrs into offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
randomPoison committed Mar 4, 2024
1 parent 89acd73 commit e1c517e
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 38 deletions.
20 changes: 14 additions & 6 deletions src/cdef_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,10 @@ pub(crate) unsafe fn rav1d_cdef_brow<BD: BitDepth>(
} else if sbrow_start && by == by_start {
if resize {
offset = ((sby - 1) * 4) as isize * y_stride + (bx * 4) as isize;
top = f.lf.cdef_lpf_line[0].cast::<BD::Pixel>().offset(offset);
top = cdef_line_buf
.as_mut_ptr()
.add(f.lf.cdef_lpf_line[0])
.offset(offset);
} else {
offset = (sby * ((4 as c_int) << sb128) - 4) as isize * y_stride
+ (bx * 4) as isize;
Expand All @@ -337,7 +340,10 @@ pub(crate) unsafe fn rav1d_cdef_brow<BD: BitDepth>(
.offset(offset);
if resize {
offset = (sby * 4 + 2) as isize * y_stride + (bx * 4) as isize;
bot = f.lf.cdef_lpf_line[0].cast::<BD::Pixel>().offset(offset);
bot = cdef_line_buf
.as_mut_ptr()
.add(f.lf.cdef_lpf_line[0])
.offset(offset);
} else {
let line = sby * ((4 as c_int) << sb128) + 4 * sb128 + 2;
offset = line as isize * y_stride + (bx * 4) as isize;
Expand Down Expand Up @@ -407,8 +413,9 @@ pub(crate) unsafe fn rav1d_cdef_brow<BD: BitDepth>(
if resize {
offset = ((sby - 1) * 4) as isize * uv_stride
+ (bx * 4 >> ss_hor) as isize;
top = f.lf.cdef_lpf_line[pl]
.cast::<BD::Pixel>()
top = cdef_line_buf
.as_mut_ptr()
.add(f.lf.cdef_lpf_line[pl])
.offset(offset);
} else {
let line_0 = sby * ((4 as c_int) << sb128) - 4;
Expand All @@ -429,8 +436,9 @@ pub(crate) unsafe fn rav1d_cdef_brow<BD: BitDepth>(
if resize {
offset = (sby * 4 + 2) as isize * uv_stride
+ (bx * 4 >> ss_hor) as isize;
bot = f.lf.cdef_lpf_line[pl]
.cast::<BD::Pixel>()
bot = cdef_line_buf
.as_mut_ptr()
.add(f.lf.cdef_lpf_line[pl])
.offset(offset);
} else {
let line_1 = sby * ((4 as c_int) << sb128) + 4 * sb128 + 2;
Expand Down
21 changes: 8 additions & 13 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4424,28 +4424,23 @@ pub(crate) unsafe fn rav1d_decode_frame_init(
f.lf.cdef_line[1][2] = offset.wrapping_add_signed(uv_stride_px * 6);
}

let mut ptr =
f.lf.cdef_line_buf
.as_mut_ptr()
.add(32)
.offset(y_stride.abs() * f.sbh as isize * 4);
if need_cdef_lpf_copy != 0 {
ptr = ptr.offset(uv_stride.abs() * f.sbh as isize * 8);
offset = offset.wrapping_add_signed(uv_stride_px.abs() * f.sbh as isize * 8);
if y_stride < 0 {
f.lf.cdef_lpf_line[0] =
ptr.offset(-(y_stride * (f.sbh as isize * 4 - 1))) as *mut DynPixel;
offset.wrapping_add_signed(-(y_stride_px * (f.sbh as isize * 4 - 1)));
} else {
f.lf.cdef_lpf_line[0] = ptr as *mut DynPixel;
f.lf.cdef_lpf_line[0] = offset;
}
ptr = ptr.offset(y_stride.abs() * f.sbh as isize * 4);
offset = offset.wrapping_add_signed(y_stride_px.abs() * f.sbh as isize * 4);
if uv_stride < 0 {
f.lf.cdef_lpf_line[1] =
ptr.offset(-(uv_stride * (f.sbh as isize * 4 - 1))) as *mut DynPixel;
offset.wrapping_add_signed(-(uv_stride_px * (f.sbh as isize * 4 - 1)));
f.lf.cdef_lpf_line[2] =
ptr.offset(-(uv_stride * (f.sbh as isize * 8 - 1))) as *mut DynPixel;
offset.wrapping_add_signed(-(uv_stride_px * (f.sbh as isize * 8 - 1)));
} else {
f.lf.cdef_lpf_line[1] = ptr as *mut DynPixel;
f.lf.cdef_lpf_line[2] = ptr.offset(uv_stride * f.sbh as isize * 4) as *mut DynPixel;
f.lf.cdef_lpf_line[1] = offset;
f.lf.cdef_lpf_line[2] = offset.wrapping_add_signed(uv_stride_px * f.sbh as isize * 4);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,9 @@ pub struct Rav1dFrameContext_lf {
pub tx_lpf_right_edge: TxLpfRightEdge,
pub cdef_line_buf: AlignedVec32<u8>, /* AlignedVec32<DynPixel> */
pub lr_line_buf: *mut u8,
pub cdef_line: [[usize; 3]; 2], /* [2 pre/post][3 plane] */
pub cdef_lpf_line: [*mut DynPixel; 3], /* plane */
pub lr_lpf_line: [*mut DynPixel; 3], /* plane */
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 */

// in-loop filter per-frame state keeping
pub start_of_tile_row: *mut u8,
Expand Down
71 changes: 55 additions & 16 deletions src/lf_apply.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::include::common::bitdepth::BitDepth;
use crate::include::dav1d::headers::Rav1dFrameHeader;
use crate::include::dav1d::headers::Rav1dPixelLayout;
use crate::src::env::BlockContext;
use crate::src::internal::Rav1dContext;
Expand All @@ -21,7 +22,6 @@ use std::slice;
// stripe with the top of the next super block row.
unsafe fn backup_lpf<BD: BitDepth>(
c: &Rav1dContext,
f: &Rav1dFrameData,
mut dst: *mut BD::Pixel,
dst_stride: ptrdiff_t,
mut src: *const BD::Pixel,
Expand All @@ -34,9 +34,13 @@ unsafe fn backup_lpf<BD: BitDepth>(
h: c_int,
ss_hor: c_int,
lr_backup: c_int,
frame_hdr: &Rav1dFrameHeader,
dsp: *const Rav1dDSPContext,
resize_step: [c_int; 2],
resize_start: [c_int; 2],
bitdepth_max: c_int,
) {
let cdef_backup = (lr_backup == 0) as c_int;
let frame_hdr = &***f.frame_hdr.as_ref().unwrap();
let dst_w = if frame_hdr.size.super_res.enabled != 0 {
frame_hdr.size.width[1] + ss_hor >> ss_hor
} else {
Expand Down Expand Up @@ -108,21 +112,20 @@ unsafe fn backup_lpf<BD: BitDepth>(
}
dst = dst.offset(4 * BD::pxstride(dst_stride as usize) as isize);
}
let frame_hdr = &***f.frame_hdr.as_ref().unwrap();
if lr_backup != 0 && frame_hdr.size.width[0] != frame_hdr.size.width[1] {
while row + stripe_h <= row_h {
let n_lines = 4 - (row + stripe_h + 1 == h) as c_int;
((*f.dsp).mc.resize)(
((*dsp).mc.resize)(
dst.cast(),
dst_stride,
src.cast(),
src_stride,
dst_w,
n_lines,
src_w,
f.resize_step[ss_hor as usize],
f.resize_start[ss_hor as usize],
f.bitdepth_max,
resize_step[ss_hor as usize],
resize_start[ss_hor as usize],
bitdepth_max,
);
row += stripe_h; // unmodified stripe_h for the 1st stripe
stripe_h = 64 >> ss_ver;
Expand Down Expand Up @@ -191,6 +194,9 @@ pub(crate) unsafe fn rav1d_copy_lpf<BD: BitDepth>(
.offset(tt_off as isize * BD::pxstride(*lr_stride.offset(1) as usize) as isize),
];
let restore_planes = f.lf.restore_planes;

let cdef_line_buf = BD::cast_pixel_slice_mut(&mut f.lf.cdef_line_buf);

if seq_hdr.cdef != 0 || restore_planes & LR_RESTORE_Y as c_int != 0 {
let h = f.cur.p.h;
let w = f.bw << 2;
Expand All @@ -199,7 +205,6 @@ pub(crate) unsafe fn rav1d_copy_lpf<BD: BitDepth>(
if restore_planes & LR_RESTORE_Y as c_int != 0 || resize == 0 {
backup_lpf::<BD>(
c,
f,
dst[0],
*lr_stride.offset(0),
(*src.offset(0)).offset(
Expand All @@ -214,15 +219,22 @@ pub(crate) unsafe fn rav1d_copy_lpf<BD: BitDepth>(
h,
0,
1,
frame_hdr,
f.dsp,
f.resize_step,
f.resize_start,
f.bitdepth_max,
);
}
if have_tt != 0 && resize != 0 {
let cdef_off_y: ptrdiff_t =
(sby * 4) as isize * BD::pxstride(*src_stride.offset(0) as usize) as isize;
backup_lpf::<BD>(
c,
f,
(f.lf.cdef_lpf_line[0] as *mut BD::Pixel).offset(cdef_off_y as isize),
cdef_line_buf
.as_mut_ptr()
.add(f.lf.cdef_lpf_line[0])
.offset(cdef_off_y),
*src_stride.offset(0),
(*src.offset(0)).offset(
-offset as isize * BD::pxstride(*src_stride.offset(0) as usize) as isize,
Expand All @@ -236,6 +248,11 @@ pub(crate) unsafe fn rav1d_copy_lpf<BD: BitDepth>(
h,
0,
0,
frame_hdr,
f.dsp,
f.resize_step,
f.resize_start,
f.bitdepth_max,
);
}
}
Expand All @@ -255,7 +272,6 @@ pub(crate) unsafe fn rav1d_copy_lpf<BD: BitDepth>(
if restore_planes & LR_RESTORE_U as c_int != 0 || resize == 0 {
backup_lpf::<BD>(
c,
f,
dst[1],
*lr_stride.offset(1),
(*src.offset(1)).offset(
Expand All @@ -270,13 +286,20 @@ pub(crate) unsafe fn rav1d_copy_lpf<BD: BitDepth>(
h_0,
ss_hor,
1,
frame_hdr,
f.dsp,
f.resize_step,
f.resize_start,
f.bitdepth_max,
);
}
if have_tt != 0 && resize != 0 {
backup_lpf::<BD>(
c,
f,
(f.lf.cdef_lpf_line[1] as *mut BD::Pixel).offset(cdef_off_uv as isize),
cdef_line_buf
.as_mut_ptr()
.add(f.lf.cdef_lpf_line[1])
.offset(cdef_off_uv),
*src_stride.offset(1),
(*src.offset(1)).offset(
-offset_uv as isize * BD::pxstride(*src_stride.offset(1) as usize) as isize,
Expand All @@ -290,14 +313,18 @@ pub(crate) unsafe fn rav1d_copy_lpf<BD: BitDepth>(
h_0,
ss_hor,
0,
frame_hdr,
f.dsp,
f.resize_step,
f.resize_start,
f.bitdepth_max,
);
}
}
if seq_hdr.cdef != 0 || restore_planes & LR_RESTORE_V as c_int != 0 {
if restore_planes & LR_RESTORE_V as c_int != 0 || resize == 0 {
backup_lpf::<BD>(
c,
f,
dst[2],
*lr_stride.offset(1),
(*src.offset(2)).offset(
Expand All @@ -312,13 +339,20 @@ pub(crate) unsafe fn rav1d_copy_lpf<BD: BitDepth>(
h_0,
ss_hor,
1,
frame_hdr,
f.dsp,
f.resize_step,
f.resize_start,
f.bitdepth_max,
);
}
if have_tt != 0 && resize != 0 {
backup_lpf::<BD>(
c,
f,
(f.lf.cdef_lpf_line[2] as *mut BD::Pixel).offset(cdef_off_uv as isize),
cdef_line_buf
.as_mut_ptr()
.add(f.lf.cdef_lpf_line[2])
.offset(cdef_off_uv),
*src_stride.offset(1),
(*src.offset(2)).offset(
-offset_uv as isize * BD::pxstride(*src_stride.offset(1) as usize) as isize,
Expand All @@ -332,6 +366,11 @@ pub(crate) unsafe fn rav1d_copy_lpf<BD: BitDepth>(
h_0,
ss_hor,
0,
frame_hdr,
f.dsp,
f.resize_step,
f.resize_start,
f.bitdepth_max,
);
}
}
Expand Down

0 comments on commit e1c517e

Please sign in to comment.