aom: Add the CONFIG_SVT_AV1 cmake option

From dc8a68933b13dd1beceded8c072afddd9ad7bd9b Mon Sep 17 00:00:00 2001
From: Wan-Teh Chang <[EMAIL REDACTED]>
Date: Tue, 13 Aug 2024 15:48:28 -0700
Subject: [PATCH] Add the CONFIG_SVT_AV1 cmake option

If CONFIG_SVT_AV1 (default: 1) is set to 0, third_party/SVT-AV1 won't be
used.

Bug: 359670383
Change-Id: Ibe9a86abb0b900ac389f522bafde587577edc340
---
 aom_dsp/aom_dsp.cmake                 | 16 ++++++++++------
 av1/common/filter.h                   |  4 ++++
 av1/common/x86/convolve_2d_avx2.c     |  8 ++++++++
 av1/common/x86/convolve_avx2.c        | 12 ++++++++++++
 build/cmake/aom_config_defaults.cmake |  3 +++
 5 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/aom_dsp/aom_dsp.cmake b/aom_dsp/aom_dsp.cmake
index b021b0824..46e6da312 100644
--- a/aom_dsp/aom_dsp.cmake
+++ b/aom_dsp/aom_dsp.cmake
@@ -93,12 +93,16 @@ list(APPEND AOM_DSP_COMMON_INTRIN_AVX2
             "${AOM_ROOT}/aom_dsp/x86/intrapred_avx2.c"
             "${AOM_ROOT}/aom_dsp/x86/loopfilter_avx2.c"
             "${AOM_ROOT}/aom_dsp/x86/blend_a64_mask_avx2.c"
-            "${AOM_ROOT}/aom_dsp/x86/bitdepth_conversion_avx2.h"
-            "${AOM_ROOT}/third_party/SVT-AV1/convolve_2d_avx2.h"
-            "${AOM_ROOT}/third_party/SVT-AV1/convolve_avx2.h"
-            "${AOM_ROOT}/third_party/SVT-AV1/EbMemory_AVX2.h"
-            "${AOM_ROOT}/third_party/SVT-AV1/EbMemory_SSE4_1.h"
-            "${AOM_ROOT}/third_party/SVT-AV1/synonyms.h")
+            "${AOM_ROOT}/aom_dsp/x86/bitdepth_conversion_avx2.h")
+
+if(CONFIG_SVT_AV1)
+  list(APPEND AOM_DSP_COMMON_INTRIN_AVX2
+              "${AOM_ROOT}/third_party/SVT-AV1/convolve_2d_avx2.h"
+              "${AOM_ROOT}/third_party/SVT-AV1/convolve_avx2.h"
+              "${AOM_ROOT}/third_party/SVT-AV1/EbMemory_AVX2.h"
+              "${AOM_ROOT}/third_party/SVT-AV1/EbMemory_SSE4_1.h"
+              "${AOM_ROOT}/third_party/SVT-AV1/synonyms.h")
+endif()
 
 list(APPEND AOM_DSP_COMMON_INTRIN_NEON
             "${AOM_ROOT}/aom_dsp/arm/aom_convolve_copy_neon.c"
diff --git a/av1/common/filter.h b/av1/common/filter.h
index 7073da2ad..d1b76bd5a 100644
--- a/av1/common/filter.h
+++ b/av1/common/filter.h
@@ -307,10 +307,14 @@ static inline int get_filter_tap(const InterpFilterParams *const filter_params,
   if (filter[1] | filter[6]) {
     return 6;
   }
+#if CONFIG_SVT_AV1
   if (filter[2] | filter[5]) {
     return 4;
   }
   return 2;
+#else
+  return 4;
+#endif
 }
 
 #ifdef __cplusplus
diff --git a/av1/common/x86/convolve_2d_avx2.c b/av1/common/x86/convolve_2d_avx2.c
index e3ba0f19e..521326cab 100644
--- a/av1/common/x86/convolve_2d_avx2.c
+++ b/av1/common/x86/convolve_2d_avx2.c
@@ -13,7 +13,9 @@
 
 #include "config/av1_rtcd.h"
 
+#if CONFIG_SVT_AV1
 #include "third_party/SVT-AV1/convolve_2d_avx2.h"
+#endif
 
 #include "aom_dsp/x86/convolve_avx2.h"
 #include "aom_dsp/aom_filter.h"
@@ -143,6 +145,7 @@ void av1_convolve_2d_sr_avx2(
     int32_t w, int32_t h, const InterpFilterParams *filter_params_x,
     const InterpFilterParams *filter_params_y, const int32_t subpel_x_qn,
     const int32_t subpel_y_qn, ConvolveParams *conv_params) {
+#if CONFIG_SVT_AV1
   const int32_t tap_x = get_filter_tap(filter_params_x, subpel_x_qn);
   const int32_t tap_y = get_filter_tap(filter_params_y, subpel_y_qn);
 
@@ -156,4 +159,9 @@ void av1_convolve_2d_sr_avx2(
                                         filter_params_x, filter_params_y,
                                         subpel_x_qn, subpel_y_qn, conv_params);
   }
+#else
+  convolve_2d_sr_general_avx2(src, src_stride, dst, dst_stride, w, h,
+                              filter_params_x, filter_params_y, subpel_x_qn,
+                              subpel_y_qn, conv_params);
+#endif
 }
diff --git a/av1/common/x86/convolve_avx2.c b/av1/common/x86/convolve_avx2.c
index dddaa4bca..d250d8842 100644
--- a/av1/common/x86/convolve_avx2.c
+++ b/av1/common/x86/convolve_avx2.c
@@ -13,7 +13,9 @@
 
 #include "config/av1_rtcd.h"
 
+#if CONFIG_SVT_AV1
 #include "third_party/SVT-AV1/convolve_avx2.h"
+#endif
 
 #include "aom_dsp/aom_dsp_common.h"
 #include "aom_dsp/x86/convolve_avx2.h"
@@ -513,6 +515,7 @@ void av1_convolve_y_sr_avx2(const uint8_t *src, int32_t src_stride,
                             int32_t h,
                             const InterpFilterParams *filter_params_y,
                             const int32_t subpel_y_qn) {
+#if CONFIG_SVT_AV1
   const int vert_tap = get_filter_tap(filter_params_y, subpel_y_qn);
 
   if (vert_tap == 12) {
@@ -522,6 +525,10 @@ void av1_convolve_y_sr_avx2(const uint8_t *src, int32_t src_stride,
     av1_convolve_y_sr_specialized_avx2(src, src_stride, dst, dst_stride, w, h,
                                        filter_params_y, subpel_y_qn);
   }
+#else
+  av1_convolve_y_sr_general_avx2(src, src_stride, dst, dst_stride, w, h,
+                                 filter_params_y, subpel_y_qn);
+#endif
 }
 
 static inline void av1_convolve_x_sr_general_avx2(
@@ -903,6 +910,7 @@ void av1_convolve_x_sr_avx2(const uint8_t *src, int32_t src_stride,
                             const InterpFilterParams *filter_params_x,
                             const int32_t subpel_x_qn,
                             ConvolveParams *conv_params) {
+#if CONFIG_SVT_AV1
   const int horz_tap = get_filter_tap(filter_params_x, subpel_x_qn);
 
   if (horz_tap == 12) {
@@ -913,4 +921,8 @@ void av1_convolve_x_sr_avx2(const uint8_t *src, int32_t src_stride,
                                        filter_params_x, subpel_x_qn,
                                        conv_params);
   }
+#else
+  av1_convolve_x_sr_general_avx2(src, src_stride, dst, dst_stride, w, h,
+                                 filter_params_x, subpel_x_qn, conv_params);
+#endif
 }
diff --git a/build/cmake/aom_config_defaults.cmake b/build/cmake/aom_config_defaults.cmake
index 2f11828ff..ae0842c6e 100644
--- a/build/cmake/aom_config_defaults.cmake
+++ b/build/cmake/aom_config_defaults.cmake
@@ -75,6 +75,9 @@ set_aom_config_var(CONFIG_GCC 0 "Building with GCC (detect).")
 set_aom_config_var(CONFIG_GCOV 0 "Enable gcov support.")
 set_aom_config_var(CONFIG_GPROF 0 "Enable gprof support.")
 set_aom_config_var(CONFIG_LIBYUV 1 "Enables libyuv scaling/conversion support.")
+# Set CONFIG_SVT_AV1 to 0 to avoid the BSD 3-Clause Clear License used by the
+# code in third_party/SVT-AV1/.
+set_aom_config_var(CONFIG_SVT_AV1 1 "Enables SVT-AV1 AVX2 convolution support.")
 
 set_aom_config_var(CONFIG_AV1_HIGHBITDEPTH 1
                    "Build with high bitdepth support.")