forge
Explore
Log in

Don't you dare go Hollow

A deblock-only filter candidate keeps its own planes as the deblock cache

Browse files at this commit

3a4b874be6ee04e84fa9183ba4d9f216c1c0a7faAhmet Kaan GümüşParent: 34dfd1e
  • perf
    • a deblock-only filter candidate keeps its own planes as the deblock cache
Show full message
perf(av1): a deblock-only filter candidate keeps its own planes as the deblock cache

An all-zero-strength CDEF writes no sample (apply_cdef's cdef_all_zero
early return), so the planes a level-changing candidate just deblocked
ARE its output: they become the cache directly instead of being copied
into it, three ~6 MB copies less on every candidate of the deblocking
half of the search. 4K 4x2/8 plane copies 235 -> 204 ms.
crates/ec-av1/src/decode.rsmodified+49 -8
@@ -19915,6 +19915,10 @@ fn replay_inner(
1991519915 REPLAY.with_borrow_mut(|slot| {
1991619916 let r = slot.as_mut()?;
1991719917 let hit = matches!(&r.deblocked, Some((lf, ..)) if lf == loop_filter);
19918+ // Set when the working planes ARE the deblocked planes (see below):
19919+ // they go into the cache at the end, and the picture is cropped out
19920+ // of them rather than taking their buffers.
19921+ let mut share = false;
1991819922 let cpt = crate::par::timer(crate::par::S_COPY);
1991919923 let (mut y, mut u, mut v) = if hit {
1992019924 let (deblocked, scratch) = (&r.deblocked, &mut r.scratch);
@@ -19942,9 +19946,23 @@ fn replay_inner(
1994219946 r.frame_height,
1994319947 fctx,
1994419948 );
19945- let scratch = &mut r.scratch;
19946- r.deblocked =
19947- Some((*loop_filter, pooled(&y, scratch), pooled(&u, scratch), pooled(&v, scratch)));
19949+ // lane-av1cap2: an all-zero-strength CDEF writes no sample at
19950+ // all ([`cdef_all_zero`]'s own early return), so THESE planes
19951+ // are already this candidate's output -- they become the
19952+ // deblock cache at the end instead of being copied into it
19953+ // here, which is three ~6 MB copies less per candidate that
19954+ // moves the levels (the whole deblocking half of the search:
19955+ // its CDEF strengths are still (0,0)).
19956+ share = cdef_all_zero(cdef);
19957+ if !share {
19958+ let scratch = &mut r.scratch;
19959+ r.deblocked = Some((
19960+ *loop_filter,
19961+ pooled(&y, scratch),
19962+ pooled(&u, scratch),
19963+ pooled(&v, scratch),
19964+ ));
19965+ }
1994819966 (y, u, v)
1994919967 };
1995019968 drop(cpt);
@@ -19969,7 +19987,13 @@ fn replay_inner(
1996919987 // post-CDEF stands in for post-deblock, as the capture decode
1997019988 // had it); the FILTER this frame ends up applying reads the
1997119989 // real post-deblock rows, which is what the decoder does.
19972- let snapshot = r.deblocked.as_ref().map(|(_, dy, ..)| plane_snapshot(dy, 0));
19990+ let snapshot = if share {
19991+ // Nothing filtered these planes after the deblock, so they
19992+ // are the post-deblock picture themselves.
19993+ Some(plane_snapshot(&y, 0))
19994+ } else {
19995+ r.deblocked.as_ref().map(|(_, dy, ..)| plane_snapshot(dy, 0))
19996+ };
1997319997 let scratch = &mut r.scratch;
1997419998 r.final_luma = snapshot.map(|d| (pooled(&y, scratch), d));
1997519999 }
@@ -19993,6 +20017,17 @@ fn replay_inner(
1999320017 let (fw, fh) = (r.frame_width, r.frame_height);
1999420018 if fw == r.width && fh == r.height {
1999520019 fctx.last_frame_wide_margin.with(|m| *m.borrow_mut() = None);
20020+ if share {
20021+ let picture = Picture {
20022+ width: r.width,
20023+ height: r.height,
20024+ y: y.data.to_vec(),
20025+ u: u.data.to_vec(),
20026+ v: v.data.to_vec(),
20027+ };
20028+ r.deblocked = Some((*loop_filter, y, u, v));
20029+ return Some((picture, stages));
20030+ }
1999620031 return Some((
1999720032 Picture {
1999820033 width: r.width,
@@ -20028,10 +20063,16 @@ fn replay_inner(
2002820063 u: crop(&u, fw.div_ceil(2), fh.div_ceil(2)),
2002920064 v: crop(&v, fw.div_ceil(2), fh.div_ceil(2)),
2003020065 };
20031- // The working planes outlive the crop, so they go back to the pool.
20032- for plane in [y, u, v] {
20033- if r.scratch.len() < 6 {
20034- r.scratch.push(plane.data.into_owned());
20066+ // The working planes outlive the crop: either they ARE the
20067+ // deblocked planes this candidate's successors reuse, or they go
20068+ // back to the pool.
20069+ if share {
20070+ r.deblocked = Some((*loop_filter, y, u, v));
20071+ } else {
20072+ for plane in [y, u, v] {
20073+ if r.scratch.len() < 6 {
20074+ r.scratch.push(plane.data.into_owned());
20075+ }
2003520076 }
2003620077 }
2003720078 Some((out, stages))