One warp_plane_allowed() gate for the per-plane 8px bail-out, with a hit counter
Browse files at this commit3aa99eb389eee90c1df1faf61600b3b5e7833a85Parent: d5c0a13- refactor
- one warp_plane_allowed() gate for the per-plane 8px bail-out, with a hit counter
1 changed file +35 -8
- crates/ec-av1/src/decode.rs +35 -8
crates/ec-av1/src/decode.rsmodified+35 -8
| @@ -262,6 +262,33 @@ thread_local! { | ||
| 262 | 262 | static CDEF_IDX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | +// How many times a warp was suppressed for one PLANE because that plane's own | |
| 266 | +// block is narrower or shorter than 8 (`av1_init_warp_params`'s own bail-out, | |
| 267 | +// reconinter.c) -- the gate's proof that a stream really carries the shape, | |
| 268 | +// since the square `side`/`chroma_side` can be 8 or more while the plane's | |
| 269 | +// true block is 4 wide (an 8x16 luma block's 4x8 chroma). | |
| 270 | +thread_local! { | |
| 271 | + static WARP_PLANE_SUPPRESS_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 272 | +} | |
| 273 | + | |
| 274 | +/// Current value of [`WARP_PLANE_SUPPRESS_HITS`]. | |
| 275 | +pub(crate) fn warp_plane_suppress_hits() -> usize { | |
| 276 | + WARP_PLANE_SUPPRESS_HITS.with(|c| c.get()) | |
| 277 | +} | |
| 278 | + | |
| 279 | +/// `av1_init_warp_params` (libaom reconinter.c): warp is decided per PLANE and | |
| 280 | +/// bails out at `block_width < 8 || block_height < 8`, so the plane's OWN | |
| 281 | +/// block dimensions decide it -- never the square `side`/`chroma_side`, which | |
| 282 | +/// for a rectangular luma block (8x16, 16x8) or a PARTITION_HORZ/VERT strip is | |
| 283 | +/// bigger than the real block in one axis. | |
| 284 | +fn warp_plane_allowed(w: usize, h: usize) -> bool { | |
| 285 | + if w >= 8 && h >= 8 { | |
| 286 | + return true; | |
| 287 | + } | |
| 288 | + WARP_PLANE_SUPPRESS_HITS.with(|c| c.set(c.get() + 1)); | |
| 289 | + false | |
| 290 | +} | |
| 291 | + | |
| 265 | 292 | /// Current value of [`CDEF_IDX_HITS`]. |
| 266 | 293 | pub(crate) fn cdef_idx_hits() -> usize { |
| 267 | 294 | CDEF_IDX_HITS.with(|c| c.get()) |
| @@ -20563,7 +20590,7 @@ fn decode_inter_block( | ||
| 20563 | 20590 | // lane-cwarp r1: this reference's own GLOBAL warp replaces the |
| 20564 | 20591 | // translational tap (libaom `av1_warp_plane` with |
| 20565 | 20592 | // `conv_params->is_compound`); the blend below is unchanged. |
| 20566 | - if let Some(wp) = warp0.as_ref().filter(|_| write_w >= 8 && write_h >= 8) { | |
| 20593 | + if let Some(wp) = warp0.as_ref().filter(|_| warp_plane_allowed(write_w, write_h)) { | |
| 20567 | 20594 | crate::warp::warp_affine_compound( |
| 20568 | 20595 | wp, &py0.data, py0.true_width as i32, py0.true_height as i32, |
| 20569 | 20596 | py0.width as i32, &mut inter0_y, px as i32, py as i32, side as i32, |
| @@ -20590,7 +20617,7 @@ fn decode_inter_block( | ||
| 20590 | 20617 | // lane-cwarp r1: this reference's own GLOBAL warp replaces the |
| 20591 | 20618 | // translational tap (libaom `av1_warp_plane` with |
| 20592 | 20619 | // `conv_params->is_compound`); the blend below is unchanged. |
| 20593 | - if let Some(wp) = warp1.as_ref().filter(|_| write_w >= 8 && write_h >= 8) { | |
| 20620 | + if let Some(wp) = warp1.as_ref().filter(|_| warp_plane_allowed(write_w, write_h)) { | |
| 20594 | 20621 | crate::warp::warp_affine_compound( |
| 20595 | 20622 | wp, &py1.data, py1.true_width as i32, py1.true_height as i32, |
| 20596 | 20623 | py1.width as i32, &mut inter1_y, px as i32, py as i32, side as i32, |
| @@ -20640,7 +20667,7 @@ fn decode_inter_block( | ||
| 20640 | 20667 | // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma |
| 20641 | 20668 | // block of an 8x8 luma block stays translational. |
| 20642 | 20669 | if let Some(wp) = &warp0 { |
| 20643 | - if write_chroma_w >= 8 && write_chroma_h >= 8 { | |
| 20670 | + if warp_plane_allowed(write_chroma_w, write_chroma_h) { | |
| 20644 | 20671 | crate::warp::warp_affine_compound( |
| 20645 | 20672 | wp, &pu0.data, pu0.true_width as i32, pu0.true_height as i32, |
| 20646 | 20673 | pu0.width as i32, &mut inter0_u, cpx as i32, cpy as i32, |
| @@ -20669,7 +20696,7 @@ fn decode_inter_block( | ||
| 20669 | 20696 | // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma |
| 20670 | 20697 | // block of an 8x8 luma block stays translational. |
| 20671 | 20698 | if let Some(wp) = &warp1 { |
| 20672 | - if write_chroma_w >= 8 && write_chroma_h >= 8 { | |
| 20699 | + if warp_plane_allowed(write_chroma_w, write_chroma_h) { | |
| 20673 | 20700 | crate::warp::warp_affine_compound( |
| 20674 | 20701 | wp, &pu1.data, pu1.true_width as i32, pu1.true_height as i32, |
| 20675 | 20702 | pu1.width as i32, &mut inter1_u, cpx as i32, cpy as i32, |
| @@ -20714,7 +20741,7 @@ fn decode_inter_block( | ||
| 20714 | 20741 | // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma |
| 20715 | 20742 | // block of an 8x8 luma block stays translational. |
| 20716 | 20743 | if let Some(wp) = &warp0 { |
| 20717 | - if write_chroma_w >= 8 && write_chroma_h >= 8 { | |
| 20744 | + if warp_plane_allowed(write_chroma_w, write_chroma_h) { | |
| 20718 | 20745 | crate::warp::warp_affine_compound( |
| 20719 | 20746 | wp, &pv0.data, pv0.true_width as i32, pv0.true_height as i32, |
| 20720 | 20747 | pv0.width as i32, &mut inter0_v, cpx as i32, cpy as i32, |
| @@ -20743,7 +20770,7 @@ fn decode_inter_block( | ||
| 20743 | 20770 | // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma |
| 20744 | 20771 | // block of an 8x8 luma block stays translational. |
| 20745 | 20772 | if let Some(wp) = &warp1 { |
| 20746 | - if write_chroma_w >= 8 && write_chroma_h >= 8 { | |
| 20773 | + if warp_plane_allowed(write_chroma_w, write_chroma_h) { | |
| 20747 | 20774 | crate::warp::warp_affine_compound( |
| 20748 | 20775 | wp, &pv1.data, pv1.true_width as i32, pv1.true_height as i32, |
| 20749 | 20776 | pv1.width as i32, &mut inter1_v, cpx as i32, cpy as i32, |
| @@ -21843,7 +21870,7 @@ fn decode_inter_block( | ||
| 21843 | 21870 | // own block is `write_w`x`write_h` (a PARTITION_HORZ/VERT |
| 21844 | 21871 | // strip is not `side`x`side`), so a strip under 8 px in |
| 21845 | 21872 | // either direction keeps the translational prediction too. |
| 21846 | - if write_w >= 8 && write_h >= 8 { | |
| 21873 | + if warp_plane_allowed(write_w, write_h) { | |
| 21847 | 21874 | crate::warp::warp_affine( |
| 21848 | 21875 | params, &py_ref.data, py_ref.true_width as i32, py_ref.true_height as i32, |
| 21849 | 21876 | py_ref.width as i32, &mut pred_y, px as i32, py as i32, side as i32, |
| @@ -21860,7 +21887,7 @@ fn decode_inter_block( | ||
| 21860 | 21887 | // block has `chroma_side == 8` but a 4x8 chroma block, so |
| 21861 | 21888 | // the square side warped chroma libaom predicts |
| 21862 | 21889 | // translationally; lane-gmaffine r4 for the 8x8 leaf). |
| 21863 | - if write_chroma_w >= 8 && write_chroma_h >= 8 { | |
| 21890 | + if warp_plane_allowed(write_chroma_w, write_chroma_h) { | |
| 21864 | 21891 | crate::warp::warp_affine( |
| 21865 | 21892 | params, &pu_ref.data, pu_ref.true_width as i32, pu_ref.true_height as i32, |
| 21866 | 21893 | pu_ref.width as i32, &mut pred_u, cpx as i32, cpy as i32, chroma_side as i32, |