ref: 7c5574a635fccf8bde063426ff2b167dc91bfb8a
parent: bd53f0cc9faefbca2dcb6b21b6849d5e24141c9c
parent: fe1c7d2d8cce13d9cd1edfe11a6703e5521ae561
author: Cheng Chen <chengchen@google.com>
date: Tue Jun 29 12:48:29 EDT 2021
Merge "Disallow skipping transform and quantization" into main
--- a/vp9/encoder/vp9_block.h
+++ b/vp9/encoder/vp9_block.h
@@ -157,6 +157,9 @@
// skip forward transform and quantization
uint8_t skip_txfm[MAX_MB_PLANE << 2];
#define SKIP_TXFM_NONE 0
+// TODO(chengchen): consider remove SKIP_TXFM_AC_DC from vp9 completely
+// since it increases risks of bad perceptual quality.
+// https://crbug.com/webm/1729
#define SKIP_TXFM_AC_DC 1
#define SKIP_TXFM_AC_ONLY 2
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -745,8 +745,8 @@
MODE_INFO *const mi = xd->mi[0];
int64_t rd1, rd2, rd;
int rate;
- int64_t dist;
- int64_t sse;
+ int64_t dist = INT64_MAX;
+ int64_t sse = INT64_MAX;
const int coeff_ctx =
combine_entropy_contexts(args->t_left[blk_row], args->t_above[blk_col]);
struct buf_2d *recon = args->this_recon;
@@ -799,6 +799,13 @@
if (max_txsize_lookup[plane_bsize] == tx_size)
skip_txfm_flag = x->skip_txfm[(plane << 2) + (block >> (tx_size << 1))];
+ // This reduces the risk of bad perceptual quality due to bad prediction.
+ // We always force the encoder to perform transform and quantization.
+ if (!args->cpi->sf.allow_skip_txfm_ac_dc &&
+ skip_txfm_flag == SKIP_TXFM_AC_DC) {
+ skip_txfm_flag = SKIP_TXFM_NONE;
+ }
+
if (skip_txfm_flag == SKIP_TXFM_NONE ||
(recon && skip_txfm_flag == SKIP_TXFM_AC_ONLY)) {
// full forward transform and quantization
@@ -827,17 +834,7 @@
dist = VPXMAX(0, sse - dc_correct);
}
} else {
- // SKIP_TXFM_AC_DC
- // skip forward transform. Because this is handled here, the quantization
- // does not need to do it.
- x->plane[plane].eobs[block] = 0;
- sse = x->bsse[(plane << 2) + (block >> (tx_size << 1))] << 4;
- dist = sse;
- if (recon) {
- uint8_t *rec_ptr = &recon->buf[4 * (blk_row * recon->stride + blk_col)];
- copy_block_visible(xd, pd, dst, dst_stride, rec_ptr, recon->stride,
- blk_row, blk_col, plane_bsize, tx_bsize);
- }
+ assert(0 && "allow_skip_txfm_ac_dc does not allow SKIP_TXFM_AC_DC.");
}
}
--- a/vp9/encoder/vp9_speed_features.c
+++ b/vp9/encoder/vp9_speed_features.c
@@ -940,6 +940,7 @@
sf->enable_tpl_model = oxcf->enable_tpl_model;
sf->prune_ref_frame_for_rect_partitions = 0;
sf->temporal_filter_search_method = MESH;
+ sf->allow_skip_txfm_ac_dc = 0;
for (i = 0; i < TX_SIZES; i++) {
sf->intra_y_mode_mask[i] = INTRA_ALL;
--- a/vp9/encoder/vp9_speed_features.h
+++ b/vp9/encoder/vp9_speed_features.h
@@ -612,6 +612,12 @@
// For real-time mode: force DC only under intra search when content
// does not have high souce SAD.
int rt_intra_dc_only_low_content;
+
+ // The encoder has a feature that skips forward transform and quantization
+ // based on a model rd estimation to reduce encoding time.
+ // However, this feature is dangerous since it could lead to bad perceptual
+ // quality. This flag is added to guard the feature.
+ int allow_skip_txfm_ac_dc;
} SPEED_FEATURES;
struct VP9_COMP;