From 7e4c7149ab99794157190f04d99e899d9af54627 Mon Sep 17 00:00:00 2001 From: Nicole LeGare Date: Thu, 21 Mar 2024 14:05:25 -0700 Subject: [PATCH] `Rav1dTileState::lflvl`: Make into enum Rename `TileStateDq` to `TileStateRef` and use it for both fields, since both have the same structure of either referencing a field in the frame data or referencing the local tile state field. --- src/decode.rs | 22 +++++++++++++++------- src/internal.rs | 6 +++--- src/recon.rs | 6 +++--- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/decode.rs b/src/decode.rs index 403306dd3..0b6618373 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -70,7 +70,7 @@ use crate::src::internal::Rav1dTaskContext; use crate::src::internal::Rav1dTaskContext_scratch_pal; use crate::src::internal::Rav1dTileState; use crate::src::internal::ScalableMotionParams; -use crate::src::internal::TileStateDq; +use crate::src::internal::TileStateRef; use crate::src::intra_edge::EdgeFlags; use crate::src::intra_edge::EdgeIndex; use crate::src::intra_edge::IntraEdges; @@ -1867,19 +1867,19 @@ unsafe fn decode_b_inner( } if ts.last_qidx == frame_hdr.quant.yac { // assign frame-wide q values to this sb - ts.dq = TileStateDq::Frame; + ts.dq = TileStateRef::Frame; } else if ts.last_qidx != prev_qidx { // find sb-specific quant parameters init_quant_tables(seq_hdr, frame_hdr, ts.last_qidx, &mut ts.dqmem); - ts.dq = TileStateDq::Local; + ts.dq = TileStateRef::Local; } if ts.last_delta_lf == [0, 0, 0, 0] { // assign frame-wide lf values to this sb - ts.lflvl = f.lf.lvl.as_ptr(); + ts.lflvl = TileStateRef::Frame; } else if ts.last_delta_lf != prev_delta_lf { // find sb-specific lf lvl parameters rav1d_calc_lf_values(&mut ts.lflvlmem, frame_hdr, &ts.last_delta_lf); - ts.lflvl = ts.lflvlmem.as_ptr(); + ts.lflvl = TileStateRef::Local; } } @@ -2154,11 +2154,15 @@ unsafe fn decode_b_inner( } if f.frame_hdr().loopfilter.level_y != [0, 0] { + let lflvl = match ts.lflvl { + TileStateRef::Frame => &f.lf.lvl, + TileStateRef::Local => &ts.lflvlmem, + }; rav1d_create_lf_mask_intra( &mut *t.lf_mask, &mut f.lf.level, f.b4_stride, - &*ts.lflvl.offset(b.seg_id as isize), + &lflvl[b.seg_id as usize], t.bx, t.by, f.w4, @@ -3152,6 +3156,10 @@ unsafe fn decode_b_inner( ytx = TX_4X4 as RectTxfmSize; uvtx = TX_4X4 as RectTxfmSize; } + let lflvl = match ts.lflvl { + TileStateRef::Frame => &f.lf.lvl, + TileStateRef::Local => &ts.lflvlmem, + }; rav1d_create_lf_mask_inter( &mut *t.lf_mask, &mut f.lf.level, @@ -3161,7 +3169,7 @@ unsafe fn decode_b_inner( // even though the whole array is not passed. // Dereferencing this in Rust is UB, so instead // we pass the indices as args, which are then applied at the use sites. - &*ts.lflvl.offset(b.seg_id as isize), + &lflvl[b.seg_id as usize], (b.r#ref()[0] + 1) as usize, is_globalmv == 0, t.bx, diff --git a/src/internal.rs b/src/internal.rs index 50d40f3e9..2f1b80a36 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -644,17 +644,17 @@ pub struct Rav1dTileState { pub lowest_pixel: *mut [[c_int; 2]; 7], pub dqmem: [[[u16; 2]; 3]; RAV1D_MAX_SEGMENTS as usize], /* [RAV1D_MAX_SEGMENTS][3 plane][2 dc/ac] */ - pub dq: TileStateDq, + pub dq: TileStateRef, pub last_qidx: c_int, pub last_delta_lf: [i8; 4], pub lflvlmem: [[[[u8; 2]; 8]; 4]; 8], /* [8 seg_id][4 dir][8 ref][2 is_gmv] */ - pub lflvl: *const [[[u8; 2]; 8]; 4], + pub lflvl: TileStateRef, pub lr_ref: [Av1RestorationUnit; 3], } #[derive(Clone, Copy)] -pub enum TileStateDq { +pub enum TileStateRef { Frame, Local, } diff --git a/src/recon.rs b/src/recon.rs index 3ab61100c..e26d14e9a 100644 --- a/src/recon.rs +++ b/src/recon.rs @@ -20,7 +20,7 @@ use crate::src::internal::Rav1dDSPContext; use crate::src::internal::Rav1dFrameData; use crate::src::internal::Rav1dTaskContext; use crate::src::internal::Rav1dTileState; -use crate::src::internal::TileStateDq; +use crate::src::internal::TileStateRef; use crate::src::intra_edge::EdgeFlags; use crate::src::ipred_prepare::rav1d_prepare_intra_edges; use crate::src::ipred_prepare::sm_flag; @@ -1380,8 +1380,8 @@ unsafe fn decode_coefs( rc = 0 as c_int as c_uint; } let dq = match (*ts).dq { - TileStateDq::Frame => &f.dq, - TileStateDq::Local => &(*ts).dqmem, + TileStateRef::Frame => &f.dq, + TileStateRef::Local => &(*ts).dqmem, }; let dq_tbl = &dq[b.seg_id as usize][plane as usize]; let qm_tbl: *const u8 = if (*txtp as c_uint) < IDTX as c_int as c_uint {