Disable hash me for non-intra frames

Introduced a speed feature to disable hash data generation and use of
the same for cur_frame_force_integer_mv decision. This change is
applicable for non-intra frames of screen contents.

STATS_CHANGED

Change-Id: Ia2260e91f0cdd61fc31910f45e21ce481dae82f1
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index f14ec03..be09a1f 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -5038,7 +5038,7 @@
 
   cm->allow_intrabc &= (cpi->oxcf.enable_intrabc);
 
-  if (cpi->oxcf.pass != 1 && av1_use_hash_me(cm) &&
+  if (cpi->oxcf.pass != 1 && av1_use_hash_me(cpi) &&
       !cpi->sf.use_nonrd_pick_mode) {
     // add to hash table
     const int pic_width = cpi->source->y_crop_width;
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 6813da3..086887d 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -5532,8 +5532,6 @@
   aom_clear_system_state();
   // check use hash ME
   int k;
-  uint32_t hash_value_1;
-  uint32_t hash_value_2;
 
   const int block_size = FORCE_INT_MV_DECISION_BLOCK_SIZE;
   const double threshold_current = 0.8;
@@ -5596,14 +5594,15 @@
         S++;
         continue;
       }
-
-      av1_get_block_hash_value(
-          cur_picture->y_buffer + y_pos * stride_cur + x_pos, stride_cur,
-          block_size, &hash_value_1, &hash_value_2,
-          (cur_picture->flags & YV12_FLAG_HIGHBITDEPTH), &cpi->td.mb);
-      // Hashing does not work for highbitdepth currently.
-      // TODO(Roger): Make it work for highbitdepth.
-      if (av1_use_hash_me(&cpi->common)) {
+      if (av1_use_hash_me(cpi)) {
+        uint32_t hash_value_1;
+        uint32_t hash_value_2;
+        av1_get_block_hash_value(
+            cur_picture->y_buffer + y_pos * stride_cur + x_pos, stride_cur,
+            block_size, &hash_value_1, &hash_value_2,
+            (cur_picture->flags & YV12_FLAG_HIGHBITDEPTH), &cpi->td.mb);
+        // Hashing does not work for highbitdepth currently.
+        // TODO(Roger): Make it work for highbitdepth.
         if (av1_has_exact_match(last_hash_table, hash_value_1, hash_value_2)) {
           M++;
         }
@@ -6064,7 +6063,7 @@
   // Store encoded frame's hash table for in_integer_mv() next time.
   // Beware! If we don't update previous_hash_table here we will leak the
   // items stored in cur_frame's hash_table!
-  if (oxcf->pass != 1 && av1_use_hash_me(cm)) {
+  if (oxcf->pass != 1 && av1_use_hash_me(cpi)) {
     cpi->previous_hash_table = &cm->cur_frame->hash_table;
     cpi->need_to_clear_prev_hash_table = 1;
   }
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index b54e58d..95f7035 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -1263,8 +1263,8 @@
 }
 
 // TODO(huisu@google.com, youzhou@microsoft.com): enable hash-me for HBD.
-static INLINE int av1_use_hash_me(const AV1_COMMON *const cm) {
-  return cm->allow_screen_content_tools;
+static INLINE int av1_use_hash_me(const AV1_COMP *const cpi) {
+  return (cpi->common.allow_screen_content_tools && !cpi->sf.disable_hash_me);
 }
 
 static INLINE hash_table *av1_get_ref_frame_hash_map(
diff --git a/av1/encoder/mcomp.c b/av1/encoder/mcomp.c
index 921d52a..ee27d1d 100644
--- a/av1/encoder/mcomp.c
+++ b/av1/encoder/mcomp.c
@@ -2415,7 +2415,7 @@
 
   // Use hash-me for intrablock copy
   do {
-    if (!intra || !av1_use_hash_me(&cpi->common)) break;
+    if (!intra || !av1_use_hash_me(cpi)) break;
 
     // already single ME
     // get block size and original buffer of current block
diff --git a/av1/encoder/speed_features.c b/av1/encoder/speed_features.c
index c3b6ecb..f9404ef 100644
--- a/av1/encoder/speed_features.c
+++ b/av1/encoder/speed_features.c
@@ -282,6 +282,9 @@
 
   if (speed >= 1) {
     sf->selective_ref_frame = 2;
+    // TODO(any): Experiment with this speed feature for speed=0 and clean-up
+    // the code altogether.
+    sf->disable_hash_me = frame_is_intra_only(cm) ? 0 : 1;
 
     sf->prune_ref_frame_for_gm_search = boosted ? 0 : 1;
     sf->intra_tx_size_search_init_depth_rect = 1;
@@ -821,6 +824,7 @@
   sf->use_intra_txb_hash = 0;
   sf->use_inter_txb_hash = 1;
   sf->use_mb_rd_hash = 1;
+  sf->disable_hash_me = 0;
   sf->optimize_b_precheck = 0;
   sf->use_dist_wtd_comp_flag = DIST_WTD_COMP_ENABLED;
   sf->reuse_inter_intra_mode = 0;
diff --git a/av1/encoder/speed_features.h b/av1/encoder/speed_features.h
index bf6cd1e..96eaf5f 100644
--- a/av1/encoder/speed_features.h
+++ b/av1/encoder/speed_features.h
@@ -561,6 +561,10 @@
   // to avoid repeated search on the same residue signal.
   int use_mb_rd_hash;
 
+  // Use to control hash generation and use of the same
+  // Applicable only for screen contents
+  int disable_hash_me;
+
   // Calculate RD cost before doing optimize_b, and skip if the cost is large.
   int optimize_b_precheck;