Enable ml_early_term_after_part_split for speed 0

This affects low and mid resolutions.

Coding loss(%):
lowres  0.04%
midres  0.01%

Speed gains(%):
lowres  7.0%
midres  6.7%

STATS_CHANGED for speed 0 only

Change-Id: I24d9f64454319f66b2f1f063031808684ec456ac
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index b2b4a6a..544cec4 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -2968,15 +2968,16 @@
     restore_context(x, &x_ctx, mi_row, mi_col, bsize, num_planes);
   }  // if (do_split)
 
-  if (cpi->sf.ml_early_term_after_part_split && !frame_is_intra_only(cm) &&
-      !terminate_partition_search && do_rectangular_split &&
+  if (cpi->sf.ml_early_term_after_part_split_level &&
+      !frame_is_intra_only(cm) && !terminate_partition_search &&
+      do_rectangular_split &&
       (partition_horz_allowed || partition_vert_allowed)) {
     av1_ml_early_term_after_split(cpi, x, pc_tree, bsize, best_rdc.rdcost,
                                   part_none_rd, part_split_rd, split_rd, mi_row,
                                   mi_col, &terminate_partition_search);
   }
 
-  if (!cpi->sf.ml_early_term_after_part_split &&
+  if (!cpi->sf.ml_early_term_after_part_split_level &&
       cpi->sf.ml_prune_rect_partition && !frame_is_intra_only(cm) &&
       (partition_horz_allowed || partition_vert_allowed) &&
       !(prune_horz || prune_vert) && !terminate_partition_search) {
diff --git a/av1/encoder/partition_strategy.c b/av1/encoder/partition_strategy.c
index 695a80e..b379218 100644
--- a/av1/encoder/partition_strategy.c
+++ b/av1/encoder/partition_strategy.c
@@ -899,6 +899,9 @@
   }
   if (!nn_config) return;
 
+  // Use more conservative threshold for level 1.
+  if (cpi->sf.ml_early_term_after_part_split_level < 2) thresh -= 0.3f;
+
   const MACROBLOCKD *const xd = &x->e_mbd;
   const int dc_q = av1_dc_quant_QTX(x->qindex, 0, xd->bd) >> (xd->bd - 8);
   const int bs = block_size_wide[bsize];
diff --git a/av1/encoder/speed_features.c b/av1/encoder/speed_features.c
index 66d47e8..e3eb193 100644
--- a/av1/encoder/speed_features.c
+++ b/av1/encoder/speed_features.c
@@ -114,6 +114,7 @@
     sf->ml_partition_search_breakout_thresh[2] = 300;  // BLOCK_32X32
     sf->ml_partition_search_breakout_thresh[3] = 500;  // BLOCK_64X64
     sf->ml_partition_search_breakout_thresh[4] = -1;   // BLOCK_128X128
+    sf->ml_early_term_after_part_split_level = 1;
   }
 
   if (is_720p_or_larger && speed >= CONFIG_2PASS_PARTITION_SEARCH_LVL_START &&
@@ -143,7 +144,7 @@
       // TODO(chiyotsai@google.com): Try to disable two pass partition search
       // and turn on hdres
       sf->simple_motion_search_split_speed = 1;
-      sf->ml_early_term_after_part_split = 1;
+      sf->ml_early_term_after_part_split_level = 2;
     }
   }
 
@@ -172,7 +173,7 @@
 
   if (speed >= 3) {
     sf->simple_motion_search_split_speed = 2;
-    sf->ml_early_term_after_part_split = 0;
+    sf->ml_early_term_after_part_split_level = 0;
     if (is_720p_or_larger) {
       sf->partition_search_breakout_dist_thr = (1 << 25);
       sf->partition_search_breakout_rate_thr = 200;
@@ -765,7 +766,7 @@
   sf->ml_prune_rect_partition = 0;
   sf->ml_prune_ab_partition = 0;
   sf->ml_prune_4_partition = 0;
-  sf->ml_early_term_after_part_split = 0;
+  sf->ml_early_term_after_part_split_level = 0;
   sf->fast_cdef_search = 0;
   for (i = 0; i < PARTITION_BLOCK_SIZES; ++i) {
     sf->ml_partition_search_breakout_thresh[i] = -1;  // -1 means not enabled.
diff --git a/av1/encoder/speed_features.h b/av1/encoder/speed_features.h
index e82f3d9..1cc1b82 100644
--- a/av1/encoder/speed_features.h
+++ b/av1/encoder/speed_features.h
@@ -386,8 +386,9 @@
   int ml_prune_4_partition;
 
   // Use a ML model to adaptively terminate partition search after trying
-  // PARTITION_SPLIT.
-  int ml_early_term_after_part_split;
+  // PARTITION_SPLIT. Can take values 0 - 2, 0 meaning not being enabled, and
+  // 1 - 2 increasing aggressiveness in order.
+  int ml_early_term_after_part_split_level;
 
   int fast_cdef_search;