From 8d38199446c25c6ecd5f325d014489f9039bc0e1 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Mar 2024 19:32:27 +0100 Subject: [PATCH 1/2] `enum InterPredMode` and `enum CompInterPredMode`: make real enums --- src/decode.rs | 79 ++++++++++++++++++++++++++++----------------------- src/levels.rs | 50 ++++++++++++++++++++------------ src/recon.rs | 53 ++++++++++++++++++++++++++++++++-- src/tables.rs | 19 ++++--------- 4 files changed, 132 insertions(+), 69 deletions(-) diff --git a/src/decode.rs b/src/decode.rs index afb853c64..6fedc0ecb 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -79,11 +79,13 @@ use crate::src::levels::Av1Block; use crate::src::levels::BlockLevel; use crate::src::levels::BlockPartition; use crate::src::levels::BlockSize; +use crate::src::levels::CompInterPredMode; use crate::src::levels::CompInterType; use crate::src::levels::DrlProximity; use crate::src::levels::Filter2d; use crate::src::levels::InterIntraPredMode; use crate::src::levels::InterIntraType; +use crate::src::levels::InterPredMode; use crate::src::levels::MVJoint; use crate::src::levels::MotionMode; use crate::src::levels::RectTxfmSize; @@ -91,13 +93,6 @@ use crate::src::levels::TxfmSize; use crate::src::levels::CFL_PRED; use crate::src::levels::DC_PRED; use crate::src::levels::FILTER_PRED; -use crate::src::levels::GLOBALMV; -use crate::src::levels::GLOBALMV_GLOBALMV; -use crate::src::levels::NEARESTMV; -use crate::src::levels::NEARESTMV_NEARESTMV; -use crate::src::levels::NEARMV; -use crate::src::levels::NEWMV; -use crate::src::levels::NEWMV_NEWMV; use crate::src::levels::N_COMP_INTER_PRED_MODES; use crate::src::levels::N_INTRA_PRED_MODES; use crate::src::levels::N_RECT_TX_SIZES; @@ -910,7 +905,8 @@ unsafe fn splat_oneref_mv( ], }, bs, - mf: (mode == GLOBALMV && cmp::min(bw4, bh4) >= 2) as u8 | (mode == NEWMV) as u8 * 2, + mf: (mode == InterPredMode::GLOBALMV.into() && cmp::min(bw4, bh4) >= 2) as u8 + | (mode == InterPredMode::NEWMV.into()) as u8 * 2, })); c.refmvs_dsp.splat_mv( &mut t.rt.r[((t.b.y & 31) + 5) as usize..], @@ -964,7 +960,8 @@ unsafe fn splat_tworef_mv( r#ref: [b.r#ref()[0] + 1, b.r#ref()[1] + 1], }, bs, - mf: (mode == GLOBALMV_GLOBALMV) as u8 | (1 << mode & 0xbc != 0) as u8 * 2, + mf: (mode == CompInterPredMode::GLOBALMV_GLOBALMV) as u8 + | (1 << mode as u8 & 0xbc != 0) as u8 * 2, })); c.refmvs_dsp.splat_mv( &mut t.rt.r[((t.b.y & 31) + 5) as usize..], @@ -2164,7 +2161,7 @@ unsafe fn decode_b_inner( frame_hdr.skip_mode.refs[1] as i8, ]; *b.comp_type_mut() = Some(CompInterType::Avg); - *b.inter_mode_mut() = NEARESTMV_NEARESTMV; + *b.inter_mode_mut() = CompInterPredMode::NEARESTMV_NEARESTMV; *b.drl_idx_mut() = DrlProximity::Nearest; has_subpel_filter = false; @@ -2290,14 +2287,15 @@ unsafe fn decode_b_inner( frame_hdr, ); - *b.inter_mode_mut() = rav1d_msac_decode_symbol_adapt8( + *b.inter_mode_mut() = CompInterPredMode::from_repr(rav1d_msac_decode_symbol_adapt8( &mut ts.msac, &mut ts.cdf.m.comp_inter_mode[ctx as usize], N_COMP_INTER_PRED_MODES as usize - 1, - ) as u8; + ) as usize) + .expect("valid variant"); if debug_block_info!(f, t.b) { println!( - "Post-compintermode[{},ctx={},n_mvs={}]: r={}", + "Post-compintermode[{:?},ctx={},n_mvs={}]: r={}", b.inter_mode(), ctx, n_mvs, @@ -2307,7 +2305,7 @@ unsafe fn decode_b_inner( let im = &dav1d_comp_inter_pred_modes[b.inter_mode() as usize]; *b.drl_idx_mut() = DrlProximity::Nearest; - if b.inter_mode() == NEWMV_NEWMV { + if b.inter_mode() == CompInterPredMode::NEWMV_NEWMV { if n_mvs > 1 { // `Nearer` or `Near` let drl_ctx_v1 = get_drl_context(&mvstack, 0); @@ -2336,7 +2334,7 @@ unsafe fn decode_b_inner( ); } } - } else if im[0] == NEARMV || im[1] == NEARMV { + } else if im[0] == InterPredMode::NEARMV || im[1] == InterPredMode::NEARMV { *b.drl_idx_mut() = DrlProximity::Nearer; if n_mvs > 2 { // `Near` or `Nearish` @@ -2368,13 +2366,14 @@ unsafe fn decode_b_inner( } } - has_subpel_filter = cmp::min(bw4, bh4) == 1 || b.inter_mode() != GLOBALMV_GLOBALMV; + has_subpel_filter = + cmp::min(bw4, bh4) == 1 || b.inter_mode() != CompInterPredMode::GLOBALMV_GLOBALMV; let mut assign_comp_mv = |idx: usize| match im[idx] { - NEARMV | NEARESTMV => { + InterPredMode::NEARMV | InterPredMode::NEARESTMV => { b.mv_mut()[idx] = mvstack[b.drl_idx() as usize].mv.mv[idx]; fix_mv_precision(frame_hdr, &mut b.mv_mut()[idx]); } - GLOBALMV => { + InterPredMode::GLOBALMV => { has_subpel_filter |= frame_hdr.gmv[b.r#ref()[idx] as usize].r#type == Rav1dWarpedMotionType::Translation; b.mv_mut()[idx] = get_gmv_2d( @@ -2386,7 +2385,7 @@ unsafe fn decode_b_inner( frame_hdr, ); } - NEWMV => { + InterPredMode::NEWMV => { b.mv_mut()[idx] = mvstack[b.drl_idx() as usize].mv.mv[idx]; read_mv_residual( t, @@ -2396,7 +2395,6 @@ unsafe fn decode_b_inner( !frame_hdr.force_integer_mv, ); } - _ => {} }; assign_comp_mv(0); assign_comp_mv(1); @@ -2593,7 +2591,7 @@ unsafe fn decode_b_inner( &mut ts.cdf.m.globalmv_mode[(ctx >> 3 & 1) as usize], ) { - *b.inter_mode_mut() = GLOBALMV; + *b.inter_mode_mut() = InterPredMode::GLOBALMV.into(); b.mv_mut()[0] = get_gmv_2d( &frame_hdr.gmv[b.r#ref()[0] as usize], t.b.x, @@ -2612,7 +2610,7 @@ unsafe fn decode_b_inner( &mut ts.cdf.m.refmv_mode[(ctx >> 4 & 15) as usize], ) { // `Nearer`, `Near` or `Nearish` - *b.inter_mode_mut() = NEARMV; + *b.inter_mode_mut() = InterPredMode::NEARMV.into(); *b.drl_idx_mut() = DrlProximity::Nearer; if n_mvs > 2 { // `Nearer`, `Near` or `Nearish` @@ -2636,7 +2634,7 @@ unsafe fn decode_b_inner( } } } else { - *b.inter_mode_mut() = NEARESTMV as u8; + *b.inter_mode_mut() = InterPredMode::NEARESTMV.into(); *b.drl_idx_mut() = DrlProximity::Nearest; } b.mv_mut()[0] = mvstack[b.drl_idx() as usize].mv.mv[0]; @@ -2647,7 +2645,7 @@ unsafe fn decode_b_inner( if debug_block_info!(f, t.b) { println!( - "Post-intermode[{},drl={:?},mv=y:{},x:{},n_mvs={}]: r={}", + "Post-intermode[{:?},drl={:?},mv=y:{},x:{},n_mvs={}]: r={}", b.inter_mode(), b.drl_idx(), b.mv()[0].y, @@ -2658,7 +2656,7 @@ unsafe fn decode_b_inner( } } else { has_subpel_filter = true; - *b.inter_mode_mut() = NEWMV; + *b.inter_mode_mut() = InterPredMode::NEWMV.into(); *b.drl_idx_mut() = DrlProximity::Nearest; if n_mvs > 1 { // `Nearer`, `Near` or `Nearish` @@ -2690,7 +2688,7 @@ unsafe fn decode_b_inner( } if debug_block_info!(f, t.b) { println!( - "Post-intermode[{},drl={:?}]: r={}", + "Post-intermode[{:?},drl={:?}]: r={}", b.inter_mode(), b.drl_idx(), ts.msac.rng, @@ -2768,7 +2766,7 @@ unsafe fn decode_b_inner( && cmp::min(bw4, bh4) >= 2 // is not warped global motion && !(!frame_hdr.force_integer_mv - && b.inter_mode() == GLOBALMV + && b.inter_mode() == InterPredMode::GLOBALMV.into() && frame_hdr.gmv[b.r#ref()[0] as usize].r#type > Rav1dWarpedMotionType::Translation) // has overlappable neighbours && (have_left && findoddzero(&t.l.intra.0[by4 as usize..][..h4 as usize]) @@ -2911,8 +2909,12 @@ unsafe fn decode_b_inner( let frame_hdr = f.frame_hdr(); if frame_hdr.loopfilter.level_y != [0, 0] { - let is_globalmv = - (b.inter_mode() == if is_comp { GLOBALMV_GLOBALMV } else { GLOBALMV }) as c_int; + let is_globalmv = (b.inter_mode() + == if is_comp { + CompInterPredMode::GLOBALMV_GLOBALMV + } else { + InterPredMode::GLOBALMV.into() + }) as c_int; let tx_split = [b.tx_split0() as u16, b.tx_split1()]; let mut ytx = b.max_ytx() as RectTxfmSize; let mut uvtx = b.uvtx as RectTxfmSize; @@ -2981,7 +2983,7 @@ unsafe fn decode_b_inner( case.set(&mut dir.comp_type.0, b.comp_type()); case.set(&mut dir.filter.0[0], filter[0]); case.set(&mut dir.filter.0[1], filter[1]); - case.set(&mut dir.mode.0, b.inter_mode()); + case.set(&mut dir.mode.0, b.inter_mode() as u8); case.set(&mut dir.r#ref.0[0], b.r#ref()[0]); case.set(&mut dir.r#ref.0[1], b.r#ref()[1]); }, @@ -3041,7 +3043,8 @@ unsafe fn decode_b_inner( if b.comp_type().is_none() { // y if cmp::min(bw4, bh4) > 1 - && (b.inter_mode() == GLOBALMV && f.gmv_warp_allowed[b.r#ref()[0] as usize] != 0 + && (b.inter_mode() == InterPredMode::GLOBALMV.into() + && f.gmv_warp_allowed[b.r#ref()[0] as usize] != 0 || b.motion_mode() == MotionMode::Warp && t.warpmv.r#type > Rav1dWarpedMotionType::Translation) { @@ -3154,7 +3157,7 @@ unsafe fn decode_b_inner( &f.svc[b.r#ref()[0] as usize][1], ); } else if cmp::min(cbw4, cbh4) > 1 - && (b.inter_mode() == GLOBALMV + && (b.inter_mode() == InterPredMode::GLOBALMV.into() && f.gmv_warp_allowed[b.r#ref()[0] as usize] != 0 || b.motion_mode() == MotionMode::Warp && t.warpmv.r#type > Rav1dWarpedMotionType::Translation) @@ -3201,7 +3204,9 @@ unsafe fn decode_b_inner( let refmvs = || std::iter::zip(b.r#ref(), b.mv()).map(|(r#ref, mv)| (r#ref as usize, mv)); for (r#ref, mv) in refmvs() { - if b.inter_mode() == GLOBALMV_GLOBALMV && f.gmv_warp_allowed[r#ref] != 0 { + if b.inter_mode() == CompInterPredMode::GLOBALMV_GLOBALMV + && f.gmv_warp_allowed[r#ref] != 0 + { affine_lowest_px_luma( t, &mut lowest_px[r#ref][0], @@ -3220,7 +3225,9 @@ unsafe fn decode_b_inner( } } for (r#ref, mv) in refmvs() { - if b.inter_mode() == GLOBALMV_GLOBALMV && f.gmv_warp_allowed[r#ref] != 0 { + if b.inter_mode() == CompInterPredMode::GLOBALMV_GLOBALMV + && f.gmv_warp_allowed[r#ref] != 0 + { affine_lowest_px_luma( t, &mut lowest_px[r#ref][0], @@ -3242,7 +3249,7 @@ unsafe fn decode_b_inner( // uv if has_chroma { for (r#ref, mv) in refmvs() { - if b.inter_mode() == GLOBALMV_GLOBALMV + if b.inter_mode() == CompInterPredMode::GLOBALMV_GLOBALMV && cmp::min(cbw4, cbh4) > 1 && f.gmv_warp_allowed[r#ref] != 0 { @@ -3631,7 +3638,7 @@ fn reset_context(ctx: &mut BlockContext, keyframe: bool, pass: c_int) { r#ref.fill(-1); } ctx.comp_type.0.fill(None); - ctx.mode.0.fill(NEARESTMV); + ctx.mode.0.fill(InterPredMode::NEARESTMV as u8); } ctx.lcoef.0.fill(0x40); for ccoef in &mut ctx.ccoef.0 { diff --git a/src/levels.rs b/src/levels.rs index edd45fc86..25a83380a 100644 --- a/src/levels.rs +++ b/src/levels.rs @@ -189,12 +189,13 @@ pub enum MVJoint { HV = 3, } -pub type InterPredMode = u8; -pub const _N_INTER_PRED_MODES: usize = 4; -pub const NEWMV: InterPredMode = 3; -pub const GLOBALMV: InterPredMode = 2; -pub const NEARMV: InterPredMode = 1; -pub const NEARESTMV: InterPredMode = 0; +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum InterPredMode { + NEARESTMV = 0, + NEARMV = 1, + GLOBALMV = 2, + NEWMV = 3, +} #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub enum DrlProximity { @@ -204,16 +205,29 @@ pub enum DrlProximity { Nearish, } -pub type CompInterPredMode = u8; pub const N_COMP_INTER_PRED_MODES: usize = 8; -pub const NEWMV_NEWMV: CompInterPredMode = 7; -pub const GLOBALMV_GLOBALMV: CompInterPredMode = 6; -pub const NEWMV_NEARMV: CompInterPredMode = 5; -pub const NEARMV_NEWMV: CompInterPredMode = 4; -pub const NEWMV_NEARESTMV: CompInterPredMode = 3; -pub const NEARESTMV_NEWMV: CompInterPredMode = 2; -pub const NEARMV_NEARMV: CompInterPredMode = 1; -pub const NEARESTMV_NEARESTMV: CompInterPredMode = 0; +#[derive(Debug, Clone, Copy, PartialEq, Eq, FromRepr)] +pub enum CompInterPredMode { + NEARESTMV_NEARESTMV = 0, + NEARMV_NEARMV = 1, + NEARESTMV_NEWMV = 2, + NEWMV_NEARESTMV = 3, + NEARMV_NEWMV = 4, + NEWMV_NEARMV = 5, + GLOBALMV_GLOBALMV = 6, + NEWMV_NEWMV = 7, +} + +impl From for CompInterPredMode { + fn from(value: InterPredMode) -> Self { + match value { + InterPredMode::NEARESTMV => CompInterPredMode::NEARESTMV_NEARESTMV, + InterPredMode::NEARMV => CompInterPredMode::NEARMV_NEARMV, + InterPredMode::GLOBALMV => CompInterPredMode::NEARESTMV_NEWMV, + InterPredMode::NEWMV => CompInterPredMode::NEWMV_NEARESTMV, + } + } +} #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub enum CompInterType { @@ -319,7 +333,7 @@ pub union Av1Block_inter_nd { pub struct Av1Block_inter { pub c2rust_unnamed: Av1Block_inter_nd, pub comp_type: Option, - pub inter_mode: u8, + pub inter_mode: CompInterPredMode, pub motion_mode: MotionMode, pub drl_idx: DrlProximity, pub r#ref: [i8; 2], @@ -383,11 +397,11 @@ impl Av1Block { &mut self.c2rust_unnamed.c2rust_unnamed_0.drl_idx } - pub unsafe fn inter_mode(&self) -> u8 { + pub unsafe fn inter_mode(&self) -> CompInterPredMode { self.c2rust_unnamed.c2rust_unnamed_0.inter_mode } - pub unsafe fn inter_mode_mut(&mut self) -> &mut u8 { + pub unsafe fn inter_mode_mut(&mut self) -> &mut CompInterPredMode { &mut self.c2rust_unnamed.c2rust_unnamed_0.inter_mode } diff --git a/src/recon.rs b/src/recon.rs index 548f78783..3abb32b48 100644 --- a/src/recon.rs +++ b/src/recon.rs @@ -31,10 +31,12 @@ use crate::src::ipred_prepare::sm_uv_flag; use crate::src::levels::mv; use crate::src::levels::Av1Block; use crate::src::levels::BlockSize; +use crate::src::levels::CompInterPredMode; use crate::src::levels::CompInterType; use crate::src::levels::Filter2d; use crate::src::levels::InterIntraPredMode; use crate::src::levels::InterIntraType; +use crate::src::levels::InterPredMode; use crate::src::levels::IntraPredMode; use crate::src::levels::MotionMode; use crate::src::levels::RectTxfmSize; @@ -45,8 +47,6 @@ use crate::src::levels::CFL_PRED; use crate::src::levels::DCT_DCT; use crate::src::levels::DC_PRED; use crate::src::levels::FILTER_PRED; -use crate::src::levels::GLOBALMV; -use crate::src::levels::GLOBALMV_GLOBALMV; use crate::src::levels::IDTX; use crate::src::levels::RTX_16X32; use crate::src::levels::RTX_16X4; @@ -3235,11 +3235,28 @@ pub(crate) unsafe fn rav1d_recon_b_inter( .c2rust_unnamed .c2rust_unnamed .c2rust_unnamed +<<<<<<< HEAD .seg_mask; for i in 0..2 { let refp = &f.refp[b.r#ref()[i] as usize]; if b.c2rust_unnamed.c2rust_unnamed_0.inter_mode == GLOBALMV_GLOBALMV && f.gmv_warp_allowed[b.r#ref()[i] as usize] != 0 +======= + .seg_mask) + .as_mut_ptr(); + let mut mask: *const u8 = 0 as *const u8; + let mut i = 0; + while i < 2 { + let refp: *const Rav1dThreadPicture = &*(f.refp).as_ptr().offset( + *(b.c2rust_unnamed.c2rust_unnamed_0.r#ref) + .as_ptr() + .offset(i as isize) as isize, + ) as *const Rav1dThreadPicture; + if b.c2rust_unnamed.c2rust_unnamed_0.inter_mode == CompInterPredMode::GLOBALMV_GLOBALMV + && f.gmv_warp_allowed[b.c2rust_unnamed.c2rust_unnamed_0.r#ref[i as usize] as usize] + as c_int + != 0 +>>>>>>> 8ecd7c33 (`enum InterPredMode` and `enum CompInterPredMode`: make real enums) { warp_affine::( f, @@ -3332,11 +3349,27 @@ pub(crate) unsafe fn rav1d_recon_b_inter( } } } +<<<<<<< HEAD if has_chroma { for pl in 0..2 { for i in 0..2 { let refp = &f.refp[b.r#ref()[i] as usize]; if b.inter_mode() == GLOBALMV_GLOBALMV +======= + if has_chroma != 0 { + let mut pl = 0; + while pl < 2 { + let mut i = 0; + while i < 2 { + let refp: *const Rav1dThreadPicture = &*(f.refp).as_ptr().offset( + *(b.c2rust_unnamed.c2rust_unnamed_0.r#ref) + .as_ptr() + .offset(i as isize) as isize, + ) + as *const Rav1dThreadPicture; + if b.c2rust_unnamed.c2rust_unnamed_0.inter_mode + == CompInterPredMode::GLOBALMV_GLOBALMV +>>>>>>> 8ecd7c33 (`enum InterPredMode` and `enum CompInterPredMode`: make real enums) && cmp::min(cbw4, cbh4) > 1 && f.gmv_warp_allowed[b.r#ref()[i] as usize] != 0 { @@ -3418,8 +3451,15 @@ pub(crate) unsafe fn rav1d_recon_b_inter( let refp = &f.refp[b.r#ref()[0] as usize]; let filter_2d = b.filter2d(); if cmp::min(bw4, bh4) > 1 +<<<<<<< HEAD && (b.inter_mode() == GLOBALMV && f.gmv_warp_allowed[b.r#ref()[0] as usize] != 0 || b.motion_mode() == MotionMode::Warp +======= + && (b.c2rust_unnamed.c2rust_unnamed_0.inter_mode == InterPredMode::GLOBALMV.into() + && f.gmv_warp_allowed[b.c2rust_unnamed.c2rust_unnamed_0.r#ref[0] as usize] as c_int + != 0 + || b.c2rust_unnamed.c2rust_unnamed_0.motion_mode == MotionMode::Warp +>>>>>>> 8ecd7c33 (`enum InterPredMode` and `enum CompInterPredMode`: make real enums) && t.warpmv.r#type > Rav1dWarpedMotionType::Translation) { warp_affine::( @@ -3681,9 +3721,18 @@ pub(crate) unsafe fn rav1d_recon_b_inter( } } else { if cmp::min(cbw4, cbh4) > 1 +<<<<<<< HEAD && (b.inter_mode() == GLOBALMV && f.gmv_warp_allowed[b.r#ref()[0] as usize] != 0 || b.motion_mode() == MotionMode::Warp +======= + && (b.c2rust_unnamed.c2rust_unnamed_0.inter_mode + == InterPredMode::GLOBALMV.into() + && f.gmv_warp_allowed[b.c2rust_unnamed.c2rust_unnamed_0.r#ref[0] as usize] + as c_int + != 0 + || b.c2rust_unnamed.c2rust_unnamed_0.motion_mode == MotionMode::Warp +>>>>>>> 8ecd7c33 (`enum InterPredMode` and `enum CompInterPredMode`: make real enums) && t.warpmv.r#type > Rav1dWarpedMotionType::Translation) { for pl in 0..2 { diff --git a/src/tables.rs b/src/tables.rs index f03e96a26..7d90faeba 100644 --- a/src/tables.rs +++ b/src/tables.rs @@ -8,6 +8,7 @@ use crate::src::align::Align8; use crate::src::levels::BlockLevel; use crate::src::levels::BlockPartition; use crate::src::levels::BlockSize; +use crate::src::levels::CompInterPredMode; use crate::src::levels::Filter2d; use crate::src::levels::InterPredMode; use crate::src::levels::TxClass; @@ -24,8 +25,6 @@ use crate::src::levels::DIAG_DOWN_RIGHT_PRED; use crate::src::levels::FLIPADST_ADST; use crate::src::levels::FLIPADST_DCT; use crate::src::levels::FLIPADST_FLIPADST; -use crate::src::levels::GLOBALMV; -use crate::src::levels::GLOBALMV_GLOBALMV; use crate::src::levels::HOR_DOWN_PRED; use crate::src::levels::HOR_PRED; use crate::src::levels::HOR_UP_PRED; @@ -33,16 +32,6 @@ use crate::src::levels::H_ADST; use crate::src::levels::H_DCT; use crate::src::levels::H_FLIPADST; use crate::src::levels::IDTX; -use crate::src::levels::NEARESTMV; -use crate::src::levels::NEARESTMV_NEARESTMV; -use crate::src::levels::NEARESTMV_NEWMV; -use crate::src::levels::NEARMV; -use crate::src::levels::NEARMV_NEARMV; -use crate::src::levels::NEARMV_NEWMV; -use crate::src::levels::NEWMV; -use crate::src::levels::NEWMV_NEARESTMV; -use crate::src::levels::NEWMV_NEARMV; -use crate::src::levels::NEWMV_NEWMV; use crate::src::levels::N_COMP_INTER_PRED_MODES; use crate::src::levels::N_INTRA_PRED_MODES; use crate::src::levels::N_RECT_TX_SIZES; @@ -480,7 +469,10 @@ pub static dav1d_txtp_from_uvmode: [TxfmType; N_UV_INTRA_PRED_MODES] = { }; pub static dav1d_comp_inter_pred_modes: [[InterPredMode; 2]; N_COMP_INTER_PRED_MODES] = { - let mut tbl = [[0; 2]; 8]; + use CompInterPredMode::*; + use InterPredMode::*; + + let mut tbl = [[InterPredMode::NEARESTMV; 2]; 8]; tbl[NEARESTMV_NEARESTMV as usize] = [NEARESTMV, NEARESTMV]; tbl[NEARMV_NEARMV as usize] = [NEARMV, NEARMV]; tbl[NEWMV_NEWMV as usize] = [NEWMV, NEWMV]; @@ -489,6 +481,7 @@ pub static dav1d_comp_inter_pred_modes: [[InterPredMode; 2]; N_COMP_INTER_PRED_M tbl[NEWMV_NEARMV as usize] = [NEWMV, NEARMV]; tbl[NEARESTMV_NEWMV as usize] = [NEARESTMV, NEWMV]; tbl[NEARMV_NEWMV as usize] = [NEARMV, NEWMV]; + tbl }; From 9743090c276f97e5135727844a5478ed3a634864 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 22 Mar 2024 19:39:19 +0100 Subject: [PATCH 2/2] rename variants --- src/cdf.rs | 6 +++--- src/decode.rs | 49 +++++++++++++++++++++---------------------- src/levels.rs | 43 +++++++++++++++++++------------------- src/recon.rs | 58 +++++---------------------------------------------- src/tables.rs | 21 +++++++++---------- 5 files changed, 63 insertions(+), 114 deletions(-) diff --git a/src/cdf.rs b/src/cdf.rs index 39c3e0294..8cccbb1a6 100644 --- a/src/cdf.rs +++ b/src/cdf.rs @@ -10,8 +10,8 @@ use crate::src::internal::Rav1dContext; use crate::src::levels::BlockLevel; use crate::src::levels::BlockPartition; use crate::src::levels::BlockSize; +use crate::src::levels::CompInterPredMode; use crate::src::levels::MVJoint; -use crate::src::levels::N_COMP_INTER_PRED_MODES; use crate::src::levels::N_INTRA_PRED_MODES; use crate::src::levels::N_TX_SIZES; use crate::src::levels::N_UV_INTRA_PRED_MODES; @@ -89,7 +89,7 @@ pub struct CdfModeContext { pub cfl_sign: Align16<[u16; 8]>, pub angle_delta: Align16<[[u16; 8]; 8]>, pub filter_intra: Align16<[u16; 8]>, - pub comp_inter_mode: Align16<[[u16; N_COMP_INTER_PRED_MODES]; 8]>, + pub comp_inter_mode: Align16<[[u16; CompInterPredMode::COUNT]; 8]>, pub seg_id: Align16<[[u16; RAV1D_MAX_SEGMENTS as usize]; 3]>, pub pal_sz: Align16<[[[u16; 8]; 7]; 2]>, pub color_map: Align16<[[[[u16; 8]; 5]; 7]; 2]>, @@ -5048,7 +5048,7 @@ pub(crate) fn rav1d_cdf_thread_update( update_bit_1d!(2, m.globalmv_mode); update_bit_1d!(6, m.refmv_mode); update_bit_1d!(3, m.drl_bit); - update_cdf_2d!(8, N_COMP_INTER_PRED_MODES - 1, m.comp_inter_mode); + update_cdf_2d!(8, CompInterPredMode::COUNT - 1, m.comp_inter_mode); update_bit_1d!(4, m.intra); update_bit_1d!(5, m.comp); update_bit_1d!(5, m.comp_dir); diff --git a/src/decode.rs b/src/decode.rs index 6fedc0ecb..55a1a8915 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -93,7 +93,6 @@ use crate::src::levels::TxfmSize; use crate::src::levels::CFL_PRED; use crate::src::levels::DC_PRED; use crate::src::levels::FILTER_PRED; -use crate::src::levels::N_COMP_INTER_PRED_MODES; use crate::src::levels::N_INTRA_PRED_MODES; use crate::src::levels::N_RECT_TX_SIZES; use crate::src::levels::N_UV_INTRA_PRED_MODES; @@ -905,8 +904,8 @@ unsafe fn splat_oneref_mv( ], }, bs, - mf: (mode == InterPredMode::GLOBALMV.into() && cmp::min(bw4, bh4) >= 2) as u8 - | (mode == InterPredMode::NEWMV.into()) as u8 * 2, + mf: (mode == InterPredMode::Global.into() && cmp::min(bw4, bh4) >= 2) as u8 + | (mode == InterPredMode::New.into()) as u8 * 2, })); c.refmvs_dsp.splat_mv( &mut t.rt.r[((t.b.y & 31) + 5) as usize..], @@ -960,7 +959,7 @@ unsafe fn splat_tworef_mv( r#ref: [b.r#ref()[0] + 1, b.r#ref()[1] + 1], }, bs, - mf: (mode == CompInterPredMode::GLOBALMV_GLOBALMV) as u8 + mf: (mode == CompInterPredMode::GlobalGlobal) as u8 | (1 << mode as u8 & 0xbc != 0) as u8 * 2, })); c.refmvs_dsp.splat_mv( @@ -2161,7 +2160,7 @@ unsafe fn decode_b_inner( frame_hdr.skip_mode.refs[1] as i8, ]; *b.comp_type_mut() = Some(CompInterType::Avg); - *b.inter_mode_mut() = CompInterPredMode::NEARESTMV_NEARESTMV; + *b.inter_mode_mut() = CompInterPredMode::NearestNearest; *b.drl_idx_mut() = DrlProximity::Nearest; has_subpel_filter = false; @@ -2290,7 +2289,7 @@ unsafe fn decode_b_inner( *b.inter_mode_mut() = CompInterPredMode::from_repr(rav1d_msac_decode_symbol_adapt8( &mut ts.msac, &mut ts.cdf.m.comp_inter_mode[ctx as usize], - N_COMP_INTER_PRED_MODES as usize - 1, + CompInterPredMode::COUNT as usize - 1, ) as usize) .expect("valid variant"); if debug_block_info!(f, t.b) { @@ -2305,7 +2304,7 @@ unsafe fn decode_b_inner( let im = &dav1d_comp_inter_pred_modes[b.inter_mode() as usize]; *b.drl_idx_mut() = DrlProximity::Nearest; - if b.inter_mode() == CompInterPredMode::NEWMV_NEWMV { + if b.inter_mode() == CompInterPredMode::NewNew { if n_mvs > 1 { // `Nearer` or `Near` let drl_ctx_v1 = get_drl_context(&mvstack, 0); @@ -2334,7 +2333,7 @@ unsafe fn decode_b_inner( ); } } - } else if im[0] == InterPredMode::NEARMV || im[1] == InterPredMode::NEARMV { + } else if im[0] == InterPredMode::Near || im[1] == InterPredMode::Near { *b.drl_idx_mut() = DrlProximity::Nearer; if n_mvs > 2 { // `Near` or `Nearish` @@ -2367,13 +2366,13 @@ unsafe fn decode_b_inner( } has_subpel_filter = - cmp::min(bw4, bh4) == 1 || b.inter_mode() != CompInterPredMode::GLOBALMV_GLOBALMV; + cmp::min(bw4, bh4) == 1 || b.inter_mode() != CompInterPredMode::GlobalGlobal; let mut assign_comp_mv = |idx: usize| match im[idx] { - InterPredMode::NEARMV | InterPredMode::NEARESTMV => { + InterPredMode::Near | InterPredMode::Nearest => { b.mv_mut()[idx] = mvstack[b.drl_idx() as usize].mv.mv[idx]; fix_mv_precision(frame_hdr, &mut b.mv_mut()[idx]); } - InterPredMode::GLOBALMV => { + InterPredMode::Global => { has_subpel_filter |= frame_hdr.gmv[b.r#ref()[idx] as usize].r#type == Rav1dWarpedMotionType::Translation; b.mv_mut()[idx] = get_gmv_2d( @@ -2385,7 +2384,7 @@ unsafe fn decode_b_inner( frame_hdr, ); } - InterPredMode::NEWMV => { + InterPredMode::New => { b.mv_mut()[idx] = mvstack[b.drl_idx() as usize].mv.mv[idx]; read_mv_residual( t, @@ -2591,7 +2590,7 @@ unsafe fn decode_b_inner( &mut ts.cdf.m.globalmv_mode[(ctx >> 3 & 1) as usize], ) { - *b.inter_mode_mut() = InterPredMode::GLOBALMV.into(); + *b.inter_mode_mut() = InterPredMode::Global.into(); b.mv_mut()[0] = get_gmv_2d( &frame_hdr.gmv[b.r#ref()[0] as usize], t.b.x, @@ -2610,7 +2609,7 @@ unsafe fn decode_b_inner( &mut ts.cdf.m.refmv_mode[(ctx >> 4 & 15) as usize], ) { // `Nearer`, `Near` or `Nearish` - *b.inter_mode_mut() = InterPredMode::NEARMV.into(); + *b.inter_mode_mut() = InterPredMode::Near.into(); *b.drl_idx_mut() = DrlProximity::Nearer; if n_mvs > 2 { // `Nearer`, `Near` or `Nearish` @@ -2634,7 +2633,7 @@ unsafe fn decode_b_inner( } } } else { - *b.inter_mode_mut() = InterPredMode::NEARESTMV.into(); + *b.inter_mode_mut() = InterPredMode::Nearest.into(); *b.drl_idx_mut() = DrlProximity::Nearest; } b.mv_mut()[0] = mvstack[b.drl_idx() as usize].mv.mv[0]; @@ -2656,7 +2655,7 @@ unsafe fn decode_b_inner( } } else { has_subpel_filter = true; - *b.inter_mode_mut() = InterPredMode::NEWMV.into(); + *b.inter_mode_mut() = InterPredMode::New.into(); *b.drl_idx_mut() = DrlProximity::Nearest; if n_mvs > 1 { // `Nearer`, `Near` or `Nearish` @@ -2766,7 +2765,7 @@ unsafe fn decode_b_inner( && cmp::min(bw4, bh4) >= 2 // is not warped global motion && !(!frame_hdr.force_integer_mv - && b.inter_mode() == InterPredMode::GLOBALMV.into() + && b.inter_mode() == InterPredMode::Global.into() && frame_hdr.gmv[b.r#ref()[0] as usize].r#type > Rav1dWarpedMotionType::Translation) // has overlappable neighbours && (have_left && findoddzero(&t.l.intra.0[by4 as usize..][..h4 as usize]) @@ -2911,9 +2910,9 @@ unsafe fn decode_b_inner( if frame_hdr.loopfilter.level_y != [0, 0] { let is_globalmv = (b.inter_mode() == if is_comp { - CompInterPredMode::GLOBALMV_GLOBALMV + CompInterPredMode::GlobalGlobal } else { - InterPredMode::GLOBALMV.into() + InterPredMode::Global.into() }) as c_int; let tx_split = [b.tx_split0() as u16, b.tx_split1()]; let mut ytx = b.max_ytx() as RectTxfmSize; @@ -3043,7 +3042,7 @@ unsafe fn decode_b_inner( if b.comp_type().is_none() { // y if cmp::min(bw4, bh4) > 1 - && (b.inter_mode() == InterPredMode::GLOBALMV.into() + && (b.inter_mode() == InterPredMode::Global.into() && f.gmv_warp_allowed[b.r#ref()[0] as usize] != 0 || b.motion_mode() == MotionMode::Warp && t.warpmv.r#type > Rav1dWarpedMotionType::Translation) @@ -3157,7 +3156,7 @@ unsafe fn decode_b_inner( &f.svc[b.r#ref()[0] as usize][1], ); } else if cmp::min(cbw4, cbh4) > 1 - && (b.inter_mode() == InterPredMode::GLOBALMV.into() + && (b.inter_mode() == InterPredMode::Global.into() && f.gmv_warp_allowed[b.r#ref()[0] as usize] != 0 || b.motion_mode() == MotionMode::Warp && t.warpmv.r#type > Rav1dWarpedMotionType::Translation) @@ -3204,7 +3203,7 @@ unsafe fn decode_b_inner( let refmvs = || std::iter::zip(b.r#ref(), b.mv()).map(|(r#ref, mv)| (r#ref as usize, mv)); for (r#ref, mv) in refmvs() { - if b.inter_mode() == CompInterPredMode::GLOBALMV_GLOBALMV + if b.inter_mode() == CompInterPredMode::GlobalGlobal && f.gmv_warp_allowed[r#ref] != 0 { affine_lowest_px_luma( @@ -3225,7 +3224,7 @@ unsafe fn decode_b_inner( } } for (r#ref, mv) in refmvs() { - if b.inter_mode() == CompInterPredMode::GLOBALMV_GLOBALMV + if b.inter_mode() == CompInterPredMode::GlobalGlobal && f.gmv_warp_allowed[r#ref] != 0 { affine_lowest_px_luma( @@ -3249,7 +3248,7 @@ unsafe fn decode_b_inner( // uv if has_chroma { for (r#ref, mv) in refmvs() { - if b.inter_mode() == CompInterPredMode::GLOBALMV_GLOBALMV + if b.inter_mode() == CompInterPredMode::GlobalGlobal && cmp::min(cbw4, cbh4) > 1 && f.gmv_warp_allowed[r#ref] != 0 { @@ -3638,7 +3637,7 @@ fn reset_context(ctx: &mut BlockContext, keyframe: bool, pass: c_int) { r#ref.fill(-1); } ctx.comp_type.0.fill(None); - ctx.mode.0.fill(InterPredMode::NEARESTMV as u8); + ctx.mode.0.fill(InterPredMode::Nearest as u8); } ctx.lcoef.0.fill(0x40); for ccoef in &mut ctx.ccoef.0 { diff --git a/src/levels.rs b/src/levels.rs index 25a83380a..59cd20a3f 100644 --- a/src/levels.rs +++ b/src/levels.rs @@ -189,14 +189,6 @@ pub enum MVJoint { HV = 3, } -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum InterPredMode { - NEARESTMV = 0, - NEARMV = 1, - GLOBALMV = 2, - NEWMV = 3, -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub enum DrlProximity { Nearest, @@ -205,26 +197,33 @@ pub enum DrlProximity { Nearish, } -pub const N_COMP_INTER_PRED_MODES: usize = 8; -#[derive(Debug, Clone, Copy, PartialEq, Eq, FromRepr)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum InterPredMode { + Nearest = 0, + Near = 1, + Global = 2, + New = 3, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, FromRepr, EnumCount)] pub enum CompInterPredMode { - NEARESTMV_NEARESTMV = 0, - NEARMV_NEARMV = 1, - NEARESTMV_NEWMV = 2, - NEWMV_NEARESTMV = 3, - NEARMV_NEWMV = 4, - NEWMV_NEARMV = 5, - GLOBALMV_GLOBALMV = 6, - NEWMV_NEWMV = 7, + NearestNearest = 0, + NearNear = 1, + NearestNew = 2, + NewNearest = 3, + NearNew = 4, + NewNear = 5, + GlobalGlobal = 6, + NewNew = 7, } impl From for CompInterPredMode { fn from(value: InterPredMode) -> Self { match value { - InterPredMode::NEARESTMV => CompInterPredMode::NEARESTMV_NEARESTMV, - InterPredMode::NEARMV => CompInterPredMode::NEARMV_NEARMV, - InterPredMode::GLOBALMV => CompInterPredMode::NEARESTMV_NEWMV, - InterPredMode::NEWMV => CompInterPredMode::NEWMV_NEARESTMV, + InterPredMode::Nearest => CompInterPredMode::NearestNearest, + InterPredMode::Near => CompInterPredMode::NearNear, + InterPredMode::Global => CompInterPredMode::NearestNew, + InterPredMode::New => CompInterPredMode::NewNearest, } } } diff --git a/src/recon.rs b/src/recon.rs index 3abb32b48..af004b56d 100644 --- a/src/recon.rs +++ b/src/recon.rs @@ -3235,28 +3235,11 @@ pub(crate) unsafe fn rav1d_recon_b_inter( .c2rust_unnamed .c2rust_unnamed .c2rust_unnamed -<<<<<<< HEAD .seg_mask; for i in 0..2 { let refp = &f.refp[b.r#ref()[i] as usize]; - if b.c2rust_unnamed.c2rust_unnamed_0.inter_mode == GLOBALMV_GLOBALMV + if b.inter_mode() == CompInterPredMode::GlobalGlobal && f.gmv_warp_allowed[b.r#ref()[i] as usize] != 0 -======= - .seg_mask) - .as_mut_ptr(); - let mut mask: *const u8 = 0 as *const u8; - let mut i = 0; - while i < 2 { - let refp: *const Rav1dThreadPicture = &*(f.refp).as_ptr().offset( - *(b.c2rust_unnamed.c2rust_unnamed_0.r#ref) - .as_ptr() - .offset(i as isize) as isize, - ) as *const Rav1dThreadPicture; - if b.c2rust_unnamed.c2rust_unnamed_0.inter_mode == CompInterPredMode::GLOBALMV_GLOBALMV - && f.gmv_warp_allowed[b.c2rust_unnamed.c2rust_unnamed_0.r#ref[i as usize] as usize] - as c_int - != 0 ->>>>>>> 8ecd7c33 (`enum InterPredMode` and `enum CompInterPredMode`: make real enums) { warp_affine::( f, @@ -3349,27 +3332,11 @@ pub(crate) unsafe fn rav1d_recon_b_inter( } } } -<<<<<<< HEAD if has_chroma { for pl in 0..2 { for i in 0..2 { let refp = &f.refp[b.r#ref()[i] as usize]; - if b.inter_mode() == GLOBALMV_GLOBALMV -======= - if has_chroma != 0 { - let mut pl = 0; - while pl < 2 { - let mut i = 0; - while i < 2 { - let refp: *const Rav1dThreadPicture = &*(f.refp).as_ptr().offset( - *(b.c2rust_unnamed.c2rust_unnamed_0.r#ref) - .as_ptr() - .offset(i as isize) as isize, - ) - as *const Rav1dThreadPicture; - if b.c2rust_unnamed.c2rust_unnamed_0.inter_mode - == CompInterPredMode::GLOBALMV_GLOBALMV ->>>>>>> 8ecd7c33 (`enum InterPredMode` and `enum CompInterPredMode`: make real enums) + if b.inter_mode() == CompInterPredMode::GlobalGlobal && cmp::min(cbw4, cbh4) > 1 && f.gmv_warp_allowed[b.r#ref()[i] as usize] != 0 { @@ -3451,15 +3418,9 @@ pub(crate) unsafe fn rav1d_recon_b_inter( let refp = &f.refp[b.r#ref()[0] as usize]; let filter_2d = b.filter2d(); if cmp::min(bw4, bh4) > 1 -<<<<<<< HEAD - && (b.inter_mode() == GLOBALMV && f.gmv_warp_allowed[b.r#ref()[0] as usize] != 0 + && (b.inter_mode() == InterPredMode::Global.into() + && f.gmv_warp_allowed[b.r#ref()[0] as usize] != 0 || b.motion_mode() == MotionMode::Warp -======= - && (b.c2rust_unnamed.c2rust_unnamed_0.inter_mode == InterPredMode::GLOBALMV.into() - && f.gmv_warp_allowed[b.c2rust_unnamed.c2rust_unnamed_0.r#ref[0] as usize] as c_int - != 0 - || b.c2rust_unnamed.c2rust_unnamed_0.motion_mode == MotionMode::Warp ->>>>>>> 8ecd7c33 (`enum InterPredMode` and `enum CompInterPredMode`: make real enums) && t.warpmv.r#type > Rav1dWarpedMotionType::Translation) { warp_affine::( @@ -3721,18 +3682,9 @@ pub(crate) unsafe fn rav1d_recon_b_inter( } } else { if cmp::min(cbw4, cbh4) > 1 -<<<<<<< HEAD - && (b.inter_mode() == GLOBALMV + && (b.inter_mode() == InterPredMode::Global.into() && f.gmv_warp_allowed[b.r#ref()[0] as usize] != 0 || b.motion_mode() == MotionMode::Warp -======= - && (b.c2rust_unnamed.c2rust_unnamed_0.inter_mode - == InterPredMode::GLOBALMV.into() - && f.gmv_warp_allowed[b.c2rust_unnamed.c2rust_unnamed_0.r#ref[0] as usize] - as c_int - != 0 - || b.c2rust_unnamed.c2rust_unnamed_0.motion_mode == MotionMode::Warp ->>>>>>> 8ecd7c33 (`enum InterPredMode` and `enum CompInterPredMode`: make real enums) && t.warpmv.r#type > Rav1dWarpedMotionType::Translation) { for pl in 0..2 { diff --git a/src/tables.rs b/src/tables.rs index 7d90faeba..91fb54b33 100644 --- a/src/tables.rs +++ b/src/tables.rs @@ -32,7 +32,6 @@ use crate::src::levels::H_ADST; use crate::src::levels::H_DCT; use crate::src::levels::H_FLIPADST; use crate::src::levels::IDTX; -use crate::src::levels::N_COMP_INTER_PRED_MODES; use crate::src::levels::N_INTRA_PRED_MODES; use crate::src::levels::N_RECT_TX_SIZES; use crate::src::levels::N_TX_TYPES_PLUS_LL; @@ -468,19 +467,19 @@ pub static dav1d_txtp_from_uvmode: [TxfmType; N_UV_INTRA_PRED_MODES] = { tbl }; -pub static dav1d_comp_inter_pred_modes: [[InterPredMode; 2]; N_COMP_INTER_PRED_MODES] = { +pub static dav1d_comp_inter_pred_modes: [[InterPredMode; 2]; CompInterPredMode::COUNT] = { use CompInterPredMode::*; use InterPredMode::*; - let mut tbl = [[InterPredMode::NEARESTMV; 2]; 8]; - tbl[NEARESTMV_NEARESTMV as usize] = [NEARESTMV, NEARESTMV]; - tbl[NEARMV_NEARMV as usize] = [NEARMV, NEARMV]; - tbl[NEWMV_NEWMV as usize] = [NEWMV, NEWMV]; - tbl[GLOBALMV_GLOBALMV as usize] = [GLOBALMV, GLOBALMV]; - tbl[NEWMV_NEARESTMV as usize] = [NEWMV, NEARESTMV]; - tbl[NEWMV_NEARMV as usize] = [NEWMV, NEARMV]; - tbl[NEARESTMV_NEWMV as usize] = [NEARESTMV, NEWMV]; - tbl[NEARMV_NEWMV as usize] = [NEARMV, NEWMV]; + let mut tbl = [[InterPredMode::Nearest; 2]; 8]; + tbl[NearestNearest as usize] = [Nearest, Nearest]; + tbl[NearNear as usize] = [Near, Near]; + tbl[NewNew as usize] = [New, New]; + tbl[GlobalGlobal as usize] = [Global, Global]; + tbl[NewNearest as usize] = [New, Nearest]; + tbl[NewNear as usize] = [New, Near]; + tbl[NearestNew as usize] = [Nearest, New]; + tbl[NearNew as usize] = [Near, New]; tbl };