aom: rtc: Move force_zeromv_skip logic up in nonrd_pickmode

From 608f9241e2d426b8817b7036457f10c336a69965 Mon Sep 17 00:00:00 2001
From: Marco Paniconi <[EMAIL REDACTED]>
Date: Mon, 8 Apr 2024 10:34:11 -0700
Subject: [PATCH] rtc: Move force_zeromv_skip logic up in nonrd_pickmode

Move the skip logic for force_zeromv_for_blk further up
in the nonrd_pickmode, to avoid possible conflict with
the sb_me_block feature, which has an early exit that
conflict with force_zeromv_skip. Currently this has no
effect, but change it now in case the sb_me_block feature
is modified.

We also need to move up the check on use_ref_frame_mask,
otherwise the frame_mv (in the force_zeromv_skip_for_blk check)
may not be set. This is a re-application of the patch
https://aomedia-review.googlesource.com/c/aom/+/188741, with
the fix for the valgrind issue.

Bitexact on screen, with neutral IC speedup.

Change-Id: I33d4fcb25022abf43a109e7412cf7ea6b12f053b
---
 av1/encoder/nonrd_pickmode.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/av1/encoder/nonrd_pickmode.c b/av1/encoder/nonrd_pickmode.c
index 57c74f66d..fdc10ded5 100644
--- a/av1/encoder/nonrd_pickmode.c
+++ b/av1/encoder/nonrd_pickmode.c
@@ -2361,6 +2361,18 @@ static AOM_FORCE_INLINE bool skip_inter_mode_nonrd(
       (*this_mode != GLOBALMV || *ref_frame != LAST_FRAME))
     return true;
 
+  // Skip the mode if use reference frame mask flag is not set.
+  if (!search_state->use_ref_frame_mask[*ref_frame]) return true;
+
+  // Skip mode for some modes and reference frames when
+  // force_zeromv_skip_for_blk flag is true.
+  if (x->force_zeromv_skip_for_blk &&
+      ((!(*this_mode == NEARESTMV &&
+          search_state->frame_mv[*this_mode][*ref_frame].as_int == 0) &&
+        *this_mode != GLOBALMV) ||
+       *ref_frame != LAST_FRAME))
+    return true;
+
   if (x->sb_me_block && *ref_frame == LAST_FRAME) {
     // We want to make sure to test the superblock MV:
     // so don't skip (return false) for NEAREST_LAST or NEAR_LAST if they
@@ -2400,18 +2412,6 @@ static AOM_FORCE_INLINE bool skip_inter_mode_nonrd(
   mi->ref_frame[0] = *ref_frame;
   mi->ref_frame[1] = *ref_frame2;
 
-  // Skip the mode if use reference frame mask flag is not set.
-  if (!search_state->use_ref_frame_mask[*ref_frame]) return true;
-
-  // Skip mode for some modes and reference frames when
-  // force_zeromv_skip_for_blk flag is true.
-  if (x->force_zeromv_skip_for_blk &&
-      ((!(*this_mode == NEARESTMV &&
-          search_state->frame_mv[*this_mode][*ref_frame].as_int == 0) &&
-        *this_mode != GLOBALMV) ||
-       *ref_frame != LAST_FRAME))
-    return true;
-
   // Skip compound mode based on variance of previously evaluated single
   // reference modes.
   if (rt_sf->prune_compoundmode_with_singlemode_var && !*is_single_pred &&