Avoid memcpy to/from row_ctx in row-mt for rtc mode
In rtc mode with row-mt enabled, avoid copying the
top-right superblock context for the first superblock
column in a tile. Also, after encoding a superblock,
do not save the updated tile context.
Change-Id: Ifdb34671e83893b4c79f35b7c5d654dd247f6107
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 821a6cc..7566b07 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -775,6 +775,10 @@
const int mib_size_log2 = cm->seq_params.mib_size_log2;
const int sb_row = (mi_row - tile_info->mi_row_start) >> mib_size_log2;
const int use_nonrd_mode = cpi->sf.rt_sf.use_nonrd_pick_mode;
+ const CostUpdateFreq *const cost_upd_freq = &cpi->oxcf.cost_upd_freq;
+ const int rtc_mode = is_rtc_mode(cost_upd_freq, use_nonrd_mode);
+ const int update_cdf =
+ tile_data->allow_update_cdf && row_mt_enabled && !rtc_mode;
#if CONFIG_COLLECT_COMPONENT_TIMING
start_timing(cpi, encode_sb_row_time);
@@ -799,26 +803,20 @@
mi_col < tile_info->mi_col_end; mi_col += mib_size, sb_col_in_tile++) {
(*(enc_row_mt->sync_read_ptr))(row_mt_sync, sb_row, sb_col_in_tile);
- if (tile_data->allow_update_cdf && row_mt_enabled &&
- (tile_info->mi_row_start != mi_row)) {
+ if (update_cdf && (tile_info->mi_row_start != mi_row)) {
if ((tile_info->mi_col_start == mi_col)) {
// restore frame context at the 1st column sb
memcpy(xd->tile_ctx, x->row_ctx, sizeof(*xd->tile_ctx));
} else {
- if (!cpi->sf.rt_sf.use_nonrd_pick_mode ||
- cpi->oxcf.cost_upd_freq.coeff < 2 ||
- cpi->oxcf.cost_upd_freq.mode < 2 ||
- cpi->oxcf.cost_upd_freq.mv < 2) {
- // update context
- int wt_left = AVG_CDF_WEIGHT_LEFT;
- int wt_tr = AVG_CDF_WEIGHT_TOP_RIGHT;
- if (tile_info->mi_col_end > (mi_col + mib_size))
- av1_avg_cdf_symbols(xd->tile_ctx, x->row_ctx + sb_col_in_tile,
- wt_left, wt_tr);
- else
- av1_avg_cdf_symbols(xd->tile_ctx, x->row_ctx + sb_col_in_tile - 1,
- wt_left, wt_tr);
- }
+ // update context
+ int wt_left = AVG_CDF_WEIGHT_LEFT;
+ int wt_tr = AVG_CDF_WEIGHT_TOP_RIGHT;
+ if (tile_info->mi_col_end > (mi_col + mib_size))
+ av1_avg_cdf_symbols(xd->tile_ctx, x->row_ctx + sb_col_in_tile,
+ wt_left, wt_tr);
+ else
+ av1_avg_cdf_symbols(xd->tile_ctx, x->row_ctx + sb_col_in_tile - 1,
+ wt_left, wt_tr);
}
}
@@ -856,8 +854,7 @@
}
// Update the top-right context in row_mt coding
- if (tile_data->allow_update_cdf && row_mt_enabled &&
- (tile_info->mi_row_end > (mi_row + mib_size))) {
+ if (update_cdf && (tile_info->mi_row_end > (mi_row + mib_size))) {
if (sb_cols_in_tile == 1)
memcpy(x->row_ctx, xd->tile_ctx, sizeof(*xd->tile_ctx));
else if (sb_col_in_tile >= 1)
@@ -959,6 +956,7 @@
get_start_tok(cpi, tile_row, tile_col, mi_row, &tok,
cm->seq_params.mib_size_log2 + MI_SIZE_LOG2, num_planes);
+ assert(tplist != NULL);
tplist[sb_row_in_tile].start = tok;
encode_sb_row(cpi, td, this_tile, mi_row, &tok);
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index a23892e..2db238a 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -3213,6 +3213,12 @@
cm->show_frame;
}
+static AOM_INLINE int is_rtc_mode(const CostUpdateFreq *cost_upd_freq,
+ int use_non_rd_mode) {
+ return (use_non_rd_mode && cost_upd_freq->coeff >= 2 &&
+ cost_upd_freq->mode >= 2 && cost_upd_freq->mv >= 2);
+}
+
#if CONFIG_AV1_TEMPORAL_DENOISING
static INLINE int denoise_svc(const struct AV1_COMP *const cpi) {
return (!cpi->use_svc || (cpi->use_svc && cpi->svc.spatial_layer_id >=
diff --git a/av1/encoder/ethread.c b/av1/encoder/ethread.c
index 0a9325c..25f8e77 100644
--- a/av1/encoder/ethread.c
+++ b/av1/encoder/ethread.c
@@ -432,6 +432,9 @@
int thread_id = thread_data->thread_id;
AV1EncRowMultiThreadInfo *const enc_row_mt = &cpi->mt_info.enc_row_mt;
int cur_tile_id = enc_row_mt->thread_id_to_tile_id[thread_id];
+ const CostUpdateFreq *const cost_upd_freq = &cpi->oxcf.cost_upd_freq;
+ const int rtc_mode =
+ is_rtc_mode(cost_upd_freq, cpi->sf.rt_sf.use_nonrd_pick_mode);
#if CONFIG_MULTITHREAD
pthread_mutex_t *enc_row_mt_mutex_ = enc_row_mt->mutex_;
#endif
@@ -471,7 +474,7 @@
td->mb.e_mbd.tile_ctx = td->tctx;
td->mb.tile_pb_ctx = &this_tile->tctx;
- if (this_tile->allow_update_cdf) {
+ if (this_tile->allow_update_cdf && !rtc_mode) {
td->mb.row_ctx = this_tile->row_ctx;
if (current_mi_row == tile_info->mi_row_start)
memcpy(td->mb.e_mbd.tile_ctx, &this_tile->tctx, sizeof(FRAME_CONTEXT));