From 4414fef362fb146852493840f1b0da8332341baf Mon Sep 17 00:00:00 2001 From: Henrik Gramner Date: Tue, 2 Apr 2024 20:45:48 +0200 Subject: [PATCH 1/2] cdf: Remove separate intra-only dmv contexts We can simply use the regular mv contexts for intra frames. They are mutually exclusive, and the dmv contexts were already discarded and replaced with default contexts on frame completion. --- src/cdf.c | 4 +--- src/cdf.h | 10 +++++----- src/decode.c | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/cdf.c b/src/cdf.c index ac7751732..85275909c 100644 --- a/src/cdf.c +++ b/src/cdf.c @@ -4072,9 +4072,7 @@ void dav1d_cdf_thread_copy(CdfContext *const dst, const CdfThreadContext *const memcpy(dst->kfym, default_kf_y_mode_cdf, sizeof(default_kf_y_mode_cdf)); dst->coef = av1_default_coef_cdf[src->data.qcat]; memcpy(dst->mv.joint, default_mv_joint_cdf, sizeof(default_mv_joint_cdf)); - memcpy(dst->dmv.joint, default_mv_joint_cdf, sizeof(default_mv_joint_cdf)); - dst->mv.comp[0] = dst->mv.comp[1] = dst->dmv.comp[0] = dst->dmv.comp[1] = - default_mv_component_cdf; + dst->mv.comp[0] = dst->mv.comp[1] = default_mv_component_cdf; } } diff --git a/src/cdf.h b/src/cdf.h index def835399..3ba594d88 100644 --- a/src/cdf.h +++ b/src/cdf.h @@ -108,13 +108,13 @@ typedef struct CdfCoefContext { typedef struct CdfMvComponent { ALIGN(uint16_t classes[11 + 5], 32); + ALIGN(uint16_t sign[2], 4); + ALIGN(uint16_t class0[2], 4); ALIGN(uint16_t class0_fp[2][4], 8); - ALIGN(uint16_t classN_fp[4], 8); ALIGN(uint16_t class0_hp[2], 4); - ALIGN(uint16_t classN_hp[2], 4); - ALIGN(uint16_t class0[2], 4); ALIGN(uint16_t classN[10][2], 4); - ALIGN(uint16_t sign[2], 4); + ALIGN(uint16_t classN_fp[4], 8); + ALIGN(uint16_t classN_hp[2], 4); } CdfMvComponent; typedef struct CdfMvContext { @@ -126,7 +126,7 @@ typedef struct CdfContext { CdfModeContext m; ALIGN(uint16_t kfym[5][5][N_INTRA_PRED_MODES + 3], 32); CdfCoefContext coef; - CdfMvContext mv, dmv; + CdfMvContext mv; } CdfContext; typedef struct CdfThreadContext { diff --git a/src/decode.c b/src/decode.c index c7fd02696..c6091ee4d 100644 --- a/src/decode.c +++ b/src/decode.c @@ -1324,7 +1324,7 @@ static int decode_b(Dav1dTaskContext *const t, } const union mv ref = b->mv[0]; - read_mv_residual(t, &b->mv[0], &ts->cdf.dmv, 0); + read_mv_residual(t, &b->mv[0], &ts->cdf.mv, 0); // clip intrabc motion vector to decoded parts of current tile int border_left = ts->tiling.col_start * 4; From 6c3dbcde3c762c9dec52ec92862552bb54615085 Mon Sep 17 00:00:00 2001 From: Frank Bossen Date: Tue, 11 Jun 2024 17:41:05 -0400 Subject: [PATCH 2/2] Port C code changes to Rust --- src/cdf.rs | 8 +++----- src/decode.rs | 29 ++++------------------------- 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/src/cdf.rs b/src/cdf.rs index 0b3e70935..cb9bd0de1 100644 --- a/src/cdf.rs +++ b/src/cdf.rs @@ -32,7 +32,6 @@ pub struct CdfContext { pub kfym: Align32<[[[u16; N_INTRA_PRED_MODES + 3]; 5]; 5]>, pub coef: CdfCoefContext, pub mv: CdfMvContext, - pub dmv: CdfMvContext, } #[derive(Clone)] @@ -55,13 +54,13 @@ impl Default for CdfMvContext { #[repr(C)] pub struct CdfMvComponent { pub classes: Align32<[u16; 16]>, + pub sign: Align4<[u16; 2]>, + pub class0: Align4<[u16; 2]>, pub class0_fp: Align8<[[u16; 4]; 2]>, - pub classN_fp: Align8<[u16; 4]>, pub class0_hp: Align4<[u16; 2]>, + pub classN_fp: Align8<[u16; 4]>, pub classN_hp: Align4<[u16; 2]>, - pub class0: Align4<[u16; 2]>, pub classN: Align4<[[u16; 2]; 10]>, - pub sign: Align4<[u16; 2]>, } impl Default for CdfMvComponent { @@ -5103,7 +5102,6 @@ pub fn rav1d_cdf_thread_copy(src: &CdfThreadContext) -> CdfContext { kfym: default_kf_y_mode_cdf, coef: av1_default_coef_cdf[*i as usize].clone(), mv: Default::default(), - dmv: Default::default(), }, } } diff --git a/src/decode.rs b/src/decode.rs index 03a4d7f52..96a82fcbb 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -273,16 +273,10 @@ fn read_mv_component_diff( } } -enum MvCdfSelect { - Mv, - Dmv, -} - fn read_mv_residual( f: &Rav1dFrameData, ts_c: &mut Rav1dTileStateContext, ref_mv: &mut mv, - mv_cdf: MvCdfSelect, have_fp: bool, ) { let mv_joint = MVJoint::from_repr(rav1d_msac_decode_symbol_adapt4( @@ -292,10 +286,7 @@ fn read_mv_residual( ) as usize) .expect("valid variant"); - let mv_cdf = match mv_cdf { - MvCdfSelect::Mv => &mut ts_c.cdf.mv, - MvCdfSelect::Dmv => &mut ts_c.cdf.dmv, - }; + let mv_cdf = &mut ts_c.cdf.mv; match mv_joint { MVJoint::HV => { @@ -2137,7 +2128,7 @@ fn decode_b( } }; - read_mv_residual(f, ts_c, &mut r#ref, MvCdfSelect::Dmv, false); + read_mv_residual(f, ts_c, &mut r#ref, false); // clip intrabc motion vector to decoded parts of current tile let mut border_left = ts.tiling.col_start * 4; @@ -2564,13 +2555,7 @@ fn decode_b( } NEWMV => { let mut mv1d = mvstack[drl_idx as usize].mv.mv[i]; - read_mv_residual( - f, - ts_c, - &mut mv1d, - MvCdfSelect::Mv, - !frame_hdr.force_integer_mv, - ); + read_mv_residual(f, ts_c, &mut mv1d, !frame_hdr.force_integer_mv); mv1d } _ => unreachable!(), @@ -2891,13 +2876,7 @@ fn decode_b( inter_mode, drl_idx, ts_c.msac.rng, ); } - read_mv_residual( - f, - ts_c, - &mut mv1d0, - MvCdfSelect::Mv, - !frame_hdr.force_integer_mv, - ); + read_mv_residual(f, ts_c, &mut mv1d0, !frame_hdr.force_integer_mv); if debug_block_info!(f, t.b) { println!( "Post-residualmv[mv=y:{},x:{}]: r={}",