From 325b0dd514b5a7ea3a355194d170a0d041cc93a9 Mon Sep 17 00:00:00 2001 From: Nicole LeGare Date: Fri, 1 Mar 2024 15:34:26 -0800 Subject: [PATCH] `Rav1dFrameContext_lf::cdef_lpf_line`: Make ptrs into offsets --- src/cdef_apply.rs | 20 +++++++++---- src/decode.rs | 21 ++++++-------- src/internal.rs | 6 ++-- src/lf_apply.rs | 71 ++++++++++++++++++++++++++++++++++++----------- 4 files changed, 80 insertions(+), 38 deletions(-) diff --git a/src/cdef_apply.rs b/src/cdef_apply.rs index 9b197d422..ac0293abf 100644 --- a/src/cdef_apply.rs +++ b/src/cdef_apply.rs @@ -321,7 +321,10 @@ pub(crate) unsafe fn rav1d_cdef_brow( } 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::().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; @@ -337,7 +340,10 @@ pub(crate) unsafe fn rav1d_cdef_brow( .offset(offset); if resize { offset = (sby * 4 + 2) as isize * y_stride + (bx * 4) as isize; - bot = f.lf.cdef_lpf_line[0].cast::().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; @@ -407,8 +413,9 @@ pub(crate) unsafe fn rav1d_cdef_brow( if resize { offset = ((sby - 1) * 4) as isize * uv_stride + (bx * 4 >> ss_hor) as isize; - top = f.lf.cdef_lpf_line[pl] - .cast::() + 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; @@ -429,8 +436,9 @@ pub(crate) unsafe fn rav1d_cdef_brow( if resize { offset = (sby * 4 + 2) as isize * uv_stride + (bx * 4 >> ss_hor) as isize; - bot = f.lf.cdef_lpf_line[pl] - .cast::() + 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; diff --git a/src/decode.rs b/src/decode.rs index 0c5fa9525..1720633d6 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -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); } } diff --git a/src/internal.rs b/src/internal.rs index 837567b6b..5fcdccb1b 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -462,9 +462,9 @@ pub struct Rav1dFrameContext_lf { pub tx_lpf_right_edge: TxLpfRightEdge, pub cdef_line_buf: AlignedVec32, /* AlignedVec32 */ 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, diff --git a/src/lf_apply.rs b/src/lf_apply.rs index 46aa74865..d73475d32 100644 --- a/src/lf_apply.rs +++ b/src/lf_apply.rs @@ -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; @@ -21,7 +22,6 @@ use std::slice; // stripe with the top of the next super block row. unsafe fn backup_lpf( c: &Rav1dContext, - f: &Rav1dFrameData, mut dst: *mut BD::Pixel, dst_stride: ptrdiff_t, mut src: *const BD::Pixel, @@ -34,9 +34,13 @@ unsafe fn backup_lpf( 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 { @@ -108,11 +112,10 @@ unsafe fn backup_lpf( } 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(), @@ -120,9 +123,9 @@ unsafe fn backup_lpf( 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; @@ -191,6 +194,9 @@ pub(crate) unsafe fn rav1d_copy_lpf( .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; @@ -199,7 +205,6 @@ pub(crate) unsafe fn rav1d_copy_lpf( if restore_planes & LR_RESTORE_Y as c_int != 0 || resize == 0 { backup_lpf::( c, - f, dst[0], *lr_stride.offset(0), (*src.offset(0)).offset( @@ -214,6 +219,11 @@ pub(crate) unsafe fn rav1d_copy_lpf( h, 0, 1, + frame_hdr, + f.dsp, + f.resize_step, + f.resize_start, + f.bitdepth_max, ); } if have_tt != 0 && resize != 0 { @@ -221,8 +231,10 @@ pub(crate) unsafe fn rav1d_copy_lpf( (sby * 4) as isize * BD::pxstride(*src_stride.offset(0) as usize) as isize; backup_lpf::( 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, @@ -236,6 +248,11 @@ pub(crate) unsafe fn rav1d_copy_lpf( h, 0, 0, + frame_hdr, + f.dsp, + f.resize_step, + f.resize_start, + f.bitdepth_max, ); } } @@ -255,7 +272,6 @@ pub(crate) unsafe fn rav1d_copy_lpf( if restore_planes & LR_RESTORE_U as c_int != 0 || resize == 0 { backup_lpf::( c, - f, dst[1], *lr_stride.offset(1), (*src.offset(1)).offset( @@ -270,13 +286,20 @@ pub(crate) unsafe fn rav1d_copy_lpf( 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::( 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, @@ -290,6 +313,11 @@ pub(crate) unsafe fn rav1d_copy_lpf( h_0, ss_hor, 0, + frame_hdr, + f.dsp, + f.resize_step, + f.resize_start, + f.bitdepth_max, ); } } @@ -297,7 +325,6 @@ pub(crate) unsafe fn rav1d_copy_lpf( if restore_planes & LR_RESTORE_V as c_int != 0 || resize == 0 { backup_lpf::( c, - f, dst[2], *lr_stride.offset(1), (*src.offset(2)).offset( @@ -312,13 +339,20 @@ pub(crate) unsafe fn rav1d_copy_lpf( 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::( 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, @@ -332,6 +366,11 @@ pub(crate) unsafe fn rav1d_copy_lpf( h_0, ss_hor, 0, + frame_hdr, + f.dsp, + f.resize_step, + f.resize_start, + f.bitdepth_max, ); } }