Remove first partition search pass

Removed first partition search pass code since two pass partition
search is not used.

Change-Id: I7171a77551789a7ec03c84f48071068d3bd3fb8a
diff --git a/av1/encoder/block.h b/av1/encoder/block.h
index 16ccc38..13f248b 100644
--- a/av1/encoder/block.h
+++ b/av1/encoder/block.h
@@ -151,33 +151,6 @@
 // 4: NEAREST, NEW, NEAR, GLOBAL
 #define SINGLE_REF_MODES ((REF_FRAMES - 1) * 4)
 
-// Region size for mode decision sampling in the first pass of partition
-// search(two_pass_partition_search speed feature), in units of mi size(4).
-// Used by the mode pruning in two_pass_partition_search feature.
-#define FIRST_PARTITION_PASS_SAMPLE_REGION 8
-#define FIRST_PARTITION_PASS_SAMPLE_REGION_LOG2 3
-#define FIRST_PARTITION_PASS_STATS_TABLES                     \
-  (MAX_MIB_SIZE >> FIRST_PARTITION_PASS_SAMPLE_REGION_LOG2) * \
-      (MAX_MIB_SIZE >> FIRST_PARTITION_PASS_SAMPLE_REGION_LOG2)
-#define FIRST_PARTITION_PASS_STATS_STRIDE \
-  (MAX_MIB_SIZE_LOG2 - FIRST_PARTITION_PASS_SAMPLE_REGION_LOG2)
-
-static INLINE int av1_first_partition_pass_stats_index(int mi_row, int mi_col) {
-  const int row =
-      (mi_row & MAX_MIB_MASK) >> FIRST_PARTITION_PASS_SAMPLE_REGION_LOG2;
-  const int col =
-      (mi_col & MAX_MIB_MASK) >> FIRST_PARTITION_PASS_SAMPLE_REGION_LOG2;
-  return (row << FIRST_PARTITION_PASS_STATS_STRIDE) + col;
-}
-
-typedef struct {
-  uint8_t ref0_counts[REF_FRAMES];  // Counters for ref_frame[0].
-  uint8_t ref1_counts[REF_FRAMES];  // Counters for ref_frame[1].
-  int sample_counts;                // Number of samples collected.
-  uint8_t interintra_motion_mode_count[REF_FRAMES];  // Counter for interintra
-                                                     // motion mode
-} FIRST_PARTITION_PASS_STATS;
-
 #define MAX_INTERP_FILTER_STATS 64
 typedef struct {
   InterpFilters filters;
@@ -213,14 +186,6 @@
   // to select transform kernel.
   int rd_model;
 
-  // Indicate if the encoder is running in the first pass partition search.
-  // In that case, apply certain speed features therein to reduce the overhead
-  // cost in the first pass search.
-  int cb_partition_scan;
-
-  FIRST_PARTITION_PASS_STATS
-  first_partition_pass_stats[FIRST_PARTITION_PASS_STATS_TABLES];
-
   // [comp_idx][saved stat_idx]
   INTERPOLATION_FILTER_STATS interp_filter_stats[2][MAX_INTERP_FILTER_STATS];
   int interp_filter_stats_idx[2];
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 21e58de..ae3fffc 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -2197,307 +2197,6 @@
   }
 }
 
-static void rd_pick_sqr_partition(AV1_COMP *const cpi, ThreadData *td,
-                                  TileDataEnc *tile_data, TOKENEXTRA **tp,
-                                  int mi_row, int mi_col, BLOCK_SIZE bsize,
-                                  RD_STATS *rd_cost, int64_t best_rd,
-                                  PC_TREE *pc_tree, int64_t *none_rd) {
-  const AV1_COMMON *const cm = &cpi->common;
-  TileInfo *const tile_info = &tile_data->tile_info;
-  MACROBLOCK *const x = &td->mb;
-  MACROBLOCKD *const xd = &x->e_mbd;
-  const int mi_step = mi_size_wide[bsize] / 2;
-  RD_SEARCH_MACROBLOCK_CONTEXT x_ctx;
-  const TOKENEXTRA *const tp_orig = *tp;
-  PICK_MODE_CONTEXT *ctx_none = &pc_tree->none;
-  int tmp_partition_cost[PARTITION_TYPES];
-  BLOCK_SIZE subsize;
-  RD_STATS this_rdc, sum_rdc, best_rdc, pn_rdc;
-  const int bsize_at_least_8x8 = (bsize >= BLOCK_8X8);
-  int do_square_split = bsize_at_least_8x8;
-  const int pl = bsize_at_least_8x8
-                     ? partition_plane_context(xd, mi_row, mi_col, bsize)
-                     : 0;
-  const int *partition_cost =
-      pl >= 0 ? x->partition_cost[pl] : x->partition_cost[0];
-  const int num_planes = av1_num_planes(cm);
-
-  int64_t split_rd[4] = { 0, 0, 0, 0 };
-
-  // Override skipping rectangular partition operations for edge blocks
-  const int has_rows = (mi_row + mi_step < cm->mi_rows);
-  const int has_cols = (mi_col + mi_step < cm->mi_cols);
-
-  if (none_rd) *none_rd = 0;
-
-  int partition_none_allowed = has_rows && has_cols;
-
-  (void)*tp_orig;
-  (void)split_rd;
-
-  if (best_rd < 0) {
-    pc_tree->none.rd_stats.rdcost = INT64_MAX;
-    pc_tree->none.rd_stats.skip = 0;
-    av1_invalid_rd_stats(rd_cost);
-    return;
-  }
-  pc_tree->pc_tree_stats.valid = 1;
-
-  // Override partition costs at the edges of the frame in the same
-  // way as in read_partition (see decodeframe.c)
-  if (!(has_rows && has_cols)) {
-    assert(bsize_at_least_8x8 && pl >= 0);
-    const aom_cdf_prob *partition_cdf = cm->fc->partition_cdf[pl];
-    for (int i = 0; i < PARTITION_TYPES; ++i) tmp_partition_cost[i] = INT_MAX;
-    if (has_cols) {
-      // At the bottom, the two possibilities are HORZ and SPLIT
-      aom_cdf_prob bot_cdf[2];
-      partition_gather_vert_alike(bot_cdf, partition_cdf, bsize);
-      static const int bot_inv_map[2] = { PARTITION_HORZ, PARTITION_SPLIT };
-      av1_cost_tokens_from_cdf(tmp_partition_cost, bot_cdf, bot_inv_map);
-    } else if (has_rows) {
-      // At the right, the two possibilities are VERT and SPLIT
-      aom_cdf_prob rhs_cdf[2];
-      partition_gather_horz_alike(rhs_cdf, partition_cdf, bsize);
-      static const int rhs_inv_map[2] = { PARTITION_VERT, PARTITION_SPLIT };
-      av1_cost_tokens_from_cdf(tmp_partition_cost, rhs_cdf, rhs_inv_map);
-    } else {
-      // At the bottom right, we always split
-      tmp_partition_cost[PARTITION_SPLIT] = 0;
-    }
-
-    partition_cost = tmp_partition_cost;
-  }
-
-#ifndef NDEBUG
-  // Nothing should rely on the default value of this array (which is just
-  // leftover from encoding the previous block. Setting it to fixed pattern
-  // when debugging.
-  // bit 0, 1, 2 are blk_skip of each plane
-  // bit 4, 5, 6 are initialization checking of each plane
-  memset(x->blk_skip, 0x77, sizeof(x->blk_skip));
-#endif  // NDEBUG
-
-  assert(mi_size_wide[bsize] == mi_size_high[bsize]);
-
-  av1_init_rd_stats(&this_rdc);
-  av1_init_rd_stats(&sum_rdc);
-  av1_invalid_rd_stats(&best_rdc);
-  best_rdc.rdcost = best_rd;
-
-  set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize);
-
-  if (bsize == BLOCK_16X16 && cpi->vaq_refresh)
-    x->mb_energy = av1_log_block_var(cpi, x, bsize);
-
-  xd->above_txfm_context = cm->above_txfm_context[tile_info->tile_row] + mi_col;
-  xd->left_txfm_context =
-      xd->left_txfm_context_buffer + (mi_row & MAX_MIB_MASK);
-  save_context(x, &x_ctx, mi_row, mi_col, bsize, num_planes);
-
-#if CONFIG_DIST_8X8
-  if (x->using_dist_8x8) {
-    if (block_size_high[bsize] <= 8 || block_size_wide[bsize] <= 8)
-      do_square_split = 0;
-  }
-#endif
-
-  // PARTITION_NONE
-  if (partition_none_allowed) {
-    int pt_cost = 0;
-    if (bsize_at_least_8x8) {
-      pc_tree->partitioning = PARTITION_NONE;
-      pt_cost = partition_cost[PARTITION_NONE] < INT_MAX
-                    ? partition_cost[PARTITION_NONE]
-                    : 0;
-    }
-    const int64_t partition_rd_cost = RDCOST(x->rdmult, pt_cost, 0);
-    const int64_t best_remain_rdcost =
-        best_rdc.rdcost == INT64_MAX ? INT64_MAX
-                                     : (best_rdc.rdcost - partition_rd_cost);
-    pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &this_rdc, PARTITION_NONE,
-                  bsize, ctx_none, best_remain_rdcost, PICK_MODE_RD);
-
-    pc_tree->pc_tree_stats.rdcost = ctx_none->rd_stats.rdcost;
-    pc_tree->pc_tree_stats.skip = ctx_none->rd_stats.skip;
-
-    if (none_rd) *none_rd = this_rdc.rdcost;
-    if (this_rdc.rate != INT_MAX) {
-      if (bsize_at_least_8x8) {
-        this_rdc.rate += pt_cost;
-        this_rdc.rdcost = RDCOST(x->rdmult, this_rdc.rate, this_rdc.dist);
-      }
-
-      if (this_rdc.rdcost < best_rdc.rdcost) {
-        // Adjust dist breakout threshold according to the partition size.
-        const int64_t dist_breakout_thr =
-            cpi->sf.partition_search_breakout_dist_thr >>
-            ((2 * (MAX_SB_SIZE_LOG2 - 2)) -
-             (mi_size_wide_log2[bsize] + mi_size_high_log2[bsize]));
-        const int rate_breakout_thr =
-            cpi->sf.partition_search_breakout_rate_thr *
-            num_pels_log2_lookup[bsize];
-
-        best_rdc = this_rdc;
-        if (bsize_at_least_8x8) pc_tree->partitioning = PARTITION_NONE;
-
-        pc_tree->cb_search_range = SEARCH_FULL_PLANE;
-
-        if (!x->e_mbd.lossless[xd->mi[0]->segment_id] && ctx_none->skippable) {
-          const int use_ml_based_breakout =
-              bsize <= cpi->sf.use_square_partition_only_threshold &&
-              bsize > BLOCK_4X4 && xd->bd == 8;
-
-          // TODO(anyone): Currently this is using the same model and threshold
-          // values as in rd_pick_partition. Retraining the model and tuning the
-          // threshold values might be helpful to improve the speed.
-          if (use_ml_based_breakout) {
-            if (av1_ml_predict_breakout(cpi, bsize, x, &this_rdc,
-                                        x->source_variance)) {
-              do_square_split = 0;
-            }
-          }
-
-          // If all y, u, v transform blocks in this partition are skippable,
-          // and the dist & rate are within the thresholds, the partition search
-          // is terminated for current branch of the partition search tree. The
-          // dist & rate thresholds are set to 0 at speed 0 to disable the early
-          // termination at that speed.
-          if (best_rdc.dist < dist_breakout_thr &&
-              best_rdc.rate < rate_breakout_thr) {
-            do_square_split = 0;
-          }
-        }
-
-        if (cpi->sf.firstpass_simple_motion_search_early_term &&
-            cm->show_frame && bsize <= BLOCK_32X32 && bsize >= BLOCK_8X8 &&
-            !frame_is_intra_only(cm) && mi_row + mi_step < cm->mi_rows &&
-            mi_col + mi_step < cm->mi_cols && this_rdc.rdcost < INT64_MAX &&
-            this_rdc.rdcost >= 0 && this_rdc.rate < INT_MAX &&
-            this_rdc.rate >= 0 && do_square_split) {
-          av1_firstpass_simple_motion_search_early_term(
-              cpi, x, pc_tree, mi_row, mi_col, bsize, &this_rdc,
-              &do_square_split);
-        }
-      }
-    }
-
-    restore_context(x, &x_ctx, mi_row, mi_col, bsize, num_planes);
-  }
-
-  // store estimated motion vector
-  if (cpi->sf.adaptive_motion_search) store_pred_mv(x, ctx_none);
-
-  int64_t temp_best_rdcost = best_rdc.rdcost;
-  pn_rdc = best_rdc;
-
-  // PARTITION_SPLIT
-  if (do_square_split) {
-    int reached_last_index = 0;
-    subsize = get_partition_subsize(bsize, PARTITION_SPLIT);
-    int idx;
-
-    sum_rdc.rate = partition_cost[PARTITION_SPLIT];
-    sum_rdc.rdcost = RDCOST(x->rdmult, sum_rdc.rate, 0);
-
-    for (idx = 0; idx < 4 && sum_rdc.rdcost < temp_best_rdcost; ++idx) {
-      const int x_idx = (idx & 1) * mi_step;
-      const int y_idx = (idx >> 1) * mi_step;
-
-      if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols)
-        continue;
-
-      if (cpi->sf.adaptive_motion_search) load_pred_mv(x, ctx_none);
-
-      pc_tree->split[idx]->index = idx;
-      int64_t *p_split_rd = &split_rd[idx];
-      const int64_t best_remain_rdcost =
-          (temp_best_rdcost == INT64_MAX) ? INT64_MAX
-                                          : (temp_best_rdcost - sum_rdc.rdcost);
-      rd_pick_sqr_partition(
-          cpi, td, tile_data, tp, mi_row + y_idx, mi_col + x_idx, subsize,
-          &this_rdc, best_remain_rdcost, pc_tree->split[idx], p_split_rd);
-
-      pc_tree->pc_tree_stats.sub_block_rdcost[idx] = this_rdc.rdcost;
-      pc_tree->pc_tree_stats.sub_block_skip[idx] =
-          pc_tree->split[idx]->none.rd_stats.skip;
-
-      if (this_rdc.rate == INT_MAX) {
-        sum_rdc.rdcost = INT64_MAX;
-        break;
-      } else {
-        sum_rdc.rate += this_rdc.rate;
-        sum_rdc.dist += this_rdc.dist;
-        sum_rdc.rdcost += this_rdc.rdcost;
-      }
-    }
-    reached_last_index = (idx == 4);
-
-    if (reached_last_index && sum_rdc.rdcost < best_rdc.rdcost) {
-      sum_rdc.rdcost = RDCOST(x->rdmult, sum_rdc.rate, sum_rdc.dist);
-
-      if (sum_rdc.rdcost < best_rdc.rdcost) {
-        best_rdc = sum_rdc;
-        pc_tree->partitioning = PARTITION_SPLIT;
-      }
-    }
-
-    int has_split = 0;
-    if (pc_tree->partitioning == PARTITION_SPLIT) {
-      for (int cb_idx = 0; cb_idx <= AOMMIN(idx, 3); ++cb_idx) {
-        if (pc_tree->split[cb_idx]->partitioning == PARTITION_SPLIT)
-          ++has_split;
-      }
-
-      if (has_split >= 3 || sum_rdc.rdcost < (pn_rdc.rdcost >> 1)) {
-        pc_tree->cb_search_range = SPLIT_PLANE;
-      }
-    }
-
-    if (pc_tree->partitioning == PARTITION_NONE) {
-      pc_tree->cb_search_range = SEARCH_SAME_PLANE;
-      if (pn_rdc.dist <= sum_rdc.dist)
-        pc_tree->cb_search_range = NONE_PARTITION_PLANE;
-    }
-
-    if (pn_rdc.rate == INT_MAX) pc_tree->cb_search_range = NONE_PARTITION_PLANE;
-
-    restore_context(x, &x_ctx, mi_row, mi_col, bsize, num_planes);
-  }  // if (do_split)
-
-  pc_tree->pc_tree_stats.split = pc_tree->partitioning == PARTITION_SPLIT;
-  if (do_square_split) {
-    for (int i = 0; i < 4; ++i) {
-      pc_tree->pc_tree_stats.sub_block_split[i] =
-          pc_tree->split[i]->partitioning == PARTITION_SPLIT;
-    }
-  }
-
-  // TODO(jbb): This code added so that we avoid static analysis
-  // warning related to the fact that best_rd isn't used after this
-  // point.  This code should be refactored so that the duplicate
-  // checks occur in some sub function and thus are used...
-  (void)best_rd;
-  *rd_cost = best_rdc;
-
-  if (best_rdc.rate < INT_MAX && best_rdc.dist < INT64_MAX &&
-      pc_tree->index != 3) {
-    if (bsize == cm->seq_params.sb_size) {
-      restore_context(x, &x_ctx, mi_row, mi_col, bsize, num_planes);
-    } else {
-      encode_sb(cpi, td, tile_data, tp, mi_row, mi_col, DRY_RUN_NORMAL, bsize,
-                pc_tree, NULL);
-    }
-  }
-
-  if (bsize == cm->seq_params.sb_size) {
-    assert(best_rdc.rate < INT_MAX);
-    assert(best_rdc.dist < INT64_MAX);
-  } else {
-    assert(tp_orig == *tp);
-  }
-}
-
 // Record the ref frames that have been selected by square partition blocks.
 static void update_picked_ref_frames_mask(MACROBLOCK *const x, int ref_type,
                                           BLOCK_SIZE bsize, int mib_size,
@@ -3691,23 +3390,6 @@
 }
 #undef NUM_SIMPLE_MOTION_FEATURES
 
-// Set all the counters as max.
-static void init_first_partition_pass_stats_tables(
-    AV1_COMP *cpi, FIRST_PARTITION_PASS_STATS *stats) {
-  for (int i = 0; i < FIRST_PARTITION_PASS_STATS_TABLES; ++i) {
-    memset(stats[i].ref0_counts, 0xff, sizeof(stats[i].ref0_counts));
-    memset(stats[i].ref1_counts, 0xff, sizeof(stats[i].ref1_counts));
-    stats[i].sample_counts = INT_MAX;
-    if (cpi->sf.use_first_partition_pass_interintra_stats)
-      memset(stats[i].interintra_motion_mode_count, 0xff,
-             sizeof(stats[i].interintra_motion_mode_count));
-  }
-}
-
-// Minimum number of samples to trigger the mode pruning in
-// two_pass_partition_search feature.
-#define FIRST_PARTITION_PASS_MIN_SAMPLES 16
-
 static int get_rdmult_delta(AV1_COMP *cpi, BLOCK_SIZE bsize, int mi_row,
                             int mi_col, int orig_rdmult) {
   assert(IMPLIES(cpi->twopass.gf_group.size > 0,
@@ -3918,82 +3600,6 @@
   }
 }
 
-// First pass of partition search only considers square partition block sizes.
-// The results will be used in the second partition search pass to prune
-// unlikely partition candidates.
-static void first_partition_search_pass(AV1_COMP *cpi, ThreadData *td,
-                                        TileDataEnc *tile_data, int mi_row,
-                                        int mi_col, TOKENEXTRA **tp) {
-  MACROBLOCK *const x = &td->mb;
-  x->cb_partition_scan = 1;
-
-  const SPEED_FEATURES *const sf = &cpi->sf;
-  // Reset the stats tables.
-  av1_zero(x->first_partition_pass_stats);
-
-  AV1_COMMON *const cm = &cpi->common;
-  const BLOCK_SIZE sb_size = cm->seq_params.sb_size;
-  const int mib_size_log2 = cm->seq_params.mib_size_log2;
-  PC_TREE *const pc_root = td->pc_root[mib_size_log2 - MIN_MIB_SIZE_LOG2];
-  RD_STATS dummy_rdc;
-  rd_pick_sqr_partition(cpi, td, tile_data, tp, mi_row, mi_col, sb_size,
-                        &dummy_rdc, INT64_MAX, pc_root, NULL);
-  x->cb_partition_scan = 0;
-
-  x->source_variance = UINT_MAX;
-  x->simple_motion_pred_sse = UINT_MAX;
-  if (sf->adaptive_pred_interp_filter) {
-    const int leaf_nodes = 256;
-    for (int i = 0; i < leaf_nodes; ++i) {
-      td->pc_tree[i].vertical[0].pred_interp_filter = SWITCHABLE;
-      td->pc_tree[i].vertical[1].pred_interp_filter = SWITCHABLE;
-      td->pc_tree[i].horizontal[0].pred_interp_filter = SWITCHABLE;
-      td->pc_tree[i].horizontal[1].pred_interp_filter = SWITCHABLE;
-    }
-  }
-
-  x->mb_rd_record.num = x->mb_rd_record.index_start = 0;
-  av1_zero(x->txb_rd_record_8X8);
-  av1_zero(x->txb_rd_record_16X16);
-  av1_zero(x->txb_rd_record_32X32);
-  av1_zero(x->txb_rd_record_64X64);
-  av1_zero(x->txb_rd_record_intra);
-  av1_zero(x->pred_mv);
-  pc_root->index = 0;
-
-  for (int idy = 0; idy < mi_size_high[sb_size]; ++idy) {
-    for (int idx = 0; idx < mi_size_wide[sb_size]; ++idx) {
-      const int offset = cm->mi_stride * (mi_row + idy) + (mi_col + idx);
-      cm->mi_grid_visible[offset] = 0;
-    }
-  }
-
-  x->use_cb_search_range = 1;
-
-  for (int i = 0; i < FIRST_PARTITION_PASS_STATS_TABLES; ++i) {
-    FIRST_PARTITION_PASS_STATS *const stat = &x->first_partition_pass_stats[i];
-    if (stat->sample_counts < FIRST_PARTITION_PASS_MIN_SAMPLES) {
-      // If there are not enough samples collected, make all available.
-      memset(stat->ref0_counts, 0xff, sizeof(stat->ref0_counts));
-      memset(stat->ref1_counts, 0xff, sizeof(stat->ref1_counts));
-      if (cpi->sf.use_first_partition_pass_interintra_stats)
-        memset(stat->interintra_motion_mode_count, 0xff,
-               sizeof(stat->interintra_motion_mode_count));
-    } else if (sf->selective_ref_frame < 3) {
-      // ALTREF2_FRAME and BWDREF_FRAME may be skipped during the
-      // initial partition scan, so we don't eliminate them.
-      stat->ref0_counts[ALTREF2_FRAME] = 0xff;
-      stat->ref1_counts[ALTREF2_FRAME] = 0xff;
-      stat->ref0_counts[BWDREF_FRAME] = 0xff;
-      stat->ref1_counts[BWDREF_FRAME] = 0xff;
-      if (cpi->sf.use_first_partition_pass_interintra_stats) {
-        stat->interintra_motion_mode_count[ALTREF2_FRAME] = 0xff;
-        stat->interintra_motion_mode_count[BWDREF_FRAME] = 0xff;
-      }
-    }
-  }
-}
-
 #define AVG_CDF_WEIGHT_LEFT 3
 #define AVG_CDF_WEIGHT_TOP_RIGHT 1
 
@@ -4356,22 +3962,6 @@
       adjust_rdmult_tpl_model(cpi, x, mi_row, mi_col);
       reset_partition(pc_root, sb_size);
       x->use_cb_search_range = 0;
-#if CONFIG_COLLECT_COMPONENT_TIMING
-      start_timing(cpi, first_partition_search_pass_time);
-#endif
-      init_first_partition_pass_stats_tables(cpi,
-                                             x->first_partition_pass_stats);
-      // Do the first pass if we need two pass partition search
-      if (cpi->two_pass_partition_search &&
-          cpi->sf.use_square_partition_only_threshold > BLOCK_4X4 &&
-          mi_row + mi_size_high[sb_size] <= cm->mi_rows &&
-          mi_col + mi_size_wide[sb_size] <= cm->mi_cols &&
-          cm->current_frame.frame_type != KEY_FRAME) {
-        first_partition_search_pass(cpi, td, tile_data, mi_row, mi_col, tp);
-      }
-#if CONFIG_COLLECT_COMPONENT_TIMING
-      end_timing(cpi, first_partition_search_pass_time);
-#endif
 
 #if CONFIG_COLLECT_COMPONENT_TIMING
       start_timing(cpi, rd_pick_partition_time);
@@ -4859,10 +4449,6 @@
 
   av1_zero(*td->counts);
   av1_zero(rdc->comp_pred_diff);
-  // Two pass partition search can be enabled/disabled for different frames.
-  // Reset this data at frame level to avoid any incorrect usage.
-  if (!cpi->sf.use_nonrd_pick_mode)
-    init_first_partition_pass_stats_tables(cpi, x->first_partition_pass_stats);
 
   // Reset the flag.
   cpi->intrabc_used = 0;
@@ -5586,33 +5172,6 @@
   const int mi_height = mi_size_high[bsize];
   const int is_inter = is_inter_block(mbmi);
 
-  if (cpi->two_pass_partition_search && x->cb_partition_scan) {
-    for (int row = mi_row; row < mi_row + mi_width;
-         row += FIRST_PARTITION_PASS_SAMPLE_REGION) {
-      for (int col = mi_col; col < mi_col + mi_height;
-           col += FIRST_PARTITION_PASS_SAMPLE_REGION) {
-        const int index = av1_first_partition_pass_stats_index(row, col);
-        FIRST_PARTITION_PASS_STATS *const stats =
-            &x->first_partition_pass_stats[index];
-        // Increase the counter of data samples.
-        ++stats->sample_counts;
-        // Increase the counter for ref_frame[0] and ref_frame[1].
-        if (stats->ref0_counts[mbmi->ref_frame[0]] < 255)
-          ++stats->ref0_counts[mbmi->ref_frame[0]];
-        if (mbmi->ref_frame[1] >= 0 &&
-            stats->ref1_counts[mbmi->ref_frame[1]] < 255)
-          ++stats->ref1_counts[mbmi->ref_frame[1]];
-        if (cpi->sf.use_first_partition_pass_interintra_stats) {
-          // Increase the counter for interintra_motion_mode_count
-          if (mbmi->motion_mode == 0 && mbmi->ref_frame[1] == INTRA_FRAME &&
-              stats->interintra_motion_mode_count[mbmi->ref_frame[0]] < 255) {
-            ++stats->interintra_motion_mode_count[mbmi->ref_frame[0]];
-          }
-        }
-      }
-    }
-  }
-
   if (!is_inter) {
     xd->cfl.is_chroma_reference =
         is_chroma_reference(mi_row, mi_col, bsize, cm->seq_params.subsampling_x,
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 2650bfe..8bc0124 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -4840,9 +4840,6 @@
   if (cpi->oxcf.pass == 2 && cpi->sf.adaptive_interp_filter_search)
     cpi->sf.interp_filter_search_mask = setup_interp_filter_search_mask(cpi);
 
-  cpi->two_pass_partition_search = cpi->sf.two_pass_partition_search &&
-                                   !cpi->partition_search_skippable_frame;
-
   if (encode_show_existing_frame(cm)) {
     restore_coding_context(cpi);
 
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index d4b1a36..2b6ff18 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -669,7 +669,6 @@
   av1_compute_global_motion_time,
   av1_setup_motion_field_time,
   encode_sb_time,
-  first_partition_search_pass_time,
   rd_pick_partition_time,
   rd_pick_sb_modes_time,
   av1_rd_pick_intra_mode_sb_time,
@@ -697,8 +696,6 @@
       return "av1_compute_global_motion_time";
     case av1_setup_motion_field_time: return "av1_setup_motion_field_time";
     case encode_sb_time: return "encode_sb_time";
-    case first_partition_search_pass_time:
-      return "first_partition_search_pass_time";
     case rd_pick_partition_time: return "rd_pick_partition_time";
     case rd_pick_sb_modes_time: return "rd_pick_sb_modes_time";
     case av1_rd_pick_intra_mode_sb_time:
@@ -747,8 +744,6 @@
 
   // For a still frame, this flag is set to 1 to skip partition search.
   int partition_search_skippable_frame;
-  // The following item corresponds to two_pass_partition_search speed features.
-  int two_pass_partition_search;
 
   double csm_rate_array[32];
   double m_rate_array[32];
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 67b3b2e..edffe9e 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -3043,7 +3043,7 @@
       (is_inter && x->use_default_inter_tx_type)) {
     txk_allowed =
         get_default_tx_type(0, xd, tx_size, cpi->is_screen_content_type);
-  } else if (x->rd_model == LOW_TXFM_RD || x->cb_partition_scan) {
+  } else if (x->rd_model == LOW_TXFM_RD) {
     if (plane == 0) txk_allowed = DCT_DCT;
   }
 
@@ -3121,8 +3121,7 @@
 #endif
   int calc_pixel_domain_distortion_final =
       cpi->sf.use_transform_domain_distortion == 1 &&
-      use_transform_domain_distortion && x->rd_model != LOW_TXFM_RD &&
-      !x->cb_partition_scan;
+      use_transform_domain_distortion && x->rd_model != LOW_TXFM_RD;
   if (calc_pixel_domain_distortion_final &&
       (txk_allowed < TX_TYPES || allowed_tx_mask == 0x0001))
     calc_pixel_domain_distortion_final = use_transform_domain_distortion = 0;
@@ -5210,7 +5209,7 @@
     }
   }
 
-  if (x->e_mbd.bd == 8 && !x->cb_partition_scan && try_split &&
+  if (x->e_mbd.bd == 8 && try_split &&
       !(ref_best_rd == INT64_MAX && no_split.rd == INT64_MAX)) {
     const int threshold = cpi->sf.tx_type_search.ml_tx_split_thresh;
     if (threshold >= 0) {
@@ -9174,36 +9173,6 @@
   return mv_field_check_ctxt.mv_field_check_result;
 }
 
-static int skip_interintra_based_on_first_pass_stats(const AV1_COMP *const cpi,
-                                                     MACROBLOCK *const x,
-                                                     BLOCK_SIZE bsize,
-                                                     int mi_row, int mi_col) {
-  MACROBLOCKD *xd = &x->e_mbd;
-  MB_MODE_INFO *mbmi = xd->mi[0];
-  if (cpi->two_pass_partition_search &&
-      cpi->sf.use_first_partition_pass_interintra_stats &&
-      !x->cb_partition_scan) {
-    const int mi_width = mi_size_wide[bsize];
-    const int mi_height = mi_size_high[bsize];
-    // Search in the stats table to see if obmc motion mode was used in the
-    // first pass of partition search.
-    for (int row = mi_row; row < mi_row + mi_width;
-         row += FIRST_PARTITION_PASS_SAMPLE_REGION) {
-      for (int col = mi_col; col < mi_col + mi_height;
-           col += FIRST_PARTITION_PASS_SAMPLE_REGION) {
-        const int index = av1_first_partition_pass_stats_index(row, col);
-        const FIRST_PARTITION_PASS_STATS *const stats =
-            &x->first_partition_pass_stats[index];
-        if (stats->interintra_motion_mode_count[mbmi->ref_frame[0]]) {
-          return 0;
-        }
-      }
-    }
-    return 1;
-  }
-  return 0;
-}
-
 // TODO(afergs): Refactor the MBMI references in here - there's four
 // TODO(afergs): Refactor optional args - add them to a struct or remove
 static int64_t motion_mode_rd(
@@ -9224,7 +9193,6 @@
   RD_STATS best_rd_stats, best_rd_stats_y, best_rd_stats_uv;
   uint8_t best_blk_skip[MAX_MIB_SIZE * MAX_MIB_SIZE];
   const int rate_mv0 = *rate_mv;
-  int skip_interintra_mode = 0;
   const int interintra_allowed = cm->seq_params.enable_interintra_compound &&
                                  is_interintra_allowed(mbmi) &&
                                  mbmi->compound_idx;
@@ -9407,9 +9375,6 @@
         continue;
       }
     } else if (is_interintra_mode) {
-      skip_interintra_mode = skip_interintra_based_on_first_pass_stats(
-          cpi, x, bsize, mi_row, mi_col);
-      if (skip_interintra_mode) continue;
       const int ret = handle_inter_intra_mode(
           cpi, x, bsize, mi_row, mi_col, mbmi, args, ref_best_rd, &tmp_rate_mv,
           &tmp_rate2, orig_dst);
@@ -11757,8 +11722,7 @@
 // Case 2: return 1, means skip this mode completely
 // Case 3: return 2, means skip compound only, but still try single motion modes
 static int inter_mode_search_order_independent_skip(
-    const AV1_COMP *cpi, const MACROBLOCK *x, BLOCK_SIZE bsize, int mi_row,
-    int mi_col, mode_skip_mask_t *mode_skip_mask,
+    const AV1_COMP *cpi, const MACROBLOCK *x, mode_skip_mask_t *mode_skip_mask,
     InterModeSearchState *search_state, int skip_ref_frame_mask) {
   const SPEED_FEATURES *const sf = &cpi->sf;
   const AV1_COMMON *const cm = &cpi->common;
@@ -11807,29 +11771,6 @@
     if (skip_ref) return 1;
   }
 
-  if (cpi->two_pass_partition_search && !x->cb_partition_scan) {
-    const int mi_width = mi_size_wide[bsize];
-    const int mi_height = mi_size_high[bsize];
-    int found = 0;
-    // Search in the stats table to see if the ref frames have been used in the
-    // first pass of partition search.
-    for (int row = mi_row; row < mi_row + mi_width && !found;
-         row += FIRST_PARTITION_PASS_SAMPLE_REGION) {
-      for (int col = mi_col; col < mi_col + mi_height && !found;
-           col += FIRST_PARTITION_PASS_SAMPLE_REGION) {
-        const int index = av1_first_partition_pass_stats_index(row, col);
-        const FIRST_PARTITION_PASS_STATS *const stats =
-            &x->first_partition_pass_stats[index];
-        if (stats->ref0_counts[ref_frame[0]] &&
-            (ref_frame[1] < 0 || stats->ref1_counts[ref_frame[1]])) {
-          found = 1;
-          break;
-        }
-      }
-    }
-    if (!found) return 1;
-  }
-
   // This is only used in motion vector unit test.
   if (cpi->oxcf.motion_vector_unit_test && ref_frame[0] == INTRA_FRAME)
     return 1;
@@ -11847,7 +11788,7 @@
   }
 
   if (sf->selective_ref_frame) {
-    if (sf->selective_ref_frame >= 3 || x->cb_partition_scan) {
+    if (sf->selective_ref_frame >= 3) {
       if (ref_frame[0] == ALTREF2_FRAME || ref_frame[1] == ALTREF2_FRAME)
         if (get_relative_dist(
                 order_hint_info,
@@ -12677,8 +12618,7 @@
     if (inter_mode_compatible_skip(cpi, x, bsize, midx)) continue;
 
     const int ret = inter_mode_search_order_independent_skip(
-        cpi, x, bsize, mi_row, mi_col, &mode_skip_mask, &search_state,
-        skip_ref_frame_mask);
+        cpi, x, &mode_skip_mask, &search_state, skip_ref_frame_mask);
     if (ret == 1) continue;
     args.skip_motion_mode = (ret == 2);
 
@@ -13321,8 +13261,7 @@
     if (inter_mode_compatible_skip(cpi, x, bsize, midx)) continue;
 
     const int ret = inter_mode_search_order_independent_skip(
-        cpi, x, bsize, mi_row, mi_col, &mode_skip_mask, &search_state,
-        skip_ref_frame_mask);
+        cpi, x, &mode_skip_mask, &search_state, skip_ref_frame_mask);
     if (ret == 1) continue;
     args.skip_motion_mode = (ret == 2);
 
diff --git a/av1/encoder/speed_features.c b/av1/encoder/speed_features.c
index 6f4ac9c..eab4998 100644
--- a/av1/encoder/speed_features.c
+++ b/av1/encoder/speed_features.c
@@ -171,8 +171,6 @@
       sf->partition_search_breakout_dist_thr = (1 << 23);
       sf->partition_search_breakout_rate_thr = 120;
     }
-    sf->use_first_partition_pass_interintra_stats =
-        sf->two_pass_partition_search;
 
     // TODO(Venkat): Clean-up frame type dependency for
     // simple_motion_search_split in partition search function and set the
@@ -710,7 +708,6 @@
   sf->allow_partition_search_skip = 0;
   sf->use_accurate_subpel_search = USE_8_TAPS;
   sf->disable_wedge_search_edge_thresh = 0;
-  sf->use_first_partition_pass_interintra_stats = 0;
   sf->disable_wedge_search_var_thresh = 0;
   sf->disable_loop_restoration_chroma = 0;
   sf->enable_sgr_ep_pruning = 0;
@@ -721,7 +718,6 @@
   sf->skip_intra_in_interframe = 1;
   sf->txb_split_cap = 1;
   sf->adaptive_txb_search_level = 0;
-  sf->two_pass_partition_search = 0;
   sf->firstpass_simple_motion_search_early_term = 0;
   sf->use_intra_txb_hash = 0;
   sf->use_inter_txb_hash = 1;
diff --git a/av1/encoder/speed_features.h b/av1/encoder/speed_features.h
index 193ef74..ce7f0ac 100644
--- a/av1/encoder/speed_features.h
+++ b/av1/encoder/speed_features.h
@@ -372,10 +372,6 @@
   // Use a ML model to prune horz and vert partitions
   int ml_prune_rect_partition;
 
-  // Disable/Enable interintra motion mode based on stats collected during
-  // first_partition_search_pass
-  int use_first_partition_pass_interintra_stats;
-
   // Use a ML model to prune horz_a, horz_b, vert_a and vert_b partitions.
   int ml_prune_ab_partition;
 
@@ -387,10 +383,6 @@
   // 1 - 2 increasing aggressiveness in order.
   int ml_early_term_after_part_split_level;
 
-  // 2-pass coding block partition search, and also use the mode decisions made
-  // in the initial partition search to prune mode candidates, e.g. ref frames.
-  int two_pass_partition_search;
-
   // Terminate early in firstpass of two_pass partition search for faster
   // firstpass.
   int firstpass_simple_motion_search_early_term;