Skip to content

Commit

Permalink
Backport struct CdfContext size reduction from dav1d 1.4.2 (#1198)
Browse files Browse the repository at this point in the history
Remove separate intra-only `dmv` contexts in `struct CdfContext` and 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.
  • Loading branch information
fbossen authored Jun 12, 2024
2 parents 59e623c + 6c3dbcd commit e563950
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 39 deletions.
4 changes: 1 addition & 3 deletions src/cdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/cdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
8 changes: 3 additions & 5 deletions src/cdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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 {
Expand Down Expand Up @@ -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(),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 4 additions & 25 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,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(
Expand All @@ -291,10 +285,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 => {
Expand Down Expand Up @@ -2132,7 +2123,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;
Expand Down Expand Up @@ -2559,13 +2550,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!(),
Expand Down Expand Up @@ -2886,13 +2871,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={}",
Expand Down

0 comments on commit e563950

Please sign in to comment.