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+45 -4
@@ -19915,6 +19915,10 @@ fn replay_inner(
19915 REPLAY.with_borrow_mut(|slot| {19915 REPLAY.with_borrow_mut(|slot| {
19916 let r = slot.as_mut()?;19916 let r = slot.as_mut()?;
19917 let hit = matches!(&r.deblocked, Some((lf, ..)) if lf == loop_filter);19917 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;
19918 let cpt = crate::par::timer(crate::par::S_COPY);19922 let cpt = crate::par::timer(crate::par::S_COPY);
19919 let (mut y, mut u, mut v) = if hit {19923 let (mut y, mut u, mut v) = if hit {
19920 let (deblocked, scratch) = (&r.deblocked, &mut r.scratch);19924 let (deblocked, scratch) = (&r.deblocked, &mut r.scratch);
@@ -19942,9 +19946,23 @@ fn replay_inner(
19942 r.frame_height,19946 r.frame_height,
19943 fctx,19947 fctx,
19944 );19948 );
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 {
19945 let scratch = &mut r.scratch;19958 let scratch = &mut r.scratch;
19946- r.deblocked =19959+ r.deblocked = Some((
19947- Some((*loop_filter, pooled(&y, scratch), pooled(&u, scratch), pooled(&v, scratch)));19960+ *loop_filter,
19961+ pooled(&y, scratch),
19962+ pooled(&u, scratch),
19963+ pooled(&v, scratch),
19964+ ));
19965+ }
19948 (y, u, v)19966 (y, u, v)
19949 };19967 };
19950 drop(cpt);19968 drop(cpt);
@@ -19969,7 +19987,13 @@ fn replay_inner(
19969 // post-CDEF stands in for post-deblock, as the capture decode19987 // post-CDEF stands in for post-deblock, as the capture decode
19970 // had it); the FILTER this frame ends up applying reads the19988 // had it); the FILTER this frame ends up applying reads the
19971 // real post-deblock rows, which is what the decoder does.19989 // 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+ };
19973 let scratch = &mut r.scratch;19997 let scratch = &mut r.scratch;
19974 r.final_luma = snapshot.map(|d| (pooled(&y, scratch), d));19998 r.final_luma = snapshot.map(|d| (pooled(&y, scratch), d));
19975 }19999 }
@@ -19993,6 +20017,17 @@ fn replay_inner(
19993 let (fw, fh) = (r.frame_width, r.frame_height);20017 let (fw, fh) = (r.frame_width, r.frame_height);
19994 if fw == r.width && fh == r.height {20018 if fw == r.width && fh == r.height {
19995 fctx.last_frame_wide_margin.with(|m| *m.borrow_mut() = None);20019 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+ }
19996 return Some((20031 return Some((
19997 Picture {20032 Picture {
19998 width: r.width,20033 width: r.width,
@@ -20028,12 +20063,18 @@ fn replay_inner(
20028 u: crop(&u, fw.div_ceil(2), fh.div_ceil(2)),20063 u: crop(&u, fw.div_ceil(2), fh.div_ceil(2)),
20029 v: crop(&v, fw.div_ceil(2), fh.div_ceil(2)),20064 v: crop(&v, fw.div_ceil(2), fh.div_ceil(2)),
20030 };20065 };
20031- // The working planes outlive the crop, so they go back to the pool.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 {
20032 for plane in [y, u, v] {20072 for plane in [y, u, v] {
20033 if r.scratch.len() < 6 {20073 if r.scratch.len() < 6 {
20034 r.scratch.push(plane.data.into_owned());20074 r.scratch.push(plane.data.into_owned());
20035 }20075 }
20036 }20076 }
20077+ }
20037 Some((out, stages))20078 Some((out, stages))
20038 })20079 })
20039 }20080 }