Interintra built a square intra predictor for rectangular blocks
Browse files at this commit9a73c3092d9bf0e6fe9e80d539c4a0916ed6f6d7Parent: 3e2b507- fix
- interintra built a square intra predictor for rectangular blocks
3 changed files +62 -21
- crates/ec-av1/examples/decode_probe.rs +1 -0
- crates/ec-av1/src/decode.rs +52 -19
- crates/ec-av1/src/stream.rs +9 -2
crates/ec-av1/examples/decode_probe.rsmodified+1 -0
| @@ -43,6 +43,7 @@ fn main() { | |||
| 43 | let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters(); | 43 | let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters(); |
| 44 | println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}"); | 44 | println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}"); |
| 45 | println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits()); | 45 | println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits()); |
| 46 | + println!("interintra_rect: {}", ec_av1::decode::interintra_rect_hits()); | ||
| 46 | let (h84, h48) = ec_av1::decode::sub8_inter_rect_hits(); | 47 | let (h84, h48) = ec_av1::decode::sub8_inter_rect_hits(); |
| 47 | println!("sub8_inter_rect: horz8x4={h84} vert4x8={h48}"); | 48 | println!("sub8_inter_rect: horz8x4={h84} vert4x8={h48}"); |
| 48 | let si = ec_av1::stream::sub8_intra_rect_hits(); | 49 | let si = ec_av1::stream::sub8_intra_rect_hits(); |
crates/ec-av1/src/decode.rsmodified+52 -19
| @@ -2075,6 +2075,20 @@ pub(crate) fn interintra_hits() -> usize { | |||
| 2075 | INTERINTRA_HITS.with(|c| c.get()) | 2075 | INTERINTRA_HITS.with(|c| c.get()) |
| 2076 | } | 2076 | } |
| 2077 | 2077 | ||
| 2078 | +// lane-midcut r1: of those, how many were RECTANGULAR (`write_w != write_h`) | ||
| 2079 | +// -- the shape `interintra_blend` used to build a square `side x side` intra | ||
| 2080 | +// predictor for, with `ii_size_scales`/`edges` taken at the square. Every | ||
| 2081 | +// pre-existing interintra gate passed with that bug, so the rect arm needs | ||
| 2082 | +// its own counter to stop being vacuous. | ||
| 2083 | +thread_local! { | ||
| 2084 | + static INTERINTRA_RECT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 2085 | +} | ||
| 2086 | + | ||
| 2087 | +/// Current value of [`INTERINTRA_RECT_HITS`]. | ||
| 2088 | +pub fn interintra_rect_hits() -> usize { | ||
| 2089 | + INTERINTRA_RECT_HITS.with(|c| c.get()) | ||
| 2090 | +} | ||
| 2091 | + | ||
| 2078 | // How many blocks decoded `comp_group_idx == 1` (masked COMPOUND_REFERENCE, | 2092 | // How many blocks decoded `comp_group_idx == 1` (masked COMPOUND_REFERENCE, |
| 2079 | // wedge or diffwtd) and had `compound_type`/`wedge_idx`/`wedge_sign`/ | 2093 | // wedge or diffwtd) and had `compound_type`/`wedge_idx`/`wedge_sign`/ |
| 2080 | // `mask_type` consumed entropy-exact -- lane-maskcomp r1's proof that a | 2094 | // `mask_type` consumed entropy-exact -- lane-maskcomp r1's proof that a |
| @@ -18941,7 +18955,9 @@ fn interintra_blend( | |||
| 18941 | plane: &PlaneBuf, | 18955 | plane: &PlaneBuf, |
| 18942 | x: usize, | 18956 | x: usize, |
| 18943 | y: usize, | 18957 | y: usize, |
| 18944 | - side: usize, | 18958 | + bw: usize, |
| 18959 | + bh: usize, | ||
| 18960 | + stride: usize, | ||
| 18945 | ii_mode: u8, | 18961 | ii_mode: u8, |
| 18946 | wedge: Option<(&'static [u8], usize)>, | 18962 | wedge: Option<(&'static [u8], usize)>, |
| 18947 | pred: &mut [u16], | 18963 | pred: &mut [u16], |
| @@ -18953,16 +18969,17 @@ fn interintra_blend( | |||
| 18953 | 2 => crate::intra::H_PRED, | 18969 | 2 => crate::intra::H_PRED, |
| 18954 | _ => crate::intra::SMOOTH_PRED, | 18970 | _ => crate::intra::SMOOTH_PRED, |
| 18955 | }; | 18971 | }; |
| 18956 | - let (above, left, corner) = plane.edges( | 18972 | + let (above, left, corner) = plane.edges_rect( |
| 18957 | x, | 18973 | x, |
| 18958 | y, | 18974 | y, |
| 18959 | - side, | 18975 | + bw, |
| 18976 | + bh, | ||
| 18960 | crate::encode::Reach { | 18977 | crate::encode::Reach { |
| 18961 | above_right: false, | 18978 | above_right: false, |
| 18962 | below_left: false, | 18979 | below_left: false, |
| 18963 | }, | 18980 | }, |
| 18964 | ); | 18981 | ); |
| 18965 | - let mut intra = vec![0u16; side * side]; | 18982 | + let mut intra = vec![0u16; bw * bh]; |
| 18966 | // Edge filtering never applies here: V/H at delta 0 are plain edge | 18983 | // Edge filtering never applies here: V/H at delta 0 are plain edge |
| 18967 | // copies (angle 90/180 skip the directional walk), DC/SMOOTH carry no | 18984 | // copies (angle 90/180 skip the directional walk), DC/SMOOTH carry no |
| 18968 | // angle at all. | 18985 | // angle at all. |
| @@ -18972,22 +18989,25 @@ fn interintra_blend( | |||
| 18972 | above.as_deref(), | 18989 | above.as_deref(), |
| 18973 | left.as_deref(), | 18990 | left.as_deref(), |
| 18974 | corner, | 18991 | corner, |
| 18975 | - side, | 18992 | + bw, |
| 18976 | - side, | 18993 | + bh, |
| 18977 | false, | 18994 | false, |
| 18978 | false, | 18995 | false, |
| 18979 | &mut intra, | 18996 | &mut intra, |
| 18980 | ); | 18997 | ); |
| 18981 | - let scale = 128 / side; | 18998 | + // `ii_size_scales[bsize]` is keyed on the block's LONGER side |
| 18982 | - for i in 0..side { | 18999 | + // (`MAX_SB_SIZE >> max(bw,bh)` order), not on the square this decoder |
| 18983 | - for j in 0..side { | 19000 | + // builds the predictor buffer at. |
| 19001 | + let scale = 128 / bw.max(bh); | ||
| 19002 | + for i in 0..bh { | ||
| 19003 | + for j in 0..bw { | ||
| 18984 | let m = u32::from(match wedge { | 19004 | let m = u32::from(match wedge { |
| 18985 | // lane-wii r2: wedge-interintra mask (aom_blend_a64_mask | 19005 | // lane-wii r2: wedge-interintra mask (aom_blend_a64_mask |
| 18986 | // over the wedge codebook, intra as src0, fixed sign 0). | 19006 | // over the wedge codebook, intra as src0, fixed sign 0). |
| 18987 | // Luma plane: mask rows are luma-resolution, ms == side. | 19007 | // Luma plane: mask rows are luma-resolution, ms == side. |
| 18988 | // 4:2:0 chroma: 2x2 box average (reconinter.c sub8x8 -- | 19008 | // 4:2:0 chroma: 2x2 box average (reconinter.c sub8x8 -- |
| 18989 | // subw == subh == 1). | 19009 | // subw == subh == 1). |
| 18990 | - Some((mask, ms)) if ms == side => mask[i * side + j], | 19010 | + Some((mask, ms)) if ms == stride => mask[i * stride + j], |
| 18991 | Some((mask, ms)) => { | 19011 | Some((mask, ms)) => { |
| 18992 | let t = 2 * i * ms + 2 * j; | 19012 | let t = 2 * i * ms + 2 * j; |
| 18993 | ((u32::from(mask[t]) | 19013 | ((u32::from(mask[t]) |
| @@ -19004,9 +19024,9 @@ fn interintra_blend( | |||
| 19004 | _ => II_WEIGHTS_1D[i.min(j) * scale], | 19024 | _ => II_WEIGHTS_1D[i.min(j) * scale], |
| 19005 | }, | 19025 | }, |
| 19006 | }); | 19026 | }); |
| 19007 | - let idx = i * side + j; | 19027 | + let idx = i * stride + j; |
| 19008 | - pred[idx] = | 19028 | + pred[idx] = ((m * u32::from(intra[i * bw + j]) + (64 - m) * u32::from(pred[idx]) + 32) |
| 19009 | - ((m * u32::from(intra[idx]) + (64 - m) * u32::from(pred[idx]) + 32) >> 6) as u16; | 19029 | + >> 6) as u16; |
| 19010 | } | 19030 | } |
| 19011 | } | 19031 | } |
| 19012 | } | 19032 | } |
| @@ -21873,9 +21893,18 @@ fn decode_inter_block( | |||
| 21873 | // result, all planes (reconinter.c av1_build_interintra_predictor | 21893 | // result, all planes (reconinter.c av1_build_interintra_predictor |
| 21874 | // plane loop). | 21894 | // plane loop). |
| 21875 | if let Some(ii) = interintra_mode { | 21895 | if let Some(ii) = interintra_mode { |
| 21876 | - interintra_blend(y, px, py, side, ii, wedge_mask, &mut pred_y); | 21896 | + if write_w != write_h { |
| 21877 | - interintra_blend(u, cpx, cpy, chroma_side, ii, wedge_mask, &mut pred_u); | 21897 | + INTERINTRA_RECT_HITS.with(|c| c.set(c.get() + 1)); |
| 21878 | - interintra_blend(v, cpx, cpy, chroma_side, ii, wedge_mask, &mut pred_v); | 21898 | + } |
| 21899 | + interintra_blend(y, px, py, write_w, write_h, side, ii, wedge_mask, &mut pred_y); | ||
| 21900 | + interintra_blend( | ||
| 21901 | + u, cpx, cpy, write_chroma_w, write_chroma_h, chroma_side, ii, wedge_mask, | ||
| 21902 | + &mut pred_u, | ||
| 21903 | + ); | ||
| 21904 | + interintra_blend( | ||
| 21905 | + v, cpx, cpy, write_chroma_w, write_chroma_h, chroma_side, ii, wedge_mask, | ||
| 21906 | + &mut pred_v, | ||
| 21907 | + ); | ||
| 21879 | } | 21908 | } |
| 21880 | 21909 | ||
| 21881 | // lane-inter16ab r2: libaom `build_inter_predictors_sub8x8` | 21910 | // lane-inter16ab r2: libaom `build_inter_predictors_sub8x8` |
| @@ -25935,9 +25964,13 @@ fn decode_inter_block8( | |||
| 25935 | // Non-wedge interintra blend, mutually exclusive with OBMC (the | 25964 | // Non-wedge interintra blend, mutually exclusive with OBMC (the |
| 25936 | // motion_mode symbol is not read for an interintra block). | 25965 | // motion_mode symbol is not read for an interintra block). |
| 25937 | if let Some(ii) = interintra_mode { | 25966 | if let Some(ii) = interintra_mode { |
| 25938 | - interintra_blend(y, px, py, SIDE, ii, wedge_mask, &mut pred_y); | 25967 | + interintra_blend(y, px, py, SIDE, SIDE, SIDE, ii, wedge_mask, &mut pred_y); |
| 25939 | - interintra_blend(u, cpx, cpy, CHROMA_SIDE, ii, wedge_mask, &mut pred_u); | 25968 | + interintra_blend( |
| 25940 | - interintra_blend(v, cpx, cpy, CHROMA_SIDE, ii, wedge_mask, &mut pred_v); | 25969 | + u, cpx, cpy, CHROMA_SIDE, CHROMA_SIDE, CHROMA_SIDE, ii, wedge_mask, &mut pred_u, |
| 25970 | + ); | ||
| 25971 | + interintra_blend( | ||
| 25972 | + v, cpx, cpy, CHROMA_SIDE, CHROMA_SIDE, CHROMA_SIDE, ii, wedge_mask, &mut pred_v, | ||
| 25973 | + ); | ||
| 25941 | } | 25974 | } |
| 25942 | 25975 | ||
| 25943 | split8 = read_block_tx_size( | 25976 | split8 = read_block_tx_size( |
crates/ec-av1/src/stream.rsmodified+9 -2
| @@ -29,6 +29,13 @@ use crate::decode::{ | |||
| 29 | }; | 29 | }; |
| 30 | use crate::encode::Picture; | 30 | use crate::encode::Picture; |
| 31 | 31 | ||
| 32 | +/// lane-midcut r1: `EC_AV1_NO_GRAIN=1` skips film grain synthesis at output, so a | ||
| 33 | +/// mid-film mismatch splits into "reconstruction" (compare against | ||
| 34 | +/// `ffmpeg -c:v libdav1d -filmgrain 0`) and "grain synthesis" in one run. | ||
| 35 | +fn no_grain() -> bool { | ||
| 36 | + std::env::var_os("EC_AV1_NO_GRAIN").is_some() | ||
| 37 | +} | ||
| 38 | + | ||
| 32 | /// lane-hidden r1: where `EC_AV1_FINAL_DUMP`'s per-frame dump goes for the | 39 | /// lane-hidden r1: where `EC_AV1_FINAL_DUMP`'s per-frame dump goes for the |
| 33 | /// current thread, overriding the environment variable. Every ffmpeg/aomdec | 40 | /// current thread, overriding the environment variable. Every ffmpeg/aomdec |
| 34 | /// pixel gate in this repo compares SHOWN frames only (class | 41 | /// pixel gate in this repo compares SHOWN frames only (class |
| @@ -297,7 +304,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 297 | order_hint_slots[i] = order_hint_slots[slot]; | 304 | order_hint_slots[i] = order_hint_slots[slot]; |
| 298 | } | 305 | } |
| 299 | } | 306 | } |
| 300 | - let output = if header.film_grain.apply_grain { | 307 | + let output = if header.film_grain.apply_grain && !no_grain() { |
| 301 | // lane-hbd10 r1: grain synthesis is bit-depth generic | 308 | // lane-hbd10 r1: grain synthesis is bit-depth generic |
| 302 | // (`film_grain.rs`'s `grain_range`/`scale_lut`, spec 7.18.3). | 309 | // (`film_grain.rs`'s `grain_range`/`scale_lut`, spec 7.18.3). |
| 303 | let bit_depth = parser | 310 | let bit_depth = parser |
| @@ -967,7 +974,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 967 | decode::note_fwd_kf(); | 974 | decode::note_fwd_kf(); |
| 968 | } | 975 | } |
| 969 | if header.show_frame { | 976 | if header.show_frame { |
| 970 | - let output = if header.film_grain.apply_grain { | 977 | + let output = if header.film_grain.apply_grain && !no_grain() { |
| 971 | let mc_identity = parser | 978 | let mc_identity = parser |
| 972 | .sequence_header() | 979 | .sequence_header() |
| 973 | .is_some_and(|seq| seq.color_config.matrix_coefficients == 0); | 980 | .is_some_and(|seq| seq.color_config.matrix_coefficients == 0); |