shithub: dav1d

Download patch

ref: 96da9cc232b4b238bcd215025d075039a5b0a86f
parent: 8fb306575cef9c1882cfc693b1c47e68e27fc71a
author: Martin Storsjö <martin@martin.st>
date: Tue Feb 4 16:03:18 EST 2020

looprestoration: Add a bpc parameter to the init func

This allows using completely different codepaths for 10 and 12 bpc,
or just adding SIMD functions for either of them.

--- a/src/arm/looprestoration_init_tmpl.c
+++ b/src/arm/looprestoration_init_tmpl.c
@@ -270,7 +270,7 @@
 }
 #endif // BITDEPTH == 8
 
-COLD void bitfn(dav1d_loop_restoration_dsp_init_arm)(Dav1dLoopRestorationDSPContext *const c) {
+COLD void bitfn(dav1d_loop_restoration_dsp_init_arm)(Dav1dLoopRestorationDSPContext *const c, int bpc) {
     const unsigned flags = dav1d_get_cpu_flags();
 
     if (!(flags & DAV1D_ARM_CPU_FLAG_NEON)) return;
--- a/src/decode.c
+++ b/src/decode.c
@@ -3242,7 +3242,7 @@
             dav1d_intra_pred_dsp_init_##bd##bpc(&dsp->ipred); \
             dav1d_itx_dsp_init_##bd##bpc(&dsp->itx); \
             dav1d_loop_filter_dsp_init_##bd##bpc(&dsp->lf); \
-            dav1d_loop_restoration_dsp_init_##bd##bpc(&dsp->lr); \
+            dav1d_loop_restoration_dsp_init_##bd##bpc(&dsp->lr, bpc); \
             dav1d_mc_dsp_init_##bd##bpc(&dsp->mc); \
             dav1d_film_grain_dsp_init_##bd##bpc(&dsp->fg); \
             break
--- a/src/looprestoration.h
+++ b/src/looprestoration.h
@@ -72,8 +72,8 @@
     selfguided_fn selfguided;
 } Dav1dLoopRestorationDSPContext;
 
-bitfn_decls(void dav1d_loop_restoration_dsp_init, Dav1dLoopRestorationDSPContext *c);
-bitfn_decls(void dav1d_loop_restoration_dsp_init_arm, Dav1dLoopRestorationDSPContext *c);
+bitfn_decls(void dav1d_loop_restoration_dsp_init, Dav1dLoopRestorationDSPContext *c, int bpc);
+bitfn_decls(void dav1d_loop_restoration_dsp_init_arm, Dav1dLoopRestorationDSPContext *c, int bpc);
 bitfn_decls(void dav1d_loop_restoration_dsp_init_x86, Dav1dLoopRestorationDSPContext *c);
 bitfn_decls(void dav1d_loop_restoration_dsp_init_ppc, Dav1dLoopRestorationDSPContext *c);
 
--- a/src/looprestoration_tmpl.c
+++ b/src/looprestoration_tmpl.c
@@ -573,13 +573,13 @@
     }
 }
 
-COLD void bitfn(dav1d_loop_restoration_dsp_init)(Dav1dLoopRestorationDSPContext *const c) {
+COLD void bitfn(dav1d_loop_restoration_dsp_init)(Dav1dLoopRestorationDSPContext *const c, int bpc) {
     c->wiener = wiener_c;
     c->selfguided = selfguided_c;
 
 #if HAVE_ASM
 #if ARCH_AARCH64 || ARCH_ARM
-    bitfn(dav1d_loop_restoration_dsp_init_arm)(c);
+    bitfn(dav1d_loop_restoration_dsp_init_arm)(c, bpc);
 #elif ARCH_PPC64LE
     bitfn(dav1d_loop_restoration_dsp_init_ppc)(c);
 #elif ARCH_X86
--- a/tests/checkasm/looprestoration.c
+++ b/tests/checkasm/looprestoration.c
@@ -43,7 +43,7 @@
     }
 }
 
-static void check_wiener(Dav1dLoopRestorationDSPContext *const c) {
+static void check_wiener(Dav1dLoopRestorationDSPContext *const c, const int bpc) {
     ALIGN_STK_64(pixel, c_dst, 448 * 64,);
     ALIGN_STK_64(pixel, a_dst, 448 * 64,);
     ALIGN_STK_64(pixel, h_edge, 448 * 8,);
@@ -58,7 +58,7 @@
 
     for (int pl = 0; pl < 2; pl++) {
         if (check_func(c->wiener, "wiener_%s_%dbpc",
-                       pl ? "chroma" : "luma", BITDEPTH))
+                       pl ? "chroma" : "luma", bpc))
         {
             int16_t filter[2][3], filter_v[7], filter_h[7];
 
@@ -81,11 +81,7 @@
 
             const int base_w = 1 + (rnd() % 384);
             const int base_h = 1 + (rnd() & 63);
-#if BITDEPTH == 16
-            const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
-#else
-            const int bitdepth_max = 0xff;
-#endif
+            const int bitdepth_max = (1 << bpc) - 1;
 
             init_tmp(c_dst, 448 * sizeof(pixel), 448, 64, bitdepth_max);
             init_tmp(h_edge, 448 * sizeof(pixel), 448, 8, bitdepth_max);
@@ -112,10 +108,9 @@
                       256, 64, filter_h, filter_v, 0xf HIGHBD_TAIL_SUFFIX);
         }
     }
-    report("wiener");
 }
 
-static void check_sgr(Dav1dLoopRestorationDSPContext *const c) {
+static void check_sgr(Dav1dLoopRestorationDSPContext *const c, const int bpc) {
     ALIGN_STK_64(pixel, c_dst, 448 * 64,);
     ALIGN_STK_64(pixel, a_dst, 448 * 64,);
     ALIGN_STK_64(pixel, h_edge, 448 * 8,);
@@ -130,7 +125,7 @@
 
     for (int sgr_idx = 14; sgr_idx >= 6; sgr_idx -= 4) {
         if (check_func(c->selfguided, "selfguided_%s_%dbpc",
-                       sgr_idx == 6 ? "mix" : sgr_idx == 10 ? "3x3" : "5x5", BITDEPTH))
+                       sgr_idx == 6 ? "mix" : sgr_idx == 10 ? "3x3" : "5x5", bpc))
         {
             int16_t sgr_wt[2];
 
@@ -140,11 +135,7 @@
 
             const int base_w = 1 + (rnd() % 384);
             const int base_h = 1 + (rnd() & 63);
-#if BITDEPTH == 16
-            const int bitdepth_max = rnd() & 1 ? 0x3ff : 0xfff;
-#else
-            const int bitdepth_max = 0xff;
-#endif
+            const int bitdepth_max = (1 << bpc) - 1;
 
             init_tmp(c_dst, 448 * sizeof(pixel), 448, 64, bitdepth_max);
             init_tmp(h_edge, 448 * sizeof(pixel), 448, 8, bitdepth_max);
@@ -171,14 +162,24 @@
                       256, 64, sgr_idx, sgr_wt, 0xf HIGHBD_TAIL_SUFFIX);
         }
     }
-    report("sgr");
 }
 
 void bitfn(checkasm_check_looprestoration)(void) {
-    Dav1dLoopRestorationDSPContext c;
-
-    bitfn(dav1d_loop_restoration_dsp_init)(&c);
-
-    check_wiener(&c);
-    check_sgr(&c);
+#if BITDEPTH == 16
+    const int bpc_min = 10, bpc_max = 12;
+#else
+    const int bpc_min = 8, bpc_max = 8;
+#endif
+    for (int bpc = bpc_min; bpc <= bpc_max; bpc += 2) {
+        Dav1dLoopRestorationDSPContext c;
+        bitfn(dav1d_loop_restoration_dsp_init)(&c, bpc);
+        check_wiener(&c, bpc);
+    }
+    report("wiener");
+    for (int bpc = bpc_min; bpc <= bpc_max; bpc += 2) {
+        Dav1dLoopRestorationDSPContext c;
+        bitfn(dav1d_loop_restoration_dsp_init)(&c, bpc);
+        check_sgr(&c, bpc);
+    }
+    report("sgr");
 }