forge
Explore
Log in

Don't you dare go Hollow

The filter replay deblocks once per level pair

Browse files at this commit

95de47fc4b4ef45aea807025014d3bb28c48fa2fAhmet Kaan GümüşParent: 2b23fd6
  • perf
    • the filter replay deblocks once per level pair
Show full message
perf(av1): the filter replay deblocks once per level pair

The search fixes the deblocking levels in its first three stages and
then walks 18 CDEF strength candidates that all replay the same
deblock. The replay now keeps the deblocked planes with the levels that
produced them and copies those instead when the levels match -- the
same copy the replay was already making, with the deblock skipped.
Byte-identical on the three gate clips; ladder wall 4.64/4.21/4.91 ->
4.51/4.08/4.80 s.
crates/ec-av1/src/decode.rsmodified+27 -13
@@ -19725,6 +19725,11 @@ pub(crate) struct FilterReplay {
1972519725 frame_height: usize,
1972619726 width: usize,
1972719727 height: usize,
19728+ /// The last deblocked planes and the levels that produced them.
19729+ /// Deblocking depends on nothing else the search moves, and the search
19730+ /// fixes the levels before it walks the CDEF strengths, so every
19731+ /// candidate after the first of a level pair replays CDEF alone.
19732+ deblocked: Option<(LoopFilterParams, PlaneBuf<'static>, PlaneBuf<'static>, PlaneBuf<'static>)>,
1972819733 }
1972919734
1973019735 thread_local! {
@@ -19772,6 +19777,7 @@ fn capture_filter_replay(
1977219777 frame_height,
1977319778 width,
1977419779 height,
19780+ deblocked: None,
1977519781 });
1977619782 });
1977719783 }
@@ -19785,23 +19791,31 @@ pub(crate) fn replay_filters(
1978519791 cdef: &CdefParams,
1978619792 fctx: &FrameCtx,
1978719793 ) -> Option<Picture> {
19788- REPLAY.with_borrow(|slot| {
19789- let r = slot.as_ref()?;
19794+ REPLAY.with_borrow_mut(|slot| {
19795+ let r = slot.as_mut()?;
1979019796 let copy = |p: &PlaneBuf<'_>| PlaneBuf {
1979119797 data: std::borrow::Cow::Owned(p.data.to_vec()),
1979219798 ..*p
1979319799 };
19794- let (mut y, mut u, mut v) = (copy(&r.y), copy(&r.u), copy(&r.v));
19795- apply_deblock(
19796- &mut y,
19797- &mut u,
19798- &mut v,
19799- loop_filter,
19800- &r.neighbours,
19801- r.frame_width,
19802- r.frame_height,
19803- fctx,
19804- );
19800+ let hit = matches!(&r.deblocked, Some((lf, ..)) if lf == loop_filter);
19801+ let (mut y, mut u, mut v) = if hit {
19802+ let (_, dy, du, dv) = r.deblocked.as_ref().expect("just matched");
19803+ (copy(dy), copy(du), copy(dv))
19804+ } else {
19805+ let (mut y, mut u, mut v) = (copy(&r.y), copy(&r.u), copy(&r.v));
19806+ apply_deblock(
19807+ &mut y,
19808+ &mut u,
19809+ &mut v,
19810+ loop_filter,
19811+ &r.neighbours,
19812+ r.frame_width,
19813+ r.frame_height,
19814+ fctx,
19815+ );
19816+ r.deblocked = Some((*loop_filter, copy(&y), copy(&u), copy(&v)));
19817+ (y, u, v)
19818+ };
1980519819 apply_cdef(&mut y, &mut u, &mut v, cdef, &r.neighbours, (r.frame_width, r.frame_height), fctx);
1980619820 // The capture only happens on the shape the decoder's own tail
1980719821 // returns whole (no superres, no loop restoration, no crop), so this