forge
Explore
Log in

Don't you dare go Hollow

A NEWMV that lands on the stack's NEARESTMV reuses its trials

Browse files at this commit

12435b7e0731031c1945d7fa3d194626ae31f95cAhmet Kaan GümüşParent: 56cc232
  • perf
    • a NEWMV that lands on the stack's NEARESTMV reuses its trials
Show full message
perf(av1): a NEWMV that lands on the stack's NEARESTMV reuses its trials

Both inter paths ran motion compensation, forward transform, quantize and
reconstruct three planes' worth a second time whenever the motion search
settled on the vector the MV stack already offered as NEARESTMV -- common on
static content. The NEARESTMV trials are kept and reused when the vectors
match, so the two candidates still price separately (their mode syntax
differs) off one set of trials.

instructions:u on the 24-frame 1280x720 sequence bench: 263.5G -> 231.8G
(-12.0%); output bytes unchanged (64931), BD-rate unchanged on all three
gate clips, gate wall 7.8/7.4/7.6 -> 7.0/6.7/6.7 s.
crates/ec-av1/src/encode.rsmodified+85 -60
@@ -1856,18 +1856,28 @@ fn code_square_inter(
1856 );1856 );
1857 let new_mv = round_to_valid_mv(found.mv, stack.pred_mv);1857 let new_mv = round_to_valid_mv(found.mv, stack.pred_mv);
1858 if let Some(mv_bits) = mv_residual_bits(new_mv, stack.pred_mv) {1858 if let Some(mv_bits) = mv_residual_bits(new_mv, stack.pred_mv) {
1859- let luma_new = mc_trial(1859+ // Same reuse as `search_inter_block`: a NEWMV equal to the
1860- luma, x, y, side, new_mv, true, ref_luma.0, ref_luma.1, ref_luma.2, ref_luma.3,1860+ // stack's NEARESTMV is the same three trials, already run above.
1861- false, search.base_q_idx, search.deadzone, luma_set, fctx,1861+ let (luma_new, u_new, v_new) = if new_mv == mv {
1862- );1862+ (luma_trial.clone(), u.clone(), v.clone())
1863- let u_new = mc_trial(1863+ } else {
1864- &chroma[0], x / 2, y / 2, side / 2, new_mv, false, ref_u.0, ref_u.1, ref_u.2,1864+ (
1865- ref_u.3, false, search.base_q_idx, search.deadzone, chroma_set, fctx,1865+ mc_trial(
1866- );1866+ luma, x, y, side, new_mv, true, ref_luma.0, ref_luma.1, ref_luma.2,
1867- let v_new = mc_trial(1867+ ref_luma.3, false, search.base_q_idx, search.deadzone, luma_set, fctx,
1868- &chroma[1], x / 2, y / 2, side / 2, new_mv, false, ref_v.0, ref_v.1, ref_v.2,1868+ ),
1869- ref_v.3, false, search.base_q_idx, search.deadzone, chroma_set, fctx,1869+ mc_trial(
1870- );1870+ &chroma[0], x / 2, y / 2, side / 2, new_mv, false, ref_u.0, ref_u.1,
1871+ ref_u.2, ref_u.3, false, search.base_q_idx, search.deadzone, chroma_set,
1872+ fctx,
1873+ ),
1874+ mc_trial(
1875+ &chroma[1], x / 2, y / 2, side / 2, new_mv, false, ref_v.0, ref_v.1,
1876+ ref_v.2, ref_v.3, false, search.base_q_idx, search.deadzone, chroma_set,
1877+ fctx,
1878+ ),
1879+ )
1880+ };
1871 let skip_new = luma_new.levels.iter().all(|&l| l == 0)1881 let skip_new = luma_new.levels.iter().all(|&l| l == 0)
1872 && u_new.levels.iter().all(|&l| l == 0)1882 && u_new.levels.iter().all(|&l| l == 0)
1873 && v_new.levels.iter().all(|&l| l == 0);1883 && v_new.levels.iter().all(|&l| l == 0);
@@ -2972,6 +2982,14 @@ fn search_inter_block(
2972 // The NEARESTMV candidate: `skip` is decided below from whether its2982 // The NEARESTMV candidate: `skip` is decided below from whether its
2973 // trial actually found a nonzero level, once its residual is priced2983 // trial actually found a nonzero level, once its residual is priced
2974 // against the same CDFs the tile writer codes it with.2984 // against the same CDFs the tile writer codes it with.
2985+ //
2986+ // lane-av1speed: its three trials are kept (rather than moved straight
2987+ // into the candidate) so that a NEWMV landing on the very same vector --
2988+ // common on static content, where the stack's nearest vector is also
2989+ // what the search finds -- reuses them instead of running the same
2990+ // motion compensation, transform, quantize and reconstruct again. The
2991+ // reused trials are the same values, so the choice is bit-identical.
2992+ let nearest_trials;
2975 {2993 {
2976 let mv = stack.nearest_mv;2994 let mv = stack.nearest_mv;
2977 let luma_trial = mc_trial(2995 let luma_trial = mc_trial(
@@ -3038,6 +3056,7 @@ fn search_inter_block(
3038 } else {3056 } else {
3039 luma_trial.bits + u.bits + v.bits3057 luma_trial.bits + u.bits + v.bits
3040 });3058 });
3059+ nearest_trials = (luma_trial.clone(), u.clone(), v.clone());
3041 consider(Candidate {3060 consider(Candidate {
3042 cost,3061 cost,
3043 luma: luma_trial,3062 luma: luma_trial,
@@ -3072,54 +3091,60 @@ fn search_inter_block(
3072 stage_add(0, t.elapsed());3091 stage_add(0, t.elapsed());
3073 let mv = round_to_valid_mv(found.mv, stack.pred_mv);3092 let mv = round_to_valid_mv(found.mv, stack.pred_mv);
3074 if let Some(mv_bits) = mv_residual_bits(mv, stack.pred_mv) {3093 if let Some(mv_bits) = mv_residual_bits(mv, stack.pred_mv) {
3075- let luma_trial = mc_trial(3094+ let (luma_trial, u, v) = if mv == stack.nearest_mv {
3076- luma,3095+ nearest_trials
3077- x,3096+ } else {
3078- y,3097+ (
3079- BLOCK,3098+ mc_trial(
3080- mv,3099+ luma,
3081- true,3100+ x,
3082- ref_luma.0,3101+ y,
3083- ref_luma.1,3102+ BLOCK,
3084- ref_luma.2,3103+ mv,
3085- ref_luma.3,3104+ true,
3086- false,3105+ ref_luma.0,
3087- search.base_q_idx,3106+ ref_luma.1,
3088- search.deadzone,3107+ ref_luma.2,
3089- TxbSet::Luma32Inter, fctx,3108+ ref_luma.3,
3090- );3109+ false,
3091- let u = mc_trial(3110+ search.base_q_idx,
3092- &chroma[0],3111+ search.deadzone,
3093- x / 2,3112+ TxbSet::Luma32Inter, fctx,
3094- y / 2,3113+ ),
3095- BLOCK / 2,3114+ mc_trial(
3096- mv,3115+ &chroma[0],
3097- false,3116+ x / 2,
3098- ref_u.0,3117+ y / 2,
3099- ref_u.1,3118+ BLOCK / 2,
3100- ref_u.2,3119+ mv,
3101- ref_u.3,3120+ false,
3102- false,3121+ ref_u.0,
3103- search.base_q_idx,3122+ ref_u.1,
3104- search.deadzone,3123+ ref_u.2,
3105- chroma_set, fctx,3124+ ref_u.3,
3106- );3125+ false,
3107- let v = mc_trial(3126+ search.base_q_idx,
3108- &chroma[1],3127+ search.deadzone,
3109- x / 2,3128+ chroma_set, fctx,
3110- y / 2,3129+ ),
3111- BLOCK / 2,3130+ mc_trial(
3112- mv,3131+ &chroma[1],
3113- false,3132+ x / 2,
3114- ref_v.0,3133+ y / 2,
3115- ref_v.1,3134+ BLOCK / 2,
3116- ref_v.2,3135+ mv,
3117- ref_v.3,3136+ false,
3118- false,3137+ ref_v.0,
3119- search.base_q_idx,3138+ ref_v.1,
3120- search.deadzone,3139+ ref_v.2,
3121- chroma_set, fctx,3140+ ref_v.3,
3122- );3141+ false,
3142+ search.base_q_idx,
3143+ search.deadzone,
3144+ chroma_set, fctx,
3145+ ),
3146+ )
3147+ };
3123 let drl_bits = if stack.entries.len() > 1 {3148 let drl_bits = if stack.entries.len() > 1 {
3124 symbol_bits(&cdf::DRL_MODE[stack.drl_ctx[0]], 0)3149 symbol_bits(&cdf::DRL_MODE[stack.drl_ctx[0]], 0)
3125 } else {3150 } else {