Fix NRS named ref dependencies

This removes dependencies of named references in SVC and
nonrd pickmode

Change-Id: I86ee39da599a58ba7b720316bba82786fd25f9da
diff --git a/av1/encoder/nonrd_pickmode.c b/av1/encoder/nonrd_pickmode.c
index 27bd22f..1feac3d 100644
--- a/av1/encoder/nonrd_pickmode.c
+++ b/av1/encoder/nonrd_pickmode.c
@@ -2199,6 +2199,9 @@
 
 static AOM_INLINE int skip_mode_by_threshold(
     PREDICTION_MODE mode, MV_REFERENCE_FRAME ref_frame, int_mv mv,
+#if CONFIG_NEW_REF_SIGNALING
+    const AV1_COMMON *const cm,
+#endif  // CONFIG_NEW_REF_SIGNALING
     int frames_since_golden, const int *const rd_threshes,
     const int *const rd_thresh_freq_fact, int64_t best_cost, int best_skip) {
   int skip_this_mode = 0;
@@ -2212,11 +2215,20 @@
 
   // Increase mode_rd_thresh value for non-LAST for improved encoding
   // speed
+#if CONFIG_NEW_REF_SIGNALING
+  if (ref_frame != get_closest_pastcur_ref_index(cm)) {
+    mode_rd_thresh = mode_rd_thresh << 1;
+    if (ref_frame == cm->new_ref_frame_data.past_refs[0] &&
+        frames_since_golden > 4)
+      mode_rd_thresh = mode_rd_thresh << 1;
+  }
+#else
   if (ref_frame != LAST_FRAME) {
     mode_rd_thresh = mode_rd_thresh << 1;
     if (ref_frame == GOLDEN_FRAME && frames_since_golden > 4)
       mode_rd_thresh = mode_rd_thresh << 1;
   }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
 #if CONFIG_NEW_REF_SIGNALING
   if (rd_less_than_thresh(best_cost, mode_rd_thresh, rd_thresh_freq_fact[mode]))
@@ -2232,12 +2244,21 @@
 static AOM_INLINE int skip_mode_by_low_temp(PREDICTION_MODE mode,
                                             MV_REFERENCE_FRAME ref_frame,
                                             BLOCK_SIZE bsize,
+#if CONFIG_NEW_REF_SIGNALING
+                                            const AV1_COMMON *const cm,
+#endif  // CONFIG_NEW_REF_SIGNALING
                                             int content_state_sb, int_mv mv,
                                             int force_skip_low_temp_var) {
   // Skip non-zeromv mode search for non-LAST frame if force_skip_low_temp_var
   // is set. If nearestmv for golden frame is 0, zeromv mode will be skipped
   // later.
-  if (force_skip_low_temp_var && ref_frame != LAST_FRAME && mv.as_int != 0) {
+  if (force_skip_low_temp_var &&
+#if CONFIG_NEW_REF_SIGNALING
+      ref_frame != get_closest_pastcur_ref_index(cm) &&
+#else
+      ref_frame != LAST_FRAME &&
+#endif  // CONFIG_NEW_REF_SIGNALING
+      mv.as_int != 0) {
     return 1;
   }
 
@@ -2504,7 +2525,11 @@
                                          sse_zeromv_norm))
       continue;
 
-    if (skip_mode_by_low_temp(this_mode, ref_frame, bsize, x->content_state_sb,
+    if (skip_mode_by_low_temp(this_mode, ref_frame, bsize,
+#if CONFIG_NEW_REF_SIGNALING
+                              cm,
+#endif  // CONFIG_NEW_REF_SIGNALING
+                              x->content_state_sb,
                               frame_mv[this_mode][ref_frame],
                               force_skip_low_temp_var))
       continue;
@@ -2530,6 +2555,9 @@
 
     if (skip_mode_by_threshold(
             this_mode, ref_frame, frame_mv[this_mode][ref_frame],
+#if CONFIG_NEW_REF_SIGNALING
+            cm,
+#endif  // CONFIG_NEW_REF_SIGNALING
             cpi->rc.frames_since_golden, rd_threshes, rd_thresh_freq_fact,
             best_rdc.rdcost, best_pickmode.best_mode_skip_txfm))
       continue;
diff --git a/av1/encoder/svc_layercontext.c b/av1/encoder/svc_layercontext.c
index 412bf0e..650b060 100644
--- a/av1/encoder/svc_layercontext.c
+++ b/av1/encoder/svc_layercontext.c
@@ -204,6 +204,18 @@
   // This is to skip testing nonzero-mv for that reference if it was last
   // refreshed (i.e., buffer slot holding that reference was refreshed) on the
   // previous spatial layer(s) at the same time (current_superframe).
+#if CONFIG_NEW_REF_SIGNALING
+  if (svc->external_ref_frame_config && svc->force_zero_mode_spatial_ref) {
+    int ref_frame_idx = svc->ref_idx[get_closest_pastcur_ref_index(cm)];
+    if (svc->buffer_time_index[ref_frame_idx] == svc->current_superframe &&
+        svc->buffer_spatial_layer[ref_frame_idx] <= svc->spatial_layer_id - 1)
+      svc->skip_nonzeromv_last = 1;
+    ref_frame_idx = svc->ref_idx[cm->new_ref_frame_data.past_refs[0]];
+    if (svc->buffer_time_index[ref_frame_idx] == svc->current_superframe &&
+        svc->buffer_spatial_layer[ref_frame_idx] <= svc->spatial_layer_id - 1)
+      svc->skip_nonzeromv_gf = 1;
+  }
+#else
   if (svc->external_ref_frame_config && svc->force_zero_mode_spatial_ref) {
     int ref_frame_idx = svc->ref_idx[LAST_FRAME - 1];
     if (svc->buffer_time_index[ref_frame_idx] == svc->current_superframe &&
@@ -214,6 +226,7 @@
         svc->buffer_spatial_layer[ref_frame_idx] <= svc->spatial_layer_id - 1)
       svc->skip_nonzeromv_gf = 1;
   }
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 void av1_save_layer_context(AV1_COMP *const cpi) {