shithub: dav1d

Download patch

ref: e570088de116bbbbb0e24ae5b70c0927130e5964
parent: a4ceff6ff3567164be40192aca6b117a261e080c
author: Luc Trudeau <[email protected]>
date: Thu Oct 3 19:22:58 EDT 2019

Check for RESTORATION_NONE once per frame

Prior checks were done at the sbrow level. This now allows to call
dav1d_lr_sbrow and dav1d_lr_copy_lpf only when there's something
for them to do.

--- a/src/decode.c
+++ b/src/decode.c
@@ -2339,7 +2339,7 @@
                    ((ts->tiling.col_start & 16) >> 4);
     }
     for (int p = 0; p < 3; p++) {
-        if (f->frame_hdr->restoration.type[p] == DAV1D_RESTORATION_NONE)
+        if (!((f->lf.restore_planes >> p) & 1U))
             continue;
 
         if (f->frame_hdr->super_res.enabled) {
@@ -2503,7 +2503,7 @@
         }
         // Restoration filter
         for (int p = 0; p < 3; p++) {
-            if (f->frame_hdr->restoration.type[p] == DAV1D_RESTORATION_NONE)
+            if (!((f->lf.restore_planes >> p) & 1U))
                 continue;
 
             const int ss_ver = p && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
@@ -2817,6 +2817,10 @@
         }
         f->lf.lr_mask_sz = lr_mask_sz;
     }
+    f->lf.restore_planes =
+        ((f->frame_hdr->restoration.type[0] != DAV1D_RESTORATION_NONE) << 0) +
+        ((f->frame_hdr->restoration.type[1] != DAV1D_RESTORATION_NONE) << 1) +
+        ((f->frame_hdr->restoration.type[2] != DAV1D_RESTORATION_NONE) << 2);
     if (f->frame_hdr->loopfilter.sharpness != f->lf.last_sharpness) {
         dav1d_calc_eih(&f->lf.lim_lut, f->frame_hdr->loopfilter.sharpness);
         f->lf.last_sharpness = f->frame_hdr->loopfilter.sharpness;
--- a/src/internal.h
+++ b/src/internal.h
@@ -228,6 +228,7 @@
         int tile_row; // for carry-over at tile row edges
         pixel *p[3], *sr_p[3];
         Av1Filter *mask_ptr, *prev_mask_ptr;
+        int restore_planes; // enum LrRestorePlanes
     } lf;
 
     // threading (refer to tc[] for per-thread things)
--- a/src/lr_apply_tmpl.c
+++ b/src/lr_apply_tmpl.c
@@ -112,10 +112,7 @@
     const ptrdiff_t lr_stride = ((f->sr_cur.p.p.w + 31) & ~31) * sizeof(pixel);
 
     // TODO Also check block level restore type to reduce copying.
-    const int restore_planes =
-        ((f->frame_hdr->restoration.type[0] != DAV1D_RESTORATION_NONE) << 0) +
-        ((f->frame_hdr->restoration.type[1] != DAV1D_RESTORATION_NONE) << 1) +
-        ((f->frame_hdr->restoration.type[2] != DAV1D_RESTORATION_NONE) << 2);
+    const int restore_planes = f->lf.restore_planes;
 
     if (restore_planes & LR_RESTORE_Y) {
         const int h = f->cur.p.h;
@@ -279,11 +276,7 @@
 {
     const int offset_y = 8 * !!sby;
     const ptrdiff_t *const dst_stride = f->sr_cur.p.stride;
-
-    const int restore_planes =
-        ((f->frame_hdr->restoration.type[0] != DAV1D_RESTORATION_NONE) << 0) +
-        ((f->frame_hdr->restoration.type[1] != DAV1D_RESTORATION_NONE) << 1) +
-        ((f->frame_hdr->restoration.type[2] != DAV1D_RESTORATION_NONE) << 2);
+    const int restore_planes = f->lf.restore_planes;
 
     if (restore_planes & LR_RESTORE_Y) {
         const int h = f->sr_cur.p.p.h;
--- a/src/recon_tmpl.c
+++ b/src/recon_tmpl.c
@@ -1971,7 +1971,7 @@
                                        start_of_tile_row);
     }
 
-    if (f->seq_hdr->restoration) {
+    if (f->lf.restore_planes) {
         // Store loop filtered pixels required by loop restoration
         bytefn(dav1d_lr_copy_lpf)(f, f->lf.p, sby);
     }
@@ -2010,7 +2010,7 @@
                               f->resize_start[!!pl] HIGHBD_CALL_SUFFIX);
         }
     }
-    if (f->seq_hdr->restoration) {
+    if (f->lf.restore_planes) {
         bytefn(dav1d_lr_sbrow)(f, f->lf.sr_p, sby);
     }