A deblock-only filter candidate keeps its own planes as the deblock cache
Browse files at this commit3a4b874be6ee04e84fa9183ba4d9f216c1c0a7faParent: 34dfd1e- perf
- a deblock-only filter candidate keeps its own planes as the deblock cache
1 changed file +49 -8
- crates/ec-av1/src/decode.rs +49 -8
crates/ec-av1/src/decode.rsmodified+49 -8
| @@ -19915,6 +19915,10 @@ fn replay_inner( | ||
| 19915 | 19915 | REPLAY.with_borrow_mut(|slot| { |
| 19916 | 19916 | let r = slot.as_mut()?; |
| 19917 | 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 | 19922 | let cpt = crate::par::timer(crate::par::S_COPY); |
| 19919 | 19923 | let (mut y, mut u, mut v) = if hit { |
| 19920 | 19924 | let (deblocked, scratch) = (&r.deblocked, &mut r.scratch); |
| @@ -19942,9 +19946,23 @@ fn replay_inner( | ||
| 19942 | 19946 | r.frame_height, |
| 19943 | 19947 | fctx, |
| 19944 | 19948 | ); |
| 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 | + } | |
| 19948 | 19966 | (y, u, v) |
| 19949 | 19967 | }; |
| 19950 | 19968 | drop(cpt); |
| @@ -19969,7 +19987,13 @@ fn replay_inner( | ||
| 19969 | 19987 | // post-CDEF stands in for post-deblock, as the capture decode |
| 19970 | 19988 | // had it); the FILTER this frame ends up applying reads the |
| 19971 | 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 | 19997 | let scratch = &mut r.scratch; |
| 19974 | 19998 | r.final_luma = snapshot.map(|d| (pooled(&y, scratch), d)); |
| 19975 | 19999 | } |
| @@ -19993,6 +20017,17 @@ fn replay_inner( | ||
| 19993 | 20017 | let (fw, fh) = (r.frame_width, r.frame_height); |
| 19994 | 20018 | if fw == r.width && fh == r.height { |
| 19995 | 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 | 20031 | return Some(( |
| 19997 | 20032 | Picture { |
| 19998 | 20033 | width: r.width, |
| @@ -20028,10 +20063,16 @@ fn replay_inner( | ||
| 20028 | 20063 | u: crop(&u, fw.div_ceil(2), fh.div_ceil(2)), |
| 20029 | 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. | |
| 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 | + } | |
| 20035 | 20076 | } |
| 20036 | 20077 | } |
| 20037 | 20078 | Some((out, stages)) |