diff --git a/include/dav1d/picture.rs b/include/dav1d/picture.rs index 8003d6ec5..4edc6d6d3 100644 --- a/include/dav1d/picture.rs +++ b/include/dav1d/picture.rs @@ -17,6 +17,7 @@ use crate::include::dav1d::headers::Rav1dPixelLayout; use crate::include::dav1d::headers::Rav1dSequenceHeader; use crate::src::assume::assume; use crate::src::c_arc::RawArc; +use crate::src::cursor::Cursor; use crate::src::disjoint_mut::AsMutPtr; use crate::src::disjoint_mut::DisjointImmutGuard; use crate::src::disjoint_mut::DisjointMut; @@ -29,7 +30,6 @@ use crate::src::error::Rav1dResult; use crate::src::pixels::Pixels; use crate::src::send_sync_non_null::SendSyncNonNull; use crate::src::strided::Strided; -use crate::src::with_offset::WithOffset; use libc::ptrdiff_t; use libc::uintptr_t; use std::array; @@ -351,7 +351,7 @@ impl Rav1dPictureDataComponent { } } -pub type Rav1dPictureDataComponentOffset<'a> = WithOffset<&'a Rav1dPictureDataComponent>; +pub type Rav1dPictureDataComponentOffset<'a> = Cursor<&'a Rav1dPictureDataComponent>; impl<'a> Rav1dPictureDataComponentOffset<'a> { #[inline] // Inline to see bounds checks in order to potentially elide them. diff --git a/lib.rs b/lib.rs index 3bc3ec59c..8e812c931 100644 --- a/lib.rs +++ b/lib.rs @@ -39,7 +39,7 @@ pub mod src { mod const_fn; pub mod cpu; mod ctx; - mod cursor; + pub(crate) mod cursor; mod data; mod decode; mod dequant_tables; @@ -56,7 +56,6 @@ pub mod src { pub(crate) mod relaxed_atomic; pub mod send_sync_non_null; pub(crate) mod strided; - pub(crate) mod with_offset; pub(crate) mod wrap_fn_ptr; // TODO(kkysen) Temporarily `pub(crate)` due to a `pub use` until TAIT. mod extensions; diff --git a/src/cdef.rs b/src/cdef.rs index a768431af..4592aaa06 100644 --- a/src/cdef.rs +++ b/src/cdef.rs @@ -9,12 +9,12 @@ use crate::include::common::intops::iclip; use crate::include::dav1d::picture::Rav1dPictureDataComponentOffset; use crate::src::align::AlignedVec64; use crate::src::cpu::CpuFlags; +use crate::src::cursor::Cursor; use crate::src::disjoint_mut::DisjointMut; use crate::src::ffi_safe::FFISafe; use crate::src::pic_or_buf::PicOrBuf; use crate::src::strided::Strided as _; use crate::src::tables::dav1d_cdef_directions; -use crate::src::with_offset::WithOffset; use crate::src::wrap_fn_ptr::wrap_fn_ptr; use bitflags::bitflags; use libc::ptrdiff_t; @@ -60,8 +60,8 @@ wrap_fn_ptr!(pub unsafe extern "C" fn cdef( _bottom: *const FFISafe, ) -> ()); -pub type CdefTop<'a> = WithOffset<&'a DisjointMut>>; -pub type CdefBottom<'a> = WithOffset>>; +pub type CdefTop<'a> = Cursor<&'a DisjointMut>>; +pub type CdefBottom<'a> = Cursor>>; impl cdef::Fn { /// CDEF operates entirely on pre-filter data. diff --git a/src/cdef_apply.rs b/src/cdef_apply.rs index bb9996ae5..cab98f940 100644 --- a/src/cdef_apply.rs +++ b/src/cdef_apply.rs @@ -8,6 +8,7 @@ use crate::include::dav1d::picture::Rav1dPictureDataComponentOffset; use crate::src::align::Align16; use crate::src::align::AlignedVec64; use crate::src::cdef::CdefEdgeFlags; +use crate::src::cursor::Cursor; use crate::src::disjoint_mut::DisjointMut; use crate::src::internal::Rav1dContext; use crate::src::internal::Rav1dFrameData; @@ -15,7 +16,6 @@ use crate::src::internal::Rav1dTaskContext; use crate::src::pic_or_buf::PicOrBuf; use crate::src::strided::Strided as _; use crate::src::strided::WithStride; -use crate::src::with_offset::WithOffset; use bitflags::bitflags; use libc::ptrdiff_t; use std::cmp; @@ -271,35 +271,35 @@ pub(crate) fn rav1d_cdef_brow( None } else if sbrow_start && by == by_start { let top = if resize { - WithOffset { + Cursor { data: &f.lf.cdef_line_buf, offset: f.lf.cdef_lpf_line[0], } + ((sby - 1) * 4) as isize * y_stride + (bx * 4) as isize } else { - WithOffset { + Cursor { data: &f.lf.lr_line_buf, offset: f.lf.lr_lpf_line[0], } + (sby * (4 << sb128) - 4) as isize * y_stride + (bx * 4) as isize }; let bottom = bptrs[0] + (8 * y_stride); - Some((top, WithOffset::pic(bottom))) + Some((top, Cursor::pic(bottom))) } else if !sbrow_start && by + 2 >= by_end { - let top = WithOffset { + let top = Cursor { data: &f.lf.cdef_line_buf, offset: f.lf.cdef_line[tf as usize][0], } + (sby * 4) as isize * y_stride + (bx * 4) as isize; let buf = if resize { - WithOffset { + Cursor { data: &f.lf.cdef_line_buf, offset: f.lf.cdef_lpf_line[0], } + (sby * 4 + 2) as isize * y_stride + (bx * 4) as isize } else { let line = sby * (4 << sb128) + 4 * sb128 as c_int + 2; - WithOffset { + Cursor { data: &f.lf.lr_line_buf, offset: f.lf.lr_lpf_line[0], } + line as isize * y_stride @@ -307,7 +307,7 @@ pub(crate) fn rav1d_cdef_brow( }; Some(( top, - WithOffset { + Cursor { data: PicOrBuf::Buf(WithStride { buf: buf.data, stride: y_stride, @@ -320,13 +320,13 @@ pub(crate) fn rav1d_cdef_brow( }; let (top, bot) = top_bot.unwrap_or_else(|| { - let top = WithOffset { + let top = Cursor { data: &f.lf.cdef_line_buf, offset: f.lf.cdef_line[tf as usize][0], } + have_tt as isize * (sby * 4) as isize * y_stride + (bx * 4) as isize; let bottom = bptrs[0] + (8 * y_stride); - (top, WithOffset::pic(bottom)) + (top, Cursor::pic(bottom)) }); if y_pri_lvl != 0 { @@ -373,36 +373,36 @@ pub(crate) fn rav1d_cdef_brow( None } else if sbrow_start && by == by_start { let top = if resize { - WithOffset { + Cursor { data: &f.lf.cdef_line_buf, offset: f.lf.cdef_lpf_line[pl], } + ((sby - 1) * 4) as isize * uv_stride + (bx * 4 >> ss_hor) as isize } else { let line = sby * (4 << sb128) - 4; - WithOffset { + Cursor { data: &f.lf.lr_line_buf, offset: f.lf.lr_lpf_line[pl], } + line as isize * uv_stride + (bx * 4 >> ss_hor) as isize }; let bottom = bptrs[pl] + ((8 >> ss_ver) * uv_stride); - Some((top, WithOffset::pic(bottom))) + Some((top, Cursor::pic(bottom))) } else if !sbrow_start && by + 2 >= by_end { - let top = WithOffset { + let top = Cursor { data: &f.lf.cdef_line_buf, offset: f.lf.cdef_line[tf as usize][pl], } + (sby * 8) as isize * uv_stride + (bx * 4 >> ss_hor) as isize; let buf = if resize { - WithOffset { + Cursor { data: &f.lf.cdef_line_buf, offset: f.lf.cdef_lpf_line[pl], } + (sby * 4 + 2) as isize * uv_stride + (bx * 4 >> ss_hor) as isize } else { let line = sby * (4 << sb128) + 4 * sb128 as c_int + 2; - WithOffset { + Cursor { data: &f.lf.lr_line_buf, offset: f.lf.lr_lpf_line[pl], } + line as isize * uv_stride @@ -410,7 +410,7 @@ pub(crate) fn rav1d_cdef_brow( }; Some(( top, - WithOffset { + Cursor { data: PicOrBuf::Buf(WithStride { buf: buf.data, stride: uv_stride, @@ -423,13 +423,13 @@ pub(crate) fn rav1d_cdef_brow( }; let (top, bot) = top_bot.unwrap_or_else(|| { - let top = WithOffset { + let top = Cursor { data: &f.lf.cdef_line_buf, offset: f.lf.cdef_line[tf as usize][pl], } + have_tt as isize * (sby * 8) as isize * uv_stride + (bx * 4 >> ss_hor) as isize; let bottom = bptrs[pl] + ((8 >> ss_ver) * uv_stride); - (top, WithOffset::pic(bottom)) + (top, Cursor::pic(bottom)) }); f.dsp.cdef.fb[uv_idx as usize].call::( diff --git a/src/cursor.rs b/src/cursor.rs index e60bbe097..68e1e0f8e 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -1,3 +1,6 @@ +use crate::include::common::bitdepth::BitDepth; +use crate::src::pixels::Pixels; +use crate::src::strided::Strided; use std::ops::Add; use std::ops::AddAssign; use std::ops::Index; @@ -5,77 +8,112 @@ use std::ops::IndexMut; use std::ops::Sub; use std::ops::SubAssign; -pub struct CursorMut<'a, T> { - data: &'a mut [T], - index: usize, +#[derive(Clone, Copy)] +pub struct Cursor { + pub data: T, + pub offset: usize, } +pub type CursorMut<'a, T> = Cursor<&'a mut [T]>; + impl<'a, T> CursorMut<'a, T> { pub fn new(data: &'a mut [T]) -> Self { - CursorMut { data, index: 0 } - } - - pub fn as_slice(&self) -> &[T] { - &self.data[self.index..] + Cursor { data, offset: 0 } } - pub fn as_mut_slice(&mut self) -> &mut [T] { - &mut self.data[self.index..] + pub fn clone(&mut self) -> Cursor<&mut [T]> { + Cursor { + data: self.data, + offset: self.offset, + } } +} - #[allow(dead_code)] // TODO(kkysen) remove once used - pub fn as_ptr(&self) -> *const T { - self.as_slice().as_ptr() +impl AddAssign for Cursor { + #[cfg_attr(debug_assertions, track_caller)] + fn add_assign(&mut self, rhs: usize) { + self.offset += rhs; } +} - #[allow(dead_code)] // TODO(kkysen) remove once used - pub fn as_mut_ptr(&mut self) -> *mut T { - self.as_mut_slice().as_mut_ptr() +impl SubAssign for Cursor { + #[cfg_attr(debug_assertions, track_caller)] + fn sub_assign(&mut self, rhs: usize) { + self.offset -= rhs; } +} - pub fn clone(&mut self) -> CursorMut<'_, T> { - CursorMut { - data: self.data, - index: self.index, - } +impl AddAssign for Cursor { + #[cfg_attr(debug_assertions, track_caller)] + fn add_assign(&mut self, rhs: isize) { + self.offset = self.offset.wrapping_add_signed(rhs); } } -impl<'a, T> From<&'a mut [T]> for CursorMut<'a, T> { - fn from(value: &'a mut [T]) -> Self { - CursorMut::new(value) +impl SubAssign for Cursor { + #[cfg_attr(debug_assertions, track_caller)] + fn sub_assign(&mut self, rhs: isize) { + self.offset = self.offset.wrapping_add_signed(-rhs); } } -impl<'a, T> Add for CursorMut<'a, T> { +impl Add for Cursor { type Output = Self; + #[cfg_attr(debug_assertions, track_caller)] fn add(mut self, rhs: usize) -> Self::Output { self += rhs; self } } -impl<'a, T> AddAssign for CursorMut<'a, T> { - fn add_assign(&mut self, rhs: usize) { - self.index += rhs; - debug_assert!(self.index <= self.data.len()); +impl Sub for Cursor { + type Output = Self; + + #[cfg_attr(debug_assertions, track_caller)] + fn sub(mut self, rhs: usize) -> Self::Output { + self -= rhs; + self } } -impl<'a, T> Sub for CursorMut<'a, T> { +impl Add for Cursor { type Output = Self; - fn sub(mut self, rhs: usize) -> Self::Output { + #[cfg_attr(debug_assertions, track_caller)] + fn add(mut self, rhs: isize) -> Self::Output { + self += rhs; + self + } +} + +impl Sub for Cursor { + type Output = Self; + + #[cfg_attr(debug_assertions, track_caller)] + fn sub(mut self, rhs: isize) -> Self::Output { self -= rhs; self } } -impl<'a, T> SubAssign for CursorMut<'a, T> { - fn sub_assign(&mut self, rhs: usize) { - debug_assert!(rhs <= self.index); - self.index -= rhs; +impl Cursor

{ + #[inline] // Inline to see bounds checks in order to potentially elide them. + #[cfg_attr(debug_assertions, track_caller)] + pub fn as_ptr(&self) -> *const BD::Pixel { + self.data.as_ptr_at::(self.offset) + } + + #[inline] // Inline to see bounds checks in order to potentially elide them. + #[cfg_attr(debug_assertions, track_caller)] + pub fn as_mut_ptr(&self) -> *mut BD::Pixel { + self.data.as_mut_ptr_at::(self.offset) + } +} + +impl Strided for Cursor { + fn stride(&self) -> isize { + self.data.stride() } } @@ -83,13 +121,13 @@ impl<'a, T> Index for CursorMut<'a, T> { type Output = T; fn index(&self, index: usize) -> &Self::Output { - &self.data[self.index + index] + &self.data[self.offset + index] } } impl<'a, T> IndexMut for CursorMut<'a, T> { fn index_mut(&mut self, index: usize) -> &mut Self::Output { - &mut self.data[self.index + index] + &mut self.data[self.offset + index] } } @@ -97,7 +135,7 @@ impl<'a, T> Index for CursorMut<'a, T> { type Output = T; fn index(&self, index: isize) -> &Self::Output { - let index = self.index as isize + index; + let index = self.offset as isize + index; debug_assert!(index >= 0); &self.data[index as usize] } @@ -105,7 +143,7 @@ impl<'a, T> Index for CursorMut<'a, T> { impl<'a, T> IndexMut for CursorMut<'a, T> { fn index_mut(&mut self, index: isize) -> &mut Self::Output { - let index = self.index as isize + index; + let index = self.offset as isize + index; debug_assert!(index >= 0); &mut self.data[index as usize] } diff --git a/src/lf_apply.rs b/src/lf_apply.rs index 481ad94eb..9e6478552 100644 --- a/src/lf_apply.rs +++ b/src/lf_apply.rs @@ -5,6 +5,7 @@ use crate::include::dav1d::headers::Rav1dFrameHeader; use crate::include::dav1d::headers::Rav1dPixelLayout; use crate::include::dav1d::picture::Rav1dPictureDataComponentOffset; use crate::src::align::AlignedVec64; +use crate::src::cursor::Cursor; use crate::src::disjoint_mut::DisjointMut; use crate::src::internal::Rav1dBitDepthDSPContext; use crate::src::internal::Rav1dContext; @@ -13,7 +14,6 @@ use crate::src::lr_apply::LrRestorePlanes; use crate::src::relaxed_atomic::RelaxedAtomic; use crate::src::strided::Strided as _; use crate::src::strided::WithStride; -use crate::src::with_offset::WithOffset; use std::array; use std::cmp; use std::ffi::c_int; @@ -26,7 +26,7 @@ use std::ffi::c_uint; /// the last stripe with the top of the next super block row. fn backup_lpf( c: &Rav1dContext, - mut dst: WithOffset>>>, + mut dst: Cursor>>>, mut src: Rav1dPictureDataComponentOffset, ss_ver: c_int, sb128: u8, @@ -85,7 +85,7 @@ fn backup_lpf( while row + stripe_h <= row_h { let n_lines = 4 - (row + stripe_h + 1 == h) as c_int; dsp.mc.resize.call::( - WithOffset::buf(dst), + Cursor::buf(dst), src, dst_w, n_lines as usize, @@ -180,7 +180,7 @@ pub(crate) fn rav1d_copy_lpf( if restore_planes.contains(LrRestorePlanes::Y) || resize == 0 { backup_lpf::( c, - WithOffset { + Cursor { data: WithStride { buf: &f.lf.lr_line_buf, stride: dst[0].stride(), @@ -210,7 +210,7 @@ pub(crate) fn rav1d_copy_lpf( let cdef_line_start = (f.lf.cdef_lpf_line[0] as isize + cmp::min(y_span, 0)) as usize; backup_lpf::( c, - WithOffset { + Cursor { data: WithStride { buf: &f.lf.cdef_line_buf, stride: src[0].stride(), @@ -249,7 +249,7 @@ pub(crate) fn rav1d_copy_lpf( if restore_planes.contains(LrRestorePlanes::U) || resize == 0 { backup_lpf::( c, - WithOffset { + Cursor { data: WithStride { buf: &f.lf.lr_line_buf, stride: dst[1].stride(), @@ -279,7 +279,7 @@ pub(crate) fn rav1d_copy_lpf( (f.lf.cdef_lpf_line[1] as isize + cmp::min(uv_span, 0)) as usize; backup_lpf::( c, - WithOffset { + Cursor { data: WithStride { buf: &f.lf.cdef_line_buf, stride: src[1].stride(), @@ -307,7 +307,7 @@ pub(crate) fn rav1d_copy_lpf( if restore_planes.contains(LrRestorePlanes::V) || resize == 0 { backup_lpf::( c, - WithOffset { + Cursor { data: WithStride { buf: &f.lf.lr_line_buf, stride: dst[2].stride(), @@ -337,7 +337,7 @@ pub(crate) fn rav1d_copy_lpf( (f.lf.cdef_lpf_line[2] as isize + cmp::min(uv_span, 0)) as usize; backup_lpf::( c, - WithOffset { + Cursor { data: WithStride { buf: &f.lf.cdef_line_buf, stride: src[2].stride(), @@ -368,7 +368,7 @@ pub(crate) fn rav1d_copy_lpf( fn filter_plane_cols_y( f: &Rav1dFrameData, have_left: bool, - lvl: WithOffset<&DisjointMut>>, + lvl: Cursor<&DisjointMut>>, mask: &[[[RelaxedAtomic; 2]; 3]; 32], y_dst: Rav1dPictureDataComponentOffset, w: usize, @@ -405,7 +405,7 @@ fn filter_plane_cols_y( fn filter_plane_rows_y( f: &Rav1dFrameData, have_top: bool, - lvl: WithOffset<&DisjointMut>>, + lvl: Cursor<&DisjointMut>>, b4_stride: usize, mask: &[[[RelaxedAtomic; 2]; 3]; 32], y_dst: Rav1dPictureDataComponentOffset, @@ -437,7 +437,7 @@ fn filter_plane_rows_y( fn filter_plane_cols_uv( f: &Rav1dFrameData, have_left: bool, - lvl: WithOffset<&DisjointMut>>, + lvl: Cursor<&DisjointMut>>, mask: &[[[RelaxedAtomic; 2]; 2]; 32], u_dst: Rav1dPictureDataComponentOffset, v_dst: Rav1dPictureDataComponentOffset, @@ -480,7 +480,7 @@ fn filter_plane_cols_uv( fn filter_plane_rows_uv( f: &Rav1dFrameData, have_top: bool, - lvl: WithOffset<&DisjointMut>>, + lvl: Cursor<&DisjointMut>>, b4_stride: usize, mask: &[[[RelaxedAtomic; 2]; 2]; 32], u_dst: Rav1dPictureDataComponentOffset, @@ -622,7 +622,7 @@ pub(crate) fn rav1d_loopfilter_sbrow_cols( } } let lflvl = &f.lf.mask[lflvl_offset..]; - let lvl = WithOffset { + let lvl = Cursor { data: &f.lf.level, offset: 4 * f.b4_stride as usize * (sby * sbsz) as usize, }; @@ -643,7 +643,7 @@ pub(crate) fn rav1d_loopfilter_sbrow_cols( if frame_hdr.loopfilter.level_u == 0 && frame_hdr.loopfilter.level_v == 0 { return; } - let lvl = WithOffset { + let lvl = Cursor { data: &f.lf.level, offset: 4 * f.b4_stride as usize * (sby * sbsz >> ss_ver) as usize, }; @@ -684,7 +684,7 @@ pub(crate) fn rav1d_loopfilter_sbrow_rows( let endy4: c_uint = (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 lvl = WithOffset { + let lvl = Cursor { data: &f.lf.level, offset: 4 * f.b4_stride as usize * (sby * sbsz) as usize, }; @@ -707,7 +707,7 @@ pub(crate) fn rav1d_loopfilter_sbrow_rows( return; } - let lvl = WithOffset { + let lvl = Cursor { data: &f.lf.level, offset: 4 * f.b4_stride as usize * (sby * sbsz >> ss_ver) as usize, }; diff --git a/src/loopfilter.rs b/src/loopfilter.rs index c7303e14e..c80eb794e 100644 --- a/src/loopfilter.rs +++ b/src/loopfilter.rs @@ -7,12 +7,12 @@ use crate::include::common::intops::iclip; use crate::include::dav1d::picture::Rav1dPictureDataComponentOffset; use crate::src::align::Align16; use crate::src::cpu::CpuFlags; +use crate::src::cursor::Cursor; use crate::src::disjoint_mut::DisjointMut; use crate::src::ffi_safe::FFISafe; use crate::src::internal::Rav1dFrameData; use crate::src::lf_mask::Av1FilterLUT; use crate::src::strided::Strided as _; -use crate::src::with_offset::WithOffset; use crate::src::wrap_fn_ptr::wrap_fn_ptr; use libc::ptrdiff_t; use std::cmp; @@ -35,7 +35,7 @@ wrap_fn_ptr!(pub unsafe extern "C" fn loopfilter_sb( w: c_int, bitdepth_max: c_int, _dst: *const FFISafe, - _lvl: *const FFISafe>>>, + _lvl: *const FFISafe>>>, ) -> ()); impl loopfilter_sb::Fn { @@ -44,7 +44,7 @@ impl loopfilter_sb::Fn { f: &Rav1dFrameData, dst: Rav1dPictureDataComponentOffset, mask: &[u32; 3], - lvl: WithOffset<&DisjointMut>>, + lvl: Cursor<&DisjointMut>>, w: usize, ) { let dst_ptr = dst.as_mut_ptr::().cast(); @@ -290,7 +290,7 @@ enum YUV { fn loop_filter_sb128_rust( mut dst: Rav1dPictureDataComponentOffset, vmask: &[u32; 3], - mut lvl: WithOffset<&DisjointMut>>, + mut lvl: Cursor<&DisjointMut>>, b4_stride: usize, lut: &Align16, _wh: c_int, @@ -368,7 +368,7 @@ unsafe extern "C" fn loop_filter_sb128_c_erased, - lvl: *const FFISafe>>>, + lvl: *const FFISafe>>>, ) { // SAFETY: Was passed as `FFISafe::new(_)` in `loopfilter_sb::Fn::call`. let dst = *unsafe { FFISafe::get(dst) }; diff --git a/src/looprestoration.rs b/src/looprestoration.rs index 0af78ba16..e2b22b23e 100644 --- a/src/looprestoration.rs +++ b/src/looprestoration.rs @@ -669,8 +669,9 @@ fn selfguided_filter( } let bitdepth_min_8 = bd.bitdepth() - 8; - let mut a = CursorMut::new(&mut sumsq) + 2 * REST_UNIT_STRIDE + 3; - let mut b = CursorMut::new(&mut sum) + 2 * REST_UNIT_STRIDE + 3; + let mut a: CursorMut = CursorMut::new(&mut sumsq) + 2 * REST_UNIT_STRIDE + 3usize; + let mut b: CursorMut<::Coef> = + CursorMut::new(&mut sum) + 2 * REST_UNIT_STRIDE + 3usize; let mut aa = a.clone() - REST_UNIT_STRIDE; let mut bb = b.clone() - REST_UNIT_STRIDE; diff --git a/src/mc.rs b/src/mc.rs index e3702b28c..b8f95d1c3 100644 --- a/src/mc.rs +++ b/src/mc.rs @@ -11,6 +11,7 @@ use crate::include::dav1d::picture::Rav1dPictureDataComponent; use crate::include::dav1d::picture::Rav1dPictureDataComponentOffset; use crate::src::align::AlignedVec64; use crate::src::cpu::CpuFlags; +use crate::src::cursor::Cursor; use crate::src::enum_map::enum_map; use crate::src::enum_map::enum_map_ty; use crate::src::enum_map::DefaultValue; @@ -27,7 +28,6 @@ use crate::src::tables::dav1d_mc_subpel_filters; use crate::src::tables::dav1d_mc_warp_filter; use crate::src::tables::dav1d_obmc_masks; use crate::src::tables::dav1d_resize_filter; -use crate::src::with_offset::WithOffset; use crate::src::wrap_fn_ptr::wrap_fn_ptr; use std::cmp; use std::ffi::c_int; @@ -997,7 +997,7 @@ fn emu_edge_rust( } fn resize_rust( - dst: WithOffset>>, + dst: Cursor>>, src: Rav1dPictureDataComponentOffset, dst_w: usize, h: usize, @@ -1506,13 +1506,13 @@ wrap_fn_ptr!(pub unsafe extern "C" fn resize( mx: i32, bitdepth_max: i32, _src: *const FFISafe, - _dst: *const FFISafe>>>, + _dst: *const FFISafe>>>, ) -> ()); impl resize::Fn { pub fn call( &self, - dst: WithOffset>>, + dst: Cursor>>, src: Rav1dPictureDataComponentOffset, dst_w: usize, h: usize, @@ -1943,7 +1943,7 @@ unsafe extern "C" fn resize_c_erased( mx0: i32, bitdepth_max: i32, src: *const FFISafe, - dst: *const FFISafe>>>, + dst: *const FFISafe>>>, ) { // SAFETY: Was passed as `FFISafe::new(_)` in `resize::Fn::call`. let dst = *unsafe { FFISafe::get(dst) }; diff --git a/src/pic_or_buf.rs b/src/pic_or_buf.rs index a27923cf1..521f4161f 100644 --- a/src/pic_or_buf.rs +++ b/src/pic_or_buf.rs @@ -1,10 +1,10 @@ use crate::include::dav1d::picture::Rav1dPictureDataComponent; +use crate::src::cursor::Cursor; use crate::src::disjoint_mut::AsMutPtr; use crate::src::disjoint_mut::DisjointMut; use crate::src::pixels::Pixels; use crate::src::strided::Strided; use crate::src::strided::WithStride; -use crate::src::with_offset::WithOffset; pub enum PicOrBuf<'a, T: AsMutPtr> { Pic(&'a Rav1dPictureDataComponent), @@ -45,15 +45,15 @@ impl<'a, T: AsMutPtr> Strided for PicOrBuf<'a, T> { } } -impl<'a, T: AsMutPtr> WithOffset> { - pub fn pic(pic: WithOffset<&'a Rav1dPictureDataComponent>) -> Self { +impl<'a, T: AsMutPtr> Cursor> { + pub fn pic(pic: Cursor<&'a Rav1dPictureDataComponent>) -> Self { Self { data: PicOrBuf::Pic(pic.data), offset: pic.offset, } } - pub fn buf(buf: WithOffset>>) -> Self { + pub fn buf(buf: Cursor>>) -> Self { Self { data: PicOrBuf::Buf(buf.data), offset: buf.offset, diff --git a/src/recon.rs b/src/recon.rs index 8833022c9..e989fb816 100644 --- a/src/recon.rs +++ b/src/recon.rs @@ -21,6 +21,7 @@ use crate::include::dav1d::picture::Rav1dPictureDataComponentOffset; use crate::src::assume::assume; use crate::src::cdef_apply::rav1d_cdef_brow; use crate::src::ctx::CaseSet; +use crate::src::cursor::Cursor; use crate::src::env::get_uv_inter_txtp; use crate::src::in_range::InRange; use crate::src::internal::Bxy; @@ -88,7 +89,6 @@ use crate::src::tables::dav1d_txtp_from_uvmode; use crate::src::tables::TxfmInfo; use crate::src::wedge::dav1d_ii_masks; use crate::src::wedge::dav1d_wedge_masks; -use crate::src::with_offset::WithOffset; use assert_matches::debug_assert_matches; use libc::intptr_t; use std::array; @@ -3744,7 +3744,7 @@ pub(crate) fn rav1d_filter_sbrow_resize( let img_h = f.cur.p.h - sbsz * 4 * sby + ss_ver >> ss_ver; f.dsp.mc.resize.call::( - WithOffset::pic(dst), + Cursor::pic(dst), src, dst_w as usize, (cmp::min(img_h, h_end) + h_start) as usize, diff --git a/src/with_offset.rs b/src/with_offset.rs deleted file mode 100644 index 1aa76f388..000000000 --- a/src/with_offset.rs +++ /dev/null @@ -1,101 +0,0 @@ -use crate::include::common::bitdepth::BitDepth; -use crate::src::pixels::Pixels; -use crate::src::strided::Strided; -use std::ops::Add; -use std::ops::AddAssign; -use std::ops::Sub; -use std::ops::SubAssign; - -#[derive(Clone, Copy)] -pub struct WithOffset { - pub data: T, - pub offset: usize, -} - -impl AddAssign for WithOffset { - #[cfg_attr(debug_assertions, track_caller)] - fn add_assign(&mut self, rhs: usize) { - self.offset += rhs; - } -} - -impl SubAssign for WithOffset { - #[cfg_attr(debug_assertions, track_caller)] - fn sub_assign(&mut self, rhs: usize) { - self.offset -= rhs; - } -} - -impl AddAssign for WithOffset { - #[cfg_attr(debug_assertions, track_caller)] - fn add_assign(&mut self, rhs: isize) { - self.offset = self.offset.wrapping_add_signed(rhs); - } -} - -impl SubAssign for WithOffset { - #[cfg_attr(debug_assertions, track_caller)] - fn sub_assign(&mut self, rhs: isize) { - self.offset = self.offset.wrapping_add_signed(-rhs); - } -} - -impl Add for WithOffset { - type Output = Self; - - #[cfg_attr(debug_assertions, track_caller)] - fn add(mut self, rhs: usize) -> Self::Output { - self += rhs; - self - } -} - -impl Sub for WithOffset { - type Output = Self; - - #[cfg_attr(debug_assertions, track_caller)] - fn sub(mut self, rhs: usize) -> Self::Output { - self -= rhs; - self - } -} - -impl Add for WithOffset { - type Output = Self; - - #[cfg_attr(debug_assertions, track_caller)] - fn add(mut self, rhs: isize) -> Self::Output { - self += rhs; - self - } -} - -impl Sub for WithOffset { - type Output = Self; - - #[cfg_attr(debug_assertions, track_caller)] - fn sub(mut self, rhs: isize) -> Self::Output { - self -= rhs; - self - } -} - -impl WithOffset

{ - #[inline] // Inline to see bounds checks in order to potentially elide them. - #[cfg_attr(debug_assertions, track_caller)] - pub fn as_ptr(&self) -> *const BD::Pixel { - self.data.as_ptr_at::(self.offset) - } - - #[inline] // Inline to see bounds checks in order to potentially elide them. - #[cfg_attr(debug_assertions, track_caller)] - pub fn as_mut_ptr(&self) -> *mut BD::Pixel { - self.data.as_mut_ptr_at::(self.offset) - } -} - -impl Strided for WithOffset { - fn stride(&self) -> isize { - self.data.stride() - } -}