The filter replay's CDEF reads the deblock cache instead of copying
Browse files at this commit1085bf233cb1ec4ae7037c43a7ffdccc8c20e1afParent: 2d19659- perf
- the filter replay's CDEF reads the deblock cache instead of copying
1 changed file +36 -13
- crates/ec-av1/src/decode.rs +36 -13
crates/ec-av1/src/decode.rsmodified+36 -13
| @@ -19766,12 +19766,12 @@ pub(crate) fn set_filter_replay_disabled(off: bool) { | ||
| 19766 | 19766 | REPLAY_DISABLED.store(off, std::sync::atomic::Ordering::Relaxed); |
| 19767 | 19767 | } |
| 19768 | 19768 | |
| 19769 | -/// Test-only: run the capture decode [`replay_final`] replaced as well, and | |
| 19770 | -/// hold its picture and its [`FilterStages`] against the replay's | |
| 19771 | -/// (`encoder::tests::filter_replay_final_matches_the_capture_decode`). | |
| 19772 | -/// Thread-local, not a global: the filter stage runs on the frame thread the | |
| 19773 | -/// test itself drives, and a process-wide flag would put every test encoding | |
| 19774 | -/// in parallel with this one through the extra decode too. | |
| 19769 | +// Test-only: run the capture decode `replay_final` replaced as well, and | |
| 19770 | +// hold its picture and its `FilterStages` against the replay's | |
| 19771 | +// (`encoder::tests::filter_replay_final_matches_the_capture_decode`). | |
| 19772 | +// Thread-local, not a global: the filter stage runs on the frame thread the | |
| 19773 | +// test itself drives, and a process-wide flag would put every test encoding | |
| 19774 | +// in parallel with this one through the extra decode too. | |
| 19775 | 19775 | #[cfg(test)] |
| 19776 | 19776 | thread_local! { |
| 19777 | 19777 | static VERIFY_FINAL: std::cell::Cell<bool> = const { std::cell::Cell::new(false) }; |
| @@ -19949,7 +19949,13 @@ fn replay_inner( | ||
| 19949 | 19949 | fctx.cdef_idx_grid.with(|g| *g.borrow_mut() = grid.to_vec()); |
| 19950 | 19950 | } |
| 19951 | 19951 | let ct = crate::par::timer(crate::par::S_CDEF); |
| 19952 | - apply_cdef(&mut y, &mut u, &mut v, cdef, &r.neighbours, (r.frame_width, r.frame_height), fctx); | |
| 19952 | + let pre = r.deblocked.as_ref().map(|(_, dy, du, dv)| { | |
| 19953 | + (dy.data.as_ref(), du.data.as_ref(), dv.data.as_ref()) | |
| 19954 | + }); | |
| 19955 | + apply_cdef( | |
| 19956 | + &mut y, &mut u, &mut v, cdef, &r.neighbours, (r.frame_width, r.frame_height), fctx, | |
| 19957 | + pre, | |
| 19958 | + ); | |
| 19953 | 19959 | drop(ct); |
| 19954 | 19960 | let stages = final_pass.and_then(|(_, want)| { |
| 19955 | 19961 | want.then(|| FilterStages { |
| @@ -20732,6 +20738,13 @@ fn apply_cdef( | ||
| 20732 | 20738 | // This frame header's own CROPPED luma size, for the straddling-unit |
| 20733 | 20739 | // counter only -- CDEF itself walks the mi-rounded plane. |
| 20734 | 20740 | (frame_w, frame_h): (usize, usize), fctx: &crate::decode::FrameCtx, |
| 20741 | + // lane-av1cap: every CDEF unit reads the PRE-CDEF planes, so the filter | |
| 20742 | + // starts by copying all three (~19 MB at 4K). The encoder's filter | |
| 20743 | + // replay already holds an untouched copy of exactly those planes -- its | |
| 20744 | + // post-deblock cache, which is where the working planes were copied FROM | |
| 20745 | + // -- so it hands them straight in and the copy does not happen. `None` | |
| 20746 | + // (every decode) copies as before. | |
| 20747 | + src: Option<(&[u16], &[u16], &[u16])>, | |
| 20735 | 20748 | ) { |
| 20736 | 20749 | // lane-part32 r2 debug rung, env-gated: see `apply_deblock`'s sibling. |
| 20737 | 20750 | if crate::envflags::env_flag!("EC_AV1_DEBUG_SKIP_CDEF") { |
| @@ -20751,9 +20764,15 @@ fn apply_cdef( | ||
| 20751 | 20764 | // One entry per superblock (a few hundred at 4K), so this clone is not |
| 20752 | 20765 | // one of the per-frame copies lane-perf6 pooled below. |
| 20753 | 20766 | let idx_grid = fctx.cdef_idx_grid.with(|g| g.borrow().clone()); |
| 20754 | - let src_y = scratch_from(&y.data); | |
| 20755 | - let src_u = scratch_from(&u.data); | |
| 20756 | - let src_v = scratch_from(&v.data); | |
| 20767 | + let owned = src.is_none(); | |
| 20768 | + let (src_y, src_u, src_v) = match src { | |
| 20769 | + Some((a, b, c)) => (std::borrow::Cow::Borrowed(a), std::borrow::Cow::Borrowed(b), std::borrow::Cow::Borrowed(c)), | |
| 20770 | + None => ( | |
| 20771 | + std::borrow::Cow::Owned(scratch_from(&y.data)), | |
| 20772 | + std::borrow::Cow::Owned(scratch_from(&u.data)), | |
| 20773 | + std::borrow::Cow::Owned(scratch_from(&v.data)), | |
| 20774 | + ), | |
| 20775 | + }; | |
| 20757 | 20776 | // libaom `av1_cdef_filter_fb`: `pri_strength = level << coeff_shift`, |
| 20758 | 20777 | // `sec_strength <<= coeff_shift`, `damping += coeff_shift - (pli != 0)`. |
| 20759 | 20778 | let coeff_shift = i32::from(bit_depth(fctx)) - 8; |
| @@ -20768,9 +20787,11 @@ fn apply_cdef( | ||
| 20768 | 20787 | y, u, v, &src_y, &src_u, &src_v, cdef, skip_grid, &idx_grid, sb_cols, coeff_shift, |
| 20769 | 20788 | damping, damping_uv, (frame_w, frame_h), 0, skip_grid.mi_rows, fctx, |
| 20770 | 20789 | ); |
| 20771 | - scratch_return(src_y); | |
| 20772 | - scratch_return(src_u); | |
| 20773 | - scratch_return(src_v); | |
| 20790 | + if owned { | |
| 20791 | + scratch_return(src_y.into_owned()); | |
| 20792 | + scratch_return(src_u.into_owned()); | |
| 20793 | + scratch_return(src_v.into_owned()); | |
| 20794 | + } | |
| 20774 | 20795 | } |
| 20775 | 20796 | |
| 20776 | 20797 | /// [`FrameCtx::capture_stages`]'s write side, called between CDEF and loop |
| @@ -23346,6 +23367,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 23346 | 23367 | cdef, |
| 23347 | 23368 | &neighbours, |
| 23348 | 23369 | (frame_width as usize, frame_height as usize), fctx, |
| 23370 | + None, | |
| 23349 | 23371 | ); |
| 23350 | 23372 | dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v); |
| 23351 | 23373 | dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); |
| @@ -36161,6 +36183,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 36161 | 36183 | cdef, |
| 36162 | 36184 | &neighbours, |
| 36163 | 36185 | (frame_width as usize, frame_height as usize), fctx, |
| 36186 | + None, | |
| 36164 | 36187 | ); |
| 36165 | 36188 | } |
| 36166 | 36189 | dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v); |